Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Dec 26, 2023
1 parent d22d908 commit 07b406e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/x/txfees",
"program": "${workspaceFolder}/x/txfees/keeper/txfee_filters",
"args": [
"-test.timeout",
"30m",
"-test.run",
"TestKeeperTestSuite/TestYourName",
"TestTxFeeFilter/TestIsArbTxLooseAuthz_SwapMsg",
"-test.v"
],
},
Expand Down
58 changes: 58 additions & 0 deletions x/txfees/keeper/txfee_filters/arb_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ type AffiliateSwapMsg struct {
Swap `json:"swap"`
}

type InputCoin struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}

type Slippage struct {
MinOutputAmount string `json:"min_output_amount"`
}

type ContractSwap struct {
InputCoin InputCoin `json:"input_coin"`
OutputDenom string `json:"output_denom"`
Slippage Slippage `json:"slippage"`
}

type ContractSwapMsg struct {
ContractSwap `json:"swap"`
}

// TokenDenomsOnPath implements types.SwapMsgRoute.
func (m AffiliateSwapMsg) TokenDenomsOnPath() []string {
denoms := make([]string, 0, len(m.Routes)+1)
Expand Down Expand Up @@ -108,6 +127,15 @@ func isArbTxLooseAuthz(msg sdk.Msg, swapInDenom string, lpTypesSeen map[gammtype

// Check that the contract message is an affiliate swap message
if ok := isAffiliateSwapMsg(contractMessage); !ok {

if ok := isSwapContractMsg(contractMessage); !ok {
return swapInDenom, false
}

return swapInDenom, false
}

if ok := isSwapContractMsg(contractMessage); !ok {
return swapInDenom, false
}

Expand Down Expand Up @@ -195,3 +223,33 @@ func isAffiliateSwapMsg(msg []byte) bool {

return true
}

type Coin struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}

func isSwapContractMsg(msg []byte) bool {
// Check that the contract message is a valid JSON object
jsonObject := make(map[string]interface{})
err := json.Unmarshal(msg, &jsonObject)
if err != nil {
return false
}

// check the main key is "swap"
swap, ok := jsonObject["swap"].(map[string]interface{})
if !ok {
return false
}

if routes, ok := swap["input_coin"].([]interface{}); !ok || len(routes) == 0 {
return false
}

if tokenOutMinAmount, ok := swap["output_denom"].(map[string]interface{}); !ok || len(tokenOutMinAmount) == 0 {
return false
}

return true
}
30 changes: 30 additions & 0 deletions x/txfees/keeper/txfee_filters/arb_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_AffiliateSwapMsg() {
suite.Require().True(isArb)
}

// Tests that the arb filter is enabled on swap msg.
func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_SwapMsg() {
contractSwapMsg := &txfee_filters.ContractSwapMsg{
ContractSwap: txfee_filters.ContractSwap{
InputCoin: txfee_filters.InputCoin{
Amount: "2775854",
Denom: "ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F",
},
OutputDenom: "ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F",
Slippage: txfee_filters.Slippage{
MinOutputAmount: "2775854",
},
},
}

msgBz, err := json.Marshal(contractSwapMsg)
suite.Require().NoError(err)

// https://celatone.osmosis.zone/osmosis-1/txs/8D20755D4E009CB72C763963A76886BCCCC5C2EBFC3F57266332710216A0D10D
executeMsg := &wasmtypes.MsgExecuteContract{
Contract: "osmo1etpha3a65tds0hmn3wfjeag6wgxgrkuwg2zh94cf5hapz7mz04dq6c25s5",
Sender: "osmo1dldrxz5p8uezxz3qstpv92de7wgfp7hvr72dcm",
Funds: sdk.NewCoins(sdk.NewCoin("ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", sdk.NewInt(217084399))),
Msg: msgBz,
}

_, isArb := txfee_filters.IsArbTxLooseAuthz(executeMsg, executeMsg.Funds[0].Denom, map[types.LiquidityChangeType]bool{})
suite.Require().True(isArb)
}

func (suite *KeeperTestSuite) TestIsArbTxLooseAuthz_OtherMsg() {
otherMsg := []byte(`{"update_feed": {}}`)

Expand Down

0 comments on commit 07b406e

Please sign in to comment.