From 6c990031a627645a443a9d97e5a461315619c6b1 Mon Sep 17 00:00:00 2001 From: Marc Puig Date: Thu, 25 Jan 2024 15:01:20 +0100 Subject: [PATCH] fix: Shares to tokens (#750) * fix * changelog --- CHANGELOG.md | 1 + x/liquidstakeibc/keeper/host_chain.go | 6 +++--- x/liquidstakeibc/keeper/msg_server.go | 5 +++-- x/liquidstakeibc/keeper/msg_server_test.go | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c38e3cb10..d155fd927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +- [750](https://github.com/persistenceOne/pstake-native/pull/750) Shares to tokens. - [734](https://github.com/persistenceOne/pstake-native/pull/734) Host chain duplication check. - [731](https://github.com/persistenceOne/pstake-native/pull/731) Set limit to LSM deposit filtering. - [730](https://github.com/persistenceOne/pstake-native/pull/730) Fix deposit validate. diff --git a/x/liquidstakeibc/keeper/host_chain.go b/x/liquidstakeibc/keeper/host_chain.go index b772328a4..1ee4b8c64 100644 --- a/x/liquidstakeibc/keeper/host_chain.go +++ b/x/liquidstakeibc/keeper/host_chain.go @@ -199,7 +199,7 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( // if the bond factor functionality is disabled, calculate available room based only on the cap if hc.Params.LsmBondFactor.Equal(sdk.NewDecFromInt(sdk.NewInt(-1))) { - validatorHasEnoughRoom = msgDelegate.Amount.Amount.LT(capRoom.TruncateInt()) + validatorHasEnoughRoom = sdk.NewDecFromInt(msgDelegate.Amount.Amount).Quo(val.ExchangeRate).LT(capRoom) continue } @@ -209,8 +209,8 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( // if there is room on both caps, the validator can accept the delegation we will send on the next // delegation workflow (next block). - validatorHasEnoughRoom = msgDelegate.Amount.Amount.LT(capRoom.TruncateInt()) && - msgDelegate.Amount.Amount.LT(bondRoom.TruncateInt()) + validatorHasEnoughRoom = sdk.NewDecFromInt(msgDelegate.Amount.Amount).Quo(val.ExchangeRate).LT(capRoom) && + sdk.NewDecFromInt(msgDelegate.Amount.Amount).Quo(val.ExchangeRate).LT(bondRoom) } } diff --git a/x/liquidstakeibc/keeper/msg_server.go b/x/liquidstakeibc/keeper/msg_server.go index 721e180e3..d7931d3ba 100644 --- a/x/liquidstakeibc/keeper/msg_server.go +++ b/x/liquidstakeibc/keeper/msg_server.go @@ -495,7 +495,8 @@ func (k msgServer) LiquidStakeLSM( } // check for minimum deposit amount - if delegation.Amount.LT(hc.MinimumDeposit) { + if sdktypes.NewDecFromInt(delegation.Amount).Mul(validator.ExchangeRate). + LT(sdktypes.NewDecFromInt(hc.MinimumDeposit)) { return nil, errorsmod.Wrapf( types.ErrMinDeposit, "expected amount for delegation %s more than %s, got %s", @@ -593,7 +594,7 @@ func (k msgServer) LiquidStakeLSM( sdktypes.NewAttribute(types.AttributeChainID, hc.ChainId), sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegator.String()), sdktypes.NewAttribute(types.AttributeInputAmount, - sdktypes.NewCoin(hc.HostDenom, delegation.Amount).String()), + sdktypes.NewCoin(hc.HostDenom, deposit.Amount).String()), sdktypes.NewAttribute(types.AttributeOutputAmount, sdktypes.NewCoin(hc.MintDenom(), mintToken.Sub(protocolFee).Amount).String()), sdktypes.NewAttribute(types.AttributePstakeDepositFee, diff --git a/x/liquidstakeibc/keeper/msg_server_test.go b/x/liquidstakeibc/keeper/msg_server_test.go index e0a1a789a..f8dac2b19 100644 --- a/x/liquidstakeibc/keeper/msg_server_test.go +++ b/x/liquidstakeibc/keeper/msg_server_test.go @@ -242,6 +242,20 @@ func (suite *IntegrationTestSuite) Test_msgServer_LiquidStakeLSM() { }, want: nil, wantErr: true, + }, { + name: "Less than min amount", + args: args{ + goCtx: ctx, + msg: &types.MsgLiquidStakeLSM{ + DelegatorAddress: suite.chainA.SenderAccount.GetAddress().String(), + Delegations: sdk.NewCoins(sdk.NewCoin(lsmIbcDenom, sdk.NewInt(4))), + }, + chainActive: true, + lsmActive: true, + createSecondDeposit: true, + }, + want: nil, + wantErr: true, }, }