-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathPuzzleWalletFactory.sol
40 lines (30 loc) · 1.03 KB
/
PuzzleWalletFactory.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "./PuzzleWallet.sol";
contract PuzzleWalletFactory {
event NewWallet(address indexed wallet);
/**
* @dev Creates and initializes a PuzzleWallet instance
*/
function createInstance() public payable returns (address proxy, address instance) {
require(msg.value == 1 ether, "Must send 1 ETH to create instance");
// deploy the PuzzleWallet logic
PuzzleWallet walletLogic = new PuzzleWallet();
// deploy proxy and initialize implementation contract
bytes memory data = abi.encodeWithSelector(
PuzzleWallet.init.selector,
100 ether
);
PuzzleProxy proxy = new PuzzleProxy(
address(this),
address(walletLogic),
data
);
PuzzleWallet instance = PuzzleWallet(address(proxy));
// whitelist this contract to allow it to deposit ETH
instance.addToWhitelist(address(this));
instance.deposit{value: msg.value}();
emit NewWallet(address(proxy));
return (address(proxy), address(instance));
}
}