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

[Bug]: IV4Router Struct Mismatch Causes Type Conversion Error in ExactOutputSingleParams #449

Closed
cqlyj opened this issue Feb 18, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@cqlyj
Copy link

cqlyj commented Feb 18, 2025

Describe the bug

Description

In the file IV4Router, imported via:

import {IV4Router} from "v4-periphery/src/interfaces/IV4Router.sol";

I noticed that the parameter structure differs from what is documented. I previously raised an issue regarding this discrepancy here.

After attempting to remove the following code snippet:

IV4Router.ExactOutputSingleParams({
    poolKey: poolKey,
    zeroForOne: true, // true if swapping token0 for token1: USDC => NFT
    amountOut: amountOut,
    amountInMaximum: maxAmountIn,
    // sqrtPriceLimitX96: 0, // No price limit
    hookData: hookData
});

I encountered a new error:

Invalid type for argument in function call.  
Invalid implicit conversion from struct PoolKey memory to struct PoolKey memory requested.  
solidity(9553)

Image

What I’ve Tried

  • Verified that my installed v4-core commit hash is b619b67, and the v4-periphery commit hash matches.
  • However, if I do not import IV4Router and instead define my own minimal interface:
interface IV4Router {
    struct ExactOutputSingleParams {
        PoolKey poolKey;
        bool zeroForOne;
        uint128 amountOut;
        uint128 amountInMaximum;
        uint160 sqrtPriceLimitX96;
        bytes hookData;
    }
}

then everything compiles and works as expected.

Question

Why does using the imported IV4Router cause a type conversion error, but defining a local version of the interface resolves it? Could this be due to different struct definitions in v4-core vs. v4-periphery despite the same commit hash?

Would appreciate any insights—thanks!

Expected Behavior

When importing IV4Router from v4-periphery, the ExactOutputSingleParams struct should match the documented definition and work without type conversion errors.

  • The struct should accept PoolKey without requiring any implicit conversions.
  • Removing sqrtPriceLimitX96 should not cause an error.
  • Using the official IV4Router interface should behave the same as a manually defined minimal version.

To Reproduce

  1. Import IV4Router from v4-periphery and PoolKey from v4-core:

    import {IV4Router} from "v4-periphery/src/interfaces/IV4Router.sol";
    import {PoolKey} from "v4-core/src/types/PoolKey.sol";
  2. Use the ExactOutputSingleParams struct in a function:

    IV4Router.ExactOutputSingleParams({
        poolKey: poolKey,
        zeroForOne: true, // true if swapping token0 for token1: USDC => NFT
        amountOut: amountOut,
        amountInMaximum: maxAmountIn,
        // sqrtPriceLimitX96: 0, // No price limit
        hookData: hookData
    });
  3. Compile the contract and observe the error:

    Invalid type for argument in function call.
    Invalid implicit conversion from struct PoolKey memory to struct PoolKey memory requested.
    solidity(9553)
    
  4. Instead, define a minimal interface manually:

    interface IV4Router {
        struct ExactOutputSingleParams {
            PoolKey poolKey;
            bool zeroForOne;
            uint128 amountOut;
            uint128 amountInMaximum;
            uint160 sqrtPriceLimitX96;
            bytes hookData;
        }
    }
  5. Replace the imported IV4Router with the manually defined one, and compile again—this time, it works without errors.

Additional context

No response

@cqlyj cqlyj added the bug Something isn't working label Feb 18, 2025
@saucepoint
Copy link
Collaborator

saucepoint commented Feb 21, 2025

@cqlyj this is a repo configuration problem. If you want to use v4-periphery with a top-level v4-core install, you will need to remap v4-periphery's core dependency:

inside remappings.txt

lib/v4-periphery:@uniswap/v4-core/=lib/v4-core/

v4-periphery installs with its own copy of v4-core, so youre attempting to use PoolKey definitions from different files (lib/v4-core and lib/v4-periphery/lib/v4-core)

@cqlyj
Copy link
Author

cqlyj commented Feb 21, 2025

@cqlyj this is a repo configuration problem. If you want to use v4-periphery with a top-level v4-core install, you will need to remap v4-periphery's core dependency:

inside remappings.txt

lib/v4-periphery:@uniswap/v4-core/=lib/v4-core/

v4-periphery installs with its own copy of v4-core, so youre attempting to use PoolKey definitions from different files (lib/v4-core and lib/v4-periphery/lib/v4-core)

That fix this, Thanks! But that IRouterV4 issue is still there: Uniswap/docs#901

@cqlyj cqlyj closed this as completed Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants