Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions basic/01-web3js-deploy/README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ https://ithelp.ithome.com.tw/articles/10202794 在成功创建 Infura Project

- 为方便代码测试, 在 .env 中放入私钥和Infura Project ID,格式为 "PRIVATE_KEY=xxxx" "INFURA_ID=yyyyyyyy", index.js代码会自动从中读取, 样例文件可参考 .env.example

- 同时在 BiliBili 上有上传本样例代码的讲解演示:
https://www.bilibili.com/video/BV1Y44y1r7E6/


## 合约功能说明
constructor: 构造函数, 用于部署合约时调用, 同时在其中初始化了公共变量 number 的值
Expand Down
1 change: 0 additions & 1 deletion basic/01-web3js-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Through this basic task, you can learn the processes of compiling and deploying

| Note: You can check the `.env.example` file.

- If you know Chinese, you can check these tasks on [BILIBILI](https://www.bilibili.com/video/BV1Y44y1r7E6/).


# Getting Started
Expand Down
56 changes: 55 additions & 1 deletion basic/08-hardhat-graph/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,61 @@ graph-node:
RUST_LOG: info
```

> 注意: graph-node 连接的节点需要开启 archive 模式(启动节点时,添加 flag --syncmode full --gcmode archive)。
> 注意 1: graph-node 连接的节点需要开启 archive 模式(启动节点时,添加 flag --syncmode full --gcmode archive)。
> 注意 2: 当需要在一个机器中启动多个 graph-node, 并且每个 graph-node 连接到不同的链时,只需要在 docker-compose.yml 添加对应的 graph-node service 即可。如下,配置里 sepolia 和 optimism 的 graph node 服务,同时修改 graph-node-optimism 对外暴露的端口为 8100,8101,8120,8130,8140。修改的时候特别需要注意的是,只能修改暴露的本地端口 (8100/8101/8120/8130/8140), 容器内部的端口 (8000/8001/8020/8030/8040) 千万不要修改,不然会启动报错

```yaml
version: '3'
services:
graph-node-sepolia:
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'sepolia:http://infura.sepolia.com/xxxx'
GRAPH_LOG: info
graph-node-optimism:
image: graphprotocol/graph-node
ports:
- '8100:8000'
- '8101:8001'
- '8120:8020'
- '8130:8030'
- '8140:8040'
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'optimism:http://infura.optimism.com/yyy'
GRAPH_LOG: info
ipfs:
image: ipfs/kubo:v0.17.0
ports:
- '5001:5001'
volumes:
- ./data/ipfs:/data/ipfs:Z
```

2. graph-node 启动

Expand Down
57 changes: 56 additions & 1 deletion basic/08-hardhat-graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,62 @@ graph-node:
RUST_LOG: info
```

> Note: the node in graph-node need start archive mode(when start the node, add flag --syncmode full --gcmode archive). 2. graph-node startup
> Note 1: the node in graph-node need start archive mode(when start the node, add flag --syncmode full --gcmode archive). 2. graph-node startup
> Note 1: When you need to start multiple graph-nodes in one machine, and each graph-node is connected to a different chain, you only need to add the corresponding graph-node service in docker-compose. Configure the sepolia and optimism graph node services as follows, and change the ports exposed to graph-node-optimism to 8100,8101,8120,8130,8140. Note that you can only modify the exposed local port (8100/8101/8120/8130/8140). Do not modify the port (8000/8001/8020/8030/8040) in the container. Otherwise, an error will be reported.

```yaml
version: '3'
services:
graph-node-sepolia:
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'sepolia:http://infura.sepolia.com/xxxx'
GRAPH_LOG: info
graph-node-optimism:
image: graphprotocol/graph-node
ports:
- '8100:8000'
- '8101:8001'
- '8120:8020'
- '8130:8030'
- '8140:8040'
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'optimism:http://infura.optimism.com/yyy'
GRAPH_LOG: info
ipfs:
image: ipfs/kubo:v0.17.0
ports:
- '5001:5001'
volumes:
- ./data/ipfs:/data/ipfs:Z
```


2. Startup with docker compose directly

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require('dotenv').config();

const {
saveRedpacketDeployment,
request,
} = require("../utils");

async function getQuote (fromChain, toChain, fromToken, toToken, fromAmount, slippage, fromAddress, toAddress) {
Expand All @@ -32,22 +33,40 @@ async function getQuote (fromChain, toChain, fromToken, toToken, fromAmount, sli

async function main() {
const [deployer] = await ethers.getSigners();
const fromChain = 'OPT';

// Bridge from OP to Zksync Era
// const fromChain = 'OPT'; // Symbols for Optimism: OPT, Ethereum: ETH
// const fromToken = 'USDT';
// const toChain = 'ERA'; // Symbols for Zksync Era: ERA
// const toToken = 'USDT';
// const fromAmount = '1000000';
// const slippage = 0.05;
// const fromAddress = deployer.address;
// const toAddress = deployer.address;
// const signer = await ethers.provider.getSigner()
// const tokenAddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58" // USDT
// let quote = await getQuote(fromChain, toChain, fromToken, toToken, fromAmount, slippage,fromAddress,toAddress);
// console.log(quote.transactionRequest)


// Bridge from OP to ARB
// we can call `https://li.quest/v1/chains` to get the symbols of supported chains
const fromChain = 'OPT'; // Symbols for Optimism: OPT, Ethereum: ETH
const fromToken = 'USDT';
const toChain = 'ARB';
const toChain = 'ARB'; // Symbols for Zksync Era: ERA
const toToken = 'USDT';
const fromAmount = '1000000';
const slippage = 0.05;
const fromAddress = deployer.address;
const toAddress = deployer.address;
const signer = await ethers.provider.getSigner()
const OPUSDTaddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
const tokenAddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58" // USDT
let quote = await getQuote(fromChain, toChain, fromToken, toToken, fromAmount, slippage,fromAddress,toAddress);
console.log(quote.transactionRequest)

// approve USDT
const usdtContracct = await ethers.getContractAt('IERC20', OPUSDTaddress, deployer);
let approveTx = await usdtContracct.approve(quote.transactionRequest.to, fromAmount);
const tokenContracct = await ethers.getContractAt('IERC20', tokenAddress, deployer);
let approveTx = await tokenContracct.approve(quote.transactionRequest.to, fromAmount);
await approveTx.wait();
console.log(`Approve USDT to ${quote.transactionRequest.to} successfully`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require('dotenv').config();
const {
readRedpacketDeployment,
getStatus,
request,
} = require("../utils");

async function getQuote (fromChain, toChain, fromToken, toToken, fromAmount, slippage, fromAddress, toAddress) {
Expand All @@ -33,6 +34,21 @@ async function getQuote (fromChain, toChain, fromToken, toToken, fromAmount, sli

async function main() {
const [deployer] = await ethers.getSigners();

// Bridge From Op to Zksync ERA
// const fromChain = 'OPT';
// const fromToken = 'USDT';
// const toChain = 'ERA';
// const toToken = 'USDT';
// const fromAmount = '1000000';
// const slippage = 0.03;
// const fromAddress = deployer.address;
// const toAddress = deployer.address;
// let quote = await getQuote(fromChain, toChain, fromToken, toToken, fromAmount, slippage,fromAddress,toAddress);
// console.log(quote.transactionRequest)


// Bridge From Op to ARB
const fromChain = 'OPT';
const fromToken = 'USDT';
const toChain = 'ARB';
Expand All @@ -41,8 +57,6 @@ async function main() {
const slippage = 0.03;
const fromAddress = deployer.address;
const toAddress = deployer.address;
const signer = await ethers.provider.getSigner()
const OPUSDTaddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
let quote = await getQuote(fromChain, toChain, fromToken, toToken, fromAmount, slippage,fromAddress,toAddress);
// console.log(quote.transactionRequest)

Expand Down
2 changes: 1 addition & 1 deletion basic/80-crossChainTransfer/celerBridge/README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cp .env.example .env
```

## 执行跨链
- 以流动性池方式进行跨链
- 以流动性池方式进行跨链
```
npx hardhat run scripts/1-poolBasedTransfer.js --network optim
```
Expand Down
2 changes: 1 addition & 1 deletion basic/80-crossChainTransfer/celerBridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cp .env.example .env
```

## Executing Cross-Chain Operations
- Cross-chain operation in Pool-Based mode
- Cross-chain operation in Pool-Based mode
```
npx hardhat run scripts/1-poolBasedTransfer.js --network optim
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,55 @@ async function main() {
console.log("Try to getTransferConfigs")
await getTransferConfigs()

const sourceChainID = 10 // Op Mainnet
const destChainID = 137 // Polygon Mainnet
// Bridge from OP to Zksync Era
// const sourceChainID = 10 // Op Mainnet: 10, Ethereum: 1
// const destChainID = 324 // Polygon Mainnet: 137, zkSync Era: 324
// const tokenSymbol = "USDT" // transfer USDT
// const slippageTolerance = 3000 // if the user sets slippage_tolerance with 0.05%, slippage_tolerance in the request will be 0.05% * 1M = 500
// const transferAmount = 21000000
// const tokenAddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
// const nonce = new Date().getTime()


// Bridge from Ethereum to Zksync Era
// const sourceChainID = 1 // Op Mainnet
// const destChainID = 324 // Zksync Era Mainnet
// const tokenSymbol = "USDC" // transfer USDT
// const slippageTolerance = 3000 // if the user sets slippage_tolerance with 0.05%, slippage_tolerance in the request will be 0.05% * 1M = 500
// const transferAmount = 21000000 // The transfer amount must be greater than 20 USDC.e.
// const tokenAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" // celeBridge support USDC.e & wETH right now, please refer to https://cbridge.celer.network/1/324/USDC for more details
// const nonce = new Date().getTime()


// Bridge from OP to Polygon
const sourceChainID = 10 // Op Mainnet: 10, Ethereum: 1
const destChainID = 137 // Polygon Mainnet: 137, zkSync Era: 324
const tokenSymbol = "USDT" // transfer USDT
const slippageTolerance = 3000 // if the user sets slippage_tolerance with 0.05%, slippage_tolerance in the request will be 0.05% * 1M = 500
const transferAmount = 21000000
const OpUSDTAddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
const tokenAddress = "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
const nonce = new Date().getTime()
// const nonce = 1708951941243


console.log("Try to estimate transfer amt")
const estimageResult = await estimateAmt(sourceChainID,destChainID,tokenSymbol,deployer.address,slippageTolerance,transferAmount)

// Pool Based Transfer for USDT, from Op to Polygon
// for contract address, refer to https://cbridge-docs.celer.network/reference/contract-addresses
const OpPoolBasedBridgeContract = "0x9D39Fc627A6d9d9F8C831c16995b209548cc3401"
const usdtContracct = await ethers.getContractAt('IERC20', OpUSDTAddress, deployer);
const usdtContracct = await ethers.getContractAt('IERC20', tokenAddress, deployer);

let tx = await usdtContracct.approve(OpPoolBasedBridgeContract, transferAmount);
await tx.wait();
console.log("Approve USDT to OpPoolBasedBridge successfully")

const bridge = await ethers.getContractAt('Bridge', OpPoolBasedBridgeContract, deployer);
let receipt = await bridge.send(deployer.address, OpUSDTAddress,transferAmount,destChainID,nonce,slippageTolerance)
let receipt = await bridge.send(deployer.address, tokenAddress,transferAmount,destChainID,nonce,slippageTolerance)
await receipt.wait()

console.log("Send bridge request successfully")

let transferID = getPoolBasedTransferID(deployer.address, deployer.address,OpUSDTAddress,transferAmount,destChainID,nonce,sourceChainID)
let transferID = getPoolBasedTransferID(deployer.address, deployer.address,tokenAddress,transferAmount,destChainID,nonce,sourceChainID)
console.log(transferID)
// let transferID = "0xasdfasfsfasf"
saveRedpacketDeployment({
Expand Down
3 changes: 2 additions & 1 deletion basic/80-crossChainTransfer/layerZero/README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ npx hardhat run scripts/sendTokens/7-checkResultOnOpsepolia.js --network optim_s


# 参考文档
- 官方文档: https://docs.layerzero.network/contracts/getting-started
- 官方文档 v1: https://docs.layerzero.network/contracts/getting-started
- 官方文档 v2: https://docs.layerzero.network/v2
- example for OmniCounter: https://github.com/LayerZero-Labs/solidity-examples/blob/main/test/examples/OmniCounter.test.js
- blog: https://senn.fun/layerzero-v1
- layerzero scan: https://testnet.layerzeroscan.com/
Expand Down
Loading