[HOTFIX] Fix outgoing swaps in BEP3 sims (#490)

* check available asset supply on outgoing swaps

* switch maximum, current
This commit is contained in:
Denali Marsh 2020-05-06 17:29:59 -07:00 committed by GitHub
parent 611eff93cf
commit 8ef03e4181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,9 +114,21 @@ func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simula
return simulation.NoOpMsg(types.ModuleName), nil, err return simulation.NoOpMsg(types.ModuleName), nil, err
} }
// Get maximum valid amount
maximumAmount := senderAcc.SpendableCoins(ctx.BlockTime()).Sub(fees).AmountOf(denom)
// The maximum amount for outgoing swaps is limited by the asset's current supply
if recipient.Equals(deputyAcc) {
assetSupply, foundAssetSupply := k.GetAssetSupply(ctx, []byte(denom))
if !foundAssetSupply {
return noOpMsg, nil, fmt.Errorf("no asset supply found")
}
if maximumAmount.GT(assetSupply.CurrentSupply.Amount) {
maximumAmount = assetSupply.CurrentSupply.Amount
}
}
// Get an amount of coins between 0.1 and 2% of total coins // Get an amount of coins between 0.1 and 2% of total coins
availableAmount := senderAcc.SpendableCoins(ctx.BlockTime()).Sub(fees).AmountOf(denom) amount := maximumAmount.Quo(sdk.NewInt(int64(simulation.RandIntBetween(r, 50, 1000))))
amount := availableAmount.Quo(sdk.NewInt(int64(simulation.RandIntBetween(r, 50, 1000))))
if amount.IsZero() { if amount.IsZero() {
return simulation.NewOperationMsgBasic(types.ModuleName, fmt.Sprintf("no-operation (all funds exhausted for asset %s)", denom), "", false, nil), nil, nil return simulation.NewOperationMsgBasic(types.ModuleName, fmt.Sprintf("no-operation (all funds exhausted for asset %s)", denom), "", false, nil), nil, nil
} }