Next Article in Journal
q-Analogs of Hn,mrσ and Their Applications
Previous Article in Journal
Efficient Monitoring of a Parameter of Non-Normal Process Using a Robust Efficient Control Chart: A Comparative Study
Previous Article in Special Issue
LB-GLAT: Long-Term Bi-Graph Layer Attention Convolutional Network for Anti-Money Laundering in Transactional Blockchain
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

The Method of Choosing Parameters for Margin Trading Protocols in the Constant Product Model

by
Lyudmila Kovalchuk
1,2,*,
Volodymyr Kostanda
3,
Oleksandr Marukhnenko
3,4,
Nataliia Kuchynska
1 and
Yuliia Marchuk
3,*
1
Department of Mathematical Methods of Information Security, Institute of Physics and Technology NTUU “Igor Sikorsky Kyiv Polytechnic Institute”, 03056 Kyiv, Ukraine
2
Department of Mathematical and Computer Modeling, Pukhov Institute for Modelling in Energy Engineering, General Naumov Str., 15, 03164 Kyiv, Ukraine
3
PrimexLabs OÜ, Harju Maakond, Kesklinna Linnaosa, Vesivärava tn 50-201, 10152 Tallinn, Estonia
4
Department of Information Technology Security, Faculty of Computer Engineering and Control, Kharkiv National University of Radioelectronics, 61166 Kharkiv, Ukraine
*
Authors to whom correspondence should be addressed.
Mathematics 2023, 11(19), 4158; https://doi.org/10.3390/math11194158
Submission received: 18 August 2023 / Revised: 10 September 2023 / Accepted: 14 September 2023 / Published: 3 October 2023
(This article belongs to the Special Issue Mathematics, Cryptocurrencies and Blockchain Technology, 2nd Edition)

Abstract

:
We introduce a new method of choosing parameters for margin trading protocols in the Constant Product Model and apply it to our new DeFi Margin Trading protocol Primex, which can work with different DEXs and DeFi platforms. The main advantages of Primex, in comparison with existing DeFi protocols, are the following: (1) the possibility to trade with leverage, using large asset amounts and having only a small part (deposit) in one of the assets; (2) full explanation and justification of the choice of protocol parameters and relations (such as liquidation condition, maximum leverage, different fees, etc.), which allows to estimate different risks (for Lenders and the protocol) and reduce them to the required level; (3) additional decentralization and, at the same time, protection against different faults in protocol functioning, achieved by the usage of the decentralized Keeper; (4) transparent rules and conditions for all participants—Lenders, Traders, and Keepers. We give a detailed explanation for our approach to set protocol parameters and build a corresponding method to obtain their numerical values in the case of the Constant Product Model. The obtained numerical results provide additional indirect confirmation of the consistency of our method. Note that it also may be applied (after the corresponding recalculation of some coefficients) to other models, such as the Order Book Model, Constant Sum Model, or the Mixed Constant Sum/Constant Product Model (as described in the Curve whitepaper), and even other types of DeFi protocols after some modification.

1. Introduction

Decentralized finance (DeFi) [1] is a new financial technology based on distributed ledgers similar to those used in cryptocurrencies. DeFi protocols may be considered a set of programs, such as smart contracts (SCs) and virtual machines (VMs), that define how digital assets are used in a blockchain network. DeFi protocols include exchanges, enabling users to lend and borrow cryptoassets and run decentralized autonomous organizations (DAOs) by using smart contracts, without any trusted party. Thus, they have more favorable conditions, such as transparency, trustlessness, and, sometimes, lower rates due to absence of additional fees, such as bank fees.
The DeFi market is growing every day, and lots of new protocols have appeared in the last few years. The total value locked in DeFi assets was 56.8 billion https://defillama.com as of September 2022 [2]. This is one of the main reasons for investigating the most widely used DeFi protocols, their capabilities, security, risks, and possible profit.
There are a lot of directions for DeFi investigations. The most interesting and the most relevant in this case are described in the following recent papers (see also the included bibliography):
  • The evaluation of relevant DeFi performance metrics related to the valuations of DeFi protocols; investigating how these valuations depend on values such as total value locked (TVL), protocol income, total income, trading volume, and inflation factor (see for example [3] and the included rich review);
  • Security against attacks on decentralized trust-based oracles function [4], especially in cases when one protocol uses the oracle function of another protocol, such as the usage of Chainlink [5,6] and Oraclize [7];
  • The creation and analysis of different automated market-making (AMM) mechanisms, such as Constant Product [8,9] and Combined Constant Sum and Constant Product [10,11];
  • The methods and tools that allow overcoming the problem of cross-blockchain interaction in the DeFi industry [12] (and plenty of additional references inside).
Note that important areas of investigation such as the choice of protocol parameters, risk estimations, and the relations and dependencies between them are presented very poorly both in scientific and technical publications.
Though most DeFi protocols are based on similar concepts, each is unique with its own properties, purposes, and description in the documents. From a general point of view, all DeFi protocols may be divided into the following types [13].
(i)
Decentralized Exchange (DEX): a platform used for trading different assets, e.g., exchanging stablecoins for other cryptocoins and vice versa. DEX links users without third parties, as all DeFi protocols do. Popular solutions include Uniswap [9], Curve [11,14], Balancer [15], and Bancor [16].
(ii)
Decentralized Lending/Borrowing Platform (DLBP): these platforms enable market players (such as Lenders and Borrowers) to lend and borrow assets based on rules such as overcollateralization requirement or restrictions for liquidity usage described in smart contracts. Thus, a Borrower (who also may be Trader) is obligated to pay the fee for the loan (as a regular payment or by a deadline), and a Lender earns interest for providing liquidity. The most well-known DLBP protocols are Aave [17], Compound [18], and MakerDAO [19].
(iii)
Decentralized Insurance Platform (DIP): these platforms are useful because of numerous cases of fraud and protocol hacks, and may be considered as an alternative to traditional insurance. In such situations, they aim to reduce users’ risk in such situations and protect their digital assets. Market players pay for the service and are provided with this insurance in case of different situations, such as smart contract bugs or hacker attacks. A DIP offers various use cases of insurance, such as crypto wallet insurance, smart contract cover, collateral protection for crypto-backed loans, etc. Nexus Mutual [20], Etherisc [21], and VouchForMe [22] are examples of leading decentralized insurance providers.
(iv)
Decentralized Prediction Market (DPM): a platform that is used by people who are willing to buy predictions rather than products or currencies. Such users can bet on different future events, from tomorrow’s weather to presidential elections, by buying the shares that align with their predictions. Augur [23] and Gnosis [24] are two well-known DPM projects.
(v)
Asset Management Tools (AMT): a protocol type which may help users seeking to make investments but who need some help in choosing the best possible investment strategies. The platform proposes some variants for investor, and then takes over and runs the investment process according to their choice. Set Protocol [25] is a popular asset management solution. In this work, we introduce a new method of choosing parameters for margin trading protocols in the Constant Product Model [26] and apply this method to our new DeFi Margin Trading protocol Primex [27], which can work with different DEXs and DeFi protocols. Primex is a new DeFi protocol type: a Decentralized Margin Trading Protocol (DMTP). Though it has some similarities with DEXs and lending protocols, it is also significantly different from them, due to its useful features.
The main advantages of Primex are as follows:
  • A DMTP that allows Traders to trade with leverage, using capital which is several times larger than their own;
  • Full explanations and justifications of the choice of protocol relations and parameters (such as the liquidation condition, maximum leverage, different fees, etc.), which allows to estimate different risks (for Lenders and the protocol) and reduce them to the required level;
  • A high level of decentralization and at the same time additional protection against different faults in protocol functioning, achieved by the usage of decentralized Keeper;
  • Transparent rules and conditions for all participants—Lenders, Traders, and Keepers.
