From fa734a4ff8f5899ddacedd75fd2bc7c9309710da Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 20 Sep 2024 18:50:09 +0530 Subject: [PATCH] Update create auction CLI with updated types --- README.md | 4 +- src/cmds/registry-cmds/auction-cmds/create.ts | 38 +++++++++---------- test/cli.test.ts | 4 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 6594f86..7afa70c 100644 --- a/README.md +++ b/README.md @@ -663,7 +663,7 @@ laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55b Create a `provider` auction: ```bash -laconic registry auction create --kind provider --commits-duration 60 --reveals-duration 60 --denom alnt --commit-fee 1000 --reveal-fee 1000 --max-price 100000 --num-providers 1 +laconic registry auction create --kind provider --commits-duration 60 --reveals-duration 60 --denom alnt --commit-fee 1000 --reveal-fee 1000 --max-price 100000 --num-providers 5 {"auctionId":"73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630"} @@ -730,7 +730,7 @@ laconic registry auction get $AUCTION "type": "alnt", "quantity": 100000 }, - "numProviders": 1, + "numProviders": 5, "bids": [ { "bidderAddress": "laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r", diff --git a/src/cmds/registry-cmds/auction-cmds/create.ts b/src/cmds/registry-cmds/auction-cmds/create.ts index d16b189..089a114 100644 --- a/src/cmds/registry-cmds/auction-cmds/create.ts +++ b/src/cmds/registry-cmds/auction-cmds/create.ts @@ -1,9 +1,7 @@ import { Arguments } from 'yargs'; import assert from 'assert'; -import Long from 'long'; -import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Duration, Registry } from '@cerc-io/registry-sdk'; -import { coin } from '@cosmjs/amino'; +import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Registry } from '@cerc-io/registry-sdk'; import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util'; @@ -17,11 +15,11 @@ export const builder = { describe: 'Auction kind (vickrey | provider)' }, 'commits-duration': { - type: 'number', + type: 'string', describe: 'Duration for bid commit phase in seconds' }, 'reveals-duration': { - type: 'number', + type: 'string', describe: 'Duration for bid reveal phase in seconds' }, denom: { @@ -29,20 +27,20 @@ export const builder = { describe: 'Denom to use' }, 'commit-fee': { - type: 'number', + type: 'string', describe: 'Fee for committing a bid to the auction' }, 'reveal-fee': { - type: 'number', + type: 'string', describe: 'Fee for revealing a bid in the auction' }, 'minimum-bid': { - type: 'number', + type: 'string', default: 0, describe: 'Minimum bid amount (only for vickrey auction)' }, 'max-price': { - type: 'number', + type: 'string', default: 0, describe: 'Max acceptable bid price (only for provider auction)' }, @@ -56,6 +54,9 @@ export const handler = async (argv: Arguments) => { const { config } = argv; const kind = argv.kind as string; + const validAuctionKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER]; + assert(validAuctionKinds.includes(kind), `Invalid auction kind, has to be one of ${validAuctionKinds}.`); + if (kind === AUCTION_KIND_VICKREY) { assert(argv.minimumBid, 'Invalid minimum bid.'); assert(!argv.maxPrice, `Max price can only be used with ${AUCTION_KIND_PROVIDER} auction.`); @@ -71,19 +72,16 @@ export const handler = async (argv: Arguments) => { assert(argv.commitFee, 'Invalid commit fee.'); assert(argv.revealFee, 'Invalid reveal fee.'); - const commitsDuration = Duration.fromPartial({ seconds: Long.fromNumber(argv.commitsDuration as number) }); - const revealsDuration = Duration.fromPartial({ seconds: Long.fromNumber(argv.revealsDuration as number) }); + const commitsDuration = argv.commitsDuration as string; + const revealsDuration = argv.revealsDuration as string; const denom = argv.denom as string; - const commitFee = coin(argv.commitFee as string, denom); - const revealFee = coin(argv.revealFee as string, denom); - const minimumBid = coin(argv.minimumBid as string, denom); - const maxPrice = coin(argv.maxPrice as string, denom); + const commitFee = argv.commitFee as string; + const revealFee = argv.revealFee as string; + const minimumBid = argv.minimumBid as string; + const maxPrice = argv.maxPrice as string; const numProviders = argv.numProviders as number; - const validAuctionKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER]; - assert(validAuctionKinds.includes(kind), `Invalid auction kind, has to be one of ${validAuctionKinds}.`); - const { services: { registry: registryConfig } } = getConfig(config as string); const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig); assert(rpcEndpoint, 'Invalid registry RPC endpoint.'); @@ -98,9 +96,9 @@ export const handler = async (argv: Arguments) => { let result: any; if (kind === AUCTION_KIND_VICKREY) { - result = await registry.createAuction({ commitsDuration, revealsDuration, commitFee, revealFee, minimumBid }, privateKey, fee); + result = await registry.createAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, minimumBid }, privateKey, fee); } else { - result = await registry.createProviderAuction({ commitsDuration, revealsDuration, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee); + result = await registry.createProviderAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee); } const jsonString = `{"auctionId":"${result.auction?.id}"}`; diff --git a/test/cli.test.ts b/test/cli.test.ts index 4786a5b..90f15f5 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -599,7 +599,7 @@ describe('Test laconic CLI commands', () => { const bidAmount = 25000000; let bidRevealFilePath: string; - test('laconic registry auction create --kind --commits-duration --reveals-duration --commit-fee --reveal-fee --minimum-bid ', async () => { + test('laconic registry auction create --kind --commits-duration --reveals-duration --denom --commit-fee --reveal-fee --minimum-bid ', async () => { const createAuctionResult = spawnSync('laconic', [ 'registry', 'auction', @@ -723,7 +723,7 @@ describe('Test laconic CLI commands', () => { const bidAmount = 25000; let bidRevealFilePath: string; - test('laconic registry auction create --kind --commits-duration --reveals-duration --commit-fee --reveal-fee --max-price --num-providers ', async () => { + test('laconic registry auction create --kind --commits-duration --reveals-duration --denom --commit-fee --reveal-fee --max-price --num-providers ', async () => { const createAuctionResult = spawnSync('laconic', [ 'registry', 'auction',