> For the complete documentation index, see [llms.txt](https://docs.gage.cash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gage.cash/protocol/invariants.md).

# Security invariants

The properties the contracts hold at all times, each one a test in the suite: vault, engine, token and Earn.

Each of these is a property, fuzz or invariant test in the contract suite. They are the promises the rest of this documentation rests on. The first table is V1 (`DealVault` and the LP extension vaults); the second is the native engines; the third and fourth are the token layer and Earn.

## V1 vault

| #   | Invariant                                                                                                                                                                                                                                                                  |
| --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| I1  | Escrowed collateral is credited out only by `reclaim` to the borrower, `claim` to the lender, or `cancel` to the borrower. Every token the vault holds is either in an open deal or credited to a balance, and open collateral never exceeds the registry's cap.           |
| I2  | The vault has no owner and no admin function. Nothing can move collateral or USDG belonging to a user, change a live deal's cap, term, expiry or parties, delay a reclaim or accelerate a claim.                                                                           |
| I3  | Pausing affects only listing and funding. Cancel, reclaim, claim and withdraw can never be paused.                                                                                                                                                                         |
| I4  | Funding is atomic: escrow becomes the borrower's balance plus the fee, the state becomes FUNDED and the expiry is set, with no intermediate state observable.                                                                                                              |
| I5  | Solvency: the vault's USDG balance is at least the sum of open bid escrows plus the sum of USDG balances, at all times.                                                                                                                                                    |
| I6  | `reclaim` requires exactly the cap and credits exactly the cap to the lender.                                                                                                                                                                                              |
| I7  | A claim never lands before `expiry + grace`. Reclaim stays open until a claim executes, and a reclaim that lands first wins. RECLAIMED and CLAIMED are mutually exclusive.                                                                                                 |
| I8  | Exactly one accepted bid per funded deal, at the deal's price and lender; a bid above the cap, below the asking price, past its expiry, or on a non-LISTED deal is rejected.                                                                                               |
| I9  | The position adapter rejects wrong NFT contracts, unlisted pools, delisted pair tokens, hooks with removal permissions, liquidity at or below the minimum, out-of-range positions when the flag is on, and subscribed positions.                                           |
| I10 | All external token paths are reentrancy-guarded. The vault accepts an NFT only from the PositionManager and only during an in-flight listing.                                                                                                                              |
| I11 | No price is read on-chain except the current tick for the in-range check at deposit. No oracle dependency exists anywhere in the deal path.                                                                                                                                |
| I12 | Code is immutable. Fee and terms are bounded at compile time. The grace is fixed per deployment and never under 24 hours: 48 hours on the V1 vault, at least 24 on each extension vault. The native engines' grace is E2's; the current ones, the Intent cores, have none. |

## Native engines

| #  | Invariant                                                                                                                                                                                                     |
| -- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E1 | The engine has no owner. A registry change gates new listings and funding only; repayment and recovery follow the loan's recorded economics whatever the registry says afterwards.                            |
| E2 | Repayment closes and default finalization opens at the same second, `fundedAt + term + grace`. A loan is repaid on time or it is defaulted, never raced. The grace is fixed at deployment and at most 7 days. |
| E3 | The engine's USDG equals deposits less withdrawals, and every activated loan charges exactly one origination fee.                                                                                             |
| E4 | A loan bridged to the legacy vault follows the engine: it never repays after a default, and every adapter receipt backs exactly one unsettled legacy deal.                                                    |
| E5 | The reward ledger preserves claims already earned; only active loans hold future allocations.                                                                                                                 |
| E6 | A paused or blocked reward token never blocks repayment or recovery.                                                                                                                                          |
| E7 | Every transfer in is checked by balance delta; a fee-on-transfer token cannot be listed or used to pay.                                                                                                       |
| E8 | A reclaim right moves only through the engine's own sale. No plain transfer exists.                                                                                                                           |

## Private lane router

| #  | Invariant                                                                                                                                                                         |
| -- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| P1 | Collateral comes only out of the pool the Entrypoint registers for the token, withdrawn by a valid proof; the router takes nothing from the caller.                               |
| P2 | The proof binds the borrower and every loan term: a call with other terms reverts before anything moves, whoever sends it.                                                        |
| P3 | A borrow needs the screener's attestation of the Entrypoint's latest root, for this token, router and chain, living at most two minutes; a cleared attester refuses every borrow. |
| P4 | The pool must deliver exactly the amount withdrawn, and the router ends every call with the balances it started with.                                                             |
| P5 | The principal open through the router against a token never exceeds that token's cap, itself at most 10,000,000 USDG; only the owner sets caps and the attester.                  |
| P6 | A loan's principal returns to its token's capacity only once the loan has left funding and activity, by repayment or default.                                                     |

## Token layer

| #  | Invariant                                                                                                                                                                               |
| -- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| T1 | sGAGE total supply only ever decreases. It is minted once and burned by the floor's sweeps, by the liquidity-rewards burn path and at the end of emissions.                             |
| T2 | The emissions contract can send sGAGE only to the reward contracts, cumulative emission never exceeds the schedule, and nothing leaves it after week 52 except to the burn.             |
| T3 | Unlocking sGAGE follows only the curve. No function, owner or otherwise, releases it early or slows it.                                                                                 |
| T4 | A deal's reward is at most the rate times the fee paid, and a zero-fee deal earns zero.                                                                                                 |
| T5 | The pool hook never reverts and never changes the result of a swap or a liquidity change. It only records. No token-layer contract ever holds a user's position NFT.                    |
| T6 | DealFeeRouter only buys: deal fees become GAGE in clips within the 1% impact bound and the threshold, deposited into the floor. It never sells GAGE or sGAGE.                           |
| T7 | FeeFloor sends creator fees only to the operations wallet and the floor bands, in the fixed half split. Its bands only ever bid for sGAGE; what a band buys is burned, never sold back. |
| T8 | The reinvest and zap routers end every transaction holding nothing, and the position they mint is owned by the caller.                                                                  |

## Earn, third design

| #  | Invariant                                                                                                                                                |
| -- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| S1 | Value is conserved: cash, the reserve position, open loans at principal and accrued return reconcile with the shares, and USDG held matches the ledgers. |
| S2 | Fees come only from a loan's return, never from principal.                                                                                               |
| S3 | A written-off loan's collateral is held for the holders of record at the write-off, in kind.                                                             |
| S4 | Accrued return is bounded by each loan's fixed cost, and rewards are conserved.                                                                          |
| S5 | Pricing pauses only while a loan past the end of its term is unsettled.                                                                                  |

## How they are tested

Unit and fuzz tests against test tokens that can pause, blocklist and charge transfer fees. Invariant tests run with a handler that exercises every external function and ghost totals for every balance, and fail on any revert the handler did not predict; the engine fixture runs a zero-grace engine over a 48-hour legacy vault. Fork tests run against the live chain state. The suite runs on every commit.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gage.cash/protocol/invariants.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
