Skip to content

Conversation

@jake-nyquist
Copy link
Contributor

@jake-nyquist jake-nyquist commented Apr 1, 2023

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 coverage has 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.js to 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 interface
  • src/lib/lyra/BlackScholes.sol: Lyra's Black Scholes calculator
  • src/lib/lyra/FixedPointMathLib.sol: FixedPointMath for Black Scholes
  • src/lib/lyra/Math.sol: Regular math for Black Scholes. ABS Value also used by skew in the PoolOrders.sol file
  • src/lib/synthetix/DecimalMath.sol: Decimal Math required by Black Scholes
  • src/lib/synthetix/SignedDecimalMath.sol: Signed Decimal math required by Black Scholes

Copy link
Contributor Author

jake-nyquist commented Apr 1, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

This was referenced Apr 1, 2023
@jake-nyquist jake-nyquist marked this pull request as ready for review April 5, 2023 15:46
@jake-nyquist jake-nyquist changed the base branch from nyquist/puts to 03-31-forge-fmt April 11, 2023 14:35
@jake-nyquist jake-nyquist force-pushed the 04-01-bid_pool branch 3 times, most recently from 265a812 to 6980293 Compare April 12, 2023 20:57
@jake-nyquist jake-nyquist changed the base branch from 03-31-forge-fmt to main April 13, 2023 03:12
@jake-nyquist jake-nyquist merged commit 0548fc7 into main Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants