Skip to content

Commit 623d3ec

Browse files
unknownunknown1jaybuidl
authored andcommitted
feat(Curate): update contract
1 parent 3340837 commit 623d3ec

File tree

2 files changed

+780
-94
lines changed

2 files changed

+780
-94
lines changed

contracts/src/CurateFactory.sol

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/**
4+
* @authors: [@mtsalenc*, @unknownunknown1]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
11+
pragma solidity 0.8.18;
12+
13+
import {Curate, IArbitratorV2} from "./CurateV2.sol";
14+
15+
/**
16+
* @title CurateFactory
17+
* This contract acts as a registry for Curate instances.
18+
*/
19+
contract CurateFactory {
20+
/**
21+
* @dev Emitted when a new Curate contract is deployed using this factory. TODO: change TCR mentions.
22+
* @param _address The address of the newly deployed Curate contract.
23+
*/
24+
event NewGTCR(Curate indexed _address);
25+
26+
Curate[] public instances;
27+
address public curate;
28+
29+
/**
30+
* @dev Constructor.
31+
* @param _curate Address of the Curate contract that is going to be used for each new deployment.
32+
*/
33+
constructor(address _curate) {
34+
curate = _curate;
35+
}
36+
37+
/**
38+
* @dev Deploy the arbitrable curated registry.
39+
* @param _arbitrator Arbitrator to resolve potential disputes. The arbitrator is trusted to support appeal periods and not reenter.
40+
* @param _arbitratorExtraData Extra data for the trusted arbitrator contract.
41+
* @param _connectedTCR The address of the Curate contract that stores related Curate addresses. This parameter can be left empty.
42+
* @param _registrationTemplateParameters Template and data mappings json for registration requests.
43+
* @param _removalTemplateParameters Template and data mappings json for removal requests.
44+
* @param _governor The trusted governor of this contract.
45+
* @param _baseDeposits The base deposits for requests/challenges as follows:
46+
* - The base deposit to submit an item.
47+
* - The base deposit to remove an item.
48+
* - The base deposit to challenge a submission.
49+
* - The base deposit to challenge a removal request.
50+
* @param _challengePeriodDuration The time in seconds parties have to challenge a request.
51+
* @param _relayerContract The address of the relay contract to add/remove items directly.
52+
* @param _templateRegistry The dispute template registry.
53+
*/
54+
function deploy(
55+
IArbitratorV2 _arbitrator,
56+
bytes calldata _arbitratorExtraData,
57+
address _connectedTCR,
58+
string[2] calldata _registrationTemplateParameters,
59+
string[2] calldata _removalTemplateParameters,
60+
address _governor,
61+
uint256[4] calldata _baseDeposits,
62+
uint256 _challengePeriodDuration,
63+
address _relayerContract,
64+
address _templateRegistry
65+
) public {
66+
Curate instance = clone(curate);
67+
instance.initialize(
68+
_arbitrator,
69+
_arbitratorExtraData,
70+
_connectedTCR,
71+
_registrationTemplateParameters,
72+
_removalTemplateParameters,
73+
_governor,
74+
_baseDeposits,
75+
_challengePeriodDuration,
76+
_relayerContract,
77+
_templateRegistry
78+
);
79+
instances.push(instance);
80+
emit NewGTCR(instance);
81+
}
82+
83+
/**
84+
* @notice Adaptation of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Clones.sol.
85+
* @dev Deploys and returns the address of a clone that mimics the behaviour of `curate`.
86+
* @param _implementation Address of the contract to clone.
87+
* This function uses the create opcode, which should never revert.
88+
*/
89+
function clone(address _implementation) internal returns (Curate instance) {
90+
/// @solidity memory-safe-assembly
91+
assembly {
92+
// Cleans the upper 96 bits of the `_implementation` word, then packs the first 3 bytes
93+
// of the `_implementation` address with the bytecode before the address.
94+
mstore(0x00, or(shr(0xe8, shl(0x60, _implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
95+
// Packs the remaining 17 bytes of `_implementation` with the bytecode after the address.
96+
mstore(0x20, or(shl(0x78, _implementation), 0x5af43d82803e903d91602b57fd5bf3))
97+
instance := create(0, 0x09, 0x37)
98+
}
99+
require(instance != Curate(address(0)), "ERC1167: create failed");
100+
}
101+
102+
/**
103+
* @return The number of deployed Curate contracts using this factory.
104+
*/
105+
function count() external view returns (uint256) {
106+
return instances.length;
107+
}
108+
}

0 commit comments

Comments
 (0)