Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 committed Oct 7, 2024
1 parent a773ea4 commit 50e5c8f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 81 deletions.
84 changes: 37 additions & 47 deletions app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const (
ValAddressPrefix = "valoper"
ConsAddressPrefix = "valcons"

NewAddrPrefix = "fetch"

FlagGenesisTime = "genesis-time"

ModuleAccount = "/cosmos.auth.v1beta1.ModuleAccount"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down
11 changes: 2 additions & 9 deletions app/upgrade_cudos_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
34 changes: 9 additions & 25 deletions app/upgrade_v_11_4_network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ var NetworkInfos = map[string]NetworkConfig{
VestingCollisionDestAddr: "fetch122j02czdt5ca8cf576wy2hassyxyx67wg5xmgc", // Replace!!
CommunityPoolBalanceDestAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",

NewAddrPrefix: "fetch",
OldAddrPrefix: "cudos",
SourceChainAddressPrefix: "cudos",

OriginalDenom: "acudos",
ConvertedDenom: "afet",
Expand Down Expand Up @@ -145,8 +144,7 @@ var NetworkInfos = map[string]NetworkConfig{
VestingCollisionDestAddr: "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5",
//CommunityPoolBalanceDestAddr: "cudos1dslwarknhfsw3pfjzxxf5mn28q3ewfectw0gta",

NewAddrPrefix: "fetch",
OldAddrPrefix: "cudos",
SourceChainAddressPrefix: "cudos",

OriginalDenom: "acudos",
ConvertedDenom: "atestfet",
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 50e5c8f

Please sign in to comment.