Skip to content

Commit

Permalink
Merge pull request #1024 from 0x-stan/main
Browse files Browse the repository at this point in the history
add basic/task-80 circle cttp
  • Loading branch information
hotaplayer authored Feb 27, 2024
2 parents 837e58d + 7a6d8e8 commit 312c351
Show file tree
Hide file tree
Showing 9 changed files with 846 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ You are welcome to PR improvements to existing tutorial projects or to create mo
74. [erc20-meta-token](https://github.com/0xsequence/erc20-meta-token)
75. [golang-dapp](basic/75-golang-dapp)
76. [Push Protocol](https://docs.epns.io/developers)
77. [orbit](basic/77-orbit)
78. [wallet connect](basic/78-wallet-connect)
79. [hardhat-foundry](basic/79-hardhat-foundry)
80. [Circle CCTP](basic/80-circle-cctp)

Welcome to submit pull request, [Add a new basic task or update the above task](https://github.com/Dapp-Learning-DAO/Dapp-Learning/issues/new)

Expand Down
3 changes: 3 additions & 0 deletions basic/80-circle-cctp/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALCHEMY_KEY=
SEPOLIA_ACCOUNT_PK=
AVAX_FUJI_PRIVATE_KEY=
31 changes: 31 additions & 0 deletions basic/80-circle-cctp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
_cjs
_esm
_types
*.local
.DS_Store
.eslintcache
.next
bench
cache
coverage
node_modules
tsconfig*.tsbuildinfo

# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.envrc

# tests
generated.ts
vectors/**/*.json

# docs
site/dist
.vercel

# build
dist/
209 changes: 209 additions & 0 deletions basic/80-circle-cctp/README-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# Circle CCTP

中文 / [English](./README.md)

## 概览

跨链转账协议(CCTP)是一个无需许可的链上工具,通过原生的 burn 和 mint 机制,在区块链网络之间安全地转移 USDC。提高使用跨区块链网络 USDC 时的资本效率。CCTP 使开发者能够构建多链应用,为用户提供跨区块链的安全、1:1 的 USDC 转账。

## 工作原理

在源链上燃烧 USDC:在源链上燃烧指定数量的 USDC。
从 Circle 获取签名的证明:Circle 观察并证明源链上的 brun 事件。从 Circle 请求证明,Circle 提供授权在目的链上铸造指定数量的 USDC。
在目标链上铸造 USDC:使用证明触发 USDC 的 mint,并发送到接收者的钱包地址。

跨链转账协议(CCTP)消息传递机制,在支持的区块链之间 burn 和 mint USDC,这一过程包括三个步骤:

1. 源域上的链上组件发出消息。
2. Circle 的链下证明服务对消息进行签名。
3. 目的域上的链上组件接收消息,并将消息体转发给指定的接收者。

## Get-Started

将 USDC 从 Ethereum 测试网 跨链到 Avalanche 测试网

- install

```sh
pnpm install
```

- run script

```sh
pnpm start
```

### Script Output

```sh
Ethereum Sepolia testnet Wallet address: 0xe45d43FEb3F65B4587510A68722450b629154e6f
Avalache Fuji testnet Wallet address: 0xe45d43FEb3F65B4587510A68722450b629154e6f
sepolia test USDC balanceOf 9900000
Amount that will be transferred 100000

STEP 1: Approve messenger contract to withdraw from our active eth address
ApproveTx 0x3a6e906cfd6d6af92ae0520662dd40d126f6e8cb1e76c0b98904d2e3e5739a4f
ApproveTxReceipt: {
...
}

STEP 2: Burn USDC
BurnTx 0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616
BurnTxReceipt: {
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
blockNumber: 5334096n,
contractAddress: null,
cumulativeGasUsed: 10852617n,
effectiveGasPrice: 5774590432n,
from: '0xe45d43feb3f65b4587510a68722450b629154e6f',
gasUsed: 103504n,
logs: [
{
address: '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 5334096n,
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
logIndex: 171,
removed: false
},
{
address: '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 5334096n,
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
logIndex: 172,
removed: false
},
{
address: '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 5334096n,
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
logIndex: 173,
removed: false
},
{
address: '0x7865fafc2db2093669d92c0f33aeef291086befd',
topics: [Array],
data: '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f8000000000000000000000001000000000003ec700000000000000000000000009f3b8679c73c2fef8b59b4f3444d4e156fb70aa5000000000000000000000000eb08f243e5d3fcff26a9e38ae5520a669f4019d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f0000000000000000',
blockNumber: 5334096n,
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
logIndex: 174,
removed: false
},
{
address: '0x9f3b8679c73c2fef8b59b4f3444d4e156fb70aa5',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eb08f243e5d3fcff26a9e38ae5520a669f4019d00000000000000000000000000000000000000000000000000000000000000000',
blockNumber: 5334096n,
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
blockHash: '0x895655d141bc5d34c49d9bf47b3678bedfd43f6f1450a9547653a4196ca3b456',
logIndex: 175,
removed: false
}
],
logsBloom: '0x00000000000000000000000000000000000000000000001000000000000200002000000000000200000000000000000000002010000004000000000000000000100000000000000000000008000000000000000000000000000200020000000001000000022000400000000000000800080000000040000000100010100000000000000000101004000000000000000000000000000000000000000000200000000000000000000000000000000000040000008000000000000000000000000000000002000000000480000000000000000000000000000000000000020020000000000400000020000010000000000000080000000000000000000000000000',
status: 'success',
to: '0x9f3b8679c73c2fef8b59b4f3444d4e156fb70aa5',
transactionHash: '0x95d6a57ce1c4cc35e50cf7561dcbe6bc1df0924912a13d5c293d23472cad6616',
transactionIndex: 106,
type: 'eip1559'
}

STEP 3: Retrieve message bytes from logs

message
0x000000000000000000000001000000000003ec700000000000000000000000009f3b8679c73c2fef8b59b4f3444d4e156fb70aa5000000000000000000000000eb08f243e5d3fcff26a9e38ae5520a669f4019d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f

messageHash 0x921854a0cc7746e05082591412747ffa0c497e6c4785504b29061c5d36b0e1b0

STEP 4: Fetch attestation signature
Signature: 0x5c515abc1964dfe1e46a4a4daacb897a24d586e15d0ff93617e8f22793ed6192565957db1dc55b4011409f4b7dbb4e072a8365fa11071b393c41a6e2527a1b421c6d49f035e9665c55568afea143e3490fa8a1d5f6409fbc94956a9a95cfe258f6236e0805e96080d8347153d64d8823983e9cdfbdb08140d1933b3d8f874356551c

STEP 5: Using the message bytes and signature recieve the funds on destination chain and address
ReceiveTx 0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4

ReceiveTxReceipt: {
blockHash: '0xc7635b7727dd31d44f7b75edfb7298cfe661da5c8910fda8eaa1638a98b9fc68',
blockNumber: 30168739n,
contractAddress: null,
cumulativeGasUsed: 325719n,
effectiveGasPrice: 25000000000n,
from: '0xe45d43feb3f65b4587510a68722450b629154e6f',
gasUsed: 143755n,
logs: [
{
address: '0x5425890298aed601595a70ab815c96711a31bc65',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 30168739n,
transactionHash: '0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4',
transactionIndex: 1,
blockHash: '0xc7635b7727dd31d44f7b75edfb7298cfe661da5c8910fda8eaa1638a98b9fc68',
logIndex: 2,
removed: false
},
{
address: '0x5425890298aed601595a70ab815c96711a31bc65',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 30168739n,
transactionHash: '0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4',
transactionIndex: 1,
blockHash: '0xc7635b7727dd31d44f7b75edfb7298cfe661da5c8910fda8eaa1638a98b9fc68',
logIndex: 3,
removed: false
},
{
address: '0xeb08f243e5d3fcff26a9e38ae5520a669f4019d0',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000186a0',
blockNumber: 30168739n,
transactionHash: '0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4',
transactionIndex: 1,
blockHash: '0xc7635b7727dd31d44f7b75edfb7298cfe661da5c8910fda8eaa1638a98b9fc68',
logIndex: 4,
removed: false
},
{
address: '0xa9fb1b3009dcb79e2fe346c16a604b8fa8ae0a79',
topics: [Array],
data: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000009f3b8679c73c2fef8b59b4f3444d4e156fb70aa500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000084000000000000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000e45d43feb3f65b4587510a68722450b629154e6f00000000000000000000000000000000000000000000000000000000',
blockNumber: 30168739n,
transactionHash: '0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4',
transactionIndex: 1,
blockHash: '0xc7635b7727dd31d44f7b75edfb7298cfe661da5c8910fda8eaa1638a98b9fc68',
logIndex: 5,
removed: false
}
],
logsBloom: '0x0000000000000000008000000000000100004000000000000000010000200000200000000400000000000000000002000000a000000000000000000000000000000000000000000000000008000000000080000000000000000000200000000001020000020000000000000000012800000000000000000000400010000000000000000000000400000000001000000000000000000002000000000000010400000000000000000004100000000000040000000000000000000000000000000000000002000010000080000000000000000000000000000000000000020020000000000000000000000000000000004000000000000800000000000000000000',
status: 'success',
to: '0xa9fb1b3009dcb79e2fe346c16a604b8fa8ae0a79',
transactionHash: '0xa4960f3caad924ffd6982bde512dff930cc1276e4d2ea92b7ab2f1f81bf17bc4',
transactionIndex: 1,
type: 'eip1559'
}
Check USDC on Avax testnet balanceOf 10000
```

## 参考链接

- doc <https://developers.circle.com/stablecoins/docs/transfer-usdc-on-testnet-from-ethereum-to-avalanche>

- contract deployment <https://developers.circle.com/stablecoins/docs/evm-smart-contracts>

- USDC Testnet faucet <https://faucet.circle.com/?_gl=1*ouhs7l*_ga_GJDVPCQNRV*MTcwODUwNDQ1OC4zLjEuMTcwODUwNDQ5MS4yNy4wLjA>
Loading

0 comments on commit 312c351

Please sign in to comment.