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

IndexPool: swap failing #53

Closed
technicallyty opened this issue Aug 13, 2021 · 1 comment
Closed

IndexPool: swap failing #53

technicallyty opened this issue Aug 13, 2021 · 1 comment
Assignees

Comments

@technicallyty
Copy link
Contributor

technicallyty commented Aug 13, 2021

Isolated test here: https://github.com/sushiswap/trident/blob/master/test/IndexPool.test.ts

IndexPool is currently failing on swap. The _getAmountOut function is returning an unexpectedly large number that causes an overflow when outRecord.amount is updated.

Also appears to be a logic error in the y value calculation - dividing tokenbalanceIn by itself

    function _getAmountOut(
        uint256 tokenBalanceIn,
        uint256 tokenWeightIn,
        uint256 tokenBalanceOut,
        uint256 tokenWeightOut,
        uint256 tokenAmountIn
    ) internal view returns (uint256 finalAmountOut) {
        uint256 weightRatio = tokenWeightIn / tokenWeightOut;
        uint256 adjustedIn = BASE - swapFee;
        adjustedIn = tokenAmountIn * adjustedIn;
        uint256 y = tokenBalanceIn / tokenBalanceIn + adjustedIn; // tokenBalanceIn/tokenBalancein ?
        uint256 foo = pow(y, weightRatio);
        uint256 bar = BASE - foo;
        finalAmountOut = tokenBalanceOut * bar;
    }
@Okavango
Copy link
Contributor

fixed

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

3 participants