diff --git a/app/upgrade_cudos.go b/app/upgrade_cudos.go index 7608c49a..d974ecc0 100644 --- a/app/upgrade_cudos.go +++ b/app/upgrade_cudos.go @@ -34,8 +34,6 @@ const ( ValAddressPrefix = "valoper" ConsAddressPrefix = "valcons" - NewAddrPrefix = "fetch" - FlagGenesisTime = "genesis-time" ModuleAccount = "/cosmos.auth.v1beta1.ModuleAccount" @@ -64,24 +62,6 @@ const ( RecursionDepthLimit = 50 ) -func convertAddressToFetch(addr string, addressPrefix string) (string, error) { - _, decodedAddrData, err := bech32.DecodeAndConvert(addr) - if err != nil { - return "", err - } - - newAddress, err := bech32.ConvertAndEncode(NewAddrPrefix+addressPrefix, decodedAddrData) - if err != nil { - return "", err - } - - err = sdk.VerifyAddressFormat(decodedAddrData) - if err != nil { - return "", err - } - - return newAddress, nil -} func convertAddressPrefix(addr string, newPrefix string) (string, error) { _, decodedAddrData, err := bech32.DecodeAndConvert(addr) if err != nil { @@ -99,7 +79,7 @@ func convertAddressPrefix(addr string, newPrefix string) (string, error) { func convertAddressToRaw(addr string, cudosCfg *CudosMergeConfig) (sdk.AccAddress, error) { prefix, decodedAddrData, err := bech32.DecodeAndConvert(addr) - if prefix != cudosCfg.config.OldAddrPrefix { + if prefix != cudosCfg.config.SourceChainAddressPrefix { return nil, fmt.Errorf("unknown prefix: %s", prefix) } @@ -878,31 +858,46 @@ func createDelegation(ctx sdk.Context, app *App, originalValidator string, newDe return nil } -func fundCommunityPool(ctx sdk.Context, app *App, genesisData *GenesisData, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) error { +func handleCommunityPoolBalance(ctx sdk.Context, app *App, genesisData *GenesisData, cudosCfg *CudosMergeConfig, manifest *UpgradeManifest) error { + // Get addresses and amounts - cudosCommunityPoolFundsAccount := genesisData.accounts.MustGet(cudosCfg.config.RemainingDistributionBalanceAddr) + RemainingDistributionBalanceAccount := genesisData.accounts.MustGet(cudosCfg.config.RemainingDistributionBalanceAddr) communityPoolBalance, _ := genesisData.distributionInfo.feePool.communityPool.TruncateDecimal() convertedCommunityPoolBalance, err := convertBalance(communityPoolBalance, cudosCfg) if err != nil { return err } - // Mint balance to distribution leftover address - err = migrateToAccount(ctx, app, minttypes.ModuleName, cudosCommunityPoolFundsAccount.rawAddress, communityPoolBalance, convertedCommunityPoolBalance, "community_pool_balance", manifest) - if err != nil { - return err - } + if cudosCfg.config.CommunityPoolBalanceDestAddr == "" { + // If community pool balance destination address is not we move community pool balance to destination chain community pool - // Move balance to destination chain community pool - err = app.DistrKeeper.FundCommunityPool(ctx, convertedCommunityPoolBalance, cudosCommunityPoolFundsAccount.rawAddress) - if err != nil { - return err - } + // Mint balance to distribution leftover address + err = migrateToAccount(ctx, app, minttypes.ModuleName, RemainingDistributionBalanceAccount.rawAddress, communityPoolBalance, convertedCommunityPoolBalance, "community_pool_balance", manifest) + if err != nil { + return err + } + + // Move balance to destination chain community pool + err = app.DistrKeeper.FundCommunityPool(ctx, convertedCommunityPoolBalance, RemainingDistributionBalanceAccount.rawAddress) + if err != nil { + return err + } + + // Subtract balance from genesis balances + err = removeGenesisBalance(genesisData, cudosCfg.config.RemainingDistributionBalanceAddr, communityPoolBalance, "community_pool_balance", manifest) + if err != nil { + return err + } + + } else { + // If community pool destination balance is set we move community pool tokens there. + if cudosCfg.config.CommunityPoolBalanceDestAddr != "" { + err = moveGenesisBalance(genesisData, RemainingDistributionBalanceAccount.address, cudosCfg.config.CommunityPoolBalanceDestAddr, communityPoolBalance, "community_pool_balance", manifest, cudosCfg) + if err != nil { + return fmt.Errorf("failed to move community pool balance %w", err) + } + } - // Subtract balance from genesis balances - err = removeGenesisBalance(genesisData, cudosCfg.config.RemainingDistributionBalanceAddr, communityPoolBalance, "community_pool_balance", manifest) - if err != nil { - return err } return nil @@ -1197,7 +1192,7 @@ func parseGenesisIBCAccounts(jsonData map[string]interface{}, cudosCfg *CudosMer } rawAddr := ibctransfertypes.GetEscrowAddress(portId, channelId) - channelAddr, err := sdk.Bech32ifyAddressBytes(cudosCfg.config.OldAddrPrefix, rawAddr) + channelAddr, err := sdk.Bech32ifyAddressBytes(cudosCfg.config.SourceChainAddressPrefix, rawAddr) if err != nil { return nil, err } @@ -1795,7 +1790,7 @@ func MigrateGenesisAccounts(genesisData *GenesisData, ctx sdk.Context, app *App, err = migrateToAccount(ctx, app, "mint_module", commissionRawAcc, sdk.NewCoins(), totalCommission, "total_commission", manifest) extraSupplyInCudos := cudosCfg.config.TotalCudosSupply.Sub(genesisData.totalSupply.AmountOf(cudosCfg.config.OriginalDenom)) - extraSupplyCudosAddress, err := convertAddressPrefix(cudosCfg.config.ExtraSupplyFetchAddr, cudosCfg.config.OldAddrPrefix) + extraSupplyCudosAddress, err := convertAddressPrefix(cudosCfg.config.ExtraSupplyFetchAddr, cudosCfg.config.SourceChainAddressPrefix) if err != nil { return err } @@ -1807,15 +1802,10 @@ func MigrateGenesisAccounts(genesisData *GenesisData, ctx sdk.Context, app *App, return err } - if cudosCfg.config.CommunityPoolBalanceDestAddr == "" { - // Move balance to community pool if destination address is not set - - err := fundCommunityPool(ctx, app, genesisData, cudosCfg, manifest) - if err != nil { - return fmt.Errorf("failed to fund community pool: %w", err) - } + err = handleCommunityPoolBalance(ctx, app, genesisData, cudosCfg, manifest) + if err != nil { + return fmt.Errorf("failed to handle community pool balance: %w", err) } - // Else accounts were moved in cash before minting // Mint the rest of the supply for _, genesisAccountAddress := range genesisData.accounts.Keys() { diff --git a/app/upgrade_cudos_distribution.go b/app/upgrade_cudos_distribution.go index ae3e9ab5..230c61ce 100644 --- a/app/upgrade_cudos_distribution.go +++ b/app/upgrade_cudos_distribution.go @@ -396,13 +396,6 @@ func withdrawGenesisDistributionRewards(app *App, genesisData *GenesisData, cudo distributionModuleAccount := genesisData.accounts.MustGet(genesisData.distributionInfo.distributionModuleAccountAddress) remainingBalance := distributionModuleAccount.balance.Sub(communityBalance) - // If community pool destination balance is set we move community pool tokens there. - if cudosCfg.config.CommunityPoolBalanceDestAddr != "" { - err := moveGenesisBalance(genesisData, genesisData.distributionInfo.distributionModuleAccountAddress, cudosCfg.config.CommunityPoolBalanceDestAddr, communityBalance, "community_pool_balance", manifest, cudosCfg) - if err != nil { - return fmt.Errorf("failed to move community pool balance %w", err) - } - } // Withdraw remaining balance app.Logger().Info("cudos merge: remaining dist balance", "amount", remainingBalance.String()) @@ -426,7 +419,7 @@ func withdrawAccumulatedCommissions(genesisData *GenesisData, cudosCfg *CudosMer for _, validatorAddress := range genesisData.distributionInfo.validatorAccumulatedCommissions.Keys() { accumulatedCommission := genesisData.distributionInfo.validatorAccumulatedCommissions.MustGet(validatorAddress) - accountAddress, err := convertAddressPrefix(validatorAddress, cudosCfg.config.OldAddrPrefix) + accountAddress, err := convertAddressPrefix(validatorAddress, cudosCfg.config.SourceChainAddressPrefix) if err != nil { return err } @@ -447,7 +440,7 @@ func withdrawValidatorOutstandingRewards(genesisData *GenesisData, cudosCfg *Cud for _, validatorAddress := range genesisData.distributionInfo.outstandingRewards.Keys() { outstandingRewards := genesisData.distributionInfo.outstandingRewards.MustGet(validatorAddress) - accountAddress, err := convertAddressPrefix(validatorAddress, cudosCfg.config.OldAddrPrefix) + accountAddress, err := convertAddressPrefix(validatorAddress, cudosCfg.config.SourceChainAddressPrefix) if err != nil { return err } diff --git a/app/upgrade_v_11_4_network_config.go b/app/upgrade_v_11_4_network_config.go index 87daed2b..5e5dff81 100644 --- a/app/upgrade_v_11_4_network_config.go +++ b/app/upgrade_v_11_4_network_config.go @@ -71,8 +71,7 @@ var NetworkInfos = map[string]NetworkConfig{ VestingCollisionDestAddr: "fetch122j02czdt5ca8cf576wy2hassyxyx67wg5xmgc", // Replace!! CommunityPoolBalanceDestAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5", - NewAddrPrefix: "fetch", - OldAddrPrefix: "cudos", + SourceChainAddressPrefix: "cudos", OriginalDenom: "acudos", ConvertedDenom: "afet", @@ -145,8 +144,7 @@ var NetworkInfos = map[string]NetworkConfig{ VestingCollisionDestAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5", //CommunityPoolBalanceDestAddr: "cudos1dslwarknhfsw3pfjzxxf5mn28q3ewfectw0gta", - NewAddrPrefix: "fetch", - OldAddrPrefix: "cudos", + SourceChainAddressPrefix: "cudos", OriginalDenom: "acudos", ConvertedDenom: "atestfet", @@ -320,8 +318,7 @@ type CudosMergeConfigJSON struct { ExtraSupplyFetchAddr string `json:"extra_supply_fetch_addr"` // Fetch address for extra supply VestingCollisionDestAddr string `json:"vesting_collision_dest_addr"` // This gets converted to raw address, so it can be fetch or cudos address - NewAddrPrefix string `json:"new_addr_prefix"` - OldAddrPrefix string `json:"old_addr_prefix"` + SourceChainAddressPrefix string `json:"old_addr_prefix"` OriginalDenom string `json:"original_denom"` ConvertedDenom string `json:"converted_denom"` @@ -365,25 +362,12 @@ func NewCudosMergeConfig(config *CudosMergeConfigJSON) *CudosMergeConfig { retval.MovedAccounts = NewOrderedMapFromPairs(config.MovedAccounts) retval.validatorsMap = NewOrderedMapFromPairs(config.ValidatorsMap) - //for _, exchangeRate := range config.BalanceConversionConstants { - // retval.BalanceConversionConstants.SetNew(exchangeRate.Denom, exchangeRate.ExchangeRate) - //} - - //for _, account := range config.NotVestedAccounts { - // retval.NotVestedAccounts.SetNew(account, true) - //} - - //for _, account := range config.NotDelegatedAccounts { - // retval.NotDelegatedAccounts.SetNew(account, true) - //} - - //for _, account := range config.MovedAccounts { - // retval.MovedAccounts.SetNew(account.FromAccountAddr, account.ToAccountAddr) - //} - - //for _, validator := range config.ValidatorsMap { - // retval.ValidatorsMap.SetNew(validator.FromCudosValidatorOperatorAddr, validator.ToFetchValidatorOperatorOperAddr) - //} + // Ensure that commission address won't be vested + commissionCudosAddress, err := convertAddressPrefix(config.CommissionFetchAddr, config.SourceChainAddressPrefix) + if err != nil { + return nil + } + retval.notVestedAccounts.Set(commissionCudosAddress, true) return retval }