Skip to content

Commit

Permalink
hard fork for fix rate limit with osmo token
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong177 committed Sep 15, 2023
1 parent 7200b73 commit 81aa753
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import (

v4_5 "github.com/notional-labs/centauri/v5/app/upgrades/v4_5"
v4_5_1 "github.com/notional-labs/centauri/v5/app/upgrades/v4_5_1"

Check failure on line 122 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/notional-labs/centauri/v5/app/upgrades/v4_5_1" is being imported more than once (stylecheck)
v5_1_0 "github.com/notional-labs/centauri/v5/app/upgrades/v4_5_1"

Check failure on line 123 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/notional-labs/centauri/v5/app/upgrades/v4_5_1" (stylecheck)

upgrades "github.com/notional-labs/centauri/v5/app/upgrades"
)
Expand All @@ -140,7 +141,7 @@ var (
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v4.Upgrade, v5.Upgrade}
Forks = []upgrades.Fork{v4_5.Fork, v4_5_1.Fork}
Forks = []upgrades.Fork{v4_5.Fork, v4_5_1.Fork, v5_1_0.Fork}
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v5_1_0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v5_1_0

import "github.com/notional-labs/centauri/v5/app/upgrades"

const (
// UpgradeName defines the on-chain upgrade name for the Composable v5 upgrade.
UpgradeName = "v5_1_0"

// UpgradeHeight defines the block height at which the Composable v6 upgrade is
// triggered.
UpgradeHeight = 1532990
)

var Fork = upgrades.Fork{
UpgradeName: UpgradeName,
UpgradeHeight: UpgradeHeight,
BeginForkLogic: RunForkLogic,
}
61 changes: 61 additions & 0 deletions app/upgrades/v5_1_0/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package v5_1_0

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/notional-labs/centauri/v5/app/keepers"
rateLimitKeeper "github.com/notional-labs/centauri/v5/x/ratelimit/keeper"
"github.com/notional-labs/centauri/v5/x/ratelimit/types"
)

const uosmo = "ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23"

func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {
ctx.Logger().Info("Applying v5_1_0 upgrade" +
"Fix Rate Limit With Osmosis Token",
)

FixRateLimit(ctx, &keepers.RatelimitKeeper)
}

func FixRateLimit(ctx sdk.Context, rlKeeper *rateLimitKeeper.Keeper) {
uosmoRateLimit, found := rlKeeper.GetRateLimit(ctx, uosmo, "channel-2")
if !found {
channelValue := rlKeeper.GetChannelValue(ctx, uosmo)
// Create and store the rate limit object
path := types.Path{
Denom: uosmo,
ChannelID: "channel-2",
}
quota := types.Quota{
MaxPercentSend: sdk.NewInt(30),
MaxPercentRecv: sdk.NewInt(30),
DurationHours: 24,
}
flow := types.Flow{
Inflow: math.ZeroInt(),
Outflow: math.ZeroInt(),
ChannelValue: channelValue,
}
uosmoRateLimit = types.RateLimit{
Path: &path,
Quota: &quota,
Flow: &flow,
MinRateLimitAmount: sdk.NewInt(1), // decimal 6
}
rlKeeper.SetRateLimit(ctx, uosmoRateLimit)
} else {
uosmoRateLimit.MinRateLimitAmount = sdk.NewInt(1282_000_000)
rlKeeper.SetRateLimit(ctx, uosmoRateLimit)
}

// double check
allRateLiit := rlKeeper.GetAllRateLimits(ctx)
for _, ratelimit := range allRateLiit {
if ratelimit.MinRateLimitAmount.IsNil() {
ratelimit.MinRateLimitAmount = sdk.NewInt(1)
rlKeeper.SetRateLimit(ctx, ratelimit)
}
}
}

0 comments on commit 81aa753

Please sign in to comment.