The ThorSwap bridge facet works by forwarding calls to the Thorchain router contract on the source chain. Quotes are obtained using the ThorSwap API.
THORSwap is a multi-chain DEX aggregator built on THORChain's cross-chain liquidity protocol and the #1 interface for all THORChain services such as Savers, liquidity providing, THORNames, Synthetic Assets & THORSafe multisig wallets. In our belief that the future is multi-chain, THORSwap developed a secure solution to remove technical barriers for trading any assets across chains, without relying on wrapped assets or bridges.
graph LR;
D{LiFiDiamond}-- DELEGATECALL -->C(ThorSwapFacet);
C(ThorSwapFacet) -- CALL --> D(ThorchainRouter)
function startBridgeTokensViaThorSwap(BridgeData memory _bridgeData, ThorSwapData calldata _thorSwapData)
- Simply bridges tokens using ThorSwapFacet
function swapAndStartBridgeTokensViaThorSwap(BridgeData memory _bridgeData, SwapData[] calldata _swapData, ThorSwapData calldata _thorSwapData)
- Performs swap(s) before bridging tokens using bridgeFacet
Some of the methods listed above take a variable labeled _thorSwapData
.
This data is specific to ThorSwap and is represented as the following struct type:
/// @notice The struct for the ThorSwap data.
/// @param vault The Thorchain vault address
/// @param memo The memo to send to Thorchain for the swap
/// @param expiration The expiration time for the swap
struct ThorSwapData {
address vault;
string memo;
uint256 expiration;
}
Some methods accept a SwapData _swapData
parameter.
Swapping is performed by a swap specific library that expects an array of calldata to can be run on various DEXs (i.e. Uniswap) to make one or multiple swaps before performing another action.
The swap library can be found here.
Most of the methods accept a BridgeData _bridgeData
parameter.
In the ThorSwap contract call the fields minAmount
and sendingAssetId
are used for the transfer amount and the asset to be sent. Since the ThorSwap bridge does not support native token bridging (it's mainly a stablecoin bridge) the methods will fail if native assets are tried to be bridged.
It's also used to emit events that we can later track and index in our subgraphs and provide data on how our contracts are being used. BridgeData
and the events we can emit can be found here.
In the following some sample calls are shown that allow you to retrieve a populated transaction that can be sent to our contract