Skip to content

Commit

Permalink
fix: remaining module balances (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 authored Oct 25, 2024
1 parent 2d56bb7 commit 215d101
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
26 changes: 26 additions & 0 deletions app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func ProcessSourceNetworkGenesis(logger log.Logger, cudosCfg *CudosMergeConfig,
return fmt.Errorf("cudos merge: failed to withdraw gravity: %w", err)
}

err = withdrawGenesisRemainingModulesBalance(genesisData, cudosCfg, manifest)
if err != nil {
return fmt.Errorf("cudos merge: failed to withdraw remaining modules balance: %w", err)
}

err = DoGenesisAccountMovements(genesisData, cudosCfg, manifest)
if err != nil {
return fmt.Errorf("cudos merge: failed to move funds: %w", err)
Expand Down Expand Up @@ -1960,6 +1965,27 @@ func checkDecTolerance(coins sdk.DecCoins, maxToleratedDiff sdk.Int) error {
return nil
}

func withdrawGenesisRemainingModulesBalance(genesisData *GenesisData, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) error {

if cudosCfg.Config.GenericModuleRemainingBalance == "" {
return fmt.Errorf("no remaining modules balances destination address provided")
}
for _, genesisAccountAddress := range genesisData.Accounts.Keys() {
genesisAccount := genesisData.Accounts.MustGet(genesisAccountAddress)
if genesisAccount.AccountType == ModuleAccountType && !genesisAccount.Balance.IsZero() {
memo := fmt.Sprintf("leftover_module_balance_%s", genesisAccount.Name)
err := moveGenesisBalance(genesisData, genesisAccountAddress, cudosCfg.Config.GenericModuleRemainingBalance, genesisAccount.Balance, memo, manifest, cudosCfg)
if err != nil {
return err
}

}

}

return nil
}

func withdrawGenesisGravity(genesisData *GenesisData, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) error {

gravityBalance := genesisData.Accounts.MustGet(genesisData.GravityModuleAccountAddress).Balance
Expand Down
15 changes: 9 additions & 6 deletions app/upgrade_network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var NetworkInfos = map[string]NetworkConfig{
RemainingGravityBalanceAddr: "cudos1qqz5ezf9ylgft0eq97d66v5aakynux540ds9mv", // Replace!!
RemainingDistributionBalanceAddr: "cudos1qqz5ezf9ylgft0eq97d66v5aakynux540ds9mv", // Replace!!
ContractDestinationFallbackAddr: "cudos1qqz5ezf9ylgft0eq97d66v5aakynux540ds9mv", // Replace!!
GenericModuleRemainingBalance: "cudos1qqz5ezf9ylgft0eq97d66v5aakynux540ds9mv", // Replace!!

CommissionFetchAddr: "fetch122j02czdt5ca8cf576wy2hassyxyx67wg5xmgc", // Replace!!
ExtraSupplyFetchAddr: "fetch122j02czdt5ca8cf576wy2hassyxyx67wg5xmgc", // Replace!!
Expand Down Expand Up @@ -154,6 +155,7 @@ var NetworkInfos = map[string]NetworkConfig{
RemainingGravityBalanceAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",
RemainingDistributionBalanceAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",
ContractDestinationFallbackAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",
GenericModuleRemainingBalance: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",

CommissionFetchAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // Fetch ecosystem wallet
ExtraSupplyFetchAddr: "fetch1wp8fl6fl4je40cfh2reeyj6cvucve9s6antdav",
Expand Down Expand Up @@ -332,12 +334,13 @@ func LoadAndVerifyNetworkConfigFromFile(configFilePath string, expectedSha256Hex
}

type CudosMergeConfigJSON struct {
IbcTargetAddr string `json:"ibc_target_addr"` // Cudos address
RemainingStakingBalanceAddr string `json:"remaining_staking_balance_addr"` // Cudos account for remaining bonded and not-bonded pool balances
RemainingGravityBalanceAddr string `json:"remaining_gravity_balance_addr"` // Cudos address
RemainingDistributionBalanceAddr string `json:"remaining_distribution_balance_addr"` // Cudos address
ContractDestinationFallbackAddr string `json:"contract_destination_fallback_addr"` // Cudos address
CommunityPoolBalanceDestAddr string `json:"community_pool_balance_dest_addr,omitempty"` // Cudos address, funds are moved to destination chain community pool if not set
IbcTargetAddr string `json:"ibc_target_addr"` // Cudos address
RemainingStakingBalanceAddr string `json:"remaining_staking_balance_addr"` // Cudos account for remaining bonded and not-bonded pool balances
RemainingGravityBalanceAddr string `json:"remaining_gravity_balance_addr"` // Cudos address
RemainingDistributionBalanceAddr string `json:"remaining_distribution_balance_addr"` // Cudos address
ContractDestinationFallbackAddr string `json:"contract_destination_fallback_addr"` // Cudos address
CommunityPoolBalanceDestAddr string `json:"community_pool_balance_dest_addr"` // Cudos address, funds are moved to destination chain community pool if not set
GenericModuleRemainingBalance string `json:"generic_module_remaining_balance"` // Cudos address for all leftover funds remaining on module accounts after the processing

CommissionFetchAddr string `json:"commission_fetch_addr"` // Fetch address for commission
ExtraSupplyFetchAddr string `json:"extra_supply_fetch_addr"` // Fetch address for extra supply
Expand Down
7 changes: 6 additions & 1 deletion cmd/fetchd/cmd/cudos_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ func VerifyConfigFile(configFilePath string, GenesisFilePath string, ctx client.
return fmt.Errorf("contract destination fallback address error: %v", err)
}

err = app.VerifyAddressPrefix(cudosConfig.Config.GenericModuleRemainingBalance, genesisData.Prefix)
if err != nil {
return fmt.Errorf("remaining general module balance address error: %v", err)
}

// Community pool address is optional
if cudosConfig.Config.CommunityPoolBalanceDestAddr != "" {
err = app.VerifyAddressPrefix(cudosConfig.Config.CommunityPoolBalanceDestAddr, genesisData.Prefix)
Expand Down Expand Up @@ -559,7 +564,7 @@ func ManifestAddressInfo(manifestFilePath string, address string, ctx client.Con
if err != nil {
return err
}

address, err = app.ConvertAddressPrefix(address, manifestData.sourcePrefix)
if err != nil {
return err
Expand Down

0 comments on commit 215d101

Please sign in to comment.