diff --git a/docs/contracts/v4/guides/09-swap-routing.mdx b/docs/contracts/v4/guides/09-swap-routing.mdx index 376bdb744..75fddc2bb 100644 --- a/docs/contracts/v4/guides/09-swap-routing.mdx +++ b/docs/contracts/v4/guides/09-swap-routing.mdx @@ -136,19 +136,32 @@ First, let’s define our function signature: ```solidity function swapExactInputSingle( - PoolKey calldata key, - uint128 amountIn, - uint128 minAmountOut + PoolKey calldata key, // PoolKey struct that identifies the v4 pool + uint128 amountIn, // Exact amount of tokens to swap + uint128 minAmountOut // Minimum amount of output tokens expected ) external returns (uint256 amountOut) { // Implementation will follow } ``` +**Important note:** -The function takes: +When swapping tokens involving native ETH, we use `Currency.wrap(address(0))` to represent ETH in the `PoolKey` struct. -- `key`: The PoolKey struct that identifies the v4 pool -- `amountIn`: The exact amount of tokens to swap -- `minAmountOut`: The minimum amount of output tokens expected +```solidity +struct PoolKey { + /// @notice The lower currency of the pool, sorted numerically. + /// For native ETH, Currency currency0 = Currency.wrap(address(0)); + Currency currency0; + /// @notice The higher currency of the pool, sorted numerically + Currency currency1; + /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000 + uint24 fee; + /// @notice Ticks that involve positions must be a multiple of tick spacing + int24 tickSpacing; + /// @notice The hooks of the pool + IHooks hooks; +} +``` ### 3.2: Encoding the Swap Command diff --git a/docs/contracts/v4/quickstart/02-manage-liquidity/00-setup-liquidity.mdx b/docs/contracts/v4/quickstart/02-manage-liquidity/00-setup-liquidity.mdx index 96b8de76b..6cbe7abca 100644 --- a/docs/contracts/v4/quickstart/02-manage-liquidity/00-setup-liquidity.mdx +++ b/docs/contracts/v4/quickstart/02-manage-liquidity/00-setup-liquidity.mdx @@ -46,6 +46,5 @@ After cloning the repository, and installing foundry, developers can manually se forge-std/=lib/v4-core/lib/forge-std/src/ permit2/=lib/v4-periphery/lib/permit2/ solmate/=lib/v4-core/lib/solmate/ - v4-core/=lib/v4-core/ v4-periphery/=lib/v4-periphery/ ``` diff --git a/docs/contracts/v4/quickstart/02-manage-liquidity/01-mint-position.mdx b/docs/contracts/v4/quickstart/02-manage-liquidity/01-mint-position.mdx index 9b771c628..7145e9880 100644 --- a/docs/contracts/v4/quickstart/02-manage-liquidity/01-mint-position.mdx +++ b/docs/contracts/v4/quickstart/02-manage-liquidity/01-mint-position.mdx @@ -60,6 +60,10 @@ The `MINT_POSITION` action requires the following parameters: | `hookData` | _bytes_ | arbitrary data that will be forwarded to hook functions | ```solidity +Currency currency0 = Currency.wrap(); // tokenAddress1 = 0 for native ETH +Currency currency1 = Currency.wrap(); +PoolKey poolKey = PoolKey(currency0, currency1, 3000, 60, IHooks(hook)); + params[0] = abi.encode(poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, recipient, hookData); ``` @@ -79,7 +83,9 @@ The entrypoint for all liquidity operations is `modifyLiquidities()` ```solidity uint256 deadline = block.timestamp + 60; -posm.modifyLiquidities( +uint256 valueToPass = currency0.isAddressZero() ? amount0Max : 0; + +posm.modifyLiquidities{value: valueToPass}( abi.encode(actions, params), deadline ); diff --git a/docs/contracts/v4/quickstart/02-manage-liquidity/02-increase-liquidity.mdx b/docs/contracts/v4/quickstart/02-manage-liquidity/02-increase-liquidity.mdx index f3023a0d8..f0daf3567 100644 --- a/docs/contracts/v4/quickstart/02-manage-liquidity/02-increase-liquidity.mdx +++ b/docs/contracts/v4/quickstart/02-manage-liquidity/02-increase-liquidity.mdx @@ -102,6 +102,8 @@ The `SETTLE_PAIR` action requires the following parameters: In the above case, the parameter encoding is: ```solidity +Currency currency0 = Currency.wrap(); // tokenAddress1 = 0 for native ETH +Currency currency1 = Currency.wrap(); params[1] = abi.encode(currency0, currency1); ``` @@ -131,7 +133,10 @@ The entrypoint for all liquidity operations is `modifyLiquidities()`. ```solidity uint256 deadline = block.timestamp + 60; -posm.modifyLiquidities( + +uint256 valueToPass = currency0.isAddressZero() ? amount0Max : 0; + +posm.modifyLiquidities{value: valueToPass}( abi.encode(actions, params), deadline ); diff --git a/docs/contracts/v4/quickstart/02-manage-liquidity/03-decrease-liquidity.mdx b/docs/contracts/v4/quickstart/02-manage-liquidity/03-decrease-liquidity.mdx index 2821266d4..aa9de3c52 100644 --- a/docs/contracts/v4/quickstart/02-manage-liquidity/03-decrease-liquidity.mdx +++ b/docs/contracts/v4/quickstart/02-manage-liquidity/03-decrease-liquidity.mdx @@ -95,6 +95,8 @@ The `TAKE_PAIR` action requires the following parameters: In the above case, the parameter encoding is: ```solidity +Currency currency0 = Currency.wrap(); // tokenAddress1 = 0 for native ETH +Currency currency1 = Currency.wrap(); params[1] = abi.encode(currency0, currency1, recipient); ``` @@ -116,7 +118,10 @@ The entrypoint for all liquidity operations is `modifyLiquidities()`. ```solidity uint256 deadline = block.timestamp + 60; -posm.modifyLiquidities( + +uint256 valueToPass = currency0.isAddressZero() ? amount0Max : 0; + +posm.modifyLiquidities{value: valueToPass}( abi.encode(actions, params), deadline ); diff --git a/docs/contracts/v4/quickstart/02-manage-liquidity/04-collect.mdx b/docs/contracts/v4/quickstart/02-manage-liquidity/04-collect.mdx index 02a38b7d7..5b4cc8114 100644 --- a/docs/contracts/v4/quickstart/02-manage-liquidity/04-collect.mdx +++ b/docs/contracts/v4/quickstart/02-manage-liquidity/04-collect.mdx @@ -64,6 +64,8 @@ The `TAKE_PAIR` action requires the following parameters: * `recipient` - _address_, destination of the fee revenue for both tokens ```solidity +Currency currency0 = Currency.wrap(); // tokenAddress1 = 0 for native ETH +Currency currency1 = Currency.wrap(); params[1] = abi.encode(currency0, currency1, recipient); ``` @@ -73,7 +75,10 @@ The entrypoint for all liquidity operations is `modifyLiquidities()`. ```solidity uint256 deadline = block.timestamp + 60; -posm.modifyLiquidities( + +uint256 valueToPass = currency0.isAddressZero() ? amount0Max : 0; + +posm.modifyLiquidities{value: valueToPass}( abi.encode(actions, params), deadline ); diff --git a/docs/contracts/v4/quickstart/03-swap.mdx b/docs/contracts/v4/quickstart/03-swap.mdx index 71082d629..8dbbd3551 100644 --- a/docs/contracts/v4/quickstart/03-swap.mdx +++ b/docs/contracts/v4/quickstart/03-swap.mdx @@ -68,16 +68,6 @@ In this step, we’re importing the necessary contracts and interfaces: - `IPermit2`: This interface allows us to interact with the Permit2 contract, which provides enhanced token approval functionality. - `StateLibrary`: This provides optimized functions for interacting with the PoolManager’s state. By using `StateLibrary`, we can more efficiently read and manipulate pool states, which is crucial for many operations in Uniswap v4. -**Important note:** - -To use the Universal Router imports, you'll need to set up remappings in your project. This can be done using a `remappings.txt` file: - -``` -@uniswap/universal-router/=lib/universal-router/ - -[...] -``` - ## Step 2: Implement Token Approval with Permit2 `UniversalRouter` integrates with [Permit2](https://github.com/Uniswap/permit2), to enable users to have more safety, flexibility, and control over their ERC20 token approvals. @@ -107,19 +97,32 @@ First, let’s define our function signature: ```solidity function swapExactInputSingle( - PoolKey calldata key, - uint128 amountIn, - uint128 minAmountOut + PoolKey calldata key, // PoolKey struct that identifies the v4 pool + uint128 amountIn, // Exact amount of tokens to swap + uint128 minAmountOut // Minimum amount of output tokens expected ) external returns (uint256 amountOut) { // Implementation will follow } ``` +**Important note:** -The function takes: +When swapping tokens involving native ETH, we use `Currency.wrap(address(0))` to represent ETH in the `PoolKey` struct. -- `key`: The [PoolKey](https://github.com/Uniswap/v4-core/blob/main/src/types/PoolKey.sol) struct that identifies the v4 pool -- `amountIn`: The exact amount of tokens to swap -- `minAmountOut`: The minimum amount of output tokens expected +```solidity +struct PoolKey { + /// @notice The lower currency of the pool, sorted numerically. + /// For native ETH, Currency currency0 = Currency.wrap(address(0)); + Currency currency0; + /// @notice The higher currency of the pool, sorted numerically + Currency currency1; + /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000 + uint24 fee; + /// @notice Ticks that involve positions must be a multiple of tick spacing + int24 tickSpacing; + /// @notice The hooks of the pool + IHooks hooks; +} +``` ### 3.2: Encoding the Swap Command