How you calculate the price RSK Swap

How you calculate the price RSK Swap

RSK Swap is a decentralized exchange that allows ERC20 tokens exchange automatically. There is no need to wait for a buyer or a seller. It has the advantage of the low costs and security of the RSK network. It also does not require KYC and has no limits for withdrawals or deposits.

This post will try to explain the mechanics used by RSK Swap to calculate the price, if you want to learn how to exchange tokens you can see this post RSK Swap is based on the Uniswap v2 protocol, which uses a smart contract for each pair of tokens that you want to exchange, we will call this the Liquidity Pool. Someone adds both tokens to the smart contract providing liquidity, these people are called Liquidity Providers, and they obtain profits from the 0.3% interest that the protocol charges when a swap is made in this pair.

The pricing mechanism is called the “Constant Product Market Maker Model”. Instead of specifying the buy and sell price, users simply choose an entry and exit token and the DEX calculates the market rate at that time. RSK Swap can provide liquidity for most tokens at all times as the price of a particular token would rise and fall as demand rises and falls.

RSK Swap Logic

The idea is as follows: we have a pool with two types of tokens that can be swapped. Each pool is made up of two tokens (RBTC-DOC) for example, and there will be a different pool for each pair that can be swapped. When a person wants to swap 1 RBTC, for its value in DOC, the price at which the DOC will be acquired, will depend on the situation of the pool. The more RBTC you want to swap, the more expensive the swap will be.

The math that governs this calculation is the formula for the constant product x * y = k. When a token is deposited (sold), a proportional amount must be withdrawn to keep it constant. On the contrary, if a token is withdrawn (bought), a proportional amount must also be deposited.

Suppose a person wants to change 1 DOC and receive RIF in return. The swap price is directly related to the liquidity of the pool, and the total number of tokens to be exchanged, since the more pressure is put on the pool, the more expensive the exchange will be. This makes it possible to discourage swaps when there is little liquidity in the pool, and to encourage swaps when the opposite is the case.

Before the swap request, the pool has the following situation: it consists of 10 DOCs and 500 RIFs. From there, the “invariant” is calculated, a number that cannot vary and is calculated by multiplying the amount of DOC * by the amount of RIF.

When requesting the swap, the pool starts to have more DOC than it had before (11), so the Smart Contract must execute a calculation to know how much RIF is left in the pool to be able to maintain the invariant at 5,000 (10 * 500).

That is: 500- (5000/11) -> the result will be the amount of RIF that you will receive for 1 DOC, in this case is 45.45 RIF.

If in the example the swap were of less value (suppose 0.1 DOC), the amount received would change and would become 4.9 RIF. As you can see, the acquired value is proportionally higher than before, since by taking less from the pool, the liquidity is not as compromised, and offers a better price for the swap.

How to make profit on RSK Swap?

Token swapping alone is not a great money generator unless there is arbitrage involved and very large sums. However, providing liquidity can produce better returns. This is done by clicking on “Pool” on the exchange interface.

It will then ask you for two tokens to use in your liquidity pool. You must have enough of one to cover the liquidity of the other.

Metamask (or whatever wallet you use) will appear asking for confirmation and gas rate. Once you have added the tokens, you will receive Pool tokens or “p tokens” that represent your position in that pool.

The tokens automatically earn fees representative of their position in the pool and can be redeemed at any time.

Once the transaction is complete, you can examine the liquidity pool. This will show the amount of each token you have deposited. Eliminating liquidity is just as easy. You can do this by clicking the “Remove” button under the “Pool” option when viewing your own liquidity pools.

Impermanent losses should be mentioned at this stage, as this can happen when a liquidity provider’s earnings decrease despite additional rewards, i.e. it has more B tokens but the value of A token has increased since it was deposited in the pool. In these cases it may be more profitable to simply hold onto A token rather than use it for liquidity provision. If the prices returned to the same value they were when the liquidity provider added its liquidity, this loss would disappear, that is why they are called impermanent loss.

This loss only becomes real when the liquidity provider withdraws its liquidity, that is, it is based on the price difference between the deposit and the withdrawal. There is a full explanation here.

think and dev (c) all rights reserved

Add Comment