The integration of DeFi standards on Bitcoin has been a massive challenge to undertake. By leveraging UTXO’s determinism to its full potential we created BitWeave: Smart Contract behaviour on Bitcoin Layer 1.

This technology is the necessary building block to deploy true permissionless DeFi protocols on Bitcoin.

Orderbook DEX

Our Orderbook DEX is the first ever fully permissionless exchange made on Bitcoin L1. Starting from the whitepaper of Casey (Ordinals creator) about light pools, the DEX leverages BitWeave technology to allow a safe and cheap user experience for both parties when they swap their orders.

On FluidTokens, anyone can place a limit order, a market order or both. Each order can be a BUY or a SELL and orders can be partially filled.

1. Limit Orders

Being an orderbook, the DEX liquidity is first of all filled by limit orders. For each tokens pair, any user can set a limit order at a certain price, that will be spent when the price reaches that level. On the DEX, limit orders are soft commitments, in the sense that the user indicates which UTXOs to use for his limit order and he signs the message. A limit order is created but it's not yet a transaction that can be submitted to the Bitcoin blockchain.

If the user spends the limit orders tokens (BTC or runes) somewhere else, the limit orders become invalid and they are removed from the DEX.

All limit orders are then virtually aggregated and their order is used to fill market orders.

2. Market Orders

Market orders are executed against the best available limit orders, either partially or selecting multiple orders to fill completely the swap.

On our DEX, market orders are the limit orders partial transactions (PSBT) that are signed by the market order user. These transactions are not submitted to the Bitcoin blockchain yet, because they need the signature of the limit order user too. Therefore they are sent to the limit order user offchain.

3. Swap

To recap, both parties of a swap fill the inputs and outputs of a transaction to create the swap and they sign it to make it submittable to the blockchain.

Once both signatures are applied to the transaction, the two parties wait the confirmation from Bitcoin itself. Once confirmed, the swap has happened and the tokens are automatically transferred to the correct parties.

Risks and mitigations

As in traditional finance orderbook exchanges, the prices to buy and sell a certain token depends on supply and demand. Supply and demand are formed by the many limit orders present in the orderbook.

If the user is buying tokens, he will pay the smallest possible price specified in the supply side. If the user is selling tokens, he will pay the highest possible price specified in the demand side.

If the user is buying/selling a too big amount, several limit orders with different prices will be spent. Therefore the user needs to be careful about the incresing price he may have to spend.

Finally, parties shall know the instrinsic risks of DeFi.