From 1d7c442523fc9c1e6e657df0087b858afd1e62c4 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Mon, 28 Aug 2023 18:04:46 +0700 Subject: [PATCH 1/2] add upgrade min amount --- app/upgrades/v5/upgrade.go | 145 +++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/app/upgrades/v5/upgrade.go b/app/upgrades/v5/upgrade.go index 9bcbed994..e57d1ba14 100644 --- a/app/upgrades/v5/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -1,11 +1,21 @@ package v5 import ( + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/notional-labs/centauri/v4/app/keepers" "github.com/notional-labs/centauri/v4/app/upgrades" + "github.com/notional-labs/centauri/v4/x/ratelimit/types" +) + +const ( + // https://github.com/cosmos/chain-registry/blob/master/composable/assetlist.json + uatom = "ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0" + dot = "ibc/3CC19CEC7E5A3E90E78A5A9ECC5A0E2F8F826A375CF1E096F4515CF09DA3E366" + ksm = "ibc/EE9046745AEC0E8302CB7ED9D5AD67F528FB3B7AE044B247FB0FB293DBDA35E9" + usdt = "ibc/F3EC9F834E57DF704FA3AEAF14E8391C2E58397FE56960AD70E67562990D8265" ) func CreateUpgradeHandler( @@ -15,6 +25,141 @@ func CreateUpgradeHandler( keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // add min amount for rate limit + rlKeeper := keepers.RatelimitKeeper + // add uatom + uatomRateLimit, found := rlKeeper.GetRateLimit(ctx, uatom, "channel-2") + if !found { + channelValue := rlKeeper.GetChannelValue(ctx, uatom) + if channelValue.IsZero() { + panic("Zero channel value") + } + // Create and store the rate limit object + path := types.Path{ + Denom: uatom, + 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, + } + uatomRateLimit = types.RateLimit{ + Path: &path, + Quota: "a, + Flow: &flow, + MinRateLimitAmount: sdk.NewInt(1282_000_000), + } + rlKeeper.SetRateLimit(ctx, uatomRateLimit) + } else { + uatomRateLimit.MinRateLimitAmount = sdk.NewInt(1282_000_000) + rlKeeper.SetRateLimit(ctx, uatomRateLimit) + } + // add dot + dotRateLimit, found := rlKeeper.GetRateLimit(ctx, dot, "channel-2") + if !found { + channelValue := rlKeeper.GetChannelValue(ctx, dot) + if channelValue.IsZero() { + panic("Zero channel value") + } + // Create and store the rate limit object + path := types.Path{ + Denom: dot, + 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, + } + dotRateLimit = types.RateLimit{ + Path: &path, + Quota: "a, + Flow: &flow, + MinRateLimitAmount: sdk.NewInt(2267_000_000_000_000), + } + rlKeeper.SetRateLimit(ctx, dotRateLimit) + } else { + dotRateLimit.MinRateLimitAmount = sdk.NewInt(2267_000_000_000_000) + rlKeeper.SetRateLimit(ctx, dotRateLimit) + } + // add ksm + ksmRateLimit, found := rlKeeper.GetRateLimit(ctx, ksm, "channel-2") + if !found { + channelValue := rlKeeper.GetChannelValue(ctx, ksm) + if channelValue.IsZero() { + panic("Zero channel value") + } + // Create and store the rate limit object + path := types.Path{ + Denom: ksm, + 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, + } + ksmRateLimit = types.RateLimit{ + Path: &path, + Quota: "a, + Flow: &flow, + MinRateLimitAmount: sdk.NewInt(510_000_000_000_000), + } + rlKeeper.SetRateLimit(ctx, ksmRateLimit) + } else { + ksmRateLimit.MinRateLimitAmount = sdk.NewInt(510_000_000_000_000) + rlKeeper.SetRateLimit(ctx, ksmRateLimit) + } + // add usdt + usdtRateLimit, found := rlKeeper.GetRateLimit(ctx, usdt, "channel-2") + if !found { + channelValue := rlKeeper.GetChannelValue(ctx, usdt) + if channelValue.IsZero() { + panic("Zero channel value") + } + // Create and store the rate limit object + path := types.Path{ + Denom: usdt, + 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, + } + usdtRateLimit = types.RateLimit{ + Path: &path, + Quota: "a, + Flow: &flow, + MinRateLimitAmount: sdk.NewInt(10_000_000_000_000_000), + } + rlKeeper.SetRateLimit(ctx, usdtRateLimit) + } else { + usdtRateLimit.MinRateLimitAmount = sdk.NewInt(10_000_000_000_000_000) + rlKeeper.SetRateLimit(ctx, usdtRateLimit) + } + return mm.RunMigrations(ctx, configurator, vm) } } From 613c45fa7514501ed3baab33d60748799c2a14e5 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Mon, 28 Aug 2023 18:05:51 +0700 Subject: [PATCH 2/2] nit --- app/upgrades/v5/upgrade.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/upgrades/v5/upgrade.go b/app/upgrades/v5/upgrade.go index e57d1ba14..5de1d507c 100644 --- a/app/upgrades/v5/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -32,7 +32,7 @@ func CreateUpgradeHandler( if !found { channelValue := rlKeeper.GetChannelValue(ctx, uatom) if channelValue.IsZero() { - panic("Zero channel value") + panic("Zero ATOM channel value") } // Create and store the rate limit object path := types.Path{ @@ -65,7 +65,7 @@ func CreateUpgradeHandler( if !found { channelValue := rlKeeper.GetChannelValue(ctx, dot) if channelValue.IsZero() { - panic("Zero channel value") + panic("Zero DOT channel value") } // Create and store the rate limit object path := types.Path{ @@ -98,7 +98,7 @@ func CreateUpgradeHandler( if !found { channelValue := rlKeeper.GetChannelValue(ctx, ksm) if channelValue.IsZero() { - panic("Zero channel value") + panic("Zero KSM channel value") } // Create and store the rate limit object path := types.Path{ @@ -131,7 +131,7 @@ func CreateUpgradeHandler( if !found { channelValue := rlKeeper.GetChannelValue(ctx, usdt) if channelValue.IsZero() { - panic("Zero channel value") + panic("Zero USDT channel value") } // Create and store the rate limit object path := types.Path{