-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForwarderFactoryV4.sol
89 lines (83 loc) · 3.2 KB
/
ForwarderFactoryV4.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.20;
import './ForwarderV4.sol';
import './CloneFactory.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
/**
* @title ForwarderFactoryV4
* @notice This contract will deploy new forwarder contracts using the create2 opcode
* @custom:version 4.0.0
*/
contract ForwarderFactoryV4 is CloneFactory, Ownable {
address public immutable implementationAddress;
address public deployer;
/**
* @notice Event triggered when a new forwarder is deployed
* @param newForwarderAddress Address of the newly deployed forwarder
* @param parentAddress Address to which the funds should be forwarded
* @param feeAddress Address which is allowed to call methods on forwarder contract alongwith the parentAddress
* @param shouldAutoFlushERC721 Whether to automatically flush ERC721 tokens or not
* @param shouldAutoFlushERC1155 Whether to automatically flush ERC1155 tokens or not
*/
event ForwarderCreated(
address newForwarderAddress,
address parentAddress,
address feeAddress,
bool shouldAutoFlushERC721,
bool shouldAutoFlushERC1155
);
/**
* @notice Initializes the factory with the address of the current forwarder implementation
* @param _implementationAddress Address of the current forwarder implementation
* @param _deployer Address of the deployer. In charge of creating new forwarders
*/
constructor(address _implementationAddress, address _deployer) Ownable(_deployer) {
implementationAddress = _implementationAddress;
deployer = _deployer;
}
/**
* @notice Creates a new forwarder contract
* @param parent Address to which the funds should be forwarded
* @param feeAddress Address which is allowed to call methods on forwarder contract alongwith the parentAddress
* @param salt Salt to be used while deploying the contract
*/
function createForwarder(
address parent,
address feeAddress,
bytes32 salt
) external {
this.createForwarder(parent, feeAddress, salt, true, false);
}
/**
* @notice Creates a new forwarder contract
* @param parent Address to which the funds should be forwarded
* @param feeAddress Address which is allowed to call methods on forwarder contract alongwith the parentAddress
* @param salt Salt to be used while deploying the contract
* @param shouldAutoFlushERC721 Whether to automatically flush ERC721 tokens or not
* @param shouldAutoFlushERC1155 Whether to automatically flush ERC1155 tokens or not
*/
function createForwarder(
address parent,
address feeAddress,
bytes32 salt,
bool shouldAutoFlushERC721,
bool shouldAutoFlushERC1155
) external onlyOwner {
/// include the parent and fee address in the salt so any contract deployed directly relies on the parent address and the fee address
bytes32 finalSalt = keccak256(abi.encodePacked(parent, feeAddress, salt));
address payable clone = createClone(implementationAddress, finalSalt);
emit ForwarderCreated(
clone,
parent,
feeAddress,
shouldAutoFlushERC721,
shouldAutoFlushERC1155
);
ForwarderV4(clone).init(
parent,
feeAddress,
shouldAutoFlushERC721,
shouldAutoFlushERC1155
);
}
}