Add commands for auction operations

This commit is contained in:
nabarun 2022-04-26 12:27:02 +05:30 committed by Ashwin Phatak
parent 7f3b07b394
commit 11482ab5c8
8 changed files with 169 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
node_modules/
dist/*
out
config.yml

View File

@ -6,6 +6,7 @@
"author": "",
"license": "UNLICENSED",
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.25",
@ -14,6 +15,7 @@
},
"dependencies": {
"chiba-clonk-client": "https://github.com/vulcanize/chiba-clonk-client.git#ec31da8cdea79170a87caf6124d9c12cd54dfbe4",
"fs-extra": "^10.1.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"lodash-clean": "^2.2.3",

View File

@ -0,0 +1,49 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import path from 'path';
import { Account, createBid, Registry } from 'chiba-clonk-client';
import { ensureDir } from 'fs-extra';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
const OUT_DIR = 'out';
export const command = 'commit [auction-id] [quantity] [type]';
export const desc = 'Commit auction bid.';
export const handler = async (argv: Arguments) => {
const auctionId = argv.auctionId as string;
const quantity = argv.quantity as string;
const denom = argv.type as string;
assert(auctionId, 'Invalid auction ID.');
assert(quantity, 'Invalid token quantity.');
assert(denom, 'Invalid token type.');
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 account = new Account(Buffer.from(privateKey, 'hex'));
const bidderAddress = account.formattedCosmosAddress;
const bidAmount = `${quantity}${denom}`;
const { reveal, commitHash } = await createBid(chainId, auctionId, bidderAddress, bidAmount);
// Save reveal file.
const outDirPath = path.join(process.cwd(), OUT_DIR);
const revealFilePath = path.join(outDirPath, `${commitHash}.json`);
await ensureDir(outDirPath);
fs.writeFileSync(revealFilePath, JSON.stringify(reveal, undefined, 2));
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
console.log(`\nReveal file: ${revealFilePath}`);
}

View File

@ -0,0 +1,32 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import path from 'path';
import { Registry } from 'chiba-clonk-client';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
export const command = 'reveal [auction-id] [file-path]';
export const desc = 'Reveal auction bid.';
export const handler = async (argv: Arguments) => {
const auctionId = argv.auctionId as string;
const filePath = argv.filePath as string;
assert(auctionId, 'Invalid auction ID.');
assert(filePath, 'Invalid reveal file path.');
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 reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -0,0 +1,15 @@
import yargs from 'yargs';
export const command = 'bid';
export const desc = 'Auction bid operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.options({
'auction-id': { type: 'string' },
'type': { type: 'string' },
'quantity': { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
.demandCommand();
}

View File

@ -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 [id]';
export const desc = 'Get auction information.';
export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid auction ID.');
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.getAuctionsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -0,0 +1,10 @@
import yargs from 'yargs';
export const command = 'auction';
export const desc = 'Auction operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('auction-cmds')
.demandCommand();
}

View File

@ -480,6 +480,13 @@
dependencies:
"@types/node" "*"
"@types/fs-extra@^9.0.13":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
integrity sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==
dependencies:
"@types/node" "*"
"@types/google-protobuf@^3.15.5":
version "3.15.5"
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.5.tgz#644b2be0f5613b1f822c70c73c6b0e0b5b5fa2ad"
@ -968,6 +975,15 @@ follow-redirects@^1.14.8:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
fs-extra@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@ -1000,6 +1016,11 @@ google-protobuf@^3.19.4:
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.20.1.tgz#1b255c2b59bcda7c399df46c65206aa3c7a0ce8b"
integrity sha512-XMf1+O32FjYIV3CYu6Tuh5PNbfNEU5Xu22X+Xkdb/DUexFlCzhvv7d5Iirm4AOwn8lv4al1YvIhzGrg2j9Zfzw==
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==
graphql.js@^0.6.8:
version "0.6.8"
resolved "https://registry.yarnpkg.com/graphql.js/-/graphql.js-0.6.8.tgz#5c2e57311b5e74c6665ff9394394bc76f273542f"
@ -1105,6 +1126,15 @@ js-yaml@^4.1.0:
dependencies:
argparse "^2.0.1"
jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"
jsonschema@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/jsonschema/-/jsonschema-1.4.0.tgz#1afa34c4bc22190d8e42271ec17ac8b3404f87b2"
@ -1451,6 +1481,11 @@ uint8array-tools@0.0.7:
resolved "https://registry.yarnpkg.com/uint8array-tools/-/uint8array-tools-0.0.7.tgz#a7a2bb5d8836eae2fade68c771454e6a438b390d"
integrity sha512-vrrNZJiusLWoFWBqz5Y5KMCgP9W9hnjZHzZiZRT8oNAkq3d5Z5Oe76jAvVVSRh4U8GGR90N2X1dWtrhvx6L8UQ==
universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
util-deprecate@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"