-
Notifications
You must be signed in to change notification settings - Fork 14
/
keys.go
109 lines (90 loc) · 3.67 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
const (
// ModuleName is the name of the liquidity module
ModuleName = "liquidity"
// RouterKey is the message router key for the liquidity module
RouterKey = ModuleName
// StoreKey is the default store key for the liquidity module
StoreKey = ModuleName
// QuerierRoute is the querier route for the liquidity module
QuerierRoute = ModuleName
// PoolCoinDenomPrefix is the prefix used for liquidity pool coin representation
PoolCoinDenomPrefix = "pool"
)
var (
// param key for global Liquidity Pool IDs
GlobalLiquidityPoolIDKey = []byte("globalLiquidityPoolId")
PoolKeyPrefix = []byte{0x11}
PoolByReserveAccIndexKeyPrefix = []byte{0x12}
PoolBatchKeyPrefix = []byte{0x22}
PoolBatchDepositMsgStateIndexKeyPrefix = []byte{0x31}
PoolBatchWithdrawMsgStateIndexKeyPrefix = []byte{0x32}
PoolBatchSwapMsgStateIndexKeyPrefix = []byte{0x33}
)
// GetPoolKey returns kv indexing key of the pool
func GetPoolKey(poolID uint64) []byte {
key := make([]byte, 9)
key[0] = PoolKeyPrefix[0]
copy(key[1:], sdk.Uint64ToBigEndian(poolID))
return key
}
// GetPoolByReserveAccIndexKey returns kv indexing key of the pool indexed by reserve account
func GetPoolByReserveAccIndexKey(reserveAcc sdk.AccAddress) []byte {
return append(PoolByReserveAccIndexKeyPrefix, address.MustLengthPrefix(reserveAcc.Bytes())...)
}
// GetPoolBatchKey returns kv indexing key of the pool batch indexed by pool id
func GetPoolBatchKey(poolID uint64) []byte {
key := make([]byte, 9)
key[0] = PoolBatchKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
return key
}
// GetPoolBatchDepositMsgStatesPrefix returns prefix of deposit message states in the pool's latest batch for iteration
func GetPoolBatchDepositMsgStatesPrefix(poolID uint64) []byte {
key := make([]byte, 9)
key[0] = PoolBatchDepositMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
return key
}
// GetPoolBatchWithdrawMsgsPrefix returns prefix of withdraw message states in the pool's latest batch for iteration
func GetPoolBatchWithdrawMsgsPrefix(poolID uint64) []byte {
key := make([]byte, 9)
key[0] = PoolBatchWithdrawMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
return key
}
// GetPoolBatchSwapMsgStatesPrefix returns prefix of swap message states in the pool's latest batch for iteration
func GetPoolBatchSwapMsgStatesPrefix(poolID uint64) []byte {
key := make([]byte, 9)
key[0] = PoolBatchSwapMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
return key
}
// GetPoolBatchDepositMsgStateIndexKey returns kv indexing key of the latest index value of the msg index
func GetPoolBatchDepositMsgStateIndexKey(poolID, msgIndex uint64) []byte {
key := make([]byte, 17)
key[0] = PoolBatchDepositMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex))
return key
}
// GetPoolBatchWithdrawMsgStateIndexKey returns kv indexing key of the latest index value of the msg index
func GetPoolBatchWithdrawMsgStateIndexKey(poolID, msgIndex uint64) []byte {
key := make([]byte, 17)
key[0] = PoolBatchWithdrawMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex))
return key
}
// GetPoolBatchSwapMsgStateIndexKey returns kv indexing key of the latest index value of the msg index
func GetPoolBatchSwapMsgStateIndexKey(poolID, msgIndex uint64) []byte {
key := make([]byte, 17)
key[0] = PoolBatchSwapMsgStateIndexKeyPrefix[0]
copy(key[1:9], sdk.Uint64ToBigEndian(poolID))
copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex))
return key
}