@@ -26,12 +26,6 @@ import (
2626)
2727
2828const (
29- BridgeContractAddress = "fetch1qxxlalvsdjd07p07y3rc5fu6ll8k4tmetpha8n"
30- NewBridgeContractAdmin = "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw"
31-
32- IbcWithdrawAddress = "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x" /* "asi1rhrlzsx9z865dqen8t4v47r99dw6y4vaw76rd9" */
33- ReconciliationWithdrawAddress = "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x"
34-
3529 Bech32Chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
3630 AddrDataLength = 32
3731 WasmAddrDataLength = 52
@@ -41,16 +35,43 @@ const (
4135 ValAddressPrefix = "valoper"
4236 ConsAddressPrefix = "valcons"
4337
44- NewBaseDenom = "asi"
45- NewDenom = "aasi"
46- NewAddrPrefix = "asi"
47- NewChainId = "asi-1"
48- NewDescription = "ASI Token" // TODO(JS): change this, potentially
49-
50- OldDenom = "afet"
38+ NewAddrPrefix = "asi"
5139 OldAddrPrefix = "fetch"
5240)
5341
42+ var ReconciliationTargetAddr = "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x"
43+
44+ var networkInfos = map [string ]NetworkConfig {
45+ "fetchhub-4" : {
46+ NewChainID : "asi-1" ,
47+ NewDescription : "ASI token" , // TODO(JS): confirm this
48+ DenomInfo : DenomInfo {
49+ NewBaseDenom : "asi" ,
50+ NewDenom : "aasi" ,
51+ OldDenom : "afet" ,
52+ },
53+ IbcTargetAddr : "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x" , // TODO(JS): amend this
54+ ReconciliationTargetAddr : & ReconciliationTargetAddr , // TODO(JS): amend this
55+ Contracts : & Contracts {
56+ TokenBridge : & TokenBridge {
57+ Addr : "fetch1qxxlalvsdjd07p07y3rc5fu6ll8k4tmetpha8n" ,
58+ NewAdmin : "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw" ,
59+ },
60+ },
61+ },
62+
63+ "dorado-1" : {
64+ NewChainID : "asi-1" , // TODO(JS): likely amend this
65+ NewDescription : "Test ASI token" , // TODO(JS): confirm this
66+ DenomInfo : DenomInfo {
67+ NewBaseDenom : "testasi" ,
68+ NewDenom : "atestasi" ,
69+ OldDenom : "atestfet" ,
70+ },
71+ IbcTargetAddr : "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x" , // TODO(JS): amend this
72+ },
73+ }
74+
5475//go:embed reconciliation_data.csv
5576var reconciliationData []byte
5677
@@ -85,35 +106,45 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
85106 return fmt .Errorf ("failed to unmarshal genesis state: %w" , err )
86107 }
87108
109+ var ok bool
110+ var networkConfig NetworkConfig // TODO(JS): potentially just read Chain-ID, instead of taking a new arg
111+ if networkConfig , ok = networkInfos [genDoc .ChainID ]; ! ok {
112+ return fmt .Errorf ("network not found, not match for Chain-ID" )
113+ }
114+
88115 var jsonData map [string ]interface {}
89116 if err = json .Unmarshal (genDoc .AppState , & jsonData ); err != nil {
90117 return fmt .Errorf ("failed to unmarshal app state: %w" , err )
91118 }
92119
93120 // replace chain-id
94- ASIGenesisUpgradeReplaceChainID (genDoc )
121+ ASIGenesisUpgradeReplaceChainID (genDoc , networkConfig )
95122
96123 // replace bridge contract admin
97- ASIGenesisUpgradeReplaceBridgeAdmin (jsonData )
124+ if networkConfig .Contracts != nil && networkConfig .Contracts .TokenBridge != nil {
125+ ASIGenesisUpgradeReplaceBridgeAdmin (jsonData , networkConfig )
126+ }
98127
99128 // withdraw balances from IBC channels
100- if err = ASIGenesisUpgradeWithdrawIBCChannelsBalances (jsonData ); err != nil {
129+ if err = ASIGenesisUpgradeWithdrawIBCChannelsBalances (jsonData , networkConfig ); err != nil {
101130 return err
102131 }
103132
104133 // withdraw balances from reconciliation addresses
105- if err = ASIGenesisUpgradeWithdrawReconciliationBalances (jsonData ); err != nil {
106- return err
134+ if networkConfig .ReconciliationTargetAddr != nil {
135+ if err = ASIGenesisUpgradeWithdrawReconciliationBalances (jsonData , networkConfig ); err != nil {
136+ return err
137+ }
107138 }
108139
109140 // set denom metadata in bank module
110- ASIGenesisUpgradeReplaceDenomMetadata (jsonData )
141+ ASIGenesisUpgradeReplaceDenomMetadata (jsonData , networkConfig )
111142
112143 // replace denom across the genesis file
113- ASIGenesisUpgradeReplaceDenom (jsonData )
144+ ASIGenesisUpgradeReplaceDenom (jsonData , networkConfig )
114145
115146 // replace addresses across the genesis file
116- ASIGenesisUpgradeReplaceAddresses (jsonData )
147+ ASIGenesisUpgradeReplaceAddresses (jsonData , networkConfig )
117148
118149 var encodedAppState []byte
119150 if encodedAppState , err = json .Marshal (jsonData ); err != nil {
@@ -126,50 +157,55 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
126157 }
127158
128159 cmd .Flags ().String (flags .FlagHome , defaultNodeHome , "The application home directory" )
129- cmd .Flags ().String (flags .FlagKeyringBackend , flags .DefaultKeyringBackend , "Select keyring's backend (os|file|kwallet|pass|test)" )
160+ cmd .Flags ().String (flags .FlagKeyringBackend , flags .DefaultKeyringBackend , "Select keyring backend (os|file|kwallet|pass|test)" )
130161 flags .AddQueryFlagsToCmd (cmd )
131162
132163 return cmd
133164}
134165
135- func ASIGenesisUpgradeReplaceDenomMetadata (jsonData map [string ]interface {}) {
166+ func ASIGenesisUpgradeReplaceDenomMetadata (jsonData map [string ]interface {}, networkInfo NetworkConfig ) {
136167 type jsonMap map [string ]interface {}
137168
138- NewBaseDenomUpper := strings .ToUpper (NewBaseDenom )
169+ newBaseDenom := networkInfo .DenomInfo .NewBaseDenom
170+ oldDenom := networkInfo .DenomInfo .OldDenom
171+ newDenom := networkInfo .DenomInfo .NewDenom
172+ newDescription := networkInfo .NewDescription
173+
174+ NewBaseDenomUpper := strings .ToUpper (newBaseDenom )
139175
140176 newMetadata := jsonMap {
141- "base" : NewDenom ,
177+ "base" : newDenom ,
142178 "denom_units" : []jsonMap {
143179 {
144180 "denom" : NewBaseDenomUpper ,
145181 "exponent" : 18 ,
146182 },
147183 {
148- "denom" : fmt .Sprintf ("m%s" , NewBaseDenom ),
184+ "denom" : fmt .Sprintf ("m%s" , newBaseDenom ),
149185 "exponent" : 15 ,
150186 },
151187 {
152- "denom" : fmt .Sprintf ("u%s" , NewBaseDenom ),
188+ "denom" : fmt .Sprintf ("u%s" , newBaseDenom ),
153189 "exponent" : 12 ,
154190 },
155191 {
156- "denom" : fmt .Sprintf ("n%s" , NewBaseDenom ),
192+ "denom" : fmt .Sprintf ("n%s" , newBaseDenom ),
157193 "exponent" : 9 ,
158194 },
159195 {
160- "denom" : fmt .Sprintf ("p%s" , NewBaseDenom ),
196+ "denom" : fmt .Sprintf ("p%s" , newBaseDenom ),
161197 "exponent" : 6 ,
162198 },
163199 {
164- "denom" : fmt .Sprintf ("f%s" , NewBaseDenom ),
200+ "denom" : fmt .Sprintf ("f%s" , newBaseDenom ),
165201 "exponent" : 3 ,
166202 },
167203 {
168- "denom" : fmt .Sprintf ("a%s" , NewBaseDenom ),
204+ "denom" : fmt .Sprintf ("a%s" , newBaseDenom ),
169205 "exponent" : 0 ,
170206 },
171207 },
172- "description" : NewDescription ,
208+ "description" : newDescription ,
173209 "display" : NewBaseDenomUpper ,
174210 "name" : NewBaseDenomUpper ,
175211 "symbol" : NewBaseDenomUpper ,
@@ -180,46 +216,48 @@ func ASIGenesisUpgradeReplaceDenomMetadata(jsonData map[string]interface{}) {
180216
181217 for i , metadata := range denomMetadata {
182218 denomUnit := metadata .(map [string ]interface {})
183- if denomUnit ["base" ] == OldDenom {
219+ if denomUnit ["base" ] == oldDenom {
184220 denomMetadata [i ] = newMetadata
185221 break
186222 }
187223 }
188224}
189225
190- func ASIGenesisUpgradeReplaceChainID (genesisData * types.GenesisDoc ) {
191- genesisData .ChainID = NewChainId
226+ func ASIGenesisUpgradeReplaceChainID (genesisData * types.GenesisDoc , networkInfo NetworkConfig ) {
227+ genesisData .ChainID = networkInfo . NewChainID
192228}
193229
194- func ASIGenesisUpgradeReplaceBridgeAdmin (jsonData map [string ]interface {}) {
230+ func ASIGenesisUpgradeReplaceBridgeAdmin (jsonData map [string ]interface {}, networkInfo NetworkConfig ) {
195231 contracts := jsonData ["wasm" ].(map [string ]interface {})["contracts" ].([]interface {})
196232
197233 for i , contract := range contracts {
198234 c := contract .(map [string ]interface {})
199- if c ["contract_address" ] == BridgeContractAddress {
235+ if c ["contract_address" ] == networkInfo . Contracts . TokenBridge . Addr {
200236 contractInfo := c ["contract_info" ].(map [string ]interface {})
201- contractInfo ["admin" ] = NewBridgeContractAdmin
237+ contractInfo ["admin" ] = networkInfo . Contracts . TokenBridge . NewAdmin
202238 contracts [i ] = c
203239 break
204240 }
205241 }
206242}
207243
208- func ASIGenesisUpgradeReplaceDenom (jsonData map [string ]interface {}) {
244+ func ASIGenesisUpgradeReplaceDenom (jsonData map [string ]interface {}, networkInfo NetworkConfig ) {
209245 targets := map [string ]struct {}{"denom" : {}, "bond_denom" : {}, "mint_denom" : {}, "base_denom" : {}, "base" : {}}
246+ oldDenom := networkInfo .DenomInfo .OldDenom
247+ newDenom := networkInfo .DenomInfo .NewDenom
210248
211249 crawlJson ("" , jsonData , - 1 , func (key string , value interface {}, idx int ) interface {} {
212250 if str , ok := value .(string ); ok {
213251 _ , isInTargets := targets [key ]
214- if str == OldDenom && isInTargets {
215- return NewDenom
252+ if str == oldDenom && isInTargets {
253+ return newDenom
216254 }
217255 }
218256 return value
219257 })
220258}
221259
222- func ASIGenesisUpgradeReplaceAddresses (jsonData map [string ]interface {}) {
260+ func ASIGenesisUpgradeReplaceAddresses (jsonData map [string ]interface {}, networkInfo NetworkConfig ) {
223261 // account addresses
224262 replaceAddresses (AccAddressPrefix , jsonData , AddrDataLength + AddrChecksumLength )
225263 // validator addresses
@@ -249,12 +287,13 @@ func replaceAddresses(addressTypePrefix string, jsonData map[string]interface{},
249287 })
250288}
251289
252- func ASIGenesisUpgradeWithdrawIBCChannelsBalances (jsonData map [string ]interface {}) error {
290+ func ASIGenesisUpgradeWithdrawIBCChannelsBalances (jsonData map [string ]interface {}, networkInfo NetworkConfig ) error {
253291 bank := jsonData [banktypes .ModuleName ].(map [string ]interface {})
254292 balances := bank ["balances" ].([]interface {})
255293 balanceMap := getGenesisBalancesMap (balances )
294+ ibcWithdrawalAddress := networkInfo .IbcTargetAddr
256295
257- withdrawalBalanceIdx , ok := (* balanceMap )[IbcWithdrawAddress ]
296+ withdrawalBalanceIdx , ok := (* balanceMap )[ibcWithdrawalAddress ]
258297 if ! ok {
259298 fmt .Println ("failed to find Ibc withdrawal address in genesis balances - have addresses already been converted?" )
260299 return nil
@@ -319,9 +358,10 @@ func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
319358 return & accountMap
320359}
321360
322- func ASIGenesisUpgradeWithdrawReconciliationBalances (jsonData map [string ]interface {}) error {
361+ func ASIGenesisUpgradeWithdrawReconciliationBalances (jsonData map [string ]interface {}, networkInfo NetworkConfig ) error {
323362 bank := jsonData [banktypes .ModuleName ].(map [string ]interface {})
324363 balances := bank ["balances" ].([]interface {})
364+ reconciliationWithdrawAddress := networkInfo .ReconciliationTargetAddr
325365
326366 balanceMap := getGenesisBalancesMap (balances )
327367
@@ -336,9 +376,9 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa
336376 log .Fatalf ("Error reading reconciliation data: %s" , err )
337377 }
338378
339- reconciliationBalanceIdx , ok := (* balanceMap )[ReconciliationWithdrawAddress ]
379+ reconciliationBalanceIdx , ok := (* balanceMap )[* reconciliationWithdrawAddress ]
340380 if ! ok {
341- return fmt .Errorf ("no genesis match for reconciliation address: %s" , ReconciliationWithdrawAddress )
381+ return fmt .Errorf ("no match in genesis for reconciliation address: %s" , * reconciliationWithdrawAddress )
342382 }
343383
344384 for _ , row := range items {
@@ -348,7 +388,7 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa
348388
349389 accSequence , ok := (* accountSequenceMap )[addr ]
350390 if ! ok {
351- return fmt .Errorf ("no genesis match for reconciliation address: %s" , addr )
391+ return fmt .Errorf ("no match in genesis for reconciliation address: %s" , addr )
352392 }
353393
354394 balanceIdx , ok := (* balanceMap )[addr ]
@@ -455,3 +495,27 @@ func getInterfaceSliceFromCoins(coins sdk.Coins) []interface{} {
455495 }
456496 return balance
457497}
498+
499+ type NetworkConfig struct {
500+ NewChainID string
501+ NewDescription string
502+ IbcTargetAddr string
503+ ReconciliationTargetAddr * string
504+ Contracts * Contracts
505+ DenomInfo DenomInfo
506+ }
507+
508+ type DenomInfo struct {
509+ NewBaseDenom string
510+ NewDenom string
511+ OldDenom string
512+ }
513+
514+ type Contracts struct {
515+ TokenBridge * TokenBridge
516+ }
517+
518+ type TokenBridge struct {
519+ Addr string
520+ NewAdmin string
521+ }
0 commit comments