From 9195ba60e11e3b6a5ca97b0c73a8bb059c5767bd Mon Sep 17 00:00:00 2001 From: Sachin Date: Mon, 18 Apr 2022 23:12:04 +0530 Subject: [PATCH] Refactor require to check for position unit during engage (#29) --- .../DeltaNeutralBasisTradingStrategyExtension.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/extensions/DeltaNeutralBasisTradingStrategyExtension.sol b/contracts/extensions/DeltaNeutralBasisTradingStrategyExtension.sol index 82650c4..e6ca587 100644 --- a/contracts/extensions/DeltaNeutralBasisTradingStrategyExtension.sol +++ b/contracts/extensions/DeltaNeutralBasisTradingStrategyExtension.sol @@ -1152,7 +1152,11 @@ contract DeltaNeutralBasisTradingStrategyExtension is BaseExtension { function _getAndValidateEngageInfo() internal view returns(LeverageInfo memory) { ActionInfo memory engageInfo = _createActionInfo(); - require(engageInfo.accountInfo.collateralBalance == 0, "PerpV2 collateral balance must be 0"); + // Check that there is zero position unit of USDC of collateral value. Allows to neglect dust amounts. + require( + engageInfo.accountInfo.collateralBalance.preciseDiv(engageInfo.setTotalSupply.toInt256()) == 0, + "PerpV2 collateral balance must be 0" + ); return LeverageInfo({ action: engageInfo,