Robert Leifke
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Spec: Panoptic Protocol An exchange protocol for trading non-linear perpetuals on the Ethereum Virtual Machine (EVM). ## Introduction ### Cryptocurrency Perpetuals The cryptocurrency perpetuals market is massive. In fact, over a \$1B in notional value is traded on Deribit, a centralized options exchange on any given day. This is becuase options which are financial instrument that gives a buyer the right but not obligation to buy an asset have been incredibly useful for hedging the volatility that is seen in cryptocurrency markets. Yet it's growth has been limited by the liquidity fragmentation inherent to option contracts. Options volume bale in comparison to perpetual futures which trade upwards of \$60B a day on centralized venues. In an attempt replicate the success of "perpetual futures," Dave White et al. (2021) introduced in \emph{power perpetuals} a mechanism for making an option's convexity exposure perpetual. The derivative achieves this by squaring the price of an underlier to mathematically ensure constant gamma. While the continuous leverage is attractive, the constant gamma exposure could also open the door to hedging volatility in cryptocurrency markets. Yet, volume remains low, constrained by the available liquidity on-chain. For the few power perpetual derivatives that do exist on-chain such as Squeeth, they rely on sophisticated market makers, centralized infrastructure, and oracles. This has caused them to suffer many shortcomings including scaling liquidity with demand and supporting long tail assets. ### CFMMs CFMMs, short for constant function market makers describe an automated system for pooling liquidity to a single trading function where the payoff of the pooled liquidity produces a non-linear payoff. These payoffs have been shown to be that of a replicated portfolio of options. In the case of Panoptic, it leverages the liquidity in the Uniswap V3 protocol to create a greater array of payoffs, including leveraged ones. #### Duality The duality between a CFMM trading function and its payoff can be expressed as. ## Architecture [Panoptic](https://arxiv.org/pdf/2204.14232.pdf) is built as a collection of smart contracts that enable the lending and liquidity management of existing Uniswap V3 positions for the purpose of turning them into tokenized options. The core logic is written in four contracts `PanopticPool.sol` contract where the actual option is minited, burned, and can be managed. Each instance is deployed sperately. Panoptic uses its own for expressing option position called **SFPM** short for **SemiFungiblePositionManager** which inherits ERC-1155. Then there is the `collateralTracker` which is a system for which margining is set for each individual pool. **Diagram from panoptic repo:** ```ml contracts/ ├── CollateralTracker — "ERC4626 vault where token liquidity from Panoptic Liquidity Providers (PLPs) and collateral for option positions are deposited and collateral requirements are computed" ├── PanopticFactory — "Handles deployment new Panoptic instances on top of Uniswap pools, initial liquidity deployments, and NFT rewards for deployers" ├── PanopticPool — "Coordinates all options trading activity - minting, burning, rolling, force exercises, liquidations" ├── SemiFungiblePositionManager — "The 'engine' of Panoptic - manages all Uniswap V3 positions in the protocol as well as being a more advanced, gas-efficient alternative to NFPM for Uniswap LPs" ├── tokens │ ├── ERC1155Minimal — "A minimalist implementation of the ERC1155 token standard without metadata" │ ├── ERC20Minimal — "A minimialist implementation of the ERC20 token standard without metadata" │ └── interfaces │ └── IERC20Partial — "An incomplete ERC20 interface containing functions used in Panoptic with some return values omitted to support noncompliant tokens such as USDT" ├── types │ ├── TickStateCallContext — "Implementation for a custom data type that can hold a current and a median Uniswap pool tick, as well as a caller" │ ├── LeftRight — "Implementation for a set of custom data types that can hold two 128-bit numbers" │ ├── LiquidityChunk — "Implementation for a custom data type that can represent a liquidity chunk of a given size in Uniswap - containing a tickLower, tickUpper, and liquidity" │ └── TokenId — "Implemenation for the custom data type used in the SFPM and Panoptic to encode position data in 256-bit ERC1155 tokenIds - holds a pool identifier and up to four full position legs" ├── libraries │ ├── CallbackLib — "Library for verifying and decoding Uniswap callbacks" │ ├── Constants — "Library of Constants used in Panoptic" │ ├── Errors — "Contains all custom errors used in Panoptic's core contracts" │ ├── FeesCalc — "Utility to calculate up-to-date swap fees for liquidity chunks" │ ├── InteractionHelper — "Helpers to perform bytecode-size-heavy interactions with external contracts like batch approvals and metadata queries" │ ├── Math — "Library of generic math functions like abs(), mulDiv, etc" │ └── PanopticMath — "Library containing advanced Panoptic/Uniswap-specific functionality such as our TWAP, price conversions, and position sizing math" │ └── SafeTransferLib — "Safe ERC20 transfer library that gracefully handles missing return values" ├── univ3-libraries │ ├── TickMath — "Math library for computing sqrt prices from ticks and vice versa" │ └── LiquidityAmounts — "Provides functions for computing liquidity amounts from token amounts and prices" ├── multicall │ └── Multicall — "Adds a function to inheriting contracts that allows for multiple calls to be executed in a single transaction" └── periphery └── PanopticHelper — "Contains useful position construction and query functions, including collateral checks and account liquidation price finders" ``` ### Option properties Every option is perpetual with #### Stremia The "streaming premia" or the continous fee earned by an option seller for the duration that liquidity is deposited in Panoptic. Each pool in Uniswap V3 has to keep track of fees so that when a LP withdraws and burns their position, they earn back the value of their portfolio and the fees accumlated. To do this, the protocol uses two variables called `feeGrowthGlobal0X128` and `feeGrowthGlobal1X128` as global accumaltors. Where fees owed for each position are in terms of `token0` and `token1` ``` /// @notice Emitted when a position is created/minted /// @dev Recipient is used to track whether it was minted directly by the user or through an option contract /// @param caller the caller who created the position. In 99% of cases `caller` == `recipient`. /// @param tokenId The tokenId of the minted position /// @param positionSize The number of contracts minted, expressed in terms of the asset event TokenizedPositionMinted( address indexed caller, uint256 indexed tokenId, uint128 positionSize ); ``` `positionSize` is the number of Fees accumlate to on deposited V3 positions using the SFPM. The fees earned is accounted as the `s_grossPremia` and `s_owedPremia` is the premia owed after the user withdraws from Panoptic. ll `PanopticPool.sol` `mintOptions` `burnOptions` `rollOptions` UniswapV3 `TickStateCallContent.sol` contains that tick state. `LeftRight.sol` SemiFungiblePositionManager.sol SFPM legs of different sizes optionRatio: 1 isLong: tokenType: 0 or 1 (put or call option) riskPartner: strike: width: pp.mintOptions() `effectiveLiquidityLimitX32` is the an **optional** parameter that allows us to specify an upper bound of liquidity for a certain chunk. Option buyers (borrowing a LP position) will set this so that the stremia multiplier is below a certain threshold. Max slippage value => tickLimit?? ### CollateralTracker An ERC-4626 Vault * commission fees and options premia * payments for options * calculating liquidation bonuses * collateral requirment of every account and position A Uniswap LP position is deposited into a CollateralTracker Vault. ### Minting an Option `legIndex` is 0 to 3 (four legs) and is the position of the leg in the tokenId. `optionRatio` is the size of the leg compared to other legs. We need to pass in a positionIDList and specify a size. Answers from Henry #### How do fees factor in to how much debt you owe? By "debt" I assume you mean debt from option sellers to PLPs. We have fixed commission fees, so after you open your position you owe a constant amount of debt (denominated in tokenType) until it is closed. #### Are you only allowed to borrow the same positions (tick upper and tick lower) that have already been deposited by shorts? Yep! You cannot open a long position if the underlying (tickLower, tickUpper, tokenType) chunk has not already been sold by a seller - it is not there to remove in the first place! ## Liquidity tracking in Panoptic Liquidity in "chunks" and moved from `uniswap pool` into panoptic to mint a option position. * `tokenType`: long or short * `TickLowLimit`: lower tick limit for price slippage * `TickHighLimit`: upper tick All define a specific location for the UniswapV3 Pool. * `liquidity`: The total amount of liquidity sitting in Uniswap is the `netLiquidity` and `removeLiquidity` signifying the total liquidity that has been removed to mint option. `owed` #### Liquidity Calculation ### Payoff compiler Each tick is a dirac delta function with the #### Power Perpetual A power perpetual is a fixed gamma derivative that aims consolidate liquidity across an options chain in one fungible contract. On panoptic, one could mint "Squeeth," a power perpetual with a fixed gamma of two, by specifying the `width` paramater when minting an multi-legged option from the `PanopticPool.sol` contract. Applications include hedging off-chain options, arbitraging volatility, or going long on an underlier with added convexity.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully