From ee95d5e574712ceae2489749ed5bd053b736a4a0 Mon Sep 17 00:00:00 2001 From: Jake Kidd Date: Thu, 11 Jul 2024 12:29:38 -0400 Subject: [PATCH] fix: integration --- src/contracts/QWManager.sol | 5 +- src/contracts/components/QWAaveV2.sol | 5 +- .../components/QWUniswapV3Stable.sol | 2 +- src/interfaces/IQWManager.sol | 62 +++++++++---------- test/integration/components/QWAaveV3.t.sol | 1 + .../components/QWUniswapV3Stable.t.sol | 7 +++ 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/contracts/QWManager.sol b/src/contracts/QWManager.sol index 886b5c6..f8e6c6f 100644 --- a/src/contracts/QWManager.sol +++ b/src/contracts/QWManager.sol @@ -86,7 +86,7 @@ contract QWManager is IQWManager, Ownable { nft.transferFrom(address(this), batch.protocol, protocol.nftId); } - // Call the create function on the target contract with the provided calldata. + // Call the open function on the target contract with the provided calldata. (bool success, uint256 assetAmountReceived) = IQWComponent(batch.protocol).open(batch.amount); if (!success) { // TODO: Event for batches that fail. @@ -124,6 +124,7 @@ contract QWManager is IQWManager, Ownable { // Calculate the amount to withdraw based on the ratio provided. uint256 amountToWithdraw = (totalHoldings * batch.ratio) / 1e8; + // TODO // Update the protocol asset details. protocol.assetAmount -= amountToWithdraw; @@ -139,7 +140,7 @@ contract QWManager is IQWManager, Ownable { } // Call the close function on the child contract. - (bool success, uint256 tokenAmountReceived) = IQWComponent(batch.protocol).close(batch.ratio); + (bool success, uint256 tokenAmountReceived) = IQWComponent(batch.protocol).close(amountToWithdraw); if (!success) { revert CallFailed(); } diff --git a/src/contracts/components/QWAaveV2.sol b/src/contracts/components/QWAaveV2.sol index 011fa6d..425330e 100644 --- a/src/contracts/components/QWAaveV2.sol +++ b/src/contracts/components/QWAaveV2.sol @@ -39,9 +39,6 @@ contract QWAaveV2 is IQWComponent, QWComponentBase { * @return assetAmountReceived Amount of asset tokens received. */ function open(uint256 _amount) external override onlyQwManager returns (bool success, uint256 assetAmountReceived) { - // Transfer tokens from QWManager to this contract. - // IERC20 token = IERC20(INVESTMENT_TOKEN); - // token.transferFrom(QW_MANAGER, address(this), _amount); // Check whether we have been transferred the tokens to spend. _checkInvestment(_amount); @@ -72,7 +69,7 @@ contract QWAaveV2 is IQWComponent, QWComponentBase { _checkAssets(_amount); // Withdraw the tokens from Aave. - ILendingPool(LENDING_POOL).withdraw(INVESTMENT_TOKEN, _amount, address(this)); + ILendingPool(LENDING_POOL).withdraw(ASSET_TOKEN, _amount, address(this)); // Check the balance of the investment token received. tokenAmountReceived = _checkInvestmentAny(); diff --git a/src/contracts/components/QWUniswapV3Stable.sol b/src/contracts/components/QWUniswapV3Stable.sol index c22c6d7..3e2dbb0 100644 --- a/src/contracts/components/QWUniswapV3Stable.sol +++ b/src/contracts/components/QWUniswapV3Stable.sol @@ -80,7 +80,7 @@ contract QWUniswapV3Stable is IQWComponent, QWComponentBase, Ownable, IERC721Rec (uint256 liquidity, uint256 amount0, uint256 amount1) = increaseLiquidityCurrentRange(_amount); - assetAmountReceived = uint256(liquidity); + assetAmountReceived = uint256(liquidity); // TODO: Is liquidity the total amount or the amount received? // TODO: Send NFT to QWManager diff --git a/src/interfaces/IQWManager.sol b/src/interfaces/IQWManager.sol index 2a07bbd..d31b899 100644 --- a/src/interfaces/IQWManager.sol +++ b/src/interfaces/IQWManager.sol @@ -29,38 +29,38 @@ interface IQWManager { */ function withdraw(address _user, address _tokenAddress, uint256 _amount) external; - /** - * @notice Receive funds from a specified user. - * Transfers a specified amount of funds from the user to this contract. - * @param _user The address of the user sending the funds. - * @param _tokenAddress The address of the token to transfer. - * @param _amount The amount of funds to transfer to this contract. - */ - function receiveFunds(address _user, address _tokenAddress, uint256 _amount) external; + /** + * @notice Receive funds from a specified user. + * Transfers a specified amount of funds from the user to this contract. + * @param _user The address of the user sending the funds. + * @param _tokenAddress The address of the token to transfer. + * @param _amount The amount of funds to transfer to this contract. + */ + function receiveFunds(address _user, address _tokenAddress, uint256 _amount) external; - /** - * @notice Get the address of the Quant Wealth Registry. - * @return The address of the registry contract. - */ - function REGISTRY() external view returns (address); + /** + * @notice Get the address of the Quant Wealth Registry. + * @return The address of the registry contract. + */ + function REGISTRY() external view returns (address); - /** - * @notice OpenBatch struct to hold batch data for executing investments. - * @param protocol The protocol into which we are investing funds. - * @param amount The total amount being invested in the given token by all users into this protocol. - */ - struct OpenBatch { - address protocol; - uint256 amount; - } + /** + * @notice OpenBatch struct to hold batch data for executing investments. + * @param protocol The protocol into which we are investing funds. + * @param amount The total amount being invested in the given token by all users into this protocol. + */ + struct OpenBatch { + address protocol; + uint256 amount; + } - /** - * @notice CloseBatch struct to hold batch data for closing investments. - * @param protocol The protocol from which we are withdrawing funds. - * @param ratio The percentage amount of holdings to withdraw from the given protocol. - */ - struct CloseBatch { - address protocol; - uint256 ratio; - } + /** + * @notice CloseBatch struct to hold batch data for closing investments. + * @param protocol The protocol from which we are withdrawing funds. + * @param ratio The percentage amount of holdings to withdraw from the given protocol. + */ + struct CloseBatch { + address protocol; + uint256 ratio; + } } diff --git a/test/integration/components/QWAaveV3.t.sol b/test/integration/components/QWAaveV3.t.sol index 13eba9d..3e80e6a 100644 --- a/test/integration/components/QWAaveV3.t.sol +++ b/test/integration/components/QWAaveV3.t.sol @@ -5,6 +5,7 @@ import {IntegrationBase} from '../IntegrationBase.t.sol'; import {IRewardsController} from '@aave/periphery-v3/contracts/rewards/interfaces/IRewardsController.sol'; import {IERC20, IPool, QWAaveV3} from 'contracts/components/QWAaveV3.sol'; +import {IQWManager} from 'interfaces/IQWManager.sol'; import {IQWComponent} from 'interfaces/IQWComponent.sol'; contract AaveIntegrationV3 is IntegrationBase { diff --git a/test/integration/components/QWUniswapV3Stable.t.sol b/test/integration/components/QWUniswapV3Stable.t.sol index 7820acd..a6d71f0 100644 --- a/test/integration/components/QWUniswapV3Stable.t.sol +++ b/test/integration/components/QWUniswapV3Stable.t.sol @@ -11,6 +11,7 @@ import { IUniswapV3Pool, QWUniswapV3Stable } from 'contracts/components/QWUniswapV3Stable.sol'; +import {IQWManager} from 'interfaces/IQWManager.sol'; contract UniswapV3stableIntegration is IntegrationBase { IUniswapV3Pool internal _uniswapUSDCUSDTPool = IUniswapV3Pool(0x7858E59e0C01EA06Df3aF3D20aC7B0003275D4Bf); @@ -58,6 +59,12 @@ contract UniswapV3stableIntegration is IntegrationBase { // Create dynamic arrays with one element each address[] memory targetQWChild = new address[](1); targetQWChild[0] = address(_QWUniswapV3Stable); + // Create an array with one element + IQWManager.OpenBatch[] memory openBatchArr = new IQWManager.OpenBatch[](1); + openBatchArr[0] = IQWManager.OpenBatch({ + protocol: address(_qwCompound), + amount: amount + }); // execute the investment vm.prank(_owner);