-1

I have few question:

1.

bool zeroForOne = params.tokenIn < params.tokenOut;

This code means: if params.tokenIn is less than params.tokenOut then make zeroForOne true, am i right?

2. There is a library named Path.sol in libraries directory, it has a function named numPools(). In a contract this library was imported and used forbytes, using Path for bytes, how this code is working then:

sqrtPriceX96AfterList = new uint160[](path.numPools());  

we are imported Path.sol but how path came in path.numPools()? Should not it be Path.numPools()?

3. A code is :

import "./libraries/Path.sol"
contract Check {
    using Path for bytes;
    struct SwapCallbackData {
        bytes path; // swap path
        address payer; // address who provides inout token in swaps
    }
    function _swap(
    uint256 amountIn,
    address recipient,
    uint160 sqrtPriceLimitX96,
    SwapCallbackData memory data
    ) internal returns (uint256 amountOut) {
    
    
    (address tokenIn, address tokenOut, uint24 tickSpacing) = data
    .path
    .decodeFirstPool();
  }
}

Here decodeFirstPool() is a function of Path.sol library, how data.path.decodeFirstPool() is working? I asked about the path in question 2, i am confused on how the connection was made between data and path??

1
  • Hi, please check the help center on how what's the expected question format. Please keep to one question per post and use informative titles.
    – kfx
    Commented Apr 14, 2023 at 16:11

1 Answer 1

0

Here are the answers:

  1. Yes, you're correct bool zeroForOne would be true if params.tokenIn is greater than params.tokenOut.
  2. as the path is of type bytes, when you call path.numPools() is actually calling the numPools() function from the Path library.
  3. as data.path is of type bytes which is using Path library you can call the decodeFirstPool() function of Path Liberary.

P.S. using Path for bytes; creates a linkage between the Path library and the bytes data type.

4
  • Where the path [ small letter p ] came from?? i did not initialize path anywhere, it is Path not path.
    – Hacek
    Commented Apr 14, 2023 at 17:28
  • can you share the code inside Path.sol or the full code where sqrtPriceX96AfterList = new uint160[](path.numPools()); is.? Commented Apr 14, 2023 at 18:31
  • It is project related, so i can't, but i described everything
    – Hacek
    Commented Apr 14, 2023 at 20:44
  • I suppose the path variable is being defined there, can you make sure? Commented Apr 15, 2023 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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