2024-02-15 11:54:57 +00:00
|
|
|
import debug from 'debug';
|
|
|
|
|
2024-10-07 12:53:53 +00:00
|
|
|
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
|
2024-02-15 11:54:57 +00:00
|
|
|
|
2024-10-03 10:44:08 +00:00
|
|
|
import { getConfig } from '../src/utils';
|
2024-02-15 11:54:57 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:initialize-registry');
|
|
|
|
|
2024-10-03 04:50:38 +00:00
|
|
|
const DENOM = 'alnt';
|
2024-02-15 11:54:57 +00:00
|
|
|
const BOND_AMOUNT = '1000000000';
|
|
|
|
|
|
|
|
async function main () {
|
2024-10-03 04:50:38 +00:00
|
|
|
const { registryConfig } = await getConfig();
|
2024-02-15 11:54:57 +00:00
|
|
|
|
2024-02-23 09:17:29 +00:00
|
|
|
// TODO: Get authority names from args
|
|
|
|
const authorityNames = ['snowballtools', registryConfig.authority];
|
|
|
|
|
2024-10-03 04:50:38 +00:00
|
|
|
const registry = new Registry(registryConfig.gqlEndpoint, registryConfig.restEndpoint, {chainId: registryConfig.chainId});
|
2024-02-15 11:54:57 +00:00
|
|
|
|
|
|
|
const bondId = await registry.getNextBondId(registryConfig.privateKey);
|
|
|
|
log('bondId:', bondId);
|
2024-10-03 04:50:38 +00:00
|
|
|
|
2024-10-07 12:53:53 +00:00
|
|
|
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
|
2024-10-03 04:50:38 +00:00
|
|
|
|
2024-02-22 05:45:17 +00:00
|
|
|
await registry.createBond(
|
|
|
|
{ denom: DENOM, amount: BOND_AMOUNT },
|
|
|
|
registryConfig.privateKey,
|
2024-10-03 04:50:38 +00:00
|
|
|
fee
|
2024-02-22 05:45:17 +00:00
|
|
|
);
|
2024-02-15 11:54:57 +00:00
|
|
|
|
2024-02-23 09:17:29 +00:00
|
|
|
for await (const name of authorityNames) {
|
2024-10-03 04:50:38 +00:00
|
|
|
await registry.reserveAuthority({ name }, registryConfig.privateKey, fee);
|
2024-02-15 11:54:57 +00:00
|
|
|
log('Reserved authority name:', name);
|
2024-02-22 05:45:17 +00:00
|
|
|
await registry.setAuthorityBond(
|
|
|
|
{ name, bondId },
|
|
|
|
registryConfig.privateKey,
|
2024-10-03 04:50:38 +00:00
|
|
|
fee
|
2024-02-22 05:45:17 +00:00
|
|
|
);
|
2024-02-15 11:54:57 +00:00
|
|
|
log(`Bond ${bondId} set for authority ${name}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|