Skip to content

Commit dd17fa3

Browse files
committed
merge code
2 parents c851590 + 60202f7 commit dd17fa3

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ DAPP架构请参考文章--[从架构维度看Web2.0与Web3.0应用之别](https
169169
63. [HTLC-crosschain](https://yuanxuxu.com/2020/08/05/%E5%8C%BA%E5%9D%97%E9%93%BE%E8%B7%A8%E9%93%BE%E6%8A%80%E6%9C%AF%E4%B9%8B%E5%93%88%E5%B8%8C%E6%97%B6%E9%97%B4%E9%94%81/)
170170
64. [Web3-Rust](https://github.com/tomusdrw/rust-web3)
171171
65. [ZK-NFT](https://github.com/kevinz917/zk-NFT)
172-
66. [Kleros](https://kleros.io/)
172+
66. [Kleros](https://kleros.io/)
173173
67. [Go-Ethereum Code Analysis](https://geth.ethereum.org/)
174174
68. [Config discord with Collab.land](https://collabland.freshdesk.com/support/solutions/articles/70000036689-discord-bot-walkthrough)
175-
69. [Decentralized OTC](https://github.com/DOTCPro)
175+
69. [Decentralized OTC](https://github.com/DOTCPro)
176+
70. [Tenderly](https://dashboard.tenderly.co/explorer)
177+
176178
欢迎提交 PR,[添加新的基础任务或者更新上面的任务](https://github.com/rebase-network/Dapp-Learning/issues/new)
177179

178180
## 项目任务

basic/39-Multicall/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INFURA_ID=yyyyyyyy

basic/39-Multicall/README.md

+48-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
1-
# Multicall
2-
1+
# Multicall
32
Multicall aggregates results from multiple contract **constant function calls**.
4-
53
This reduces the number of separate JSON RPC requests that need to be sent (especially useful if using remote nodes like Infura), while also providing the guarantee that all values returned are from the same block (like an atomic read) and returning the block number the values are from (giving them important context so that results from old blocks can be ignored if they're from an out-of-date node).
64

7-
This smart contract is intended to be used with **Multicall.js** in front-end dapps.
5+
This smart contract is intended to be used with **Multicall.js** in front-end dapps
86

9-
index finance 的 multicall 实现更为简单。
107

118
## 合约调用方法
9+
合约之间的调用有 2 种方式: 底层的 call 方式和 new 合约的方式
1210

13-
合约之间的调用有 2 种方式: 底层的 call 方式和 new 合约的方式
14-
15-
call:通过合约 ContractAddres.call(编码后的方法名和参数),返回调用是否成功,以及返回值 data
11+
call:通过合约 ContractAddres.call(编码后的方法名和参数),返回调用是否成功,以及返回值 data
1612

17-
delegatecall :设计是为了调用其它合约的 API 用的,类似于 Copy 了 API 合约的 API 函数到**本地合约**执行,会修改调用者合约的状态变量。
13+
delegatecall :设计是为了调用其它合约的 API 用的,类似于 Copy 了 API 合约的 API 函数到**本地合约**执行,会修改调用者合约的状态变量。
1814

1915
staticcall: Since byzantium staticcall can be used as well. This is basically the same as call, but will revert if the called function modifies the state in any way
2016
eth.call 方法可以在本地节点执行方法;
2117

2218
## Multicall.js
23-
24-
project url: https://github.com/makerdao/multicall.js
25-
26-
- Get the return value(s) of multiple smart contract function calls in a single call
27-
- Guarantee that all values are from the same block
28-
- Use watchers to poll for multiple blockchain state variables/functions
29-
- Get updates when a watcher detects state has changed
30-
- Results from out of sync nodes are automatically ignored
31-
- Get new block updates
32-
33-
## indexed-finance-multicall.js
34-
35-
indexed-finance multicall: https://github.com/indexed-finance/multicall
36-
37-
与常规 Muticall 合约调用不同,indexed-finance multicall 不用依赖链上已经部署成功的 multicall 合约,而是将 muticall 请求放到了待部署合约的 constructor 中,通过假部署的方式,拿到链上查询的结果。
38-
39-
indexed-finance multicall 的“骚操作”:
40-
19+
Multicall.js是一个轻量级的 JavaScript 库, 用于与多个智能合约进行交互.
20+
Multicall.js 库具有以下这些特点:
21+
- 在一次调用中获取多个智能合约函数调用的返回值
22+
- 保证所有值都来自同一个块
23+
- 使用观察者轮询多个区块链状态变量/函数
24+
- 当观察者检测到状态发生变化时获取更新
25+
- 不同步节点的结果会被自动忽略
26+
- 获取新的区块更新
27+
28+
## indexed-finance-multicall.js
29+
与常规 Muticall 合约调用不同,indexed-finance multicall 不用依赖链上已经部署成功的 multicall 合约,而是将 muticall 请求放到了待部署合约的 constructor 中,通过假部署的方式,拿到链上查询的结果。
30+
indexed-finance multicall 的“骚操作”:
4131
1. constructor中进行 muticall 请求
4232
2. 利用 `assembly` 修改evm的返回数据,将本来为 revert 的信息,替换为muticall请求结果
4333

@@ -68,9 +58,36 @@ contract MultiCall {
6858
}
6959
```
7060

71-
## 参考链接
61+
## 测试步骤
62+
- 安装依赖
63+
```shell
64+
yarn
65+
```
66+
67+
- 配置环境变量
68+
```shell
69+
cp .env.example .env
70+
71+
## 配置 .evn 文件中的 INFURA_ID
72+
```
73+
74+
- 测试 makerdao-multicall.js
75+
```shell
76+
npx hardhat run scripts/makerdao-multicall.js
77+
```
78+
79+
- 测试 indexed-finance-multicall.js
80+
```shell
81+
npx hardhat run scripts/indexed-finance-multicall.js
82+
```
83+
84+
- 单元测试
85+
```shell
86+
npx hardhat test --network mainnet
87+
```
7288

73-
- github 仓库地址: https://github.com/ETHLend/Microstaking/blob/master/contracts/StakingContract.sol
74-
- index finance: https://github.com/indexed-finance/dividends/tree/master/contracts
89+
## 参考链接
90+
- Multicall.js github 地址: https://github.com/makerdao/multicall.js
91+
- index finance github 地址: https://github.com/indexed-finance/dividends/tree/master/contracts
7592
- Solidity Call 函数: https://www.jianshu.com/p/a5c97d0d7cae
76-
- https://zhuanlan.zhihu.com/p/35292014
93+
- call/delegatecall/staticcall 介绍: https://zhuanlan.zhihu.com/p/35292014

0 commit comments

Comments
 (0)