Skip to content

Commit

Permalink
Try respect authz (#6793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Nov 10, 2023
1 parent 6b47b73 commit e607673
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions x/txfees/keeper/txfee_filters/arb_tx.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
}

0 comments on commit e607673

Please sign in to comment.