-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
908 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"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" | ||
) | ||
|
||
func CmdGetOrderCount() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get-order-count [contract] [price denom] [asset denom] [LONG|SHORT] [price]", | ||
Short: "get number of orders at a price leve", | ||
Args: cobra.ExactArgs(5), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
var direction types.PositionDirection | ||
switch args[3] { | ||
case "LONG": | ||
direction = types.PositionDirection_LONG | ||
case "SHORT": | ||
direction = types.PositionDirection_SHORT | ||
default: | ||
return fmt.Errorf("unknown direction %s", args[3]) | ||
} | ||
price := sdk.MustNewDecFromStr(args[4]) | ||
res, err := queryClient.GetOrderCount(context.Background(), &types.QueryGetOrderCountRequest{ | ||
ContractAddr: args[0], | ||
PriceDenom: args[1], | ||
AssetDenom: args[2], | ||
PositionDirection: direction, | ||
Price: &price, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k KeeperWrapper) GetOrderCount(c context.Context, req *types.QueryGetOrderCountRequest) (*types.QueryGetOrderCountResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
return &types.QueryGetOrderCountResponse{Count: k.GetOrderCountState(ctx, req.ContractAddr, req.PriceDenom, req.AssetDenom, req.PositionDirection, *req.Price)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package query_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" | ||
"github.com/sei-protocol/sei-chain/x/dex/keeper/query" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetOrderCount(t *testing.T) { | ||
keeper, ctx := keepertest.DexKeeper(t) | ||
wrapper := query.KeeperWrapper{Keeper: keeper} | ||
wctx := sdk.WrapSDKContext(ctx) | ||
keeper.SetOrderCount(ctx, keepertest.TestContract, keepertest.TestPair.PriceDenom, keepertest.TestPair.AssetDenom, types.PositionDirection_LONG, sdk.NewDec(1), 5) | ||
price := sdk.NewDec(1) | ||
query := types.QueryGetOrderCountRequest{ | ||
ContractAddr: keepertest.TestContract, | ||
PriceDenom: keepertest.TestPriceDenom, | ||
AssetDenom: keepertest.TestAssetDenom, | ||
PositionDirection: types.PositionDirection_LONG, | ||
Price: &price, | ||
} | ||
resp, err := wrapper.GetOrderCount(wctx, &query) | ||
require.Nil(t, err) | ||
require.Equal(t, uint64(5), resp.Count) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package migrations | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sei-protocol/sei-chain/x/dex/keeper" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
) | ||
|
||
func V14ToV15(ctx sdk.Context, dexkeeper keeper.Keeper) error { | ||
// This isn't the cleanest migration since it could potentially revert any dex params we have changed | ||
// but we haven't, so we'll just do this. | ||
defaultParams := types.DefaultParams() | ||
dexkeeper.SetParams(ctx, defaultParams) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package migrations_test | ||
|
||
import ( | ||
"testing" | ||
|
||
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" | ||
"github.com/sei-protocol/sei-chain/x/dex/migrations" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMigrate14to15(t *testing.T) { | ||
dexkeeper, ctx := keepertest.DexKeeper(t) | ||
// write old params | ||
prevParams := types.Params{} | ||
dexkeeper.SetParams(ctx, prevParams) | ||
|
||
// migrate to default params | ||
err := migrations.V14ToV15(ctx, *dexkeeper) | ||
require.NoError(t, err) | ||
params := dexkeeper.GetParams(ctx) | ||
require.Equal(t, params.MaxOrderPerPrice, uint64(types.DefaultMaxOrderPerPrice)) | ||
require.Equal(t, params.MaxPairsPerContract, uint64(types.DefaultMaxPairsPerContract)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.