@@ -50,6 +50,10 @@ var networkInfos = map[string]NetworkConfig{
5050 NewDenom : "aasi" ,
5151 OldDenom : "afet" ,
5252 },
53+ SupplyInfo : SupplyInfo {
54+ SupplyToMint : "100000000000000000000000000" , // TODO(JS): likely amend this
55+ UpdatedSupplyOverflowAddr : "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw" , // TODO(JS): likely amend this
56+ },
5357 IbcTargetAddr : "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x" , // TODO(JS): amend this
5458 ReconciliationTargetAddr : & ReconciliationTargetAddr , // TODO(JS): amend this
5559 Contracts : & Contracts {
@@ -68,6 +72,10 @@ var networkInfos = map[string]NetworkConfig{
6872 NewDenom : "atestasi" ,
6973 OldDenom : "atestfet" ,
7074 },
75+ SupplyInfo : SupplyInfo {
76+ SupplyToMint : "100000000000000000000000000" , // TODO(JS): likely amend this
77+ UpdatedSupplyOverflowAddr : "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw" , // TODO(JS): likely amend this
78+ },
7179 IbcTargetAddr : "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x" , // TODO(JS): amend this
7280 },
7381}
@@ -85,10 +93,10 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
8593 - The native coin denom will be updated to "asi"
8694 - The denom metadata will be updated to the new ASI token
8795 - The address prefix will be updated to "asi"
88- - The old fetch addresses will be updated to the new asi addresses
96+ - The old fetch addresses will be updated to the new asi addresses, e.g. asivaloper1, asivalcons1, asi1, etc.
8997 - The bridge contract admin will be updated to the new address
90- - The IBC withdrawal address will be updated to the new address
91- - The reconciliation withdrawal address will be updated to the new address
98+ - The IBC channel funds will be transferred to the IBC withdrawal address
99+ - The reconciliation withdrawal funds (if applicable) will be transferred to the reconciliation withdrawal address
92100` ,
93101
94102 Args : cobra .ExactArgs (0 ),
@@ -145,6 +153,9 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
145153 // replace denom across the genesis file
146154 ASIGenesisUpgradeReplaceDenom (jsonData , networkConfig )
147155
156+ // supplement the genesis supply
157+ ASIGenesisUpgradeASISupply (jsonData , networkConfig )
158+
148159 // replace addresses across the genesis file
149160 ASIGenesisUpgradeReplaceAddresses (jsonData , networkConfig )
150161
@@ -305,7 +316,7 @@ func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{
305316 }
306317 withdrawalBalanceIdx , ok := (* balanceMap )[ibcWithdrawalAddress ]
307318 if ! ok {
308- fmt .Println ("failed to find Ibc withdrawal address in genesis balances - have addresses already been converted?" )
319+ fmt .Println ("failed to find ibc withdrawal address in genesis balances - have addresses already been converted?" )
309320 return nil
310321 }
311322
@@ -314,8 +325,12 @@ func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{
314325 ibcChannels := channelGenesis ["channels" ].([]interface {})
315326
316327 for _ , channel := range ibcChannels {
317- channelId := channel .(map [string ]interface {})["channel_id" ].(string )
318- portId := channel .(map [string ]interface {})["port_id" ].(string )
328+ channelMap := channel .(map [string ]interface {})
329+ channelId := channelMap ["channel_id" ].(string )
330+ portId := channelMap ["port_id" ].(string )
331+
332+ // close channel
333+ channelMap ["state" ] = "STATE_CLOSED"
319334
320335 rawAddr := ibctransfertypes .GetEscrowAddress (portId , channelId )
321336 channelAddr , err := sdk .Bech32ifyAddressBytes (OldAddrPrefix + AccAddressPrefix , rawAddr )
@@ -350,15 +365,17 @@ func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
350365 accountMap := make (map [string ]int )
351366
352367 for _ , acc := range accounts {
353- accType := acc .(map [string ]interface {})["@type" ]
368+ accMap := acc .(map [string ]interface {})
369+ accType := accMap ["@type" ]
354370
355371 accData := acc
356372 if accType == ModuleAccount {
357- accData = acc .( map [ string ] interface {}) ["base_account" ]
373+ accData = accMap ["base_account" ]
358374 }
359375
360- addr := accData .(map [string ]interface {})["address" ].(string )
361- sequence := accData .(map [string ]interface {})["sequence" ].(string )
376+ accDataMap := accData .(map [string ]interface {})
377+ addr := accDataMap ["address" ].(string )
378+ sequence := accDataMap ["sequence" ].(string )
362379
363380 sequenceInt , ok := strconv .Atoi (sequence )
364381 if ok != nil {
@@ -436,6 +453,54 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa
436453 return nil
437454}
438455
456+ func ASIGenesisUpgradeASISupply (jsonData map [string ]interface {}, networkInfo NetworkConfig ) {
457+ denomInfo := networkInfo .DenomInfo
458+ supplyInfo := networkInfo .SupplyInfo
459+ additionalSupply , ok := sdk .NewIntFromString (supplyInfo .SupplyToMint )
460+ if ! ok {
461+ panic ("asi upgrade update supply: failed to convert new supply value to int" )
462+ }
463+
464+ if additionalSupply .LT (sdk .ZeroInt ()) {
465+ panic ("asi upgrade update supply: additional supply value is negative" )
466+ }
467+
468+ bank := jsonData [banktypes .ModuleName ].(map [string ]interface {})
469+ supply := bank ["supply" ].([]interface {})
470+ balances := bank ["balances" ].([]interface {})
471+ balancesMap := getGenesisBalancesMap (bank ["balances" ].([]interface {}))
472+
473+ var curSupply sdk.Int
474+ var curSupplyIdx int
475+ for idx , coin := range supply {
476+ coinData := coin .(map [string ]interface {})
477+ if coinData ["denom" ] == denomInfo .NewDenom {
478+ curSupplyIdx = idx
479+ curSupply , ok = sdk .NewIntFromString (coinData ["amount" ].(string ))
480+ if ! ok {
481+ panic ("asi upgrade update supply: failed to convert coin amount to int" )
482+ }
483+ break
484+ }
485+ }
486+
487+ overflowAddressBalance := balances [(* balancesMap )[supplyInfo .UpdatedSupplyOverflowAddr ]]
488+ overflowAddressBalanceCoins := getCoinsFromInterfaceSlice (overflowAddressBalance )
489+
490+ additionalSupplyCoin := sdk .NewCoin (denomInfo .NewDenom , additionalSupply )
491+ curSupplyCoin := sdk .NewCoin (denomInfo .NewDenom , curSupply )
492+
493+ // add new coins to the current supply
494+ newSupplyCoins := curSupplyCoin .Add (additionalSupplyCoin )
495+
496+ // add the additional coins to the overflow address balance
497+ overflowAddressBalanceCoins = overflowAddressBalanceCoins .Add (additionalSupplyCoin )
498+
499+ // update the supply in the bank module
500+ supply [curSupplyIdx ].(map [string ]interface {})["amount" ] = newSupplyCoins .Amount .String ()
501+ balances [(* balancesMap )[supplyInfo .UpdatedSupplyOverflowAddr ]].(map [string ]interface {})["coins" ] = getInterfaceSliceFromCoins (overflowAddressBalanceCoins )
502+ }
503+
439504func convertAddressToASI (addr string , addressPrefix string ) (string , error ) {
440505 _ , decodedAddrData , err := bech32 .Decode (addr )
441506 if err != nil {
@@ -497,7 +562,7 @@ func getCoinsFromInterfaceSlice(data interface{}) sdk.Coins {
497562 coinDenom := coinData ["denom" ].(string )
498563 coinAmount , ok := sdk .NewIntFromString (coinData ["amount" ].(string ))
499564 if ! ok {
500- panic ("IBC withdraw: failed to convert coin amount to int" )
565+ panic ("ibc withdraw: failed to convert coin amount to int" )
501566 }
502567 balanceCoins = append (balanceCoins , sdk .NewCoin (coinDenom , coinAmount ))
503568 }
@@ -520,8 +585,14 @@ type NetworkConfig struct {
520585 NewDescription string
521586 IbcTargetAddr string
522587 ReconciliationTargetAddr * string
523- Contracts * Contracts
588+ SupplyInfo SupplyInfo
524589 DenomInfo DenomInfo
590+ Contracts * Contracts
591+ }
592+
593+ type SupplyInfo struct {
594+ UpdatedSupplyOverflowAddr string
595+ SupplyToMint string
525596}
526597
527598type DenomInfo struct {
0 commit comments