Protocol Maths
POOL STRUCTURE MATHS
Bin limits
Nitro Finance uses 128.128 binary fixed-point representation, where the left 128 bits represent integers and the right 128 bits represent fractional parts. The upper limit of the price is constrained by 2128, a significant value that ensures a broad range for asset pricing.
how many bins could we possibly have?
Bin prices follow a geometric sequence, denoted as (1+s)i. We now need to find the maximum integer for i such that the entire value is less than the upper limit of price, 2128This can be expressed as the formula ((1+s)i<2128).
Taking the smallest possible value of bin step(s) which is 1 basis point, we can solve this as follows:
(1+0.0001)i<2128n
log2(1.0001)i<log2(2128)
i⋅log2(1.0001)<128
i<log2(1.0001)128≈887,273,
i=887,273
The above equation shows how many bins are needed to cover the entire range when i is a positive integer, so we account for when it is negative by doubling it which equals to 2×887,272=1,774,544 bins.
Bin Indexing
the Nitro Finance system uses the uint24 data type. It's sufficient to cover the range of possible bins,
uint24 is 224−1=16,777,215
Range: 0 to 16,777,215
Minimum Value: 0
Maximum Value: 16,777,215
Every bin is assigned a unique identifier (bin ID) based on a mathematical relationship between the bin's price and a fixed reference point within the system.
Reference Point=2(16,777,215−0)+1=216,777,216=8,388,608
bin Id=log(1+10000bin Step)log(Price)+8388608
bin Step(s) is in basis points, converted to a decimal.
Price is the specific price level for calculating the bin ID.
8388608 is the midpoint of the range.
Bin pricing
The price of each bin is a function of the pair’s bin step and the bin’s index, The bin step parameter determines the constant percentage increase or decrease in price between each incremental bin.
8388608= reference point
Pricebin=(1+bin step)(bin index−8388608)
LIQUIDITY STRUCTURE MATHS
Bin liquidity
The total liquidity in a bin: P.(X+Zx)+(Y+Zy)=LT
Available liquidity in a bin: P.(X)+(Y)=LA
P= price in terms of Y X= base asset Y= quote asset Zy= collateralized quote asset Zx= collateralized base asset
Bin composition
The Liquidity Composition factor (Lc) determines the ratio of the base asset to the quote asset. Lc=YX
The debt composition factor (Dc) determines the debt ratio.
Dc=LTZy+(P.Zx)
Dc = 0: There is no debt in the bin
Dc > 1: There is debt in the bin
BASIC INTERACTION MATHS
Adding liquidity
Adding liquidity to a bin will conserve the (Lc) of the bin. If a certain quantity of X (base asset) is determined, it is possible to compute the associated amount of Y (quote asset) to be added, and vice versa.
Liquidity added (L) = P.∆x+∆y
Bin Shares Received (B):
When adding, you will receive bin shares representing the liquidity added. B=LTL×TBS
Removing liquidity
Removing liquidity results in the burning of Bin shares(B) which results in the receipt of assets X, and Y from the pool, and the minting of B (bin shares) associated with debt.
X,Y,B=TBSB×(Rx,Ry,Dc×TBS)
L = liquidity added B = bin shares TBS = total bin shares LT= total liquidity Dc = debt composition Rx= X reserve. hhh Ry = Y reserve
Swaps
Selling Base Asset (X) for Quote Asset (Y): ∆y=P×∆x
Buying Base Asset (X) with Quote Asset (Y): ∆x=P∆y
DEBT INTERACTION MATHS
Borrowing:
Below Active Bin:
Collateralize base asset (X), borrow quote asset (Y).
∆y=P×∆Zx
Above Active Bin:
Collateralize quote asset (Y), borrow base asset (X).
∆x=P∆Zy
Repaying:
Below Active Bin:
Return borrowed Y, retrieve collateralized X.
∆Zx=P∆y
Active Bin ID ≤ Borrow Bin ID ⇒ Repayment ≠ Possible
Above Active Bin:
Return borrowed X, retrieve collateralized Y.
∆Zy=P×∆x
Active Bin ID ≥ Borrow Bin ID ⇒ Repayment ≠ Possible
Debt rollover
Extends the lifespan of a debt to its default duration (Td)
Td = Default debt lifespan (7 days in this case)
Trem= Remaining time to expiry
Troll= New lifespan of the debt after rollover
Debt rollover is represented as:
Trollover=Tdefault
regardless of Trem=Time remaining, the lifespan is reset to Td= default time once a rollover occurs.
Blacklist (Auto debt recovery)
When the remaining time of a debt reaches zero, the debt is blacklisted and becomes liquidatable.
Trem= 0 ⇒ Blacklist⇒ Liquidatable
Blacklisted debts automatically absorb the collateral into the liquidity pool.
Buffer Range:
Buffer Range: ±bins, indicating the range on either side of the active bin functioning as a safeguard to preserve liquidity for swaps and prevent liquidity depletion due to borrowing activities
±bins=sBP
Buffer percent (Bp): A predetermined percentage.
Bin Step (s): The rate of price change between each bin.
Implications:
Borrow and Debt Rollover:
Allowed={0,1,if within buffer range (±bins)otherwise
Repayment and Liquidation:
Always Allowed=1
FEE MATHS
Swap Fee (F):
The Swap Fee applies to all token exchanges within the liquidity pool.
F=Base factor×Bin step
Base Factor: A multiplier set by the protocol to adjust the fee rate as needed.
Bin Step: The percentage price difference between consecutive bins.
Borrow Fee (Bf)
The Borrow Fee is incurred when initiating a borrowing position.
Bf=F×Borrowfactor
Borrow Factor: A multiplier set by the protocol to control borrowing costs independently of swap fees.
Streaming of Borrow Fee: seconds in 7-days of debtBin fee reserve=λ
Where λ is the per-second fee allocation from the bin's fee reserve.
Repay Fee (Rf):
The Repay Fee compensates LPs for the opportunity cost of inactive liquidity due to debt.
(Bin activation index- Debt activation index)×F
Bin Activation Index:
The number of times a bin was activated
Debt Activation Index:
Set when borrowing, matching the Bin Activation Index of the bin at that time.
Debt Rollover Fee:
The Debt Rollover Fee applies when a borrower extends their debt's lifespan.
DRF=F+Rf
F: The Swap Fee.
Rf: The Repay Fee.
Last updated