From c40010c0b84116111c7de5f456f9442fc2c30287 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:57:02 +0900 Subject: [PATCH] feat: add zero deposit_denom rate error --- x/irs/keeper/stripping.go | 9 +++++++++ x/irs/keeper/swap_advanced.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/x/irs/keeper/stripping.go b/x/irs/keeper/stripping.go index 6e528e945..f66b3488e 100644 --- a/x/irs/keeper/stripping.go +++ b/x/irs/keeper/stripping.go @@ -230,6 +230,9 @@ func (k Keeper) CalculateRedeemAmount(ctx sdk.Context, pool types.TranchePool, t info := k.GetStrategyDepositInfo(ctx, pool.StrategyContract) rate := sdk.MustNewDecFromStr(info.DepositDenomRate) + if rate.IsZero() { + return sdk.Coin{}, sdk.Coin{}, types.ErrZeroDepositRate + } redeemAmount := sdk.NewDecFromInt(utAmount).Mul(rate).TruncateInt() redeemCoin := sdk.NewCoin(redeemDenom, redeemAmount) @@ -261,6 +264,9 @@ func (k Keeper) RedeemPtAtMaturity(ctx sdk.Context, sender sdk.AccAddress, pool info := k.GetStrategyDepositInfo(ctx, pool.StrategyContract) rate := sdk.MustNewDecFromStr(info.DepositDenomRate) + if rate.IsZero() { + return types.ErrZeroDepositRate + } redeemAmount := sdk.NewDecFromInt(ptAmount.Amount).Mul(rate).TruncateInt() return k.UnstakeFromStrategy(ctx, moduleAddr, sender.String(), pool.StrategyContract, redeemAmount) @@ -316,6 +322,9 @@ func (k Keeper) CalculateRedeemYtAmount(ctx sdk.Context, pool types.TranchePool, utAmount := vaultAmount.Sub(ptSupply.Amount).Mul(ytAmount.Amount).Quo(ytSupply.Amount) info := k.GetStrategyDepositInfo(ctx, pool.StrategyContract) rate := sdk.MustNewDecFromStr(info.DepositDenomRate) + if rate.IsZero() { + return sdk.ZeroInt(), types.ErrZeroDepositRate + } redeemAmount := sdk.NewDecFromInt(utAmount).Mul(rate).TruncateInt() return redeemAmount, nil } diff --git a/x/irs/keeper/swap_advanced.go b/x/irs/keeper/swap_advanced.go index 961902a80..b57c716f2 100644 --- a/x/irs/keeper/swap_advanced.go +++ b/x/irs/keeper/swap_advanced.go @@ -14,6 +14,9 @@ func (k Keeper) SwapToYt(ctx sdk.Context, sender sdk.AccAddress, pool types.Tran } info := k.GetStrategyDepositInfo(ctx, pool.StrategyContract) rate := sdk.MustNewDecFromStr(info.DepositDenomRate) + if rate.IsZero() { + return types.ErrZeroDepositRate + } loanAmount := sdk.NewDecFromInt(requiredYtAmount).Mul(rate).TruncateInt() loan := sdk.NewCoin(tokenIn.Denom, loanAmount) ptDenom := types.PtDenom(pool) @@ -56,6 +59,9 @@ func (k Keeper) SwapToYt(ctx sdk.Context, sender sdk.AccAddress, pool types.Tran func (k Keeper) CalculateRequiredDepositSwapToYt(ctx sdk.Context, pool types.TranchePool, requiredYtAmount math.Int) (sdk.Coin, error) { info := k.GetStrategyDepositInfo(ctx, pool.StrategyContract) rate := sdk.MustNewDecFromStr(info.DepositDenomRate) + if rate.IsZero() { + return sdk.Coin{}, types.ErrZeroDepositRate + } loanAmount := sdk.NewDecFromInt(requiredYtAmount).Mul(rate).TruncateInt() loan := sdk.NewCoin(pool.Denom, loanAmount) ptDenom := types.PtDenom(pool)