> For the complete documentation index, see [llms.txt](https://docs.efficientdex.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.efficientdex.com/reference/smart-contracts.md).

# Smart contracts

Every contract behind Efficient and what it does, with the events each one emits and the calls and errors integrators and pool operators meet most.

**Efficient's contracts fall into three groups: shared core, each pool's own, and optional periphery.** This page lists their roles, key calls, events and common errors.

The page describes the contracts of the pending redeployment. [Deployments](/reference/deployments.md) lists the chains, the code each one runs today and when addresses will be published.

A pool's pair is its pool asset and its first loan asset. The loan asset is the token the pool can borrow: USDC, in an Efficient pool that trades BTC against USDC. Any extra token the pool can borrow is a loan asset too.

## Contracts

**Core contracts serve many pools at once.** Each pool has its own authority record and hooks, plus lending-market accounts if it uses lending markets. Periphery is optional, and most of it serves a single pool.

### Core

| Contract            | In code                 | What it does                                                                                                                                                                                                                                                            |
| ------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Factory             | `FLAMMFactory`          | Creates and lists pools. It's also the beacon that holds the code every pool runs. The protocol Safe sets each pool's protocol performance fee through it                                                                                                               |
| Pool implementation | `FLAMMFront`            | The code every pool runs. It handles `swap`, `previewSwap`, `poke`, `recenter` and the reads a swap makes (`switches`, `paused`, `loanConfig`) itself. Most other calls pass to `FLAMM`, the full pool contract. `fullImplementation()` returns that contract's address |
| Financing router    | `MMRouter`              | Factory pools that use lending markets reach them through this one contract. It moves their supply. For a pool that borrows, it also moves collateral and debt. The factory deploys it. It records each pool's loan assets, venues, caps, funding orders and LTV pin    |
| Account deployer    | `MorphoAccountDeployer` | Deploys a pool's lending-market accounts for one venue type, once the pool uses a lending market of that type. Morpho Blue is kind 0 in the code, and the only venue type implemented so far                                                                            |
| Price feed          | `PriceFeed`             | Checked USD prices per token from Chainlink feeds, with no cross rates. A pool names its feed at creation. One feed can serve many pools                                                                                                                                |

### Each pool's own

| Contract                                   | In code                           | What it does                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Pool                                       | `FLAMMProxy`                      | The market and the share token in one contract. It's a beacon proxy, and its beacon is the factory. Integrators call it through `IFLAMM` for swaps, flows, most reads, `poke`, `recenter` and `skimPerformanceFee`. They use `FLAMM`'s ABI for `swapLoan`, `maintainCollateral`, `mintProRata`, the deposit and exit maximums, `pendingHookSet`, and the other governance and upkeep calls |
| Authority contract                         | `EverlongCore`                    | Records the pool's roles: the pool operator, which owns it, and the guardian, keeper and fee receiver the pool operator appoints. The creator supplies it. The pool's `core()` returns it                                                                                                                                                                                                  |
| Deposit allowlist                          | `DepositAllowlist`                | Decides who can receive shares from a deposit. A pool bound to no allowlist contract admits every receiver                                                                                                                                                                                                                                                                                 |
| Invariant, fee and recentring hooks        | `EverlongHook` in Everlong vaults | The three required hooks. The invariant hook prices each fill on the pool's liquidity curve. The fee hook prices its fee. The recentring hook folds in price observations and moves the anchor. A required hook names a single pool, so each pool needs its own                                                                                                                            |
| Controller hook and loan-to-loan swap hook | Optional                          | A controller hook orders a pool's lending markets for certain operations, when the pool has more than one. It can also run maintenance and recentres. A loan-to-loan swap hook prices swaps between loan assets. Both slots are empty in the first Everlong vault                                                                                                                          |
| Lending-market accounts                    | `MorphoBlueAccount`               | One per loan asset and venue type. Each holds the pool's lending-market positions in the account's own name. An account deploys with its first venue, so a pool with no lending market has none                                                                                                                                                                                            |

A pool's shares are ERC-20 tokens with the ERC-4626 views `asset`, `totalAssets`, `convertToShares` and `convertToAssets`. The pool has no ERC-4626 `deposit`, `mint`, `withdraw` or `redeem`.

### Periphery

| Contract           | In code                 | What it does                                                                                                                                              |
| ------------------ | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Lens               | `FLAMMLens`             | Read-only reports on any pool. Calls that need a price return an `ok` flag instead of reverting                                                           |
| `PoolSwapAdapter`  | `PoolSwapAdapter`       | Exact-input swaps against one pool. It refunds unused input and checks the pool's report                                                                  |
| Tycho adapter      | `FLAMMTychoSwapAdapter` | The swap adapter for Tycho by PropellerHeads. It covers every pool the factory has created, for sell orders only                                          |
| Asset router       | `FLAMMAssetRouter`      | Single-asset deposits and exits for one pool with a single loan asset                                                                                     |
| Entry market       | `FLAMMEntryMarket`      | Deposit and exit requests for one pool. A matching request, a maker or anyone calling `crank` settles them                                                |
| DEX aggregator     | `MultiDexAggregator`    | Converts tokens through DEX routers that the pool operator of its one bound pool whitelists. That pool's asset router and entry market convert through it |
| Tranche controller | `TrancheController`     | Splits one pool's shares into a senior and a junior tranche                                                                                               |
| Tranche tokens     | `TrancheToken`          | The senior and junior tokens. Each is an ERC-20 whose asset is the pool share                                                                             |

[Build a hook](/run-a-pool/build-a-hook.md) covers the interfaces each hook implements. For the Everlong hook, see [The Everlong strategy](https://docs.foreverlong.io/everlong/everlong-strategy).

## Key calls

**Most calls go to the pool, and anyone can make most of them.** Each table shows who can call and where it's covered in full.

### On the pool

| Call                                                                                                                                                                         | Who                                                                                             | What it does                                                                                                                                                                                                                                                                                                         | Covered in                                                                                              |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `swap(tokenIn, tokenOut, amountIn, minAmountOut, to, deadline)`                                                                                                              | Anyone                                                                                          | Exact-input swap between the pool asset and the first loan asset, in either direction                                                                                                                                                                                                                                | [Trade](/use-efficient/trade.md)                                                                        |
| `previewSwap(poolAssetIn, amountIn)`                                                                                                                                         | Anyone                                                                                          | Quotes the input used, the output after the fee and the fee rate                                                                                                                                                                                                                                                     | [Trade](/use-efficient/trade.md)                                                                        |
| `swapLoan(assetIn, assetOut, amountIn, minOut, to, deadline)`                                                                                                                | Anyone                                                                                          | Swaps between two loan assets at the loan-to-loan swap hook's price. No loan-to-loan swap hook ships yet. The first Everlong vault has none and feature bit 6 off, so `swapLoan` reverts there with `LoanSwapDisabled`. A pool that needs these swaps adds the hook when it deploys, or later through a new hook set | [Hooks](/how-pools-work/hooks.md)                                                                       |
| `depositProRata`                                                                                                                                                             | Anyone, for a receiver the allowlist admits                                                     | Deposits into every leg of the book in proportion                                                                                                                                                                                                                                                                    | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                                |
| `mintProRata`                                                                                                                                                                | Anyone, for a receiver the allowlist admits                                                     | Mints an exact number of shares for a proportional slice of every leg. It works only while the book owes nothing and within `mintProRataCap`                                                                                                                                                                         | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                                |
| `redeemProRata`                                                                                                                                                              | The share owner or an address it has approved                                                   | Exits every leg in proportion. It repays the shares' slice of debt in the same call                                                                                                                                                                                                                                  | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                                |
| `previewDepositProRata(poolAssets)`, `previewRedeemProRata(shares)`                                                                                                          | Anyone                                                                                          | Quote the shares or the payout, and every leg                                                                                                                                                                                                                                                                        | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                                |
| `maxDepositProRata(receiver)`, `maxRedeemProRata(owner)`                                                                                                                     | Anyone                                                                                          | The largest deposit or exit that would go through now. The deposit maximum reads `type(uint256).max` when no lending-market limit bounds a deposit, as in a pool with no lending market                                                                                                                              | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                                |
| `totalAssets()`, `convertToAssets(shares)`                                                                                                                                   | Anyone                                                                                          | Net asset value, and the value of a number of shares, in the pool asset                                                                                                                                                                                                                                              | [Understanding returns](/use-efficient/provide-liquidity/understanding-returns.md)                      |
| `asset()`, `loanAsset()`, `loanCount()`, `loanConfig(idx)`                                                                                                                   | Anyone                                                                                          | The pool asset, the first loan asset, and each loan asset's settings and balance held                                                                                                                                                                                                                                | [Trade](/use-efficient/trade.md)                                                                        |
| `limits()`, `dials()`, `switches()`, `paused()`, `hooks()`, `pendingHookSet()`, `ceilings()`                                                                                 | Anyone                                                                                          | Limits and fees, the LTV pin and credit setting, feature bits, the pause, the hook set, scheduled changes, and the band and fee-cap ceilings                                                                                                                                                                         | [Roles and governance](/run-a-pool/roles-and-governance.md)                                             |
| `poke()`                                                                                                                                                                     | Anyone                                                                                          | Passes the feed's latest price to the recentring hook. A pool with no price band refuses it with `NoBand`                                                                                                                                                                                                            | [Swaps for aggregators and solvers](/integrate/swaps-for-aggregators-and-solvers.md#price-observations) |
| `maintainCollateral()`                                                                                                                                                       | Anyone                                                                                          | Tops up collateral at the least healthy indebted venue that's due a top-up                                                                                                                                                                                                                                           | [Credit and collateral](/how-pools-work/credit-and-collateral.md#collateral-top-ups)                    |
| `skimPerformanceFee()`, `executePerformanceFee()`                                                                                                                            | Anyone                                                                                          | Charges the performance fee, and applies a due rise in the pool operator's rate                                                                                                                                                                                                                                      | [Fees](/use-efficient/fees.md)                                                                          |
| `proveDebtFree()`                                                                                                                                                            | Anyone                                                                                          | Marks each loan asset the pool no longer owes as debt-free, for example after a liquidation at a lending market                                                                                                                                                                                                      | [Roles and governance](/run-a-pool/roles-and-governance.md#calls-open-to-anyone)                        |
| `recenter(minAnchorN36, maxAnchorN36, deadline)`                                                                                                                             | Keeper, pool operator or controller hook                                                        | Asks the recentring hook to move its anchor, inside the caller's bounds                                                                                                                                                                                                                                              | [Operate a pool](/run-a-pool/operate-a-pool.md)                                                         |
| `setDials(phiWad, ltvWad)`                                                                                                                                                   | Keeper or pool operator                                                                         | Moves the LTV pin and the credit setting inside their limits                                                                                                                                                                                                                                                         | [Credit and collateral](/how-pools-work/credit-and-collateral.md#moving-the-dials)                      |
| `setPriorities`, `maintain(kind, a, b, amount)`                                                                                                                              | Keeper, pool operator or controller hook                                                        | Sets venue order, and tops up, releases, refinances or migrates supply at venues                                                                                                                                                                                                                                     | [Just-in-time financing](/how-pools-work/just-in-time-financing.md)                                     |
| `setPaused(bool)`                                                                                                                                                            | Pool operator or guardian to pause, pool operator to unpause                                    | Stops sells, deposits, observations, recentres and loan swaps. Buys and exits go on                                                                                                                                                                                                                                  | [Roles and governance](/run-a-pool/roles-and-governance.md)                                             |
| `setFeatures`, `setRiskLimits`, `setLoanConfig`, `setLoanCaps`, `setVenueFlags`, `setVenueCaps`, `setOracleBand`, `setFundRecheck`, `setMinSupplyBatch`, `setMintProRataCap` | Pool operator, or the guardian to tighten                                                       | Feature switches, caps, price bands within their ceiling, the oracle band, the fund re-check and each loan asset's execution buffer                                                                                                                                                                                  | [Configure a pool](/run-a-pool/configure-a-pool.md)                                                     |
| `setPoolAssetReserve(venueId, reserve)`, `poolAssetReserve()`                                                                                                                | Pool operator, or the guardian to switch it off                                                 | Sets how far a buy refills the execution buffer, the pool asset held unposted. The rest stays posted. It needs a venue whose venue type pays a return on collateral, and Morpho Blue isn't one                                                                                                                       | [Configure a pool](/run-a-pool/configure-a-pool.md)                                                     |
| `setMarketBand(off, bandWad)`                                                                                                                                                | Pool operator to drop the band, and the pool operator or guardian to attach one                 | Drops the price band. That needs a band ceiling that allows none, no debt, borrowing off, one loan asset and an invariant hook that declares `HOOK_CAP_UNPRICED`. Attaching a band applies at once                                                                                                                   | [Configure a pool](/run-a-pool/configure-a-pool.md)                                                     |
| `scheduleHookSet`, `executeHookSet`, `addVenue`, `addLoanAsset`, `setPerformanceFeeBp`, `setBandAndFeeCeilings`                                                              | Pool operator. The guardian can cancel a scheduled hook set, venue, loan asset or ceiling raise | Changes that wait out the governance delay. A band-ceiling raise waits at least 10 days. A performance fee cut or a ceiling cut applies at once. A hook set also waits at least 10 days while the band ceiling allows no price band, or while a raise to allow none is scheduled                                     | [Roles and governance](/run-a-pool/roles-and-governance.md)                                             |
| `setFeeBounds`, `retireVenue`, `retireLoanAsset`, `seedLeg(assets, to)`                                                                                                      | Pool operator                                                                                   | Sets the fee floor and cap, retires an empty venue or loan asset, or seeds the first loan asset                                                                                                                                                                                                                      | [Configure a pool](/run-a-pool/configure-a-pool.md)                                                     |
| `emergency(kind, id, assets)`                                                                                                                                                | Pool operator or guardian                                                                       | Repays debt, tops up collateral, or recalls supply or collateral at one venue, even during a pause                                                                                                                                                                                                                   | [Credit and collateral](/how-pools-work/credit-and-collateral.md#emergency-calls)                       |

### On the factory and shared contracts

| Contract           | Call                                                                                  | Who                                            | What it does                                                                                                  | Covered in                                                            |
| ------------------ | ------------------------------------------------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| Factory            | `createPool(p, hooks, salt, venues)`                                                  | Anyone                                         | Deploys, initialises and seeds a pool in one call                                                             | [Configure a pool](/run-a-pool/configure-a-pool.md)                   |
| Factory            | `predictPool(creator, salt, p)`                                                       | Anyone                                         | Returns the address `createPool` will deploy, so pool-bound hooks can be deployed first                       | [Configure a pool](/run-a-pool/configure-a-pool.md)                   |
| Factory            | `pools()`, `isPool(pool)`                                                             | Anyone                                         | Every pool the factory has created, and whether an address is one of them                                     | [Integrate](/integrate.md)                                            |
| Factory            | `scheduleImplementation`, `scheduleAccountDeployer`, `scheduleProtocolFee`            | Protocol Safe                                  | Schedules new code for every pool, a new venue type or a rise in a pool's protocol fee. A cut applies at once | [Roles and governance](/run-a-pool/roles-and-governance.md)           |
| Factory            | `executeImplementation()`, `executeAccountDeployer(kind)`, `executeProtocolFee(pool)` | Anyone                                         | Applies a scheduled change once the factory's upgrade delay has passed                                        | [Roles and governance](/run-a-pool/roles-and-governance.md)           |
| Financing router   | `setGlobalPaused(bool)`                                                               | Protocol Safe                                  | Stops or resumes new borrowing and supply for every pool                                                      | [Roles and governance](/run-a-pool/roles-and-governance.md)           |
| Price feed         | `usd(token)`, `peekUsd(token)`, `pair(base, quote)`                                   | Anyone                                         | A token's checked USD price, or two at once. `peekUsd` returns an `ok` flag instead of reverting              | [Price feeds and oracles](/how-pools-work/price-feeds-and-oracles.md) |
| Price feed         | `scheduleOracle`, `executeOracle(token)`                                              | The feed's Safe schedules, and anyone executes | Replaces a token's Chainlink feed, staleness limit and peg band after a delay                                 | [Price feeds and oracles](/how-pools-work/price-feeds-and-oracles.md) |
| Authority contract | `setKeeper`, `setGuardian`, `setFeeReceiver`, `transferOwnership`                     | Pool operator                                  | Appoints roles at once, or hands over the pool operator role. The new address then accepts it                 | [Roles and governance](/run-a-pool/roles-and-governance.md)           |
| Deposit allowlist  | `setDepositorAllowed(depositor, allowed)`, `setEnabled(bool)`                         | Pool operator                                  | Lists or removes a depositor, or switches the list off so anyone can deposit                                  | [Provide liquidity](/use-efficient/provide-liquidity.md)              |

### On the periphery

| Contract                             | Call                                                                 | Who                                                                                                                | What it does                                                                   | Covered in                                                                                          |
| ------------------------------------ | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- |
| Lens                                 | `identity`, `facts`, `config`, `price`, `nav`, `previewSwap`         | Anyone                                                                                                             | Reports on any pool without reverting on a missing price                       | [Swaps for aggregators and solvers](/integrate/swaps-for-aggregators-and-solvers.md#read-only-lens) |
| `PoolSwapAdapter`                    | `swapExactIn(tokenIn, tokenOut, amountIn, minOut, to, deadline)`     | Anyone                                                                                                             | Pulls `amountIn`, swaps through the pool and refunds any unused input          | [Swaps for aggregators and solvers](/integrate/swaps-for-aggregators-and-solvers.md)                |
| Tycho adapter                        | `getPoolIds`, `price`, `getLimits`, `swap`                           | Anyone                                                                                                             | Lists factory pools, then prices, sizes and executes sell orders               | [Swaps for aggregators and solvers](/integrate/swaps-for-aggregators-and-solvers.md)                |
| Asset router                         | `depositFromAsset`, `redeemToAsset`                                  | Anyone deposits, and only the share owner exits                                                                    | Deposits or exits in one token, converting the rest through the DEX aggregator | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                            |
| Entry market                         | `requestDeposit`, `requestRedeem`                                    | Anyone, though a deposit request needs a requester the allowlist admits                                            | Posts a request, escrowing the pool asset or pool shares                       | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                            |
| Entry market                         | `net`, `fill`, `fillPar`, `crank`                                    | Anyone, though a requester can't `fill` or `fillPar` their own request                                             | Settles open requests against each other, from a maker or through the pool     | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                            |
| Entry market                         | `cancel(id)`                                                         | The requester at any time, or anyone once the request expires or the allowlist stops admitting a deposit requester | Returns the escrow to the requester                                            | [Deposits and exits for apps](/integrate/deposits-and-exits-for-apps.md)                            |
| Senior tranche token                 | `deposit`, `depositWithDeadline`, `requestRedeem`, `claimRedeem(id)` | Anyone enters once the pool operator has seeded the tranche. The owner or its operator claims                      | Enters at once, or exits through the seven-day queue                           | [Tranches](/use-efficient/provide-liquidity/tranches.md)                                            |
| Junior tranche token, and controller | `requestDeposit`, `requestRedeem`, then `settleForward(id)`          | Anyone files a request once the tranche is seeded, and anyone fills it                                             | Enters or exits the junior tranche at a later price update                     | [Tranches](/use-efficient/provide-liquidity/tranches.md)                                            |
| DEX aggregator                       | `setDexRouter(index, router)`                                        | Pool operator                                                                                                      | Whitelists a DEX router at an index, or clears it                              | [Roles and governance](/run-a-pool/roles-and-governance.md)                                         |

## Events

**Each contract emits events for the changes it makes.** Every financing router event about a pool carries that pool as an indexed field. The Everlong hook's events appear only on Everlong vaults. Other hooks emit their own.

### Trading and prices

| Event         | Emitted by    | What it records                                                                                                                                                                                                                                                                    |
| ------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Swap`        | Pool          | One swap, whichever curve fills it: caller, recipient, direction, input used, output, fee, fee rate, the hook's price after, gross output and curve position. [Swaps for aggregators and solvers](/integrate/swaps-for-aggregators-and-solvers.md#the-swap-event) gives each field |
| `LoanSwapped` | Pool          | A swap between two loan assets: caller, recipient, both loan-asset indexes, input used and output                                                                                                                                                                                  |
| `Observed`    | Pool          | The feed price and timestamp that a `poke` passed to the recentring hook                                                                                                                                                                                                           |
| `Recentered`  | Pool          | A recentre: the price it used, whether the anchor moved, and the new anchor                                                                                                                                                                                                        |
| `Levered`     | Everlong hook | A fill on the leverage curve: the stable leg the book added or removed, and the hook's frame collateral ratio at the mark before and after. The pool's `Swap` for the same fill follows it                                                                                         |

[The Everlong strategy](https://docs.foreverlong.io/everlong/everlong-strategy#the-leverage-frame) defines the frame collateral ratio in `Levered`. It isn't a lending market's ratio of collateral to debt. The Everlong hook's other events track its price observations, recentres, idle balances and settings, which belong to that strategy.

### Deposits, exits and fees

| Event                                                                                | Emitted by         | What it records                                                                                                                                 |
| ------------------------------------------------------------------------------------ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `ProRataDeposit`, `ProRataRedeem`                                                    | Pool               | A proportional entry or exit: caller, receiver, the owner on an exit, shares, the pool asset, and the first loan asset's net amounts in and out |
| `PerformanceFeeCharged`                                                              | Pool               | A performance fee charge: shares minted for the pool operator's part and the protocol's part, and the high-water mark before and after          |
| `DepositFromAsset`, `RedeemToAsset`                                                  | Asset router       | A single-asset entry or exit: the tokens used, the amount spent, and the shares or payout                                                       |
| `IntentOpened`, `IntentCancelled`                                                    | Entry market       | A new request, with its amount, minimum, maximum discount, ramp and expiry. A cancelled request, with the escrow returned                       |
| `Netted`, `MakerFilled`, `ParFilled`, `CrankFilled`                                  | Entry market       | A settlement through `net`, `fill`, `fillPar` or `crank`: the amount settled, what the requester received, and the discount or value per share  |
| `TrancheDeposit`, `TrancheRedeem`                                                    | Tranche controller | An entry into or exit from either tranche, in pool shares and tranche shares                                                                    |
| `RedeemRequested`, `RedeemRequestCancelled`, `RedeemClaimed`                         | Tranche controller | A senior exit queued, cancelled or settled                                                                                                      |
| `FwdRequested`, `FwdEntryRequested`, `FwdFilled`, `FwdCancelStarted`, `FwdCancelled` | Tranche controller | A junior exit or entry request filed, filled in whole or in part, or cancelled in its two steps                                                 |

### Financing

| Event                                                                                            | Emitted by       | What it records                                                                    |
| ------------------------------------------------------------------------------------------------ | ---------------- | ---------------------------------------------------------------------------------- |
| `CollateralPosted`, `CollateralWithdrawn`, `Borrowed`, `Repaid`, `Supplied`, `SuppliedWithdrawn` | Financing router | Each move at a venue, with the pool and the venue indexed                          |
| `DebtRefinanced`, `SupplyMigrated`                                                               | Financing router | Debt or supply moved between two venues of one loan asset                          |
| `CollateralMaintained`                                                                           | Pool             | A top-up through `maintainCollateral`: the venue, the amount posted and the caller |
| `CollateralToppedUp`, `CollateralReleased`                                                       | Pool             | A top-up or a release through `maintain`                                           |
| `EmergencyAction`                                                                                | Pool             | One emergency call: its kind, the venue, the amount and the caller                 |
| `GlobalPauseSet`                                                                                 | Financing router | The protocol Safe stopping or resuming new borrowing and supply                    |

### Settings and governance

**Each setting change emits an event named for it.** The event comes from the pool or the financing router. For example, `setDials` emits `DialsSet` on the pool and `PinSet` on the financing router. A delayed change emits one event when it's scheduled and another when it applies. [Roles and governance](/run-a-pool/roles-and-governance.md#seeing-a-delayed-change-coming) lists the events that announce a delayed change.

The deposit allowlist, the DEX aggregator, the entry market and the tranche controller also emit an event per setting. Each conversion through the aggregator emits `Routed` or `RoutedExactOut`.

The factory, the price feed and the authority contract emit these:

| Event                                                                                                                                                           | Emitted by         | What it records                                                                                                                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PoolCreated`                                                                                                                                                   | Factory            | A new pool: its authority contract, creator and implementation, its invariant hook with that hook's code hash, and hashes of its hook set and risk settings. It also gives the first loan asset's Morpho Blue account, or zero for a pool created without one |
| `ImplementationScheduled`, `ImplementationCancelled`, `ImplementationChanged`, `AccountDeployerScheduled`, `AccountDeployerCancelled`, `AccountDeployerChanged` | Factory            | New code for every pool, or a venue type's account deployer, scheduled, cancelled or installed                                                                                                                                                                |
| `ProtocolFeeScheduled`, `ProtocolFeeCancelled`, `ProtocolFeeReceiverSet`, `DefaultProtocolFeeScheduled`, `DefaultProtocolFeeSet`                                | Factory            | Changes to each pool's protocol fee, its receiver and the rate new pools start at                                                                                                                                                                             |
| `TokenAdded`, `OracleScheduled`, `OracleCancelled`, `OracleReplaced`                                                                                            | Price feed         | A token listed, and a feed replacement scheduled, cancelled or executed                                                                                                                                                                                       |
| `GuardianSet`, `KeeperSet`, `FeeReceiverSet`                                                                                                                    | Authority contract | Each role appointment                                                                                                                                                                                                                                         |

## Common errors

**Swap reverts are listed once, under** [**Common reverts**](/use-efficient/trade.md#common-reverts) **on Trade.** The table below covers the other flows.

Deposits and exits stop while a lending market that can refuse actions holds a position but allows none. In that state, NAV reverts with `VenueFrozen`. Morpho Blue, the only venue type in the code, never reaches that state. See [The pool and its book](/how-pools-work/the-pool-and-its-book.md#when-a-position-cant-be-read).

| Error                                                                                                                                                               | Raised by                  | Cause                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DepositNotPermitted`                                                                                                                                               | Pool                       | The deposit allowlist doesn't admit the deposit's receiver. A pool with no allowlist contract admits every receiver                                                                                                                                                                                                                                                                                                  |
| `DepositCapExceeded`                                                                                                                                                | Pool                       | A `mintProRata` would lift the share supply past `mintProRataCap`. That cap starts at zero, so the entry stays closed until the pool operator raises it                                                                                                                                                                                                                                                              |
| `BookHasDebt`                                                                                                                                                       | Pool                       | A `mintProRata` while the book owes debt at any lending market                                                                                                                                                                                                                                                                                                                                                       |
| `FeatureDisabled(uint8)`                                                                                                                                            | Pool                       | The call's feature bit is off: bit 0 for deposits, 4 for `maintain` and 6 for `swapLoan`                                                                                                                                                                                                                                                                                                                             |
| `Paused`                                                                                                                                                            | Pool                       | A deposit, `poke`, `recenter` or `swapLoan` while the pool is paused                                                                                                                                                                                                                                                                                                                                                 |
| `PriceUnchecked`                                                                                                                                                    | Pool                       | A loan asset with net debt, or one the call must price, has no checked feed price. While a performance or protocol fee rate is on, a deposit also needs a checked price for every loan asset that holds a position. A deposit's borrow leg, a `maintainCollateral` top-up and a fee rise can all raise it                                                                                                            |
| `PegBroken`                                                                                                                                                         | Pool                       | A deposit's borrow leg needs its loan asset on its peg                                                                                                                                                                                                                                                                                                                                                               |
| `ZeroShares`                                                                                                                                                        | Pool                       | A deposit too small to mint a share                                                                                                                                                                                                                                                                                                                                                                                  |
| `Slippage`, `LoanAssetInExceeded`, `LoanAssetOutBelowMin`                                                                                                           | Pool                       | A proportional deposit or exit misses one of the caller's bounds on shares, the pool asset or a loan asset's net amount                                                                                                                                                                                                                                                                                              |
| `InvalidAmount`                                                                                                                                                     | Pool                       | A zero amount, an exit of more shares than the owner holds, or a bounds array whose length isn't the loan-asset count                                                                                                                                                                                                                                                                                                |
| `BelowMinimumShares`                                                                                                                                                | Pool                       | An exit would leave fewer than 1,000 base units of shares in the pool                                                                                                                                                                                                                                                                                                                                                |
| `LedgerBoundBreached`, `ExitWorsensLedger`                                                                                                                          | Pool                       | A deposit fails the credit check, or an exit would worsen a loan asset's ratio of net debt to the pool asset the pool holds, posted or not. See [Credit and collateral](/how-pools-work/credit-and-collateral.md#deposits-buys-and-exits)                                                                                                                                                                            |
| `PokeMove`                                                                                                                                                          | Pool                       | A `poke` would move the invariant hook's spot price by more than 1%, or move it away from the feed price to more than 3% off                                                                                                                                                                                                                                                                                         |
| `NoBand`                                                                                                                                                            | Pool                       | A `poke` on a pool with no price band, or a rise in the pool operator's performance fee scheduled there with `setPerformanceFeeBp`                                                                                                                                                                                                                                                                                   |
| `AnchorOutOfBounds`                                                                                                                                                 | Pool                       | A recentre would move the anchor outside the caller's bounds                                                                                                                                                                                                                                                                                                                                                         |
| `NothingToMaintain`                                                                                                                                                 | Pool                       | `maintainCollateral` finds no top-up due                                                                                                                                                                                                                                                                                                                                                                             |
| `LoanSwapDisabled`, `StalePair`, `FillMismatch`                                                                                                                     | Pool                       | A `swapLoan` on a pool with no loan-to-loan swap hook, with either USD price older than the pool's maximum price age, or whose hook fills differently from its quote                                                                                                                                                                                                                                                 |
| `NotCurator`, `NotGuardianOrCurator`, `NotKeeperOrCurator`                                                                                                          | Pool and periphery         | The caller doesn't hold a role the call needs. In these names, `Curator` means the pool operator                                                                                                                                                                                                                                                                                                                     |
| `GuardianMayOnlyTighten`                                                                                                                                            | Pool                       | A guardian call would loosen a setting                                                                                                                                                                                                                                                                                                                                                                               |
| `CeilingBreached`                                                                                                                                                   | Pool                       | A price band or fee cap set above its ceiling, or a ceiling cut below the band or fee cap in force                                                                                                                                                                                                                                                                                                                   |
| `HookSetNotReady` on the pool, and `ImplementationNotReady`, `DeployerNotReady(uint8)`, `ProtocolFeeNotReady(address)`, `DefaultProtocolFeeNotReady` on the factory | Pool, factory              | A scheduled change executed before its delay ends. On the pool, that covers hook sets, venues, loan assets, performance fee rises and ceiling raises                                                                                                                                                                                                                                                                 |
| `NoHookSetScheduled`, `NoVenueScheduled`, `NoLoanAssetScheduled`, `NoPerformanceFeeScheduled`                                                                       | Pool                       | A cancel or execute finds nothing scheduled, or `executeHookSet` gets a set other than the scheduled one                                                                                                                                                                                                                                                                                                             |
| `NotPaused`                                                                                                                                                         | Pool                       | `executeHookSet` while the pool isn't paused                                                                                                                                                                                                                                                                                                                                                                         |
| `HookInvalid`                                                                                                                                                       | Pool                       | A hook in a new set has no code, names another pool or the wrong interface version, or the set names a fee or recentring hook that [Build a hook](/run-a-pool/build-a-hook.md#implement-the-interfaces) rules out. In a pool with no price band, it also covers an invariant hook that doesn't declare `HOOK_CAP_UNPRICED`                                                                                           |
| `DialOutOfEnvelope`, `LtvStepTooLarge`, `DialCooldown`, `LtvLltvGap`, `LtvFloorBreached`                                                                            | Pool                       | A `setDials` move breaks one of its limits. See [Credit and collateral](/how-pools-work/credit-and-collateral.md#moving-the-dials)                                                                                                                                                                                                                                                                                   |
| `CreateFailed`                                                                                                                                                      | Factory                    | The pool's initialiser refused the creation, for example for a pair its price feed doesn't admit                                                                                                                                                                                                                                                                                                                     |
| `InvalidConfig`                                                                                                                                                     | Most contracts             | A setting or argument outside its bounds                                                                                                                                                                                                                                                                                                                                                                             |
| `GlobalPaused`                                                                                                                                                      | Financing router           | A deposit's borrow or supply leg, a refinance or a supply migration while the protocol Safe has paused new borrowing and supply                                                                                                                                                                                                                                                                                      |
| `VenueDisabled`, `DrawOutsideDrawnSet`, `DebtCapExceeded`, `SupplyCapExceeded`, `RateCeiling`, `OracleBand`, `VenueOverPinned`, `Unhealthy`                         | Financing router           | A deposit's borrow or supply leg breaks a venue limit: a switch, the drawn set, a cap, the rate ceiling, the oracle band, the venue's LLTV or the LTV pin. See [Credit and collateral](/how-pools-work/credit-and-collateral.md#limits-on-new-borrowing)                                                                                                                                                             |
| `TooManyLoanAssets`, `DuplicateLoanAsset`, `TooManyVenues`                                                                                                          | Financing router, pool     | A 17th loan asset, a loan asset already listed, or a venue past the pool's 32 slots                                                                                                                                                                                                                                                                                                                                  |
| `MaxAssetIn`, `MinSharesOut`, `MinAssetOut`, `NotOwner`, `BadAsset`                                                                                                 | Asset router               | The call would spend more than `maxAssetIn` or pay less than its minimum, someone other than the share owner calls an exit, or a token is neither of the pool's assets                                                                                                                                                                                                                                               |
| `RouteShort`, `Oversold`, `BadLeg`, `AdapterMisreport`                                                                                                              | Asset router, entry market | A conversion leg delivers less than the flow needs, sells more than it needs, has a kind it can't use there, or moves balances that disagree with the aggregator's report. `AdapterMisreport` also covers a leg that gets less for its actual spend than a price floor. On the asset router, the floor is the pool's checked price less 1%. In the entry market, it's that price less the request's ramped tolerance |
| `InsufficientOutput`, `InputNotConsumed`, `InvalidDexIndex`, `RouterCallFailed`                                                                                     | DEX aggregator             | A conversion returns less than its floor, leaves an exact input partly unspent, names an index with no whitelisted router, or the DEX router's call fails with no revert data                                                                                                                                                                                                                                        |
| `MultiLoan`                                                                                                                                                         | Asset router, entry market | The pool has more than one loan asset. The asset router, `fillPar` and `crank` don't handle that                                                                                                                                                                                                                                                                                                                     |
| `NotAllowed`, `MarketPaused`, `BadParams`                                                                                                                           | Entry market               | A deposit requester the allowlist doesn't admit, a new request while the market is paused, a request outside its limits on amount, minimum, discount, ramp or expiry, or a requester filling their own request                                                                                                                                                                                                       |
| `SameBlock`, `NotOpen`, `Expired`, `NotExpired`, `NothingToDo`                                                                                                      | Entry market               | A settlement in the posting block, of a closed request or at expiry, a cancel by someone else before expiry, or a settlement that rounds to nothing                                                                                                                                                                                                                                                                  |
| `CapBreached`, `PrintNotFresh`, `CancelPending`, `NotYetClaimable`                                                                                                  | Tranche controller         | An entry past its cap or a junior exit whose lane admits none of it, a request not yet fillable, a request whose cancel has bound, or a senior claim before its seven days have passed                                                                                                                                                                                                                               |
| `ForwardPriced`, `SeniorExitQueued`                                                                                                                                 | Tranche tokens             | An instant `redeem` or `withdraw`, or a junior `deposit` or `mint` after the pool operator's seed. These go through requests instead                                                                                                                                                                                                                                                                                 |
| `UnknownPool`, `BadPair`, `UnsupportedSide`                                                                                                                         | Tycho adapter              | An id that isn't a factory pool, a pair other than the pool asset and the first loan asset, or a buy order                                                                                                                                                                                                                                                                                                           |

[Roles and governance](/run-a-pool/roles-and-governance.md) explains who holds each role. The [Glossary](/glossary.md) defines each term Efficient and Everlong use.
