-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Arb checktx filter, to raise gas * Add config params for min fee for arbitrage tx * Small improvements, add changelog * Fix bug in swap_msg logic
- Loading branch information
1 parent
bc65a83
commit 13531e5
Showing
10 changed files
with
224 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package types | ||
|
||
type LiquidityChangeType int | ||
|
||
const ( | ||
AddLiquidity LiquidityChangeType = iota | ||
RemoveLiquidity | ||
) | ||
|
||
// LiquidityChangeMsg defines a simple interface for determining if an LP msg | ||
// is removing or adding liquidity. | ||
type LiquidityChangeMsg interface { | ||
LiquidityChangeType() LiquidityChangeType | ||
} | ||
|
||
var _ LiquidityChangeMsg = MsgExitPool{} | ||
var _ LiquidityChangeMsg = MsgExitSwapShareAmountIn{} | ||
var _ LiquidityChangeMsg = MsgExitSwapExternAmountOut{} | ||
|
||
var _ LiquidityChangeMsg = MsgJoinPool{} | ||
var _ LiquidityChangeMsg = MsgJoinSwapExternAmountIn{} | ||
var _ LiquidityChangeMsg = MsgJoinSwapShareAmountOut{} | ||
|
||
func (msg MsgExitPool) LiquidityChangeType() LiquidityChangeType { | ||
return RemoveLiquidity | ||
} | ||
func (msg MsgExitSwapShareAmountIn) LiquidityChangeType() LiquidityChangeType { | ||
return RemoveLiquidity | ||
} | ||
func (msg MsgExitSwapExternAmountOut) LiquidityChangeType() LiquidityChangeType { | ||
return RemoveLiquidity | ||
} | ||
|
||
func (msg MsgJoinPool) LiquidityChangeType() LiquidityChangeType { | ||
return AddLiquidity | ||
} | ||
func (msg MsgJoinSwapExternAmountIn) LiquidityChangeType() LiquidityChangeType { | ||
return AddLiquidity | ||
} | ||
func (msg MsgJoinSwapShareAmountOut) LiquidityChangeType() LiquidityChangeType { | ||
return AddLiquidity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package types | ||
|
||
// SwapMsg defines a simple interface for getting the token denoms on a swap message route. | ||
type SwapMsgRoute interface { | ||
TokenInDenom() string | ||
TokenOutDenom() string | ||
TokenDenomsOnPath() []string | ||
} | ||
|
||
var _ SwapMsgRoute = MsgSwapExactAmountOut{} | ||
var _ SwapMsgRoute = MsgSwapExactAmountIn{} | ||
|
||
func (msg MsgSwapExactAmountOut) TokenInDenom() string { | ||
return msg.Routes[0].GetTokenInDenom() | ||
} | ||
func (msg MsgSwapExactAmountOut) TokenOutDenom() string { | ||
return msg.TokenOut.Denom | ||
} | ||
func (msg MsgSwapExactAmountOut) TokenDenomsOnPath() []string { | ||
denoms := make([]string, 0, len(msg.Routes)+1) | ||
for i := 0; i < len(msg.Routes); i++ { | ||
denoms = append(denoms, msg.Routes[i].TokenInDenom) | ||
} | ||
denoms = append(denoms, msg.TokenOutDenom()) | ||
return denoms | ||
} | ||
|
||
func (msg MsgSwapExactAmountIn) TokenInDenom() string { | ||
return msg.TokenIn.Denom | ||
} | ||
func (msg MsgSwapExactAmountIn) TokenOutDenom() string { | ||
lastRouteIndex := len(msg.Routes) - 1 | ||
return msg.Routes[lastRouteIndex].GetTokenOutDenom() | ||
} | ||
func (msg MsgSwapExactAmountIn) TokenDenomsOnPath() []string { | ||
denoms := make([]string, 0, len(msg.Routes)+1) | ||
denoms = append(denoms, msg.TokenInDenom()) | ||
for i := 0; i < len(msg.Routes); i++ { | ||
denoms = append(denoms, msg.Routes[i].TokenOutDenom) | ||
} | ||
return denoms | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TXfee filters | ||
|
||
See https://github.com/osmosis-labs/osmosis/issues/738 | ||
|
||
Want to move towards that, right now this is a stepping stone for that. We currently define a filter for recognizing if a tx is an arb transaction, and if so raising its gas price accordingly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package txfee_filters | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
gammtypes "github.com/osmosis-labs/osmosis/x/gamm/types" | ||
) | ||
|
||
// We check if a tx is an arbitrage for the mempool right now by seeing: | ||
// 1) does start token of a msg = final token of msg (definitionally correct) | ||
// 2) does it have multiple swap messages, with different tx ins. If so, we assume its an arb. | ||
// - This has false positives, but is intended to avoid the obvious solution of splitting | ||
// an arb into multiple messages. | ||
// 3) We record all denoms seen across all swaps, and see if any duplicates. (TODO) | ||
// 4) Contains both JoinPool and ExitPool messages in one tx. | ||
// - Has some false positives, but they seem relatively contrived. | ||
// TODO: Move the first component to a future router module | ||
func IsArbTxLoose(tx sdk.Tx) bool { | ||
msgs := tx.GetMsgs() | ||
|
||
swapInDenom := "" | ||
lpTypesSeen := make(map[gammtypes.LiquidityChangeType]bool, 2) | ||
|
||
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 | ||
} | ||
} | ||
|
||
swapMsg, isSwapMsg := m.(gammtypes.SwapMsgRoute) | ||
if !isSwapMsg { | ||
continue | ||
} | ||
|
||
// (1) Check that swap denom in != swap denom out | ||
if swapMsg.TokenInDenom() == swapMsg.TokenOutDenom() { | ||
return true | ||
} | ||
|
||
// (2) | ||
if swapInDenom != "" && swapMsg.TokenInDenom() != swapInDenom { | ||
return true | ||
} | ||
swapInDenom = swapMsg.TokenInDenom() | ||
} | ||
|
||
return false | ||
} |