kopi.money
  • Welcome
  • Introduction
    • The Kopi Money Market
    • What is a crypto wallet
    • What is a DEX?
    • Strategies to maximize earnings
    • Tokenomics
  • Using Kopi
    • Connect your wallet
  • How to trade
  • How to place orders
  • Using arbitrage
  • Working with automations
  • Essentials
    • Trade execution
    • kCoins
    • Lending
    • Borrowing
    • Fees & Protocol Income
    • Interest rates
    • Liquidations
    • Adding new tokens to the DEX
  • Tokenfactory
    • Factory tokens
    • Liquidity pool
    • Vesting
    • Offers
  • Technical details
    • Constant product
    • Prices
  • Liquidity
  • Epochs
  • Running a node
  • Transaction fees
Powered by GitBook
On this page
  • Updating prices
  • Minimum liquidity
  • Global price updates
  • Dollar prices
  1. Technical details

Prices

For Decentralized exchanges that have dedicated trading pools, the price of a currency directly relates to the ratio of the liquidity in each trading pool where it is listed. When users add liquidity, they have to add liquidity in all currencies of that pool so that adding liquidity does not change prices.

Kopi only has one global trading pool while also offering users to add liquidity one currency at a time. To achieve this, the amount of liquidity as well as the prices are seperated from each other. Each currency is stored with its price in relation to XKP. Since everything is stored in relation to XKP, a price for any currency pair can be created: When 1 XKP = 0.25 kUSD and 1 XKP = 0.25 USDC, then 1 kUSD = 1 USDC.

Updating prices

Prices are updated after each trade. The prices are changed by the amount of liquidity added or removed respectively. When a trade has changed the available liquidity of XKP, all prices need to be adjusted since all prices are related to XKP. When a trade has not touched XKP, only the prices of the two affected currencies are changed.

When updating prices, the protocol creates a liquidity pair between XKP and the currency for which the price will be changed. If the values of available liquidity differ (which probably always is the case), the smaller value will be used as reference. By using the smaller value, currencies with smaller liquidity are subject to higher price fluctations compared to when the bigger value would have been used.

Trade:
Given into the pool: 10 kUSD
Received in return: 40 XKP

// Example 1
Available XKP: 1,000
Available kUSD: 100
Current price: 1 XKP = 0.25 kUSD
Value of kUSD liquidity in XKP: 400

Used liquidity for price change calculation: XKP = 400, kUSD = 100
Liquidity after change: XKP = 360 kUSD = 110
New price: 1 XKP = 110 / 360 = 0.30 kUSD

// Example 2
Available XKP: 1,000
Available kUSD: 10,000
Current price: 1 XKP = 0.25 kUSD
Value of kUSD liquidity in XKP: 40,000

Used liquidity for price change calculation: XKP = 1,000, kUSD = 250
Liquidity after change: XKP = 960 kUSD = 260
New price: 1 XKP = 260 / 960 = 0.27 kUSD

The two examples include one case where the available liquidity of kUSD is worth less than the value of available XKP liquidity; the other example shows a case where the available XKP liquidity is worth less than the available kUSD liquidity. It can be seen how having more liquidity available result in a smaller price change.

Minimum liquidity

Examples 1 and 2 show that trading tokens with small liquidity can have big impact on their prices. If there are currencies like USDC, USDT and kUSD who are supposed to stay at parity, their prices can fluctuate heavily when they only have little liquidity.

To counter this, each currency that is listed on the DEX has a paramater indicating minimum liquidity to add when changing its price. This number is added to the liquidity regardless of how much liquidity is actually present.

// Example 3

Trade:
Given into the pool: 10 kUSD
Received in return: 40 XKP

Available XKP: 1,000
Available kUSD: 1,000
Current price: 1 XKP = 0.25 kUSD
Value of kUSD liquidity in XKP: 4,000
Minimum liquidity for kUSD: 10,000
Minimum liquidity for kUSD in XKP: 40,000
Extra virtual liquidity for kUSD: 10,000 - 1,000 = 9,000
Extra virtual liquidity for XKP: 40,000 - 1,000 = 39,000

Used liquidity for price change calculation: XKP = 40,000, kUSD = 10,000
Liquidity after change: XKP = 39,960 kUSD = 10,010
New price: 1 XKP = 10,010 / 39,960 = 0.2505 kUSD

