Skip to content

Commit 32851cb

Browse files
authored
Merge pull request #584 from yingjingyang/main
add redpacket contract
2 parents 1635f94 + c246e5c commit 32851cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3914
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ DAPP架构请参考文章--[从架构维度看Web2.0与Web3.0应用之别](https
154154
47. [TWAMM: Time-Weighted Average Market Maker](https://www.paradigm.xyz/2021/07/twamm/)
155155
48. [state channel](https://ethereum.org/en/developers/docs/scaling/state-channels/)
156156
49. [sniper](https://github.com/Supercycled/cake_sniper.git)
157-
50. [solidity security](basic/50-solidity-security/readme.md)
158-
51. [alchemix](https://github.com/alchemix-finance/alchemix-protocol)
157+
50. [solidity security](basic/50-solidity-security/readme.md)
158+
51. [NYM](https://myz1237.substack.com/p/nymwhitepaper?r=uaq4w&utm_campaign=post&utm_medium=web&utm_source=)
159159
52. [Governace](https://github.com/withtally/safeguard)
160160
53. [Freelancer's Smart Contract](https://github.com/jacksonng77/freelancer)
161161
54. [Cryptovoxels](https://zhuanlan.zhihu.com/p/379249411)
@@ -174,7 +174,6 @@ DAPP架构请参考文章--[从架构维度看Web2.0与Web3.0应用之别](https
174174
68. [Config discord with Collab.land](https://collabland.freshdesk.com/support/solutions/articles/70000036689-discord-bot-walkthrough)
175175
69. [Decentralized OTC](https://github.com/DOTCPro)
176176
70. [Tenderly](https://dashboard.tenderly.co/explorer)
177-
71. [NYM](https://myz1237.substack.com/p/nymwhitepaper?r=uaq4w&utm_campaign=post&utm_medium=web&utm_source=)
178177

179178

180179
## 项目任务
@@ -214,7 +213,8 @@ DAPP架构请参考文章--[从架构维度看Web2.0与Web3.0应用之别](https
214213
18. [Set](https://www.tokensets.com/)
215214
19. [Dhedge](https://docs.dhedge.org/dhedge-protocol/managing-on-v2)
216215
20. [Liquity](defi/Liquity/readme.md)
217-
21. [RAI](https://www.youtube.com/watch?v=ADK91Zw4sJA&list=PL-GxJch-YeZerVVV8dY8qU2VkJfbnSfdN&index=3)
216+
21. [RAI](https://www.youtube.com/watch?v=ADK91Zw4sJA&list=PL-GxJch-YeZerVVV8dY8qU2VkJfbnSfdN&index=3)
217+
22. [Alchemix](https://github.com/alchemix-finance/alchemix-protocol)
218218

219219

220220
## NFT 进阶
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PRIVATE_KEY=yyyy
2+
INFURA_ID=zzzz
3+
PROJECT_ID=xxxxx
4+
TARGET_ACCOUNT=mmm

basic/42-merkle-distributor-airdrop/README.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
### ERC20 merkel airdrop
1414

1515
参考 1inch,dydx,uniswap 都实现 merkle 空投。 具体原理请参考:
16-
https://itzone.com.vn/en/article/merkle-airdrop-the-airdrop-solution-for-token-issues/
16+
https://itzone.com.vn/en/article/merkle-airdrop-the-airdrop-solution-for-token-issues/
17+
18+
### 抢红包
19+
本样例演示了抢红包合约的功能, 在节假日的时候可以部署相应的合约进行红包发放.
20+
对应合约路径为 contracts/redpacket
1721

1822
## 合约功能说明
1923

@@ -90,7 +94,7 @@ await expect(this.registry.redeem(this.token.account, this.token.tokenId, this.t
9094
```
9195

9296
## 测试流程
93-
97+
### Merkle airdrop
9498
- 安装依赖
9599

96100
```bash
@@ -103,6 +107,67 @@ yarn
103107
npx hardhat test
104108
```
105109

110+
### 抢红包
111+
- 配置环境环境变量
112+
```shell
113+
cp .env.exmpale .env
114+
115+
## 在 .env 文件中配置 PRIVATE_KEY, INFURA_ID, PROJECT_ID, TARGET_ACCOUNT
116+
## 比如有一个账户 A , 那么 PRIVATE_KEY 为账户 A 对应的 PRIVATE_KEY, TARGET_ACCOUNT 为账户 A 对应的账户地址
117+
```
118+
119+
- 配置 redpacketAddressList
120+
因为红包领取时会进行 Merkle 校验, 所以需要在 Merkle List 中配置对应的账户地址.
121+
修改 scripts/redpacket/redpacketAddressList.json 文件,在其中加入上一步操作中 "TARGET_ACCOUNT" 的值.
122+
123+
- 安装依赖
124+
```shell
125+
yarn
126+
```
127+
128+
- 部署 ERC20 合约
129+
执行如下命令,然后获取输出的 "Token address" 值
130+
```shell
131+
npx hardhat run scripts/redpacket/1-deploySimpleToken.js --network kovan
132+
133+
## 输入信息如下:
134+
Deploying contracts with the account: 0x3238f24e7C752398872B768Ace7dd63c54CfEFEc
135+
Account balance: 796474026501725149
136+
Token address: 0xdc6999dC3f818B4f74550569CCC7C82091cA419F
137+
1000000000
138+
```
139+
140+
- 部署 RedPacket 合约
141+
执行如下命令,然后获取输出的 "RedPacket address" 值
142+
```shell
143+
npx hardhat run scripts/redpacket/2-deployHappyRedPacket.js --network kovan
144+
145+
## 输出信息如下:
146+
Deploying contracts with the account: 0x3238f24e7C752398872B768Ace7dd63c54CfEFEc
147+
Account balance: 783625061469463255
148+
RedPacket address: 0x6F35e57a7421F5b04DDb47b67453A5a5Be32e58B
149+
```
150+
151+
- 创建红包
152+
修改 scripts/redpacket/3-createRedPacket.js 文件中的 "HappyRedPacketAddress" 和 "SimpleTokenAddress" 地址为上面输出的地址, 然后执行下面的命令, 获取输出的 "RedpacketId"
153+
```shell
154+
npx hardhat run scripts/redpacket/3-createRedPacket.js --network kovan
155+
156+
## 输出值
157+
Approve Successfully
158+
merkleTree Root: 0x5cc6f1ff34a2c6f871d40cdc4559468f96a7ec06d7bf6ab0f9b5aeccc9b33154
159+
CreationSuccess Event, total: 10000 RedpacketId: 0x45eb11e56a1b699f5e99bd16785c84b73a8257c712e0d1f31306ab1e3423b2e0
160+
Create Red Packet successfully
161+
```
162+
163+
- 领取红包
164+
修改 "4-claimRedpacket.js" 文件中的 "HappyRedPacketAddress" 和 "redpacketID" 值为上面的输出值, 然后执行下面的命令进行红包的 claim
165+
```shell
166+
npx hardhat run scripts/redpacket/4-claimRedpacket.js --network kovan
167+
168+
## 得到的输出 "Sign Message:" 即为领取红包时需要输入的签名信息,防止恶意领取
169+
```
170+
106171
## 参考链接
107172

108173
- https://github.com/Anish-Agnihotri/merkle-airdrop-starter

0 commit comments

Comments
 (0)