Header | Content |
---|---|
Author | Edson Ayllon (@relativeread) |
Created | 2022-7-6 |
Status | Draft |
Motivation
This integration will add a new financial tool for managers, options trading. This may attract managers with options trading as a skill/expertise. As well as letting existing managers create more dynamic strategies enabled by options, such as going long or short volatility.
Description
Lyra is an options trading platform built on top of Synthetix. Integrating Lyra would bring options trading to dHEDGE managers.
Implementation
Contract Guards
LyraOptionMarketWrapperContractGuard
The Lyra Finance UI uses this contract for all the frontend transactions. I believe for opening and closing the positions, the frontend only uses openPosition, closePosition (and I can see some transactions of forceClosePosition)
openPosition
This will create a NFT of position, if a position already exists, then it will increase the position amount.
Inputs: OptionPositionParams uint strikeId; // The id of the relevant OptionListing uint positionId; uint iterations; uint setCollateralTo; uint currentCollateral; OptionMarket.OptionType optionType; // Is the trade a long/short & call/put? uint amount; // The amount the user has requested to close uint minCost; // Min amount for the cost of the trade uint maxCost; // Max amount for the cost of the trade uint stableAmount; // Amount of stable coins the user can use ERC20 stableAsset; // Address of coin user wants to open with
Guard implementation:
- Ensure quote asset is supported by the pool.
synthQuoteKey = SynthetixAdapter.quoteKey(OptionMarket)
synthQuote = SynthetixProxyAddressResolver.target.getAddress(synthQuoteKey)
require(isValidAsset(synthQuote))
- Ensure base asset is supported by the pool.
synthBaseKey = SynthetixAdapter.baseKey(OptionMarket)
synthBase = SynthetixProxyAddressResolver.target.getAddress(synthBaseKey)
require(isValidAsset(synthBase))
closePosition
/ forceClosePosition
This will reduce or close the existing position.
Inputs: OptionPositionParams uint strikeId; // The id of the relevant OptionListing uint positionId; uint iterations; uint setCollateralTo; uint currentCollateral; OptionMarket.OptionType optionType; // Is the trade a long/short & call/put? uint amount; // The amount the user has requested to close uint minCost; // Min amount for the cost of the trade uint maxCost; // Max amount for the cost of the trade uint stableAmount; // Amount of stable coins the user can use ERC20 stableAsset; // Address of coin user wants to open with
Guard implementation:
- Ensure quote asset is supported by the pool.
synthQuoteKey = SynthetixAdapter.quoteKey(OptionMarket)
synthQuote = SynthetixProxyAddressResolver.target.getAddress(synthQuoteKey)
require(isValidAsset(synthQuote))
- Ensure base asset is supported by the pool.
synthBaseKey = SynthetixAdapter.baseKey(OptionMarket)
synthBase = SynthetixProxyAddressResolver.target.getAddress(synthBaseKey)
require(isValidAsset(synthBase))
Asset Guard
LyraOptionMarketWrapperAssetGuard
Asset guard for the lyra option market wrapper contract. (new Asset Type = 10) The dHEDGE pool will receive the NFTs of option positions.
Similar to Uni v3 Asset Guard with NFT positions to get the user position NFTs. Each NFT position needs to be priced (likely in sUSD, then converted to real USD). We can enable a maximum of 2 positions in a dHEDGE pool. (this is configurable via constructor)
getBalance`
The balance will be similar to the UniswapV3AssetGuard, but it will calculate the value of the positions in sUSD.
- Query all available markets and owned positions.
- Check if exceeds the maxium position count.
- Calculate the value of a position. The position value calculation logic is different per each option type. Available option types are
LONG_CALL
,LONG_PUT
,SHORT_CALL_BASE
,SHORT_CALL_QUOTE
,SHORT_PUT_QUOTE
. - Returns the value of total positions in sUSD
withdrawProcessing
- Query all available markets and owned positions.
- Check if exceeds the maxium position count.
- Prepare following two transactions per each positionFirst transactions is option token (NFT)
approve
transaction to our dHEDGE lyra wrapper contract. The LyraOptionMarketWrapper contract’s forceClosePosition function doesn’t accept any recipient parameter. We decided to build our own wrapper contract that accept the recipient parameter and transfers the withdrawn portion directly to user. BTW this approve transaction is required because the LyraOptionMarketWrapper’sforceClosePosition
requies the ownership of Option NFT.Second transaction isforceClosePosition
transaction to our dHEDGE lyra wrapper contract. Our wrapper contract will receive Option NFT ownership and callsforceClosePosition
function of LyraOptionMarketWrapper contract. It transfers the withdrawn portion assets to recipient address. It also returns the Option NFT back to the pool.
Asset Aggregator
Use the chainlink price oracle for sUSD