forked from wighawag/clones-with-immutable-args
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExampleCloneFactory.sol
58 lines (51 loc) · 1.5 KB
/
ExampleCloneFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: BSD
pragma solidity ^0.8.4;
import {ExampleClone} from "./ExampleClone.sol";
import {ClonesWithImmutableArgs} from "./ClonesWithImmutableArgs.sol";
contract ExampleCloneFactory {
using ClonesWithImmutableArgs for address;
ExampleClone public implementation;
constructor(ExampleClone implementation_) {
implementation = implementation_;
}
function createClone(
address param1,
uint256 param2,
uint64 param3,
uint8 param4
)
external
returns (ExampleClone clone)
{
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
clone = ExampleClone(address(implementation).clone(data));
}
function createDeterministicClone(
address param1,
uint256 param2,
uint64 param3,
uint8 param4,
bytes32 salt
)
external
returns (ExampleClone clone)
{
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
clone =
ExampleClone(address(implementation).cloneDeterministic(salt, data));
}
function predictDeterministicCloneAddress(
address param1,
uint256 param2,
uint64 param3,
uint8 param4,
bytes32 salt
)
external
view
returns (address, bool)
{
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
return address(implementation).predictDeterministicAddress(salt, data);
}
}