Compare commits
6 Commits
main
...
iv-gas-con
Author | SHA1 | Date | |
---|---|---|---|
|
56f958b9d3 | ||
743f5ebc3c | |||
705bf0257a | |||
426515a9a1 | |||
f99f222162 | |||
02057d891a |
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,7 +4,6 @@ dist/*
|
|||||||
out
|
out
|
||||||
|
|
||||||
config.yml
|
config.yml
|
||||||
.env
|
|
||||||
*~
|
*~
|
||||||
|
|
||||||
.idea
|
.idea
|
210
README.md
210
README.md
@ -4,7 +4,7 @@ CLI utility written in TS, used to interact with laconicd. Depends on [registry-
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
* Add `.npmrc` file in desired project to resolve package
|
- Add `.npmrc` file in desired project to resolve package
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@cerc-io:registry=https://git.vdb.to/api/packages/cerc-io/npm/
|
@cerc-io:registry=https://git.vdb.to/api/packages/cerc-io/npm/
|
||||||
@ -12,13 +12,13 @@ CLI utility written in TS, used to interact with laconicd. Depends on [registry-
|
|||||||
|
|
||||||
This will set the registry for `cerc-io` scoped packages in the project
|
This will set the registry for `cerc-io` scoped packages in the project
|
||||||
|
|
||||||
* Install the CLI using package manager
|
- Install the CLI using package manager
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add @cerc-io/laconic-registry-cli
|
yarn add @cerc-io/laconic-registry-cli
|
||||||
```
|
```
|
||||||
|
|
||||||
* For installing CLI globally add `.npmrc` file above in home directory and run
|
- For installing CLI globally add `.npmrc` file above in home directory and run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn global add @cerc-io/laconic-registry-cli
|
yarn global add @cerc-io/laconic-registry-cli
|
||||||
@ -26,13 +26,13 @@ CLI utility written in TS, used to interact with laconicd. Depends on [registry-
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
* Run `yarn` to install all dependencies.
|
- Run `yarn` to install all dependencies.
|
||||||
|
|
||||||
* Run `yarn build`.
|
- Run `yarn build`.
|
||||||
|
|
||||||
* Create a `config.yml` file from [config.example.yml](./config.example.yml) file.
|
- Create a `config.yml` file from [config.example.yml](./config.example.yml) file.
|
||||||
|
|
||||||
* Add CLI cmd to path
|
- Add CLI cmd to path
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export PATH="$PWD/bin:$PATH"
|
export PATH="$PWD/bin:$PATH"
|
||||||
@ -42,7 +42,7 @@ CLI utility written in TS, used to interact with laconicd. Depends on [registry-
|
|||||||
|
|
||||||
Run the chain:
|
Run the chain:
|
||||||
|
|
||||||
* In laconicd repo run:
|
- In laconicd repo run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
TEST_AUCTION_ENABLED=true ./scripts/init.sh clean
|
TEST_AUCTION_ENABLED=true ./scripts/init.sh clean
|
||||||
@ -66,24 +66,24 @@ services:
|
|||||||
|
|
||||||
## Gas and Fees
|
## Gas and Fees
|
||||||
|
|
||||||
* Gas and fees in `cosmos-sdk`:
|
- Gas and fees in `cosmos-sdk`:
|
||||||
* <https://docs.cosmos.network/v0.50/learn/beginner/gas-fees>
|
- <https://docs.cosmos.network/v0.50/learn/beginner/gas-fees>
|
||||||
* `gas` is a special unit that is used to track the consumption of resources during execution of a transaction
|
- `gas` is a special unit that is used to track the consumption of resources during execution of a transaction
|
||||||
* The maximum value a tx is allowed to consume can be capped by setting `gas` in the config
|
- The maximum value a tx is allowed to consume can be capped by setting `gas` in the config
|
||||||
* `fees` have to be paid by sender to allow the transaction into the mempool and is calculated using `gasPrice`:
|
- `fees` have to be paid by sender to allow the transaction into the mempool and is calculated using `gasPrice`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fees = gas * gasPrice
|
fees = gas * gasPrice
|
||||||
```
|
```
|
||||||
|
|
||||||
* Typically, validators / full nodes set `min-gas-prices` to only allow txs providing minimum amount of fees
|
- Typically, validators / full nodes set `min-gas-prices` to only allow txs providing minimum amount of fees
|
||||||
* Using `cosmjs`, there are two ways max fees amount can be given for a tx:
|
- Using `cosmjs`, there are two ways max fees amount can be given for a tx:
|
||||||
* Either by specifying `fees` and `gas` (in which case `fees` should be >= `gas` * `min-gas-price`)
|
- Either by specifying `fees` and `gas` (in which case `fees` should be >= `gas` * `min-gas-price`)
|
||||||
* Or by specifying a `gasPrice` (in which case `gasPrice` should be >= `min-gas-price` set by the node and fees is `auto` calculated by simulating the tx)
|
- Or by specifying a `gasPrice` (in which case `gasPrice` should be >= `min-gas-price` set by the node and fees is `auto` calculated by simulating the tx)
|
||||||
|
|
||||||
When using the `auto` fees calculation, the gas estimation by tx simulation is typically multiplied by a multiplier
|
When using the `auto` fees calculation, the gas estimation by tx simulation is typically multiplied by a multiplier
|
||||||
* As such, following `gas`, `fees` and `gasPrice` combinations can be used in `laconic-registry-cli`:
|
- As such, following `gas`, `fees` and `gasPrice` combinations can be used in `laconic-registry-cli`:
|
||||||
* Gas set, fees set to `Xalnt`:
|
- Gas set, fees set to `Xalnt`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
@ -92,10 +92,10 @@ services:
|
|||||||
gasPrice:
|
gasPrice:
|
||||||
```
|
```
|
||||||
|
|
||||||
* `gasPrice` config ignored
|
- `gasPrice` config ignored
|
||||||
* tx rejected if given `fees` < `gas` * `min-gas-price` set by the node
|
- tx rejected if given `fees` < `gas` * `min-gas-price` set by the node
|
||||||
* tx fails mid-execution if it runs out of given `gas`
|
- tx fails mid-execution if it runs out of given `gas`
|
||||||
* Fees not set, gas price set to `Xalnt`:
|
- Fees not set, gas price set to `Xalnt`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
@ -104,11 +104,11 @@ services:
|
|||||||
gasPrice: 1alnt
|
gasPrice: 1alnt
|
||||||
```
|
```
|
||||||
|
|
||||||
* `gas` config ignored
|
- `gas` config ignored
|
||||||
* uses `auto` fee calculation using gas estimation with [default multiplier](https://git.vdb.to/cerc-io/registry-sdk/src/branch/main/src/constants.ts) value from `registry-sdk`
|
- uses `auto` fee calculation using gas estimation with [default multiplier](https://git.vdb.to/cerc-io/registry-sdk/src/branch/main/src/constants.ts) value from `registry-sdk`
|
||||||
* tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
- tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
||||||
* tx fails mid-execution if it runs out of calculated gas
|
- tx fails mid-execution if it runs out of calculated gas
|
||||||
* Fees set to a `X` (without `alnt` suffix), gas price set to `Yalnt`:
|
- Fees set to a `X` (without `alnt` suffix), gas price set to `Yalnt`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
@ -117,11 +117,11 @@ services:
|
|||||||
gasPrice: 1alnt
|
gasPrice: 1alnt
|
||||||
```
|
```
|
||||||
|
|
||||||
* `gas` config ignored
|
- `gas` config ignored
|
||||||
* uses `auto` fee calculation using gas estimation with `fees` as the multiplier
|
- uses `auto` fee calculation using gas estimation with `fees` as the multiplier
|
||||||
* tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
- tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
||||||
* tx fails mid-execution if it runs out of calculated gas, can be retried with a higher gas estimation multiplier (`fees`)
|
- tx fails mid-execution if it runs out of calculated gas, can be retried with a higher gas estimation multiplier (`fees`)
|
||||||
* Fees and gas price both not set:
|
- Fees and gas price both not set:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
@ -130,15 +130,15 @@ services:
|
|||||||
gasPrice:
|
gasPrice:
|
||||||
```
|
```
|
||||||
|
|
||||||
* `gas` config ignored
|
- `gas` config ignored
|
||||||
* uses `auto` fee calculation using gas estimation
|
- uses `auto` fee calculation using gas estimation
|
||||||
* throws error:
|
- throws error:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Gas price must be set in the client options when auto gas is used.
|
Gas price must be set in the client options when auto gas is used.
|
||||||
```
|
```
|
||||||
|
|
||||||
* The `gas`, `fees` and `gasPrice` can be set to some default values in the config as shown above, and can be overriden for each command using the `--gas`, `--fees` and `--gasPrice` arguments:
|
- The `gas`, `fees` and `gasPrice` can be set to some default values in the config as shown above, and can be overriden for each command using the `--gas`, `--fees` and `--gasPrice` arguments:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example:
|
# Example:
|
||||||
@ -152,7 +152,7 @@ These commands require a `config.yml` file present in the current working direct
|
|||||||
Get node status:
|
Get node status:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry status
|
$ laconic registry status
|
||||||
{
|
{
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"node": {
|
"node": {
|
||||||
@ -186,7 +186,7 @@ laconic registry status
|
|||||||
Get account details:
|
Get account details:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry account get --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
$ laconic registry account get --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"address": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
"address": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
@ -206,7 +206,7 @@ laconic registry account get --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7m
|
|||||||
Send tokens:
|
Send tokens:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry tokens send --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k --type alnt --quantity 1000000000
|
$ laconic registry tokens send --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k --type alnt --quantity 1000000000
|
||||||
{
|
{
|
||||||
"tx": {
|
"tx": {
|
||||||
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
||||||
@ -250,7 +250,7 @@ laconic registry tokens send --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7m
|
|||||||
Get token TX details:
|
Get token TX details:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry tokens gettx --hash 977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC
|
$ laconic registry tokens gettx --hash 977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC
|
||||||
{
|
{
|
||||||
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
||||||
"height": 343369,
|
"height": 343369,
|
||||||
@ -280,7 +280,7 @@ record:
|
|||||||
Publish record (see below for commands to create/query bonds):
|
Publish record (see below for commands to create/query bonds):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000 --fees 250000alnt
|
$ laconic registry record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000 --fees 250000alnt
|
||||||
|
|
||||||
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
|
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
|
||||||
```
|
```
|
||||||
@ -288,7 +288,7 @@ laconic registry record publish --filename watcher.yml --bond-id 58508984500aa2e
|
|||||||
Get record:
|
Get record:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry record get --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
$ laconic registry record get --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
||||||
@ -341,7 +341,7 @@ laconic registry authority reserve laconic
|
|||||||
Check authority information:
|
Check authority information:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry authority whois laconic
|
$ laconic registry authority whois laconic
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"ownerAddress": "",
|
"ownerAddress": "",
|
||||||
@ -387,7 +387,7 @@ laconic registry authority whois laconic
|
|||||||
Get authority auction info:
|
Get authority auction info:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48
|
$ laconic registry auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
||||||
@ -425,7 +425,7 @@ laconic registry auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d246
|
|||||||
Commit an auction bid:
|
Commit an auction bid:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction bid commit 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 25000000 alnt
|
$ laconic registry auction bid commit 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 25000000 alnt
|
||||||
|
|
||||||
Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
||||||
```
|
```
|
||||||
@ -475,7 +475,7 @@ laconic registry name set lrn://laconic/watcher/erc20 bafyreic3auqajvgszh3vfjsou
|
|||||||
Lookup name information:
|
Lookup name information:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry name lookup lrn://laconic/watcher/erc20
|
$ laconic registry name lookup lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"latest": {
|
"latest": {
|
||||||
@ -489,7 +489,7 @@ laconic registry name lookup lrn://laconic/watcher/erc20
|
|||||||
Resolve name:
|
Resolve name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry name resolve lrn://laconic/watcher/erc20
|
$ laconic registry name resolve lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
||||||
@ -530,9 +530,9 @@ laconic registry name resolve lrn://laconic/watcher/erc20
|
|||||||
Delete name:
|
Delete name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry name delete lrn://laconic/watcher/erc20
|
$ laconic registry name delete lrn://laconic/watcher/erc20
|
||||||
|
|
||||||
laconic registry name resolve lrn://laconic/watcher/erc20
|
$ laconic registry name resolve lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
@ -547,7 +547,7 @@ laconic registry bond create --type alnt --quantity 1000
|
|||||||
List bonds:
|
List bonds:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry bond list
|
$ laconic registry bond list
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
@ -575,7 +575,7 @@ laconic registry bond list
|
|||||||
Get bond:
|
Get bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
$ laconic registry bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
@ -593,7 +593,7 @@ laconic registry bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361
|
|||||||
Query bonds by owner:
|
Query bonds by owner:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry bond list --owner laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
$ laconic registry bond list --owner laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
@ -659,107 +659,3 @@ Reassociate records (switch bond):
|
|||||||
```bash
|
```bash
|
||||||
laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
||||||
```
|
```
|
||||||
|
|
||||||
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 5
|
|
||||||
|
|
||||||
{"auctionId":"73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630"}
|
|
||||||
|
|
||||||
# Set auction id in a variable
|
|
||||||
AUCTION=
|
|
||||||
```
|
|
||||||
|
|
||||||
Commit an auction bid:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
laconic registry auction bid commit $AUCTION 25000 alnt
|
|
||||||
|
|
||||||
{"reveal_file":"/home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json"}
|
|
||||||
```
|
|
||||||
|
|
||||||
Reveal an auction bid:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
laconic registry auction bid reveal $AUCTION /home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json
|
|
||||||
|
|
||||||
{"success": true}
|
|
||||||
```
|
|
||||||
|
|
||||||
Check the auction state on completion:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
laconic registry auction get $AUCTION
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": "b66b74048fc360de6a926123b760e6485276d90ad2274b5386c02664cd04bace",
|
|
||||||
"kind": "provider",
|
|
||||||
"status": "completed",
|
|
||||||
"ownerAddress": "laconic1maqfgs93hnvzqh5mfj9kxt4e3n27vhd0w7emrx",
|
|
||||||
"createTime": "2024-09-17T09:51:48.605610628",
|
|
||||||
"commitsEndTime": "2024-09-17T09:52:48.605610628",
|
|
||||||
"revealsEndTime": "2024-09-17T09:53:48.605610628",
|
|
||||||
"commitFee": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 1000
|
|
||||||
},
|
|
||||||
"revealFee": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 1000
|
|
||||||
},
|
|
||||||
"minimumBid": {
|
|
||||||
"type": "",
|
|
||||||
"quantity": 0
|
|
||||||
},
|
|
||||||
"winnerAddresses": [
|
|
||||||
"laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r"
|
|
||||||
],
|
|
||||||
"winnerBids": [
|
|
||||||
{
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 25000
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"winnerPrice": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 25000
|
|
||||||
},
|
|
||||||
"maxPrice": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 100000
|
|
||||||
},
|
|
||||||
"numProviders": 5,
|
|
||||||
"bids": [
|
|
||||||
{
|
|
||||||
"bidderAddress": "laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r",
|
|
||||||
"status": "reveal",
|
|
||||||
"commitHash": "bafyreifjkhiakayvvaasnsw7ufaax54ncow4xuycqnox7hxay34c6yod7a",
|
|
||||||
"commitTime": "2024-09-17T09:52:03.665761945",
|
|
||||||
"revealTime": "2024-09-17T09:53:00.904061323",
|
|
||||||
"commitFee": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 1000
|
|
||||||
},
|
|
||||||
"revealFee": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 1000
|
|
||||||
},
|
|
||||||
"bidAmount": {
|
|
||||||
"type": "alnt",
|
|
||||||
"quantity": 25000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
Release provider winning funds:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
laconic registry auction release-funds $AUCTION
|
|
||||||
|
|
||||||
{"success": true}
|
|
||||||
```
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/laconic-registry-cli",
|
"name": "@cerc-io/laconic-registry-cli",
|
||||||
"version": "0.2.10",
|
"version": "0.2.6",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
||||||
"author": "",
|
"author": "",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/registry-sdk": "^0.2.11",
|
"@cerc-io/registry-sdk": "^0.2.6",
|
||||||
"@cosmjs/stargate": "^0.32.2",
|
"@cosmjs/stargate": "^0.32.2",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"js-yaml": "^3.14.1",
|
"js-yaml": "^3.14.1",
|
||||||
|
@ -1,106 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Registry } from '@cerc-io/registry-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'create';
|
|
||||||
|
|
||||||
export const desc = 'Create auction.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
kind: {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Auction kind (vickrey | provider)'
|
|
||||||
},
|
|
||||||
'commits-duration': {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Duration for bid commit phase in seconds'
|
|
||||||
},
|
|
||||||
'reveals-duration': {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Duration for bid reveal phase in seconds'
|
|
||||||
},
|
|
||||||
denom: {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Denom to use'
|
|
||||||
},
|
|
||||||
'commit-fee': {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Fee for committing a bid to the auction'
|
|
||||||
},
|
|
||||||
'reveal-fee': {
|
|
||||||
type: 'string',
|
|
||||||
describe: 'Fee for revealing a bid in the auction'
|
|
||||||
},
|
|
||||||
'minimum-bid': {
|
|
||||||
type: 'string',
|
|
||||||
default: 0,
|
|
||||||
describe: 'Minimum bid amount (only for vickrey auction)'
|
|
||||||
},
|
|
||||||
'max-price': {
|
|
||||||
type: 'string',
|
|
||||||
default: 0,
|
|
||||||
describe: 'Max acceptable bid price (only for provider auction)'
|
|
||||||
},
|
|
||||||
'num-providers': {
|
|
||||||
type: 'number',
|
|
||||||
describe: 'Number ofdesired providers (only for provider auction)'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.`);
|
|
||||||
assert(!argv.numProviders, `Num providers can only be used with ${AUCTION_KIND_PROVIDER} auction.`);
|
|
||||||
} else if (kind === AUCTION_KIND_PROVIDER) {
|
|
||||||
assert(argv.maxPrice, 'Invalid max price.');
|
|
||||||
assert(argv.numProviders, 'Invalid num providers.');
|
|
||||||
assert(!argv.minimumBid, `Minimum bid can only be used with ${AUCTION_KIND_VICKREY} auction.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(argv.commitsDuration, 'Invalid commits duration.');
|
|
||||||
assert(argv.revealsDuration, 'Invalid reveals duration.');
|
|
||||||
assert(argv.commitFee, 'Invalid commit fee.');
|
|
||||||
assert(argv.revealFee, 'Invalid reveal fee.');
|
|
||||||
|
|
||||||
const commitsDuration = argv.commitsDuration as string;
|
|
||||||
const revealsDuration = argv.revealsDuration as string;
|
|
||||||
|
|
||||||
const denom = argv.denom as string;
|
|
||||||
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 { 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 gasPrice = getGasPrice(argv, registryConfig);
|
|
||||||
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
|
||||||
|
|
||||||
const fee = getGasAndFees(argv, registryConfig);
|
|
||||||
|
|
||||||
let result: any;
|
|
||||||
if (kind === AUCTION_KIND_VICKREY) {
|
|
||||||
result = await registry.createAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, minimumBid }, privateKey, fee);
|
|
||||||
} else {
|
|
||||||
result = await registry.createProviderAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee);
|
|
||||||
}
|
|
||||||
|
|
||||||
const jsonString = `{"auctionId":"${result.auction?.id}"}`;
|
|
||||||
txOutput(result, jsonString, argv.output, argv.verbose);
|
|
||||||
};
|
|
@ -1,34 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { Account, Registry } from '@cerc-io/registry-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'release-funds [auction-id]';
|
|
||||||
|
|
||||||
export const desc = 'Release funds of provider auction winners.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const auctionId = argv.auctionId as string;
|
|
||||||
assert(auctionId, 'Invalid auction ID.');
|
|
||||||
|
|
||||||
const { services: { registry: registryConfig } } = getConfig(argv.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 gasPrice = getGasPrice(argv, registryConfig);
|
|
||||||
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
|
||||||
const fee = getGasAndFees(argv, registryConfig);
|
|
||||||
|
|
||||||
const result = await registry.releaseFunds({ auctionId }, privateKey, fee);
|
|
||||||
|
|
||||||
const success = '{"success": true}';
|
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
|
||||||
};
|
|
@ -1,6 +1,5 @@
|
|||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
|
||||||
import { Registry } from '@cerc-io/registry-sdk';
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
@ -27,7 +27,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const { owner } = argv;
|
const { owner } = argv;
|
||||||
if (owner) {
|
if (owner) {
|
||||||
const [bondsByOwnerResult] = await registry.queryBondsByOwners([String(owner)]);
|
const [bondsByOwnerResult] = await registry.queryBondsByOwner([String(owner)]);
|
||||||
result = bondsByOwnerResult.bonds;
|
result = bondsByOwnerResult.bonds;
|
||||||
} else {
|
} else {
|
||||||
result = await registry.queryBonds();
|
result = await registry.queryBonds();
|
||||||
|
@ -24,23 +24,13 @@ export const builder = {
|
|||||||
all: {
|
all: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false
|
default: false
|
||||||
},
|
|
||||||
refs: {
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
limit: {
|
|
||||||
type: 'number'
|
|
||||||
},
|
|
||||||
offset: {
|
|
||||||
type: 'number'
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
const { type, name, bondId, owner, all, refs, limit, offset } = argv;
|
const { type, name, bondId, owner, all } = argv;
|
||||||
const filters: any = {};
|
const filters: any = {};
|
||||||
|
|
||||||
const filterArgs = argv._.slice(3);
|
const filterArgs = argv._.slice(3);
|
||||||
@ -54,7 +44,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean, refs as boolean, limit as number, offset as number);
|
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean);
|
||||||
|
|
||||||
// Apply ex post filters.
|
// Apply ex post filters.
|
||||||
if (bondId) {
|
if (bondId) {
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
import assert from 'assert';
|
||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
|
|
||||||
import { parseGasAndFees, getGasPrice as registryGetGasPrice } from '@cerc-io/registry-sdk';
|
import { StdFee, GasPrice, parseCoins } from '@cosmjs/stargate';
|
||||||
import { StdFee, GasPrice } from '@cosmjs/stargate';
|
|
||||||
|
export const parseGasAndFees = (gas?: string, fees?: string): StdFee | number | undefined => {
|
||||||
|
const isFeesANumber = !isNaN(Number(fees));
|
||||||
|
|
||||||
|
// If fees is a number or not given, treat it as a gas estimation multiplier
|
||||||
|
if (fees == null) {
|
||||||
|
return undefined;
|
||||||
|
} else if (isFeesANumber) {
|
||||||
|
return Number(fees);
|
||||||
|
} else {
|
||||||
|
// If fees is not a gas estimation multiplier, gas is required
|
||||||
|
assert(gas, 'Invalid gas.');
|
||||||
|
|
||||||
|
return {
|
||||||
|
amount: parseCoins(String(fees)),
|
||||||
|
gas: String(gas)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => {
|
export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => {
|
||||||
return parseGasAndFees(
|
return parseGasAndFees(
|
||||||
@ -13,5 +32,5 @@ export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | numbe
|
|||||||
|
|
||||||
export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => {
|
export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => {
|
||||||
const gasPriceString = argv.gasPrice || config.gasPrice;
|
const gasPriceString = argv.gasPrice || config.gasPrice;
|
||||||
return registryGetGasPrice(gasPriceString);
|
return gasPriceString != null ? GasPrice.fromString(String(gasPriceString)) : undefined;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Run CLI tests
|
## Run CLI tests
|
||||||
|
|
||||||
* Follow the project `Setup` and `Account Setup` from root [README](./../README.md)
|
* Follow the project `Setup` and `Account Setup` from root [README](./../README.md)
|
||||||
|
|
||||||
|
334
test/cli.test.ts
334
test/cli.test.ts
@ -2,8 +2,6 @@ import fs from 'fs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
|
|
||||||
import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CHAIN_ID,
|
CHAIN_ID,
|
||||||
TOKEN_TYPE,
|
TOKEN_TYPE,
|
||||||
@ -18,9 +16,7 @@ import {
|
|||||||
getAuthorityObj,
|
getAuthorityObj,
|
||||||
getAuctionObj,
|
getAuctionObj,
|
||||||
getBidObj,
|
getBidObj,
|
||||||
updateGasAndFeesConfig,
|
updateGasAndFeesConfig
|
||||||
AUCTION_STATUS,
|
|
||||||
getFeesConfig
|
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
|
||||||
describe('Test laconic CLI commands', () => {
|
describe('Test laconic CLI commands', () => {
|
||||||
@ -229,7 +225,6 @@ describe('Test laconic CLI commands', () => {
|
|||||||
expect(outputObj.accounts.length).toEqual(2);
|
expect(outputObj.accounts.length).toEqual(2);
|
||||||
expect(outputObj.accounts).toMatchObject(expectedAccounts);
|
expect(outputObj.accounts).toMatchObject(expectedAccounts);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('laconic registry tokens gettx --hash <hash>', async () => {
|
test('laconic registry tokens gettx --hash <hash>', async () => {
|
||||||
const sendAmount = 1000000000;
|
const sendAmount = 1000000000;
|
||||||
|
|
||||||
@ -374,7 +369,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Authority auction operations', () => {
|
describe('Auction operations', () => {
|
||||||
const bidAmount = 25000000;
|
const bidAmount = 25000000;
|
||||||
let bidRevealFilePath: string;
|
let bidRevealFilePath: string;
|
||||||
|
|
||||||
@ -592,331 +587,6 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Vickrey Auction operations', () => {
|
|
||||||
const commitFee = 1000;
|
|
||||||
const revealFee = 1000;
|
|
||||||
const minimumBid = 100000;
|
|
||||||
|
|
||||||
const bidAmount = 25000000;
|
|
||||||
let bidRevealFilePath: string;
|
|
||||||
|
|
||||||
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --minimum-bid <minimum_bid>', async () => {
|
|
||||||
const createAuctionResult = spawnSync('laconic', [
|
|
||||||
'registry',
|
|
||||||
'auction',
|
|
||||||
'create',
|
|
||||||
'--kind', AUCTION_KIND_VICKREY,
|
|
||||||
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
|
||||||
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
|
||||||
'--denom', TOKEN_TYPE,
|
|
||||||
'--commit-fee', commitFee.toString(),
|
|
||||||
'--reveal-fee', revealFee.toString(),
|
|
||||||
'--minimum-bid', minimumBid.toString()
|
|
||||||
]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
|
||||||
|
|
||||||
expect(outputObj).toHaveProperty('auctionId');
|
|
||||||
|
|
||||||
testAuctionId = outputObj.auctionId;
|
|
||||||
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
kind: AUCTION_KIND_VICKREY,
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
commitFee: { quantity: commitFee },
|
|
||||||
revealFee: { quantity: revealFee },
|
|
||||||
minimumBid: { quantity: minimumBid },
|
|
||||||
winnerAddresses: [],
|
|
||||||
winnerBids: [],
|
|
||||||
maxPrice: { quantity: 0 },
|
|
||||||
numProviders: 0,
|
|
||||||
bids: []
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
// Expected output
|
|
||||||
expect(outputObj.reveal_file).toBeDefined();
|
|
||||||
|
|
||||||
bidRevealFilePath = outputObj.reveal_file;
|
|
||||||
});
|
|
||||||
|
|
||||||
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
|
||||||
// Wait for auction commits duration (60s)
|
|
||||||
await delay(AUCTION_COMMIT_DURATION * 1000);
|
|
||||||
|
|
||||||
let auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
let auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
winnerAddresses: [],
|
|
||||||
winnerBids: [],
|
|
||||||
bids: [{
|
|
||||||
bidderAddress: testAccount,
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
bidAmount: { quantity: 0 }
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
|
|
||||||
// Reveal bid
|
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
// Expected output
|
|
||||||
expect(outputObj).toEqual({ success: true });
|
|
||||||
|
|
||||||
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
|
|
||||||
expect(revealObject).toMatchObject({
|
|
||||||
chainId: CHAIN_ID,
|
|
||||||
auctionId: testAuctionId,
|
|
||||||
bidderAddress: testAccount,
|
|
||||||
bidAmount: `${bidAmount}${TOKEN_TYPE}`
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get auction with revealed bid
|
|
||||||
auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartialOnBidReveal = {
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
winnerAddresses: [],
|
|
||||||
bids: [{
|
|
||||||
bidderAddress: testAccount,
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
bidAmount: { quantity: bidAmount }
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
|
||||||
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
||||||
|
|
||||||
test('laconic registry auction get <auction_id>', async () => {
|
|
||||||
// Wait for auction reveals duration (60s)
|
|
||||||
await delay(AUCTION_REVEAL_DURATION * 1000);
|
|
||||||
|
|
||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.COMPLETED,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
winnerAddresses: [testAccount],
|
|
||||||
winnerBids: [{ quantity: bidAmount }],
|
|
||||||
winnerPrice: { quantity: bidAmount }
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Provider Auction operations', () => {
|
|
||||||
const txFees = getFeesConfig();
|
|
||||||
|
|
||||||
const commitFee = 1000;
|
|
||||||
const revealFee = 1000;
|
|
||||||
const maxPrice = 1000000;
|
|
||||||
const numProviders = 2;
|
|
||||||
const bidderInitialBlanace = 1000000000;
|
|
||||||
testAuctionId = '5e9dd5501e965f25db4fa62635d0ce5f6c59d73ab1a2ea999f8c5bf2f6fb6350';
|
|
||||||
|
|
||||||
const bidderAccounts = [
|
|
||||||
{
|
|
||||||
privateKey: 'f40f8e2c9ba70595b6d1cf3bcc47ba539e7d6ad2bcdb16e26c1e369378fd5a55',
|
|
||||||
address: 'laconic13cd6ntlcf5y0zmafg6wf96y6vsnq46xagpmjtc',
|
|
||||||
bidAmount: 25000
|
|
||||||
},
|
|
||||||
{
|
|
||||||
privateKey: '2c70e81c285e12f196837911aa258b11dff7e4189fc0f11e28cb228956807881',
|
|
||||||
address: 'laconic15x7sw49w3x2pahjlr48hunp5gpr7hm54eg3f8h',
|
|
||||||
bidAmount: 25300
|
|
||||||
},
|
|
||||||
{
|
|
||||||
privateKey: '1d3a47900e1a5980b171419ac700e779330bc0f85389a4113ff608ca314e25bb',
|
|
||||||
address: 'laconic1lkgay8ejvcwmngj3jua2ancdxxkukecz7hty89',
|
|
||||||
bidAmount: 25200
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const winnerAccounts = [bidderAccounts[0], bidderAccounts[2]];
|
|
||||||
const winnerPrice = bidderAccounts[2].bidAmount;
|
|
||||||
|
|
||||||
const bidRevealFilePaths: string[] = [];
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
// Fund all bidder accounts
|
|
||||||
bidderAccounts.forEach(account => {
|
|
||||||
spawnSync('laconic', ['registry', 'tokens', 'send', '--address', account.address, '--type', TOKEN_TYPE, '--quantity', bidderInitialBlanace.toString()]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --max-price <max_price> --num-providers <num_providers>', async () => {
|
|
||||||
const createAuctionResult = spawnSync('laconic', [
|
|
||||||
'registry',
|
|
||||||
'auction',
|
|
||||||
'create',
|
|
||||||
'--kind', AUCTION_KIND_PROVIDER,
|
|
||||||
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
|
||||||
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
|
||||||
'--denom', TOKEN_TYPE,
|
|
||||||
'--commit-fee', commitFee.toString(),
|
|
||||||
'--reveal-fee', revealFee.toString(),
|
|
||||||
'--max-price', maxPrice.toString(),
|
|
||||||
'--num-providers', numProviders.toString()
|
|
||||||
]);
|
|
||||||
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
|
||||||
|
|
||||||
expect(outputObj).toHaveProperty('auctionId');
|
|
||||||
|
|
||||||
testAuctionId = outputObj.auctionId;
|
|
||||||
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
kind: AUCTION_KIND_PROVIDER,
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
commitFee: { quantity: commitFee },
|
|
||||||
revealFee: { quantity: revealFee },
|
|
||||||
minimumBid: { quantity: 0 },
|
|
||||||
winnerAddresses: [],
|
|
||||||
winnerBids: [],
|
|
||||||
maxPrice: { quantity: maxPrice },
|
|
||||||
numProviders: numProviders,
|
|
||||||
bids: []
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
|
||||||
for (const bidderAccount of bidderAccounts) {
|
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidderAccount.bidAmount.toString(), TOKEN_TYPE, '--txKey', bidderAccount.privateKey]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
// Expected output
|
|
||||||
expect(outputObj.reveal_file).toBeDefined();
|
|
||||||
|
|
||||||
bidRevealFilePaths.push(outputObj.reveal_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedBids = bidderAccounts.map(account => ({
|
|
||||||
bidderAddress: account.address,
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
bidAmount: { quantity: 0 }
|
|
||||||
}));
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
winnerAddresses: [],
|
|
||||||
winnerBids: [],
|
|
||||||
bids: expectedBids
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
|
||||||
// Wait for auction commits duration (60s)
|
|
||||||
await delay(AUCTION_COMMIT_DURATION * 1000);
|
|
||||||
|
|
||||||
// Reveal bid
|
|
||||||
for (let i = 0; i < bidderAccounts.length; i++) {
|
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePaths[i], '--txKey', bidderAccounts[i].privateKey]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
// Expected output
|
|
||||||
expect(outputObj).toEqual({ success: true });
|
|
||||||
|
|
||||||
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePaths[i], 'utf8'));
|
|
||||||
expect(revealObject).toMatchObject({
|
|
||||||
chainId: CHAIN_ID,
|
|
||||||
auctionId: testAuctionId,
|
|
||||||
bidderAddress: bidderAccounts[i].address,
|
|
||||||
bidAmount: `${bidderAccounts[i].bidAmount}${TOKEN_TYPE}`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get auction with revealed bid
|
|
||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedBids = bidderAccounts.map(account => ({
|
|
||||||
bidderAddress: account.address,
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
bidAmount: { quantity: account.bidAmount }
|
|
||||||
}));
|
|
||||||
const expectedAuctionObjPartialOnBidReveal = {
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
winnerAddresses: [],
|
|
||||||
bids: expectedBids
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
|
||||||
}, (AUCTION_COMMIT_DURATION + 60) * 1000);
|
|
||||||
|
|
||||||
test('laconic registry auction get <auction_id>', async () => {
|
|
||||||
// Wait for auction reveals duration (60s)
|
|
||||||
await delay(AUCTION_REVEAL_DURATION * 1000);
|
|
||||||
|
|
||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedWinnerAddresses = winnerAccounts.map(account => account.address);
|
|
||||||
const expectedWinnerBids = winnerAccounts.map(account => ({ quantity: account.bidAmount }));
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.COMPLETED,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
winnerAddresses: expectedWinnerAddresses,
|
|
||||||
winnerBids: expectedWinnerBids,
|
|
||||||
winnerPrice: { quantity: winnerPrice },
|
|
||||||
fundsReleased: false
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
|
|
||||||
|
|
||||||
test('laconic registry auction release-funds <auction_id>', async () => {
|
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'release-funds', testAuctionId]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
expect(outputObj).toEqual({ success: true });
|
|
||||||
|
|
||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.COMPLETED,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
fundsReleased: true
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
|
|
||||||
const expectedBalances = [
|
|
||||||
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice,
|
|
||||||
bidderInitialBlanace - (commitFee) - (2 * txFees),
|
|
||||||
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let i = 0; i < bidderAccounts.length; i++) {
|
|
||||||
const result = spawnSync('laconic', ['registry', 'account', 'get', '--address', bidderAccounts[i].address]);
|
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
|
||||||
|
|
||||||
// Expected account
|
|
||||||
const expectedAccount = getAccountObj({ address: bidderAccounts[i].address, balance: expectedBalances[i] });
|
|
||||||
|
|
||||||
expect(outputObj.length).toEqual(1);
|
|
||||||
expect(outputObj[0]).toMatchObject(expectedAccount);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Gas and fees config', () => {
|
describe('Gas and fees config', () => {
|
||||||
const bondAmount = 1000;
|
const bondAmount = 1000;
|
||||||
|
|
||||||
|
@ -2,21 +2,11 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import { SpawnSyncReturns, spawnSync } from 'child_process';
|
import { SpawnSyncReturns, spawnSync } from 'child_process';
|
||||||
import { Arguments } from 'yargs';
|
|
||||||
|
|
||||||
import { StdFee } from '@cosmjs/stargate';
|
import { getConfig } from '../src/util';
|
||||||
|
|
||||||
import { getConfig, getGasAndFees } from '../src/util';
|
|
||||||
|
|
||||||
export const CHAIN_ID = 'laconic_9000-1';
|
export const CHAIN_ID = 'laconic_9000-1';
|
||||||
export const TOKEN_TYPE = 'alnt';
|
export const TOKEN_TYPE = 'alnt';
|
||||||
export const CONFIG_FILE = 'config.yml';
|
|
||||||
|
|
||||||
export enum AUCTION_STATUS {
|
|
||||||
COMMIT = 'commit',
|
|
||||||
REVEAL = 'reveal',
|
|
||||||
COMPLETED = 'completed'
|
|
||||||
}
|
|
||||||
|
|
||||||
export const AUCTION_FEES = {
|
export const AUCTION_FEES = {
|
||||||
commit: 1000000,
|
commit: 1000000,
|
||||||
@ -27,10 +17,6 @@ export const AUCTION_COMMIT_DURATION = 60; // 60s
|
|||||||
export const AUCTION_REVEAL_DURATION = 60; // 60s
|
export const AUCTION_REVEAL_DURATION = 60; // 60s
|
||||||
|
|
||||||
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
|
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
|
||||||
if (result.status !== 0) {
|
|
||||||
console.log('stderr', result.stderr.toString().trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(result.status).toBe(0);
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
const errorOutput = result.stderr.toString().trim();
|
const errorOutput = result.stderr.toString().trim();
|
||||||
@ -109,8 +95,7 @@ export function getAuctionObj (params: { owner: string, status?: string }): any
|
|||||||
type: TOKEN_TYPE,
|
type: TOKEN_TYPE,
|
||||||
quantity: AUCTION_FEES.minimumBid
|
quantity: AUCTION_FEES.minimumBid
|
||||||
},
|
},
|
||||||
winnerAddresses: [],
|
winnerAddress: ''
|
||||||
winnerBids: []
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,35 +122,30 @@ export async function delay (ms: number): Promise<any> {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFeesConfig (): number {
|
|
||||||
const { services: { registry: registryConfig } } = getConfig(CONFIG_FILE);
|
|
||||||
const fee = getGasAndFees({} as Arguments, registryConfig);
|
|
||||||
return Number((fee as StdFee).amount[0].amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateGasAndFeesConfig (gas?: string | null, fees?: string | null, gasPrice?: string | null): void {
|
export function updateGasAndFeesConfig (gas?: string | null, fees?: string | null, gasPrice?: string | null): void {
|
||||||
const config = getConfig(path.resolve(CONFIG_FILE));
|
const configFilePath = './config.yml';
|
||||||
|
const config = getConfig(path.resolve(configFilePath));
|
||||||
|
|
||||||
if (gas) {
|
if (gas != null) {
|
||||||
config.services.registry.gas = gas;
|
config.services.registry.gas = gas;
|
||||||
} else if (gas === null) {
|
} else if (gas === null) {
|
||||||
delete config.services.registry.gas;
|
delete config.services.registry.gas;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fees) {
|
if (fees != null) {
|
||||||
config.services.registry.fees = fees;
|
config.services.registry.fees = fees;
|
||||||
} else if (fees === null) {
|
} else if (fees === null) {
|
||||||
delete config.services.registry.fees;
|
delete config.services.registry.fees;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gasPrice) {
|
if (gasPrice != null) {
|
||||||
config.services.registry.gasPrice = gasPrice;
|
config.services.registry.gasPrice = gasPrice;
|
||||||
} else if (gasPrice === null) {
|
} else if (gasPrice === null) {
|
||||||
delete config.services.registry.gasPrice;
|
delete config.services.registry.gasPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(CONFIG_FILE, yaml.dump(config), 'utf8');
|
fs.writeFileSync(configFilePath, yaml.dump(config), 'utf8');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error writing config file:', e);
|
console.error('Error writing config file:', e);
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -302,10 +302,10 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@cerc-io/registry-sdk@^0.2.11":
|
"@cerc-io/registry-sdk@^0.2.6":
|
||||||
version "0.2.11"
|
version "0.2.6"
|
||||||
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.11/registry-sdk-0.2.11.tgz#019b792c68f440f2cfca5af2f49e1205bb33ba72"
|
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.6/registry-sdk-0.2.6.tgz#af8a5844bdb742a01d322a9d93ace90d35aad37e"
|
||||||
integrity sha512-IipqJzaBQEXMNH6yWFG2E/o0U6IAXw35PBMHx6QIboVu/sMNLIsWy1P8MmR8C8xYsmHOhgXLsC4hYSeFMXrqFw==
|
integrity sha512-Z2rneeoPLTJk9aBTqMrR9WPKfPQZhNWShI4IYOb7kzoIorp3eD8mEals0I5bVjzStjapw/5RKf8lVnDCX9I4iA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@cosmjs/amino" "^0.28.1"
|
"@cosmjs/amino" "^0.28.1"
|
||||||
"@cosmjs/crypto" "^0.28.1"
|
"@cosmjs/crypto" "^0.28.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user