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

Using wrappedToken in CompositeLiquidityRouter in ERC4626Pool operations #1201

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1ca2458
fist iteration
elshan-eth Dec 24, 2024
757545a
fix code and tests
elshan-eth Jan 7, 2025
9dbf7fc
change var name
elshan-eth Jan 8, 2025
4b39b72
refactoring prepareTokens
elshan-eth Jan 9, 2025
f6bcd4e
fixes
elshan-eth Jan 10, 2025
413315d
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
c441933
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
164cdae
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
6d7f538
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
c4a2662
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
6b1c8db
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
b0eeb6e
Update pkg/vault/contracts/CompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
6008eca
Update pkg/vault/contracts/CompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
06ab630
Update pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
9fe3242
Update pkg/vault/contracts/CompositeLiquidityRouter.sol
elshan-eth Jan 13, 2025
acac9ec
small fixes
elshan-eth Jan 13, 2025
8a876c8
Merge branch 'using-wrapped-amount-in-erc4626-operations-in-clr' of h…
elshan-eth Jan 13, 2025
cf43702
fixes
elshan-eth Jan 13, 2025
af63d70
update snapshots
elshan-eth Jan 13, 2025
8ca5aa6
small fixes
elshan-eth Jan 14, 2025
537f45f
small fixes
elshan-eth Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions pkg/interfaces/contracts/vault/ICompositeLiquidityRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ interface ICompositeLiquidityRouter {
* the "parent" pool, and also make sure limits are set properly.
*
* @param pool Address of the liquidity pool
* @param exactUnderlyingAmountsIn Exact amounts of underlying tokens in, sorted in token registration order of
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
Comment on lines +33 to 36
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (transfer the underlying asset and wrap) or as a standard ERC20 (transfer the wrapped token directly)
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order

I think this spells it out. The tokens are specified in registration order, the only question is whether they'll be used directly or interpreted as underlying instead.

You could also have non-ERC4626 tokens (where the flag would be true), which is why I don't think "order of wrapped tokens" is appropriate. It's just the order of tokens as they were registered.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not in the diff, but we also need to fix other references to underlying tokens, such as the notice of this function:
"Add arbitrary amounts of underlying tokens to an ERC4626 pool through the buffer."

Generally "underlying tokens" should just be "tokens" where it appears (e.g., notice NatSpec for add/remove functions)

* @param minBptAmountOut Minimum amount of pool tokens to be received
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
Expand All @@ -39,7 +41,8 @@ interface ICompositeLiquidityRouter {
*/
function addLiquidityUnbalancedToERC4626Pool(
address pool,
uint256[] memory exactUnderlyingAmountsIn,
bool[] memory useAsStandardToken,
uint256[] memory exactAmountsIn,
uint256 minBptAmountOut,
bool wethIsEth,
bytes memory userData
Expand All @@ -52,55 +55,64 @@ interface ICompositeLiquidityRouter {
* the "parent" pool, and also make sure limits are set properly.
*
* @param pool Address of the liquidity pool
* @param maxUnderlyingAmountsIn Maximum amounts of underlying tokens in, sorted in token registration order of
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param maxAmountsIn Maximum amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
Comment on lines +58 to 61
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param maxAmountsIn Maximum amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (transfer the underlying asset and wrap) or as a standard ERC20 (transfer the wrapped token directly)
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order

Same as above

* @param exactBptAmountOut Exact amount of pool tokens to be received
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data required for adding liquidity
* @return underlyingAmountsIn Actual amounts of tokens added, sorted in token registration order of wrapped tokens
* in the pool
* @return tokensIn Actual tokens added in the pool
* @return amountsIn Actual amounts of tokens added in the pool
Comment on lines +65 to +66
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return tokensIn Actual tokens added in the pool
* @return amountsIn Actual amounts of tokens added in the pool
* @return tokensIn Actual tokens added to the pool
* @return amountsIn Actual amounts of tokens added to the pool

*/
function addLiquidityProportionalToERC4626Pool(
address pool,
uint256[] memory maxUnderlyingAmountsIn,
bool[] memory useAsStandardToken,
uint256[] memory maxAmountsIn,
uint256 exactBptAmountOut,
bool wethIsEth,
bytes memory userData
) external payable returns (uint256[] memory underlyingAmountsIn);
) external payable returns (address[] memory tokensIn, uint256[] memory amountsIn);

/**
* @notice Remove proportional amounts of underlying from an ERC4626 pool, burning an exact pool token amount.
* @dev An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).
* @param pool Address of the liquidity pool
* @param useAsStandardToken An array indicating whether to use the token as standard or unwrap it,
* sorted in token registration order of wrapped tokens in the pool
Comment on lines +81 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or unwrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (unwrap and transfer the underlying asset) or as a standard ERC20 (transfer the wrapped token directly)

* @param exactBptAmountIn Exact amount of pool tokens provided
* @param minUnderlyingAmountsOut Minimum amounts of underlying tokens out, sorted in token registration order of
* @param minAmountsOut Minimum amounts of each token, sorted according to tokensIn array
* wrapped tokens in the pool
Comment on lines +84 to 85
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param minAmountsOut Minimum amounts of each token, sorted according to tokensIn array
* wrapped tokens in the pool
* @param minAmountsOut Minimum amounts of each token, corresponding to `tokensOut`

* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data required for removing liquidity
* @return underlyingAmountsOut Actual amounts of tokens received, sorted in token registration order of wrapped
* tokens in the pool
* @return tokensOut Actual tokens received
* @return amountsOut Actual amounts of tokens received
*/
function removeLiquidityProportionalFromERC4626Pool(
address pool,
bool[] memory useAsStandardToken,
uint256 exactBptAmountIn,
uint256[] memory minUnderlyingAmountsOut,
uint256[] memory minAmountsOut,
bool wethIsEth,
bytes memory userData
) external payable returns (uint256[] memory underlyingAmountsOut);
) external payable returns (address[] memory tokensOut, uint256[] memory amountsOut);

/**
* @notice Queries an `addLiquidityUnbalancedToERC4626Pool` operation without actually executing it.
* @dev An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).
* @param pool Address of the liquidity pool
* @param exactUnderlyingAmountsIn Exact amounts of underlying tokens in, sorted in token registration order of
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
Comment on lines +104 to +105
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (transfer the underlying asset and wrap) or as a standard ERC20 (transfer the wrapped token directly)

* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
Comment on lines +106 to 107
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order
* wrapped tokens in the pool
* @param exactAmountsIn Exact amounts of underlying/wrapped tokens in, sorted in token registration order

* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data required for the query
* @return bptAmountOut Expected amount of pool tokens to receive
*/
function queryAddLiquidityUnbalancedToERC4626Pool(
address pool,
uint256[] memory exactUnderlyingAmountsIn,
bool[] memory useAsStandardToken,
uint256[] memory exactAmountsIn,
address sender,
bytes memory userData
) external returns (uint256 bptAmountOut);
Expand All @@ -109,35 +121,41 @@ interface ICompositeLiquidityRouter {
* @notice Queries an `addLiquidityProportionalToERC4626Pool` operation without actually executing it.
* @dev An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).
* @param pool Address of the liquidity pool
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap/unwrap it,
* sorted in token registration order of wrapped tokens in the pool
Comment on lines +124 to +125
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or wrap/unwrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (transfer the underlying asset and wrap) or as a standard ERC20 (transfer the wrapped token directly)

* @param exactBptAmountOut Exact amount of pool tokens to be received
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data required for the query
* @return underlyingAmountsIn Expected amounts of tokens to add, sorted in token registration order of wrapped
* tokens in the pool
* @return tokensIn Expected tokens added in the pool
* @return amountsIn Expected amounts of tokens added in the pool
Comment on lines +129 to +130
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return tokensIn Expected tokens added in the pool
* @return amountsIn Expected amounts of tokens added in the pool
* @return tokensIn Expected tokens added to the pool
* @return amountsIn Expected amounts of tokens added to the pool

*/
function queryAddLiquidityProportionalToERC4626Pool(
address pool,
bool[] memory useAsStandardToken,
uint256 exactBptAmountOut,
address sender,
bytes memory userData
) external returns (uint256[] memory underlyingAmountsIn);
) external returns (address[] memory tokensIn, uint256[] memory amountsIn);

/**
* @notice Queries a `removeLiquidityProportionalFromERC4626Pool` operation without actually executing it.
* @dev An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).
* @param pool Address of the liquidity pool
* @param useAsStandardToken An array indicating whether to use the token as standard or unwrap it,
* sorted in token registration order of wrapped tokens in the pool
Comment on lines +144 to +145
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param useAsStandardToken An array indicating whether to use the token as standard or unwrap it,
* sorted in token registration order of wrapped tokens in the pool
* @param useAsStandardToken Flags indicating whether the corresponding token should be treated as an ERC4626
* (unwrap and transfer the underlying asset) or as a standard ERC20 (transfer the wrapped token directly)

* @param exactBptAmountIn Exact amount of pool tokens provided for the query
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data required for the query
* @return underlyingAmountsOut Expected amounts of tokens to receive, sorted in token registration order of
* wrapped tokens in the pool
* @return tokensOut Expected tokens to receive
* @return amountsOut Expected amounts of tokens to receive
*/
function queryRemoveLiquidityProportionalFromERC4626Pool(
address pool,
bool[] memory useAsStandardToken,
uint256 exactBptAmountIn,
address sender,
bytes memory userData
) external returns (uint256[] memory underlyingAmountsOut);
) external returns (address[] memory tokensOut, uint256[] memory amountsOut);

