Skip to content

feat: add bytes utils - #10

Open
tiennampham23 wants to merge 3 commits into
mainfrom
feat/byte-utils
Open

feat: add bytes utils#10
tiennampham23 wants to merge 3 commits into
mainfrom
feat/byte-utils

Conversation

@tiennampham23

Copy link
Copy Markdown

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
@tiennampham23
tiennampham23 requested a review from piavgh June 13, 2023 04:06
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