Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ASI test tweaks #359

Merged
merged 5 commits into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 59 additions & 42 deletions cmd/fetchd/cmd/genesis-asi-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ var networkInfos = map[string]NetworkConfig{
OldDenom: "afet",
},
SupplyInfo: SupplyInfo{
SupplyToMint: "100000000000000000000000000", // TODO(JS): likely amend this
SupplyToMint: "0", // TODO(JS): likely amend this
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
},
IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
ReconciliationTargetAddr: &ReconciliationTargetAddr, // TODO(JS): amend this
Contracts: &Contracts{
Almanac: &Almanac{
Addr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y", // mainnet STAGING contract,
StagingAddr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y", // mainnet STAGING contract,
},
AName: &AName{
Addr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q", // mainnet DEVELOPMENT contract,
StagingAddr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q", // mainnet STAGING contract,
},
MobixStaking: &MobixStaking{
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e", // TODO(JS): amend this
Expand All @@ -101,32 +101,34 @@ var networkInfos = map[string]NetworkConfig{
},

"dorado-1": {
NewChainID: "asi-1", // TODO(JS): likely amend this
NewChainID: "eridanus-1",
NewDescription: "Test ASI token", // TODO(JS): confirm this
DenomInfo: DenomInfo{
NewBaseDenom: "testasi",
NewDenom: "atestasi",
OldDenom: "atestfet",
},
SupplyInfo: SupplyInfo{
SupplyToMint: "100000000000000000000000000", // TODO(JS): likely amend this
SupplyToMint: "0", // TODO(JS): likely amend this
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
},
IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
//IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
Contracts: &Contracts{
Almanac: &Almanac{
Addr: "fetch135h26ys2nwqealykzey532gamw4l4s07aewpwc0cyd8z6m92vyhsplf0vp", // testnet DEVELOPMENT contract,
StagingAddr: "fetch1tjagw8g8nn4cwuw00cf0m5tl4l6wfw9c0ue507fhx9e3yrsck8zs0l3q4w", // testnet STAGING contract,
DevAddr: "fetch135h26ys2nwqealykzey532gamw4l4s07aewpwc0cyd8z6m92vyhsplf0vp", // testnet DEVELOPMENT contract,
},
AName: &AName{
Addr: "fetch1kewgfwxwtuxcnppr547wj6sd0e5fkckyp48dazsh89hll59epgpspmh0tn", // testnet DEVELOPMENT contract,
DevAddr: "fetch1kewgfwxwtuxcnppr547wj6sd0e5fkckyp48dazsh89hll59epgpspmh0tn", // testnet DEVELOPMENT contract,
StagingAddr: "fetch1mxz8kn3l5ksaftx8a9pj9a6prpzk2uhxnqdkwuqvuh37tw80xu6qges77l", // testnet STAGING contract,
},
MobixStaking: &MobixStaking{
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e",
},
TokenBridge: &TokenBridge{
Addr: "fetch1kewgfwxwtuxcnppr547wj6sd0e5fkckyp48dazsh89hll59epgpspmh0tn",
NewAdmin: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw",
},
//TokenBridge: &TokenBridge{
// Addr: "",
// NewAdmin: "",
//},
FccCw20: &FccCw20{
Addr: "fetch1s0p7pwtm8qhvh2sfpg0ajgl20hwtehr0vcztyeku0vkzzvg044xqx4t7pt",
},
Expand Down Expand Up @@ -209,16 +211,10 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
ASIGenesisUpgradeUpdateFccIssuanceContract(jsonData, networkConfig)

// withdraw balances from IBC channels
if err = ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData, networkConfig, &manifest); err != nil {
return err
}
ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData, networkConfig, &manifest)

// withdraw balances from reconciliation addresses
if networkConfig.ReconciliationTargetAddr != nil {
if err = ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData, networkConfig, &manifest); err != nil {
return err
}
}
ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData, networkConfig, &manifest)

// set denom metadata in bank module
ASIGenesisUpgradeReplaceDenomMetadata(jsonData, networkConfig)
Expand Down Expand Up @@ -274,6 +270,9 @@ func replaceAddressInContractStateKey2(keyBytes []byte, prefix []byte) string {
panic(err)
}

// set to new address length
address1Len = len(address1)

var buffer bytes.Buffer
writer := bufio.NewWriter(&buffer)

Expand Down Expand Up @@ -607,23 +606,33 @@ func ASIGenesisUpgradeReplaceAlmanacState(jsonData map[string]interface{}, netwo
return
}

almanacContractAddress := networkInfo.Contracts.Almanac.Addr
almanacContract := getContractFromAddr(almanacContractAddress, jsonData)
for _, addr := range []string{networkInfo.Contracts.Almanac.StagingAddr, networkInfo.Contracts.Almanac.DevAddr} {
if addr == "" {
continue
}

almanacContract := getContractFromAddr(addr, jsonData)

// empty the almanac contract state
almanacContract["contract_state"] = []interface{}{}
// empty the almanac contract state
almanacContract["contract_state"] = []interface{}{}
}
}

