Comment on page
How THORChain supports cross-chain aggregation.
THORChain will only support a set number of assets and is not designed to support log tailed assets. If a user wants to swap from a long tail ERC20 asset to Bitcoin, they have to use an Ethereum AMM like Sushi Swap to swap the ERC20 asset to ETH then they can swap the ETH to BTC.
The same process applies for long tail tokens on other chains such as Avalance and Cosmos.
Aggregator is the ability for a user swap long tail assets via leveraging a supported on-chain AMMs and THORChain in one transaction.
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.
ETH swap contracts such as Sushi Swap to convert to/from THORChain support L1 tokens such as BTC. Example, in one transaction:
- 1.User swaps long-tail ERC20 to ETH in SushiSwap, then swaps that ETH to BTC.
- 2.User swaps BTC into ETH, then swaps that ETH into long-tail ERC20
There can be multiple
aggregators. The first
thorchain aggregatorwill 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.
Destination addresses should only be user-controlled addresses, not smart contract addresses.
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.
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, limitare 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
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.
For SwapIn The caller must first execute a
MsgExecuteContract, then call a
MsgSendinto THORChain vaults with the correct memo.
For SwapOut THORChain will execute a
MsgExecuteContractwhich then sends the final asset to the user. If failed, THORChain will execute the fallback and send the member the base asset instead.
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.