Skip to content

Commit a18eea5

Browse files
authored
Merge pull request #1289 from yanyanho/main
complement some task
2 parents 58d60b0 + 814b39b commit a18eea5

File tree

23 files changed

+758
-92
lines changed

23 files changed

+758
-92
lines changed

basic/07-hardhat/hardhat.config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require("@nomicfoundation/hardhat-toolbox");
1+
require('@nomicfoundation/hardhat-toolbox');
22
require('dotenv').config();
33

44
// This is a sample Hardhat task. To learn how to create your own go to
@@ -42,12 +42,12 @@ module.exports = {
4242
},
4343
etherscan: {
4444
apiKey: {
45-
sepolia: process.env.APIKEY
46-
} ,
45+
sepolia: process.env.APIKEY,
46+
},
4747
},
4848
sourcify: {
4949
// Disabled by default
5050
// Doesn't need an API key
51-
enabled: true
52-
}
51+
enabled: true,
52+
},
5353
};

basic/17-etherjs-wallet-develop/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"license": "ISC",
99
"dependencies": {
1010
"@nomiclabs/hardhat-waffle": "^2.0.6",
11+
"bip39": "^3.1.0",
1112
"chai": "^5.1.0",
1213
"hardhat": "^2.22.2",
14+
"keccak": "^3.0.4",
1315
"mocha": "^10.4.0"
1416
}
1517
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const {ethers} = require("hardhat");
2+
const bip39 = require('bip39');
3+
4+
// 通过助记词创建钱包
5+
//squirrel refuse ozone miracle hollow renew sail clever fruit chaos merit brown
6+
function* permutations(arr, n = arr.length) {
7+
if (n <= 1) yield arr.slice();
8+
else for (let i = 0; i < n; i++) {
9+
yield* permutations(arr, n - 1);
10+
const j = n % 2 ? 0 : i;
11+
[arr[n - 1], arr[j]] = [arr[j], arr[n - 1]];
12+
}
13+
}
14+
15+
const words = mnemonic.split(' ');
16+
17+
for (const perm of permutations(words)) {
18+
const testMnemonic = perm.join(' ');
19+
console.log(testMnemonic);
20+
if (bip39.validateMnemonic(testMnemonic)) {
21+
22+
23+
for (let i = 0; i <= 10; i++) {
24+
let path = `m/44'/60'/1'/0/${i}`;
25+
let secondMnemonicWallet = ethers.Wallet.fromMnemonic(testMnemonic, path);
26+
if (secondMnemonicWallet.address.toLowerCase() === "0x55A68930b14f8166AD0c432C01d68739B94d3cf3".toLowerCase()) {
27+
console.log(`Valid mnemonic: ${testMnemonic} with path: ${path}`);
28+
break;
29+
}
30+
}
31+
32+
}
33+
34+
}
35+
36+
// if (validMnemonics.length > 0) {
37+
// console.log("Valid mnemonic orders found:");
38+
// validMnemonics.forEach(mnemonic => console.log(mnemonic));
39+
// } else {
40+
// console.error("No valid mnemonic order found.");
41+
// }
42+
43+
// const wallet2 = ethers.Wallet.fromMnemonic(validMnemonics[0] ? validMnemonics[0] : mnemonic);
44+
// console.log("Address: " + wallet2.address);
45+
46+
// // Load the second account from a mnemonic
47+
// let path = "m/44'/60'/1'/0/0";
48+
// let secondMnemonicWallet = ethers.Wallet.fromMnemonic(validMnemonics[0] ? validMnemonics[0] : mnemonic, path);
49+
// // Load using a non-english locale wordlist (the path "null" will use the default)
50+
// // let secondMnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic, null, ethers.wordlists.ko);

basic/25-multi-sig-wallet/README-CN.md

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ INFURA_ID = yyyyyyyy; // 替换为infura节点
113113

114114
- New Version Gnosis Safe Contracts: <https://github.com/safe-global/safe-contracts>
115115

116+
gnosis safe - 4337
117+
https://docs.safe.global/advanced/erc-4337/4337-safe
118+
119+
gnosis safe - 7702
120+
https://docs.safe.global/advanced/eip-7702/overview
121+
116122
## 参考链接
117123

