Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V18 Upgrade Migrations #1084

Merged
merged 41 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dbfc0c3
re-fetched updated records after refresh
sampocs Jan 16, 2024
df83c77
added unit test for native refresh
sampocs Jan 17, 2024
910490d
Merge branch 'main' into reload-after-refresh
sampocs Jan 17, 2024
8354eaa
add upgrade handler
shellvish Jan 18, 2024
ff6fbab
Merge remote-tracking branch 'origin/reload-after-refresh' into v18-u…
shellvish Jan 18, 2024
c67c9f9
remove hub tokenizations
shellvish Jan 18, 2024
a3bd21c
migrate URRs
shellvish Jan 19, 2024
6552b59
set host zone unbonding at end of migration
shellvish Jan 19, 2024
a1773ab
nit changes
sampocs Jan 25, 2024
a66d8c4
Update x/stakeibc/keeper/unbonding_records.go
shellvish Jan 25, 2024
c3beefa
added constants file
sampocs Jan 25, 2024
421b1e6
switched to using redemption rate instead of unbond amount
sampocs Jan 25, 2024
9ac0359
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 25, 2024
02784bf
nit
sampocs Jan 25, 2024
ecfbd8b
nit
sampocs Jan 25, 2024
2759211
bugs
sampocs Jan 25, 2024
ebe7c3d
unit test
sampocs Jan 26, 2024
6403334
added starting epoch catch
sampocs Jan 26, 2024
3ae173c
Merge branch 'main' into v18-upgrade-migrations
asalzmann Jan 26, 2024
59d980a
add store key (#1088)
asalzmann Jan 26, 2024
72113ff
added upgrade unit test
sampocs Jan 26, 2024
98db45a
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
51eb82b
decrement terra delegations in progress by 3 in upgrade (#1089)
riley-stride Jan 26, 2024
3d9e44d
fixed unbonding unit tests (#1090)
sampocs Jan 26, 2024
f5ec490
added test case for status
sampocs Jan 26, 2024
ad69282
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
78b0e5f
lint fix
sampocs Jan 26, 2024
a73128a
added additional upgrade unit tests
sampocs Jan 26, 2024
ea02062
nit
sampocs Jan 26, 2024
289e922
nit
sampocs Jan 26, 2024
2f2f290
update constants
shellvish Jan 26, 2024
64fa722
Revert "update constants"
shellvish Jan 26, 2024
86c642d
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
bc3ec3d
Update constants.go
shellvish Jan 26, 2024
7f36d24
update starting estimate
shellvish Jan 26, 2024
1f06083
Update constants.go
shellvish Jan 26, 2024
5912787
Signaling prop in upgrade (#1092)
sampocs Jan 26, 2024
f9dea85
update constants with most recent data
shellvish Jan 26, 2024
0dd8f75
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
011a78a
fixed unit test after refresh
sampocs Jan 26, 2024
56602ca
Merge branch 'main' into v18-upgrade-migrations
sampocs Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
v15 "github.com/Stride-Labs/stride/v17/app/upgrades/v15"
v16 "github.com/Stride-Labs/stride/v17/app/upgrades/v16"
v17 "github.com/Stride-Labs/stride/v17/app/upgrades/v17"
v18 "github.com/Stride-Labs/stride/v17/app/upgrades/v18"
v2 "github.com/Stride-Labs/stride/v17/app/upgrades/v2"
v3 "github.com/Stride-Labs/stride/v17/app/upgrades/v3"
v4 "github.com/Stride-Labs/stride/v17/app/upgrades/v4"
Expand Down Expand Up @@ -232,6 +233,17 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
),
)

// v18 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v18.UpgradeName,
v18.CreateUpgradeHandler(
app.mm,
app.configurator,
app.StakeibcKeeper,
app.RecordsKeeper,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand Down
252 changes: 252 additions & 0 deletions app/upgrades/v18/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
package v18

import sdk "github.com/cosmos/cosmos-sdk/types"

var (
UpgradeName = "v18"

// Redemption rate bounds updated to give ~3 months of slack on outer bounds
RedemptionRateOuterMinAdjustment = sdk.MustNewDecFromStr("0.05")
RedemptionRateOuterMaxAdjustment = sdk.MustNewDecFromStr("0.10")

// Osmosis will have a slighly larger buffer with the redemption rate
// since their yield is less predictable
OsmosisChainId = "osmosis-1"
OsmosisRedemptionRateBuffer = sdk.MustNewDecFromStr("0.02")

// Get Initial Redemption Rates for Unbonding Records Migration
RedemptionRatesAtTimeOfProp = map[string]sdk.Dec{
"comdex-1": sdk.MustNewDecFromStr("1.204404927372203376"),
"cosmoshub-4": sdk.MustNewDecFromStr("1.299315098715274953"),
"evmos_9001-2": sdk.MustNewDecFromStr("1.492396096716486696"),
"injective-1": sdk.MustNewDecFromStr("1.215553256473652866"),
"juno-1": sdk.MustNewDecFromStr("1.418210972076073590"),
"osmosis-1": sdk.MustNewDecFromStr("1.201353579705385297"),
"phoenix-1": sdk.MustNewDecFromStr("1.178171857075037002"),
"sommelier-3": sdk.MustNewDecFromStr("1.025900883208774724"),
"stargaze-1": sdk.MustNewDecFromStr("1.429976684963222047"),
"umee-1": sdk.MustNewDecFromStr("1.128473850654652585"),
}

// Get Amount Unbonded for each HostZone for Unbonding Records Migration
RedemptionRatesBeforeProp = map[string]map[uint64]sdk.Dec{
sampocs marked this conversation as resolved.
Show resolved Hide resolved
"juno-1": {
480: sdk.MustNewDecFromStr("1.4053501787364933"),
481: sdk.MustNewDecFromStr("1.4053501787364933"),
482: sdk.MustNewDecFromStr("1.4053501787364933"),
484: sdk.MustNewDecFromStr("1.4053501787364933"),
487: sdk.MustNewDecFromStr("1.4087287741035914"),
488: sdk.MustNewDecFromStr("1.4087287741035914"),
489: sdk.MustNewDecFromStr("1.4087287741035914"),
490: sdk.MustNewDecFromStr("1.4099190036765492"),
491: sdk.MustNewDecFromStr("1.4099190036765492"),
493: sdk.MustNewDecFromStr("1.4099190036765492"),
494: sdk.MustNewDecFromStr("1.4099190036765492"),
495: sdk.MustNewDecFromStr("1.4138284392049727"),
496: sdk.MustNewDecFromStr("1.4138284392049727"),
497: sdk.MustNewDecFromStr("1.4138284392049727"),
500: sdk.MustNewDecFromStr("1.4161992241945822"),
501: sdk.MustNewDecFromStr("1.4161992241945822"),
503: sdk.MustNewDecFromStr("1.4161992241945822"),
504: sdk.MustNewDecFromStr("1.4161992241945822"),
505: sdk.MustNewDecFromStr("1.417724248601981"),
507: sdk.MustNewDecFromStr("1.417724248601981"),
508: sdk.MustNewDecFromStr("1.417724248601981"),
},
"phoenix-1": {
480: sdk.MustNewDecFromStr("1.1617706976314004"),
sampocs marked this conversation as resolved.
Show resolved Hide resolved
481: sdk.MustNewDecFromStr("1.1617706976314004"),
482: sdk.MustNewDecFromStr("1.1617706976314004"),
483: sdk.MustNewDecFromStr("1.1617706976314004"),
486: sdk.MustNewDecFromStr("1.1617706976314004"),
487: sdk.MustNewDecFromStr("1.1617706976314004"),
488: sdk.MustNewDecFromStr("1.1617706976314004"),
489: sdk.MustNewDecFromStr("1.1617706976314004"),
490: sdk.MustNewDecFromStr("1.1617706976314004"),
491: sdk.MustNewDecFromStr("1.1617706976314004"),
492: sdk.MustNewDecFromStr("1.1642615263477947"),
493: sdk.MustNewDecFromStr("1.1642615263477947"),
495: sdk.MustNewDecFromStr("1.1642615263477947"),
496: sdk.MustNewDecFromStr("1.1740941880190199"),
498: sdk.MustNewDecFromStr("1.1740941880190199"),
499: sdk.MustNewDecFromStr("1.1740941880190199"),
500: sdk.MustNewDecFromStr("1.175864139818246"),
503: sdk.MustNewDecFromStr("1.175864139818246"),
504: sdk.MustNewDecFromStr("1.1776233988812017"),
505: sdk.MustNewDecFromStr("1.1776233988812017"),
506: sdk.MustNewDecFromStr("1.1776233988812017"),
507: sdk.MustNewDecFromStr("1.1776233988812017"),
508: sdk.MustNewDecFromStr("1.177732197355669"),
},
"sommelier-3": {
482: sdk.MustNewDecFromStr("1.0221309385498634"),
483: sdk.MustNewDecFromStr("1.0221309385498634"),
484: sdk.MustNewDecFromStr("1.0221309385498634"),
486: sdk.MustNewDecFromStr("1.022666920867979"),
488: sdk.MustNewDecFromStr("1.022666920867979"),
489: sdk.MustNewDecFromStr("1.022666920867979"),
490: sdk.MustNewDecFromStr("1.023749963371928"),
493: sdk.MustNewDecFromStr("1.023749963371928"),
495: sdk.MustNewDecFromStr("1.024808400658687"),
496: sdk.MustNewDecFromStr("1.024808400658687"),
497: sdk.MustNewDecFromStr("1.024808400658687"),
499: sdk.MustNewDecFromStr("1.024808400658687"),
501: sdk.MustNewDecFromStr("1.0256449837573494"),
502: sdk.MustNewDecFromStr("1.0256449837573494"),
503: sdk.MustNewDecFromStr("1.0256449837573494"),
504: sdk.MustNewDecFromStr("1.0256449837573494"),
505: sdk.MustNewDecFromStr("1.0259008616418266"),
507: sdk.MustNewDecFromStr("1.0259008616418266"),
508: sdk.MustNewDecFromStr("1.0259008616418266"),
},
"cosmoshub-4": {
484: sdk.MustNewDecFromStr("1.2875942696916478"),
485: sdk.MustNewDecFromStr("1.2875942696916478"),
486: sdk.MustNewDecFromStr("1.2875942696916478"),
487: sdk.MustNewDecFromStr("1.2875942696916478"),
488: sdk.MustNewDecFromStr("1.2901383615073008"),
489: sdk.MustNewDecFromStr("1.2901383615073008"),
490: sdk.MustNewDecFromStr("1.2901383615073008"),
491: sdk.MustNewDecFromStr("1.2901383615073008"),
492: sdk.MustNewDecFromStr("1.2914303773961855"),
493: sdk.MustNewDecFromStr("1.2914303773961855"),
494: sdk.MustNewDecFromStr("1.2914303773961855"),
495: sdk.MustNewDecFromStr("1.2914303773961855"),
496: sdk.MustNewDecFromStr("1.2946765429135605"),
497: sdk.MustNewDecFromStr("1.2946765429135605"),
498: sdk.MustNewDecFromStr("1.2946765429135605"),
499: sdk.MustNewDecFromStr("1.2946765429135605"),
500: sdk.MustNewDecFromStr("1.2966353732132307"),
501: sdk.MustNewDecFromStr("1.2966353732132307"),
502: sdk.MustNewDecFromStr("1.2966353732132307"),
503: sdk.MustNewDecFromStr("1.2966353732132307"),
504: sdk.MustNewDecFromStr("1.2986468613477709"),
505: sdk.MustNewDecFromStr("1.2986468613477709"),
506: sdk.MustNewDecFromStr("1.2986468613477709"),
507: sdk.MustNewDecFromStr("1.2986468613477709"),
508: sdk.MustNewDecFromStr("1.2990760366941585"),
509: sdk.MustNewDecFromStr("1.2990760366941585"),
},
"comdex-1": {
485: sdk.MustNewDecFromStr("1.1865251410281585"),
486: sdk.MustNewDecFromStr("1.1865251410281585"),
488: sdk.MustNewDecFromStr("1.1891618527186743"),
489: sdk.MustNewDecFromStr("1.1891618527186743"),
490: sdk.MustNewDecFromStr("1.1891618527186743"),
491: sdk.MustNewDecFromStr("1.1891618527186743"),
492: sdk.MustNewDecFromStr("1.1926667940346496"),
493: sdk.MustNewDecFromStr("1.1926667940346496"),
494: sdk.MustNewDecFromStr("1.1926667940346496"),
495: sdk.MustNewDecFromStr("1.1926667940346496"),
496: sdk.MustNewDecFromStr("1.1973725182109523"),
497: sdk.MustNewDecFromStr("1.1973725182109523"),
498: sdk.MustNewDecFromStr("1.1973725182109523"),
499: sdk.MustNewDecFromStr("1.1973725182109523"),
500: sdk.MustNewDecFromStr("1.2004214235326311"),
501: sdk.MustNewDecFromStr("1.2004214235326311"),
502: sdk.MustNewDecFromStr("1.2004214235326311"),
503: sdk.MustNewDecFromStr("1.2004214235326311"),
504: sdk.MustNewDecFromStr("1.2034589430292977"),
505: sdk.MustNewDecFromStr("1.2034589430292977"),
506: sdk.MustNewDecFromStr("1.2034589430292977"),
507: sdk.MustNewDecFromStr("1.2034589430292977"),
508: sdk.MustNewDecFromStr("1.2040062434963579"),
},
"injective-1": {
464: sdk.MustNewDecFromStr("1.1500807256744128"),
465: sdk.MustNewDecFromStr("1.1500807256744128"),
466: sdk.MustNewDecFromStr("1.1500807256744128"),
467: sdk.MustNewDecFromStr("1.1500807256744128"),
468: sdk.MustNewDecFromStr("1.1500807256744128"),
469: sdk.MustNewDecFromStr("1.1500807256744128"),
470: sdk.MustNewDecFromStr("1.1500807256744128"),
471: sdk.MustNewDecFromStr("1.1500807256744128"),
472: sdk.MustNewDecFromStr("1.1500807256744128"),
473: sdk.MustNewDecFromStr("1.1500807256744128"),
474: sdk.MustNewDecFromStr("1.1500807256744128"),
475: sdk.MustNewDecFromStr("1.1500807256744128"),
476: sdk.MustNewDecFromStr("1.1500807256744128"),
477: sdk.MustNewDecFromStr("1.1500807256744128"),
478: sdk.MustNewDecFromStr("1.1500807256744128"),
479: sdk.MustNewDecFromStr("1.1500807256744128"),
480: sdk.MustNewDecFromStr("1.1500807256744128"),
481: sdk.MustNewDecFromStr("1.1500807256744128"),
482: sdk.MustNewDecFromStr("1.1500807256744128"),
483: sdk.MustNewDecFromStr("1.1500807256744128"),
484: sdk.MustNewDecFromStr("1.1500807256744128"),
485: sdk.MustNewDecFromStr("1.1500807256744128"),
486: sdk.MustNewDecFromStr("1.1500807256744128"),
487: sdk.MustNewDecFromStr("1.1500807256744128"),
488: sdk.MustNewDecFromStr("1.1500807256744128"),
489: sdk.MustNewDecFromStr("1.1500807256744128"),
498: sdk.MustNewDecFromStr("1.1500807256744128"),
499: sdk.MustNewDecFromStr("1.1500807256744128"),
500: sdk.MustNewDecFromStr("1.212374830290344"),
501: sdk.MustNewDecFromStr("1.212374830290344"),
502: sdk.MustNewDecFromStr("1.212374830290344"),
503: sdk.MustNewDecFromStr("1.212374830290344"),
504: sdk.MustNewDecFromStr("1.2147869431614962"),
505: sdk.MustNewDecFromStr("1.2147869431614962"),
507: sdk.MustNewDecFromStr("1.2147869431614962"),
508: sdk.MustNewDecFromStr("1.214906161115688"),
},
"evmos_9001-2": {
492: sdk.MustNewDecFromStr("1.4846653184918148"),
493: sdk.MustNewDecFromStr("1.4846653184918148"),
494: sdk.MustNewDecFromStr("1.4846653184918148"),
495: sdk.MustNewDecFromStr("1.4877949604847145"),
496: sdk.MustNewDecFromStr("1.4877949604847145"),
497: sdk.MustNewDecFromStr("1.4877949604847145"),
499: sdk.MustNewDecFromStr("1.4895996973002357"),
500: sdk.MustNewDecFromStr("1.4895996973002357"),
501: sdk.MustNewDecFromStr("1.490678848400448"),
502: sdk.MustNewDecFromStr("1.490678848400448"),
503: sdk.MustNewDecFromStr("1.490678848400448"),
504: sdk.MustNewDecFromStr("1.4917210211376328"),
505: sdk.MustNewDecFromStr("1.4917210211376328"),
507: sdk.MustNewDecFromStr("1.4918520366929944"),
508: sdk.MustNewDecFromStr("1.4918520366929944"),
},
"osmosis-1": {
492: sdk.MustNewDecFromStr("1.1963688867243563"),
493: sdk.MustNewDecFromStr("1.1963688867243563"),
494: sdk.MustNewDecFromStr("1.1963688867243563"),
495: sdk.MustNewDecFromStr("1.1970692695006457"),
496: sdk.MustNewDecFromStr("1.1970692695006457"),
497: sdk.MustNewDecFromStr("1.1970692695006457"),
498: sdk.MustNewDecFromStr("1.1987054330176354"),
499: sdk.MustNewDecFromStr("1.1987054330176354"),
500: sdk.MustNewDecFromStr("1.1987054330176354"),
501: sdk.MustNewDecFromStr("1.1997005791572002"),
502: sdk.MustNewDecFromStr("1.1997005791572002"),
503: sdk.MustNewDecFromStr("1.1997005791572002"),
504: sdk.MustNewDecFromStr("1.200668177509732"),
505: sdk.MustNewDecFromStr("1.200668177509732"),
506: sdk.MustNewDecFromStr("1.200668177509732"),
507: sdk.MustNewDecFromStr("1.2008572054271187"),
508: sdk.MustNewDecFromStr("1.2008572054271187"),
509: sdk.MustNewDecFromStr("1.2008572054271187"),
},
"stargaze-1": {
492: sdk.MustNewDecFromStr("1.4221879666345822"),
493: sdk.MustNewDecFromStr("1.4221879666345822"),
494: sdk.MustNewDecFromStr("1.4221879666345822"),
495: sdk.MustNewDecFromStr("1.4234096730900296"),
496: sdk.MustNewDecFromStr("1.4234096730900296"),
498: sdk.MustNewDecFromStr("1.425950601619048"),
499: sdk.MustNewDecFromStr("1.425950601619048"),
500: sdk.MustNewDecFromStr("1.425950601619048"),
501: sdk.MustNewDecFromStr("1.4273024812101673"),
502: sdk.MustNewDecFromStr("1.4273024812101673"),
503: sdk.MustNewDecFromStr("1.4273024812101673"),
504: sdk.MustNewDecFromStr("1.4288169571251907"),
505: sdk.MustNewDecFromStr("1.4288169571251907"),
506: sdk.MustNewDecFromStr("1.4288169571251907"),
507: sdk.MustNewDecFromStr("1.429363817000515"),
508: sdk.MustNewDecFromStr("1.429363817000515"),
},
"umee-1": {
505: sdk.MustNewDecFromStr("1.1275274920184462"),
},
}
)
116 changes: 116 additions & 0 deletions app/upgrades/v18/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package v18

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

recordskeeper "github.com/Stride-Labs/stride/v17/x/records/keeper"
recordtypes "github.com/Stride-Labs/stride/v17/x/records/types"
stakeibckeeper "github.com/Stride-Labs/stride/v17/x/stakeibc/keeper"
stakeibctypes "github.com/Stride-Labs/stride/v17/x/stakeibc/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v18
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
stakeibcKeeper stakeibckeeper.Keeper,
recordsKeeper recordskeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v18...")

ctx.Logger().Info("Updating redemption rate bounds...")
UpdateRedemptionRateBounds(ctx, stakeibcKeeper)

ctx.Logger().Info("Updating unbonding records...")
err := UpdateUnbondingRecords(ctx, stakeibcKeeper, recordsKeeper, RedemptionRatesBeforeProp, RedemptionRatesAtTimeOfProp)
if err != nil {
return vm, err
}

return mm.RunMigrations(ctx, configurator, vm)
}
}

// Updates the outer redemption rate bounds
func UpdateRedemptionRateBounds(ctx sdk.Context, k stakeibckeeper.Keeper) {
sampocs marked this conversation as resolved.
Show resolved Hide resolved
for _, hostZone := range k.GetAllHostZone(ctx) {
// Give osmosis a bit more slack since OSMO stakers collect real yield
outerAdjustment := RedemptionRateOuterMaxAdjustment
if hostZone.ChainId == OsmosisChainId {
outerAdjustment = outerAdjustment.Add(OsmosisRedemptionRateBuffer)
}

outerMinDelta := hostZone.RedemptionRate.Mul(RedemptionRateOuterMinAdjustment)
outerMaxDelta := hostZone.RedemptionRate.Mul(outerAdjustment)

outerMin := hostZone.RedemptionRate.Sub(outerMinDelta)
outerMax := hostZone.RedemptionRate.Add(outerMaxDelta)

hostZone.MinRedemptionRate = outerMin
hostZone.MaxRedemptionRate = outerMax

k.SetHostZone(ctx, hostZone)
}
}

// Modify HostZoneUnbonding and UserRedemptionRecords NativeTokenAmount to reflect new data structs
func UpdateUnbondingRecords(
ctx sdk.Context,
sk stakeibckeeper.Keeper,
rk recordskeeper.Keeper,
redemptionRatesBeforeProp map[string]map[uint64]sdk.Dec,
redemptionRatesDuringProp map[string]sdk.Dec,
sampocs marked this conversation as resolved.
Show resolved Hide resolved
) error {
// loop over host zone unbonding records
for _, epochUnbondingRecord := range rk.GetAllEpochUnbondingRecord(ctx) {
for _, hostZoneUnbonding := range epochUnbondingRecord.HostZoneUnbondings {

// we can ignore any record that's not currently unbonding
if hostZoneUnbonding.Status != recordtypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE {
continue
}

// Grab the redemption rates from before the prop was posted, for a given chain
// across all the epochs that unbonded
hostZoneRRBeforeProp, ok := redemptionRatesBeforeProp[hostZoneUnbonding.HostZoneId]
if !ok {
ctx.Logger().Error("Host zone from unbonding record not included in redemption rate mapping")
continue
}

// Grab the redemption rate for this specific epoch
// If it's not found, that means the unbonding for this epoch occurred after the prop was live
recordRedemptionRate, recordUnbondedBeforeProp := hostZoneRRBeforeProp[epochUnbondingRecord.EpochNumber]

// If we don't have the redemption rate, estimate it
if !recordUnbondedBeforeProp {
hostZone, found := sk.GetHostZone(ctx, hostZoneUnbonding.HostZoneId)
if !found {
return errorsmod.Wrapf(stakeibctypes.ErrHostZoneNotFound, "unable to find host zone with chain-id %s", hostZoneUnbonding.HostZoneId)
}

redemptionRateDuringProp := redemptionRatesDuringProp[hostZoneUnbonding.HostZoneId]
redemptionRateDuringUpgrade := hostZone.RedemptionRate
recordRedemptionRate = redemptionRateDuringProp.Add(redemptionRateDuringUpgrade).Quo(sdk.NewDec(2))
}

// now update all userRedemptionRecords by using the redemption rate to set the native token amount
for _, userRedemptionRecordId := range hostZoneUnbonding.UserRedemptionRecords {
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
userRedemptionRecord, found := rk.GetUserRedemptionRecord(ctx, userRedemptionRecordId)
if !found {
return errorsmod.Wrapf(recordtypes.ErrHostUnbondingRecordNotFound, "unable to find user redemption record with id %s", userRedemptionRecordId)
}
userRedemptionRecord.NativeTokenAmount = sdk.NewDecFromInt(userRedemptionRecord.StTokenAmount).Mul(recordRedemptionRate).TruncateInt()
rk.SetUserRedemptionRecord(ctx, userRedemptionRecord)
}

sampocs marked this conversation as resolved.
Show resolved Hide resolved
// finally, update the hostZoneUnbonding record
return rk.SetHostZoneUnbondingRecord(ctx, epochUnbondingRecord.EpochNumber, hostZoneUnbonding.HostZoneId, *hostZoneUnbonding)
}
}
return nil
}
Loading
Loading