From 994a7abdd3be2fcfc951148d62b20e5f757edfcd Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Tue, 31 Oct 2023 18:50:25 +0100 Subject: [PATCH] Try respect authz --- x/txfees/keeper/txfee_filters/arb_tx.go | 60 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/x/txfees/keeper/txfee_filters/arb_tx.go b/x/txfees/keeper/txfee_filters/arb_tx.go index 1d1c8e7e17a..012d01c6344 100644 --- a/x/txfees/keeper/txfee_filters/arb_tx.go +++ b/x/txfees/keeper/txfee_filters/arb_tx.go @@ -1,6 +1,8 @@ package txfee_filters import ( + authztypes "github.com/cosmos/cosmos-sdk/x/authz" + gammtypes "github.com/osmosis-labs/osmosis/v20/x/gamm/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types" @@ -23,33 +25,53 @@ func IsArbTxLoose(tx sdk.Tx) bool { swapInDenom := "" lpTypesSeen := make(map[gammtypes.LiquidityChangeType]bool, 2) + isArb := false for _, m := range msgs { - // (4) Check that the tx doesn't have both JoinPool & ExitPool msgs - lpMsg, isLpMsg := m.(gammtypes.LiquidityChangeMsg) - if isLpMsg { - lpTypesSeen[lpMsg.LiquidityChangeType()] = true - if len(lpTypesSeen) > 1 { - return true - } + swapInDenom, isArb = isArbTxLooseAuthz(m, swapInDenom, lpTypesSeen) + if isArb { + return true } + } - swapMsg, isSwapMsg := m.(poolmanagertypes.SwapMsgRoute) - if !isSwapMsg { - continue - } + return false +} - // (1) Check that swap denom in != swap denom out - if swapMsg.TokenInDenom() == swapMsg.TokenOutDenom() { - return true +func isArbTxLooseAuthz(msg sdk.Msg, swapInDenom string, lpTypesSeen map[gammtypes.LiquidityChangeType]bool) (string, bool) { + if authzMsg, ok := msg.(*authztypes.MsgExec); ok { + msgs, _ := authzMsg.GetMessages() + for _, m := range msgs { + swapInDenom, isAuthz := isArbTxLooseAuthz(m, swapInDenom, lpTypesSeen) + if isAuthz { + return swapInDenom, true + } } + return swapInDenom, false + } - // (2) - if swapInDenom != "" && swapMsg.TokenInDenom() != swapInDenom { - return true + // (4) Check that the tx doesn't have both JoinPool & ExitPool msgs + lpMsg, isLpMsg := msg.(gammtypes.LiquidityChangeMsg) + if isLpMsg { + lpTypesSeen[lpMsg.LiquidityChangeType()] = true + if len(lpTypesSeen) > 1 { + return swapInDenom, true } - swapInDenom = swapMsg.TokenInDenom() } - return false + swapMsg, isSwapMsg := msg.(poolmanagertypes.SwapMsgRoute) + if !isSwapMsg { + return swapInDenom, false + } + + // (1) Check that swap denom in != swap denom out + if swapMsg.TokenInDenom() == swapMsg.TokenOutDenom() { + return swapInDenom, true + } + + // (2) + if swapInDenom != "" && swapMsg.TokenInDenom() != swapInDenom { + return swapInDenom, true + } + swapInDenom = swapMsg.TokenInDenom() + return swapInDenom, false }