118124
- [Now open source: friendly multi-signatures for Ethereum 🔑](https://medium.com/dsys/now-open-source-friendly-multi-signatures-for-ethereum-d75ca5a0dc5c)

basic/37-erc4626/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"@aave/periphery-v3": "2.5.2",
66
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
77
"@openzeppelin/contracts": "^5.0.1",
8-
"@openzeppelin/contracts-upgradeable": "5.0.2",
8+
"@openzeppelin/contracts-upgradeable": "5.0.1",
99
"dotenv": "^16.0.0",
1010
"hardhat": "^2.22.6"
1111
}

basic/38-alloy-rust/readme.md

+11
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,14 @@
8383
assert_eq!(receipt.status(), true);
8484
info!("Transfer successful");
8585
```
86+
87+
8. 启动本地节点
88+
```shell
89+
anvil
90+
```
91+
92+
9. 运行项目
93+
94+
```rust
95+
cargo run src/main.rs
96+
```

basic/38-alloy-rust/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2525

2626
let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key");
2727
let address = signer.address();
28+
info!("Using address: {}", address);
2829
let wallet = EthereumWallet::from(signer);
2930
let provider =
3031
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(rpc_url);

basic/39-Multicall/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ https://github.com/Vectorized/multicaller/blob/main/src/MulticallerWithSender.so
107107
- index finance github 地址: https://github.com/indexed-finance/dividends/tree/master/contracts
108108
- Solidity Call 函数: https://www.jianshu.com/p/a5c97d0d7cae
109109
- call/delegatecall/staticcall 介绍: https://zhuanlan.zhihu.com/p/35292014
110+
- https://destiner.io/blog/post/multicall-how-to-make-multiple-ethereum-calls-in-a-single-request/

basic/39-Multicall/hardhat.config.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
require("@nomiclabs/hardhat-waffle");
2-
require('dotenv').config()
1+
require('@nomiclabs/hardhat-waffle');
2+
require('dotenv').config();
33

44
// This is a sample Hardhat task. To learn how to create your own go to
55
// https://hardhat.org/guides/create-task.html
6-
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
6+
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
77
const accounts = await hre.ethers.getSigners();
88

99
for (const account of accounts) {
1010
console.log(account.address);
1111
}
1212
});
1313

14+
function mnemonic() {
15+
//can config 3 PRIVATE_KEY
16+
//return process.env.PRIVATE_KEY,process.env.PRIVATE_KEY1,process.env.PRIVATE_KEY2;
17+
return process.env.PRIVATE_KEY;
18+
}
19+
1420
// You need to export an object to set up your config
1521
// Go to https://hardhat.org/config/ to learn more
1622

@@ -19,17 +25,18 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
1925
*/
2026
module.exports = {
2127
networks: {
22-
hardhat: {
23-
},
24-
kovan: {
25-
url: `https://kovan.infura.io/v3/${process.env.INFURA_ID}`,
28+
hardhat: {},
29+
sepolia: {
30+
url: `https://sepolia.infura.io/v3/${process.env.INFURA_ID}`,
31+
accounts: [mnemonic()],
2632
},
2733
mainnet: {
2834
url: `https://mainnet.infura.io/v3/${process.env.INFURA_ID}`,
35+
accounts: [mnemonic()],
2936
},
3037
},
31-
solidity: "0.8.4",
38+
solidity: '0.8.4',
3239
mocha: {
33-
timeout: 60000
34-
}
40+
timeout: 60000,
41+
},
3542
};

basic/39-Multicall/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"ethers": "^5.5.2",
1212
"hardhat": "^2.8.0"
1313
}
14-
}
14+
}

