Skip to content

Commit

Permalink
fix: integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jakekidd committed Jul 11, 2024
1 parent 580c207 commit ee95d5e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
5 changes: 3 additions & 2 deletions src/contracts/QWManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
5 changes: 1 addition & 4 deletions src/contracts/components/QWAaveV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/components/QWUniswapV3Stable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 31 additions & 31 deletions src/interfaces/IQWManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions test/integration/components/QWAaveV3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check warning on line 8 in test/integration/components/QWAaveV3.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IQWManager" is unused
import {IQWComponent} from 'interfaces/IQWComponent.sol';

contract AaveIntegrationV3 is IntegrationBase {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/components/QWUniswapV3Stable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ee95d5e

Please sign in to comment.