fmrmf
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# A Liquidity Density Profile for StableSwap-like Hooks Specifies a liquidity density profile on a concentrated liquidity AMM that closely resembles the slippage of the StableSwap invariant across the full tick range, enabling passive, efficient like-like liquidity provision on CLMMs. The liquidity profile function that appears to work well and is simple to implement follows a Cauchy distribution, supplemented by a constant base layer of full range liquidity $$ l_{\gamma, \rho}(\tau) = \frac{L}{\pi \gamma} \bigg[ \frac{1}{1 + (\tau/\gamma)^2} + \frac{1}{1 + (\rho/\gamma)^2} \bigg] $$ Parameter constants $\gamma, \rho$ describe - $\gamma$ -- Half width of liquidity profile around tick zero, acting like 1 / leverage for the AMM - $\rho$ -- How quickly the AMM transitions from constant sum like behavior to constant product $L$ increases/decreases as LPs add/remove liquidity to the profile, but is constant for swaps (ignoring possible compounding of fees). Liquidity is fungible with shares issued proportional to $L$, and weightings between constant base and Cauchy determined by the location in the tick range and profile params. Should be easy to calculate given Cauchy as a probability density normalizes to 1 $$ \frac{1}{L}\int_{-\infty}^{\infty} l_{cauchy}(\tau) d\tau = 1 $$ Plots of price slippage given a fraction of x reserves sold into the pool, $\Delta x / x$, ![slippage-all](https://hackmd.io/_uploads/HywQp8_pJe.png) *Slippage for Modified Cauchy liquidity profile for various $\rho$ compared with Uniswap v2, StableSwap* produce StableSwap-like behavior across the full price range for appropriate parameter choice. For example, Curve $A = 250$ (dotted purple) seems to be most similar in swap dynamics to $l_{\gamma, \rho}$ with $\gamma= 0.0125, \rho=0.4$ (green). Reasoning about appropriate parameter choice seems relatively straight-forward with the liquidity density function approach given the liquidity profile resembles that of log-price behavior in most simple financial models (albeit with a heavier tailed distribution). Would expect ideal $\gamma$ values to relate directly to the half width of the log-price behavior. Meaning, if the log-price process is anticipated to walk around tick 0 with volatility of 50 bps, an appropriate choice of $\gamma$ might be e.g. 150 bps so that the leveraged constant sum regime covers the majority of paths due to the anticipated spread in the log-price process. Constant product via the additional constant liquidity term then kicks in outside the peak to cover tail scenarios, with $\rho$ dictating the speed of the transition. ## Intro Curve's StableSwap invariant extended Uniswap for low slippage swaps between like-like pairs. Stableswap LPs effectively leverage liquidity to offer constant sum (i.e. zero slippage) like behavior around an optimal price of 1, with divergence away from 1 resulting in the AMM curve transitioning to higher slippage constant product like swaps. Curve and Uniswap v2 allowed LPs to be passive, with the AMM curve (and protocol parameter selection) outside of the control of LPs, and the responsibility of LP profitability put on the protocol. Since then, the AMM space has been dominated by concentrated liquidity after the introduction of Uniswap v3, allowing liquidity providers to choose the profile they wish to provide liquidity in. The upside being LPs have more flexibility in their liquidity provision strategies, but the downside is these strategies require a more active approach (and are still not necessarily profitable), result in greater complexity, and sacrifice the fungibility of the LP token position. Vault protocols like Bunni v1, Arrakis, and Gamma Strategies aimed to fill this gap for more passive LPs via managed liquidity strategies. However, given the architecture of Uniswap v3, vaults are an external layer outside of the main logic of the AMM, unable to respond to changes in AMM state via e.g. user-initiated swaps at the moment of the swap. Vault strategies then lag behind the state of the AMM and the vault manager pays the rebalancing costs in both time and transaction fees. Ekubo v1 and now Uniswap v4 recently introduced the concept of extensions/hooks, that allow developers to insert logic at various points in the lifecycle of the user interaction with the underlying concentrated liquidity AMM. Hooks enable passive liquidity products that do not require active external management, likely enabling both active and passive LPs in the same AMM pool. ## A Profile for Like-Like Pairs Bunni v2 proposed the concept of liquidity density profiles to address the passive use case. Bunni v2 LPs deposit fungible liquidity into their Uniswap v4 hook, which specifies a liquidity density function to provision liquidity with across the full tick range of the CLMM pool. The hook adds/removes liquidity to the CLMM pool according to the shape of the profile function at each tick $\tau$ in the full tick range. The liquidity density profile effectively defines the AMM curve in liquidity, price space (instead of reserves space), and the associated slippage swappers receive at different price points. Liquidity density profiles offer the possibility of many different AMM curves at the hook layer, without having to rewrite the underlying pool logic. To transform an AMM specified in reserves space to liquidity space, one could use price as the first derivative of y with respect to x reserves and invert $$ x(p) = {\frac{dy}{dx}}^{-1}(-p) $$ alongside the Uniswap v3 definition of the liquidity function as $$ l(p) = - p \frac{dx}{d\sqrt{p}} $$ But $(dy/dx)^{-1}$ is not necessarily invertible nor simple. To arrive at a Curve-like profile, instead I take a similar approach to the original StableSwap paper. Realizing that in liquidity space, constant sum around price 1 is a Dirac delta function at tick zero scaled by the liquidity amount and constant product is simply a constant. Linear combination of the two would yield a good starting point $$ \chi \cdot \delta(\tau) + c $$ where the symmetry about tick zero is desired for the like-like pairs. As with StableSwap, I want the weighting $\chi$ on the constant sum behavior to reduce to zero as one moves away from the optimal price of 1, which requires spreading the liquidity distribution out away from a Dirac delta. There are a few well known density functions that reduce to a Dirac delta as one takes the width of the density to zero, but easiest to work with and code on-chain would be the Cauchy density function $$ \frac{1}{\pi \gamma} \frac{1}{1 + (\tau/\gamma)^2} $$ where $\gamma \to 0$ limit is the infinite leverage Dirac delta constant sum. Cauchy has the added benefit of being a heavier-tailed density, resulting in a higher (and more concentrated) peak near tick 0, and less tail drop off as $\tau \to \pm \infty$ for the wanted transition to constant product. ![cauchy-gammas](https://hackmd.io/_uploads/SyV0wDOpyx.png) *Cauchy liquidity profile for various $\gamma$ values* Simulating price slippage across a CLMM with a liquidity profile of only Cauchy shows the near zero slippage constant sum behavior occurs for a large % of reserves into the pool (as with Curve) but the dropoff vs StableSwap whitepaper's figure 2 is far more severe outside of the set liquidity spread. ![slippage-cauchy](https://hackmd.io/_uploads/r1wtjwdp1l.png) *Slippage on Cauchy liquidity profile* As tick deviates $|\tau| > \gamma$ away from 0, the amount of capital in as a fraction of reserves needed to move price falls off a cliff, even more so than StableSwap behavior. The tail behavior desired of a transition to constant product is difficult to reproduce for higher leverage (smaller $\gamma$) liquidity profiles. Modifying the Cauchy profile by adding a constant term as a base layer of full range liquidity does the trick $$ l_{\gamma, \rho} (\tau) = {l_{cauchy}}_{\gamma} (\tau) + {l_{cauchy}}_{\gamma} (\rho) $$ ![slippage-cauchy-modified-gammas](https://hackmd.io/_uploads/ry5uNu_pyl.png) producing constant product like slippage (i.e. slippage curve flips from concave to convex) as price deviates out to the tails of the liquidity profile. The constant parameter $\rho$ is best set to be some larger multiple of gamma $n \gamma$ so as not to diminish the concentrated liquidity constant sum behavior near tick zero. ![slippage-all](https://hackmd.io/_uploads/HywQp8_pJe.png) *Slippage for Modified Cauchy liquidity profile for various $\rho$ compared with Uniswap v2, StableSwap* Larger $\rho$ results in the transition to constant product taking longer and will be more drastic once it happens, but with greater amounts of capital dedicated to concentrating liquidity in the peak of the profile. Plotting slippage against Uniswap v2 and StableSwap as well produces a pretty good fit for the green curve above.

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