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

fix: payment trigger percentage & 0.5.1 update #532

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (app App) RegisterUpgradeHandlers() {
app.registerUpgrade0_4_0(upgradeInfo)
app.registerUpgrade0_4_1(upgradeInfo)
app.registerUpgrade0_5_0(upgradeInfo)
app.registerUpgrade0_5_1(upgradeInfo)
}

// performs upgrade from v0.1.3 to v0.1.4
Expand Down Expand Up @@ -358,6 +359,21 @@ func (app *App) registerUpgrade0_5_0(upgradeInfo upgradetypes.Plan) {
})
}

func (app *App) registerUpgrade0_5_1(_ upgradetypes.Plan) {
const planName = "v0.5.1"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.Logger().Info("Upgrade handler execution", "name", planName)

params := app.GasEstimateKeeper.GetParams(sdkCtx)
params.GasAdjustment = "0.35"
app.GasEstimateKeeper.SetParams(sdkCtx, params)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

// helper function to check if the store loader should be upgraded
func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) {
if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) {
Expand Down
6 changes: 5 additions & 1 deletion x/gmp/types/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
)

func (p Payment) TriggerUpdate(rate math.LegacyDec, ctx sdk.Context) bool {
return p.LastPrice.Sub(rate).Abs().GT(p.Deviation) ||
// Calculate the percentage difference
priceDiff := p.LastPrice.Sub(rate).Abs()
percentageDiff := priceDiff.Quo(p.LastPrice).MulInt64(100)

return percentageDiff.GT(p.Deviation) ||
p.LastBlock < ctx.BlockHeight()-p.Heartbeat
}
13 changes: 13 additions & 0 deletions x/gmp/types/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func TestPayment_TriggerUpdate(t *testing.T) {
ctx: sdk.Context{}.WithBlockHeight(102),
want: true,
},

{
name: "should not trigger update - deviation within threshol",
payment: Payment{
LastPrice: math.LegacyMustNewDecFromStr("200"),
Deviation: math.LegacyMustNewDecFromStr("1"),
Heartbeat: 100,
LastBlock: 100,
},
rate: math.LegacyMustNewDecFromStr("202"),
ctx: sdk.Context{}.WithBlockHeight(101),
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading