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
This commit is contained in:
Kevin Davis 2021-07-15 10:46:56 -05:00 committed by GitHub
parent 290cb61882
commit da5a852a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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))

View File

@ -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