ERC-7390 ERC-20 vanilla option standard (Vanilla Options for ERC-20 Tokens)
Draft · Vaults & DeFi · created 2022-09-02
Defines a common interface for creating, buying, and exercising vanilla options, the right to buy or sell an ERC-20 token at a fixed price within a fixed period. The right is represented as an ERC-1155 token, so it can be partially purchased or transferred to someone else.
Why it is needed
Options are a financial instrument widely used to manage risk or to invest in price-movement opportunities. Many platforms selling options have also emerged in decentralized finance (DeFi), but each platform has defined and implemented options in its own different way. This creates a compatibility problem, where an option created on one platform cannot be used on another. The starting point of this proposal is that, just as fungible tokens or NFTs are usable everywhere thanks to common standards, options should likewise be compatible with each other. With a common interface, users can trade options seamlessly across multiple apps, and developers can build decentralized option platforms or more complex exotic options on top of this standard.
What to implement
function create(VanillaOptionData calldata optionData) external returns (uint256);: Takes a struct containing the option terms, creates a new issuance, moves the collateral into the contract, and returns the issuance id.function buy(uint256 id, uint256 amount) external;: Buys amount worth of options from the given issuance, pays the premium to the issuer, and receives a redeem token.function exercise(uint256 id, uint256 amount) external;: Exercises amount worth of options within the exercise window. For a call, the holder pays the strike price and receives the underlying token. For a put, the holder gives up the underlying token and receives the strike price.function retrieveExpiredTokens(uint256 id, address receiver) external;: After the exercise window ends, the issuer retrieves the remaining unexercised collateral to the receiver.function cancel(uint256 id, address receiver) external;: The issuer cancels an issuance that no one has bought yet and gets the collateral back to the receiver.function updatePremium(uint256 id, uint256 amount) external;: The issuer changes the premium price. This has no effect on buyers who have already purchased.function updateAllowed(uint256 id, address[] memory allowed) external;: The issuer changes the list of addresses allowed to buy.function issuance(uint256 id) external view returns (OptionIssuance memory);: Queries all the key information about the issuance for the given id.event Created(uint256 indexed id);: Emitted when an issuance is successfully created and the collateral is locked.event Bought(uint256 indexed id, uint256 amount, address indexed buyer);: Emitted when an option is purchased, along with the issuance id, amount, and buyer address.event Exercised(uint256 indexed id, uint256 amount);: Emitted when an option is exercised.event Expired(uint256 indexed id);: Emitted when the issuer retrieves unexercised collateral.event Canceled(uint256 indexed id);: Emitted when the issuer cancels an issuance.event PremiumUpdated(uint256 indexed id, uint256 amount);: Emitted when the issuer changes the premium. The changed value applies to the entire issuance.event AllowedUpdated(uint256 indexed id, address[] allowed);: Emitted when the issuer changes the list of addresses allowed to buy.
In depth
Issuance units and the VanillaOptionData struct
Options are managed as units of issuance, and each issuance is distinguished by an id and independently bought, exercised, and canceled. When calling create, the issuer fills in and passes a VanillaOptionData struct. side is Call or Put, underlyingToken is the underlying token, and amount is the maximum quantity of the underlying token that can be exercised. strikeToken and strike set the exercise price, where strike is the price per one unit of the underlying token denominated in strikeToken. premiumToken and premium are the payment token and amount of the premium, where premium is set as the value for exercising the full amount of the issuance. exerciseWindowStart and exerciseWindowEnd are the exercisable period in Unix seconds, and allowed is the list of addresses permitted to buy; if empty, anyone can buy. Issuance state is stored in the OptionIssuance struct along with writer (the issuer), exercisedAmount (amount exercised), and soldAmount (amount sold).
create and the collateralization rules
create transfers collateral from the issuer to the contract, mints a new issuance, returns an id, and emits a Created event. For a call, the caller must pre-approve the underlying token equal to amount; for a put, the caller must pre-approve the exercise cost computed from strikeToken. The exercise cost (exerciseCost) is calculated at issuance time as (strike * amount) / 10^(underlying token decimals). To avoid increasing counterparty risk, it is strongly recommended that an issuance be fully collateralized at the time of create, and implementations that allow undercollateralization must define their own mechanism for replenishing collateral. The function must revert if underlyingToken or strikeToken is the zero address, if premium is nonzero but premiumToken is the zero address, if amount or strike is zero, or if exerciseWindowStart is earlier than the current time or exerciseWindowEnd is earlier than exerciseWindowStart.
buy and the ERC-1155 redeem token
buy(id, amount) is the function for purchasing amount units of an option from a given issuance. The buyer must pre-approve spending of premiumToken equal to their share of the total premium, and the premium is transferred directly to the issuer during execution of the function. If the allowed list is non-empty, the buyer's address must be on it, and the call must revert if amount is zero or exceeds the remaining sellable quantity, or if the current time is past exerciseWindowEnd. On a successful purchase, amount units of an ERC-1155 redeem token are minted to the buyer and a Bought event is emitted. Because the redeem token can be transferred between users, the right to exercise itself can be passed on, and this structure allows a single issuance to have multiple buyers.
How exercise works
exercise(id, amount) burns amount of the buyer's redeem tokens and exercises the option. For a call, the buyer pays the issuer strikeToken equal to the exercise price and receives the underlying token. For a put, the buyer transfers the underlying token to the issuer and receives strikeToken equal to the exercise price. Therefore, before exercising, the buyer must have pre-approved spending of strikeToken for a call or underlyingToken for a put. Exercise is only possible when exerciseWindowStart <= current time <= exerciseWindowEnd, and the call must revert if amount is zero or if the buyer does not hold that many redeem tokens. If only part of the position is exercised, the exercise amount is adjusted proportionally, and an Exercised event is emitted on success.
Collateral retrieval (retrieveExpiredTokens) and cancellation (cancel)
Once the current time is past exerciseWindowEnd, the issuer can call retrieveExpiredTokens(id, receiver) to retrieve the remaining, unexercised collateral to receiver. For a call this returns the underlying token, for a put it returns strikeToken, and an Expired event is emitted. An issuance that has not sold any portion at all can be canceled with cancel(id, receiver) to reclaim the collateral, emitting a Canceled event. Both functions must revert if called by an address other than the issuer, and receiver must be set to the caller's address if it is the zero address. On a successful retrieval or cancellation, an implementation MAY delete the issuance from the contract.
Updating the premium and the allowed list
The issuer can change the premium at any time with updatePremium(id, amount). Here, amount is a price based on the issuance's total amount, not the unsold remainder, and it has no effect on buyers who have already purchased. updateAllowed(id, allowed) can also be used to change the list of addresses permitted to buy; a buyer who has already purchased the option can continue to exercise it even if removed from the new list. Both functions can only be called by the issuer, must revert if the current time is past exerciseWindowEnd, and emit a PremiumUpdated or AllowedUpdated event, respectively, on success.
Oracle-free design and support for European and American style
This standard operates without an oracle, since it assumes a rational buyer will only exercise when it is profitable to do so. Premium calculation is also left to be done off-chain, for example using a Black-Scholes-type model, to save on gas costs, and the issuer can adjust it at any time to match market conditions. The two exercise window values can express both European and American style options. For European style, exerciseWindowStart is set to the expiration date and exerciseWindowEnd to some period after it; for American style, exerciseWindowStart is set to the current time so exercise is possible immediately. The allowed list can be used to prevent a third party from buying an option before it goes on-chain, which two users had already agreed to off-chain. The standard is specific to ERC-20 tokens, but it can also serve as a basis for other standards handling tokens such as ERC-721.
Proposal status and prerequisites
This proposal is still in Draft status. Its contents may change and discussion may stall, so the latest source should be checked before actual implementation. Implementations of this standard must also implement ERC-1155 to support purchasing only part of an issuance; a separate constructor is not needed, but the ERC-1155 constructor must be invoked. The underlying token, strike token, and premium token are all assumed to be ERC-20 tokens.
Things to watch out for
- Caution regarding arbitrage bots for European-style options: When operating in European style, it is strongly recommended that the issuer significantly raise the premium via updatePremium at the moment the exercise window opens. Otherwise, bots could buy the remaining options and exercise them immediately to capture the arbitrage. This adjustment is not necessary for American style.
- Front-running via premium changes: Since the issuer can change the premium at any time, an attack is possible where the premium is raised very high right before the buyer's transaction. Buyers should only approve spending equal to the agreed premium amount and should not approve more than that.
- Rounding error on partial purchases: When purchasing only part of an issuance, if the proportional share of the premium does not divide evenly, it is rounded down, so the issuer receives less premium than expected. The risk is considered small since most tokens have a large number of decimal places, but it is also possible to attempt repeated purchases of very small amounts to pay less premium overall. However, gas costs make this difficult to turn into a profit.
- Exercise is impossible once the exercise period has passed: Once the current time is past exerciseWindowEnd, the buyer can no longer exercise, and the issuer can retrieve the remaining collateral. Buyers should check the exercisable window and exercise within it.