-
Notifications
You must be signed in to change notification settings - Fork 208
/
tokens.go
94 lines (86 loc) · 2.81 KB
/
tokens.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
// Abstractions for keeping track of token names and their corresponding
// decimal precision exponents.
package tokens
import (
sdk "github.com/cosmos/cosmos-sdk/types"
// sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
// "github.com/osmosis-labs/osmosis/v043_temp/address"
)
type Native struct {
HumanDisplay string // "nibi"
HumanExponent int64 // 18
Base string // "anibi"
BaseDisplay string // "anibi"
BaseExponent int64 // 0
DefaultBondDenom string
Bech32PrefixAccAddr string
}
func NewNativeToken(humanDisplay string, humanExponent int64, base string, baseDisplay string) Native {
token := new(Native)
token.HumanDisplay = humanDisplay
token.HumanExponent = humanExponent
token.Base = base
token.BaseDisplay = baseDisplay
token.BaseExponent = 0
token.DefaultBondDenom = base
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
token.Bech32PrefixAccAddr = humanDisplay
return *token
}
// Metadata for non-native assets used in the chain.
type IBCToken struct {
HumanDisplay string // "atom"
HumanExponent int64 // 6
Base string // "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
BaseDisplay string // "uatom"
BaseExponent int64 // 0
DefaultBondDenom string
}
func NewIBCToken(humanDisplay string, humanExponent int64, baseDisplay string, base string) IBCToken {
token := new(IBCToken)
token.HumanDisplay = humanDisplay
token.HumanExponent = humanExponent
token.Base = base
token.BaseDisplay = baseDisplay
token.BaseExponent = 0
token.DefaultBondDenom = base
return *token
}
const ibcPlaceholder string = "ibc/..."
var (
NATIVE_MAP = map[string]Native{
"nibi": NewNativeToken("nibi", 18, "anibi", "anibi"),
}
// TODO Use IBC addresses from https://docs.osmosis.zone/developing/assets/asset-info.html
IBC_MAP = map[string]IBCToken{
"nusd": NewIBCToken("nusd", 6, "unusd", "unusd"),
"osmo": NewIBCToken("osmo", 6, "uosmo", ibcPlaceholder),
"ust": NewIBCToken("ust", 6, "uust", ibcPlaceholder),
"ion": NewIBCToken("ion", 6, "uion", ibcPlaceholder),
"atom": NewIBCToken(
"atom", /* HumanDisplay */
6, /* HumanExponent */
"uatom", /* BaseDisplay */
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"),
"juno": NewIBCToken(
"juno", 6, "ujuno",
"ibc/46B44899322F3CD854D2D46DEEF881958467CDD4B3B10086DA49296BBED94BED"),
"luna": NewIBCToken(
"luna", 6, "uluna",
"ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0"),
}
)
func RegisterDenoms() {
for denom, tokenRegistry := range NATIVE_MAP {
err := sdk.RegisterDenom(denom, sdk.OneDec())
if err != nil {
panic(err)
}
err = sdk.RegisterDenom(
tokenRegistry.Base,
sdk.NewDecWithPrec(1, tokenRegistry.HumanExponent))
if err != nil {
panic(err)
}
}
}