TUNDRA Lending Protocol
This page is the mechanism underneath Lending (TUNDRA). For reading markets and building transactions, see the developer guide. For every contract id, see the contract reference.
TUNDRA is a fork of Morpho Blue running on alkanes. Where alkanes allows Morpho Blue's behaviour, it is reproduced exactly, constants included. Where it does not, the difference is stated below. What TUNDRA keeps above all is Morpho Blue's trust model: markets are created by anyone, a market's risk parameters are fixed forever, and governance cannot pause, seize or retune anything that is live.
Architecture
TUNDRA factory 4:881050
(registry: market id -> pool, enable-lists, fee settings)
| |
pool 2:98445 pool 2:98619
DIESEL -> frUSD market DIESEL -> frBTC market
holds only its own tokens holds only its own tokens
| | | |
oracle 4:727967 IRM 4:674184 oracle 4:727968
\______________ TUNDRACLE 4:9010 _____/
The factory
The factory (4:881050) does four things:
- Creates markets.
CreateMarketis permissionless. It clones the pool template (4:668244) for the new market, initializes the clone, verifies it, and recordsmarket id -> poolin its registry. - Keeps the enable-lists. A market can only use an interest rate model (IRM) and an LLTV that governance has enabled. Enabling is one-way: once enabled, an IRM or LLTV can never be disabled.
- Holds the fee settings. The default fee every new market starts at (10% today) and the fee recipient.
- Answers discovery.
GetPool(market id)is the only authority on which contract serves a market.
The factory holds no user funds and has no user operations. Users call pools directly.
One pool per market
Upstream Morpho Blue is one contract holding every market. TUNDRA instead clones a separate pool contract for each market. A pool holds only its own market's tokens and carries the whole user surface: supply, withdraw, borrow, repay, add collateral, close, liquidate and flash loans.
This is the largest departure from upstream, and it buys isolation: a ledger bug reaches one market's tokens, not every market's, and a flash loan can only lend what that one pool holds. The trust model does not change.
Pool units are the supply token
Each pool is also its own token. Supplying mints the pool's own units to the supplier, and withdrawing burns them. There is no separate share token and no external mint or burn opcode.
Interest raises the pool's total supplied assets while the number of units stays the same, so each unit redeems for more over time. Holding the units is the claim: there is no supply-side registration, and units can be transferred or held by other contracts like any alkane.
A new pool opens at 1,000,000 units per base unit of the loan token (Morpho Blue's virtual shares, which defend against the "inflation" attack on an empty pool). Pool names are Tundra Pool <first 8 hex digits of the market id>, with the symbol TUN-P.
Governance is one bearer token
Governance is a single indivisible token: one unit of the factory's own id, 4:881050, minted when the factory was deployed. Holding the UTXO that carries it is governance, and handing it over is spending it. The same token authorizes SetFee on every pool.
What governance can do:
- enable an interest rate model,
- enable an LLTV,
- set a market's fee, up to 25% of interest,
- set the default fee for markets created later,
- name the fee recipient.
What governance cannot do: pause a market, seize or move a position, change a live market's oracle, interest model, LLTV or minimum borrow, upgrade a pool, or stop a liquidation. If the governance token were ever lost, every market would keep working exactly as before; only the enable-lists and fee settings would freeze.
Today the enabled LLTVs are 35% and 40%, and the enabled IRM is the adaptive curve model at 4:674184.
Markets and market ids
A market is defined by six parameters, encoded as ten little-endian u128 words:
| words | parameter |
|---|---|
| 1-2 | loan token (block, tx) |
| 3-4 | collateral token |
| 5-6 | oracle |
| 7-8 | interest rate model |
| 9 | LLTV, scaled by 1e18 |
| 10 | minimum borrow, in loan token base units (0 disables it) |
The market id is the SHA-256 of those 160 bytes (Morpho Blue uses keccak256; alkanes has only SHA-256). Two people who agree on the parameters agree on the market without coordinating, and changing any parameter produces a different market. That is why no parameter can be changed: a "changed" market is simply another market.
The minimum borrow is a TUNDRA addition. Upstream has five fields. See Minimum borrow.
Discovery rule
Anyone can clone the pool template with made-up parameters, and a fake pool can answer every view however its creator likes. A pool is a real TUNDRA market only if both of these hold:
pool.GetFactory() == 4:881050
factory.GetPool(pool.GetMarketId()) == pool
The SUBFROST app and the liquidation bot refuse any pool that fails this check.
Accounts and positions
An alkanes contract cannot pay an address. It returns tokens in its response, and the runtime routes them to the output the transaction's pointer names. TUNDRA builds its ownership model on that.
- Suppliers hold pool units, so they need no account.
- Borrowers own a position, keyed by an owner and a salt. An owner is either:
- a script (a Bitcoin output script, such as a taproot address). This is how a person borrows. The salt must be 0, so each script has one position per market.
- an alkane (a contract). The salt lets one contract keep many positions.
The position key is:
key = sha256(owner_encoding || salt as 16 bytes little-endian)
owner_encoding = 0x01 || script length (1 byte) || script (script owner)
= 0x00 || block (16 bytes LE) || tx (16 bytes LE) (alkane owner)
A script-owned position is authorized by proving the payout lands on that script: the pool reads its own transaction, finds its own protostone, and checks that the protostone's pointer is a real output whose script is the owner's. Three rules make that safe:
- Top-level calls only. A script owner's authorization only counts in a top-level protostone, because routing to the pointer only happens there. A contract cannot act for a script owner. A contract that wants to manage a position must own it as an alkane owner.
- No edicts on an authorized message. The runtime applies a protostone's edicts after it routes the response, so an edict could move a payout away from the owner after the check passed. The pool refuses any authorized message that carries an edict. In practice, tokens are moved into the call by an earlier, edict-only protostone.
- The pointer must be a real output, not a later protostone.
What each operation needs:
| operation | effect on the owner | authorization |
|---|---|---|
| supply, add collateral, repay | value in, health improves | none |
| withdraw | burns pool units the caller sends | the units themselves |
| open or add to a borrow | debt up | the loan must be paid to the owner (pointer) |
| close (debt at zero) | collateral returned | the collateral must be paid to the owner (pointer) |
| liquidate | permissionless, as upstream | none |
| flash loan | atomic, creates no position | none |
Adding to a borrow. A second borrow by the same owner merges into the existing position, and is admitted only if:
- it does not raise the position's ratio of debt to collateral. With existing debt
D, collateralC, and an addition ofddebt andccollateral,d × C <= D × c. This needs no price, so it holds at any price; - the merged position is healthy at the oracle price.
Together these make borrowing against someone else's position pointless: the loan goes to the owner, and the owner's ratio cannot get worse.
No partial collateral withdrawal. Collateral leaves a position only through ClosePosition (all of it, debt must be zero) or liquidation. A borrower who wants less collateral repays, closes and reopens.
Interest
Interest accrues per block, because a contract on Bitcoin can read the block height but not a clock. Every rate is per block, against 52,560 blocks a year. Bitcoin blocks usually come slightly faster than every ten minutes, so borrowers pay a little over the nominal annual rate, and suppliers receive the same small excess.
The adaptive curve IRM
4:674184 is Morpho Blue's AdaptiveCurveIRM, with the same constants:
| constant | value |
|---|---|
target utilization u* | 90% |
curve steepness k | 4 |
| initial rate at target | 4% a year |
| rate at target bounds | 0.1% to 200% a year |
| adjustment speed | 50 a year |
With utilization u, the normalized error is:
e = (u − u*) / u* if u <= u*
e = (u − u*) / (1 − u*) if u > u*
The borrow rate is a multiple of the current rate at target r_t:
r = r_t × (1 + (1 − 1/k) × e) if e < 0 (r_t / 4 at u = 0)
r = r_t × (1 + (k − 1) × e) if e >= 0 (4 × r_t at u = 1)
Between accruals the rate at target adapts exponentially:
r_t(new) = r_t × exp(speed × e × elapsed blocks / 52,560)
clamped to the bounds. At e = ±1 that doubles or halves r_t roughly every five days. The rate charged over an interval is an average along that path, so one long gap between accruals costs the same as many short ones. The IRM keeps one rate at target per calling pool.
Accrual and fees
Supply, withdraw, borrow, repay and liquidate accrue interest first. For n blocks at per-block rate r, interest is total borrowed × (e^(r·n) − 1), computed with Morpho Blue's third-order Taylor expansion. The interest is added to both total borrowed and total supplied.
The fee takes a share of each accrual. It is minted as new pool units for the fee recipient, valued exactly at the fee amount, so it does not dilute itself. The recipient collects them with ClaimFee. Both live markets started at the factory's 10% default; the maximum is 25%.
supplier rate = borrow rate × utilization × (1 − fee)
Health and liquidation
Health
Prices are in the oracle's scale: loan token base units per collateral base unit, times 1e27.
max borrow = collateral × price / 1e27 × LLTV
healthy ⇔ debt <= max borrow
Debt is computed from the position's borrow shares, rounded up. A position with no debt is always healthy.
Liquidation
Any unhealthy position can be liquidated by anyone. The liquidator names either how much collateral to seize or how many borrow shares to repay, and the other is computed with the liquidation incentive factor:
LIF = min(1.15, 1 / (1 − 0.5 × (1 − LLTV)))
seized collateral value = repaid debt × LIF
Upstream uses a cursor of 0.3 in that formula. TUNDRA uses 0.5, because a liquidator on Bitcoin cannot react within a block, pays a real fee per attempt and can lose the race for inclusion, so the bonus has to cover a fixed cost rather than a competitive one. The 1.15 cap is upstream's.
| LLTV | LIF | liquidator bonus |
|---|---|---|
| 40% | 1.15 (capped) | 15.00% |
| 77% | 1.130 | 12.99% |
| 86% | 1.075 | 7.53% |
For both live markets (LLTV 40%) the bonus is a flat 15%.
There is no close factor: a position can be liquidated in full in one call. If a liquidation takes the last of a position's collateral while debt remains, that debt is bad debt and is written off against the suppliers in the same call by reducing total supplied assets. There is no insurance fund.
The cushion. A position at the limit stops being fully clearable when the price falls below LLTV × LIF of the price at which it became liquidatable. The safe drop from that point is 1 − LLTV × LIF: 54% at LLTV 40%.
Callbacks. Liquidate takes an optional callee. With one set, the pool settles its own state first, sends the seized collateral to the callee, and takes the repayment out of what the callee returns; anything else the callee returns goes to the liquidator. This lets a liquidator with no loan tokens sell the collateral and repay in the same transaction. 4:999999 is such a callee: it sells through the AMM factory 4:65522 and reverts the whole liquidation if the sale cannot cover the debt. See Running a liquidator.
Minimum borrow
A position too small to be worth liquidating becomes bad debt in a crash. TUNDRA adds a sixth market parameter, the minimum borrow, enforced on chain:
- at open and at add, against the position's total debt;
- on a partial repay, which is capped so that exactly the minimum remains (the excess is refunded) unless the repay clears the whole debt;
- on a partial liquidation, which may not leave a remainder below the minimum. A full liquidation, or one that takes all the collateral, is always allowed.
The live minimums (3,000 frUSD and 0.035 frBTC) were sized so that the 15% bonus covers three liquidation attempts at a crash-level fee of about 450 vB at 300 sat/vB.
Choosing the LLTV
Before the first market was listed, 347 days of hourly DIESEL / frBTC prices (8,322 candles) was used to count how often each candidate LLTV's cushion would have been broken within one to eight hours. At LLTV 40% there were no breaches within two hours, and a replay of the worst crash in the sample (a 57.5% fall) liquidated cleanly. LLTVs of 60% and above broke their cushion repeatedly in the same sample. Governance enabled 35% and 40% only.
The oracle
TUNDRA follows Morpho Blue in having one oracle function per market: price(), opcode 2, returning loan units per collateral unit at 1e27. Each market names its own oracle adapter, and both live adapters read TUNDRACLE (4:9010):
| adapter | reads | price |
|---|---|---|
4:727967 | TUNDRACLE market 4 | DIESEL in US dollars, used as frUSD per DIESEL |
4:727968 | TUNDRACLE market 5 | DIESEL / frBTC, a ratio of two feeds |
TUNDRACLE reports at 1e8, so each adapter multiplies by 1e19 to reach 1e27. The adapter settings are fixed at deployment, because the adapter's id is part of the market id.
Where the prices come from
TUNDRACLE subscribes to DOOMACLE (4:9000), the SUBFROST oracle. Prices are written to DOOMACLE by the DOOMACLE signing group, a 6-of-9 FROST threshold group whose address is bc1pp9xj9ww24x5wenae96dpj3jtxnvrwehn4gqtam7xfc0dfwcmn2rqnms0du. Six of the nine signers must agree on the exact transaction before a price is written.
The prices are read from Bitcoin itself, from on-chain AMM pools, so every signer computes the same number from the same chain state:
- BTC from the frBTC / frUSD pool (
4:1778), - DIESEL from the DIESEL / frBTC pool (
2:77087), multiplied by BTC, - frBTC equal to BTC, by the custody peg,
- frUSD fixed at $1.
Each price is the median of 12 samples taken 12 blocks apart, a window of 144 blocks (about one day). A median ignores a single manipulated sample, so moving a pool for one block does not move the price. The cost is lag: a real move reaches the oracle gradually.
The freshness gate
Each TUNDRACLE feed is stale when it has not been updated for more than 144 blocks. A ratio market (like DIESEL / frBTC) is fresh only when both of its feeds are fresh.
TUNDRACLE keeps a stale price rather than zeroing it, because a zero price would make every position liquidatable at once. The TUNDRA adapter therefore reverts when the price is not fresh. The effect on a pool:
| operation | needs a price | with a stale price |
|---|---|---|
| open or add to a borrow | yes | refused |
| liquidate | yes | refused |
| supply, withdraw | no | works |
| repay, add collateral, close | no | works |
So a market with a stale feed freezes new risk but can always be wound down.
Fees
| fee | value | who sets it |
|---|---|---|
| Protocol fee on interest | 10% on both markets | governance, up to 25% per market |
| Default fee for new markets | 10% | governance |
| Supply, withdraw, borrow, repay | none beyond the Bitcoin network fee | |
| Flash loans | free |
The fee recipient is named on the factory (GetFeeRecipient, opcode 107) and is listed in the contract reference.
Compared with Morpho Blue
| Morpho Blue | TUNDRA | |
|---|---|---|
| Layout | one singleton contract | a factory and one pool per market |
| Supply position | shares in a ledger | the pool's own token (pool units) |
| Accounts | Ethereum addresses | a Bitcoin script (authorized by where the payout lands) or an alkane (authorized by caller) |
| Market parameters | 5 | 6: adds a minimum borrow |
| Market id | keccak256 | SHA-256 |
| Time | seconds | blocks (52,560 a year) |
| Oracle scale | 1e36 | 1e27 (1e36 does not fit in a 128-bit word) |
| Liquidation cursor | 0.3 | 0.5 |
| Borrowing into a position | owner or approved operator | anyone, but it must not raise the debt ratio and the loan goes to the owner |
| Partial collateral withdrawal | yes | no; close and reopen |
| Governance | an owner address | a bearer token |
| New market fee | 0 until set | starts at the default fee |
| Unchanged | 25% max fee, 1.15 max incentive, virtual shares, rounding directions, the adaptive IRM and its constants, immediate bad debt, permissionless creation, frozen parameters |
Upstream's MetaMorpho vault layer is not part of TUNDRA.
Next steps
- Lending (TUNDRA): the user guide.
- TUNDRA developer guide: reads, transactions and liquidation.
- TUNDRA contract reference.
- The Oracle.