A more detailed comparison with such protocols is given below.
Comparison with lending protocols. Lending protocols, such as AAVE [17] and Compound [18], are overcollateralized. Borrowers cannot borrow more liquidity than they deposited, and funds are transferred to borrowers wallets and can be used for any purpose. In Primex, funds are borrowed only for a specific purpose—margin trading. Thus, funds stay in the protocol, and debts are not overcollateralized by Traders.
Comparison with AMM DEXs. DEXs, such as Uniswap [9], Curve [11,14], and Balancer [15], allow swapping one token for another based on their internal formulas. They do not have margin trading and sophisticated orders. Primex does not compete with AMM DEXs but works on top of them, increasing their trading volumes.
Comparison with DEX aggregator. DEX aggregators, such as 1inch [28] and Paraswap [29], find optimal routs for swaps, and, similarly to Primex, they defragment the market. However, most of them do not provide additional liquidity or sophisticated orders.
Comparison with derivative DEXs. On GMX [30] and DyDx [31], all trades happen inside the platform, so Traders compete with one another and with Lenders. For this reason, Lenders lose their liquidity when Traders win. In Primex, Traders interact with multiple DEXs and receive profits from there, so the only risk for Lenders is delayed liquidations (such risk is essentially restricted, due to some protocol features). On derivative DEXs, trading is available only inside the specific protocol causing additional fragmentation, while Primex connects Traders with external market.
Another difference between Primex from the above-mentioned protocols is Primex’s a sophisticated and decentralized Keeper network that increases protocol stability and minimizes centralization with special consensus algorithms.
Descriptions of DEXs and Lending protocols, given in the corresponding documents such as Whitepapers, mainly focus on their technical details and many mathematical aspects and methodologies of parameter choice are described briefly.
The main point of our investigation is to create a mathematical method which allows justifying the choice of parameters for different DeFi protocols, such as Primex, by analyzing different connections between protocol parameters and risks. We describe the method and taking Primex as an example. We believe that choosing these Primex parameters will provide stability and reduce risks to a given acceptable level (under some common assumptions used in mathematical statistics, for example about properties of sample parameters).
The article is organized as follows. In Section 2, we briefly describe the main ideas of Primex in general. Section 3 is the central part of our work; here, we formulate and prove several Statements (Theorems, Lemmas, Corollaries) that form the base of our method and are of vital importance for the formalization of the liquidation condition, the restriction of the leverage size, and setting other parameters. In Section 3.1, of Section 3, we introduce the main definitions and designations, and then describe the mathematical model of Constant Product Market (CPM) in Section 3.2. Using this mathematical description, in Section 3.3, we formulate and prove the main properties of asset value function for the CPM, such as non-linearity (Theorems 1 and 2) with upper and lower bounds and losses in two mutual swaps (Theorem 3). Based on these properties, we formulate the liquidation condition in Section 3.4 and set explicit formulas for maximum leverages in Section 3.5 for different cases of deposit assets. Furthermore, in Section 3.5, we give numerical results for the maximum leverage (Table 1), calculated for different assets using our formulas.
In the Conclusion, we discuss the obtained results and show the directions for further investigations.
Furthermore, in Appendix A, we provide a definition for one of the central values used both in liquidation condition and maximum leverage calculation—maximum price drop ν max . Using a large amount of statistical data, we also explain how it should be calculated, and give corresponding numerical results (Table A1).

2. Primex—A Brief Description of a New Margin Trading Protocol

In this section, we briefly describe the main idea of the Margin Trading protocol Primex and then pay attention to the details related to the process of a conditional position closing. This type of position closing is called liquidation, and its correctness is of interest to this paper.
There are three types of actors in Primex: Lenders, Traders, and Keepers. Lenders provide liquidity to the Primex protocol and earn interest from fees paid by Traders for liquidity usage.
Primex provides liquidity only for a specific type of use: margin trading on DEXs. Traders may borrow some amount of liquidity (provided by Lenders), and this amount is restricted by the maximum allowed leverage and the Trader’s deposit size. They pay a borrowing fee for asset usage, which depends on the utilization ratio (ratio between total demand and total supply). In comparison with regular lending protocols with full over-collateralization, successful margin trading generates much higher returns, enabling Traders to pay higher borrowing fees to the protocol through profit-sharing. Consequently, Lenders earn more as they receive interest (in the asset type they provided) as a percentage of borrowing fees paid by Traders. The other part of the borrowing fee is accumulated in the protocol and aims to cover different risks which may occur due to different situations, such as unexpected price drops. One of the tasks of our protocol is to guarantee (with a high probability) that all Lenders will safely get back both their deposits and accumulated interest. Keepers are participants who ensure the protocol’s secure functioning. They execute conditional orders, opening and closing positions when corresponding conditions are met. For example, if a position opened by a Trader becomes risky, a decentralized Keeper (acting according to rules set in the protocol) should close it as quickly as possible. In what follows, we consider some positions as risky if the so-called liquidation condition is met for this position.
Keepers are economically incentivized to perform their duties. It is also assumed that in the early stage of the protocol, Lenders and Traders are rewarded with some amount of PMX-tokens (Keepers are rewarded with this tokens during all time of their work).

3. Materials and Methods

In what follows, we consider only one type of position closing—liquidation closing—leaving other conditions, such as stop-loss and take-profit closing, for future investigations. Liquidation closing is performed by decentralized Keepers and should happen each time when a position becomes “risky”. We will explain below what this means exactly. We are going to formulate such liquidation conditions, which should reduce different risks for the protocol and show that the maximum leverage size is determined by these conditions.
We give several theorems which are necessary for solving two main problems, connected to position liquidation, namely:
  • A formal description of the liquidation condition;
  • Restriction on the leverage size for margin trading.
Then, using these theoretical results, we formulate practical solutions for the two problems mentioned above. Numerical results obtained using these theorems are given below.

3.1. Main Designations and Relations

Capital Latin letters ( A , B , C , D ) are used to indicate the type of an asset, and the corresponding value of the asset, i.e., the number of its units, is described in lowercase letters ( a , b , c , d ) . We will also use the following function:
C A / B ( t ; a ) ,
which, in the point ( t , a ) , is equal to the number of units of asset B that can be obtained at the moment t by selling a units of asset A, based on the price given by the Oracle. We call it asset value function (AVF).
Let us consider three assets A , B , and D. Assets A and B are always different. The third asset D may coincide with one of them, but not necessarily. When opening a leveraged trading position, the Trader uses asset D (the deposit), which they have in the amount of d 0 units, borrows asset A in the amount of a units, and exchanges them ( D and A assets) for b units of asset B. The acceptable amount of the borrowed asset of a units is determined from the following ratio:
a l max · C D / A t 0 , d 0
where t 0 is the time of the position opening and value l max is set in advance. Value L max = l max + 1 is called the maximum acceptable leverage.
In what follows we will use the designation d = C D / A t 0 , d 0 .
Relation L = d + a d is called the leverage of the position. In particular, if the asset of deposit D coincides with the borrowed asset A, then d = d 0 and the allowable amount is determined by the inequality d + a d = L L max .
Value d 0 is called the Trader’s deposit. Generally speaking, depending on the trading rules, after opening a position, the deposit can be frozen and returned to the Trader only after the Trader returns a units of the borrowed asset A to the liquidity bucket, as well as all other payments under the protocol. However, hereafter, we assume that the Trader uses the deposit together with the borrowed asset, namely exchanging it for a position holding asset B (if it was in some other asset).
The deposit is a kind of insurance for Lenders in case the Trader could not predict market trends well enough and the value of asset B drops relative to the value of asset A or does not grow to the expected rate. The deposit is then used to reimburse Lenders for the asset borrowed from them and the borrowing fee provided in the protocol. At the same time, the protocol itself is built in such a way that, as the risks increase, the leveraged position is forcibly closed (liquidated), guaranteeing that the Lenders retrieve not only all their loaned assets but also the fees for the use of these assets.
After opening a position, asset A (together with the deposit) is exchanged by the Trader for some other asset B, which they hope will increase in value with respect to asset A.
There are three possible cases:
(i)
The deposit is in asset A;
(ii)
The deposit is in asset B;
(iii)
The deposit is in the third asset D.
For each case, the number of units b of asset B, which are received after opening a position, will be calculated differently.
Let a 0 be the number of units of asset A, which the Trader borrows against the deposit, and d 0 be the number of units of asset D their deposit. Then, exchanging the borrowed asset and the deposit (if D B ) for asset B, the Trader receives a certain amount of b units of asset B, defined by the following formulas:
in case ( i ) : b = C A / B 0 , a 0 + d 0 ;
in case ( ii ) : b = C A / B 0 , a 0 + d 0 ;
in case ( iii ) : b = C A / B 0 , a 0 + C D / B 0 , d 0 .
As has been noted, there is also a potential case when the asset is in deposit D, such that D A and D B , and “freezes”, and is not transferred to asset B. In this case, we have:
( iv ) b = C A / B 0 , a 0
but we will not consider it here.
The time during which the position remains open after the liquidation condition has been met is generally assumed to be limited (in this paper, we assume that it is limited to 10 min).