basic/39-Multicall/scripts/balance.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const { ethers } = require('hardhat');
2+
require('dotenv').config();
3+
4+
const provider = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/${process.env.INFURA_ID}`);
5+
6+
// Check the balance of the null address for dai and weth
7+
async function main() {
8+
const [deployer] = await ethers.getSigners();
9+
10+
console.log('Deploying contracts with the account:', deployer.address);
11+
12+
const tokens = [
13+
'0x6b175474e89094c44da98b954eedeac495271d0f', // dai
14+
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
15+
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // weth
16+
];
17+
const account = '0x89F2ab029DcD11bD5A00Ed6A77ccBE46315212e8';
18+
19+
console.log(`Checking balances for ${account}`);
20+
21+
const Multicall = await ethers.getContractFactory('Multicall');
22+
23+
const erc20Abi = [
24+
{
25+
constant: true,
26+
inputs: [{ name: '_owner', type: 'address' }],
27+
name: 'balanceOf',
28+
outputs: [{ name: 'balance', type: 'uint256' }],
29+
type: 'function',
30+
},
31+
];
32+
33+
const balanceCalls = tokens.map((tokenAddress) => ({
34+
target: tokenAddress,
35+
callData: new ethers.utils.Interface(erc20Abi).encodeFunctionData('balanceOf', [account]),
36+
}));
37+
38+
// console.log(`balanceCalls: ${JSON.stringify(balanceCalls)}`);
39+
40+
const multicall = await Multicall.attach('0x5ba1e12693dc8f9c48aad8770482f4739beed696');
41+
42+
// let balanceFunciton = '0x70a08231' + '000000000000000000000000' + account.substring(2);
43+
44+
// const result = await multicall.callStatic.aggregate([{ target: tokens[1], callData: balanceFunciton }]);
45+
const result = await multicall.callStatic.aggregate(balanceCalls);
46+
47+
console.log(`result: ${JSON.stringify(result[1])}`);
48+
}
49+
50+
// We recommend this pattern to be able to use async/await everywhere
51+
// and properly handle errors.
52+
main()
53+
.then(() => process.exit(0))
54+
.catch((error) => {
55+
console.error(error);
56+
process.exit(1);
57+
});

basic/39-Multicall/scripts/indexed-finance-multicall.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ async function main() {
1111
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // weth
1212
'0x0000000000000000000000000000000000000000', // eth
1313
];
14-
const account = '0x0000000000000000000000000000000000000000';
14+
const account = '0x89f2ab029dcd11bd5a00ed6a77ccbe46315212e8';
15+
16+
console.log(`Checking balances for ${account}`);
1517
const [blockNumber, balances] = await getBalances(provider, tokens, account).catch((err) => {});
1618

19+
console.log(`BlockNumber: ${blockNumber}`);
20+
console.log(`Balances: ${JSON.stringify(balances)}`);
1721
const daiBalance = balances['0x6b175474e89094c44da98b954eedeac495271d0f'];
1822
const wethBalance = balances['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'];
1923
const ethBalance = balances['0x0000000000000000000000000000000000000000'];

basic/39-Multicall/scripts/makerdao-multicall.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { createWatcher } = require('@makerdao/multicall');
2-
require('dotenv').config()
2+
require('dotenv').config();
33

44
const MKR_TOKEN = '0xaaf64bfcc32d0f15873a02163e7e500671a4ffcd';
55
const MKR_WHALE = '0xdb33dfd3d61308c33c63209845dad3e6bfb2c674';
@@ -11,7 +11,7 @@ const PRICE_FEED_ETH = '0xa5aA4e07F5255E14F02B385b1f04b35cC50bdb66';
1111

1212
// Alternatively the rpcUrl and multicallAddress can be specified manually
1313
const config = {
14-
rpcUrl: `wss://kovan.infura.io/ws/v3/${process.env.INFURA_ID}`,
14+
rpcUrl: `wss://sepolia.infura.io/ws/v3/${process.env.INFURA_ID}`,
1515
multicallAddress: '0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a',
1616
interval: 1000,
1717
};

