/
key.go
70 lines (54 loc) · 1.63 KB
/
key.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
package types
import (
"fmt"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
ModuleName = "gamm"
StoreKey = ModuleName
RouterKey = ModuleName
QuerierRoute = ModuleName
GAMMTokenPrefix = "gamm/pool/"
)
var (
// KeyNextGlobalPoolId defines key to store the next Pool ID to be used.
KeyNextGlobalPoolId = []byte{0x01}
// KeyPrefixPools defines prefix to store pools.
KeyPrefixPools = []byte{0x02}
// KeyTotalLiquidity defines key to store total liquidity.
KeyTotalLiquidity = []byte{0x03}
KeyPrefixMigrationInfoBalancerPool = []byte{0x04}
KeyPrefixMigrationInfoCLPool = []byte{0x05}
)
func MustGetPoolIdFromShareDenom(denom string) uint64 {
number, err := GetPoolIdFromShareDenom(denom)
if err != nil {
panic(err)
}
return number
}
func GetPoolIdFromShareDenom(denom string) (uint64, error) {
numberStr := strings.TrimLeft(denom, GAMMTokenPrefix)
number, err := strconv.Atoi(numberStr)
if err != nil {
return 0, err
}
return uint64(number), nil
}
func GetDenomPrefix(denom string) []byte {
return append(KeyTotalLiquidity, []byte(denom)...)
}
func GetPoolShareDenom(poolId uint64) string {
return fmt.Sprintf("%s%d", GAMMTokenPrefix, poolId)
}
func GetKeyPrefixPools(poolId uint64) []byte {
return append(KeyPrefixPools, sdk.Uint64ToBigEndian(poolId)...)
}
func GetKeyPrefixMigrationInfoBalancerPool(balancerPoolId uint64) []byte {
return append(KeyPrefixMigrationInfoBalancerPool, sdk.Uint64ToBigEndian(balancerPoolId)...)
}
func GetKeyPrefixMigrationInfoPoolCLPool(concentratedPoolId uint64) []byte {
return append(KeyPrefixMigrationInfoCLPool, sdk.Uint64ToBigEndian(concentratedPoolId)...)
}