Liquidity and Liquidation
5 algorithms in Digital Assets and On-Chain Finance.
In this family#
-
Impermanent-Loss Calculation contract
Value lost by providing liquidity rather than simply holding the two assets. Called impermanent because it reverses if the price returns — which it frequently does not, and the loss is realised on withdrawal.
impermanentLoss(data, config) -
Liquidity-Provider Fee APR contract
Sums attributable fee income over a daily ledger — volume × fee rate × LP share × (1 − protocol share) — divides it by time-weighted average LP capital, then scales the observed period linearly by annualization_days / elapsed_days. The annualisation is simple, not compounded. Impermanent loss, token-price P&L, incentive emissions, range uptime, gas and taxes are all outside this metric.
feeApr(data, config) -
Collateral-Health Factor contract
The ratio of weighted collateral to debt in a lending position. Below 1 the position is liquidatable, which makes it the single number a borrower has to watch.
healthFactor(data, config) -
Liquidation-Price Calculation contract
The collateral price at which a position becomes liquidatable. The number a borrower actually needs — a health factor is abstract, a price is something you can set an alert on.
liquidationPrice(data, config) -
Liquidation Waterfall contract
The order in which collateral is seized and debt repaid, including liquidation bonus and any protocol fee. Determines what a borrower recovers, and it is rarely proportional.
liquidationWaterfall(data, config)
What they share#
Every topic here is a record-transform, so once you have
called one the rest follow the same shape. Import paths differ only in the final segment:
import { impermanentLoss } from "fintech-algorithms/digital-assets-and-on-chain-finance/liquidity-and-liquidation/impermanent-loss-calculation";
import { feeApr } from "fintech-algorithms/digital-assets-and-on-chain-finance/liquidity-and-liquidation/liquidity-provider-fee-apr";Read them in the order above — the sequence is pedagogical, not alphabetical.
Where this sits#
Digital Assets and On-Chain Finance collects 10 algorithms across 2 families. For the concept behind this family rather than the call signatures, see the concept guides.