HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Help
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like1 BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Sense Math ## Notation $s(t)$ : the scale at the time $t$, i.e. the price of the Target token in the underlying token terms at the time moment $t$ $\theta$ : The tilt value, i.e. the part of the principal that belong to Claims $t_0$ : The issue time $t_m$ : The maturity time $S(t)$ : The maximum scale value earnings were collected at up until the time moment $t$ $x$ : The amount of the Target token being deposited by a user $X$ : The effective amount of the Target token being deposited $\Delta x$ : The addition amount of the Target token, collected during issuance and added to the amount deposited by the user $y$ : An amount of Zero or Claim token $x_z$ : The ideal amount of the Target token redeemed by a Zero holder $X_z$ : The actual amount of the Target token redeemed by a Zero holder $x_c$ : The ideal total amount of the Target token redeemed by a Claim holder $x'_c$ : The ideal amount of the Target token redeemable by a Claim holder before maturity $x''_c$ : The ideal amount of the Target token redeemable by a Claim holder after maturity $X_c$ : The actual total amount of the Target token redeemed by a Claim holder $X''_c$ : The actual amount of the Target token redeemable by a Claim holder after maturity ## Issue At the time moment $t_0$, a user deposits $x$ amount of the Target token. He gets: $y = x \cdot s(t_0)$ units of Zero token, and the same amount of Claim token. In case $s(t_0) < S(t_0)$ the user may immediately collect a certain amount of the Target tokens from just issued Claim token. It would be reasonable to consider this addition amount of the Target token to be added to the original deposited amount. The exact additional amount could be fond from the following equation: $$ \Delta x = (x + \Delta x) \cdot s(t_0) \cdot \left( \frac{1}{s(t_0)} - \frac{1}{S(t_0)} \right) = (x + \Delta x) \cdot \left( 1 - \frac{s(t_0)}{S(t_0)} \right) \\ \Delta x \left( 1 - \left( 1 - \frac{s(t_0)}{S(t_0)} \right) \right) = x \cdot \left( 1 - \frac{s(t_0)}{S(t_0)} \right) \\ \Delta x \cdot \frac{s(t_0)}{S(t_0)} = x \cdot \left( 1 - \frac{s(t_0)}{S(t_0)} \right) \\ \Delta x = \frac{x \cdot \left( 1 - \frac{s(t_0)}{S(t_0)} \right)}{\frac{s(t_0)}{S(t_0)}} = x \cdot \left( \frac{S(t_0)}{s(t_0)} - 1 \right) $$ So the full deposited amount is: $$ X = x + \Delta x = x + x \cdot \left( \frac{S(t_0)}{s(t_0)} - 1 \right) = x \cdot \frac{S(t_0)}{s(t_0)} $$ and the full amount of issued tokens (the same for Zero and Claim tokens) is: $$ Y = X \cdot s(t_0) = x \cdot \frac{S(t_0)}{s(t_0)} \cdot s(t_0) = x \cdot S(t_0) $$ Note, that the outcome for the user is as if the current scale was $S(t_0)$ rather than $s(t_0). Thus is would be reasonable for the protocol to use the current max scale instead of the current scale when calculating the number of Zeros and Claim to be issued. In case the user already have some amount of Claim token when issuing more tokens, earnings should be collected from these Claim token amount before issuing more Claim token. Let's assume that the user already has the amount $Y_l$ of Claim token and earnings wele last colected at the time $t_l$. Then the user may collect the following amount $x_l$ of Target token from his existing Claim holdings: $$ x_l = Y_l \cdot \left( \frac{1}{s(t_l)} - \frac{1}{S(t_0)} \right) $$ Thus the full amount of issued tokens, that takes into accountthe collected earnings from existing Claim holdings, is: $$ Y = \left( x + Y_l \cdot \left( \frac{1}{s(t_l)} - \frac{1}{S(t_0)} \right) \right) \cdot S(t_0) $$ ## Redeem ### Ideal Case In the ideal case, when a user redeems $y$ amount of Zero token, he gets the following amount of the Target token: $$ x_z = y\frac{(1 - \theta)}{s(t_m)} $$ In the ideal case, when a user redeems $y$ amount of Claim token, he gets the following total amount of the Target token: $$ x_c = y\left( \frac{\theta}{s(t_m)} + \frac{1}{s(t_0)} - \frac{1}{s(t_m)} \right) = y \left( \frac{1}{s(t_0)} - \frac{(1 - \theta)}{s(t_m)} \right) $$ Note that: $$ x_z + x_c = \frac{y}{s(t_0)} = \frac{x \cdot s(t_0)}{s(t_0)} = x $$ i.e. the whole deposited amount is redeemed. ### Real Case The following amount could be collected by Claim token holders before maturity: $$ x'_c = y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) $$ So the following amount is to be collected after maturity: $$ x''_c = x_c - x'_c = y\left( \frac{1}{s(t_0)} - \frac{(1 - \theta)}{s(t_m)} \right) - y\left( \frac{1}{s(t_0)} - \frac{y}{(t_m)} \right) = y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) $$ As it is impossible to collect a negative amount, the actual amount collected after maturity is: $$ X''_c = \max (0, x''_c) = \max \left( 0, y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) $$ Thus the actual total amount of the Target tokens got by the Claim token hoder is: $$ X_c = x'_c + X''_c = y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) + \max \left( 0, y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) $$ and the actual amount of the Target tokens got by the Zero token holder is: $$ X_z = x - X_c = \frac{y}{s(t_0)} - y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) - \max \left( 0, y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) =\\= y\left( \frac{1}{S(t_m)} - \max \left( 0, \left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) \right) $$ ### Sunny Day When $$ y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \geqslant 0 $$ we have: $$ X_c = y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) + \max \left( 0, y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) =\\= y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) + y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) =\\= y\left( \frac{1}{s(t_0)} - \frac{(1 - \theta)}{s(t_m)} \right) = x_c $$ $$ X_z = y\left( \frac{1}{S(t_m)} - \max \left( 0, \left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) \right) =\\= y\left( \frac{1}{S(t_m)} - \left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) =\\= y \frac{(1 - \theta)}{s(t_m)} = x_z $$ So, in a summy day scenario, $X_z = x_z$ and $X_c = x_c$. ### Not So Sunny Day When the day is not so sunny, i.e. $$ y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) < 0 $$ we have: $$ X_c = y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) + \max \left( 0, y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) =\\= y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) + 0 =\\= y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) $$ $$ X_z = y\left( \frac{1}{S(t_m)} - \max \left( 0, \left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \right) \right) =\\= y\left( \frac{1}{S(t_m)} - 0 \right) =\\= \frac{y}{S(t_m)} $$ ### Sunny Day Condition Lets transform the summy day condition a bit: $$ y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) \geqslant 0 \\ \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \geqslant 0 \\ s(t_m) - S(t_m) \cdot (1 - \theta) \geqslant 0 \\ s(t_m) \geqslant S(t_m) \cdot (1 - \theta) \\ \frac{s(t_m)}{S(t_m)} \geqslant 1 - \theta $$ ### The Final Formulas So, the final formulas are: Zero token holders get the following amount of the Target tokens after maturity: $$ X_z = \begin{cases} y \frac{(1 - \theta)}{s(t_m)} & \text{if} & \frac{s(t_m)}{S(t_m)} \geqslant 1 - \theta, \\ \frac{y}{S(t_m)} & \text{if} & \frac{s(t_m)}{S(t_m)} < 1 - \theta \end{cases} $$ Claim token holders get the following mount of the Target token after maturity: $$ X''_c = \begin{cases} y\left( \frac{1}{S(t_m)} - \frac{(1 - \theta)}{s(t_m)} \right) & \text{if} & \frac{s(t_m)}{S(t_m)} \geqslant 1 - \theta, \\ 0 & \text{if} & \frac{s(t_m)}{S(t_m)} < 1 - \theta \end{cases} $$ Claim token holders get the following total amount of the Target tokens: $$ X_c = \begin{cases} y\left( \frac{1}{s(t_0)} - \frac{(1 - \theta)}{s(t_m)} \right) & \text{if} & \frac{s(t_m)}{S(t_m)} \geqslant 1 - \theta, \\ y\left( \frac{1}{s(t_0)} - \frac{1}{S(t_m)} \right) & \text{if} & \frac{s(t_m)}{S(t_m)} < 1 - \theta \end{cases} $$ --- ### The Current Formula $$ X''_c = \max \left( 0, y \cdot \frac{\theta}{S(t_m)} - \left( y \cdot \frac{1 - \theta}{s(t_m)} - y \cdot \frac{1 - \theta}{S(t_m)} \right) \right) $$ ## Add Liquidity ### Target $\leftrightarrow$ Zero Pool A user wants to provide the amount $x$ of a Target token as liquidity to a Balancer pool that trades this Target token against a Zero token derived from this Target token. The user splits the oritinal Target amount into two parts: $x = x' + x''$. The first part $x'$ goes directly to the pool. The second part $x''$ is used to issue Zero that will go to the pool. The amount of Zero issued is: $$ y = x'' \cdot S(t) $$ Let $X$ be the pool reserves of the Target token, and $Y$ be the pool reserves of Zero. The user needs to provide the tokens at the same proportion, so: $$ \frac{x'}{y} = \frac{X}{Y} \\ \frac{x'}{x'' \cdot S(t)} = \frac{X}{Y} \\ \frac{x - x''}{x'' \cdot S(t)} = \frac{X}{Y} \\ (x - x'') \cdot Y = x'' \cdot S(t) \cdot X \\ x \cdot Y = x'' \cdot \left( S(t) \cdot X + Y \right) \\ x'' = x \cdot \frac{Y}{S(t) \cdot X + Y} $$ ### Underlying $\leftrightarrow$ Zero Pool A user wants to provide the amount $x$ of a Target token as liquidity to a Balancer pool that trades the Underlying token of this Target token to a Zero token derived from this Target token. The user splits the oritinal amount into two parts: $x = x' + x''$. The first part $x'$ is redeemed for the Underlying token. The amount of obtained underlying token is: $$ z = x' \cdot s(t) $$ The second part $x''$ is used to issue Zero that will go to the pool. The amount of Zero issued is: $$ y = x'' \cdot S(t) $$ Let $Z$ be the pool reserves of the Underlying token, and $Y$ be the pool reserves of Zero. The user needs to provide the tokens at the same proportion, so: $$ \frac{z}{y} = \frac{Z}{Y} \\ \frac{x' \cdot s(t)}{x'' \cdot S(t)} = \frac{Z}{Y} \\ \frac{(x - x'') \cdot s(t)}{x'' \cdot S(t)} = \frac{Z}{Y} \\ (x - x'') \cdot s(t) \cdot Y = x'' \cdot S(t) \cdot Z \\ x \cdot s(t) \cdot Y = x'' \cdot \left( S(t) \cdot Z + Y \right) \\ x'' = x \cdot \frac{s(t) \cdot Y}{S(t) \cdot Z + s(t) \cdot Y} $$ --- ### The Current Formula $$ x'' = x \cdot \frac{Y}{X + Y} $$ ### Sell Claim Mode 1. A user provides amount $x$ of the Target token 2. The amount is split into two parts: $x'$ and $x''$: $x = x' + x''$ 3. The $x''$ amount is used to issue an amount $y$ of Zero and the same amount $y$ or Claim 4. The $x'$ amount of Target and $y$ amount of Zero are put into the pool 5. The pool return the amount $z$ of the LP token 6. The returned LP token amount is sent to the user 7. ... so far so good ... 8. Some amount of the Target token is borrowed 9. The borrowed Target tokens are used to buy the amount $y$ of Zero from the pool (we just put this amount of Zero into the pool and now bying it back!) 10. The amount $y$ of Zero and the same amount $y$ of Claim are combined into the amount $x'$ of Target (we just split and now recombine!) 11. A part of the proceeds from recombining is used to repay the debt 12. The rest proceeds of recombining are returned to the user (teh user just provided some amount of Target token, and now we return part of it!) The whole schema is more or less equivalent to this one: 1. A user provides amount $x$ of the Target token 2. The amount is split into two parts: $x'$ and $x''$: $x = x' + x''$ 3. The $x''$ amount is used to buy an amount $y$ of Zero from the pool 4. The $x'$ amount of Target and $y$ amount of Zero are put into the pool 5. The pool retrun the amount $z$ of the LP token 6. The returned LP token amount is sent to the user

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

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

        Syncing

        Push failed

        Push successfully