3.2. Constant Product Market Description

We start with a short explanation of the Constant Product Market (CPM [26]), whose functioning is defined by CMT rules. Let a Constant Product Market consist of two assets, A and B, of the value a and b units, respectively, where the prices of these two assets, expressed in USD or USDT, are the same. Roughly speaking, the price of a units of asset A is b units of asset B, or the price of one unit of asset A is b a units of asset B, and vice versa. Let us define the constant T as T = a · b .
Next, define value ρ , called the transaction fee, which may be expressed as a percentage or a ratio, and value γ = 1 ρ . Note that value ρ is rather small (for example, ρ = 0.003 for Uniswap), so inequality 1 γ = 1 + ρ 1 ρ > 1 + ρ may be rewritten approximately as 1 γ 1 + ρ .
Let us assume the Trader wants to buy Δ b units of asset B. Then, the amount Δ a of asset A which the Trader should pay for it is defined from equation:
( b Δ b ) ( a + γ · Δ a ) = T
or Δ a = a · Δ b γ ( b Δ b ) , which for a large enough b and a small (w.r.t. b) value of Δ b may be approximated with equality:
Δ a ( 1 + ρ ) · a b · Δ b
using the approximation for 1 γ given above. Relation (7) explains why we consider ρ a commission: if we set ρ = 0 , we get Δ a = a b · Δ b , where the price of one unit of asset B is just a b units of asset A.
After the Δ a / Δ b exchange, we get the new state of the market and the new value T > T of the product:
T = ( b Δ b ) ( a + Δ a ) = T Δ b · a + ( b Δ b ) · Δ a = T + Δ b · a 1 γ 1 > T ,
because of 0 < γ < 1 . Thus, as we can see from (8), each trade actually increases the product of asset values. Note that if we set ρ = 0 then the value of the product will be stable all the time after any number of trades, and this fact explains the name “Constant Product Market”.
Now, consider the main properties of function (1) in the CPM [26]. In Theorems 1 and 2 below, we prove the property for (1) in the CPM, which we call quasilinearity. We show that this function is not linear on the second variable, but it is very close to linear.
Next, it should be noted that, for function (1), due to the difference (spread) in purchase and sale prices, we get the upper estimation:
C B / A t ; C A / B ( t , a ) a .
In Theorem 3, we show that the next low estimation holds for some μ ( 0 , 1 ) :
μ a < C B / A t ; C A / B ( t , a ) .
where coefficient μ depends on the parameters of the Constant Product Model (CPM). In particular, for the CPM, we get μ = 0.994 .

3.3. Properties of the Asset Value Function in the CPM

Here, we formulate and prove several inequalities which describe the useful properties of asset value function under CPM assumptions. In what follows, we use all designations given above. Furthermore, we define:
Δ 1 a , Δ 2 a as some amounts of asset A, and set Δ a = Δ 1 a + Δ 2 a ;
Δ 1 b , Δ 2 b as amounts of asset B, which we get for trading Δ 1 a , Δ 2 a , respectively;
Δ b as the amount of asset B which we get for trading Δ a .

3.3.1. Quasilinearity of A V F and Its Quasilinearity Coefficient

First, we will show that in our model, A V F is not linear on the second variable:
C A / B t , Δ 1 a + Δ 2 a C A / B t , Δ 1 a + C A / B t , Δ 2 a ,
but may be rather close to linear, depending on value ρ of the swap fee (the smaller ρ , the closer this function is to the linear one). This means that the amount of asset B, obtained in one exchange for some amount Δ a of asset A, is not equal to the amount of asset B, obtained during two consecutive exchanges, in the case where the same amount Δ a of asset A has been exchanged in total. It turns out that two consecutive exchanges are less profitable than one, if the amount of the asset we exchange is the same. In other words, it is more profitable to trade Δ a = Δ 1 a + Δ 2 a in one swap than to trade Δ 1 a and after this to trade Δ 2 a .
Theorem 1 
(non-linearity of AVF, lower bound). In our notation, the next inequality holds:
Δ b Δ 1 b + Δ 2 b ;
Moreover:
Δ b = Δ 1 b + Δ 2 b + ( 1 γ ) · γ · Δ 1 a · Δ 2 a · b Δ 1 b a + Δ 1 a + γ · Δ 2 a a + γ · Δ 1 a + Δ 2 a .
Proof. 
Consider two possible cases:
(i)
Exchange the entire quantity of asset Δ a for Δ b ;
(ii)
Exchange some quantity Δ 1 a for Δ 1 b , and then exchange Δ 2 a for Δ 2 b .
For case (i), based on equalities T = a · b = ( a + γ Δ a ) · ( b Δ b ) , we obtain Δ b as:
Δ b = b a b a + γ · Δ a = b T a + γ · Δ a = γ · Δ a · b a + γ · Δ a .
For case (ii), after the first exchange, we get:
Δ 1 b = b T a + γ · Δ 1 a
and the new product in this case will be:
T = a · b = a + Δ 1 a b Δ 1 b > T ,
where:
T = a · b = a + γ · Δ 1 a · b Δ 1 b .
After the second exchange, we get:
Δ 2 b = b T a + γ · Δ 2 a .
Thus:
Δ 1 b + Δ 2 b = b T a + γ · Δ 1 a + b T a + γ · Δ 2 a .
After some transformations, we obtain:
Δ 1 b + Δ 2 b = b T a + γ · Δ 1 a + b T a + γ · Δ 2 a ± T a + γ · Δ a = = b T a + γ · Δ a + T a + γ · Δ a T a + γ · Δ 1 a + T a + Δ 1 a T a + γ · Δ 2 a ,
where we substitute b with T a + Δ 1 a .
Therefore, using equality a + γ · Δ 2 a = a + Δ 1 a + γ · Δ 2 a , we can write:
Δ 1 b + Δ 2 b = Δ b + T · 1 a + γ · Δ a 1 a + γ · Δ 1 a +
+ T · 1 a + Δ 1 a 1 a + γ · Δ 2 a = Δ b T · γ · Δ 2 a ( a + γ · Δ a ) a + γ · Δ 1 a +
+ T · γ · Δ 2 a a + Δ 1 a a + Δ 1 a + γ · Δ 2 a =
Δ b + γ · Δ 2 a · T a + Δ 1 a a + Δ 1 a + γ Δ 2 a T ( a + γ Δ a ) a + γ Δ 1 a =
= Δ b + γ · Δ 2 a b Δ 1 b 1 a + Δ 1 a + γ Δ 2 a 1 a + γ Δ 1 a + Δ 2 a =
= Δ b + ( γ 1 ) γ · Δ 1 a · Δ 2 a b Δ 1 b a + Δ 1 a + γ Δ 2 a a + γ Δ 1 a + Δ 2 a ,
or:
Δ b = Δ 1 b + Δ 2 b + ( 1 γ ) · γ · Δ 1 a · Δ 2 a · b Δ 1 b a + Δ 1 a + γ · Δ 2 a a + γ · Δ 1 a + Δ 2 a ,
and the Theorem is proved. □
Now, we calculate the coefficient that allows us to estimate the upper bound of Δ b and write the opposite inequality.
Theorem 2 
(non-linearity of AVF, upper bound). In our notation, the next inequality holds:
Δ 1 b + Δ 2 b γ · Δ b .
Proof. 
Set Δ a = Δ 1 a + Δ 2 a and consider two possible cases:
(i)
Exchange the entire quantity of asset Δ a for Δ b ;
(ii)
Exchange some quantity Δ 1 a for Δ 1 b , then exchange Δ 2 a for Δ 2 b .
Suppose that initially, it was a units of asset A and b units of asset B, where T = a b . Then, in case (i), Δ b is calculated from relation ( a + γ · Δ a ) · ( b Δ b ) = a b as:
Δ b = b a b a + γ · Δ a = γ · b · Δ 1 a a + γ · Δ a .
Next, in case (ii), after the first exchange we obtain:
Δ 1 b = b a b a + γ · Δ 1 a = γ · b · Δ 1 a a + γ · Δ 1 a ,
from where:
b Δ 1 b = a b a + γ · Δ 1 a .
Then, from the statement of Theorem 1, we have:
Δ 1 b + Δ 2 b Δ b =
= 1 ( 1 γ ) · γ · Δ 1 a · Δ 2 a · b Δ 1 b Δ b · a + Δ 1 a + γ · Δ 2 a a + γ · Δ 1 a + γ · Δ 2 a = 1 Δ ,
where:
Δ = ( 1 γ ) · γ · Δ 1 a · Δ 2 a · b Δ 1 b Δ b · a + Δ 1 a + γ · Δ 2 a a + γ · Δ 1 a + γ · Δ 2 a > 0 ,
because of 1 γ = ρ > 0 .
By substituting (13) and (14) in Δ , we get:
Δ = ( 1 γ ) · γ · Δ 1 a · Δ 2 a · a b a + γ · Δ 1 a γ · Δ a · b a + γ · Δ a · a + Δ 1 a + γ · Δ 2 a a + γ · Δ 1 a + γ · Δ 2 a =
= ( 1 γ ) · Δ 1 a · Δ 2 a · a Δ a · a + Δ 1 a + γ · Δ 2 a ( a + γ · Δ a ) = = ( 1 γ ) · Δ 2 a Δ a · Δ 1 a a + Δ 1 a + γ · Δ 2 a · a a + γ · Δ a ( 1 γ ) .
Then, from ( 15 ) :
Δ 1 b + Δ 2 b Δ b 1 ( 1 γ ) = γ ,
or Δ 1 b + Δ 2 b γ · Δ b , and Theorem 2 is proved. □
We can combine Theorems 1 and 2 into one double inequality and rewrite it in terms of function (1) in the next Corollary.
Corollary 1 
(from Theorems 1 and 2). In our designations, inequalities hold:
γ · C A / B t , Δ 1 a + Δ 2 a < C A / B t , Δ 1 a + C A / B t , Δ 2 a < C A / B t , Δ 1 a + Δ 2 a ,
or:
C A / B t , Δ 1 a + C A / B t , Δ 2 a < C A / B t , Δ 1 a + Δ 2 a <
1 γ C A / B t , Δ 1 a + C A / B t , Δ 2 a .
We will call this property the property of quasilinearity of function (1), and the coefficients γ and 1 γ will be called the quasilinearity coefficients.
Note that the coefficient γ = 0.997 is very close to 1, so function (1) is very close to linear (on the second variable).

