From cb2b39627a0647c248c38ace1e8a68d892b2e8a8 Mon Sep 17 00:00:00 2001 From: Jiri Vestfal <45360788+MissingNO57@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:35:25 +0200 Subject: [PATCH] feat: CUDOS Manifest balance breakdown (#405) --- app/upgrade_cudos.go | 21 ++++++++++++++++----- app/upgrade_v_11_4_manifest.go | 10 ++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/upgrade_cudos.go b/app/upgrade_cudos.go index f5c2cc08..d81e7611 100644 --- a/app/upgrade_cudos.go +++ b/app/upgrade_cudos.go @@ -243,11 +243,14 @@ func writeMovedBalancesToManifest(genesisData *GenesisData, manifest *UpgradeMan if delegations, exists := genesisData.Delegations.Get(address); exists { bondedBalance := sdk.Coins{} for i := range delegations.Iterate() { - _, delegatedAmount := i.Key, i.Value + validatorOperatorAddr, delegatedAmount := i.Key, i.Value delegatedBalance := sdk.NewCoin(genesisData.BondDenom, delegatedAmount) bondedBalance = bondedBalance.Add(delegatedBalance) + upgradeBalance.BondedStakingBalances = append(upgradeBalance.BondedStakingBalances, ValidatorBalance{Validator: validatorOperatorAddr, Balance: sdk.NewCoins(delegatedBalance)}) } + upgradeBalance.BondedStakingBalancesAggr = bondedBalance + // Bonded balance is part of the bank balance in this case, so we need to subtract it upgradeBalance.BankBalance = upgradeBalance.BankBalance.Sub(bondedBalance) } @@ -280,9 +283,12 @@ func writeInitialBalancesToManifest(genesisData *GenesisData, manifest *UpgradeM if delegations, exists := genesisData.Delegations.Get(address); exists { totalBalance := sdk.Coins{} for i := range delegations.Iterate() { - _, delegatedAmount := i.Key, i.Value + validatorOperatorAddr, delegatedAmount := i.Key, i.Value delegatedBalance := sdk.NewCoin(genesisData.BondDenom, delegatedAmount) totalBalance = totalBalance.Add(delegatedBalance) + + upgradeBalance.BondedStakingBalances = append(upgradeBalance.BondedStakingBalances, ValidatorBalance{Validator: validatorOperatorAddr, Balance: sdk.NewCoins(delegatedBalance)}) + } upgradeBalance.BondedStakingBalancesAggr = totalBalance } @@ -291,9 +297,10 @@ func writeInitialBalancesToManifest(genesisData *GenesisData, manifest *UpgradeM if delegations, exists := genesisData.UnbondingDelegations.Get(address); exists { totalBalance := sdk.Coins{} for i := range delegations.Iterate() { - _, delegatedAmount := i.Key, i.Value + validatorOperatorAddr, delegatedAmount := i.Key, i.Value delegatedBalance := sdk.NewCoin(genesisData.BondDenom, delegatedAmount) totalBalance = totalBalance.Add(delegatedBalance) + upgradeBalance.UnbondingStakingBalances = append(upgradeBalance.UnbondingStakingBalances, ValidatorBalance{Validator: validatorOperatorAddr, Balance: sdk.NewCoins(delegatedBalance)}) } upgradeBalance.UnbondingStakingBalancesAggr = totalBalance } @@ -302,9 +309,11 @@ func writeInitialBalancesToManifest(genesisData *GenesisData, manifest *UpgradeM if delegations, exists := genesisData.UnbondedDelegations.Get(address); exists { totalBalance := sdk.Coins{} for i := range delegations.Iterate() { - _, delegatedAmount := i.Key, i.Value + validatorOperatorAddr, delegatedAmount := i.Key, i.Value delegatedBalance := sdk.NewCoin(genesisData.BondDenom, delegatedAmount) totalBalance = totalBalance.Add(delegatedBalance) + upgradeBalance.UnbondedStakingBalances = append(upgradeBalance.UnbondedStakingBalances, ValidatorBalance{Validator: validatorOperatorAddr, Balance: sdk.NewCoins(delegatedBalance)}) + } upgradeBalance.UnbondedStakingBalancesAggr = totalBalance } @@ -313,11 +322,13 @@ func writeInitialBalancesToManifest(genesisData *GenesisData, manifest *UpgradeM if DelegatorRewards, exists := genesisData.DistributionInfo.Rewards.Get(address); exists { totalBalance := sdk.Coins{} for j := range DelegatorRewards.Iterate() { - _, rewardDecAmount := j.Key, j.Value + validatorOperatorAddr, rewardDecAmount := j.Key, j.Value rewardAmount, _ := rewardDecAmount.TruncateDecimal() if !rewardAmount.IsZero() { totalBalance = totalBalance.Add(rewardAmount...) + upgradeBalance.DelegatorRewards = append(upgradeBalance.DelegatorRewards, ValidatorBalance{Validator: validatorOperatorAddr, Balance: rewardAmount}) } + } upgradeBalance.DelegatorRewardsAggr = totalBalance } diff --git a/app/upgrade_v_11_4_manifest.go b/app/upgrade_v_11_4_manifest.go index ce039120..dbda7c66 100644 --- a/app/upgrade_v_11_4_manifest.go +++ b/app/upgrade_v_11_4_manifest.go @@ -188,6 +188,11 @@ type UpgradeAccountCreation struct { Reason string `json:"reason"` } +type ValidatorBalance struct { + Validator string `json:"validator"` + Balance types.Coins `json:"balance"` +} + type UpgradeBalances struct { Address string `json:"address"` BankBalance types.Coins `json:"bank_balance"` @@ -197,6 +202,11 @@ type UpgradeBalances struct { UnbondingStakingBalancesAggr types.Coins `json:"unbonding_staking_balances_aggr,omitempty"` DelegatorRewardsAggr types.Coins `json:"delegator_rewards_aggr,omitempty"` ValidatorRewards types.Coins `json:"validator_rewards,omitempty"` + + BondedStakingBalances []ValidatorBalance `json:"bonded_staking_balances,omitempty"` + UnbondedStakingBalances []ValidatorBalance `json:"unbonded_staking_balances,omitempty"` + UnbondingStakingBalances []ValidatorBalance `json:"unbonding_staking_balances,omitempty"` + DelegatorRewards []ValidatorBalance `json:"delegator_rewards,omitempty"` } func getManifestFilePath(app *App, prefix string) (string, error) {