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

Feat: check if Earn vault is deployed by factory #123

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 15 additions & 2 deletions src/EulerEarnFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

// interfaces
import {IEulerEarnFactory} from "./interface/IEulerEarnFactory.sol";
// contracts
import {EulerEarn, IEulerEarn} from "./EulerEarn.sol";
// libs
Expand All @@ -9,14 +11,17 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
/// @title EulerEarnFactory contract
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
contract EulerEarnFactory {
contract EulerEarnFactory is IEulerEarnFactory {
error InvalidQuery();

/// @dev euler earn implementation address
/// @dev Euler earn implementation address
address public immutable eulerEarnImpl;
/// @dev Array for deployed Euler Earn addresses.
address[] public eulerEarnVaults;

/// @dev Mapping to set a deployed vault as verified.
mapping(address => bool) internal deployedVault;

/// @dev Emits when deploying new Earn vault.
event DeployEulerEarn(address indexed _owner, address _eulerEarnVault, address indexed _asset);

Expand Down Expand Up @@ -49,6 +54,7 @@ contract EulerEarnFactory {
IEulerEarn(eulerEulerEarnVault).init(eulerEarnVaultInitParams);

eulerEarnVaults.push(address(eulerEulerEarnVault));
deployedVault[address(eulerEulerEarnVault)] = true;

emit DeployEulerEarn(msg.sender, address(eulerEulerEarnVault), _asset);

Expand Down Expand Up @@ -77,4 +83,11 @@ contract EulerEarnFactory {

return eulerEarnVaultsList;
}

/// @notice Check if an Euler Earn vault address has been deployed by this factory.
/// @param _earnVaultAddress Euler Earn address.
/// @return A boolean, true if vault is deployed by this factory, else false.
function isValidDeployment(address _earnVaultAddress) external view returns (bool) {
return deployedVault[_earnVaultAddress];
}
}
16 changes: 16 additions & 0 deletions src/interface/IEulerEarnFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

interface IEulerEarnFactory {
function deployEulerEarn(
address _asset,
string memory _name,
string memory _symbol,
uint256 _initialCashAllocationPoints
) external returns (address);

function eulerEarnImpl() external view returns (address);
function getEulerEarnVaultsListLength() external view returns (uint256);
function getEulerEarnVaultsListSlice(uint256 _start, uint256 _end) external view returns (address[] memory);
function isValidDeployment(address _earnVaultAddress) external view returns (bool);
}
3 changes: 3 additions & 0 deletions test/common/EulerEarnBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ contract EulerEarnBase is EVaultTestBase {
assertEq(eulerEulerEarnVault.withdrawalQueueModule(), deploymentParams.withdrawalQueueModule);
assertEq(eulerEulerEarnVault.isCheckingHarvestCoolDown(), true);
assertEq(eulerEulerEarnVault.permit2Address(), permit2);

assertTrue(eulerEulerEarnVaultFactory.isValidDeployment(address(eulerEulerEarnVault)));
assertFalse(eulerEulerEarnVaultFactory.isValidDeployment(address(assetTST)));
}

function testDeployEulerEarnWithInvalidInitialCashAllocationPoints() public {
Expand Down
Loading