Skip to content

Commit

Permalink
Add migration to unwind dex state (sei-protocol#1734)
Browse files Browse the repository at this point in the history
* Add migration to unwind dex state

* Update message handler

* Update tests
  • Loading branch information
udpatil authored Jun 20, 2024
1 parent 08204c6 commit 3b8b27c
Show file tree
Hide file tree
Showing 28 changed files with 151 additions and 2,685 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ jobs:
matrix:
test: [
{
name: "Dex & Wasm Module",
name: "Wasm Module",
scripts: [
"docker exec sei-node-0 integration_test/contracts/deploy_dex_contract.sh mars",
"python3 integration_test/scripts/runner.py integration_test/dex_module/place_order_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/dex_module/cancel_order_test.yaml",
"docker exec sei-node-0 integration_test/contracts/deploy_timelocked_token_contract.sh",
"python3 integration_test/scripts/runner.py integration_test/wasm_module/timelocked_token_delegation_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/wasm_module/timelocked_token_admin_test.yaml",
Expand Down
9 changes: 5 additions & 4 deletions aclmapping/dex/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
"github.com/k0kubun/pp/v3"
dexacl "github.com/sei-protocol/sei-chain/aclmapping/dex"
Expand Down Expand Up @@ -135,13 +136,13 @@ func (suite *KeeperTestSuite) TestMsgPlaceOrder() {
{
name: "default place order",
msg: suite.msgPlaceOrders,
expectedError: nil,
expectedError: sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "deprecated"),
dynamicDep: true,
},
{
name: "dont check synchronous",
msg: suite.msgPlaceOrders,
expectedError: nil,
expectedError: sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "deprecated"),
dynamicDep: false,
},
}
Expand Down Expand Up @@ -191,13 +192,13 @@ func (suite *KeeperTestSuite) TestMsgCancelOrder() {
{
name: "default cancel order",
msg: suite.msgCancelOrders,
expectedError: nil,
expectedError: sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "deprecated"),
dynamicDep: true,
},
{
name: "dont check synchronous",
msg: suite.msgCancelOrders,
expectedError: nil,
expectedError: sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "deprecated"),
dynamicDep: false,
},
}
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ var (
oracletypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
dexmoduletypes.ModuleName: nil,
dexmoduletypes.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
Expand Down
1 change: 1 addition & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var upgradesList = []string{
"v5.5.1",
"v5.5.2",
"v5.5.5",
"v5.6.0",
}

// if there is an override list, use that instead, for integration tests
Expand Down
210 changes: 0 additions & 210 deletions tests/dex_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/dex/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ func (k *Keeper) SetWasmKeeper(wasmKeeper *wasm.Keeper) {
}

func (k Keeper) CreateModuleAccount(ctx sdk.Context) {
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName)
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Burner)
k.AccountKeeper.SetModuleAccount(ctx, moduleAcc)
}
52 changes: 2 additions & 50 deletions x/dex/keeper/msgserver/msg_server_cancel_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,11 @@ package msgserver

import (
"context"
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/sei-protocol/sei-chain/x/dex/utils"
)

func (k msgServer) CancelOrders(goCtx context.Context, msg *types.MsgCancelOrders) (*types.MsgCancelOrdersResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if err := msg.ValidateBasic(); err != nil {
ctx.Logger().Error(fmt.Sprintf("request invalid: %s", err))
return nil, err
}

events := []sdk.Event{}
for _, cancellation := range msg.GetCancellations() {
var allocation *types.Allocation
var found bool
if cancellation.PositionDirection == types.PositionDirection_LONG {
allocation, found = k.GetLongAllocationForOrderID(ctx, msg.ContractAddr, cancellation.PriceDenom, cancellation.AssetDenom, cancellation.Price, cancellation.Id)
} else {
allocation, found = k.GetShortAllocationForOrderID(ctx, msg.ContractAddr, cancellation.PriceDenom, cancellation.AssetDenom, cancellation.Price, cancellation.Id)
}
if !found {
continue
}
if allocation.Account != msg.Creator {
return nil, errors.New("cannot cancel orders created by others")
}
pair := types.Pair{PriceDenom: cancellation.PriceDenom, AssetDenom: cancellation.AssetDenom}
pairBlockCancellations := utils.GetMemState(ctx.Context()).GetBlockCancels(ctx, types.ContractAddress(msg.GetContractAddr()), pair)
if !pairBlockCancellations.Has(cancellation) {
// only cancel if it's not cancelled in a previous tx in the same block
cancel := types.Cancellation{
Id: cancellation.Id,
Initiator: types.CancellationInitiator_USER,
Creator: msg.Creator,
ContractAddr: msg.ContractAddr,
Price: cancellation.Price,
AssetDenom: cancellation.AssetDenom,
PriceDenom: cancellation.PriceDenom,
PositionDirection: cancellation.PositionDirection,
}
pairBlockCancellations.Add(&cancel)
events = append(events, sdk.NewEvent(
types.EventTypeCancelOrder,
sdk.NewAttribute(types.AttributeKeyCancellationID, fmt.Sprint(cancellation.Id)),
))
}
}
ctx.EventManager().EmitEvents(events)
utils.GetMemState(ctx.Context()).SetDownstreamsToProcess(ctx, msg.ContractAddr, k.GetContractWithoutGasCharge)
return &types.MsgCancelOrdersResponse{}, nil
return nil, sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "deprecated")
}
Loading

0 comments on commit 3b8b27c

Please sign in to comment.