Skip to content

Commit

Permalink
Add query a pool endpoint through poolCoin or reserveAcc (#390)
Browse files Browse the repository at this point in the history
* WIP Add pool query endpoints

* Add endpoint functionality for query pool by pool coin denom

* fix for #391

* change endpoint of pool query by pool_coin_denom

* add endpoint for query pool by reserve_acc

* CLI denomination and reserve acc queries added

* Add flags for query pool by pool-coin-denom or reserve-acc

* Add testcase, docs for new endpoint

* Fix typo and resolve lint issue

Co-authored-by: lukerhoads <[email protected]>
  • Loading branch information
dongsam and lukerhoads authored Jun 9, 2021
1 parent e8ab2f4 commit 874e382
Show file tree
Hide file tree
Showing 18 changed files with 1,403 additions and 158 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For detailed Mechanism, you can find on our recent [Paper](doc/LiquidityModuleLi
| Requirement | Notes |
| ----------- | ---------------- |
| Go version | Go1.15 or higher |
| Cosmos-SDK | v0.42.4 |
| Cosmos-SDK | v0.42.5 |

### Get Liquidity Module source code

Expand Down
2 changes: 1 addition & 1 deletion client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Cosmos SDK Liquidity Module - REST and gRPC Gateway docs",
"description": "A REST interface for state queries, transactions",
"version": "2.2.1"
"version": "2.2.2"
},
"apis": [
{
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

202 changes: 201 additions & 1 deletion client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swagger: '2.0'
info:
title: Cosmos SDK Liquidity Module - REST and gRPC Gateway docs
description: 'A REST interface for state queries, transactions'
version: 2.2.1
version: 2.2.2
paths:
/tendermint/liquidity/v1beta1/params:
get:
Expand Down Expand Up @@ -318,6 +318,206 @@ paths:
externalDocs:
description: Find out more about the query and error codes
url: 'https://github.com/tendermint/liquidity/blob/develop/doc/client.md'
'/tendermint/liquidity/v1beta1/pools/pool_coin_denom/{pool_coin_denom}':
get:
summary: Get specific liquidity pool corresponding to the pool_coin_denom.
description: It returns the liquidity pool corresponding to the pool_coin_denom.
operationId: LiquidityPoolByPoolCoinDenom
responses:
'200':
description: A successful response.
schema:
type: object
properties:
pool:
type: object
properties:
id:
type: string
format: uint64
example: '1'
title: id of the pool
type_id:
type: integer
format: uint32
example: '1'
title: id of the pool_type
reserve_coin_denoms:
type: array
example:
- denomX
- denomY
items:
type: string
title: denoms of reserve coin pair of the pool
reserve_account_address:
type: string
format: sdk.AccAddress
example: cosmos16ddqestwukv0jzcyfn3fdfq9h2wrs83cr4rfm3
title: reserve account address of the pool
pool_coin_denom:
type: string
example: >-
poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4
title: denom of pool coin of the pool
title: The liquidity pool information
description: >-
the response type for the QueryLiquidityPoolResponse RPC method.
It returns the liquidity pool corresponding to the requested
pool_id.
'404':
description: Not Found
schema: {}
examples:
application/json:
code: 5
message: >-
rpc error: code = NotFound desc = liquidity pool with pool coin
denom xx doesn't exist: key not found
details: []
'500':
description: Internal Server Error
schema: {}
examples:
application/json:
code: 2
message: >-
rpc error: code = NotFound desc = the liquidity pool
corresponding to the pool_coin_denom doesn't exist: key not
found
details: []
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: pool_coin_denom
in: path
required: true
type: string
tags:
- Query
externalDocs:
description: Find out more about the query and error codes
url: 'https://github.com/tendermint/liquidity/blob/develop/doc/client.md'
'/tendermint/liquidity/v1beta1/pools/reserve_acc/{reserve_acc}':
get:
summary: Get specific liquidity pool corresponding to the reserve account.
description: It returns the liquidity pool corresponding to the reserve account.
operationId: LiquidityPoolByReserveAcc
responses:
'200':
description: A successful response.
schema:
type: object
properties:
pool:
type: object
properties:
id:
type: string
format: uint64
example: '1'
title: id of the pool
type_id:
type: integer
format: uint32
example: '1'
title: id of the pool_type
reserve_coin_denoms:
type: array
example:
- denomX
- denomY
items:
type: string
title: denoms of reserve coin pair of the pool
reserve_account_address:
type: string
format: sdk.AccAddress
example: cosmos16ddqestwukv0jzcyfn3fdfq9h2wrs83cr4rfm3
title: reserve account address of the pool
pool_coin_denom:
type: string
example: >-
poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4
title: denom of pool coin of the pool
title: The liquidity pool information
description: >-
the response type for the QueryLiquidityPoolResponse RPC method.
It returns the liquidity pool corresponding to the requested
pool_id.
'404':
description: Not Found
schema: {}
examples:
application/json:
code: 5
message: >-
rpc error: code = NotFound desc = the reserve account address xx
is not valid: key not found
details: []
'500':
description: Internal Server Error
schema: {}
examples:
application/json:
code: 2
message: >-
rpc error: code = NotFound desc = the liquidity pool
corresponding to the reserve account doesn't exist: key not
found
details: []
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: reserve_acc
in: path
required: true
type: string
tags:
- Query
externalDocs:
description: Find out more about the query and error codes
url: 'https://github.com/tendermint/liquidity/blob/develop/doc/client.md'
'/tendermint/liquidity/v1beta1/pools/{pool_id}':
get:
summary: Get specific liquidity pool.
Expand Down
40 changes: 39 additions & 1 deletion doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ withdraw_fee_rate: "0.003000000000000000"

## Pool

Example `pool` query command:
Example `pool` query command using `pool-id` argument:

```bash
$ liquidityd query liquidity pool 1
Expand All @@ -687,6 +687,44 @@ pool:
type_id: 1
```

Example `pool` query command using `--pool-coin-denom` flag:

```bash
$ liquidityd query liquidity pool --pool-coin-denom=pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295
```

Result:

```json
pool:
id: "1"
pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295
reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we
reserve_coin_denoms:
- uatom
- uusd
type_id: 1
```

Example `pool` query command using `--reserve-acc` flag:

```bash
$ liquidityd query liquidity pool --reserve-acc=cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we
```

Result:

```json
pool:
id: "1"
pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295
reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we
reserve_coin_denoms:
- uatom
- uusd
type_id: 1
```

Query reserve coins of the pool:

```bash
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/tendermint/tendermint v0.34.10
Expand Down
75 changes: 75 additions & 0 deletions proto/tendermint/liquidity/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,71 @@ service Query {
};
}

// Get specific liquidity pool corresponding to the pool_coin_denom.
rpc LiquidityPoolByPoolCoinDenom (QueryLiquidityPoolByPoolCoinDenomRequest) returns (QueryLiquidityPoolResponse) {
option (google.api.http).get = "/tendermint/liquidity/v1beta1/pools/pool_coin_denom/{pool_coin_denom}";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
description: "It returns the liquidity pool corresponding to the pool_coin_denom.";
external_docs: {
url: "https://github.com/tendermint/liquidity/blob/develop/doc/client.md";
description: "Find out more about the query and error codes";
}
responses: {
key: "500"
value: {
description: "Internal Server Error"
examples: {
key: "application/json"
value: '{"code":2,"message":"rpc error: code = NotFound desc = the liquidity pool corresponding to the pool_coin_denom doesn\'t exist: key not found","details":[]}'
}
}
}
responses: {
key: "404"
value: {
description: "Not Found"
examples: {
key: "application/json"
value: '{"code":5,"message":"rpc error: code = NotFound desc = liquidity pool with pool coin denom xx doesn\'t exist: key not found","details":[]}'
}
}
}
};
}


// Get specific liquidity pool corresponding to the reserve account.
rpc LiquidityPoolByReserveAcc (QueryLiquidityPoolByReserveAccRequest) returns (QueryLiquidityPoolResponse) {
option (google.api.http).get = "/tendermint/liquidity/v1beta1/pools/reserve_acc/{reserve_acc}";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
description: "It returns the liquidity pool corresponding to the reserve account.";
external_docs: {
url: "https://github.com/tendermint/liquidity/blob/develop/doc/client.md";
description: "Find out more about the query and error codes";
}
responses: {
key: "500"
value: {
description: "Internal Server Error"
examples: {
key: "application/json"
value: '{"code":2,"message":"rpc error: code = NotFound desc = the liquidity pool corresponding to the reserve account doesn\'t exist: key not found","details":[]}'
}
}
}
responses: {
key: "404"
value: {
description: "Not Found"
examples: {
key: "application/json"
value: '{"code":5,"message":"rpc error: code = NotFound desc = the reserve account address xx is not valid: key not found","details":[]}'
}
}
}
};
}

// Get the pool's current batch.
rpc LiquidityPoolBatch (QueryLiquidityPoolBatchRequest) returns (QueryLiquidityPoolBatchResponse) {
option (google.api.http).get = "/tendermint/liquidity/v1beta1/pools/{pool_id}/batch";
Expand Down Expand Up @@ -314,6 +379,16 @@ message QueryLiquidityPoolResponse {
Pool pool = 1 [(gogoproto.nullable) = false];
}

// the request type for the QueryLiquidityByPoolCoinDenomPool RPC method. requestable specified pool_coin_denom.
message QueryLiquidityPoolByPoolCoinDenomRequest {
string pool_coin_denom = 1;
}

// the request type for the QueryLiquidityByReserveAcc RPC method. requestable specified reserve_acc.
message QueryLiquidityPoolByReserveAccRequest {
string reserve_acc = 1;
}

// the request type for the QueryLiquidityPoolBatch RPC method. requestable including specified pool_id.
message QueryLiquidityPoolBatchRequest {
// id of the target pool for query
Expand Down
Loading

0 comments on commit 874e382

Please sign in to comment.