Vol-based bid pool #88
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

A contract that allows a user to bid on a Hook Protocol option based on an implied volatility number. The actual purchase price paid for the option is computed at order fill time, using the then-current underlying asset spot price and time to option expiration.
Use Case
Bidding on options within an order book is complicated because the fair market value of that option changes rapidly based on external factors: the price of the underlying collection, the time to expiration, and other news. Typically, this can be solved by submitting orders to an order book for a short duration, and quickly canceling them if news occurs.
For casual users, these strategies are difficult because they require constant monitoring of the market, expertise in pricing transactions to cancel orders suddenly, and potential infrastructure to programmatically submit orders.
By making a longer duration order in terms of a desired implied volatility, and then computing the actual purchase price at order fill time using Black-Scholes-Merton, a user can make an order that expresses their view of the volatility quickly.
Implementation details
These orders depend on a single off-chain price oracle. The advantage of this oracle is that it can take into account order book states that may exist only off-chain (i.e., has not yet materialized in trades) and incorporate that into the view of the price. The downside is that the off-chain oracle must be trusted by the signer.
The order book offers gasless cancellations by only filling orders confirmed by a trusted oracle for a short period of time after that oracle signs the order. Off-chain, the order maker can signal to the oracle that they'd like their order to be canceled. The oracle then stops signing orders. Makers may also cancel an order by submitting a transaction on-chain.
Dependencies
The implementation depends on the well-tested BlackScholes logic used in Lyra protocol, which itself depends on the Synthetix implementation. These contracts will be out of scope for an audit.
Tests
Previously, we completed coverage testing using
npx hardhat coverage. However, since this suite was completed,forge coveragehas been released. Including this contract and going forward, we're aiming to meet our coverage requirements by writing tests in Solidity.Coverage for this contract can be computed by looking at the ./HookBidPool.sol file in the forge coverage output.
Additionally, it is easier/better to ensure that EIP-712 signatures are compliant using the Hardhat coverage test system. Additional tests have been added to
integration.t.jsto ensure that signatures are encoded and decoded correctly.Modified Files
Core Logic:
src/HookBidPool.sol: this is the main new contract, which controls the HookBidPools as described above.src/interfaces/IHookOption.sol: our existing options comply with this interface, and we'd like to also make all new option types in the future comply with it. It has the most generic form of option information.src/lib/PoolOrders.sol: order structs and EIP helpers for the new pool order types.Dependencies:
src/interfaces/zeroex-v4/IPropertyValidator.sol: 0x protocol's property validator interfacesrc/lib/lyra/BlackScholes.sol: Lyra's Black Scholes calculatorsrc/lib/lyra/FixedPointMathLib.sol: FixedPointMath for Black Scholessrc/lib/lyra/Math.sol: Regular math for Black Scholes. ABS Value also used by skew in the PoolOrders.sol filesrc/lib/synthetix/DecimalMath.sol: Decimal Math required by Black Scholessrc/lib/synthetix/SignedDecimalMath.sol: Signed Decimal math required by Black Scholes