yanyan ho
    • 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
    • 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 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
    ## 机制设计 https://pacific-tuck-372.notion.site/Rebase-5d6d695fd94e4fb6bc01a8564c06d461 https://pacific-tuck-372.notion.site/AMM-fa633aa1e1ad435ea7cb60ef0b9e3f1e https://pacific-tuck-372.notion.site/LP-83d0cc8b594541f7ad1ee2e37e3d914a # LP收益分析 AMM资金流向: ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/83af8070-a078-4a43-a9c5-0caa926811ef/Untitled.png) **添加流动性:** deltaL = deltax/RealBaseReserve * totalSupply deltaY = deltax *Y/X; **移除流动性:** x = deltaL/totalSupply * realBaseReserve y = (baseAmount * _quoteReserve) / _baseReserve; realBaseReserve相当于把netQuoteToken(净头寸)平掉,得到真实的realBaseResearve ### 推导过程: 一: 交易不影响用户LP占比,以及realBaseReserve.(手续费忽略的情况下)所以不影响之前LP用户的收益。 ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5e969b7c-08b6-4df7-8212-a260007a4101/Untitled.png) 二: LP做市影响之前LP可提取额度。(平衡新老LP收益) ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/315d628c-4b3b-40bb-962c-d6d1ff491773/Untitled.png) 已知: $X_{real} = \dfrac{X_{0}Y_{0}}{Y_{0}+netP}$ $T1 = (\dfrac{\delta{X_{0}}}{X_{real}} +1)T =\dfrac{(X_{0}+\delta{X_{0})}*Y_{0}+ \delta{X_{0}*netP}}{X_{0}*Y_{0}} * T$ ### 某LP充流动性前用户A可提流动性: $LP0 = t/T * X_{real}=t/T *\dfrac{X_{0}Y_{0}}{Y_{0}+netP}$ ### 某LP充流动性后用户A可提流动性: $LP1 = t/T1 *X_{real1}$ 根据上述公式可知T1和Xreal1: $X_{real1} = \dfrac{(X_{0}+\delta{X})(Y_{0}+P_{0}*\delta{X})}{Y_{0}+P_{0}*\delta{X}+netP}$ $LP1 = t/T*\dfrac{X_{0}*Y_{0}}{(X_{0}+\delta{X_{0})}*Y_{0}+ \delta{X_{0}*netP}}*\dfrac{(X_{0}+\delta{X})(Y_{0}+P_{0}*\delta{X})}{Y_{0}+P_{0}*\delta{X}+netP}$ 我们定义index变量,表示LP用户这次充提的影响系数。 $index = LP0/LP1=\dfrac{Y_{0}+netP+P_{0}*\delta{X}}{{Y_{0}+netP}}*\dfrac{(X_{0}+\delta{X_{0})}*Y_{0}+ \delta{X_{0}*netP}}{(X_{0}+\delta{X})(Y_{0}+P_{0}*\delta{X})}\\ \\$ $index = \dfrac{T1*X_{real}}{T*X_{real1}} = \dfrac{X_{real}+ \delta{X}}{X_{real1}}$ $index =(\dfrac{Y1+netP}{Y_{0}+netP})*[\dfrac{Y0}{Y1}+ \dfrac{\delta{X_{0}}*netP}{(X_{0}+\delta{X_{0})}Y_{1}}]$ 用户index情况也相同; ## 添加流动性对LP影响**分析:** ### 1 如果添加流动性相对于池子总流动性很小 即 $\dfrac{\delta{X_{0}}}{(X_{0}+\delta{X_{0}})} --> 0$ 则 $index =(\dfrac{Y1+netP}{Y_{0}+netP})*\dfrac{Y0}{Y1}$ **净头寸为正的话(空单>多单)index>1, 则 此次充值流动性不利于用户** **净头寸为负的话(多单>空单)index<1,则此次充值流动性有利于用户** **netP 越大,偏离越大** 请注意,此时 $\dfrac{Y0}{Y1} -->1$ , 所以index ~ 1 ### 2 如果添加的流动性相对于池子总流动性很大 即 $\dfrac{\delta{X_{0}}}{(X_{0}+\delta{X_{0}})} --> 1$ 则 $index =(\dfrac{Y1+netP}{Y_{1}})$ **净头寸为正的话(空单>多单)index>1, 则 此次充值流动性不利于用户** **净头寸为负数的话(空单<多单)index<1,则此次充值流动性有利于用户** **netP 越大,偏离越大** 请注意,此时 $\dfrac{netP}{Y1} -->0$ , 所以index ~ 1 两种情况都是净头寸决定了用户的指数的大小。所以建议在净头寸小的时候操作。 ### 一般情况 因为做市价格不变 $\dfrac{\delta{X_{0}}}{X_{1}} = \dfrac {\delta{Y_{1}}}{Y1}$ $\dfrac{\delta{X_{0}}}{(X_{0}+\delta{X_{0}})} = \dfrac {Y_{1}-Y_{0}}{Y1}= m$ $index =(\dfrac{Y1+netP}{Y_{0}+netP})*[\dfrac{Y0+m*netP}{Y_{1}}]$ $m= \dfrac{Y_{1}-Y_{0}}{netP+Y_{1}}$时, index=1; 即只有netP=0时候index才为1; $index =(\dfrac{Y1+netP}{Y_{0}+netP})*[\dfrac{Y_{0}}{Y_{1}}+\dfrac{Y{1}-Y_{0}}{Y_{1}^{2}}*netP]$ 建议在净头寸小的时候操作。(gt1) ### 验证: [https://docs.google.com/spreadsheets/d/1laOuawzlnvZTZXq8AKn3sk9WQcbIAoB4vxLTKd7zRlM/edit#gid=1553379066](https://docs.google.com/spreadsheets/d/1laOuawzlnvZTZXq8AKn3sk9WQcbIAoB4vxLTKd7zRlM/edit#gid=1553379066) ## 移除流动性对LP影响**分析:** ### 一般情况 同理可得 $index =(\dfrac{Y1+netP}{Y_{0}+netP})*[\dfrac{Y0}{Y1}- \dfrac{\delta{X_{0}}*netP}{(X_{0}-\delta{X_{0})}Y_{1}}]$ 因为做市价格不变 $\dfrac{\delta{X_{0}}}{X_{1}} = \dfrac {\delta{Y_{1}}}{Y1}$ $\dfrac{\delta{X_{0}}}{(X_{0}-\delta{X_{0}})} = \dfrac {Y_{0}-Y_{1}}{Y1}$ **即只有netP=0时候index才为1;** $index =(\dfrac{Y1+netP}{Y_{0}+netP})*[\dfrac{Y_{0}}{Y_{1}}+\dfrac{Y{1}-Y_{0}}{Y_{1}^{2}}*netP]$ 跟填充流动性式子保持一致, 不过由于Y1,Y0大小刚好相反, index取值区相反方向。 所以如果充提保持频次一样,index最终趋于一; 建议在净头寸小的时候操作。 ### Rebase机制对LP的影响 $X_{real0} = \dfrac{X_{0}Y_{0}}{Y_{0}+netP}$ $X_{real1} = \dfrac{X_{0}Y_{1}}{Y_{1}+netP}$ 已知rebase前后: $Y{0}=P_{0}*X_{0}$ $Y{1}=P_{1}*X_{0}$ $index = \dfrac{\dfrac{P_{0}*X_{0}*X_{0}}{Y_{0}+netP}}{ \dfrac{P_{1}*X_{0}*X_{0}}{Y_{1}+netP}}$ 令 $m= P0/P1$ $index= \dfrac{P_{0}}{P_{1}}*\dfrac{P_{1}X_{0}+netP}{P_{0}X_{0}+netP}= 1 + \dfrac{(m-1)netP}{Y_{0}+netP}$ netP > 0 时:空>多 1 如果向上rebase, 即m<1, 则realBaseReserve增加 2 如果向下rebase, 即m>1, 则realBaseReserve减少 netP < 0 时: 1 如果向上rebase, 即m<1, 则realBaseReserve减少 2 如果向下rebase, 即m>1, 则realBaseReserve增加 ### Liquidate机制对LP的影响 假设用户仓位为(a0, b0), $X_{real0} = \dfrac{X_{0}Y_{0}}{Y_{0}+netP}$ $X_{real1} = \dfrac{(X_{0}+a_{0}){Y_{1}}}{Y_{1}+netP}$ $index = X_{real_{0}}/X_{real_{1}}= \dfrac{Y_{1}+netP}{Y_{0}+netP}*\dfrac{X_{0}}{X_{1}} * \dfrac{Y_{0}}{Y_{1}}$ 清算时候: $\dfrac{X_{0}}{X_{1}} * \dfrac{Y_{0}}{Y_{1}} >1$ 恒成立 假设 $\dfrac{Y_{1}+netP}{Y_{0}+netP}*\dfrac{X_{0}}{X_{1}} * \dfrac{Y_{0}}{Y_{1}}>1$ 则 $netP >\dfrac{Y_{0}Y_{1}*(X_{1}-X_{0})}{X_{0}Y_{0}-X_{1}Y_{1}}$ 可以看出跟净头寸有关, **走场内价格清算:** **如果netP<0 , 且清算做多仓位(即 X1- X0 > 0),则 index<1 , realBaseReserve增加,有利于LP** **如果netP>0 , 且清算做空仓位(即 X1- X0 < 0),则 index>1,realBaseReserve减少, 则不利于LP。** **走场外价格清算:** **如果,清算做空仓位,netP减少,K值不变,则有利于LP** **清算做多仓位,netP增加,K值不变,则不利于LP** # Rebase机制调研 ### perpetual v1 ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ed3c84a5-fccf-4ace-9fb0-0e553247ff93/Untitled.png) ### perpetual v2 1. 与v1的区别 - 使用uniswap v3,taker的对手方为流动性提供者 - 交叉保证金和多抵押品交易 ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/602e7f24-cf4a-4a2c-b0e2-023fb7f75db7/Untitled.png) 1. 一次taker流程 开仓 ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/42a18dec-7466-493d-9ebe-27d1c56db41a/Untitled.png) 平仓 ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b69b83cd-13b6-4d54-97e2-b4599c239e89/Untitled.png) 1. 一次maker流程

    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