Skip to content

Commit

Permalink
chore: disable relayer basic validation
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Jul 5, 2023
1 parent 857cf03 commit ef91bae
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 116 deletions.
1 change: 0 additions & 1 deletion modules/apps/101-interchain-swap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func (k Keeper) GetCounterPartyChainID(ctx sdk.Context, portID, channelID string
if err != nil {
return "", false
}

// Cast the client state to Tendermint type
tmClientState, ok := clientState.(*ibctmtypes.ClientState)
if !ok {
Expand Down
95 changes: 3 additions & 92 deletions modules/apps/101-interchain-swap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package keeper

import (
"github.com/btcsuite/btcutil/bech32"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsmod "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/sideprotocol/ibcswap/v6/modules/apps/101-interchain-swap/types"
)

Expand Down Expand Up @@ -112,12 +110,6 @@ func (k Keeper) OnMakeMultiAssetDepositAcknowledged(ctx sdk.Context, req *types.
return types.ErrNotFoundPool
}

// Mint voucher tokens for the sender
//err := k.MintTokens(ctx, sdk.MustAccAddressFromBech32(req.Deposits[0].Sender), *res.PoolTokens[0])
// if err != nil {
// return err
// }
// Save the updated liquidity pool
k.SetInterchainLiquidityPool(ctx, pool)
return nil
}
Expand All @@ -135,14 +127,6 @@ func (k Keeper) OnTakeMultiAssetDepositAcknowledged(ctx sdk.Context, req *types.
if !found {
return types.ErrNotFoundMultiDepositOrder
}

// Mint voucher tokens for the sender
//err := k.MintTokens(ctx, sdk.MustAccAddressFromBech32(order.DestinationTaker), *stateChange.PoolTokens[1])

// if err != nil {
// return err
// }

// Update pool supply and status
for _, poolToken := range stateChange.PoolTokens {
pool.AddPoolSupply(*poolToken)
Expand Down Expand Up @@ -214,11 +198,13 @@ func (k Keeper) OnSwapAcknowledged(ctx sdk.Context, req *types.MsgSwapRequest, r
return nil
}

// onReceive
func (k Keeper) OnMakePoolReceived(ctx sdk.Context, msg *types.MsgMakePoolRequest, poolID, sourceChainId string) (*string, error) {

if err := msg.ValidateBasic(); err != nil {
return nil, err
}

_, found := k.GetInterchainLiquidityPool(ctx, poolID)

if found {
Expand Down Expand Up @@ -254,11 +240,8 @@ func (k Keeper) OnMakePoolReceived(ctx sdk.Context, msg *types.MsgMakePoolReques
}

func (k Keeper) OnTakePoolReceived(ctx sdk.Context, msg *types.MsgTakePoolRequest) (*string, error) {
if err := msg.ValidateBasic(); err != nil {
return nil, err
}
pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolId)

pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolId)
if !found {
return nil, types.ErrNotFoundPool
}
Expand All @@ -284,10 +267,6 @@ func (k Keeper) OnTakePoolReceived(ctx sdk.Context, msg *types.MsgTakePoolReques

func (k Keeper) OnSingleAssetDepositReceived(ctx sdk.Context, msg *types.MsgSingleAssetDepositRequest, stateChange *types.StateChange) (*types.MsgSingleAssetDepositResponse, error) {

if err := msg.ValidateBasic(); err != nil {
return nil, err
}

pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolId)
if !found {
return nil, types.ErrNotFoundPool
Expand All @@ -306,11 +285,6 @@ func (k Keeper) OnSingleAssetDepositReceived(ctx sdk.Context, msg *types.MsgSing
// OnMultiAssetDepositReceived processes a double deposit request and returns a response or an error.
func (k Keeper) OnMakeMultiAssetDepositReceived(ctx sdk.Context, msg *types.MsgMakeMultiAssetDepositRequest, stateChange *types.StateChange) (*types.MsgMultiAssetDepositResponse, error) {

// Validate the message
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

// Verify the sender's address
senderAcc := k.authKeeper.GetAccount(ctx, sdk.MustAccAddressFromBech32(msg.Deposits[1].Sender))
senderPrefix, _, err := bech32.Decode(senderAcc.GetAddress().String())
Expand Down Expand Up @@ -396,11 +370,6 @@ func (k Keeper) OnTakeMultiAssetDepositReceived(ctx sdk.Context, msg *types.MsgT
// OnMultiAssetWithdrawReceived processes a withdrawal request and returns a response or an error.
func (k Keeper) OnMultiAssetWithdrawReceived(ctx sdk.Context, msg *types.MsgMultiAssetWithdrawRequest, stateChange *types.StateChange) (*types.MsgMultiAssetWithdrawResponse, error) {

// Validate the message
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

// Retrieve the liquidity pool
pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolToken.Denom)
if !found {
Expand Down Expand Up @@ -437,11 +406,6 @@ func (k Keeper) OnMultiAssetWithdrawReceived(ctx sdk.Context, msg *types.MsgMult
// OnSwapReceived processes a swap request and returns a response or an error.
func (k Keeper) OnSwapReceived(ctx sdk.Context, msg *types.MsgSwapRequest, stateChange *types.StateChange) (*types.MsgSwapResponse, error) {

// Validate the message
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolId)
if !found {
return nil, types.ErrNotFoundPool
Expand All @@ -462,56 +426,3 @@ func (k Keeper) OnSwapReceived(ctx sdk.Context, msg *types.MsgSwapRequest, state
Tokens: stateChange.Out,
}, nil
}

func (k Keeper) executeDepositTx(ctx sdk.Context, msg sdk.Msg) ([]byte, error) {

txMsgData := &sdk.TxMsgData{
MsgResponses: make([]*codectypes.Any, 1),
}

// CacheContext returns a new context with the multi-store branched into a cached storage object
// writeCache is called only if all msgs succeed, performing state transitions atomically
cacheCtx, writeCache := ctx.CacheContext()
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

any, err := k.executeMsg(cacheCtx, msg)
if err != nil {
return nil, err
}
writeCache()

txMsgData.MsgResponses[0] = any
txResponse, err := k.cdc.Marshal(txMsgData)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to marshal tx data")
}

return txResponse, nil
}

// Attempts to get the message handler from the router and if found will then execute the message.
// If the message execution is successful, the proto marshaled message response will be returned.
func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) {
handler := k.msgRouter.Handler(msg)
if handler == nil {
return nil, types.ErrInvalidMsgRouter
}

res, err := handler(ctx, msg)
if err != nil {
return nil, err
}

// NOTE: The sdk msg handler creates a new EventManager, so events must be correctly propagated back to the current context
ctx.EventManager().EmitEvents(res.GetEvents())

// Each individual sdk.Result has exactly one Msg response. We aggregate here.
msgResponse := res.MsgResponses[0]
if msgResponse == nil {
return nil, errorsmod.Wrapf(types.ErrInvalidMsg, "got nil Msg response for msg %s", sdk.MsgTypeURL(msg))
}

return msgResponse, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ func (k Keeper) MakeMultiAssetDeposit(ctx context.Context, msg *types.MsgMakeMul
return nil, errormod.Wrapf(types.ErrFailedMultiAssetDeposit, "%s", types.ErrNotFoundPool)
}

// // check asset owned status
// balance := k.bankKeeper.GetBalance(sdkCtx, sdk.MustAccAddressFromBech32(msg.Deposits[0].Sender), msg.Deposits[0].Balance.Denom)
// if balance.Amount.LT(msg.Deposits[0].Balance.Amount) {
// return nil, errormod.Wrapf(types.ErrFailedMultiAssetDeposit, "%s", types.ErrInEnoughAmount)
// }

// Check initial deposit condition
if pool.Status != types.PoolStatus_ACTIVE {
return nil, errormod.Wrapf(types.ErrFailedMultiAssetDeposit, "%s", types.ErrNotReadyForSwap)
Expand Down
8 changes: 6 additions & 2 deletions modules/apps/101-interchain-swap/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,12 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
if err := types.ModuleCdc.Unmarshal(data.Data, &msg); err != nil {
return err
}
//token = *msg.
//sender = msg.Sender
order, found := k.GetMultiDepositOrder(ctx, msg.PoolId, msg.OrderId)
if !found {
return types.ErrNotFoundMultiDepositOrder
}
token = *order.Deposits[1]
sender = msg.Sender
case types.MULTI_WITHDRAW:
var msg types.MsgMultiAssetWithdrawRequest
if err := types.ModuleCdc.Unmarshal(data.Data, &msg); err != nil {
Expand Down
1 change: 1 addition & 0 deletions modules/apps/101-interchain-swap/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ var (
ErrConnection = errorsmod.Register(ModuleName, 1563, "connection doesn't establish")
ErrAlreadyCompletedOrder = errorsmod.Register(ModuleName, 1564, "already completed order")
ErrNotEnoughPermission = errorsmod.Register(ModuleName, 1565, "not enough permission.")
ErrInvalidLiquidityPair = errorsmod.Register(ModuleName, 1566, "invalid liquidity pair")
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ func (msg *MsgMakeMultiAssetDepositRequest) GetSignBytes() []byte {
}

func (msg *MsgMakeMultiAssetDepositRequest) ValidateBasic() error {
if len(msg.Deposits) != 2 {
return ErrInvalidLiquidityPair
}
_, err := sdk.AccAddressFromBech32(msg.Deposits[0].Sender)
if err != nil {
return ErrInvalidAddress
}
// Check address
for _, deposit := range msg.Deposits {
_, err := sdk.AccAddressFromBech32(deposit.Sender)
if err != nil {
return ErrInvalidAddress
}
if deposit.Balance.Amount.Equal(sdk.NewInt(0)) {
return ErrInvalidAmount
}
Expand Down
4 changes: 0 additions & 4 deletions modules/apps/101-interchain-swap/types/message_make_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func (msg *MsgMakePoolRequest) ValidateBasic() error {
if err != nil {
return ErrInvalidAddress
}
_, err = sdk.AccAddressFromBech32(msg.CounterPartyCreator)
if err != nil {
return ErrInvalidAddress
}

tokenCount := len(msg.Liquidity)
// Validation message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ func (msg *MsgTakePoolRequest) ValidateBasic() error {
if err != nil {
return ErrInvalidAddress
}

return nil
}
6 changes: 0 additions & 6 deletions proto/ibc/applications/interchain_swap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ message MsgMultiAssetWithdrawRequest {
uint64 timeoutTimeStamp = 6;
}

message WithdrawAsset {
string receiver = 1;
cosmos.base.v1beta1.Coin balance = 2;
}


message MsgMultiAssetWithdrawResponse {
repeated cosmos.base.v1beta1.Coin tokens = 1;
}
Expand Down

0 comments on commit ef91bae

Please sign in to comment.