Skip to content

Commit

Permalink
fix: rename child -> component
Browse files Browse the repository at this point in the history
  • Loading branch information
jakekidd committed Jul 8, 2024
1 parent 11b759b commit edfae0d
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 364 deletions.
6 changes: 3 additions & 3 deletions src/contracts/QWManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.23;
import {QWRegistry} from './QWRegistry.sol';
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';
import {IQWManager} from 'interfaces/IQWManager.sol';
import {IQWRegistry} from 'interfaces/IQWRegistry.sol';

Expand Down Expand Up @@ -76,7 +76,7 @@ contract QWManager is IQWManager, Ownable {
token.approve(address(batch.protocol), batch.amount);

// Call the create function on the target contract with the provided calldata.
(bool success, uint256 assetAmountReceived) = IQWChild(batch.protocol).open(batch.amount);
(bool success, uint256 assetAmountReceived) = IQWComponent(batch.protocol).open(batch.amount);
if (!success) {
// TODO: Event for batches that fail.
revert CallFailed();
Expand Down Expand Up @@ -122,7 +122,7 @@ contract QWManager is IQWManager, Ownable {
IERC20(protocol.assetAddress).transfer(batch.protocol, amountToWithdraw);

// Call the close function on the child contract.
(bool success, uint256 tokenAmountReceived) = IQWChild(batch.protocol).close(batch.ratio);
(bool success, uint256 tokenAmountReceived) = IQWComponent(batch.protocol).close(batch.ratio);
if (!success) {
revert CallFailed();
}
Expand Down
20 changes: 10 additions & 10 deletions src/contracts/QWRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.23;

import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';
import {IQWRegistry} from 'interfaces/IQWRegistry.sol';

/**
Expand All @@ -16,7 +16,7 @@ contract QWRegistry is IQWRegistry, Ownable {
mapping(address => bool) public whitelist;

// Events
event ChildRegistered(address indexed child);
event ComponentRegistered(address indexed component);

// Custom errors
error ParentMismatch(); // Error for mismatched parent contract
Expand All @@ -35,18 +35,18 @@ contract QWRegistry is IQWRegistry, Ownable {

/**
* @notice Registers a child contract in the whitelist.
* @dev This function ensures that the child contract's parent matches the QWManager.
* @param _child The address of the child contract to register.
* @dev This function ensures that the component contract's parent matches the QWManager.
* @param _component The address of the component contract to register.
*/
function registerChild(address _child) external onlyOwner {
if (_child == address(0)) {
function registerComponent(address _component) external onlyOwner {
if (_component == address(0)) {
revert InvalidAddress();
}
IQWChild childContract = IQWChild(_child);
if (childContract.QW_MANAGER() != QW_MANAGER) {
IQWComponent componentContract = IQWComponent(_component);
if (componentContract.getQWManager() != QW_MANAGER) {
revert ParentMismatch();
}
whitelist[_child] = true;
emit ChildRegistered(_child); // Emit an event when a child contract is registered
whitelist[_component] = true;
emit ComponentRegistered(_component); // Emit an event when a child contract is registered
}
}
32 changes: 7 additions & 25 deletions src/contracts/child/QWAaveV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,32 @@
pragma solidity 0.8.23;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';
import {QWComponentBase} from './QWComponentBase.sol';
import {ILendingPool} from 'interfaces/aave-v2/ILendingPool.sol';

/**
* @title AaveV2 Integration for Quant Wealth
* @notice This contract integrates with AaveV2 protocol for Quant Wealth management.
*/
contract QWAaveV2 is IQWChild {
contract QWAaveV2 is IQWComponent, QWComponentBase {
// Variables
address public immutable QW_MANAGER;
address public immutable INVESTMENT_TOKEN;
address public immutable ASSET_TOKEN;
address public immutable LENDING_POOL;

// Custom errors
error InvalidCallData(); // Error for invalid call data
error UnauthorizedAccess(); // Error for unauthorized caller
error NoInvestmentTokensReceived();
error NoAssetTokensReceived();

modifier onlyQwManager() {
if (msg.sender != QW_MANAGER) {
revert UnauthorizedAccess();
}
_;
}

/**
* @dev Constructor to initialize the contract with required addresses.
* @param _qwManager The address of the Quant Wealth Manager contract.
* @param _lendingPool The address of the AaveV2 pool contract.
* @param _investmentToken The address of the investment token (e.g., USDT).
* @param _assetToken The address of the corresponding aToken (e.g., aUSDT).
* @param _lendingPool The address of the AaveV2 pool contract.
*/
constructor(
address _qwManager,
address _lendingPool,
address _investmentToken,
address _assetToken
) {
QW_MANAGER = _qwManager;
address _assetToken,
address _lendingPool
) QWComponentBase(_qwManager, _investmentToken, _assetToken) {
LENDING_POOL = _lendingPool;
INVESTMENT_TOKEN = _investmentToken;
ASSET_TOKEN = _assetToken;
}

// Functions
Expand Down
31 changes: 10 additions & 21 deletions src/contracts/child/QWAaveV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,31 @@ pragma solidity 0.8.23;

import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';
import {QWComponentBase} from './QWComponentBase.sol';

/**
* @title AaveV3 Integration for Quant Wealth
* @notice This contract integrates with AaveV3 protocol for Quant Wealth management.
*/
contract QWAaveV3 is IQWChild {
contract QWAaveV3 is IQWComponent, QWComponentBase {
// Variables
address public immutable QW_MANAGER;
address public immutable POOL;
address public immutable INVESTMENT_TOKEN;
address public immutable ASSET_TOKEN;

// Custom errors
error InvalidCallData(); // Error for invalid call data
error UnauthorizedAccess(); // Error for unauthorized caller

modifier onlyQwManager() {
if (msg.sender != QW_MANAGER) {
revert UnauthorizedAccess();
}
_;
}

/**
* @dev Constructor to initialize the contract with required addresses.
* @param _qwManager The address of the Quant Wealth Manager contract.
* @param _pool The address of the AaveV3 pool contract.
* @param _investmentToken The address of the token to be invested.
* @param _assetToken The address of the asset token received after investment.
* @param _pool The address of the AaveV3 pool contract.
*/
constructor(address _qwManager, address _pool, address _investmentToken, address _assetToken) {
QW_MANAGER = _qwManager;
constructor(
address _qwManager,
address _investmentToken,
address _assetToken,
address _pool
) QWComponentBase(_qwManager, _investmentToken, _assetToken) {
POOL = _pool;
INVESTMENT_TOKEN = _investmentToken;
ASSET_TOKEN = _assetToken;
}

// Functions
Expand Down
17 changes: 15 additions & 2 deletions src/contracts/child/QWComponentBase.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
// SPDX-License-Identifier: APACHE
pragma solidity 0.8.23;

import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';

// TODO: Inherit and call in constructor of components.

abstract contract QWComponentBase is IQWChild {
abstract contract QWComponentBase is IQWComponent {
address public immutable QW_MANAGER;
address public immutable INVESTMENT_TOKEN;
address public immutable ASSET_TOKEN;

// Custom errors
error InvalidCallData(); // Error for invalid call data
error UnauthorizedAccess(); // Error for unauthorized caller
error NoInvestmentTokensReceived();
error NoAssetTokensReceived();

modifier onlyQwManager() {
if (msg.sender != QW_MANAGER) {
revert UnauthorizedAccess();
}
_;
}

constructor(address _qwManager, address _investmentToken, address _assetToken) {
QW_MANAGER = _qwManager;
INVESTMENT_TOKEN = _investmentToken;
Expand Down
38 changes: 7 additions & 31 deletions src/contracts/child/QWCompound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,31 @@ pragma solidity 0.8.23;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IComet} from 'interfaces/IComet.sol';
import {IQWChild} from 'interfaces/IQWChild.sol';
import {IQWComponent} from 'interfaces/IQWComponent.sol';
import {QWComponentBase} from './QWComponentBase.sol';

/**
* @title Compound Integration for Quant Wealth
* @notice This contract integrates with Compound protocol for Quant Wealth management.
*/
contract QWCompound is IQWChild {
contract QWCompound is IQWComponent, QWComponentBase {
// Variables
address public immutable QW_MANAGER;
address public immutable COMET;
address public immutable INVESTMENT_TOKEN;
address public immutable ASSET_TOKEN;

// Custom errors
error InvalidCallData(); // Error for invalid call data
error UnauthorizedAccess(); // Error for unauthorized caller

modifier onlyQwManager() {
if (msg.sender != QW_MANAGER) {
revert UnauthorizedAccess();
}
_;
}

/**
* @dev Constructor to initialize the contract with required addresses.
* @param _qwManager The address of the Quant Wealth Manager contract.
* @param _comet The address of the Compound comet contract.
* @param _investmentToken The address of the investment token (e.g., USDC).
* @param _assetToken The address of the asset token received from Compound (e.g., cUSDC).
* @param _comet The address of the Compound comet contract.
*/
constructor(
address _qwManager,
address _comet,
address _investmentToken,
address _assetToken
) {
QW_MANAGER = _qwManager;
address _assetToken,
address _comet
) QWComponentBase(_qwManager, _investmentToken, _assetToken) {
COMET = _comet;
INVESTMENT_TOKEN = _investmentToken;
ASSET_TOKEN = _assetToken;
}

// Functions
Expand Down Expand Up @@ -91,12 +75,4 @@ contract QWCompound is IQWChild {
tokenAmountReceived = balanceAfter - balanceBefore;
success = true;
}

/**
* @notice Gets the address of the Quant Wealth Manager contract.
* @dev Returns the address of the Quant Wealth Manager contract.
*/
function QW_MANAGER() external view override returns (address) {
return QW_MANAGER;
}
}
Loading

0 comments on commit edfae0d

Please sign in to comment.