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 11:20:47 +00:00
import { Registry, Util } from '@cerc-io/registry-sdk';
import { getConfig } 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 = Util.parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
2024-10-03 04:50:38 +00:00
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);
});