3.3.2. Coefficient of Mutually Inverse Swaps for AVF

Suppose that initially there were a units of asset A and b units of asset B in the pool. After that, two mutually inverse swaps were performed:
(1)
We put Δ a units of asset A into the pool, and took the corresponding amount of Δ b units of asset B from it;
(2)
Then, we immediately performed the reverse swap: we put Δ b units of asset B into the pool and took out the corresponding amount Δ 1 a units of asset A.
We want to estimate the losses of such repeated exchanges.
Theorem 3 
(losses in two mutually inverse swaps). In our notations, the next inequality holds:
Δ 1 a γ 2 · Δ a .
Proof. 
Let us denote T = a b . Then, after the first transaction, we will receive:
Δ b = γ · b · Δ a a + γ · Δ a .
The new product will be equal to:
T = a · b = ( a + Δ a ) ( b Δ b ) ,
where a = a + Δ a , b = b Δ b .
After the second transaction (putting Δ b into the pool), we calculate value Δ 1 a from equality:
a Δ 1 a b + γ · Δ b = a · b = T .
Then:
Δ 1 a = a T b + γ · Δ b = a 1 b b + γ · Δ b = γ · a · Δ b b + γ · Δ b .
Taking (17) into consideration, equality (18) can be rewritten in the following way:
Δ 1 a = γ · a · γ · b · Δ a b + γ · Δ b ( a + γ · Δ a ) = γ 2 · b · Δ a · ( a + Δ a ) ( b Δ b + γ · Δ b ) ( a + γ · Δ a ) =
= γ 2 · b · Δ a · ( a + Δ a ) ( b Δ b · ( 1 γ ) ) ( a + γ · Δ a ) ,
or:
Δ 1 a = γ 2 · Δ a · b ( b Δ b · ρ ) · ( a + Δ a ) ( a + γ · Δ a ) γ 2 · Δ a ,
and the Theorem is proved. □
Similarly to Corollary 1, we can now write the double inequality for function (1).
Corollary 2 
(Theorem 3). In our designations:
μ a < C B / A t ; C A / B ( t , a ) < a ,
where μ = γ 2 .
The double inequalities (16) and (19) will be used in the next section for the justification of the choice of protocol parameters and setting the liquidation condition.

3.4. Liquidation Process: Description and Justification of the Position Liquidation Condition for CPM

Since this position closing method carries the greatest amount of risks, special attention should be paid to the description of the conditions for position liquidation. In this section, we give a detailed description of the liquidation process and, based on this description, and set and justify the liquidation condition—the condition under which the position should be immediately closed (liquidated) by Keepers.
Let us assume that the position was opened at moment t 0 (suppose that t 0 = 0 ) and is forced to close at time t > 0 . Furthermore, we assume that the process of closing the position requires some non-zero time, caused by the delay in identifying the risky position by the Keepers and the delay in the transaction’s execution on the blockchain. In what follows, we will assume that this time is with a high probability upper bounded with 10 min, which is a slight overestimation, but fully corresponds with our intention to minimize risks and losses.
According to our notation, after opening a position, the Trader has b units of asset B, where b depends on the Trader’s deposit (namely, on the type of deposit asset and on the deposit value, see (3)–(5)), and on the leverage value chosen by the Trader in an allowed range. When liquidating the position at some moment t, the Keeper performs a reverse swap, exchanging b units of asset B for a ( t ) units of asset A, where:
a ( t ) = C B / A ( t , b ) .
Note that the gas fee for this transaction, generally speaking, does not depend on the value of b, but it depends significantly on the complexity of the transaction. According to the protocol, the Keeper uses their own funds for the transaction, so the Keeper’s reward (paid partially in the native chain asset, and partially in PMX tokens) must be large enough to consider this job profitable.
Furthermore, during the execution of the transaction (the time period between when the liquidation condition is met and the actual incorporation of the transaction into the blockchain), the value of asset B w.r.t. asset A may decrease. We will assume that during the execution of the transaction (whose duration we conditionally limit to 10 min), the maximum share of the drop of asset B relative to asset A (see Appendix A below) does not exceed a certain value ν ( 0 , 1 ) . In Appendix A, we provide a full explanation of how we define, estimate, and regularly update this value, using large amounts of up-to-date statistical data obtained from the Chainlink Oracle and different DEXs for a sufficiently large period of time (a month, a week, etc.). It is obvious that value ν behaves differently for different asset pairs.
Taking into account the value of ν , after completing the transaction we get at least the following number of units of asset A:
( 1 ν ) · a ( t )
From this number, the following payments should be completed:
  • A debt repayment to the bucket, which consists of a 0 units of asset A;
  • The Trader’s Borrowing Fee (BF), accrued at the current Borrow Annual Rate (BAR) according to the compound percent formula (Lenders also get some amount of this fee, depending on the time interval t of liquidity provision and the amount of this liquidity, in accordance with the protocol rules);
  • A part of the Trader’s Borrowing Fee, which is accrued during the liquidation period (from the moment when the liquidation condition is met and triggers liquidation until the end of the liquidation process).
