Decentralized Exchange
Introduction
The Biblepay Decentralized Exchange (DEX) was created with various goals in mind: The ability to trade your BBP coins against another currency (such as DOGE), directly with other QT wallet users, without relying on a centralized exchange (CEX). The ability to add other currencies, which are compatible with the base58 wallet, into the exchange. This may allow other communities to list their coins inside BBP's DEX.
Terminology
Native Coin: The BBP built in currency, or a standard BBP Base58/WIF keypair and its value in the BBP wallet. Colored Coin: A special coin, with a Base58 address that ends in a 4 digit alphanumeric code that designates value on another network, but stored in the wallet. Note that Colored coins cannot be sent out to native addresses (therefore preventing colored coins from going to BBP address on CEXs etc) or diluting their value. Colored coins can only be sent to other like colored addresses, using an RPC command. One example of a colored address is "COLORED-DOGE", which ends in dgzz. Another is colored "COLORED-XLM" ending in lmzz. Colored coins cannot be sent from unlike colored addresses, XLM cannot be sent to DOGE or vice versa. You cannot see colored coins in coin-control; their balances can only be queried with RPC commands. The function the colored coin provides to BBP is: 1) Convert Value from a foreign network native UTXO to a BBP colored UTXO 2) Seamlessly trade the colored coins in the DEX with other users 3) Convert Colored coin value back to native value Coin Control: From the QT left menu, click Send | Inputs. This page allows you to pick specific coins that are used in a transaction. BBP Native Receive Addresses: From the QT menu, click Window | Receiving addresses. You will see a list of BBP receive addresses. TRADING-PUBLIC-KEY: This address is the only BBP native address the DEX will spend from (for security reasons). You must deposit BBP into this address in order to place trades where you Buy foreign currency. TRADING-ASSET-DOGE: Your wallet will automatically mine a colored DOGE address. This is your colored BBP DOGE address that will hold native doge. TRADING-ASSET-XLM: Your wallet will also mine a colored XLM address. This is the address that will hold native XLM. Portfolio Builder: A satellite program that allows you to earn staking rewards for holding an equal amount of native BBP + colored foreign (see Extensions). Exchange Room | Trading Grid | Flags: The Flag "T" means theirs, "M" means Mine. This way you can see your orders are M.
Usage
To demonstrate the usage of the exchange we will go through some examples in using the exchange to buy BBP (while selling DOGE) and selling BBP (to Buy DOGE).
Prerequisites: If we want to sell DOGE and buy BBP we will need to fund our TRADING-PUBLIC-KEY. In this example, we will send 100,000 BBP from our core wallet to the TRADING-PUBLIC-KEY. Click on Exchange from the left menu. Copy BBP Trading Address to clipboard (that is equivalent to your "TRADING-PUBLIC-KEY" mentioned above). Go to Send. Paste the address in the TO. Send 100,000 BBP to yourself. Now the exchange has funds to trade with.
In this demo we also want to sell some DOGE for BBP. Therefore we need to receive some Native DOGE into the BBP colored address. Click Exchange. Copy the Native DOGE address to the clipboard. Go to your favorite DOGE wallet, and send 10 DOGE to this native address. Wait 2 blocks on the DOGE network, then click the Get button (which means get balance). Once you see the coins exist in your DOGE native address, now they need to be wrapped, or converted to colored DOGE in order to be tradeable. Now click Wrap. Choose the amount (Lets go with 9.9 to ensure there are no transaction fee errors). Look for the result, it should say "Successfully Wrapped" etc. Now you will have .10 Native doge and 9.9 Colored Doge in the "TRADING-ASSET-DOGE" address; and you can see the balances adjust on the top right.
First let us place a trade to Sell BBP while buying with DOGE. Populate 10000 into the Quantity box. Populate 0.00011001 into the Price box. Click SELL. This will place an order to sell 2.70 DOGE for 10,000 BBP. The order will appear in the Sell grid. Note that if your wallet is locked you will receive an error and will have to unlock the wallet for this tx to be created.
Next let us place a trade to Buy BBP while selling DOGE. Populate 10000 into the Quantity box. Populate 0.00010999 into the Price box. Click BUY. This will place an order to buy 2.69 DOGE for 10,000 BBP. The order will appear in the Buy grid.
NOTE: You cannot trade with yourself as our atomic tx rejects wash trades with duplicate keys; however you can trade with yourself as long as you use two QT wallets with different key sets.
Once another buyer enters the market to place an opposing trade with the same quantity and an at or better price than yours, your order will fill atomically. Partial Fills If your order is bigger in size than their order, a partial fill will occur as long as the partial fill results in a leftover quantity greater than the room minimum. As of April 2025, the DOGE-BBP room minimum is .10 DOGE per trade.
Atomic Matching The matching engine is constantly scanning for trades in the orderbook, where the quantities match and the price is at or better than the limit price; when this pair is found, an atomic transaction is created with two legs in one transaction: Colored coin going from Buyer to Seller AND Native BBP coin going from Seller to Buyer AND the network minimum transaction fee (.00100) paid in Native BBP all built in the single transaction. This means that if anything goes wrong with this transaction (not enough funds on either end, tx fee deficiency, network error, chain is out of sync, chainlocks down) etc, then this transaction will FAIL atomically. This is good, because now the trading board has not changed, and neither buyer or seller is harmed. However, if the transaction goes through, both buyer and seller are satisfied atomically. Meaning that both colored balances and both native BBP balances are instantly updated with no possibility of error on either end.
Canceling a Trade
To cancel a trade, simply highlight the row with the trade you placed (yours have M) and click Cancel.
Insufficient Funds - Orders with no backing collateral
Note that we only allow orders to enter into the orderbook, if, at the time of the trade, the user has enough collateral (IE colored coin balance and BBP balance are sufficient to place the trade).
However, since we have 24 hour atomic matching while users are offline, it is possible for a user to do an offline spend of a coin that is already in the orderbook.
First this is not a problem because Atomic trades cannot occur (if coins are spent prior to the atomic tx being created), that part is prevented.
The sanctuary thread constantly looks for trades with no backing collateral.
The sanctuary will cancel these automatically causing them to disappear from the order book.
Converting your Colored DOGE back to NATIVE DOGE
To convert your coins back to Native, click Unwrap. Type in the amount of Native you want to convert back (IE 9 in our example above). Once this process finishes, you will see the Native DOGE balance increases back to the original amount (IE 9.99~). Now to send DOGE out of your wallet back to your home DOGE wallet, go to the RPC console and type: exec senddoge doge_to_address amount
Technical Specs
Risks
Future State