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

feat: add bytes utils #10

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

feat: add bytes utils #10

wants to merge 3 commits into from

Conversation

tiennampham23
Copy link

UniswapV3 has the bytes library to decode the routes from the path in the transactions.

Example:
In this line of code

while (true) {
            bool hasMultiplePools = params.path.hasMultiplePools();

            // the outputs of prior swaps become the inputs to subsequent ones
            params.amountIn = exactInputInternal(
                params.amountIn,
                hasMultiplePools ? address(this) : params.recipient, // for intermediate swaps, this contract custodies
                0,
                SwapCallbackData({
                    path: params.path.getFirstPool(), // only the first pool in the path is necessary
                    payer: payer
                })
            );

            // decide whether to continue or terminate
            if (hasMultiplePools) {
                payer = address(this);
                params.path = params.path.skipToken();
            } else {
                amountOut = params.amountIn;
                break;
            }
        }

the path has multiple functions:

  • hasMultiplePools
  • skipToken
  • getFirstPool

@tiennampham23 tiennampham23 changed the base branch from master to main June 13, 2023 03:24
@tiennampham23 tiennampham23 changed the title WIP: add bytes utils feat: add bytes utils Jun 13, 2023
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.

1 participant