mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
[HOTFIX] Fix outgoing swaps in BEP3 sims (#490)
* check available asset supply on outgoing swaps * switch maximum, current
This commit is contained in:
parent
611eff93cf
commit
8ef03e4181
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user