-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgenesis.go
191 lines (163 loc) · 6.43 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package app
import (
"encoding/hex"
"encoding/json"
"cosmossdk.io/core/address"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icagenesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctypes "github.com/cosmos/ibc-go/v8/modules/core/types"
l2connect "github.com/initia-labs/OPinit/x/opchild/l2connect"
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
"github.com/initia-labs/initia/app/genesis_markets"
auctiontypes "github.com/skip-mev/block-sdk/v2/x/auction/types"
connecttypes "github.com/skip-mev/connect/v2/pkg/types"
marketmaptypes "github.com/skip-mev/connect/v2/x/marketmap/types"
oracletypes "github.com/skip-mev/connect/v2/x/oracle/types"
)
// GenesisState - The genesis state of the blockchain is represented here as a map of raw json
// messages key'd by a identifier string.
// The identifier is used to determine which module genesis information belongs
// to so it may be appropriately routed during init chain.
// Within this application default genesis information is retrieved from
// the ModuleBasicManager which populates json from each BasicModule
// object provided to it during init.
type GenesisState map[string]json.RawMessage
// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState(cdc codec.Codec, mbm module.BasicManager, denom string) GenesisState {
return GenesisState(mbm.DefaultGenesis(cdc)).
ConfigureMinGasPrices(cdc).
ConfigureICA(cdc).
ConfigureIBCAllowedClients(cdc).
ConfigureAuctionFee(cdc, denom).
AddMarketData(cdc, cdc.InterfaceRegistry().SigningContext().AddressCodec())
}
func (genState GenesisState) AddMarketData(cdc codec.JSONCodec, ac address.Codec) GenesisState {
var oracleGenState oracletypes.GenesisState
cdc.MustUnmarshalJSON(genState[oracletypes.ModuleName], &oracleGenState)
var marketGenState marketmaptypes.GenesisState
cdc.MustUnmarshalJSON(genState[marketmaptypes.ModuleName], &marketGenState)
// Load initial markets
markets, err := genesis_markets.ReadMarketsFromFile(genesis_markets.GenesisMarkets)
if err != nil {
panic(err)
}
marketGenState.MarketMap = genesis_markets.ToMarketMap(markets)
// Skip Admin account.
adminAddrBz, err := hex.DecodeString("51B89E89D58FFB3F9DB66263FF10A216CF388A0E")
if err != nil {
panic(err)
}
adminAddr, err := ac.BytesToString(adminAddrBz)
if err != nil {
panic(err)
}
marketGenState.Params.MarketAuthorities = []string{adminAddr}
marketGenState.Params.Admin = adminAddr
var id uint64
// Initialize all markets plus ReservedCPTimestamp
currencyPairGenesis := make([]oracletypes.CurrencyPairGenesis, len(markets)+1)
cp, err := connecttypes.CurrencyPairFromString(l2connect.ReservedCPTimestamp)
if err != nil {
panic(err)
}
currencyPairGenesis[id] = oracletypes.CurrencyPairGenesis{
CurrencyPair: cp,
CurrencyPairPrice: nil,
Nonce: 0,
Id: id,
}
id++
for i, market := range markets {
currencyPairGenesis[i+1] = oracletypes.CurrencyPairGenesis{
CurrencyPair: market.Ticker.CurrencyPair,
CurrencyPairPrice: nil,
Nonce: 0,
Id: id,
}
id++
}
oracleGenState.CurrencyPairGenesis = currencyPairGenesis
oracleGenState.NextId = id
// write the updates to genState
genState[marketmaptypes.ModuleName] = cdc.MustMarshalJSON(&marketGenState)
genState[oracletypes.ModuleName] = cdc.MustMarshalJSON(&oracleGenState)
return genState
}
func (genState GenesisState) ConfigureAuctionFee(cdc codec.JSONCodec, denom string) GenesisState {
var auctionGenState auctiontypes.GenesisState
cdc.MustUnmarshalJSON(genState[auctiontypes.ModuleName], &auctionGenState)
auctionGenState.Params.ReserveFee.Denom = denom
auctionGenState.Params.MinBidIncrement.Denom = denom
genState[auctiontypes.ModuleName] = cdc.MustMarshalJSON(&auctionGenState)
return genState
}
// ConfigureMinGasPrices generates the default state for the application.
func (genState GenesisState) ConfigureMinGasPrices(cdc codec.JSONCodec) GenesisState {
var opChildGenState opchildtypes.GenesisState
cdc.MustUnmarshalJSON(genState[opchildtypes.ModuleName], &opChildGenState)
opChildGenState.Params.MinGasPrices = nil
opChildGenState.Params.HookMaxGas = 3_000_000
genState[opchildtypes.ModuleName] = cdc.MustMarshalJSON(&opChildGenState)
return genState
}
func (genState GenesisState) ConfigureICA(cdc codec.JSONCodec) GenesisState {
// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
ControllerEnabled: true,
}
// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{
authzMsgExec,
authzMsgGrant,
authzMsgRevoke,
bankMsgSend,
bankMsgMultiSend,
feegrantMsgGrantAllowance,
feegrantMsgRevokeAllowance,
groupCreateGroup,
groupCreateGroupPolicy,
groupExec,
groupLeaveGroup,
groupSubmitProposal,
groupUpdateGroupAdmin,
groupUpdateGroupMember,
groupUpdateGroupPolicyAdmin,
groupUpdateGroupPolicyDecisionPolicy,
groupVote,
groupWithdrawProposal,
transferMsgTransfer,
nftTransferMsgTransfer,
sftTransferMsgTransfer,
moveMsgPublishModuleBundle,
moveMsgExecuteEntryFunction,
moveMsgExecuteScript,
},
}
var icaGenState icagenesistypes.GenesisState
cdc.MustUnmarshalJSON(genState[icatypes.ModuleName], &icaGenState)
icaGenState.ControllerGenesisState.Params = controllerParams
icaGenState.HostGenesisState.Params = hostParams
genState[icatypes.ModuleName] = cdc.MustMarshalJSON(&icaGenState)
return genState
}
func (genState GenesisState) ConfigureIBCAllowedClients(cdc codec.JSONCodec) GenesisState {
var ibcGenesis ibctypes.GenesisState
cdc.MustUnmarshalJSON(genState[ibcexported.ModuleName], &ibcGenesis)
allowedClients := ibcGenesis.ClientGenesis.Params.AllowedClients
for i, client := range allowedClients {
if client == ibcexported.Localhost {
allowedClients = append(allowedClients[:i], allowedClients[i+1:]...)
break
}
}
ibcGenesis.ClientGenesis.Params.AllowedClients = allowedClients
genState[ibcexported.ModuleName] = cdc.MustMarshalJSON(&ibcGenesis)
return genState
}