Skip to content

Commit c403c67

Browse files
committed
feat: Added factory
1 parent 13f5e51 commit c403c67

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/IPCM.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.so
77
contract IPCM is Ownable {
88
string private cidMapping;
99

10-
constructor(address owner, string memory initialCID) Ownable(owner) {
11-
cidMapping = initialCID;
12-
}
10+
constructor() Ownable(msg.sender) {}
1311

1412
event MappingUpdated(string value);
1513

src/IPCMFactory.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.22;
3+
4+
import "../lib/openzeppelin-contracts/contracts/proxy/Clones.sol";
5+
import "./IPCM.sol";
6+
7+
contract IPCMFactory {
8+
// Address of the implementation contract
9+
address public immutable implementation;
10+
11+
// Event to emit when a new clone is created
12+
event IPCMCreated(address cloneAddress);
13+
14+
constructor() {
15+
// Deploy the implementation contract
16+
implementation = address(new IPCM());
17+
}
18+
19+
function createIPCM() external returns (address) {
20+
address clone = Clones.clone(implementation);
21+
22+
emit IPCMCreated(clone);
23+
24+
return clone;
25+
}
26+
27+
// Optional: deterministic clone using create2
28+
// function createDeterministicHelloBase(
29+
// bytes32 salt
30+
// ) external returns (address) {
31+
// address clone = Clones.cloneDeterministic(implementation, salt);
32+
33+
// emit HelloBaseCreated(clone);
34+
35+
// return clone;
36+
// }
37+
38+
// Function to predict the address of a deterministic clone
39+
// function predictDeterministicAddress(
40+
// bytes32 salt
41+
// ) external view returns (address) {
42+
// return
43+
// Clones.predictDeterministicAddress(
44+
// implementation,
45+
// salt,
46+
// address(this)
47+
// );
48+
// }
49+
}

0 commit comments

Comments
 (0)