Contracts

Check out our shinny new repo here ✨

The Nifty Options contract allows users to deposit their NFT tokens (721 or 1155) along with the following parameters:

  • desired price for their tokens (in ETH)

  • an incentive for someone to fill their price (in ETH)

  • expiration duration (in seconds)

After doing so, a token bundle is created and assigned to a newly minted Option Token (721) for the user.

Whoever owns this Option Token is able to burn it at any point and receive the original underlying NFTs.

However, another user can come along and fill a user’s option by depositing the owner’s desired price.

By doing so, they are instantly rewarded with the incentive ETH deposited by the owner.

At this point, there are 2 outcomes: The option either expires or is manually cancelled by the owner and their underlying NFTs are redeemed and the ETH deposited by the filler is returned. The owner exercises the option before it expires and sells their underling NFTs to the filler for the agreed upon price.

Function Descriptions

contractURI()

  • Returns the medadata URI for the contract from the OptionURIFetcher

tokenURI(uint256)

  • Returns the metadata URI for the token from the OptionURIFetcher

  • The default URI is the URI from the first token in the option bundle

createOption(TokenBundle, uint256, uint256)

  • An option is created with a bundle of 721 or 1155 tokens, desired bundle price, expiration duration, and incentive (msg.value)

  • User’s NFTs are transferred in along with the incentive ETH

  • Option details are stored

  • New option 721 NFT is minted to the user

cancelOption(uint256)

  • Only owner of the option NFT can call

  • Option status must be unfilled or filled

  • Status is set to cancelled to prevent reentrency

  • Underling NFTs are transferred to the option owner

  • If the option has been filled, the ETH is returned to the filler

  • Option NFT is burned

expireOption(uint256)

  • Status must be filled

  • Option must be past expiration

  • Status is set to expired to prevent reentrancy

  • Underlying NFTs are transferred back to owner

  • ETH deposited by filler is returned

  • Option NFT is burned

fillOption(uint256)

  • ETH or WETH value must match the owner’s desired strike price - premium amount

  • Option ID must exist

  • Status must be < filled (not previously filled)

  • Details are updated

  • Incentive is immediately sent to msg.value

exerciseOption(uint256)

  • Only option owner can call

  • Status must be filled

  • Option must not be expired

  • Status is set to exercised to prevent reentrancy

  • WETH deposited by filler is sent to the option owner

  • Underlying NFTs are transferred to filler

  • Option NFT is burned

_transferToken(TokenType, bytes, bytes)

  • Given a TokenType (721 or 1155), it transfers the token with the decoded token details from the 2nd parameter:

    • from

    • to

    • token

    • tokenId

    • amount

  • The 3rd parameter is encoded data that is passed with the safeTransferFrom

_transferTokenBundleIn(TokenBundle)

  • Ensures the arrays in the bundle are the same length

  • Calls the _transferToken function described above for each token in the bundle

Last updated

Was this helpful?