The Bazaar
An order book decentralized exchange (DEX)
Introduction
The Bazaar is a decentralized exchange (DEX) that uses an order book instead of liquidity pools to manage trades. Players can create buy and sell orders for any ERC-20 or ERC-1155 token at the price point of their choosing, which will be filled immediately when able, or placed on the order book for fulfillment later.
All items or tokens traded in the Bazaar use JEWEL as the base currency on all realms.
Orders
Orders are the center of the Bazaar contract, created using the makeOrders
function and stored on the contract while they are open. Orders can be created on the buy or sell side of the contract, and are executed when an order on the other side meets an existing order's price. Orders at the same price point are executed on a first-in-first-out basis. Completed orders are deleted from the contract, and must be viewed either as OrderExecuted
events or as BazaarTransactions
in the API.
Quantity
The Bazaar is token agnostic, and is built to work with tokens of any decimal amount. The quantity
of an order is entered and stored in wei
. For DFK's many zero-decimal tokens, a single token will be a single digit. For 18-decimal tokens, all digits must be entered.
Examples
1 Greater Might Stone:
1
123.456 DFK Gold:
123456
10.5 CRYSTAL:
10500000000000000000
Price
The price of an order is entered and stored in different ways. Since all orders are placed in JEWEL, the price per unit must be expressed in wei
(18 digits).
The makeOrders
function requires an input of totalPrice
, calculated as follows:
unitPrice (in wei) * quantity (in wei) / 10^(tokenDecimals)
Once stored on the contract and in the API, the token price (per unit, not total) is multiplied by the contract's PRICE_FACTOR
, expressed as:
unitPrice (in wei) * 10^12
Examples
1 Greater Might Stone @ 250 JEWEL
Order Input:
250000000000000000000 * 1 / 10^0 = 250000000000000000000
Held in Contract as:
250000000000000000000 * 10^12 = 250000000000000000000000000000000
123.456 DFK Gold @ 0.001 JEWEL / each
Order Input:
1000000000000000 * 123456 / 10^3 = 123456000000000000
Held in Contract as:
1000000000000000 * 10^12 = 1000000000000000000000000000
10.5 CRYSTAL @ 0.16 JEWEL / each
Order Input:
160000000000000000 * 10500000000000000000 / 10^18 = 1680000000000000000
Held in Contract as:
160000000000000000 * 10^12 = 160000000000000000000000000000
Restrictions
There are a number of restrictions on how orders can be placed:
Precision
By default, the price per unit of an order is limited to 4 digits of precision. Exceeding this limit will cause the transaction to revert.
Examples
✅ 123.4 JEWEL
✅ 0.000001234 JEWEL
✅ 1234000 JEWEL
❌ 123.04 JEWEL
❌ 1.000000001 JEWEL
❌ 123402 JEWEL
Some tokens with larger prices relative to JEWEL have a precisionOverride
set. Currently these tokens include Bitcoin and Ethereum, which are set to 6
digits of precision.
Minimum & Maximum Order Value
Each Order has a minimum and maximum limit to the total value of the order, that is, the pricePerUnit * quantity + fee
. Exceeding these limits will cause the transaction to revert.
Minimum Order Value: 0.0001 JEWEL (
100000000000000 wei
)Maximum Order Value: 50,000,000 JEWEL (
50000000000000000000000000 wei
)
Contract
Addresses
Interface
ABI
Types
Order
An open order book order stored on the blockchain in the Bazaar contract.
OrderInput
The input struct to the makeOrders
function to create one or more new Orders.
EditOrderInput
The input struct to the editOrders
function to edit one or more existing Orders.
Side
The side (buy or sell) of the order book that an Order is created or stored on.
Events
OrderAdded
Emitted whenever an Order is added to the order book by the makeOrders or editOrders functions.
OrderCancelled
Emitted whenever an Order is cancelled by the cancelOrders or editOrders functions.
OrderExecuted
Emitted whenever an Order is executed by the makeOrders or editOrders function.
State-Changing Functions
cancelOrders
Removes one or more open Orders that are owned by the msg.sender
from the order book.
Emits
OrderCancelled
editOrders
Given one or more EditOrderInput
structs, cancels each Order and creates a new Order with the same token
and other parameters, but with a new totalPrice
and/or quantity
.
Editing a
buy
order on DFK Chain must submit the appropriatetotalPrice
+fee
asvalue
with the transaction.Editing a
sell
order must have already approved the appropriatequantity
oftoken
to the Bazaar contract.Emits
OrderAdded
,OrderCancelled
,OrderExecuted
makeOrders
Given one or more OrderInput
structs, creates an Order for each and executes on it when possible.
A
buy
order on DFK Chain must submit the appropriatetotalPrice
+fee
asvalue
with the transaction.A
sell
order must have already approved the appropriatequantity
oftoken
to the Bazaar contract.Emits
OrderAdded
,OrderExecuted
Related Pages
Last updated