-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfund.ts
50 lines (40 loc) · 1.62 KB
/
fund.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { LogLevel, LogOptions, logger } from '@api3/airnode-utilities';
import { go } from '@api3/promise-utils';
import * as hre from 'hardhat';
import { MerkleFunder__factory } from '../src';
import { loadConfig } from '../src/config';
import { fundChainRecipients } from '../src/merkle-funder';
async function main() {
const chainId = await hre.getChainId();
const logOptions: LogOptions = {
format: 'plain',
level: (process.env.LOG_LEVEL as LogLevel) || 'INFO',
meta: {
'CHAIN-ID': chainId,
NETWORK: hre.network.name,
},
};
const loadConfigResult = await go(() => loadConfig());
if (!loadConfigResult.success) {
logger.error(`Failed to load config:\n${loadConfigResult.error.message}`, null, logOptions);
return;
}
const merkleFunderDeployment = await hre.deployments.get('MerkleFunder');
logger.info(`MerkleFunder address: ${merkleFunderDeployment.address}`, logOptions);
const deployerAddress = (await hre.getUnnamedAccounts())[0];
logger.info(`Deployer address: ${deployerAddress}`, logOptions);
const deployer = await hre.ethers.getSigner(deployerAddress);
const merkleFunderContract = MerkleFunder__factory.connect(merkleFunderDeployment.address, deployer);
const chainConfig = loadConfigResult.data[parseInt(chainId)];
if (!chainConfig.merkleFunderDepositories) {
logger.error(`No MerkleFunderDepositories found for chain ID: ${chainId}`, null, logOptions);
return;
}
await fundChainRecipients(chainId, chainConfig, merkleFunderContract, logOptions);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});