Protocol Maths
POOL STRUCTURE MATHS
Bin limits
Nitro Finance uses 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 , 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 . We now need to find the maximum integer for such that the entire value is less than the upper limit of price, This can be expressed as the formula .
Taking the smallest possible value of bin step() which is 1 basis point, we can solve this as follows:
n
,
The above equation shows how many bins are needed to cover the entire range when is a positive integer, so we account for when it is negative by doubling it which equals to bins.
Bin Indexing
the Nitro Finance system uses the uint24 data type. It's sufficient to cover the range of possible bins,
uint24
is
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.
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.
reference point
LIQUIDITY STRUCTURE MATHS
Bin liquidity
The total liquidity in a bin:
Available liquidity in a bin:
= price in terms of Y = base asset = quote asset = collateralized quote asset = collateralized base asset
Bin composition
The Liquidity Composition factor (Lc) determines the ratio of the base asset to the quote asset.
The debt composition factor (Dc) determines the debt ratio.
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) =
Bin Shares Received (B):
When adding, you will receive bin shares representing the liquidity added.
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.
= liquidity added = bin shares = total bin shares = total liquidity = debt composition = X reserve. hhh = Y reserve
Swaps
Selling Base Asset (X) for Quote Asset (Y):
Buying Base Asset (X) with Quote Asset (Y):
DEBT INTERACTION MATHS
Borrowing:
Below Active Bin:
Collateralize base asset (X), borrow quote asset (Y).
Above Active Bin:
Collateralize quote asset (Y), borrow base asset (X).
Repaying:
Below Active Bin:
Return borrowed Y, retrieve collateralized X.
Active Bin ID ≤ Borrow Bin ID ⇒ Repayment ≠ Possible
Above Active Bin:
Return borrowed X, retrieve collateralized Y.
Active Bin ID ≥ Borrow Bin ID ⇒ Repayment ≠ Possible
Debt rollover
Extends the lifespan of a debt to its default duration
= Default debt lifespan (7 days in this case)
= Remaining time to expiry
= New lifespan of the debt after rollover
Debt rollover is represented as:
regardless of =Time remaining, the lifespan is reset to = 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.
= 0 ⇒ Blacklist⇒ Liquidatable
Blacklisted debts automatically absorb the collateral into the liquidity pool.
Buffer Range:
Buffer Range: , 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
Buffer percent : A predetermined percentage.
Bin Step (s): The rate of price change between each bin.
Implications:
Borrow and Debt Rollover:
Repayment and Liquidation:
FEE MATHS
Swap Fee (F):
The Swap Fee applies to all token exchanges within the liquidity pool.
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.
Borrow Factor: A multiplier set by the protocol to control borrowing costs independently of swap fees.
Streaming of Borrow Fee:
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:
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.
F: The Swap Fee.
Rf: The Repay Fee.
Last updated