The value of the Trader’s BF during time interval t is calculated per second, based on the current BAR, as a compound percent of borrowed liquidity. The BAR value is not constant all the time. Its value depends on the so-called utilization ratio—a fraction of borrowed liquidity in the pool (a large utilization ratio involves a larger BAR value). Let us assume that N = N t is the number of seconds in the time interval t, where N t is divided by the m periods of BAR stability: N t = n 1 + + n m , where n i is the time duration (in seconds) of the i-th period of stability; α i is the BAR value in this period, divided by the number of seconds per year (31,536,000); m is the number of periods. Then, the full value of the Trader’s payments for using a 0 units of asset A during time t can be expressed as ε ( t ) · a 0 , where:
ε ( t ) = 1 + α 1 n 1 · · 1 + α m n m .
Then, according to our assumptions, the liquidation period is limited to 600 s and the maximum value of the BAR is 1000 % . Thus, even if the BAR skyrockets to the maximum during the liquidation period, the total BF (from the moment the position is opened until the moment it is closed) will be no larger than:
Δ · ε ( t ) · a 0 = 1 + 10 31536000 600 · ε ( t ) · a 0 1 + 2 · 10 4 · ε ( t ) · a 0 ,
where Δ = 1 + 10 31536000 600 1 + 2 · 10 4 .
Thus, after completing the liquidation transaction, we receive ( 1 ν ) · a ( t ) units of asset A, and not more than Δ · ε ( t ) · a 0 units of asset A should be paid as the Borrowing Fee.
Therefore, to guarantee that all necessary payments can be paid, the next condition should be met:
( 1 ν ) · a ( t ) Δ · ε ( t ) · a 0 .
Thus, the “trigger” to begin the liquidation is the moment when the following condition is fulfilled for the first time, which is the inverse inequality to (21):
( 1 ν ) · a ( t ) Δ · ε ( t ) · a 0 .
which can also be rewritten as:
( 1 ν ) · a ( t ) Δ · ε ( t ) · a o 1
We also add some small buffer security parameter  β ( 0 , 1 ) in (22) as risk assurance and rewrite (22) as:x
( 1 β ) · ( 1 ν ) · a ( t ) Δ · ε ( t ) · a 0 ,
where we set β = 0.1 .
The resulting inequality (24) is set as the real trigger for the liquidation, and hence, is called the liquidation condition.
Let us assume that before closing the position (at some moment t > 0 ), the Trader had b units of asset B. Then, after the position closing transaction, the obtained amount of asset A is equal to a ( t ) = C B / A ( t , b ) units.
Similarly to the derivation of inequality (24), we can obtain an expression for value a ( t ) —the number of units of asset A which remain after all payments are made, taking into account the possible drop in the value of asset B and the maximum BAR value during the position’s closing:
a ( t ) = ( 1 β ) · ( 1 ν ) · a ( t ) Δ · ε ( t ) · a 0 .

3.5. Setting the Maximum Acceptable Leverage for Position Opening and the Justification of This Choice for Different Types of Deposit Assets

In this subsection, we derive constraints on the value for the maximum acceptable leverage  L max for different types of the deposit asset D. As an example, we may consider the CPM here, but all these considerations may be easily transferred to any other model, taking into account its (quasi)linearity and mutually inverse swap coefficients.
According to condition (24), the liquidation of the position should begin immediately after its opening if the next condition is met:
( 1 β ) · ( 1 v ) · a ( 0 ) Δ · ε ( 0 ) · a 0 = Δ · a 0 ,
because of ε ( 0 ) = 1 . We can avoid such a situation by setting the correct value for L max , under which the opposite inequality will be held:
( 1 β ) · ( 1 v ) · a ( 0 ) > Δ · a 0 .
Inequality (27), with a slight modification, will be used when choosing the value of the maximum leverage. Modification is needed to avoid immediate liquidation when the Trader chooses the maximum leverage. For this purpose we strengthen the requirement in condition (27) obtaining a stronger condition
( 1 β ) · ( 1 v ) · a ( 0 ) > ( 1 + ı ) Δ · a 0 ,
for some small parameter ı ( 0 , 1 ) , for example, ı = 0.1 , and will use ( 28 ) for defining the maximum leverage size.
Note that this new parameter ı appears only in (28) and does not change liquidation condition (24).

3.5.1. Deposit Asset Coincides with the Borrowed Asset: A = D

In this case, value a ( 0 ) can be represented as:
a ( 0 ) = C B / A ( 0 ; b ) = C B / A 0 ; C A / B 0 ; a 0 + d 0 ,
where, from Corollary 2, μ a 0 + d 0 < a ( 0 ) < a 0 + d 0 .
Next, let us assume that the position has been opened with a leverage equal to L L max , so a 0 = ( L 1 ) · d 0 L max 1 · d 0 .
To avoid immediate liquidation, we should provide the condition (28), which (taking into consideration that a 0 = ( L 1 ) · d 0 ) we can rewrite as:
( 1 β ) · ( 1 ν ) · a ( 0 ) > ( 1 + ı ) · Δ · ( L 1 ) · d 0 .
Then, using Corollary 2, we get inequality:
( 1 β ) · ( 1 ν ) · μ · a 0 + d 0 > ( 1 + ı ) · Δ · ( L 1 ) · d 0 ,
which is sufficient (and even stronger) for the correctness of (28).
The last inequality may be rewritten as:
( 1 β ) · ( 1 ν ) · μ · L · d 0 > ( 1 + ı ) · Δ · ( L 1 ) · d 0 ,
or:
( 1 β ) · ( 1 ν ) · μ · L > ( 1 + ı ) · Δ · ( L 1 ) ,
from which we obtain:
L < ( 1 + ı ) · Δ ( 1 + ı ) · Δ μ · ( 1 β ) · ( 1 ν ) ,
guaranteeing that the position liquidation process will not start immediately after opening it.
Note that the expression in the denominator of the right-hand side of (29) is positive if ν < 1 , which is a natural requirement. Moreover, the denominator will be less than 1 even for Δ sufficiently close to 1 (which, as has been shown, is carried out in practice). Therefore, the upper bound for L 1 , which may be obtained from ( 29 ) , is as follows:
L 1 < ( 1 β ) · μ · ( 1 ν ) ( 1 + ı ) · Δ ( 1 β ) · μ · ( 1 ν ) ,
which will always be greater than 1. It means that the requirement for L max , derived from (29) is formulated correctly as follows:
L max ( A = D ) < ( 1 + ı ) · Δ ( 1 + ı ) · Δ μ · ( 1 β ) · ( 1 ν ) ,
Inequality (30) defines the maximum leverage for the case when D = A .

3.5.2. Deposit Asset Coincides with the Position Asset: B = D

