DEX Whitepaper ENGLISH - v2
DEX Whitepaper ENGLISH - v2
DEX Whitepaper ENGLISH - v2
Table of Contents
Abstract 3
About SwapreX 3
Decentralized Exchanges 4
Onchain Orderbook 5
xDai Chain 6
DEX aggregator 8
Architecture 9
Design 10
Colors scheme 10
Home Page 11
Market Buy 17
Limit Buy 19
Market Sell 22
Limit Sell 24
Roadmap 31
Future 31
About SwapreX
We Bring together Investors & Developers
Using SwapreX platform anyone can easily create ERC-20 token in few Clicks,
no coding skill required. Users can create Token easily using Metamask for a
small fee.
SwapreX platform supports ERC-20, but soon we will add support to all popular
Chain like Binance Chain, Tronchain, etc, Which means you can raise fund
using this chain tokens as well.
The global crowdfunding market size was $84 billion as of 2018 and is
expected to reach $114 billion by 2021.
We will become the First DEFI Platform who will help projects in raising funds
without any 3rd party involvement.
SwapreX features
• A DeFi project to allow anyone to create an ICO to sell new tokens and
collect funds.
• The site will have the list of all running ICOs at the time.
• Contributors will be able to contribute using the website interacting with
a wallet or sending contributions directly to the ICO Ethereum address.
• Contributions can be sent in Ether or in any ERC-20 token, like DAI,
Wrapped BTC, USDC, etc.
• ICO Pool: SwapreX system allow investors to evaluate different ICO at
once with a community drive star ratings system, which give reviews
from investors to investors. Also the ICOs are categorized for easy
navigation.
• Payments: this option let content creators and business receive
donations and payments with any ERC-20 token or Ether. This is an
easily, fast, and secure way to get collect money.
• Token creation: All users can create ERC-20 Standard Tokens with the
platform, without the need of coding, no tech-skills required.
Decentralized Exchanges
Decentralized exchanges were proposed by Vitalik Buterin 4 years ago. The
price movement in traditional exchanges happens when the seller price meets
the buyer price in an order book; buying pressure pushes the price high, and
vice versa.
Order books are all about trading, like in stocks or cryptocurrencies. The
market change based on orders:
This tension between buy and sell order are the ones that determine the
market’s price.
xDAI chain
Ethereum gas fees has been rocketing since the price of Ethereum and the
hype about cryptocurrencies has increased.
One of these L2 solutions that has been growing fast is xDAI chain.
The xDai chain is an EVM sidechain that uses a different consensus model
(POSDAO) than Ethereum. The underlying architecture, however, mirrors
Ethereum 1.0, meaning that smart contracts can be written and deployed in
exactly the same way using a different RPC endpoint.
Any contract that works on the Ethereum mainnet can be easily redeployed to
the xDai chain. On the xDai chain, transaction costs are minimized, and all fees
and transactions are paid with a single token, xDai. 2
DEX aggregator
Swaprex DEX will have DEX aggregator features, that works out the best
crypto prices across decentralized exchanges.
The Smart Contract automatically willl be monitoring other DEX markets like:
Uniswap, Balancer, Bancor, Mooniswap, etc. Which means that the Smart
Contract will search a handful of decentralized exchanges for the cheapest
prices and reroutes its customers’ trades between them to try and ensure that
they're getting the best prices.
In conclusion, you make your orders and they will be automagically filled in a
secure way while you sleep using the best method adapted to your order, and
the market conditions.
Architecture
Colors scheme
Connect to Metamask
● Logo: link a dex.swaprex.com
● Connect to Metamask:
●
○ If the selected network in the system is Ethereum:
■ If you are logged into Metamask:
● If you are with the Ethereum mainnet network:
○ Show the user's account:
■ 0x1234 ... 7890
● If you are not with the Ethereum mainnet network
○ Show message:
■ Please switch to Ethereum
mainnet
■ If you are not logged in to Metamask:
● Show the link: Connect to Metamask
○ If the network selected in the system is xDai:
■ If you are logged in to Metamask:
● If you are connected to xDai
○ Show the user's account:
■ 0x1234 ... 7890
● If not connected to xDai
○ Show message:
■ Please switch to xDai
○ Show link:
■ Click here to learn how to connect
to xDai
■ (link to be defined)
■ If you are not logged into Metamask:
● Show link: Connect to Metamask
Network
● Ethereum: if Ethereum is selected, the Ethereum smart contract and the
Ethereum network will be used to interact with the system
● xDai: if xDai is selected, the xDai smart contract and the network of
xDai to interact with the system
Top menu
● The home page is the “Trading” option section, underline the selected
section in red
● Analytics is another page to build, different from the home page
● Signup and Login will raise a modal window to register and log into the
API. This user will be used to mark the currencies as favorites,
Sub nav
Market
Shows the selected market (currency pairs / tokens).
The pair:
WBTC / USDT: it means how many USDT should I spend to buy a WBTC
WETH / DAI: how many DAI should I spend to buy a WETH
When the market changes, the entire interface is changed to show the charts,
operations, etc. of that coin.
Example: if WBTC / DAI is selected, the market and WBTC operations against
DAI are displayed, when changing to WETH / USDT everything changes to that
pair.
The information of the available pairs comes from the system API.
The administrator user can add or delete new currency pairs (tokens ERC20)
API call:
/ pairs / user_id
Returns all pairs with your basic data if you miss the id of the user returns all
your favorite pairs:
{
"WBTC ": {
" Contract ":" 0x123 ... ",
" name ":" Wrapped Bitcoin ",
" symbol ":" WBTC ",
call Contract:
priceToken (address token_address, address [] country)
Returns the prices of that token at the moment, for example the prices of
WBTC:
[
33000000000 , <---- 33000.000000 USDT to buy 1 WBTC
330106408568574, <---- 33010.640856 DAI to buy 1 WBTC
23573380013301064085, <---- 23.57 WETH to buy 1 WBTC
]
In this case, when selecting this checkbox, only the currencies selected by the
user will be shown in the dropdown.
If the user is not logged in, clicking on "Only favorites" should raise the "Login"
window.
If the user is logged in but does not have currencies selected as favorites,
show the message: "You have not selected any Favorite coin yet" and leave
the checkbox unmarked.
Balance
The dropdown will show the entire list of currencies in which the user has funds
greater than zero.
The user can select any currency regardless of the pair selected in Market.
Call to Contract:
balances (from: user_account, address [] tokens)
Returns:
[
100000000000000, <--- 10000 XDAI
345674637, <--- 3.45674637 WBTC
]
The interface must show the balance considering the decimal places.
Example:
To:
“balance”: 345674637,
“decimals”: 8
3.467464 WBTC
In Ethereum this is the same as what was done in Donations, it is to call the
transfer function in the ERC20 contract to transfer those tokens to the DEX
contract.
Withdraw
This option allows the user to withdraw their funds.
The idea is to create a popup, similar in design to Login, which has the
following options:
If the user wants to withdraw 1 WBTC and the WBTC has 8 decimal places, he
must go to the function the amount as:
Amount: 100000000
● The user (msg.sender) does not have enough funds in that token
● The user cannot withdraw funds if they are pending on sell orders.
Therefore, if the user (msg.sender) has enough funds, but the funds
minus the open sell orders of that token is less than the amount to be
withdrawn, it must fail.
Security notes:
● For the user's address it must always be used: msg.sender do not use
any parameter
● This method must be nonReentrant
.
24 hr Stats
Statistics of the last 24 hours:
Example:
stats24hr (“0x123 ...”, “0x345 ...”)
^ WBTC ^ USDT
Returns:
{
“last_price”: 33000000000,
^ - If the USDT has 6 decimal places the last price is 33000
USDT
“yesterday_price”: 29098536758,
^ - This is used to calculate the change in the last 24 hr
Formula:
“high”: 34869068445,
^ - Yes USDT has 6 decimals the maximum is 34869 USDTs
Orders
Allows users with funds in their wallets to buy or sell
tokens.
Market Buy
It is a purchase at the market price. If the pair is WBTC /
USDT it means that the user wants to buy WBTC paying
with USDT.
Amount
It is the total that you want to buy.
Assuming that WBTC is 8 decimal places, the amount Maximum WBTC to buy
is:
int (99000000000/33000000000 * 10 ** 8) = 300000000 = 3 WBTC
100% is 3 WBTC
Both the fee, the swaprex profit and the estimated total are obtained with the
contract function:
Example:
{
"fee": 990000, <--- 0.0099 WBTC (8 decimal places)
"rewards": 9900000000000000000000, <--- 9900 SwapreX (18 decimal
places)
"total": 99000000000, <--- 99000 USDT (6 decimal places)
}
Ideally all the values in the box should be refreshed every so often. (every
minute maybe?)
Buy button
The function is called:
If there are several sell orders of this pair, the sell orders with the lowest price
that match the buy order will be executed first .
If the buyer wants to buy at market price, the lowest possible price orders are
executed.
Then 2 WBTC are sold to the buyer at 32980 and 1 WBTC to 32900, on
average the buyer pays 32987 USDT per WBTC.
Order Book:
User Sell amount Sell price Buy amount
D 3 WBTC
User D buys 3 WBTC from A and B in total. After this the Order Book remains:
Limit Buy
Limit Buy is the purchase at a price set by the user.
Price
It is the limit price that the buyer is willing to pay for the
currency to buy.
Amount
It is the total that you want to buy. The percentage are
buttons for the system to automatically calculate the amount
to buy according to the amount of funds.
For example, if the user wants to buy WBTC, maximum at 32985 USDT and
the user has 98955 USDT in his portfolio then when pressing 100% the total
will appear in 3 WBTC, if he presses 50% it will appear 1.5 WBTC, etc.
In this case the price is not needed from the market, since the user is setting
the price at which he wants to buy.
AND the user wants to buy at 32985 USDT, we transform the price given by
the user to 6 decimal places: 32985000000
Both the fee, the swaprex profit and the estimated total are obtained with the
contract function:
Example:
Buy button
The function is called:
This order is executed when there are sell orders of the same minor pair or
equal to the purchase price. In other words, the buyer sets the maximum
purchase price, but it can be executed for a lower price.
In the same example above, suppose the user wants to buy 3 WBTCs at a
maximum of 32985 USDT each. As there are four sell orders of 2 WBTC each,
the first one selling at 32990 USDT / WBTC and the second 32980 USDT /
WBTC, then 2 WBTC is sold to the buyer at 32980 and the order is pending for
1 remaining WBTC.
Order Book
User Sell amount Sell price Buy amount Buy Limit
C 3 WBTC 32985
User C buys from A 2 WBTC at 32980 and the order of 1 WBTC is pending at a
maximum of 31985 USDT. Remaining the order book with:
Order Book
User Sell amount Sell price Buy amount Buy Limit
C 1 WBTC 32985
Amount
It is the total that you want to sell.
100%: user_balance
50%: user_balance / 2
25%: user_balance / 4
Assuming the user has 2 WBTC, which is 8 decimal places, the maximum
amount of WBTC to sell is:
Both the fee, the swaprex profit and the estimated total are obtained with the
contract function:
Example:
Ideally, all values in the box should be refreshed every so often. (every minute
maybe?)
Sell button
The function is called:
If there are several buy orders of this pair, the buy orders with the highest price
that match the buy order will be executed first .
If the seller wants to sell at market price, the highest possible price orders are
executed.
Then 1 WBTC is sold at 33500 and 1 WBTC at 33400, on average the seller
charges 33450 USDT for WBTC.
Order Book:
User Sell amount Buy amount Buy price
A 1 33500 USDT
B 1 33400 USDT
C 1 33200 USDT
D 2 WBTC
C 1 33200 USDT
Limit Sell
In a sell order at the price set by the user.
Price
It is the minimum price that the seller is willing to sell the
currency he owns.
Amount
It is the total that you want to sell.
100%: user_balance
50%: user_balance / 2
25%: user_balance / 4
Assuming that the user has 2 WBTC, which is 8 decimal places, the maximum
amount of WBTC to sell is:
200000000 = 2 WBTC
100% is 2 WBTC
Both the fee, the swaprex profit and the estimated total are obtained with the
contract function:
Example:
If there are several buy orders for this pair, the orders will be executed first with
the highest price that match the purchase order.
Then 0.3 WBTC is sold at 33600, 1 WBTC at 33500 and 0.7 remains pending
WBTC to sell at 33,500 USDT.
Order Book:
User Sell amount Sell price Buy amount Buy price
B 1 33500 USDT
C 1 33400 USDT
D 2 WBTC 33500
C 1 33400 USDT
Returns:
[
{
type: sell,
price: 32000000000, <- red because it dropped
from
previous
timestamp: 1612980073
},
{
type: sell,
Example real data:
price: 34000000000, <- green because it went up
compared to previous
timestamp: 1612980072
},
{
type: sell,
price: 33000000000, <- red because neither it went
up or down and the previous one is red
timestamp: 1612980071
},
{
type: sell,
price: 33000000000, <- red because it went down
compared to the previous
timestamp: 1612980070
},
....
{
type: sell,
price: 34000000000, <- the number 11 is the last one, it is not shown but it is
used as a
reference to show the color of the 10
timestamp: 1612980069
}
]
Example:
Returns:
{
sell: [
Example real data:
{
price: 3500000000000, <- 35000 USDT
amount : 3400000000, <- 34 WBTC
time: 1612997677, <- timestamp
This is: 34 WBTC were sold at
35000 USDT at 4:55 pm8
on February
},
{
price: 3400000000000, <- 34000 USDT
amount: 1500000000, <- 15 WBTC
time: 1612997676, <- timestamp
}
...
],
}
Future
● Become a DEX Aggregator. Filling Order from all other dexes in Mainnet:
○ 1Inch
○ Uniswap
○ Sushiswap
○ Balancer
○ Bancor
○ AMong others
● Integration with other Blockchains:
○ Filling order from all other DEXes using xDai
○ Filling order from all other dexes using binance chain