Add command to create an auction and add auction CLI tests #83

Merged
nabarun merged 13 commits from deep-stack/laconic-registry-cli:iv-create-auction-cmds into main 2024-09-25 13:57:56 +00:00
3 changed files with 54 additions and 26 deletions
Showing only changes of commit b18314eef4 - Show all commits

View File

@ -2,10 +2,11 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import Long from 'long';
import { Account, DENOM, Registry } from '@cerc-io/registry-sdk';
import { Registry } from '@cerc-io/registry-sdk';
import { MsgCreateAuctionResponse } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/tx';
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
import { MsgCreateAuctionResponse } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/tx';
import { AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER } from '../../../../test/helpers';
export const command = 'create';
@ -13,28 +14,40 @@ export const desc = 'Create auction.';
export const builder = {
kind: {
type: 'string'
type: 'string',
describe: 'Type of auction (vickrey | provider)'
},
'commits-duration': {
type: 'number'
type: 'number',
describe: 'Duration for commits phase in seconds'
},
'reveals-duration': {
type: 'number'
type: 'number',
describe: 'Duration for reveals phase in seconds'
},
denom: {
type: 'string',
describe: 'Denom'
},
'commit-fee': {
type: 'string'
type: 'number',
describe: 'Fee for committing to the auction'
},
'reveal-fee': {
type: 'string'
type: 'number',
describe: 'Fee for revealing bids in the auction'
},
'minimum-bid': {
type: 'string'
type: 'number',
describe: 'Minimum bid amount (only for vickrey auction)'
},
'max-price': {
type: 'string'
type: 'number',
describe: 'Maximum price (only for provider auction)'
},
'num-providers': {
type: 'string'
type: 'number',
describe: 'Number of providers (only for provider auction)'
}
};
@ -50,29 +63,44 @@ export const handler = async (argv: Arguments) => {
seconds: Long.fromNumber(argv.revealsDuration as number),
nanos: 0
};
const denom = argv.denom as string;
const commitFee = {
denom: DENOM,
denom: denom,
amount: argv.commitFee as string
};
const revealFee = {
denom: DENOM,
denom: denom,
amount: argv.revealFee as string
};
const minimumBid = {
denom: DENOM,
denom: denom,
amount: argv.minimumBid as string
};
const maxPrice = {
denom: DENOM,
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 validKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER];
assert(validKinds.includes(kind), 'Invalid auction kind.');
if (kind === AUCTION_KIND_VICKREY) {
assert(commitsDuration, 'Invalid commits duration.');
assert(revealsDuration, 'Invalid reveals duration.');
assert(commitFee, 'Invalid commit fee.');
assert(revealFee, 'Invalid reveal fee.');
assert(!argv.maxPrice, 'Max price should not be provided for vickrey auction.');
assert(!argv.numProviders, 'Num providers should not be provided for vickrey auction.');
} else if (kind === AUCTION_KIND_PROVIDER) {
assert(commitsDuration, 'Invalid commits duration.');
assert(revealsDuration, 'Invalid reveals duration.');
assert(commitFee, 'Invalid commit fee.');
assert(revealFee, 'Invalid reveal fee.');
assert(maxPrice, 'Invalid max price.');
assert(numProviders, 'Invalid number of providers.');
assert(!argv.minimumBid, 'Minimum bid should not be provided for provider auction.');
}
const { services: { registry: registryConfig } } = getConfig(config as string);
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
@ -81,20 +109,16 @@ export const handler = async (argv: Arguments) => {
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);
if (kind === AUCTION_KIND_VICKREY) {
result = await registry.createAuction({ commitsDuration, revealsDuration, commitFee, revealFee, minimumBid }, privateKey, fee);
} else {
result = await registry.createProviderAuction({ commitsDuration, revealsDuration, commitFee, revealFee, signer, maxPrice, numProviders }, privateKey, fee);
result = await registry.createProviderAuction({ commitsDuration, revealsDuration, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee);
}
const jsonString = `{"auctionId":"${result.auction?.id}"}`;

View File

@ -1,5 +1,6 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/registry-sdk';
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';

View File

@ -16,6 +16,9 @@ export const AUCTION_FEES = {
export const AUCTION_COMMIT_DURATION = 60; // 60s
export const AUCTION_REVEAL_DURATION = 60; // 60s
export const AUCTION_KIND_VICKREY = 'vickrey';
export const AUCTION_KIND_PROVIDER = 'provider';
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
expect(result.status).toBe(0);