mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 03:57:44 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									290cb61882
								
							
						
					
					
						commit
						da5a852a6c
					
				@ -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
 | 
							// Get an amount of coins between 0.1 and 2% of total coins
 | 
				
			||||||
		amount := maximumAmount.Quo(sdk.NewInt(int64(simulation.RandIntBetween(r, 50, 1000))))
 | 
							amount := maximumAmount.Quo(sdk.NewInt(int64(simulation.RandIntBetween(r, 50, 1000))))
 | 
				
			||||||
		minAmountPlusFee := asset.MinSwapAmount.Add(asset.FixedFee)
 | 
							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
 | 
								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))
 | 
							coins := sdk.NewCoins(sdk.NewCoin(asset.Denom, amount))
 | 
				
			||||||
 | 
				
			|||||||
@ -137,6 +137,10 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed
 | 
				
			|||||||
		// close 25% of the time
 | 
							// close 25% of the time
 | 
				
			||||||
		if canClose(spendableCoins, existingCDP, debtParam.Denom) && shouldClose(r) {
 | 
							if canClose(spendableCoins, existingCDP, debtParam.Denom) && shouldClose(r) {
 | 
				
			||||||
			repaymentAmount := spendableCoins.AmountOf(debtParam.Denom)
 | 
								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))
 | 
								msg := types.NewMsgRepayDebt(acc.GetAddress(), randCollateralParam.Type, sdk.NewCoin(debtParam.Denom, repaymentAmount))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			tx := helpers.GenTx(
 | 
								tx := helpers.GenTx(
 | 
				
			||||||
@ -225,7 +229,7 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// repay debt 25% of the time
 | 
							// repay debt 25% of the time
 | 
				
			||||||
		if hasCoins(spendableCoins, debtParam.Denom) {
 | 
							if hasCoins(spendableCoins, debtParam.Denom) {
 | 
				
			||||||
			debt := existingCDP.Principal.Amount
 | 
								debt := existingCDP.Principal.Amount.Add(existingCDP.AccumulatedFees.Amount)
 | 
				
			||||||
			payableDebt := debt.Sub(debtParam.DebtFloor)
 | 
								payableDebt := debt.Sub(debtParam.DebtFloor)
 | 
				
			||||||
			if payableDebt.IsZero() {
 | 
								if payableDebt.IsZero() {
 | 
				
			||||||
				return simulation.NewOperationMsgBasic(types.ModuleName, "no-operation", "cannot make partial repayment, cdp at debt floor", false, nil), nil, nil
 | 
									return simulation.NewOperationMsgBasic(types.ModuleName, "no-operation", "cannot make partial repayment, cdp at debt floor", false, nil), nil, nil
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user