Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try respect authz #6793

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}