This project demonstrates gasless & automated cross-chain token transfer using Circle's CCTP as well as Gelato Relay and Gelato Web3 Functions.
Warning
Code is not yet audited by a third party - please use at your own discretion.
Cross-Chain Transfer Protocol (CCTP) is a permissionless on-chain utility that facilitates USDC transfers between blockchains via native burning and minting.
The Cross-Chain Transfer Protocol can be considered a bridge for native USDC.
Benefits:
- No need to lock-and-mint
- Unified liquidity (no synthetic tokens)
- USDC is burned on the source chain
- Circle observes the event and signs an attestation signature
- USDC is minted on the destination chain using the attestation
Limitations (motivations for this project):
- Steps one and three both require user-initiated transactions on-chain, requiring native tokens
- Subsequent transactions on the destination chain also require native tokens
- Step two can take up to ~13 minutes and the user must be present to initiate the final transaction
With Gelato Relay and Web3 Functions we can:
- Move USDC between chains and cover the cost using USDC
- Pay for subsequent transactions on the destination chain also using USDC
- Automate the entire process reliably in the background
Eliminating the dependence on native tokens gives us infinitely more freedom.
Implications:
- USDC acts as an interoperability layer connecting multiple chains
- Eliminates the need for per-chain native tokens
Note
Gasless refers to the absence of native tokens during transaction fee payment.
Gas is still paid, but abstracted away from the user and compensated in USDC.
- Sign two off-chain ERC-3009 transfer authorization signatures.
These authenticate token transfers, covering the base transfer amount and relay fee on each network.
Code Snippet - Sign a final ERC-2771 signature which enforces our max fee and destination domain intent.
We avoid making any trust assumptions since all data is verified on-chain to have been signed by the user.
Code Snippet - Relay a
depositForBurn
transaction on the source chain.
This burns the tokens and emits events which are observed by Circle and a Web3 Function.
Code Snippet - The Web3 Function indexes all events and periodically fetches attestation signatures from Circle.
Code Snippet - Once an attestation is issued, the Web3 Function relays a
receiveMessage
transaction on the destination chain.
This uses the attestation signature in order to mint the burnt tokens 1:1.
Code Snippet
Intermediary GelatoCCTPSender
and GelatoCCTPReceiver
contracts facilitate relay fee payment.
These are both deployed on each CCTP-compatible network allowing for any-any chain transfers.
Implementation is as simple as importing the cctp-sdk
and calling transfer
.
await transfer(
owner, // owner account address
amount, // total amount including fees
srcMaxFee, // max relay fee on the source chain
dstMaxFee, // max relay fee on the destination chain
srcChainId, // source chainId
dstChainId, // destination chainId
signTypedData // callback to sign typed data
);
- Install dependencies
yarn install
- Edit
.env
cp .env.example .env
- Transfer
10 USDC
from Avalanche to Arbitrumyarn run scripts/transfer.ts