In this case, we also use inequality (28), but value a ( 0 ) is defined in the following way:
a ( 0 ) = C B / A 0 ; b + d 0 = C B / A 0 ; C A / B 0 ; a 0 + d 0
C B / A 0 ; C A / B 0 ; a 0 + C B / A 0 ; d 0 .
Next, using Theorem 3, we obtain the following from (31):
a ( 0 ) μ · a 0 + C B / A 0 ; d 0 .
Using (32), we can write the inequality which guarantees the correctness of inequality (28) as:
( 1 β ) · ( 1 ν ) · μ · a 0 + C B / A 0 ; d 0 > ( 1 + ı ) · Δ · a 0
Since a 0 = ( L 1 ) · C B / A 0 ; d 0 , the last inequality can be rewritten as:
( 1 β ) · ( 1 ν ) μ · ( L 1 ) · C B / A 0 ; d 0 + C B / A 0 ; d 0 > ( 1 + ı ) · Δ · ( L 1 ) · C B / A 0 ; d 0
or:
( 1 β ) · ( 1 ν ) ( μ · ( L 1 ) + 1 ) > ( 1 + ı ) · Δ · ( L 1 ) ,
producing a restriction on the leverage size as follows:
L max 1 < ( 1 β ) · ( 1 ν ) ( 1 + ı ) · Δ μ · ( 1 β ) · ( 1 ν )
or:
L max ( B = D ) < ( 1 + ı ) · Δ + ( 1 μ ) · ( 1 β ) · ( 1 ν ) ( 1 + ı ) · Δ μ · ( 1 β ) · ( 1 ν ) .

3.5.3. Deposit Asset Differs from the Borrowed and Position Asset: D A , D B

