-
Notifications
You must be signed in to change notification settings - Fork 0
/
arb_tx.go
54 lines (45 loc) · 1.54 KB
/
arb_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package txfee_filters
import (
gammtypes "github.com/fury-labs/furya/v20/x/gamm/types"
sdk "github.com/cosmos/cosmos-sdk/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
}