Add command to create auctions
This commit is contained in:
parent
86259b35a6
commit
37df84b562
102
src/cmds/registry-cmds/auction-cmds/create.ts
Normal file
102
src/cmds/registry-cmds/auction-cmds/create.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import Long from 'long';
|
||||
|
||||
import { Account, DENOM, Registry } from '@cerc-io/registry-sdk';
|
||||
|
||||
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||
import { MsgCreateAuctionResponse } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/tx';
|
||||
|
||||
export const command = 'create';
|
||||
|
||||
export const desc = 'Create auction.';
|
||||
|
||||
export const builder = {
|
||||
kind: {
|
||||
type: 'string'
|
||||
},
|
||||
'commits-duration': {
|
||||
type: 'number'
|
||||
},
|
||||
'reveals-duration': {
|
||||
type: 'number'
|
||||
},
|
||||
'commit-fee': {
|
||||
type: 'string'
|
||||
},
|
||||
'reveal-fee': {
|
||||
type: 'string'
|
||||
},
|
||||
'minimum-bid': {
|
||||
type: 'string'
|
||||
},
|
||||
'max-price': {
|
||||
type: 'string'
|
||||
},
|
||||
'num-providers': {
|
||||
type: 'string'
|
||||
}
|
||||
};
|
||||
|
||||
export const handler = async (argv: Arguments) => {
|
||||
const { config } = argv;
|
||||
|
||||
const kind = argv.kind as string;
|
||||
const commitsDuration = {
|
||||
seconds: Long.fromNumber(argv.commitsDuration as number),
|
||||
nanos: 0
|
||||
};
|
||||
const revealsDuration = {
|
||||
seconds: Long.fromNumber(argv.revealsDuration as number),
|
||||
nanos: 0
|
||||
};
|
||||
const commitFee = {
|
||||
denom: DENOM,
|
||||
amount: argv.commitFee as string
|
||||
};
|
||||
const revealFee = {
|
||||
denom: DENOM,
|
||||
amount: argv.revealFee as string
|
||||
};
|
||||
const minimumBid = {
|
||||
denom: DENOM,
|
||||
amount: argv.minimumBid as string
|
||||
};
|
||||
const maxPrice = {
|
||||
denom: DENOM,
|
||||
amount: argv.maxPrice as string
|
||||
};
|
||||
const numProviders = argv.numProviders as number;
|
||||
|
||||
assert(kind, 'Invalid auction kind.');
|
||||
assert(commitsDuration, 'Invalid commits duration.');
|
||||
assert(revealsDuration, 'Invalid reveals duration.');
|
||||
assert(commitFee, 'Invalid commit fee.');
|
||||
assert(revealFee, 'Invalid reveal fee.');
|
||||
|
||||
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||
assert(privateKey, 'Invalid Transaction Key.');
|
||||
assert(chainId, 'Invalid registry Chain ID.');
|
||||
|
||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||
await account.init();
|
||||
const signer = account.address;
|
||||
|
||||
const gasPrice = getGasPrice(argv, registryConfig);
|
||||
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||
|
||||
const fee = getGasAndFees(argv, registryConfig);
|
||||
|
||||
let result: MsgCreateAuctionResponse;
|
||||
if (kind === 'vickrey') {
|
||||
result = await registry.createAuction({ commitsDuration, revealsDuration, commitFee, revealFee, minimumBid, signer }, privateKey, fee);
|
||||
} else {
|
||||
result = await registry.createProviderAuction({ commitsDuration, revealsDuration, commitFee, revealFee, signer, maxPrice, numProviders }, privateKey, fee);
|
||||
}
|
||||
const jsonString = `{"auctionId":"${result.auction?.id}"}`;
|
||||
|
||||
txOutput(result, jsonString, argv.output, argv.verbose);
|
||||
};
|
Loading…
Reference in New Issue
Block a user