Here, we use inequality (28) as well as Theorems 1–3 to construct a lower bound estimate of a ( 0 ) :
a ( 0 ) = C B / A ( 0 ; b ) = C B / A 0 ; C A / B 0 ; a 0 + C D / B 0 ; d 0
C B / A 0 ; C A / B 0 ; a 0 + C B / A 0 ; C D / B 0 ; d 0 .
Using Theorems 1–3, we can write the inequality which guarantees the correctness of the inequality (35) as:
a ( 0 ) μ · a 0 + C B / A 0 ; C D / B 0 ; d 0 .
Furthermore, since in this case a 0 = ( L 1 ) · C D / A 0 ; d 0 , we can write the inequality which guarantees the correctness of inequality (28), using inequality (36):
( 1 β ) · ( 1 ν ) · ( μ · ( L 1 ) · C D / A 0 ; d 0 + C B / A 0 ; C D / B 0 ; d 0 >
> ( 1 + ı ) · Δ · ( L 1 ) · C D / A 0 ; d 0 ,
which provides the condition that the liquidation of the position does not begin at the time when its opened.
Note that C D / B 0 ; d 0 C A / B 0 ; C D / A 0 ; d 0 , and therefore, using inequality (19), we obtain:
C B / A 0 ; C D / B 0 ; d 0 C B / A 0 ; C A / B 0 ; C D / A 0 ; d 0 μ C D / A 0 ; d 0 .
Thus, to fulfill inequality (37), it is sufficient to fulfill the following inequality:
( 1 β ) · ( 1 ν ) · μ · ( L 1 ) · C D / A 0 ; d 0 + μ · C D / A 0 ; d 0 >
> ( 1 + ı ) · Δ · ( L 1 ) · C D / A 0 ; d 0 ,
which is equivalent to the following inequality:
( 1 β ) · ( 1 ν ) · μ · L > ( 1 + ı ) · Δ · ( L 1 ) ,
from which we get the restriction on the maximum value of the leverage as follows:
L max ( B D , A D ) < ( 1 + ı ) · Δ ( 1 + ı ) · Δ ( 1 β ) · μ · ( 1 ν ) .
Note that the obtained inequality (40) for value L max ( B D , A D ) coincides with inequality (30) for L max ( A = D ) ; moreover, the upper bound for L max ( B D , A D ) is only a bit smaller than the upper bound for L max ( B = D ) (34). For these reasons, we set the same value of maximum levarage for all cases of the deposit asset as:
L max = ( 1 + ı ) · Δ ( 1 + ı ) · Δ ( 1 β ) · μ · ( 1 ν ) .
The corresponding numerical results for value (41) of the maximum leverage size are given in Table 1 below. For the calculations, we use the following parameter values: Δ = 1.0002 , μ = 0.994 , β = ı = 0.1 . Value ν max is the maximum value of asset B ’s drop ratio w.r.t. to asset A during the time interval Δ t = 600 s. It is defined and calculated for different time periods and for various pairs of assets, as shown in Appendix A.
To reduce risks, we recommend using a leverage value corresponding to the maximum value of the deposit asset’s drop ratio over a time period of two years.
To set the final value for L max , we round the value in Table 1 to one decimal (fractional leverages are also allowed). As we can see in Table 1, the size of the maximum allowed leverage is about 3, which means that the Trader may use three times the asset value than what the Trader has.

4. Conclusions

In this paper, we introduced a new margin trading protocol, Primex. We provide its comparative analysis with similar existing DeFi protocols and investigate different important questions concerning its secure functioning. We proposed a method which may be applied (with some modifications) to different DeFi protocols, first of all margin trading ones, for setting their parameters (the allowed leverage size, position size, collateralization ratio, etc.) and for setting the liquidation condition. We use mathematical approaches and rigorously proved statements to substantiate our results, and this is one of the main advantages of our proposition.
It should be noted that we use some “idealizing” assumptions for the market model which we work with. The main one is the assumption that all trading operations (and price formation) are fulfilled according to the CPM in some “closed” market space. For the “real” behavior of such processes, we need to take the so-called price impact in account, which may occur every time we exchange one asset to another, and the Oracle deviation, which characterizes the deviation of the Oracle price from DEX prices (because we check the liquidation condition using the Oracle price, but make the asset exchange on some DEXs according to their price). These values cannot be strictly calculated or predicted, because they depend on a huge number of different factors. They may be only estimated with some sufficient level of probability, using sample data, similar to the volatility coefficient, as we describe in Appendix A. Adding price impact and Oracle deviation in our model may cause a reduction in the maximum leverage size, especially in cases with low-liquid assets.
In this work, we did not describe many other questions and results, related to the margin trading protocol, such as Keepers rewards, incentivizing participants, the calculations of different fees, which should cover corresponding protocol risks, and so on. We focused on the priority issues of the maximum leverage size and liquidation conditions, which are critical points in such protocols. We are going to continue our investigations into them in future works.

Author Contributions

Conceptualization, L.K. and V.K.; methodology, L.K. and O.M.; creating code scritps and obtaining numerical results, O.M., Y.M. and N.K.; data collection and processing Y.M. and N.K. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Conflicts of Interest

The authors declare no conflict of interest.

Abbreviations

The following abbreviations are used in this manuscript:
DEXDecentralized exchange
AMMAutomated market maker

Appendix A. Definition of Asset Price Drop and Its Computation (Statistical Data and Analysis of Volatility for Oracle and DEXs)

In this section, we will show how to statistically estimate the probability of one asset falling w.r.t. another over a limited period of time (for example, 10 min), taking into account price volatility and price deviation on different DEXs from the Oracle price.
Due to the high volatility of cryptocurrency markets, attempts to use “classical” financial mathematics—in particular, the approximation of asset price changes by Lognormal Distributions [32] or more complex ones (such as Inverse Normal, the Sum of Inverse Normal and Combined Poisson as well as different variants of the generalized Hypergeometric distribution)—turned out to be unsuitable.
We should estimate the volatility of position asset B w.r.t. to borrowed asset A and take this parameter into account to avoid risks which may occur in the liquidation process. The main points of the risk are as follows:
  • In an ideal situation, we assume that the Keeper performs the liquidation instantly when the liquidation condition is met. However, in reality, some delays may occur, caused by incorrect Keepers’ behavior, connection issues, or a large queue of transactions waiting to be included in the blockchain. During this period of time, the price of the position asset may drop significantly, which may cause losses for Lenders.
  • Keepers use the Oracle price to check liquidation conditions, but actual swaps happen on DEXs. This involves risks of possible losses when the DEXs’ price of asset B is much lower than the corresponding Oracle price, which was used for checking the liquidation condition.
Thus, to reduce risks, we should define the volatility parameter, which takes into account both the volatility of Oracle prices and the deviation of DEXs price from the Oracle price.
To define and estimate such a parameter, we use statistical data obtained and processed in real time, and the forecast for the next time interval (for instance, for the next 10 min) will be recalculated periodically based on updated data on the recent period. Below, we describe the mathematical model used to construct such a prediction.
B 1 , , B n blocks are defined and analyzed. We choose n in such a way that the time creation of these blocks corresponds to some time interval Δ = t 1 , t 2 , 0 t 1 < t 2 (we mostly consider the case when the length of the interval is about t 2 t 1 = 10 minutes, which corresponds to the assumed maximum time of the liquidation).
For two fixed assets, position asset B and borrowed asset A (define P i ( d ) , i = 1 , n ¯ , d = 0 , D ¯ ), with different prices (amount of units of asset A given for one unit of asset B), taken from block B i , corresponding to the d-th DEX, where P i ( 0 ) is the Oracle price. For example, if B = E T H , A = U S D T , and for the i-th block and the d-th DEX 1 E T H = 2000 U S D T , then P i ( d ) = 2000 .
Definition A1. 
For fixed position asset B and borrowed asset A, we will call function P i ( d ) (the function of variable i) a function of the price of asset B with respect to asset A, corresponding to the d-th DEX (or to the Oracle, if d = 0 ).
Note A1. 
Let us put each value t t 1 , t 2 in correspondence with the sequence of blocks B 1 , , B m , 1 m n , which were generated during t 1 , t , and put value t in correspondence with m (for each t, there exists only one corresponding m = m ( t ) ).
Definition A2. 
Value v B / A Δ ( m ) , where 1 m n , is defined as:
ν B / A Δ ( m ) = max max i = 1 , n ¯ max j = i , n ¯ d D { 0 } P i ( 0 ) P j ( d ) P i ( 0 ) , 0 ,
which is called the maximum share of the drop ratio (or simply the maximum drop) of asset B with respect to asset A during the time interval t 1 , t , where t corresponds to the sequence B 1 , , B m , according to the Note A1. In a particular case, when t = t 2 , value ν B / A Δ ( n ) is the maximum share of the drop ratio of asset B w.r.t. asset A during time interval Δ.
Sometimes, we will write ν B / A Δ ( t ) instead of ν B / A Δ ( m ) , following Note A1, if correspondence between t and m = m ( t ) is clear.
Note that if function P i ( d ) increases on interval Δ , then for all t t 1 , t 2 , we get ν B / A Δ ( t ) = 0 .
While choosing the liquidation parameters we need to take the maximum possible value of the asset price drop ratio (during the liquidation) into account, which is value ν B / A Δ t 2 if the time of the liquidation is upper bounded with value t 2 t 1 . For this reason, we will use the empirical distribution function for ν B / A Δ t 2 built on the statistical data gathered during a long period before the liquidation. Due to the high volatility of cryptocurrencies, this distribution function will be periodically recalculated for the most recent period.
We assume that the statistical data for the last month are used to construct the empirical function of value (A1), where the length of interval Δ = t 1 , t 2 is equal to t 2 t 1 = 600 s. That is, we will calculate (A1) using a sliding window with the length of about 600 s, or 40 blocks, for the last month’s data.
At the same time, it is necessary to exclude the possibility that enormous price fluctuations (which happen with negligible probability, such as 10 4 . . 10 3 ) will have a significant impact on the liquidation parameters, which otherwise would lead to situations where positions without real risks will be closed. For this reason, we choose value ν B / A Δ t 2 in the following way. Let us choose a small ε > 0 , for instance, 10 3 or 10 4 . Next, as a value that characterizes the possible drop of asset B (relative to asset A) during liquidation, we choose such ν ε that the probability that value (A1) is larger than ν ε is not greater than the specified ε > 0 , where the probability is estimated on the basis of the empirical distribution function of (A1) for the observed period, for example, for a month.
Now, let us formalize the described approach. Let ν 1 , , ν n be a sequence of values (A1) obtained during the last month using a sliding window Δ = t 1 , t 2 with a length of about 600 s, or 40 blocks. Define value v ε as follows:
ν ε = min C > 0 : # i : ν i C n ε .
Remark.
  • The value of ν ε also depends on assets A and B. In case when these assets are fixed, we omit this dependency to simplify designation.
  • The elements of sequence ν 1 , , ν n take discrete values. For this reason, we cannot set ν ε as ν ε = C , where C is such that:
    P # i : ν i C n = ε ,
    since such a value of C, generally speaking, may not exist. Therefore, for a formal definition of ν ε we use Formula (A2).
In Table A1, below, some examples of values ν ε are given for different ε > 0 , asset pairs, and periods used to construct empirical functions. All the results are obtained for the sliding window corresponding to the time interval of about 10 min, or more precisely, 40 blocks. The empirical data for the calculations were obtained from Binance.
We present values calculated for six crypto pairs, i.e., ETH/BTC, ETH/USDT, BTC/USDT, BTC/ETH, USDT/ETH, and USDT/BTC, and for four time intervals, i.e., 1 week, 1 month, 2 months, and 2 years.
In every cell of Table A1, three values can be observed: ν max —the absolute maximum, obtained according to (A1); ν 0.0001 —such a value that the probability of ν B / A Δ ( t ) from (A1) taking a value larger than ν 0.0001 does not exceed 0.0001; ν 0.001 —such a value that the probability of ν B / A Δ ( t ) from (A1) taking a value larger than ν 0.0001 does not exceed 0.001.
Table A1. Values of ν max , ν 0.0001 , and ν 0.001 for different pairs of assets and periods of time.
Table A1. Values of ν max , ν 0.0001 , and ν 0.001 for different pairs of assets and periods of time.
1 week ( 01 / 10 / 22 01 / 17 / 22 ) 1 month ( 12 / 17 / 21 01 / 17 / 22 ) 2 months ( 11 / 17 / 21 01 / 17 / 22 ) 2 Years ( 01 / 01 / 20 01 / 01 / 22 )
ETH/BTC
ν max ν 0.0001 ν 0.001 0.005579573088 0.0054806912056 0.00510992436 0.010257147337 0.010257147337 0.0073883139 0.031001560968 0.0185985164748 0.00949784649 0.11487824769893985 0.0388133709498163 0.018025525196263242
BTC/ETH
ν max ν 0.0001 ν 0.001 0.00709338767 0.007067593535 0.0061795373948 0.013571437344 0.012831858407 0.00787884620 0.03557556176 0.0288277779 0.00849393637 0.11057776737107078 0.03757731035717723 0.018811304698347325
ETH/USDT
ν max ν 0.0001 ν 0.001 0.0251270588 0.02462910635 0.02044457 0.040140200409 0.03961801959 0.01779619829 0.098705306679 0.058021536356 0.020422584129 0.21104832017869848 0.08524176716140995 0.03618519628408739
USDT/ETH
ν max ν 0.0001 ν 0.001 0.02426152264 0.02426152264 0.01926992508 0.0307072805285 0.0275630547799 0.0194214456240 0.057748014995 0.0483511102810 0.0207973481153 0.17974229664041602 0.07815126362229755 0.03426384903035053
BTC/USDT
ν max ν 0.0001 ν 0.001 0.02246089649 0.0217491793 0.01729139034 0.0294867937 0.02901203209 0.01736979012 0.12953877053149 0.07848763557483 0.01904576006311 0.17634946315634653 0.07745471613669283 0.029683891838515608
USDT/BTC
ν max ν 0.0001 ν 0.001 0.02569541476 0.02569541476 0.01688190026 0.02569541476 0.02432515629 0.01598076319 0.0863199153 0.04744167273 0.02098599663 0.16417910447701194 0.06458050497000786 0.028390791912179008

References

  1. DeFi Protocol. Available online: https://www.pcmag.com/encyclopedia/term/defi-protocol (accessed on 21 May 2023).
  2. Defillama. Available online: https://defillama.com/ (accessed on 21 May 2023).
  3. Metelski, D.; Sobieraj, J. Decentralized Finance (DeFi) Projects: A Study of Key Performance Indicators in Terms of DeFi Protocols’ Valuations. Int. J. Financial Stud. 2022, 10, 108. [Google Scholar] [CrossRef]
  4. Aspembitova, A.T.; Bentley, M.A. Oracles in Decentralized Finance: Attack Costs, Profits and Mitigation Measures. Entropy 2023, 25, 60. [Google Scholar] [CrossRef] [PubMed]
  5. Steve, E.; Juels, A.; Nazarov, S. Chainlink: A Decentralized Oracle Network. Available online: https://research.chain.link/whitepaper-v1.pdf (accessed on 21 May 2023).
  6. Chainlink 2.0: Next Steps in the Evolution of Decentralized Oracle Networks. Available online: https://chain.link/whitepaper (accessed on 21 May 2023).
  7. Oraclize. A Scalable Architecture for On-Demand, Untrusted Delivery of Entropy. Available online: https://provable.xyz/papers/random_datasource-rev1.pdf (accessed on 21 May 2023).
  8. Adams, H.; Zinsmeister, N.; Salem, M.; Keefer, R.; Robinson, D. Uniswap v3 Core. Available online: https://uniswap.org/whitepaper-v3.pdf (accessed on 21 May 2023).
  9. Angeris, G.; Chitra, T. Improved Price Oracles: Constant Function Market Makers. In Proceedings of the 2nd ACM Conference on Advances in Financial Technologies (AFT’20), Association for Computing Machinery, New York, NY, USA, 21–23 October 2020; pp. 80–91. [Google Scholar] [CrossRef]
  10. Angeris, G.; Kao, H.T.; Chiang, R.; Noyes, C.R.; Chitra, T. An Analysis of Uniswap Markets. Cryptoecon. Syst. 2021. Available online: https://classic.curve.fi/files/stableswap-paper.pdf (accessed on 21 May 2023). [CrossRef]
  11. Tsepeleva, R.; Korkhov, V. Building DeFi Applications Using CrossBlockchain Interaction on the Wish Swap Platform. Computers 2022, 11, 99. [Google Scholar] [CrossRef]
  12. DeFi Protocols Explained: Its Function and Types. Available online: https://idealogic.dev/defi-protocols-explained-its-function-and-types/ (accessed on 21 May 2023).
  13. Egorov, M. Curve Finance Automatic Market-Making with Dynamic Peg. Swiss Stake GmbH. Available online: https://classic.curve.fi/files/crypto-poolspaper.pdf (accessed on 21 May 2023).
  14. Martinelli, F.; Mushegian, N. A Non-Custodial Portfolio Manager, Liquidity Provider, and Price Sensor. v2019-09-19. Available online: https://balancer.fi/whitepaper.pdf (accessed on 21 May 2023).
  15. Hertzog, E.; Benartzi, G.; Benartzi, G. Bancor Protocol. Available online: https://whitepaper.io/document/52/bancor-whitepaper (accessed on 21 May 2023).
  16. AAVE. Protocol Whitepaper V1.0. Available online: https://github.com/aave/aave-protocol/blob/master/docs/Aave_Protocol_Whitepaper_v1_0.pdf (accessed on 21 May 2023).
  17. Compound: The Money Market Protocol Version 1.0. Available online: https://compound.finance/documents/Compound.Whitepaper.pdf (accessed on 21 May 2023).
  18. The Maker Protocol: MakerDAO’s Multi-Collateral Dai (MCD) System. Available online: https://makerdao.com/en/whitepaper (accessed on 21 May 2023).
  19. Nexus Mutual V2: Live on Ethereum Mainnet. Available online: https://nexusmutual.io/blog/nexus-mutual-v2-live-on-ethereum-mainnet (accessed on 21 May 2023).
  20. Etherisc. Make Insurance Fair and Accessible. Available online: https://etherisc.com/ (accessed on 21 May 2023).
  21. Peterson, J.; Krug, J.; Zoltu, M.; Williams, A.K.; Alexander, S. Augur: A Decentralized Oracle and Prediction Market Platform. arXiv 2022, arXiv:1501.01042. [Google Scholar]
  22. Gnosis Whitepaper. Available online: https://www.securities.io/gnosiswhitepaper/ (accessed on 21 May 2023).
  23. TokenSets. Asset Management for a DeFi World. Available online: https://www.tokensets.com/ (accessed on 21 May 2023).
  24. Constant Function Market Makers. Available online: https://uniswapv3book.com/docs/introduction/constant-function-market-maker/ (accessed on 21 May 2023).
  25. 1inch Documentation Portal. Introduction. Available online: https://docs.linch.io/docs/aggregation-protocol/introduction (accessed on 21 May 2023).
  26. Handbook of ParaSwap. Available online: https://doc.paraswap.network/ (accessed on 21 May 2023).
  27. GMX. Available online: https://gmxio.gitbook.io/gmx/ (accessed on 21 May 2023).
  28. Juliano, A. dYdX: A Standard for Decentralized Margin Trading and Derivatives. Available online: https://whitepaper.dydx.exchange/ (accessed on 21 May 2023).
  29. Limpert, E.; Stahel, W.A.; Abbt, M. Log-normal Distributions across the Sciences: Keys and Clues: On the charms of statistics, and how mechanical models resembling gambling machines offer a link to a handy way to characterize log-normal distributions, which can provide deeper insight into variability and probability-normal or lognormal: That is the question. BioScience 2001, 51, 341352. [Google Scholar] [CrossRef]
  30. Primex.Finance. Non-Custodial Prime Brokerage Protocol. Available online: https://blog.Primex.finance/ (accessed on 21 May 2023).
  31. Hainaut, D.; Leonenko, N. Option pricing in illiquid markets: A fractional jump-diffusion approach. J. Comput. Appl. Math. 2021, 381, 112995. [Google Scholar] [CrossRef]
  32. Breymann, W.; Lüthi, D. Ghyp: A Package on Generalized Hyperbolic Distributions. 2009. Available online: https://cran.rproject.org/web/packages/ghyp/vignettes/Generalized (accessed on 21 May 2023).
Table 1. Maximum leverage values L max , calculated according to (41) for different asset pairs A / B (A is the borrowed asset, B is the position asset) and for corresponding values ν max ν max is the maximum price drop of asset B w.r.t. asset A, described and calculated in Appendix A, taken over a time period of 2 years ( 01 / 01 / 20 01 / 01 / 22 ) and over time interval Δ t = 600 ) .
Table 1. Maximum leverage values L max , calculated according to (41) for different asset pairs A / B (A is the borrowed asset, B is the position asset) and for corresponding values ν max ν max is the maximum price drop of asset B w.r.t. asset A, described and calculated in Appendix A, taken over a time period of 2 years ( 01 / 01 / 20 01 / 01 / 22 ) and over time interval Δ t = 600 ) .
PairsETH/BTCBTC/ETHETH/USDTUSDT/ETHBTC/USDTUSDT/BTC
L max 3.553.602.782.993.023.11
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Kovalchuk, L.; Kostanda, V.; Marukhnenko, O.; Kuchynska, N.; Marchuk, Y. The Method of Choosing Parameters for Margin Trading Protocols in the Constant Product Model. Mathematics 2023, 11, 4158. https://doi.org/10.3390/math11194158

AMA Style

Kovalchuk L, Kostanda V, Marukhnenko O, Kuchynska N, Marchuk Y. The Method of Choosing Parameters for Margin Trading Protocols in the Constant Product Model. Mathematics. 2023; 11(19):4158. https://doi.org/10.3390/math11194158

Chicago/Turabian Style

Kovalchuk, Lyudmila, Volodymyr Kostanda, Oleksandr Marukhnenko, Nataliia Kuchynska, and Yuliia Marchuk. 2023. "The Method of Choosing Parameters for Margin Trading Protocols in the Constant Product Model" Mathematics 11, no. 19: 4158. https://doi.org/10.3390/math11194158

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop