Off L1: Multichain Money legos in action

7 min readMar 2, 2021
  • How it started
  • Crosschain arbitrage in action
  • Under the hood
  • What does this enable?
  • Composability maximalist

How it started

This tweet triggered lots of people with over 50 comments and one of the conversations was with Peter Kim (Builder of USDC v2/Coinbase wallet) concerning the impact on gas price. The higher ETH price becomes, the less affordable it for normal people to use.

The usual response to such conversation is “L2 is soon ™️ “ but L2 still needs a bridge cost to cross from L1. When I pointed that out, Alex “What’s your ETH address? (aka Showtime)” Masmej responded that the Connext is the answer to all of this.

What is Connext? Connext is the OG of Ethereum scalability technologies called “state channels” known for integrating with Spank Chain. In my understanding, state channels are good for micropayment while all the counterparties are online so the usage was limited to the cam site or poker site (another known use-case of state channels is a poker site called Funfair).

I also remembered that the Connext team released Spacefold which allows user to send tokens across different chains without relying on bridges from L1.

It’s been a back of my “will check” list but never had time to give it a try until now.

Crosschain arbitrage in action

At that time, I was in the middle of the EthGlobal hackathon building so-called “Cross-chain arbitrage opportunity graph” to visualise the price difference between Ethereum and Matic/Polygon (I did a similar project for Ethereum and xDAI which won one of the Gitcoin hackathon prizes last year).

When I was building the one for Ethereum and Polygon version, I got the suggestion from the Polygon team that I should integrate with their bridge so that people can actually execute the arbitrage. I was a bit reluctant doing so as I knew the gas cost going back&forth the L1 bridge would eat all the profit.

Assuming the bridge cost across non-L1 chains is cheap, this shouldn’t be a problem. This is how I get started exploring Connext as a bridge solution.

When I first started, my assumption was to only use Connext to cross assets from one chain to another. What Rahul (CTO of Connext) told me is that you can not only do cross-chain transfer but you can add some sort of hocks to let Connext handle the actual swap on AMM (eg: QuickSwap on Polygon).

Here is what I came up with, 1 click cross-chain arbitrage dapp called (NOTE This is for a demo version so it will contain some bugs) .

Connext team tweeted the first demo video I created to submit for the Gitcoin Binance hackathon and got overwhelming receptions.

As another hackathon (Etherpunk) deadline was extended by one week, I kept on working and here is a bit more refined version.

In the demo, it converted 0.1 USDC to 0.102 USDT on QuickSwap on Matic/Polygon, transferred to BSC, then swapped it back from USDT to USDC at 0.102 netting 0.0002 USDC profit (1.736% return). It ain’t a lot but it’s honest work. The dapp currently works with 3 stable coins (USDC, USDT, DAI) across Matic/Polygon, Binance smart chain, and xDAI though I didn’t test every single combination.

Under the hood

(NOTE: If you are not technical you can skip this part)

The Connext documentation page describes how the state channel works in general.

In a nutshell, you put some money in multisig contract which both parties have access to. You keep giving the right for the counterpart to take a certain amount of asset by signing messages but the counterpart only withdraws when the channel is closed.

OffL1 does this in the steroid. This is my attempt at converting our app logic into the diagram. Rahul contributed most of the interaction between the state channels and contract so I had little understanding of how everything fits together.

Here is the key point of this diagram

  • Bob (the user) only clicks the Metamask popup when he sends a fund to the so-called “channel” contract on-chain ( Token.transfer()).
  • node.reconcileDeposit() moves funds to state channel (off-chain) and withdraw() moves back to on-chain (smart-contract)
  • conditionalTransfer() transfer funds by locking into Router in one chain (Polygon) then unlocking the equivalent amount on Binance smart chain with resolverTransfer()

One interesting aspect of Connext is that it allows you to specify callData when you call withdraw()(which is not even mentioned in the documentation. What a hidden gem!)

This basically allows you to instruct Connext to send the fund to an arbitrary smart contract and do some execution. In our example, it calls UniswapWithdrawHelper which does the swapping on Uniswap clones (the source is here ).

This is actually huge in terms of UX. State channels can work almost as meta transaction and keeps interacting with the smart contract until you withdraw fund back to Bob who initially put money in.

The way Connext enable cross-chain asset transfer is a bit different from other bridge solutions. In most cases (including Connext), any bridge has a vault contract in both chains. The user locks an asset in one chain and unlocks equivalent tokens on the other end. How you trust (or not trust) the locking/unlocking is where each solution differs

  • Multisig like validator model (eg: ChainBridge for Avalanche, Arbitrary Message Bridg for xDAI)
  • Have light client on both chains and does validation on chain (eg: RainbowBridge for NEAR).
  • L2 (Validity Proof for ZkRollups, Fraud Proof for Optimistic rollups)

In all the above solutions, technically there is no upper boundary of how much fund you can transfer back and forth. You can withdraw as much as you deposit. State channels, however, relies on liquidity on the intermediary (called “Router”). Currently, OffL1 uses routers provided by the Connext team and it only has 5~10 USD worth of liquidity just for the testing purpose (so no one can’t really ape in putting millions). This may be the biggest scalability limit of Connext but we have various ways to bring liquidity so there is a big design space for the team to come up with a unique liquidity mining scheme (NOTE: this is just my speculation and not an alpha leak).

What does this enable?

In case you skipped the “Under the hood” section, I will recap what Connext enabled.

  • As an end-user, you only interact with a wallet once, increasing usability.
  • You can keep moving fund back and forth between chains as well as interacting with a smart contract in a gas-less way.
  • The amount you can transfer is limited to the liquidity on the router which intermediates the asset exchange.

These are great building blocks for Dapp developers.

For example, current OffL1 completes after the money goes from Matic/Polygon to BSC but you can also extend the logic to send the money back to where it originated.

You can even split your fund into small chunks, transfer to different chains, swap, then come back.

As more Uniswap clones spawn across different chains, we will see liquidity mining war shifting from L1 to L2. This would normally fragment liquidities into small silos but Connext allows you to flexibly controls the flow of liquidity.

Composability maximalist

I am not an Ethereum nor decentralisation maximalist but I am a composability maximalist.

Would I refuse to use Stripe payment API because they are not decentralised? Do I refuse to put any fiat on-ramp solutions into my dapp? Of course not! What really excited me the most is the ultimate programmability.

This is from the first blog post I wrote about Ethereum 5 years ago. Sorry for the massive“BitCoint” typo

I am not against any other blockchain smart contract languages but what Uniswap gave us was the ultimate Defi lego house. So many people studied (there is even a Youtube video describing how to clone Uniswap and make your own Sushiswap), integrated, and cloned so that it is very easy to mashup (and the codebase is well written and documented).

Hope you are now as excited as I am. If you want to find out more, we have limited space left for the next Codeup (March 5th Friday 4~5pm) where we invite Connext and do AMM plus code walkthrough.

So far what Connext promises me sounds a bit too magical. Let’s join the call and grill the team!

Special thanks to Rosco Kalis and Rahul Sethuram for reviewing the draft