Skip to content

Commit

Permalink
add outer bound updates + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzmann committed Jan 28, 2025
1 parent a23ecf8 commit 619c63b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
40 changes: 39 additions & 1 deletion app/upgrades/v25/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ import (
staketiatypes "github.com/Stride-Labs/stride/v24/x/staketia/types"
)

const UpgradeName = "v25"
var (
UpgradeName = "v25"

// 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")
)

// CreateUpgradeHandler creates an SDK upgrade handler for v25
func CreateUpgradeHandler(
Expand All @@ -38,6 +49,9 @@ func CreateUpgradeHandler(
return vm, errorsmod.Wrapf(err, "unable to add celestia validators")
}

// Update redemption rate bounds
UpdateRedemptionRateBounds(ctx, stakeibcKeeper)

ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
Expand All @@ -63,3 +77,27 @@ func AddCelestiaValidators(ctx sdk.Context, k stakeibckeeper.Keeper) error {
}
return nil
}

// Updates the outer redemption rate bounds
func UpdateRedemptionRateBounds(ctx sdk.Context, k stakeibckeeper.Keeper) {
ctx.Logger().Info("Updating redemption rate outer bounds...")

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)
}
}
61 changes: 61 additions & 0 deletions app/upgrades/v25/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"github.com/Stride-Labs/stride/v24/app/apptesting"
)

type UpdateRedemptionRateBounds struct {
ChainId string
CurrentRedemptionRate sdk.Dec

Check failure on line 13 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMinOuterRedemptionRate sdk.Dec

Check failure on line 14 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMaxOuterRedemptionRate sdk.Dec

Check failure on line 15 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
}

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}
Expand All @@ -21,5 +28,59 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (s *UpgradeTestSuite) TestUpgrade() {
// Pre upgrade setup --------------------------
upgradeHeight := int64(4)
checkRedemptionRatesAfterUpgrade := s.SetupTestUpdateRedemptionRateBounds()

// Run the upgrade --------------------------
s.ConfirmUpgradeSucceededs(v24.UpgradeName, upgradeHeight)

Check failure on line 36 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v24

// Post upgrade tests --------------------------
checkRedemptionRatesAfterUpgrade()
}

func (s *UpgradeTestSuite) SetupTestUpdateRedemptionRateBounds() func() {
// Define test cases consisting of an initial redemption rate and expected bounds
testCases := []UpdateRedemptionRateBounds{
{
ChainId: "chain-0",
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.0"),

Check failure on line 47 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("0.95"), // 1 - 5% = 0.95

Check failure on line 48 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.10"), // 1 + 10% = 1.1

Check failure on line 49 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
},
{
ChainId: "chain-1",
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.1"),

Check failure on line 53 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("1.045"), // 1.1 - 5% = 1.045

Check failure on line 54 in app/upgrades/v25/upgrades_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: sdk
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.210"), // 1.1 + 10% = 1.21
},
{
// Max outer for osmo uses 12% instead of 10%
ChainId: v24.OsmosisChainId,
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.25"),
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("1.1875"), // 1.25 - 5% = 1.1875
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.4000"), // 1.25 + 12% = 1.400
},
}

// Create a host zone for each test case
for _, tc := range testCases {
hostZone := stakeibctypes.HostZone{
ChainId: tc.ChainId,
RedemptionRate: tc.CurrentRedemptionRate,
}
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone)
}

// Return callback to check store after upgrade
return func() {
// Confirm they were all updated
for _, tc := range testCases {
hostZone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, tc.ChainId)
s.Require().True(found)

s.Require().Equal(tc.ExpectedMinOuterRedemptionRate, hostZone.MinRedemptionRate, "%s - min outer", tc.ChainId)
s.Require().Equal(tc.ExpectedMaxOuterRedemptionRate, hostZone.MaxRedemptionRate, "%s - max outer", tc.ChainId)
}
}
}

0 comments on commit 619c63b

Please sign in to comment.