Example 3 shows that the price of kUSD hardly changes compared to when there is no extra virtual liquidity. The effect will be even more obvious when kUSD is traded with a token that has no extra virtual liquidity (the example uses an imaginary NEW token with only liquidity and a price of 1 kUSD = 1 NEW). Since the trade touches two currencies, the two currencies' prices in relation to XKP have to be updated.

Global price updates

Every trade is affecting the value of the touched currencies. When a user is selling XKP in favor of kUSD, it means the value of XKP is decreases a little while the value of kUSD increases. Since all currency prices are linked to XKP, the price of USDC has to be updated as well: USDC is linked to XKP and when the value of XKP is decreased, the price of USDC has to be increased.

One critical thing to consider is the relation by which these prices are changed: Imagine a currenc pair like XKP and kUSD having very deep liquidity, for example 100,000 XKP and 25,000 kUSD. A trade selling 10,000 XKP to buy kUSD might only affect the price a little. When at the same time the currency pair XKP/USDC only has very shallow liquidity, for example 10,000 XKP and 2,500 USDC. The same trade would have huge impact on the price of USDC.

To counter this, the trade amount to adjust other trading pairs is adjusted when the currency pair has less liquidity. In the given example, 10,000 XKP are given into a pool containing 100,000 XKP, i.e. the amount of XKP grew by 10%. To use the same relation, when updating the price of XKP in relation to USDC we calculate how much XKP would be given into this currency pair's trading pool to have it increase by 10% as well. In the given example, this would be 1,000 XKP.

// Example 4

Trade:
Given into the pool: 10 kUSD
Received in return: 40 XKP

// Updating XKP <> kUSD
Available XKP: 1,000
Available kUSD: 10,000
Current price: 1 XKP = 0.25 kUSD
Value of kUSD liquidity in XKP: 40,000
Extra virtual liquidity for kUSD: 10,000
Trade amount in relation to pool size: 0.1%

Used liquidity for price change calculation: XKP = 40,000, kUSD = 10,000
Liquidity after change: XKP = 39,960 kUSD = 10,010
New price: 1 XKP = 10,010 / 39,960 = 0.2505 kUSD
Price change in %: 0.2505 / 0.25 = 0.2%

// Updating XKP <> NEW
Available XKP: 1,000
Available NEW: 100
Current price: 1 XKP = 0.25 NEW
Value of NEW liquidity in XKP: 400
Used liquidity for price change calculation: XKP = 400, NEW = 100
Liquidity size relation: 400 / 40,000 = 1%
Used XKP trade amount: 40 * 0.001 = 0.4 XKP

Liquidity after change: XKP = 399.6, NEW = 100
New price: 1 XKP = 100 / 399.6 = 0.2502... NEW
Price change in %: 0.2502... / 0.25 = ~0.1 %

Example 4 shows how the price of kUSD (in relation to XKP) has changed more than the price of NEW (in relation to XKP).

On other decentralized exchanges, there are dedicated pools where users can trade stablecoins while there are also pools which more fluctuating prices. When trading on Kopi, users have the best of both worlds: Trading stablecoins with non-stablecoins results in the price of the stablecoin hardly moving while having dynamic prices for other tokens

Dollar prices

Users using the Kopi website will notice that for nearly all shown token amounts a dollar value is presented. That value is calculated using kUSD and its reference tokens:

kUSD is linked to various other Dollar-stablecoins like USDC and USDT, the price of which is used to indicate the parity of kUSD. All these tokens are of roughly the same vaue, although the price can vary a little. The reference currency with the highest price is used as Dollar reference for the website:

// Example 5

Currency prices:
1 XKP = 0.26 kUSD
1 XKP = 0.25 USDC
1 XKP = 0.249 USDT

=>
1 USDT = 1.004 USDC / 1 USDC = 0.996 USDT
1 USDT = 1.04 kUSD  / 1 kUSD = 0.957 USDT 

Example 5 shows possible prices of kUSD, USDC and USDT. In that example, USDT has the highest price and is used as Dollar reference. Users having 100 USDC in their wallet would see this with thevvalue of $99.60.

PreviousConstant productNextLiquidity

Last updated 1 month ago