github.com/gravity-devs/liquidity@v1.5.3/x/liquidity/types/keys.go (about) 1 package types 2 3 import ( 4 sdk "github.com/cosmos/cosmos-sdk/types" 5 "github.com/cosmos/cosmos-sdk/types/address" 6 ) 7 8 const ( 9 // ModuleName is the name of the liquidity module 10 ModuleName = "liquidity" 11 12 // RouterKey is the message router key for the liquidity module 13 RouterKey = ModuleName 14 15 // StoreKey is the default store key for the liquidity module 16 StoreKey = ModuleName 17 18 // QuerierRoute is the querier route for the liquidity module 19 QuerierRoute = ModuleName 20 21 // PoolCoinDenomPrefix is the prefix used for liquidity pool coin representation 22 PoolCoinDenomPrefix = "pool" 23 ) 24 25 var ( 26 // param key for global Liquidity Pool IDs 27 GlobalLiquidityPoolIDKey = []byte("globalLiquidityPoolId") 28 29 PoolKeyPrefix = []byte{0x11} 30 PoolByReserveAccIndexKeyPrefix = []byte{0x12} 31 32 PoolBatchKeyPrefix = []byte{0x22} 33 34 PoolBatchDepositMsgStateIndexKeyPrefix = []byte{0x31} 35 PoolBatchWithdrawMsgStateIndexKeyPrefix = []byte{0x32} 36 PoolBatchSwapMsgStateIndexKeyPrefix = []byte{0x33} 37 ) 38 39 // GetPoolKey returns kv indexing key of the pool 40 func GetPoolKey(poolID uint64) []byte { 41 key := make([]byte, 9) 42 key[0] = PoolKeyPrefix[0] 43 copy(key[1:], sdk.Uint64ToBigEndian(poolID)) 44 return key 45 } 46 47 // GetPoolByReserveAccIndexKey returns kv indexing key of the pool indexed by reserve account 48 func GetPoolByReserveAccIndexKey(reserveAcc sdk.AccAddress) []byte { 49 return append(PoolByReserveAccIndexKeyPrefix, address.MustLengthPrefix(reserveAcc.Bytes())...) 50 } 51 52 // GetPoolBatchKey returns kv indexing key of the pool batch indexed by pool id 53 func GetPoolBatchKey(poolID uint64) []byte { 54 key := make([]byte, 9) 55 key[0] = PoolBatchKeyPrefix[0] 56 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 57 return key 58 } 59 60 // GetPoolBatchDepositMsgStatesPrefix returns prefix of deposit message states in the pool's latest batch for iteration 61 func GetPoolBatchDepositMsgStatesPrefix(poolID uint64) []byte { 62 key := make([]byte, 9) 63 key[0] = PoolBatchDepositMsgStateIndexKeyPrefix[0] 64 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 65 return key 66 } 67 68 // GetPoolBatchWithdrawMsgsPrefix returns prefix of withdraw message states in the pool's latest batch for iteration 69 func GetPoolBatchWithdrawMsgsPrefix(poolID uint64) []byte { 70 key := make([]byte, 9) 71 key[0] = PoolBatchWithdrawMsgStateIndexKeyPrefix[0] 72 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 73 return key 74 } 75 76 // GetPoolBatchSwapMsgStatesPrefix returns prefix of swap message states in the pool's latest batch for iteration 77 func GetPoolBatchSwapMsgStatesPrefix(poolID uint64) []byte { 78 key := make([]byte, 9) 79 key[0] = PoolBatchSwapMsgStateIndexKeyPrefix[0] 80 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 81 return key 82 } 83 84 // GetPoolBatchDepositMsgStateIndexKey returns kv indexing key of the latest index value of the msg index 85 func GetPoolBatchDepositMsgStateIndexKey(poolID, msgIndex uint64) []byte { 86 key := make([]byte, 17) 87 key[0] = PoolBatchDepositMsgStateIndexKeyPrefix[0] 88 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 89 copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex)) 90 return key 91 } 92 93 // GetPoolBatchWithdrawMsgStateIndexKey returns kv indexing key of the latest index value of the msg index 94 func GetPoolBatchWithdrawMsgStateIndexKey(poolID, msgIndex uint64) []byte { 95 key := make([]byte, 17) 96 key[0] = PoolBatchWithdrawMsgStateIndexKeyPrefix[0] 97 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 98 copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex)) 99 return key 100 } 101 102 // GetPoolBatchSwapMsgStateIndexKey returns kv indexing key of the latest index value of the msg index 103 func GetPoolBatchSwapMsgStateIndexKey(poolID, msgIndex uint64) []byte { 104 key := make([]byte, 17) 105 key[0] = PoolBatchSwapMsgStateIndexKeyPrefix[0] 106 copy(key[1:9], sdk.Uint64ToBigEndian(poolID)) 107 copy(key[9:17], sdk.Uint64ToBigEndian(msgIndex)) 108 return key 109 }