From d688ce48c46b021a44783ffb364533714c267a88 Mon Sep 17 00:00:00 2001 From: Haythem Sellami <17862704+haythemsellami@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:45:47 +0700 Subject: [PATCH] isValidDeployment() --- src/EulerEarnFactory.sol | 17 +++++++++++++++-- src/interface/IEulerEarnFactory.sol | 16 ++++++++++++++++ test/common/EulerEarnBase.t.sol | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/interface/IEulerEarnFactory.sol diff --git a/src/EulerEarnFactory.sol b/src/EulerEarnFactory.sol index 75755628..9da7da65 100644 --- a/src/EulerEarnFactory.sol +++ b/src/EulerEarnFactory.sol @@ -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 @@ -9,14 +11,17 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; /// @title EulerEarnFactory contract /// @custom:security-contact security@euler.xyz /// @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); @@ -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); @@ -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]; + } } diff --git a/src/interface/IEulerEarnFactory.sol b/src/interface/IEulerEarnFactory.sol new file mode 100644 index 00000000..cd57feaa --- /dev/null +++ b/src/interface/IEulerEarnFactory.sol @@ -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); +} diff --git a/test/common/EulerEarnBase.t.sol b/test/common/EulerEarnBase.t.sol index 49a8133f..fb878c22 100644 --- a/test/common/EulerEarnBase.t.sol +++ b/test/common/EulerEarnBase.t.sol @@ -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 {