Inspiration

I am part of project called The Plague NFT that has an ERC20 token: $FRG. The idea is to allow users to bridge the token into other networks at a low cost.

As current solutions are costly, like the official Avax and Polygon bridges, the idea was to seek a solution to this using the power of Chainlink.

What it does

Uses Chainlink CCIP to bridge tokens from a costly network to a cheaper one, with up to 80% reduction of gas limit. Instead of paying 200,000+ gas by default, the main feature allows you to pay as low as ~45.000 gas, with a time trade off.

The main idea is simple but powerful: Use CCIP to bridge multiple users in a single transaction.

The process:

(1) A max of 778 users deposit their ERC20 token in a SourceCCCB contract, that also saves information about the deposit of each user.

(2) Use CCIP to send both tokens and data to a destination chain.

(3) In the destination chain, the DestinationCCCB contract distributes the funds according to the data in the CCIP message.

For it to work, each users pay a tax in native tokens when depositing in the source chain. At N users, the contract will accumulate N * tax native tokens in the contract.

Then any entity can call bridge() to bridge the tokens over, and as a reward, gets the accumulated N * tax native tokens.

This way, each user pays in advance its own bridge costs, and then an EVM bot can bridge the tokens when the accumulated reward is positive.

The bridge tax varies according to gas price in the network. For this we use Chainlink Price Feed, but only available for ethereum mainnet. It also varies according to how many users we want to queue as target, for now, editable by a manager.

How I built it

Firstly, using forge, solidity, and the ccip-starting-kit, I was able to built a proof of concept that allowed me to see if the idea was economically viable.

Secondly, I started making tests to see the limitations of the contract. How many users could be queued, simulations about transaction costs, and so on. With tests working I passed to the next step.

Thirdly, I deployed both contracts in Sepolia and Avalanche Fuji

Finally, I worked with wagmi, rainbow-wallet and react to build an interface to interact with both contracts, in both networks.

Challenges we ran into

Sometimes CCIP failed execution, this stuck the destination contract and the complete flow. Nevertheless, it can be manually unstuck, by retrying the transaction in the chain with problems. This can lead to a bad UX in the end.

Is worth mentioning a key limitation in the number of users that can be queued in a simple transaction. This is due to CCIP payload limitation. But the number is not bad at all: 778

It was really really hard to find working faucets for AVAX fuji. Even the chainlink one has the "Log In with Twitter" feature broken in it.

It was hard to implement solidity optimizations, but after a while researching it was possible.

Accomplishments that we're proud of

I am proud of reducing the gas cost of bridging tokens. I mean, paying around 65,000 gas to bridge a token over is great news! And if participants are enough, the cost can be even less, so I am more than happy for only this.

For instance, this could allow protocols to easily bring utility to their ERC20 tokens in other chains. Like $FRG as I was inspired by.

I am also proud of the optimization process of the contract, refactoring it over and over, to make the most of it with the least gas usage possible.

And moreover, I am proud of the time management that I had, because I was able to build a prototype like this in a week: contracts, tests and frontend.

What we learned

I learned how to use CCIP to bridge tokens and message over to other chains.

I also learned how to user Chainlink Price feeds in a contract.

I learned how to optimize contracts and tips that I did not know before to save gas.

What's next for Collective Cross Chain Bridge

If CCIP opens to new tokens such as stablecoins or DeFi tokens, this project could turn into a protocol that everyone uses to bridge their tokens over. I mean, this could save millions in cumulative transaction costs.

With USDC enabled, users could bridge it across blockchains for the same cost of a Transfer. As this coin is present in most chains, users can swap it for the ERC20 token they want, in source or destination chain. This alone opens a lot of opportunities.

The architecture can also be applied to existing bridges like the Polygon PoS bridge. We just separate the token bridge (native bridge) from the data bridge (CCIP). But, this needs an economical evaluation.

Built With

+ 22 more
Share this project:

Updates

posted an update

Hello there, I've created an second iteration of the contracts where users do not have to wait for the current round to end to deposit tokens. And the contracts no longer have a blocking state. The ccipReceive method in destination chain will distribute the funds right away.

This allows users to use the bridge at anytime, but for now, only deposit once per round.

The trade-off is that the gas cost is 20% higher per-user compared to the previous solution (still low). But I haven't optimized the contract and I added events to emit.

Work is in progress at this PR:

https://github.com/mvargas33/collective-cross-chain-bridge/pull/1

Log in or sign up for Devpost to join the conversation.

posted an update

Find the gas cost per user simulations here. You can notice the more the users queues the less the overall cost:

https://drive.google.com/file/d/1czf4roocY8oZRqTM_zP5D4COwr4xPqna/view?usp=sharing

Also checkout the smart contracts developed here:

https://github.com/mvargas33/collective-cross-chain-bridge

And the frontend repo:

https://github.com/mvargas33/cccb-frontend

Both have Apache 2 license, fell free to use any of it!

Log in or sign up for Devpost to join the conversation.