func ASIGenesisUpgradeReplaceANameState(jsonData map[string]interface{}, networkInfo NetworkConfig) {
if networkInfo.Contracts != nil && networkInfo.Contracts.AName != nil {
if networkInfo.Contracts == nil || networkInfo.Contracts.AName == nil {
return
}

anameContractAddress := networkInfo.Contracts.AName.Addr
anameContract := getContractFromAddr(anameContractAddress, jsonData)
for _, addr := range []string{networkInfo.Contracts.AName.StagingAddr, networkInfo.Contracts.AName.DevAddr} {
if addr == "" {
continue
}

anameContract := getContractFromAddr(addr, jsonData)

// empty the AName contract state
anameContract["contract_state"] = []interface{}{}
// empty the AName contract state
anameContract["contract_state"] = []interface{}{}
}
}

func getContractFromAddr(addr string, jsonData map[string]interface{}) map[string]interface{} {
Expand Down Expand Up @@ -666,7 +675,11 @@ func replaceAddresses(addressTypePrefix string, jsonData map[string]interface{},
})
}

func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) error {
func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
if networkInfo.IbcTargetAddr == "" {
return
}

bank := jsonData[banktypes.ModuleName].(map[string]interface{})
balances := bank["balances"].([]interface{})
balanceMap := getGenesisBalancesMap(balances)
Expand All @@ -678,8 +691,7 @@ func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{
}
withdrawalBalanceIdx, ok := (*balanceMap)[ibcWithdrawalAddress]
if !ok {
fmt.Println("failed to find ibc withdrawal address in genesis balances - have addresses already been converted?")
return nil
panic("failed to find ibc withdrawal address in genesis balances - have addresses already been converted?")
}

ibc := jsonData[ibccore.ModuleName].(map[string]interface{})
Expand All @@ -697,7 +709,7 @@ func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{
rawAddr := ibctransfertypes.GetEscrowAddress(portId, channelId)
channelAddr, err := sdk.Bech32ifyAddressBytes(OldAddrPrefix+AccAddressPrefix, rawAddr)
if err != nil {
return fmt.Errorf("failed to bech32ify address: %w", err)
panic(err)
}

balanceIdx, ok := (*balanceMap)[channelAddr]
Expand All @@ -718,8 +730,6 @@ func ASIGenesisUpgradeWithdrawIBCChannelsBalances(jsonData map[string]interface{
// zero out the channel balance
balances[balanceIdx].(map[string]interface{})["coins"] = []interface{}{}
}

return nil
}

func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
Expand Down Expand Up @@ -749,7 +759,11 @@ func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
return &accountMap
}

func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) error {
func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
if networkInfo.ReconciliationTargetAddr == nil {
return
}

bank := jsonData[banktypes.ModuleName].(map[string]interface{})
balances := bank["balances"].([]interface{})
reconciliationWithdrawAddress := networkInfo.ReconciliationTargetAddr
Expand All @@ -769,7 +783,7 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa

reconciliationBalanceIdx, ok := (*balanceMap)[*reconciliationWithdrawAddress]
if !ok {
return fmt.Errorf("no match in genesis for reconciliation address: %s", *reconciliationWithdrawAddress)
panic("no match in genesis for reconciliation withdraw address")
}

manifest.Reconciliation = &ASIUpgradeTransfers{
Expand All @@ -784,7 +798,7 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa

accSequence, ok := (*accountSequenceMap)[addr]
if !ok {
return fmt.Errorf("no match in genesis for reconciliation address: %s", addr)
panic("no match in genesis for reconciliation address")
}

balanceIdx, ok := (*balanceMap)[addr]
Expand Down Expand Up @@ -812,7 +826,6 @@ func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interfa
// zero out the reconciliation account balance
balances[balanceIdx].(map[string]interface{})["coins"] = []interface{}{}
}
return nil
}

func ASIGenesisUpgradeASISupply(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
Expand All @@ -823,7 +836,9 @@ func ASIGenesisUpgradeASISupply(jsonData map[string]interface{}, networkInfo Net
panic("asi upgrade update supply: failed to convert new supply value to int")
}

if additionalSupply.LT(sdk.ZeroInt()) {
if additionalSupply.IsZero() {
return
} else if additionalSupply.LT(sdk.ZeroInt()) {
panic("asi upgrade update supply: additional supply value is negative")
}

Expand Down Expand Up @@ -986,11 +1001,13 @@ type TokenBridge struct {
}

type Almanac struct {
Addr string
DevAddr string
StagingAddr string
}

type AName struct {
Addr string
DevAddr string
StagingAddr string
}

type MobixStaking struct {
Expand Down
Loading