-
Notifications
You must be signed in to change notification settings - Fork 99
/
genesis.go
68 lines (60 loc) · 1.67 KB
/
genesis.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
package types
import (
"github.com/dydxprotocol/v4-chain/protocol/lib"
)
const (
// UusdcDenom is the precomputed denom for IBC Micro USDC.
UusdcDenom = "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5"
)
var AssetUsdc Asset = Asset{
Id: 0,
Symbol: "USDC",
DenomExponent: -6,
Denom: UusdcDenom,
HasMarket: false,
AtomicResolution: lib.QuoteCurrencyAtomicResolution,
}
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Assets: []Asset{
AssetUsdc,
},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Genesis state should contain at least one asset.
if len(gs.Assets) == 0 {
return ErrNoAssetInGenesis
}
// The first asset should always be USDC.
if gs.Assets[0] != AssetUsdc {
return ErrUsdcMustBeAssetZero
}
// Provided assets should not contain duplicated asset ids, and denoms.
// Asset ids should be sequential.
// MarketId should be 0 if HasMarket is false.
assetIdSet := make(map[uint32]struct{})
denomSet := make(map[string]struct{})
expectedId := uint32(0)
for _, asset := range gs.Assets {
if _, exists := assetIdSet[asset.Id]; exists {
return ErrAssetIdAlreadyExists
}
if _, exists := denomSet[asset.Denom]; exists {
return ErrAssetDenomAlreadyExists
}
if asset.Id != expectedId {
return ErrGapFoundInAssetId
}
if !asset.HasMarket && asset.MarketId > 0 {
return ErrInvalidMarketId
}
assetIdSet[asset.Id] = struct{}{}
denomSet[asset.Denom] = struct{}{}
expectedId = expectedId + 1
}
return nil
}