How THORChain supports cross-chain aggregation. This section is a work in progress.


To support cross-chain aggregation, THORChain whitelists aggregator contracts that can call into THORChain (Swap In), or receive calls (Swap Out). Chains that do not have on-chain AMMs (like Bitcoin) cannot support SwapIn, but they can support SwapOut, since they can pass a memo to THORChain.
Example, in one transaction:
  1. 1.
    User swaps long-tail ERC20 to ETH in SushiSwap, then swaps that ETH to BTC.
  2. 2.
    User swaps BTC into ETH, then swaps that ETH into long-tail ERC20
There can be multiple aggregators. The first thorchain aggregator will use Sushiswap only and use ETH as the base asset. Aggregators need to follow a spec for compatibility with THORChain. Any THORChain ecosystem project can launch their own aggregator and get it whitelisted into THORChain. They can add custom/exotic routing logic if they wish.


The SwapIn is called by the User, which then passes a memo to THORChain to do the final swap.
User -> Call Into Aggregator -> Swap Via AMM -> Deposit into THORChain -> Swap to Base Asset
Eg: Swap long tail ERC20 via Sushiswap into BTC on THORChain.


The SwapOut is called by the User invoking the aggregator memo on THORChain. See Memos.
The User needs to pass the aggregator contract address in the memo. THORChain will perform the swap to the preferred Base Asset for that chain. The rest of the parameters, being to, asset, limit are what is passed by THORChain in the SwapOut call for further execution.
User -> Deposit into THORChain -> Swap to Base Asset -> Call into Aggregator -> Swap Via AMM
Eg: Swap from BTC on THORChain to long tail CW20 via TerraSwap.


A user can combine the two. Swapping In first, then passing an Aggregator Memo to THORChain. This will cause THORChain to perform a SwapOut.
User -> Swap In -> THORChain -> Swap Out
Eg: Swap long tail ERC20 via Sushiswap into ETH on THORChain to LUNA then long tail CW20 via TerraSwap.

EVM Implementation

CosmWasm Implementation

For SwapIn The caller must first execute a MsgExecuteContract, then call a MsgSend into THORChain vaults with the correct memo.
For SwapOut THORChain will execute a MsgExecuteContract which then sends the final asset to the user. If failed, THORChain will execute the fallback and send the member the base asset instead.

Deploying An Aggregator

If you would like to deploy your own aggregator with your own custom logic, deploy it with the principles above, then submit a PR for it to get whitelisted on THORChain.
[ADD] Whitelist aggregator contracts on testnet (!2132) · Merge requests · THORChain / THORNode
Copy link
EVM Implementation
CosmWasm Implementation
Deploying An Aggregator