Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions proto/dex/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ service Query {
}
// Queries a LongBook by id.
rpc LongBook(QueryGetLongBookRequest) returns (QueryGetLongBookResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/long_book/{contractAddr}/{priceDenom}/{assetDenom}";
option (google.api.http).get = "/sei-protocol/seichain/dex/long_book/{contractAddr}/{priceDenom}/{assetDenom}/{price}";
}

// Queries a list of LongBook items.
rpc LongBookAll(QueryAllLongBookRequest) returns (QueryAllLongBookResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/long_book";
option (google.api.http).get = "/sei-protocol/seichain/dex/long_book/{contractAddr}/{priceDenom}/{assetDenom}";
}

// Queries a ShortBook by id.
rpc ShortBook(QueryGetShortBookRequest) returns (QueryGetShortBookResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/short_book/{contractAddr}/{priceDenom}/{assetDenom}";
option (google.api.http).get = "/sei-protocol/seichain/dex/short_book/{contractAddr}/{priceDenom}/{assetDenom}/{price}";
}

// Queries a list of ShortBook items.
rpc ShortBookAll(QueryAllShortBookRequest) returns (QueryAllShortBookResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/short_book";
option (google.api.http).get = "/sei-protocol/seichain/dex/short_book/{contractAddr}/{priceDenom}/{assetDenom}";
}

