Multi-chain smart contracts are fundamental to our DeFi aggregator model, allowing users to access different chains safely, without compromising speed or self-custody. In this guide, we explain how they work (with a detailed code breakdown available at the bottom)

Security is DeFi’s biggest challenge right now. Hacks are increasing and the rise of multi-chain technology is creating new pain-points, chiefly around bridges.

At, we believe the safest way to facilitate cross-chain and multi-chain transactions is by establishing liquidity outposts on different chains and making the trades on your behalf, using smart contracts that can only be triggered with your permission. 

Our Ethereum rollup, developed with our scalability partner, StarkWare, acts as a router: you transfer tokens to and from StarkEx, so you don’t have to bridge and transact  directly on other chains.

Since we find and deal with the bridging for you, there’s no need to worry about whether a new bridge you are trying is safe from hacks, or whether you might get your funds stuck. What’s more, the smart contracts where your funds are held can be updated for new chains, so we can continue adding the most interesting DeFi opportunities for you. 

This allows us to fulfil our mission as a DeFi aggregator, adding new chains seamlessly as and when the best opportunities emerge.

We built this model when we launched cross-chain swaps to Polygon, back when we were still called DeversiFi, and have continued to tweak and hone it following our rebrand as (and our transformation into a DeFi aggregator platform).

Why we decided to do this

Previously, our users could only swap tokens that were available on StarkEx, the Ethereum rollup we developed with StarkWare. If they wanted to buy a token that was only available on Polygon, Arbitrum, or Avalanche, they needed to first withdraw to that chain, and then make a swap on another exchange or aggregator.


We wanted to expand our Swap interface, so that if a token was only available on another platform, such as Polygon (via Quickswap, for example) we could allow the user to buy it directly from our UI in one click.

Our solution: A smart wallet

On each chain, we have built a smart wallet that holds native tokens. Effectively, this wallet is a cross-chain smart contract, and it acts like a bank (although without the banker in the middle, of course). It holds funds for many different users under each user’s own address.

Crucially, only the user can instruct the contract to spend their funds, and the wallet has a simple withdraw function, allowing users to withdraw their assets at any time back to their account on another chain. This ensures full self-custody.

Since the wallet was created, we’ve branched it to allow two forms of user trigger:

  1. Swap with funds that are currently on another chain.
  2. Swap with funds that are already on the destination chain.

When a user signs a request to swap, they send us the message, allowing us to trigger and pay the fees for the swapOnBehalfOfUser function. This allows to submit swaps that the user requests and make them wherever the best price exists. This could be via an exchange like Quickswap or, more likely, via an aggregator such as Paraswap.

Case 1: Funds coming from another chain

In this case, the user gives us USDT/USDC on StarkEx and we bridge this USDT/USDC to a secondary chain (for example, Polygon). On Polygon we can swap with and bridge the user’s USDT/USDC using our own collateral, then execute the swap through Paraswap. 

Funds returned by the swap (destination token) are stored in the smart wallet under the user’s address, thus achieving self-custody. This operation is atomic past the bridge.

Case 2: Funds already on the destination chain

In case 2, the user signs a message with a set of swap parameters:

  • Token to give.
  • Token to receive (has to be USDT/USDC).
  • Amount to give.
  • Amount to receive.
  • Deadline.

Since the funds are already in the contract on the correct chain, we then call SwapWithUserSignature to execute this swap through Paraswap based on the parameters above. The contract validates the signature and if it does not match, the transaction reverts. 

Ok, want a deeper dive into our code? 

No worries. Here’s a full breakdown of our cross-chain contract, and you can also check out an early example if you want more info. 

For more coding advice, just reach out to us on Reddit, Twitter or Discord and we’ll put you in touch with one of our devs. 

If you have any other questions about our evolution as a DeFi aggregator and what this means, check out the post we wrote before Christmas. In fact, our Blog and Learn sections have loads of stuff about our platform, from basic wallet connection guides to advanced stuff about our latest chains as well as our swap, yield and investment opportunities.

And of course, if you want to try out our app, then go right ahead.

Share this post

Latest Posts

Safari Bounty Quest: Explore Arbitrum and WIN $ARB

Are you ready for an exciting journey into the world of Arbitrum? To celebrate the Arbitrum Odyssey we’ve launched the Safari Bounty Quest, where you can bridge your funds to this cutting-edge Layer 2 scaling solution and win $ARB tokens.

Read Article

Base Activity Tracker

In the crypto space, early adopters tend to be rewarded for their interest in new initiatives. This phenomenon has grown so large that it has

Read Article

zkSync Bridge Bonanza

Today, releases our newest quests, available on Galxe and QuestN and allows you to claim unique NFTs and loyalty points for bridging to and from zkSync between 22.09 – 29.09.

Read Article

Earn 19% APY on your stablecoins