Skip to content

Commit

Permalink
[Stablestake]: Withdrawal limit (#1110)
Browse files Browse the repository at this point in the history
* withdrawal limit

* fix
  • Loading branch information
amityadav0 authored Jan 24, 2025
1 parent 5b15e38 commit 8b13fc3
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 50 deletions.
108 changes: 93 additions & 15 deletions api/elys/stablestake/params.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions proto/elys/stablestake/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ message Params {
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
string max_withdraw_ratio = 12 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
2 changes: 1 addition & 1 deletion x/stablestake/keeper/msg_server_unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (k msgServer) Unbond(goCtx context.Context, msg *types.MsgUnbond) (*types.M
redemptionAmount := shareCoin.Amount.ToLegacyDec().Mul(redemptionRate).RoundInt()

amountAfterRedemption := params.TotalValue.Sub(redemptionAmount)
maxAllowed := (params.TotalValue.ToLegacyDec().Mul(params.MaxLeverageRatio)).TruncateInt()
maxAllowed := (params.TotalValue.ToLegacyDec().Mul(params.MaxWithdrawRatio)).TruncateInt()
if amountAfterRedemption.LT(maxAllowed) {
return nil, types.ErrInvalidWithdraw
}
Expand Down
13 changes: 13 additions & 0 deletions x/stablestake/migrations/v8_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package migrations

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

func (m Migrator) V8Migration(ctx sdk.Context) error {
params := m.keeper.GetParams(ctx)
params.MaxWithdrawRatio = math.LegacyMustNewDecFromStr("0.9")
m.keeper.SetParams(ctx, params)
return nil
}
4 changes: 2 additions & 2 deletions x/stablestake/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 6, m.V7Migration)
err := cfg.RegisterMigration(types.ModuleName, 7, m.V8Migration)
if err != nil {
panic(err)
}
Expand All @@ -147,7 +147,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 7 }
func (AppModule) ConsensusVersion() uint64 { return 8 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(goCtx context.Context) error {
Expand Down
2 changes: 2 additions & 0 deletions x/stablestake/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"

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

"cosmossdk.io/math"
Expand All @@ -21,6 +22,7 @@ func DefaultParams() Params {
HealthGainFactor: math.LegacyOneDec(),
TotalValue: math.ZeroInt(),
MaxLeverageRatio: math.LegacyMustNewDecFromStr("0.7"),
MaxWithdrawRatio: math.LegacyMustNewDecFromStr("0.7"),
}
}

Expand Down
Loading

0 comments on commit 8b13fc3

Please sign in to comment.