forked from wangbar0133/create2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployer.sol
51 lines (41 loc) · 1.67 KB
/
deployer.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Deployer {
bytes public initCode;
function getInitCode() public {
initCode = type(Dispatch).creationCode;
}
function deploy(uint _salt) public returns(address){
address addr;
bytes memory bytecode = type(Dispatch).creationCode;
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
}
return addr;
}
}
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
contract Dispatch {
function dispatchEther(address[] calldata recipients, uint256[] calldata values) external payable {
for (uint256 i = 0; i < recipients.length; i++)
payable(recipients[i]).transfer(values[i]);
uint256 balance = address(this).balance;
if (balance > 0)
payable(msg.sender).transfer(balance);
}
function dispatchToken(IERC20 token, address[] calldata recipients, uint256[] calldata values) external {
uint256 total = 0;
for (uint256 i = 0; i < recipients.length; i++)
total += values[i];
require(token.transferFrom(msg.sender, address(this), total));
for (uint256 i = 0; i < recipients.length; i++)
require(token.transfer(recipients[i], values[i]));
}
function dispatchTokenSimple(IERC20 token, address[] calldata recipients, uint256[] calldata values) external {
for (uint256 i = 0; i < recipients.length; i++)
require(token.transferFrom(msg.sender, recipients[i], values[i]));
}
}