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

amountIn calculation formula bug #125

Open
lidd77 opened this issue May 3, 2022 · 4 comments
Open

amountIn calculation formula bug #125

lidd77 opened this issue May 3, 2022 · 4 comments

Comments

@lidd77
Copy link

lidd77 commented May 3, 2022

hey,
image

Based on getAmountOut formula, we should not use 'add(1)' to calculate amountIn value.
But I find that getAmountIn function use 'add(1)' to calculate amountIn , I do not know why.
maybe its a bug ? .

Expecting your reply !

@kartikjn
Copy link

division in solidity takes the floor value, to compensate that loss in decimal, they are adding 1.

@fmdev99
Copy link

fmdev99 commented Jun 15, 2022

Should the formula for getAmountIn look like this?:

uint numerator = amountOut.mul(reserveIn).mul(1000);
uint denominator = reserveOut.mul(997).sub(amountOut.mul(1000));

@Samboy76
Copy link

Samboy76 commented Dec 6, 2022

I´m also having a similar issue in that whenever I perform getAmountsIn, the amountRequired ALWAYS supersedes the amountReceived via swapXXX function. Any ideas as to why is this happening?
Thank you

@Samboy76
Copy link

Samboy76 commented Dec 6, 2022

Should the formula for getAmountIn look like this?:

uint numerator = amountOut.mul(reserveIn).mul(1000); uint denominator = reserveOut.mul(997).sub(amountOut.mul(1000));

This would result in an ever worse amountRequired value over the amountReceived after a swap

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

No branches or pull requests

4 participants