basic/43-EVM/EVM.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Ethereum Virtual Machine
2+
3+
重点阅读本篇文章:
4+
- [EVM Deep Dives](https://noxx.substack.com/p/evm-deep-dives-the-path-to-shadowy?s=r)
5+
26
opcode码:https://www.ethervm.io/
7+
8+
39
![EVM](./img/evm.jpg)
410
EVM是无寄存器、基于栈的虚拟机,是合约的执行环境, 解释器中需要操作五大组件:
511
- PC:类似于 CPU 中的 PC 寄存器,指向当前执行的指令

basic/49-aa/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ yarn
3939
yarn hardhat run scripts/paymaster.js
4040
```
4141

42+
## TODO
43+
4337
44+
7702
45+
4246
## 文档
4347
- eip-4337文档:4337的规范。https://eips.ethereum.org/EIPS/eip-4337
4448
- sdk:提供了构建UserOperation,推送UserOperation的能力。源码位于https://github.com/eth-infinitism/bundler/tree/main/packages/sdk。
+37-18
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
1-
# LI.FI 介绍
2-
LI.FI 是一种跨链桥接聚合协议,通过聚合 Bridge, DEX, Solver 来支持 Token 在任意链之间转移,交易。
3-
应用场景举例如下:
1+
# LI.FI 介绍
2+
3+
LI.FI 是一种跨链桥接聚合协议,通过聚合 Bridge, DEX, Solver 来支持 Token 在任意链之间转移,交易。
4+
应用场景举例如下:
45
1)Optim 上的 USDT 转移到 Polygon 上
5-
2)Optim 上的 USDT 转移到 Polygon 上,同时将 USDT swap 为 USDC
6-
3)Optim 上的 USDT 转移到 Polygon 上,同时将 10% USDT 变为 Polygon 上原生的 gas ( Matic ),以便后续的操作。这个特性对 EVM 链和非 EVM 链来说非常便利,但目前只支持 4 个链
7-
4)Optim 上的 USDT 转移到 Polygon 上的同时,调用 Polygon 链上的一个合约进行相应处理
6+
2)Optim 上的 USDT 转移到 Polygon 上,同时将 USDT swap 为 USDC
7+
3)Optim 上的 USDT 转移到 Polygon 上,同时将 10% USDT 变为 Polygon 上原生的 gas ( Matic ),以便后续的操作。这个特性对 EVM 链和非 EVM 链来说非常便利,但目前只支持 4 个链
8+
4)Optim 上的 USDT 转移到 Polygon 上的同时,调用 Polygon 链上的一个合约进行相应处理
89

910
LI.FI 的操作很简单,用户只需在 origin chain 上发起一笔交易即可完成上述这些场景。
10-
同时为方便其他 Dapp 集成,LI.FI 提供了对应的 [SDK](https://docs.li.fi/integrate-li.fi-js-sdk/install-li.fi-sdk) 和 相应的前端 [UI components](https://docs.li.fi/integrate-li.fi-widget/li.fi-widget-overview)
11+
同时为方便其他 Dapp 集成,LI.FI 提供了对应的 [SDK](https://docs.li.fi/integrate-li.fi-js-sdk/install-li.fi-sdk) 和 相应的前端 [UI components](https://docs.li.fi/integrate-li.fi-widget/li.fi-widget-overview)
12+
13+
## Route and Quote
14+
15+
集成文档: https://docs.li.fi/integrate-li.fi-sdk/request-routes-quotes
16+
17+
安装lifi sdk,主要有两个主要函数 `getRoutes` and `getQuote` functions.
18+
19+
getRoute 返回数组,给出多个交易路径选择。里面不包含交易数据。
20+
如果想获得最佳路径,直接用 getQuote 方法即可。
21+
Route包含执行的每一步操作,quote一般就是一笔交易而已。
22+
23+
# 跨链测试
24+
25+
下面我们将使用 ARB 和 OP 这两个 Layer2 演示 USDT 跨链
26+
27+
- 软件要求
1128

12-
# 跨链测试
13-
下面我们将使用 ARB 和 OP 这两个 Layer2 演示 USDT 跨链
14-
- 软件要求
1529
```
1630
node 版本需要为 v20.11.0
1731
```
1832

19-
- 安装依赖
20-
```
33+
- 安装依赖
34+
35+
```
2136
npm install
2237
```
2338

24-
- 配置 env 文件
39+
- 配置 env 文件
40+
2541
```shell
2642
cp .env.example .env
2743
## 之后在 .env 文件中配置对应的私钥和infura
2844
```
2945

30-
- 发起跨链请求
46+
- 发起跨链请求
47+
3148
```
3249
npx hardhat run scripts/1-crossChainTokenTransfer.js --network optim
3350
```
3451

35-
- 检查跨链结果
52+
- 检查跨链结果
53+
3654
```
3755
npx hardhat run scripts/2-checkTokenTransferStatus.js --network optim
3856
```
3957

58+
## 参考文档
4059

41-
## 参考文档
42-
- 官方文档: https://docs.li.fi/
43-
- 合约仓库: https://github.com/lifinance/contracts/blob/main/docs/README.md
60+
- 官方文档: https://docs.li.fi/
61+
- 集成文档:https://docs.li.fi/integrate-li.fi-sdk/request-routes-quotes
62+
- 合约仓库: https://github.com/lifinance/contracts/blob/main/docs/README.md

0 commit comments

Comments
 (0)