diff --git a/src/cmds/cns-cmds/bond-cmds/cancel.ts b/src/cmds/cns-cmds/bond-cmds/cancel.ts new file mode 100644 index 0000000..1520bf3 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/cancel.ts @@ -0,0 +1,26 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'cancel'; + +export const desc = 'Cancel bond.'; + +export const handler = async (argv: Arguments) => { + const id = argv.id as string + assert(id, 'Invalid Bond ID.'); + + const { services: { cns: cnsConfig } } = getConfig(argv.config as string) + const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(privateKey, 'Invalid Transaction Key.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + const fee = getGasAndFees(argv, cnsConfig); + const result = await registry.cancelBond({ id }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/create.ts b/src/cmds/cns-cmds/bond-cmds/create.ts new file mode 100644 index 0000000..b3e016d --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/create.ts @@ -0,0 +1,39 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'create'; + +export const desc = 'Create bond.'; + +export const builder = { + type: { + type: 'string' + }, + quantity: { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const { config, verbose } = argv; + const denom = argv.type as string; + const amount = argv.quantity as string; + + assert(denom, 'Invalid Type.'); + assert(amount, 'Invalid Quantity.'); + + const { services: { cns: cnsConfig } } = getConfig(config as string) + const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(privateKey, 'Invalid Transaction Key.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + const fee = getGasAndFees(argv, cnsConfig); + const result = await registry.createBond({ denom, amount }, privateKey, fee); + console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data); +} diff --git a/src/cmds/cns-cmds/bond-cmds/get.ts b/src/cmds/cns-cmds/bond-cmds/get.ts new file mode 100644 index 0000000..012e273 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/get.ts @@ -0,0 +1,25 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo } from '../../../util'; + +export const command = 'get'; + +export const desc = 'Get bond.'; + +export const handler = async (argv: Arguments) => { + const { id, config } = argv; + console.assert(id, 'Bond Id is required.'); + + const { services: { cns: cnsConfig } } = getConfig(config as string) + const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + + const result = await registry.getBondsByIds([id as string]); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/list.ts b/src/cmds/cns-cmds/bond-cmds/list.ts new file mode 100644 index 0000000..8aad1a3 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/list.ts @@ -0,0 +1,29 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo } from '../../../util'; + +export const command = 'list'; + +export const desc = 'List bonds.'; + +export const builder = { + owner: { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const { services: { cns: cnsConfig } } = getConfig(argv.config as string) + const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + + const { owner } = argv; + const result = await registry.queryBonds({ owner }); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/refill.ts b/src/cmds/cns-cmds/bond-cmds/refill.ts new file mode 100644 index 0000000..e00061e --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/refill.ts @@ -0,0 +1,40 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'refill'; + +export const desc = 'Refill bond.'; + +export const builder = { + type: { + type: 'string' + }, + quantity: { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const denom = argv.type as string; + const amount = argv.quantity as string; + const id = argv.id as string + + assert(id, 'Invalid Bond ID.'); + assert(denom, 'Invalid Type.'); + assert(amount, 'Invalid Quantity.'); + + const { services: { cns: cnsConfig } } = getConfig(argv.config as string) + const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(privateKey, 'Invalid Transaction Key.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + const fee = getGasAndFees(argv, cnsConfig); + const result = await registry.refillBond({ id, denom, amount }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/withdraw.ts b/src/cmds/cns-cmds/bond-cmds/withdraw.ts new file mode 100644 index 0000000..0ac9d00 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/withdraw.ts @@ -0,0 +1,40 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'withdraw'; + +export const desc = 'Withdraw funds from bond.'; + +export const builder = { + type: { + type: 'string' + }, + quantity: { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const denom = argv.type as string; + const amount = argv.quantity as string; + const id = argv.id as string + + assert(id, 'Invalid Bond ID.'); + assert(denom, 'Invalid Type.'); + assert(amount, 'Invalid Quantity.'); + + const { services: { cns: cnsConfig } } = getConfig(argv.config as string) + const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig); + assert(restEndpoint, 'Invalid CNS REST endpoint.'); + assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); + assert(privateKey, 'Invalid Transaction Key.'); + assert(chainId, 'Invalid CNS Chain ID.'); + + const registry = new Registry(restEndpoint, gqlEndpoint, chainId); + const fee = getGasAndFees(argv, cnsConfig); + const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond.ts b/src/cmds/cns-cmds/bond.ts new file mode 100644 index 0000000..4747112 --- /dev/null +++ b/src/cmds/cns-cmds/bond.ts @@ -0,0 +1,10 @@ +import yargs from 'yargs'; + +export const command = 'bond'; + +export const desc = 'Bonds operations.'; + +exports.builder = (yargs: yargs.Argv) => { + return yargs.commandDir('bond-cmds') + .demandCommand(); +}