/***************************************************************************
Nested pools
Expand All @@ -152,7 +170,7 @@ interface ICompositeLiquidityRouter {
* @param parentPool Address of the highest level pool (which contains BPTs of other pools)
* @param tokensIn Input token addresses, sorted by user preference. `tokensIn` array must have all tokens from
* child pools and all tokens that are not BPTs from the nested pool (parent pool).
* @param exactAmountsIn Amount of each underlying token in, sorted according to tokensIn array
* @param exactAmountsIn Amount of each token in, sorted according to tokensIn array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param exactAmountsIn Amount of each token in, sorted according to tokensIn array
* @param exactAmountsIn Amount of each token in, corresponding to `tokensIn`

This seems more generic, as we might be interpreting tokens differently, such that they're not necessarily sorted

* @param minBptAmountOut Expected minimum amount of parent pool tokens to receive
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data required for the operation
Expand All @@ -172,7 +190,7 @@ interface ICompositeLiquidityRouter {
* @param parentPool Address of the highest level pool (which contains BPTs of other pools)
* @param tokensIn Input token addresses, sorted by user preference. `tokensIn` array must have all tokens from
* child pools and all tokens that are not BPTs from the nested pool (parent pool).
* @param exactAmountsIn Amount of each underlying token in, sorted according to tokensIn array
* @param exactAmountsIn Amount of each token in, sorted according to tokensIn array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param exactAmountsIn Amount of each token in, sorted according to tokensIn array
* @param exactAmountsIn Amount of each token in, corresponding to `tokensIn`

* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data required for the operation
* @return bptAmountOut Expected amount of parent pool tokens to receive
Expand All @@ -196,7 +214,7 @@ interface ICompositeLiquidityRouter {
* @param tokensOut Output token addresses, sorted by user preference. `tokensOut` array must have all tokens from
* child pools and all tokens that are not BPTs from the nested pool (parent pool). If not all tokens are informed,
* balances are not settled and the operation reverts. Tokens that repeat must be informed only once.
* @param minAmountsOut Minimum amounts of each outgoing underlying token, sorted according to tokensIn array
* @param minAmountsOut Minimum amounts of each token, sorted according to tokensIn array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param minAmountsOut Minimum amounts of each token, sorted according to tokensIn array
* @param minAmountsOut Minimum amounts of each outgoing token, corresponding to `tokensOut`

* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data required for the operation
* @return amountsOut Actual amounts of tokens received, parallel to `tokensOut`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return amountsOut Actual amounts of tokens received, parallel to `tokensOut`
* @return amountsOut Actual amounts of tokens received, corresponding to `tokensOut`

Parallel would work too, but trying to be consistent.

Expand Down
Loading
Loading