From f97fbbcde4946aa02d40f0a8a23510accc3ac334 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 13 Dec 2021 21:28:35 -0300 Subject: [PATCH] revert transaction if buyer and seller is paying zero fees (#314) --- contracts/amm/OptionAMMPool.sol | 1 + test/amm/OptionAMMPool.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/contracts/amm/OptionAMMPool.sol b/contracts/amm/OptionAMMPool.sol index 1e8cb496..521b0d82 100644 --- a/contracts/amm/OptionAMMPool.sol +++ b/contracts/amm/OptionAMMPool.sol @@ -929,6 +929,7 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, CombinedActionsGuard, function _onTrade(TradeDetails memory tradeDetails) internal override { uint256 newIV = abi.decode(tradeDetails.params, (uint256)); + require(tradeDetails.feesTokenA > 0 && tradeDetails.feesTokenB > 0, "Pool: zero fees"); priceProperties.currentIV = newIV; IERC20(tokenB()).safeTransfer(address(feePoolA), tradeDetails.feesTokenA); diff --git a/test/amm/OptionAMMPool.test.js b/test/amm/OptionAMMPool.test.js index 85f9f0ae..b3e5cc8b 100644 --- a/test/amm/OptionAMMPool.test.js +++ b/test/amm/OptionAMMPool.test.js @@ -1170,6 +1170,24 @@ scenarios.forEach(scenario => { expect(bsPriceWithOracleIV).to.be.gte(bsPriceWithoutOracleIV) }) + it('Should revert if caller is going to pay 0 fees due to a small trade', async () => { + const stableLiquidityToAdd = toBigNumber(60000).mul(toBigNumber(10).pow(scenario.strikeAssetDecimals)) + const optionLiquidityToAdd = toBigNumber(100).mul(toBigNumber(10).pow(toBigNumber(scenario.underlyingAssetDecimals))) + const optionLiquidityToBuy = toBigNumber(1) + + await addLiquidity(optionAMMPool, optionLiquidityToAdd, stableLiquidityToAdd, lp) + + await mintOptions(option, optionLiquidityToBuy, buyer) + await mockStrikeAsset.connect(buyer).mint(stableLiquidityToAdd.mul(2)) + + await option.connect(buyer).approve(optionAMMPool.address, ethers.constants.MaxUint256) + await mockStrikeAsset.connect(buyer).approve(optionAMMPool.address, ethers.constants.MaxUint256) + + const tradeDetails = await optionAMMPool.getOptionTradeDetailsExactAInput(optionLiquidityToBuy) + + await expect(optionAMMPool.connect(buyer) + .tradeExactAInput(optionLiquidityToBuy, 0, buyerAddress, tradeDetails.newIV)).to.be.revertedWith('Pool: zero fees') + }) }) describe('Withdraw Amount > TotalBalance case', () => {