Skip to main content

⚑ ThorCorn: Native BTC Bridging

Overview​

ThorCorn integrates THORChain with Corn to provide a decentralized and secure solution for bridging native BTC into the Corn network. Instead of holding assets in custody and issuing IOUs, THORChain swaps native BTC for wBTC or other synthetic BTC, ensuring users maintain ownership of their assets throughout the process. This minimizes risks while providing seamless cross-chain transfers.

Smart Contract Reference: BTC->ETH->WBTC Aggregator Implementation | BTC->WBTC Aggregator Implementation

Thorchain Logo

Architecture Notes​

The default use case of THORChain is to swap between the native assets of any two given chains (so, BTC -> ETH, for instance) with the user receiving the token on the destination chain directly in their wallet, like most bridges. However, to achieve the "one-click native BTC deposits" experience, the aggregator functionality (Zaps) of the THORChain network can be leveraged.

Aggregators are essentially Zaps that allow extra actions to occur atomically after an asset is received on a destination EVM chain. Depending on liquidity and slippage profiles, users can trade from native BTC to wBTC and into BTCN, all through THORChain via BTC -> wBTC directly or via BTC -> ETH through the network and with the ETH -> wBTC swap happening on the Ethereum side via a familiar DEX.

This process ensures high security with minimal slippage and risk, utilizing THORChain’s extensive liquidity and decentralized infrastructure. ThorCorn’s custom aggregator ensures these swaps are routed efficiently and deposited into the CornSilo.

Bridging Process: BTC -> ETH -> wBTC​

Let's examine the BTC -> ETH -> wBTC case.

In the user's initial BTC transaction, metadata for the Ethereum side is encoded using the MEMO format.

SWAP:ASSET:DESTADDR:LIM:AFFILIATE:FEE:DEXAggregatorAddr:FinalTokenAddr:MinAmountOut|

ParameterNodesConditions
:DEXAggregatorAddrThe whitelisted aggregator contractCan use the last x characters of the address to fuzz match it.
:FinalTokenAddrThe final token (must be on 1INCH Whitelist)Can be shortened.
:minAmountOutThe parameter to pass into AmountOutMin in AMM contractsHandled by the aggregator, so:
1. Can be 0 (no protection).
2. Can be in any decimals.
3. Can be in % or BasisPoints, converted at swap.

The swap is processed through the network, and the transaction to the ETH side is sent through a contract call on the Thorchain Router using the parameters of the MEMO.

function transferOutAndCall(address payable target, address finalToken, address to, uint256 amountOutMin, string memory memo) public payable nonReentrant {
uint256 _safeAmount = msg.value;
(bool success, ) = target.call{value:_safeAmount}(abi.encodeWithSignature("swapOut(address,address,uint256)", finalToken, to, amountOutMin));
if (!success) {
payable(address(to)).transfer(_safeAmount); // If can't swap, just send the recipient the ETH
}
emit TransferOutAndCall(msg.sender, target, address(0), _safeAmount, finalToken, to, amountOutMin, memo);
}

This call will enter Corn's custom Thorchain aggregator that will swap the ETH -> wBTC via a DEX and deposit the asset into the CornSilo on the user's behalf atomically.

In the event of a revert of the swap operation, the ETH will be sent directly to the user and the Bridge app will catch and help inform the user of the failure state.