The Bazaar
An order book decentralized exchange (DEX)
Last updated
An order book decentralized exchange (DEX)
Last updated
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 as the base currency on all realms.
are the center of the Bazaar contract, created using the function and stored on the contract while they are open. Orders can be created on the buy or sell 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 events or as in the API.
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.
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 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
There are a number of restrictions on how orders can be placed:
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.
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.
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
)
DFK Chain
0x902F2b740bC158e16170d57528405d7f2a793Ca2
0x767A9114B61fb14732Cfca1ccA2d9FD309c74E93
Metis
0x4cB622C886c89c0472C0056A7C4c929c98c35D14
0xa678d193fEcC677e137a00FEFb43a9ccffA53210
An open order book order stored on the blockchain in the Bazaar contract.
orderId
uint256
The unique ID of the Order
token
address
The contract address of the transacted token
tokenId
uint256
The id
of an ERC-1155 token, or 0
for an ERC-20 token
isERC20
bool
Whether the token is an ERC-20 (true
), as opposed to ERC-1155 (false
)
side
The side of the order - 0
for buy; 1
for sell
owner
address
The 0x
address of the wallet that created the order
price
uint256
The price per unit of the token
stored as unitPrice (in wei) * 10^12
quantity
uint256
The quantity of token
to be transacted, expressed in wei
feePercent
uint256
The fee percent paid/to be paid by the order owner
, expressed as decimalPercent * 10000
(e.g. 1500
for 1.5%, 1400
for 1.4%, and 1000
for 1%)
token
address
The contract address of the transacted token
tokenId
uint256
The id
of an ERC-1155 token, or 0
for an ERC-20 token
side
The side of the order - 0
for buy; 1
for sell
totalPrice
uint256
The total price of the order expressed as unitPrice (in wei) * quantity (in wei) / 10^(tokenDecimals)
quantity
uint256
The quantity of token
to be transacted, expressed in wei
addUnfilledOrderToOrderbook
bool
Whether any unfilled portion of the order should be placed on the order book (true
) or not (false
)
isERC20
bool
Whether the token is an ERC-20 (true
), as opposed to ERC-1155 (false
)
orderId
uint256
newTotalPrice
uint256
The new total price of the order expressed as unitPrice (in wei) * quantity (in wei) / 10^(tokenDecimals)
newQuantity
uint256
The new quantity of token
to be transacted, expressed in wei
BUY
0
The buy
side of the order book
SELL
1
The sell
side of the order book
orderId
uint256
token
address
The contract address of the transacted token
baseToken
address
The contract address of the base token (JEWEL)
tokenId
uint256
The id
of an ERC-1155 token, or 0
for an ERC-20 token
isERC20
bool
Whether the token is an ERC-20 (true
), as opposed to ERC-1155 (false
)
side
uint8
sender
address
The 0x
address of the wallet creating the order
price
uint256
The price per unit of the token
expressed as unitPrice (in wei) * 10^12
quantity
uint256
The quantity of token
being transacted, expressed in wei
orderId
uint256
order
orderId
uint256
initiator
address
The 0x
address of the wallet initiating the order execution
quantity
uint256
The quantity of token
being transacted, expressed in wei
remainingQuantity
uint256
The remaining quantity of the token
left in the order, expressed in wei
price
uint256
The price per unit of the token
expressed as unitPrice (in wei) * 10^12
Editing a buy
order on DFK Chain must submit the appropriate totalPrice
+ fee
as value
with the transaction.
Editing a sell
order must have already approved the appropriate quantity
of token
to the Bazaar contract.
A buy
order on DFK Chain must submit the appropriate totalPrice
+ fee
as value
with the transaction.
A sell
order must have already approved the appropriate quantity
of token
to the Bazaar contract.
The input struct to the makeOrders
function to create one or more new .
The input struct to the editOrders
function to edit one or more existing .
The orderId
of the to be edited
The side (buy or sell) of the order book that an is created or stored on.
Emitted whenever an is added to the order book by the or functions.
The unique ID of the
The of the order - 0
for buy; 1
for sell
Emitted whenever an is cancelled by the or functions.
The unique ID of the
The full struct
Emitted whenever an is executed by the or function.
The unique ID of the
Removes one or more open that are owned by the msg.sender
from the order book.
Emits
Given one or more structs, cancels each and creates a new Order with the same token
and other parameters, but with a new totalPrice
and/or quantity
.
Emits , ,
Given one or more structs, creates an for each and executes on it when possible.
Emits ,