From 030d41c1ef88c701890457fdce99910dc62085f5 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 10 Jan 2024 14:34:34 +0100 Subject: [PATCH] feat(ifc): add urd factory ifc --- src/UrdFactory.sol | 21 +++++++++++---------- src/interfaces/IUrdFactory.sol | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/interfaces/IUrdFactory.sol diff --git a/src/UrdFactory.sol b/src/UrdFactory.sol index 8ebf66c..8e3f587 100644 --- a/src/UrdFactory.sol +++ b/src/UrdFactory.sol @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.19; +import {IUrdFactory} from "./interfaces/IUrdFactory.sol"; +import {IUniversalRewardsDistributor} from "./interfaces/IUniversalRewardsDistributor.sol"; + import {EventsLib} from "./libraries/EventsLib.sol"; import {UniversalRewardsDistributor} from "./UniversalRewardsDistributor.sol"; @@ -9,28 +12,26 @@ import {UniversalRewardsDistributor} from "./UniversalRewardsDistributor.sol"; /// @author Morpho Labs /// @custom:contact security@morpho.org /// @notice This contract allows to create UniversalRewardsDistributor (URD) contracts, and to index them easily. -contract UrdFactory { +contract UrdFactory is IUrdFactory { /* STORAGE */ mapping(address => bool) public isUrd; /* EXTERNAL */ - /// @notice Creates a new URD contract using CREATE2 opcode. - /// @param initialOwner The initial owner of the URD. - /// @param initialTimelock The initial timelock of the URD. - /// @param initialRoot The initial merkle root of the URD. - /// @param initialIpfsHash The optional ipfs hash containing metadata about the root (e.g. the merkle tree itself). - /// @param salt The salt used for CREATE2 opcode. - /// @return urd The address of the newly created URD. + /// @inheritdoc IUrdFactory function createUrd( address initialOwner, uint256 initialTimelock, bytes32 initialRoot, bytes32 initialIpfsHash, bytes32 salt - ) public returns (UniversalRewardsDistributor urd) { - urd = new UniversalRewardsDistributor{salt: salt}(initialOwner, initialTimelock, initialRoot, initialIpfsHash); + ) public returns (IUniversalRewardsDistributor urd) { + urd = IUniversalRewardsDistributor( + address( + new UniversalRewardsDistributor{salt: salt}(initialOwner, initialTimelock, initialRoot, initialIpfsHash) + ) + ); isUrd[address(urd)] = true; diff --git a/src/interfaces/IUrdFactory.sol b/src/interfaces/IUrdFactory.sol new file mode 100644 index 0000000..605414c --- /dev/null +++ b/src/interfaces/IUrdFactory.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity >=0.5.0; + +import {IUniversalRewardsDistributor} from "./IUniversalRewardsDistributor.sol"; + +/// @title IUrdFactory +/// @author Morpho Labs +/// @custom:contact security@morpho.org +/// @notice Interface of UniversalRewardsDistributor's factory. +interface IUrdFactory { + /// @notice Whether a UniversalRewardsDistributor was created with the factory. + function isUrd(address target) external view returns (bool); + + /// @notice Creates a new URD contract using CREATE2 opcode. + /// @param initialOwner The initial owner of the URD. + /// @param initialTimelock The initial timelock of the URD. + /// @param initialRoot The initial merkle root of the URD. + /// @param initialIpfsHash The optional ipfs hash containing metadata about the root (e.g. the merkle tree itself). + /// @param salt The salt used for CREATE2 opcode. + /// @return The address of the newly created URD. + function createUrd( + address initialOwner, + uint256 initialTimelock, + bytes32 initialRoot, + bytes32 initialIpfsHash, + bytes32 salt + ) external returns (IUniversalRewardsDistributor); +}