/
keys.go
148 lines (116 loc) · 5.58 KB
/
keys.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package types
import (
"fmt"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName defines the module name
ModuleName = "protorev"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
)
const (
prefixTokenPairRoutes = iota + 1
prefixDenomPairToPool
prefixBaseDenoms
prefixNumberOfTrades
prefixProfitsByDenom
prefixTradesByRoute
prefixProfitsByRoute
prefixDeveloperAccount
prefixDaysSinceGenesis
prefixDeveloperFees
prefixMaxPoolPointsPerTx
prefixMaxPoolPointsPerBlock
prefixPoolPointCountForBlock
prefixLatestBlockHeight
prefixInfoByPoolType
prefixSwapsToBackrun
)
var (
// -------------- Keys for trading stores -------------- //
// KeyPrefixTokenPairRoutes is the prefix for the TokenPairArbRoutes store
KeyPrefixTokenPairRoutes = []byte{prefixTokenPairRoutes}
// KeyPrefixDenomPairToPool is the prefix that is used to store the pool id for a given denom pair (baseDenom, otherDenom)
KeyPrefixDenomPairToPool = []byte{prefixDenomPairToPool}
// KeyPrefixBaseDenoms is the prefix that is used to store the base denoms that are used to create cyclic arbitrage routes
KeyPrefixBaseDenoms = []byte{prefixBaseDenoms}
// -------------- Keys for statistics stores -------------- //
// KeyPrefixNumberOfTrades is the prefix for the store that keeps track of the number of trades executed
KeyPrefixNumberOfTrades = []byte{prefixNumberOfTrades}
// KeyPrefixProfitByDenom is the prefix for the store that keeps track of the profits
KeyPrefixProfitByDenom = []byte{prefixProfitsByDenom}
// KeyPrefixTradesByRoute is the prefix for the store that keeps track of the number of trades executed by route
KeyPrefixTradesByRoute = []byte{prefixTradesByRoute}
// KeyPrefixProfitsByRoute is the prefix for the store that keeps track of the profits made by route
KeyPrefixProfitsByRoute = []byte{prefixProfitsByRoute}
// -------------- Keys for configuration/admin stores -------------- //
// KeyPrefixDeveloperAccount is the prefix for store that keeps track of the developer account
KeyPrefixDeveloperAccount = []byte{prefixDeveloperAccount}
// KeyPrefixDaysSinceGenesis is the prefix for store that keeps track of the number of days since genesis
KeyPrefixDaysSinceGenesis = []byte{prefixDaysSinceGenesis}
// KeyPrefixDeveloperFees is the prefix for store that keeps track of the developer fees
KeyPrefixDeveloperFees = []byte{prefixDeveloperFees}
// KeyPrefixMaxPointsPerTx is the prefix for store that keeps track of the max number of pool points that can be consumed per tx
KeyPrefixMaxPointsPerTx = []byte{prefixMaxPoolPointsPerTx}
// KeyPrefixMaxPointsPerBlock is the prefix for store that keeps track of the max number of pool points that can be consumed per block
KeyPrefixMaxPointsPerBlock = []byte{prefixMaxPoolPointsPerBlock}
// KeyPrefixPointCountForBlock is the prefix for store that keeps track of the number of pool points that have been consumed in the current block
KeyPrefixPointCountForBlock = []byte{prefixPoolPointCountForBlock}
// KeyPrefixLatestBlockHeight is the prefix for store that keeps track of the latest recorded block height
KeyPrefixLatestBlockHeight = []byte{prefixLatestBlockHeight}
// KeyPrefixInfoByPoolType is the prefix for store that keeps track of the pool type info
KeyPrefixInfoByPoolType = []byte{prefixInfoByPoolType}
// KeyPrefixSwapsToBackrun is the prefix for store that keeps track of the swaps that need to be backrun for a given tx
KeyPrefixSwapsToBackrun = []byte{prefixSwapsToBackrun}
)
// Returns the key needed to fetch the pool id for a given denom
func GetKeyPrefixDenomPairToPool(baseDenom, matchDenom string) []byte {
return append(KeyPrefixDenomPairToPool, []byte(baseDenom+"|"+matchDenom)...)
}
// Returns the key needed to fetch info about base denoms
func GetKeyPrefixBaseDenom(priority uint64) []byte {
return append(KeyPrefixBaseDenoms, sdk.Uint64ToBigEndian(priority)...)
}
// Returns the key needed to fetch the tokenPair routes for a given pair of tokens
func GetKeyPrefixRouteForTokenPair(tokenA, tokenB string) []byte {
return append(KeyPrefixTokenPairRoutes, []byte(tokenA+"|"+tokenB)...)
}
// Returns the key needed to fetch the profit by coin
func GetKeyPrefixProfitByDenom(denom string) []byte {
return append(KeyPrefixProfitByDenom, []byte(denom)...)
}
// Returns the key needed to fetch the number of trades by route
func GetKeyPrefixTradesByRoute(route []uint64) []byte {
return append(KeyPrefixTradesByRoute, CreateRouteKey(route)...)
}
// Returns the key needed to fetch the profits by route
func GetKeyPrefixProfitsByRoute(route []uint64, denom string) []byte {
return append(append(KeyPrefixProfitsByRoute, CreateRouteKey(route)...), []byte(denom)...)
}
// createRouteKey creates a key for the given route. converts a slice of uint64 to a string separated by a pipe
// {1,2,3,4} -> []byte("1|2|3|4")
func CreateRouteKey(route []uint64) []byte {
return []byte(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(route)), "|"), "[]"))
}
// createRouteFromKey creates a route from a key. converts a string separated by a pipe to a slice of uint64
// []byte("1|2|3|4") -> {1,2,3,4}
func CreateRouteFromKey(key []byte) ([]uint64, error) {
var route []uint64
for _, r := range strings.Split(string(key), "|") {
pool, err := strconv.ParseUint(r, 10, 64)
if err != nil {
return []uint64{}, err
}
route = append(route, pool)
}
return route, nil
}
// Returns the key needed to fetch the developer fees by coin
func GetKeyPrefixDeveloperFees(denom string) []byte {
return append(KeyPrefixDeveloperFees, []byte(denom)...)
}