From da5a852a6c5006f3ee181e50d6e1e0f17d5e9aa2 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Thu, 15 Jul 2021 10:46:56 -0500 Subject: [PATCH] Misc simulation fixes (#963) * fix: catch min swap edge case in bep3 sims * fix: check repayment is above min in cdp sims * remove print statement --- x/bep3/simulation/operations.go | 2 +- x/cdp/simulation/operations.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/x/bep3/simulation/operations.go b/x/bep3/simulation/operations.go index 681512a9..254dacf7 100644 --- a/x/bep3/simulation/operations.go +++ b/x/bep3/simulation/operations.go @@ -158,7 +158,7 @@ func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simula // Get an amount of coins between 0.1 and 2% of total coins amount := maximumAmount.Quo(sdk.NewInt(int64(simulation.RandIntBetween(r, 50, 1000)))) minAmountPlusFee := asset.MinSwapAmount.Add(asset.FixedFee) - if amount.LT(minAmountPlusFee) { + if amount.LTE(minAmountPlusFee) { return simulation.NewOperationMsgBasic(types.ModuleName, fmt.Sprintf("no-operation (account funds exhausted for asset %s)", asset.Denom), "", false, nil), nil, nil } coins := sdk.NewCoins(sdk.NewCoin(asset.Denom, amount)) diff --git a/x/cdp/simulation/operations.go b/x/cdp/simulation/operations.go index 38d71a86..947f6c0f 100644 --- a/x/cdp/simulation/operations.go +++ b/x/cdp/simulation/operations.go @@ -137,6 +137,10 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed // close 25% of the time if canClose(spendableCoins, existingCDP, debtParam.Denom) && shouldClose(r) { repaymentAmount := spendableCoins.AmountOf(debtParam.Denom) + // check that repayment isn't below the debt floor + if existingCDP.Principal.Amount.Add(existingCDP.AccumulatedFees.Amount).Sub(repaymentAmount).LT(debtParam.DebtFloor) { + repaymentAmount = existingCDP.Principal.Amount.Add(existingCDP.AccumulatedFees.Amount).Sub(debtParam.DebtFloor) + } msg := types.NewMsgRepayDebt(acc.GetAddress(), randCollateralParam.Type, sdk.NewCoin(debtParam.Denom, repaymentAmount)) tx := helpers.GenTx( @@ -225,7 +229,7 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed // repay debt 25% of the time if hasCoins(spendableCoins, debtParam.Denom) { - debt := existingCDP.Principal.Amount + debt := existingCDP.Principal.Amount.Add(existingCDP.AccumulatedFees.Amount) payableDebt := debt.Sub(debtParam.DebtFloor) if payableDebt.IsZero() { return simulation.NewOperationMsgBasic(types.ModuleName, "no-operation", "cannot make partial repayment, cdp at debt floor", false, nil), nil, nil