Skip to content

Commit

Permalink
revert transaction if buyer and seller is paying zero fees (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robsonsjre authored Dec 14, 2021
1 parent b18a21f commit f97fbbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/amm/OptionAMMPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/amm/OptionAMMPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f97fbbc

Please sign in to comment.