Skip to content

Commit e8dd3cc

Browse files
committed
use Dropper contract for airdrop
1 parent 3579be0 commit e8dd3cc

File tree

3 files changed

+486
-110
lines changed

3 files changed

+486
-110
lines changed

src/ERC20Airdropper.sol

+68-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8;
33

4-
import "./GovernableERC20.sol";
5-
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
4+
import {GovernableERC20} from "./GovernableERC20.sol";
5+
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
6+
import {Dropper} from "./vendor/Dropper.sol";
67

78
contract ERC20Airdropper {
8-
struct Recipient {
9-
address addr;
10-
uint256 amount;
9+
struct TokenArgs {
10+
string name;
11+
string symbol;
12+
uint256 totalSupply;
13+
}
14+
15+
struct DropArgs {
16+
bytes32 merkleRoot;
17+
uint256 totalTokens;
18+
uint40 startTimestamp;
19+
uint40 expirationTimestamp;
20+
address expirationRecipient;
21+
string merkleTreeURI;
22+
string dropDescription;
1123
}
1224

1325
event ERC20Created(
@@ -16,35 +28,67 @@ contract ERC20Airdropper {
1628
string symbol,
1729
uint256 totalSupply
1830
);
19-
event Airdropped(address indexed token, Recipient[] recipients);
20-
21-
function createToken(
22-
string memory name,
23-
string memory symbol,
24-
uint256 totalSupply,
25-
Recipient[] memory recipients
26-
) external returns (ERC20) {
31+
32+
event DropCreated(
33+
uint256 indexed dropId,
34+
address indexed token,
35+
bytes32 merkleRoot,
36+
uint256 totalTokens,
37+
uint40 startTimestamp,
38+
uint40 expirationTimestamp
39+
);
40+
41+
Dropper public immutable DROPPER;
42+
43+
constructor(Dropper _dropper) {
44+
DROPPER = _dropper;
45+
}
46+
47+
function createTokenAndAirdrop(
48+
TokenArgs memory tokenArgs,
49+
DropArgs memory dropArgs
50+
) external returns (ERC20, uint256) {
2751
GovernableERC20 token = new GovernableERC20(
28-
name,
29-
symbol,
30-
totalSupply,
52+
tokenArgs.name,
53+
tokenArgs.symbol,
54+
tokenArgs.totalSupply,
3155
address(this)
3256
);
3357

34-
emit ERC20Created(address(token), name, symbol, totalSupply);
58+
emit ERC20Created(
59+
address(token),
60+
tokenArgs.name,
61+
tokenArgs.symbol,
62+
tokenArgs.totalSupply
63+
);
64+
65+
token.approve(address(DROPPER), dropArgs.totalTokens);
3566

36-
if (recipients.length > 0) {
37-
for (uint256 i = 0; i < recipients.length; i++) {
38-
token.transfer(recipients[i].addr, recipients[i].amount);
39-
}
40-
emit Airdropped(address(token), recipients);
41-
}
67+
uint256 dropId = DROPPER.createDrop(
68+
dropArgs.merkleRoot,
69+
dropArgs.totalTokens,
70+
address(token),
71+
dropArgs.startTimestamp,
72+
dropArgs.expirationTimestamp,
73+
dropArgs.expirationRecipient,
74+
dropArgs.merkleTreeURI,
75+
dropArgs.dropDescription
76+
);
77+
78+
emit DropCreated(
79+
dropId,
80+
address(token),
81+
dropArgs.merkleRoot,
82+
dropArgs.totalTokens,
83+
dropArgs.startTimestamp,
84+
dropArgs.expirationTimestamp
85+
);
4286

4387
uint256 remaining = token.balanceOf(address(this));
4488
if (remaining > 0) {
4589
token.transfer(msg.sender, remaining);
4690
}
4791

48-
return token;
92+
return (token, dropId);
4993
}
5094
}

0 commit comments

Comments
 (0)