Skip to content

Commit

Permalink
feat: CUDOS Manifest balance breakdown (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 authored Oct 21, 2024
1 parent 39cc68d commit cb2b396
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions app/upgrade_v_11_4_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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) {
Expand Down

0 comments on commit cb2b396

Please sign in to comment.