xChain Contract Calls (BETA)
LI.FI xChain Contract Calls
One of the most requested features by the projects we talk to at LI.FI is cross-chain contract calls, to execute another transaction after bridging the tokens. We believe it’s a game changer as it allows much more composability across chains. So, now, FINALLY! It’s here! The cross-chain contract calls, and we’re calling them xChain Contract Calls!
This functionality is currently in BETA. While we've worked hard to ensure its stability and functionality, there might still be some rough edges.
One of the limitations of a multi-chain future is the siloed nature of blockchains and transactions. LI.FI can batch as many transactions as a block allows inside a particular chain, but it wasn’t possible to batch transactions across two different blockchains until now.
In a normal any-to-any cross-chain swap, to swap AAVE on Polygon to OP on Optimism, we have to swap AAVE to USDC on Polygon, bridge USDC across to Optimism, and swap USDC to OP on Optimism.
In a normal any2any cross-chain swap, converting AAVE on Polygon to OP on Optimism requires the following steps:
- 1.Swap AAVE to USDC on Polygon
- 2.Bridge USDC to Optimism
- 3.Swap USDC for OP
You can’t sign the DEX swap transaction on Optimism from Polygon, so you usually have to switch the RPC and sign another transaction. But with LI.FI, you could do all three things in a single transaction on Polygon!
How? We achieved this by passing the destination swap contract call data through a bridge to execute the final swap for the user and then sending the swapped tokens to the user. Initially, we achieved this through Connext. Now Stargate also supports the destination swap feature, with many more bridges coming soon.
We’ve extended that destination swap feature to support contract calls of any kind to be passed through bridges to be executed on the destination chain. It’s now possible to perform any action on the destination chain after bridging, along with swapping.
When you request a route from LI.FI SDK for a cross-chain swap, you can pass the contract call data through the SDK as an extra parameter. If this data is passed, only the bridges that support cross-chain contract calls will be used for bridging. The bridges that support this right now include:
- 1.Connext (
amarok) - In prod
- 2.Stargate - In prod
- 3.CelerIM - In prod
- 4.deBridge - Yet to integrate
With these bridges, we could bridge and do contract calls on almost all chains we support.
Once we pass this data onto the bridges, the bridges make the contract calls on the destination chain. Also, the bridges will pay the gas fee for these transactions by taking a cut in the original token bridged. For example, Connext has a relayer fee that helps relayers pay the gas fee.
xChain Contract Calls have introduced the possibility of transaction batching. This concept is pivotal in abstracting the various opportunities users have in web3. Here’s how transaction batching will benefit all users:
Deposit directly in a pool from any asset on any chain.
One of the biggest use cases in DeFi right now is depositing your funds into a pool to earn. Thousands of people deposit into pools every day. But depositing into a pool on an L2/alt L1 chain is the hurdle here. You must bridge your funds to the chain and deposit them into the pool.
As a project on an L2 chain, you already have to work hard to get users onto your dApp from Twitter/Discord. And, even after getting someone onto the platform, the user might still have to figure out how to bridge to the chain or ask the server for the best routes — making the user journey far from ideal.
Imagine if the user could just choose their token on their chain and just click Deposit and enter your pool in 3 clicks. In the backend, LIFI searches for the best route among a large array of possibilities, and once chosen, funds will be inside the pool in a matter of minutes.
And that’s why xChain Calls are a game changer.
Derivatives trading is becoming a major use case in the L2/alt L1 chains because of their cheap gas fees, security, and fast/instant confirmation on alt L1s/Optimistic Rollups. Many full-time traders don’t have time to research bridges to deposit USDC/ETH to start trading. Traders only care about locking in their positions as quickly as possible. If trading on decentralized platforms is harder than entering your credit card and trading, what are we even offering here?
With xChain Deposits, the user can select any asset on any chain and deposit USDC/ETH into the trading contract in a single transaction.
NFTs have onboarded millions of users to Web3, and most users that enter the space through NFTs are not very DeFi savvy. Asking them to figure out bridges and DEXs before they can buy an NFT on L2 chains is a tough user journey, and they wouldn’t want to wait or get stuck while buying NFTs.
With xChain Contract Calls, a user can select any token on any chain as a mode of payment and buy the NFT in a single transaction. This is the web3 user experience that can trump any Web2 user experience.
You get the pattern.
You can currently try this out here. We are working with a few projects to pilot this feature, and we’ll update this page as those integrations go.