Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x/gamm][StableSwap] Figure out LP share amount out derivation for stableswap #1368

Closed
Tracked by #1451
ValarDragon opened this issue Apr 28, 2022 · 2 comments · Fixed by #2905
Closed
Tracked by #1451

[x/gamm][StableSwap] Figure out LP share amount out derivation for stableswap #1368

ValarDragon opened this issue Apr 28, 2022 · 2 comments · Fixed by #2905
Labels
T:task ⚙️ A task belongs to a story

Comments

@ValarDragon
Copy link
Member

No description provided.

@ValarDragon ValarDragon mentioned this issue Apr 28, 2022
6 tasks
@daniel-farina daniel-farina moved this to 🔍 Needs Review in Osmosis Chain Development Apr 28, 2022
@p0mvn p0mvn changed the title Figure out LP share amount out derivation for stableswap [x/gamm] Figure out LP share amount out derivation for stableswap May 9, 2022
@p0mvn p0mvn mentioned this issue May 9, 2022
55 tasks
@p0mvn p0mvn changed the title [x/gamm] Figure out LP share amount out derivation for stableswap [x/gamm][StableSwap] Figure out LP share amount out derivation for stableswap May 9, 2022
@p0mvn p0mvn added the T:task ⚙️ A task belongs to a story label May 9, 2022
@catShaark
Copy link
Contributor

Can you provide more description for this issue ?

@AlpinYukseloglu
Copy link
Contributor

AlpinYukseloglu commented Sep 19, 2022

Note: since our stableswap CFMM's constant does not scale linearly with pool assets like our balancer one's does, we cannot use the k value as the total number of pool shares. I have still derived a general formula for how k scales below, but we will have to figure out a way to either scale down our CFMM to make k linear or find some other way to calculate LP shares.

EDIT: It turns out for all-asset joins LP share calculation is completely independent from k value. We can just use the same process that we do for Balancer (start with some arbitrary value for all new pools, then if you increase liquidity by 10% you get 10% of the total share supply minted to you).

Leaving the calculations below in case we do need to eventually linearize k to be able to support single-asset joins.

General formula

Screen Shot 2022-09-19 at 1 51 47 AM

The general formula is: c^(4+j) * k, where c is the factor we scale the total liquidity by (e.g. increasing pool liquidity by 10% would make c = 1.1), and j is the number of assets in the pool that aren't being traded against.

A more intuitive representation might be c^(2 + numAssets) * k

Examples:

  • Two asset pool, increasing liquidity by 15% (c = 1.15, j = 0): k increases to k*(1.15^4)
  • Six-asset pool, decreasing liquidity by 4% (c = 0.96, j = 4): k decreases to k*(0.96^8)

Derivation

Two-asset CFMM:

Screen Shot 2022-09-19 at 1 31 49 AM

Multi-asset CFMM (derived example from 4-asset pool with assets x, y, m, and n):

Screen Shot 2022-09-19 at 1 47 33 AM

@mergify mergify bot closed this as completed in #2905 Oct 1, 2022
mergify bot pushed a commit that referenced this issue Oct 1, 2022
)

Closes: #1368 (this is the last step left in LP share derivation)

## What is the purpose of the change

This PR adds swap fee support for single asset joins.

## Brief Changelog

- Factor in swap fees to single asset join input and truncate to int
- Fix bug where joining then exiting could yield more tokens (specific fix: lower target for LP share binary search function by additive error tolerance so output is never greater than input)

## Testing and Verifying

- The changes made in this PR are tested in `amm_test.go` under `TestCalcSingleAssetJoinShares`

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? (no)
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? (no)
  - How is the feature or change documented? (not documented)
Repository owner moved this from Needs Review 🔍 to Done ✅ in Osmosis Chain Development Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:task ⚙️ A task belongs to a story
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants