0

With Uniswap V2 specifying the path for router function was quite simple:

address[] path;
path[0] = address1;
path[1] = address2;
path[2] = address3;

However, with Unswap V3, path is no more of type address[]. It's of type byte. I've looked through their documentation but don't understand what the byte variable should consist of and how to do the conversion.

Any help will be appreciated.

1 Answer 1

0

You should specify a path in such a form:

(token_in, pool_fee, token_out)

And you can expand it further where token_out should be the next token_in:

(token_0, pool_fee_0, token_1, pool_fee_1, token_2)

and then you encode an array with abi.encodePacked(...)

// You want to swap USDC into WETH and then WETH to UNI
address USDC = address(...);
address WETH = address(...);
address UNI  = address(...);

uint24 USDC_WETH_POOL_FEE = ...;
uint24 WETH_UNI_POOL_FEE  = ...;

bytes swapPath = abi.encodePacked(
   USDC, USDC_WETH_POOL_FEE, WETH, WETH_UNI_POOL_FEE, UNI
);

// Perform a swap
amountOut = ISwapRouter(ROUTER).exactInput(
    path: swapPath,
    ...
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.