Skip to content

Commit

Permalink
Merge pull request #112 from morpho-org/feat/interface
Browse files Browse the repository at this point in the history
feat(ifc): add urd factory ifc
  • Loading branch information
julien-devatom authored Jan 12, 2024
2 parents 6b7b75c + 030d41c commit efa8c4a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/UrdFactory.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,28 +12,26 @@ import {UniversalRewardsDistributor} from "./UniversalRewardsDistributor.sol";
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @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;

Expand Down
28 changes: 28 additions & 0 deletions src/interfaces/IUrdFactory.sol
Original file line number Diff line number Diff line change
@@ -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 [email protected]
/// @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);
}

0 comments on commit efa8c4a

Please sign in to comment.