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

[WIP] Stable swap implementation #48

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

[WIP] Stable swap implementation #48

wants to merge 7 commits into from

Conversation

referencedev
Copy link
Contributor

Adding a new type of pool for stable swap between two tokens that have equally priced.

d_prod: U256,
sum_x: Balance,
) -> Option<U256> {
let ann = amp_factor.checked_mul(N_COINS.into())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ann should be amp_factor * N ** N, but here is amp_factor * N

.checked_div(x.checked_mul(N_COINS.into())?.into())?;
c = c
.checked_mul(d)?
.checked_div(ann.checked_mul(N_COINS.into())?.into())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code logic shows n ** (2+n) but comment suggests n ** (2n)

for (idx, min_amount) in min_amounts.iter().enumerate() {
if *min_amount != 0 {
let (amount_out, fee) = invariant
.compute_withdraw_one(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems compute_withdraw_one has figured out the outcome for remove shares with one type of token. When user want withdraw both tokens, each output token balance represent the shares, so cause an insistency with share reduced and tokens balances withdrawed.

@marco-sundsk
Copy link
Contributor

When LP deposit and/or withdraw liquidity in a not perfect ratio, a fee will be charged. So, Why not we just suggest them to deposit and withdraw with perfect ratio to avoid fees? Is there any requirements that leads to support the unbalanced deposit/withdraw actions especially withdraw with one type of token?

Copy link
Contributor

@marco-sundsk marco-sundsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides comments, I made some changes in my folk repo and initate a PR to this repo, please check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants