Skip to content

Commit

Permalink
feat: add zero deposit_denom rate error
Browse files Browse the repository at this point in the history
  • Loading branch information
Senna46 committed Feb 7, 2024
1 parent 20b67b7 commit c40010c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x/irs/keeper/stripping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions x/irs/keeper/swap_advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c40010c

Please sign in to comment.