-
Notifications
You must be signed in to change notification settings - Fork 28
/
utils.go
39 lines (31 loc) · 1.08 KB
/
utils.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
package types
import (
"fmt"
"strconv"
"strings"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// GetReservePoolAddr returns the pool address for the provided liquidity denomination.
func GetReservePoolAddr(lptDenom string) sdk.AccAddress {
return sdk.AccAddress(crypto.AddressHash([]byte(lptDenom)))
}
// GetTokenPairByDenom returns the token pair for the provided denominations
func GetTokenPairByDenom(inputDenom, outputDenom string) string {
return fmt.Sprintf("%s-%s", outputDenom, inputDenom)
}
// GetPoolId returns the pool coin denom by specified sequence.
func GetPoolId(counterpartyDenom string) string {
return fmt.Sprintf("pool-%s", counterpartyDenom)
}
// GetLptDenom returns the pool coin denom by specified sequence.
func GetLptDenom(sequence uint64) string {
return fmt.Sprintf(LptTokenFormat, sequence)
}
func ParseLptDenom(lptDenom string) (uint64, error) {
result := strings.Split(lptDenom, "-")
if len(result) != 2 {
return 0, fmt.Errorf("invalid lpt denom: %s", lptDenom)
}
return strconv.ParseUint(result[1], 10, 64)
}