/
key.go
58 lines (46 loc) · 1.17 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
package types
import (
"fmt"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
ModuleName = "gamm"
StoreKey = ModuleName
RouterKey = ModuleName
QuerierRoute = ModuleName
)
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}
)
func MustGetPoolIdFromShareDenom(denom string) uint64 {
numberStr := strings.TrimLeft(denom, "gamm/pool/")
number, err := strconv.Atoi(numberStr)
if err != nil {
panic(err)
}
return uint64(number)
}
func ValidatePoolShareDenom(denom string) error {
numberStr := strings.TrimLeft(denom, "gamm/pool/")
_, err := strconv.Atoi(numberStr)
if err != nil {
return err
}
return nil
}
func GetDenomPrefix(denom string) []byte {
return append(KeyTotalLiquidity, []byte(denom)...)
}
func GetPoolShareDenom(poolId uint64) string {
return fmt.Sprintf("gamm/pool/%d", poolId)
}
func GetKeyPrefixPools(poolId uint64) []byte {
return append(KeyPrefixPools, sdk.Uint64ToBigEndian(poolId)...)
}