/ doc / src / arch / dex.md
dex.md
 1  # DEX
 2  
 3  With cross-chain bridging and darkpool DEX then DarkFi would be a very
 4  attractive trading tool.
 5  
 6  We currently have OTC swaps which are an efficient way to settle trades
 7  on-chain. But there needs to be an orderbook for matching
 8  counterparties.
 9  
10  We propose that this job can be performed by an order-matching bot
11  which maintains an orderbook. Later this role can be split with MPC.
12  
13  The order-matching party needs to be able to construct the swap trade,
14  even when the LP is offline.
15  
16  We propose to do this using the spend hook and a special `auth_otc`
17  function. The `auth_otc` basically says:
18  
19  * The sender of the funds has the right at any time to withdraw
20    liquidity and cancel the LP.
21  * The funds are delegated to the order-matching party but with
22    restrictions:
23      * Can only make an OTC swap tx using the funds.
24      * The trade parameters are completely specified such as the price
25        and currencies.
26  
27  The funds are therefore delegated to the order-matching party, who
28  finds counterparty offers and executes the trades settling them
29  on-chain. Both parties receive their funds in a trustless anonymous
30  manner. At any time the LP can be canceled and funds withdrawn.