snowballtools-base/packages/backend/test/initialize-registry.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import debug from 'debug';
2024-10-03 04:50:38 +00:00
import { Registry } from '@cerc-io/registry-sdk';
2024-10-03 04:50:38 +00:00
import { getConfig, parseGasAndFees } from '../src/utils';
const log = debug('snowball:initialize-registry');
2024-10-03 04:50:38 +00:00
const DENOM = 'alnt';
const BOND_AMOUNT = '1000000000';
async function main () {
2024-10-03 04:50:38 +00:00
const { registryConfig } = await getConfig();
// 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});
const bondId = await registry.getNextBondId(registryConfig.privateKey);
log('bondId:', bondId);
2024-10-03 04:50:38 +00:00
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
await registry.createBond(
{ denom: DENOM, amount: BOND_AMOUNT },
registryConfig.privateKey,
2024-10-03 04:50:38 +00:00
fee
);
for await (const name of authorityNames) {
2024-10-03 04:50:38 +00:00
await registry.reserveAuthority({ name }, registryConfig.privateKey, fee);
log('Reserved authority name:', name);
await registry.setAuthorityBond(
{ name, bondId },
registryConfig.privateKey,
2024-10-03 04:50:38 +00:00
fee
);
log(`Bond ${bondId} set for authority ${name}`);
}
}
main().catch((err) => {
log(err);
});