Introducing NativeSwap

TL;DR

We have the goods to perform a one-click swap from one native token to another native token across several different blockchains.

The long part

Introducing NativeSwap, a testnet example that allows users to swap ETH and MATIC (bidirectionally) using Wormhole’s generic messaging layer and existing Dex liquidity. We have plans to add Terra, Solana, BSC, and Avax very soon 😍.

NativeSwap demonstrates the power of Wormhole’s new message payload. This new type of message allows a developer to encode more information beyond the normal token bridge transfer (in our case: swap parameters to be used at a Dex on another chain).

But ser, who cares?

Users who want to hop from chain to chain to take advantage of opportunities in other ecosystems either:

  1. Have to transfer assets to a centralized exchange so that they can transfer other assets back out (yuck), or
  2. Use a decentralized bridging protocol like Wormhole.

There are a couple problems with the way users bridge assets currently.

  1. A user needs to have funds on their destination wallet to redeem their tokens.
  2. A user bridges a token from one chain to another, but doesn’t know how to put that bridged asset to use in another ecosystem.

For example, if a user bridged ETH from Ethereum to Polygon, one might expect they can put that ETH to use. Unfortunately, you can’t use this ETH to pay for transactions. And even if you did have MATIC in your wallet, it’s your job to figure out how to swap that ETH to something useful in the Polygon ecosystem. Ain’t nobody got time for that.

Devs do something

No one wants to feel rugged when they bridge assets over. We can point you to liquidity pools in every ecosystem we are connected to, but that requires you to read through our documentation. This isn’t exactly user friendly.

So what did we do? We wrote how a protocol can use Wormhole’s messaging to set up a swap between two arbitrary AMM pools.

NativeSwap

This is all we want, right? I have ETH on Ethereum and I want MATIC on Polygon to post collateral on Aave and farm for some WMATIC. Or maybe I want to go the other way around and buy a mutant ape. With one click, your tokens on one chain become tokens on another chain based on the relative prices of each between two AMM pools on two different chains.

Are we wizards?

No, we’re developers. And we have written smart contracts demonstrating how to perform this cross-chain swap. Using existing pools and DEX APIs to generate quotes for various swaps on these pools, we compute the parameters to perform your desired swap for the quantities you see in the front-end.

The pools we use are all paired with a common denominator. We chose UST as the asset to pair with wrapped native tokens (which we dub the UST highway). UST originates from one source (Terra), so there is no confusion as to which UST you have when you send it around with Wormhole token transfers (via Portal or programmatically via smart contracts). We even quote the UST amount for the intermediate step before you get your other native asset in our example.

Two chains, one click

In order to facilitate the complete swap from one chain to another, we implemented a simple relayer that would execute your smart contract on the destination chain to perform the final swap from UST to your desired native token.

Without getting into too many technical details, this relayer would be run off-chain listening to Wormhole messages, seeking out those that originate from NativeSwap with this new payload. When it finds one, it will call the smart contract with the Wormhole message as its only argument. The smart contract does all the work in decoding and doing the remaining swap.

But ser, what now?

The world is your oyster! You are not limited to native-to-native multi-chain swaps. Build in your own smart routing with whichever DEX to perform any swap from chain A to chain B. Wormhole messaging and token transfers with payload are generic enough to adapt this example for any of the chains Wormhole currently supports.

And have fun with the demo.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Wormhole

Wormhole

Cross-chain interoperability protocol connecting high value blockchains