rpc SettlementsAll(QueryAllSettlementsRequest) returns (QueryAllSettlementsResponse) {
Expand All @@ -62,11 +62,7 @@ message QueryParamsResponse {
}

message QueryGetLongBookRequest {
string price = 1 [
(gogoproto.moretags) = "yaml:\"price\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string price = 1;
string contractAddr = 2;
Denom priceDenom = 3;
Denom assetDenom = 4;
Expand All @@ -89,11 +85,7 @@ message QueryAllLongBookResponse {
}

message QueryGetShortBookRequest {
string price = 1 [
(gogoproto.moretags) = "yaml:\"price\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string price = 1;
string contractAddr = 2;
Denom priceDenom = 3;
Denom assetDenom = 4;
Expand Down
24 changes: 12 additions & 12 deletions scripts/populate_mock_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ echo
echo -n Key Name:
read keyname
echo
echo -n Price denominator {e.g. ust}:
echo -n Price denominator {e.g. sei}:
read pdenom
echo
echo -n Asset denominator {e.g. luna}:
echo -n Asset denominator {e.g. atom}:
read adenom
echo

$sei tx wasm store $contract -y --from=$keyname --chain-id=sei-chain --gas=3000000 --fees=1000ust --broadcast-mode=block
$sei tx wasm store $contract -y --from=$keyname --chain-id=sei-chain --gas=3000000 --fees=100000usei --broadcast-mode=block

addr=$($sei tx wasm instantiate 1 '{}' -y --no-admin --from=$keyname --chain-id=sei-chain --gas=1500000 --fees=1000ust --broadcast-mode=block --label=dex | grep -A 1 "key: _contract_address" | sed -n 's/.*value: //p' | xargs)
addr=$($sei tx wasm instantiate 1 '{}' -y --no-admin --from=$keyname --chain-id=sei-chain --gas=1500000 --fees=100000usei --broadcast-mode=block --label=dex | grep -A 1 "key: _contract_address" | sed -n 's/.*value: //p' | xargs)

$sei tx dex register-contract $addr 1 -y --from=$keyname --chain-id=sei-chain --fees=10000000ust --gas=500000 --broadcast-mode=block
$sei tx dex register-pair $addr $pdenom $adenom -y --from=$keyname --chain-id=sei-chain --fees=10000000ust --gas=500000 --broadcast-mode=block
$sei tx dex register-contract $addr 1 -y --from=$keyname --chain-id=sei-chain --fees=10000000usei --gas=500000 --broadcast-mode=block
$sei tx dex register-pair $addr $pdenom $adenom -y --from=$keyname --chain-id=sei-chain --fees=10000000usei --gas=500000 --broadcast-mode=block

$sei tx dex place-orders $addr 0 Long,101,5,$pdenom,$adenom,Open,Limit,1 --amount=100000ust -y --from=ta0 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr 0 Short,99,5,$pdenom,$adenom,Open,Limit,2 --amount=100000ust -y --from=ta1 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr 0 Long,99,5,$pdenom,$adenom,Open,Limit,1 --amount=100000ust -y --from=ta0 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr 0 Short,101,5,$pdenom,$adenom,Open,Limit,2 --amount=100000ust -y --from=ta1 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr 0 Long,98,3,$pdenom,$adenom,Open,Limit,1 --amount=100000ust -y --from=ta1 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr 0 Short,102,3,$pdenom,$adenom,Open,Limit,2 --amount=100000ust -y --from=ta0 --chain-id=sei-chain --fees=1000000ust --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Long,1.01,5,$pdenom,$adenom,Open,Limit,1 --amount=10000000usei -y --from=ta0 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Short,0.99,5,$pdenom,$adenom,Open,Limit,2 --amount=10000000usei -y --from=ta1 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Long,0.99,5,$pdenom,$adenom,Open,Limit,1 --amount=10000000usei -y --from=ta0 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Short,1.01,5,$pdenom,$adenom,Open,Limit,2 --amount=10000000usei -y --from=ta1 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Long,0.98,3,$pdenom,$adenom,Open,Limit,1 --amount=10000000usei -y --from=ta1 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
$sei tx dex place-orders $addr Short,1.02,3,$pdenom,$adenom,Open,Limit,2 --amount=10000000usei -y --from=ta0 --chain-id=sei-chain --fees=1000000usei --gas=50000000 --broadcast-mode=block
7 changes: 1 addition & 6 deletions x/dex/client/cli/query_long_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -73,10 +72,6 @@ func CmdShowLongBook() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)
contractAddr := args[0]
price, err := sdk.NewDecFromStr(args[1])
if err != nil {
return err
}
reqPriceDenom, unit, err := types.GetDenomFromStr(args[2])
if err != nil {
return err
Expand All @@ -93,7 +88,7 @@ func CmdShowLongBook() *cobra.Command {
}

params := &types.QueryGetLongBookRequest{
Price: price,
Price: args[1],
ContractAddr: contractAddr,
PriceDenom: reqPriceDenom,
AssetDenom: reqAssetDenom,
Expand Down
7 changes: 1 addition & 6 deletions x/dex/client/cli/query_short_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -74,10 +73,6 @@ func CmdShowShortBook() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)

contractAddr := args[0]
price, err := sdk.NewDecFromStr(args[1])
if err != nil {
return err
}
reqPriceDenom, unit, err := types.GetDenomFromStr(args[2])
if err != nil {
return err
Expand All @@ -94,7 +89,7 @@ func CmdShowShortBook() *cobra.Command {
}

params := &types.QueryGetShortBookRequest{
Price: price,
Price: args[1],
ContractAddr: contractAddr,
PriceDenom: reqPriceDenom,
AssetDenom: reqAssetDenom,
Expand Down
6 changes: 5 additions & 1 deletion x/dex/keeper/grpc_query_long_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func (k Keeper) LongBook(c context.Context, req *types.QueryGetLongBookRequest)
}

ctx := sdk.UnwrapSDKContext(c)
longBook, found := k.GetLongBookByPrice(ctx, req.ContractAddr, req.Price, req.PriceDenom, req.AssetDenom)
price, err := sdk.NewDecFromStr(req.Price)
if err != nil {
return nil, err
}
longBook, found := k.GetLongBookByPrice(ctx, req.ContractAddr, price, req.PriceDenom, req.AssetDenom)
if !found {
return nil, sdkerrors.ErrKeyNotFound
}
Expand Down
6 changes: 3 additions & 3 deletions x/dex/keeper/grpc_query_long_book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func TestLongBookQuerySingle(t *testing.T) {
}{
{
desc: "First",
request: &types.QueryGetLongBookRequest{Price: msgs[0].Price, ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetLongBookRequest{Price: msgs[0].Price.String(), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
response: &types.QueryGetLongBookResponse{LongBook: msgs[0]},
},
{
desc: "Second",
request: &types.QueryGetLongBookRequest{Price: msgs[1].Price, ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetLongBookRequest{Price: msgs[1].Price.String(), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
response: &types.QueryGetLongBookResponse{LongBook: msgs[1]},
},
{
desc: "KeyNotFound",
request: &types.QueryGetLongBookRequest{Price: sdk.NewDec(100000), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetLongBookRequest{Price: "100000", ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
err: sdkerrors.ErrKeyNotFound,
},
{
Expand Down
6 changes: 5 additions & 1 deletion x/dex/keeper/grpc_query_short_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func (k Keeper) ShortBook(c context.Context, req *types.QueryGetShortBookRequest
}

ctx := sdk.UnwrapSDKContext(c)
shortBook, found := k.GetShortBookByPrice(ctx, req.ContractAddr, req.Price, req.PriceDenom, req.AssetDenom)
price, err := sdk.NewDecFromStr(req.Price)
if err != nil {
return nil, err
}
shortBook, found := k.GetShortBookByPrice(ctx, req.ContractAddr, price, req.PriceDenom, req.AssetDenom)
if !found {
return nil, sdkerrors.ErrKeyNotFound
}
Expand Down
6 changes: 3 additions & 3 deletions x/dex/keeper/grpc_query_short_book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func TestShortBookQuerySingle(t *testing.T) {
}{
{
desc: "First",
request: &types.QueryGetShortBookRequest{Price: msgs[0].Price, ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetShortBookRequest{Price: msgs[0].Price.String(), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
response: &types.QueryGetShortBookResponse{ShortBook: msgs[0]},
},
{
desc: "Second",
request: &types.QueryGetShortBookRequest{Price: msgs[1].Price, ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetShortBookRequest{Price: msgs[1].Price.String(), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
response: &types.QueryGetShortBookResponse{ShortBook: msgs[1]},
},
{
desc: "KeyNotFound",
request: &types.QueryGetShortBookRequest{Price: sdk.NewDec(10000), ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
request: &types.QueryGetShortBookRequest{Price: "10000", ContractAddr: TEST_CONTRACT, PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM},
err: sdkerrors.ErrKeyNotFound,
},
{
Expand Down
2 changes: 1 addition & 1 deletion x/dex/types/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func GetDenomFromStr(str string) (Denom, Unit, error) {
val, err := getEnumFromStr(str, Denom_value)
if err != nil {
if str[0] == MICRO_PREFIX {
microVal, microErr := getEnumFromStr(str, Denom_value)
microVal, microErr := getEnumFromStr(str[1:], Denom_value)
if microErr == nil {
return Denom(microVal), Unit_MICRO, nil
}
Expand Down
Loading