Перейти к содержимому
Проверенный контрактТочноеUNLICENSED

FLAMMFenceLib

Адрес0x9dbba0cbd9d7883f4eedd1c8e08780fac4798f1a
Баланс

0 ETH

 

Транзакций

0

 

Компилятор

solc 0.8.35

 

Тот же код

Только этот контракт

 

Подробности

Компилятор
solc 0.8.35+commit.47b9dedd
Язык
solidity
Оптимизация
Да, 100 прогонов
Версия EVM
cancun
Через IR
да
Лицензия
UNLICENSED
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 480 474
Транзакция создания
0xd829cfff82…f0b5c838d9
Библиотеки
src/core/mm/MMRouterLib.sol:MMRouterLib0x95b3…48ef2csrc/core/flamm/FLAMMLane.sol:FLAMMLane0x5d81…90de37src/core/flamm/FLAMMRoute.sol:FLAMMRoute0xb1ff…7fb0fesrc/periphery/FLAMMMaxima.sol:FLAMMMaxima0x6854…90a91bsrc/core/flamm/FLAMMLawLib.sol:FLAMMLawLib0xf55c…49cf45src/core/flamm/FLAMMOpsLib.sol:FLAMMOpsLib0x0be7…5ecc47src/core/mm/AaveV3ReadsLib.sol:AaveV3ReadsLib0xa5db…72803esrc/core/flamm/FLAMMFlowLib.sol:FLAMMFlowLib0x2795…4cfb77src/core/flamm/FLAMMGateLib.sol:FLAMMGateLib0x3a05…434368src/core/flamm/FLAMMKeptLib.sol:FLAMMKeptLib0x70ca…60bee4src/core/mm/CTokenMarketLib.sol:CTokenMarketLib0x60e4…314010src/core/flamm/FLAMMAdmitLib.sol:FLAMMAdmitLib0x0b10…1ce950src/core/flamm/FLAMMBlindLib.sol:FLAMMBlindLib0x634d…298fcdsrc/core/flamm/FLAMMClaimLib.sol:FLAMMClaimLib0x5dc3…aa7e91src/core/flamm/FLAMMFenceLib.sol:FLAMMFenceLib0x9dbb…798f1asrc/core/flamm/FLAMMFloatLib.sol:FLAMMFloatLib0x6b2b…518935src/core/flamm/FLAMMQuoteLib.sol:FLAMMQuoteLib0x99de…929869src/core/flamm/FLAMMTopUpLib.sol:FLAMMTopUpLib0xe4be…cfac2esrc/core/mm/CTokenRewardsLib.sol:CTokenRewardsLib0x93ab…262861src/core/mm/MMRouterAdminLib.sol:MMRouterAdminLib0x6abb…60ea7esrc/core/flamm/FLAMMPolicyLib.sol:FLAMMPolicyLib0x3858…f91f06src/core/flamm/FLAMMSettleLib.sol:FLAMMSettleLib0x4551…33b301src/core/flamm/FLAMMSharedLib.sol:FLAMMSharedLib0xb852…b71005src/periphery/FLAMMExitMaxima.sol:FLAMMExitMaxima0x6a6a…798659src/hooks/everlong/LeverageLib.sol:LeverageLib0x8039…16d055src/core/flamm/FLAMMMaintainLib.sol:FLAMMMaintainLib0xaa54…b56417src/core/flamm/FLAMMPairQuoteLib.sol:FLAMMPairQuoteLib0x3bc5…2055ddsrc/hooks/everlong/EverlongOpsLib.sol:EverlongOpsLib0xf6d5…9dfeef

52 файла

Исходный код большой: показывается один файл. Выберите файл в списке.

src/core/flamm/FLAMMFenceLib.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {
    FLAMMStore, InvalidConfig, NotFenced, ProbeOutsideWindow, ProbeRefused, ClaimsOpen, VenueRefusedLeg, InvalidAmount,
    ClaimRecorded, FenceOpened, FenceProbed, FenceWrittenOff, FenceAbandoned, FenceAbandonScheduled, FenceLifted,
    TokenFenced, TokenLifted, TokenReopened, TradePairsSet, CustodyMismatch, ClaimsVaulted, HookSetNotReady
} from "src/core/flamm/FLAMMStore.sol";
import {FLAMMAdmitLib} from "src/core/flamm/FLAMMAdmitLib.sol";
import {FLAMMClaimVault} from "src/core/flamm/FLAMMClaimVault.sol";
import {FLAMMGateLib} from "src/core/flamm/FLAMMGateLib.sol";
import {FLAMMLane} from "src/core/flamm/FLAMMLane.sol";
import {IMMRouter} from "src/interfaces/core/mm/IMMRouter.sol";
import {MMRouterLib} from "src/core/mm/MMRouterLib.sol";
import {VenueReads} from "src/core/mm/VenueReads.sol";
import {
    IFinancingAccount, CAN_REPAY, CAN_RELEASE_COLLATERAL, CAN_WITHDRAW_SUPPLY
} from "src/interfaces/core/mm/IFinancingAccount.sol";
import {ReentrancyGuardLib} from "src/libraries/ReentrancyGuardLib.sol";

/// @notice The fences: a venue, or a token's custody, taken out of the pool's book while the pool still owns what sits
///         there. Swaps keep running on every other venue and token. Exits keep running: they pay every other leg and
///         leave their share of each fence that holds a pool part as a claim, which settles in kind against the fence
///         whenever its lender takes the legs ({recordClaims}, `FLAMMClaimLib`).
/// @dev - NAV refuses (`VenueFrozen`) while some fence holds a pool part not written off; the entries refuse, no fee
///        rate rises and no fee mints while some fence holds a pool part, written off or not (`FLAMM.partedFences`):
///        every share owns its slice of it.
///      - A fenced venue is locked at the Router (`IMMRouter.lockVenue`), its slot marked retired, and idle too while
///        the pool's part there is not zero, and out of its pair's venue mask, so every walk of the venues passes it
///        as it passes a retired one.
///      - A token's fence moves its custody and the protocol's fee owed in it out of the book, fences every live venue
///        of a pair naming it and closes every pair naming it.
///      - Each fence keeps two fractions of its position, of {ONE}: the pool's part (`live`) and the open claims'
///        (`claimed`). The pool's part comes back by a venue's lift, once no claim is open, or by its unwind into
///        custody, or by a token's lift, which moves the open claims' share to the key's vault.
///      - The curator writes the pool's part off after the pool's delay D, which reopens NAV (without the part), not
///        the entries, the rises of either fee rate or the skim's mints, which wait for the part's return, or for the
///        curator to give it up after D more ({abandonFence}). A cut of either fee rate lands at all times.
///      - The entries here take the pool's storage from its own namespace, never as an argument: the pool's dispatch
///        table names this library for each of their selectors (`FLAMM.route`), and no other call reaches it. Each
///        writing entry checks its own caller and holds the lock.
///      - The pool's delay D is `governanceDelaySec`; the write-off, the abandon and the lifts wait it in the pending
///        table, as the admissions do (the first call schedules, the identical call executes within one more delay or one day, whichever is longer,
///        the curator or the guardian cancels by hash, `FLAMMAdmitLib.cancel`).
///      - Frames: the venues at a frame's account (`FRAME_VENUE` in `IMMRouter.sol`, {mates}) share one position at the
///        lender, so each backs the others' debt there: a fence of one takes them all ({_open}), a lift returns them
///        together and an abandon gives them up together, its guard the frame's ({_frameGuard}), so no venue the book
///        counts backs a debt the book left out. Each keeps its own record and key, and the records keep the same
///        fractions: an exit's claims, their settlements and moves, and the pool's unwinds take the same part of each
///        (`FLAMMClaimLib`), so no one takes a venue's slice of the frame without its slices of the others.
library FLAMMFenceLib {
    /// @notice A fence's whole position, in the fractions `live` and `claimed`.
    uint256 internal constant ONE = 1e36;
    /// @notice A probe's second read fences from an hour after its first to two hours after it.
    uint256 internal constant PROBE_GAP = 1 hours;
    uint256 internal constant PROBE_WINDOW = 2 hours;
    /// @notice The record's flags: the probe opened it.
    uint8 internal constant PROBED = 1;
    /// @dev A venue fence's record of the venue's switches before its lock, which the lift restores.
    uint8 internal constant BORROW_ON = 4;
    uint8 internal constant SUPPLY_ON = 8;
    /// @notice A record's order index where the venue sat in no order at the lock.
    uint8 internal constant NO_ORDER = type(uint8).max;
    /// @dev The pending table's keys of the fence's delayed entries.
    bytes4 internal constant WRITE_OFF = bytes4(keccak256("writeOff(uint32)"));
    bytes4 internal constant LIFT_FENCE = bytes4(keccak256("liftFence(uint16)"));
    bytes4 internal constant LIFT_TOKEN = bytes4(keccak256("liftToken(uint8)"));
    bytes4 internal constant ABANDON = bytes4(keccak256("abandonFence(uint32)"));
    /// @notice The holder of a part given up ({abandonFence}): its settlement pays the void, never the pool.
    address internal constant VOID = address(0xdEaD);
    /// @dev The gas {abandonFence}'s guard and its end of a junior debt hold give each venue read ({_legsTaken},
    ///      {_deadRead}).
    uint256 internal constant DEAD_READ_GAS = 3_000_000;
    /// @dev One bit per row of the trade masks' layout (bit `16 * i`): shifted by `t`, token `t`'s column.
    uint256 private constant COLUMN = 0x0001000100010001000100010001000100010001000100010001000100010001;

    // ------------------------------------------------------------------ access and the pending table
    function _s() private pure returns (FLAMMStore.S storage) {
        return FLAMMStore.s();
    }

    /// @dev The curator or the pool's guardian; then the lock.
    function _curatorOrGuardian(FLAMMStore.S storage $) private {
        FLAMMStore.curatorOrGuardian($);
        ReentrancyGuardLib._guard();
    }

    /// @dev The curator; then the lock.
    function _curator(FLAMMStore.S storage $) private {
        FLAMMStore.requireCurator($);
        ReentrancyGuardLib._guard();
    }

    /// @dev `FLAMMAdmitLib.due` of the entry `call` names first, at the pool's delay D. The key is read from `call`, so
    ///      the four entries share one body: given as a literal it would compile to a copy of `due` each.
    function _due(FLAMMStore.S storage $, bytes memory call) private returns (bool) {
        return FLAMMAdmitLib.due($, bytes4(call), call, $.governanceDelaySec);
    }

    // ------------------------------------------------------------------ the triggers
    /// @notice Fences live venue `id` at once, the curator's or the pool's guardian's: a fence only takes exposure out
    ///         of the book, as the guardian's other tightenings do ({_open}); at a frame's account, with the frame's
    ///         other live venues.
    function fenceVenue(uint16 id) public {
        FLAMMStore.S storage $ = _s();
        _curatorOrGuardian($);
        _open($, id, _orders($), 0);
        ReentrancyGuardLib._unlockGuard();
    }

    /// @notice Anyone's fence of a live venue whose lender stopped taking repays: a venue whose kind can refuse an
    ///         action (`FLAMMStore.S.gatedVenues`), owing more than the lenders' rounding
    ///         (`MMRouterLib.RELEASE_SLACK`), whose actions lack `CAN_REPAY` (`ProbeRefused` otherwise). The first read
    ///         records its time; a second read from an hour after it to two hours after it, passing the same test,
    ///         fences the venue ({_open}: at a frame's account, with the frame's other live venues); a second read
    ///         sooner reverts `ProbeOutsideWindow`, and one later starts the probe again. A capacity read starved of
    ///         gas reverts and never reads a refusal (`IFinancingAccount`), so no caller fakes one. One pause shorter
    ///         than an hour fences nothing; the reads see no gap between them, so two pauses an hour to two hours apart
    ///         do, and two further apart do not. A venue's admission clears its slot's first read (`FLAMM.addVenue`),
    ///         so a read left there by a venue retired since counts for none admitted after it.
    function probeFence(uint16 id) public {
        FLAMMStore.S storage $ = _s();
        ReentrancyGuardLib._guard();
        IMMRouter r = _live($, id);
        (,,,, uint256 debt) = r.venuePosition(address(this), id);
        if (
            ($.gatedVenues >> id) & 1 == 0 || debt <= MMRouterLib.RELEASE_SLACK
                || r.venueActions(address(this), id) & CAN_REPAY != 0
        ) revert ProbeRefused();
        FLAMMStore.Fence storage f = $.fences[id];
        uint256 first = f.probeAt;
        if (first != 0 && block.timestamp <= first + PROBE_WINDOW) {
            if (block.timestamp < first + PROBE_GAP) revert ProbeOutsideWindow();
            _open($, id, _orders($), PROBED);
        } else {
            f.probeAt = uint48(block.timestamp);
            emit FenceProbed(id, uint48(block.timestamp), msg.sender);
        }
        ReentrancyGuardLib._unlockGuard();
    }

    /// @notice Token `t`'s fence, the token switch, at once, the curator's or the pool's guardian's; never the pool
    ///         asset, in which shares and NAV are measured, and not a token fenced already (`InvalidConfig`). Every
    ///         live venue of a pair naming `t` is fenced ({_open}, the orders read once), each at a frame's account
    ///         with the frame's other live venues. The token's custody leaves the book,
    ///         with the protocol's fee owed in it (`FLAMMStore.feeOwed`, the operator's share owed in it included),
    ///         which its record keeps and returns first at the lift: the protocol holds no share. The pool's part is
    ///         the token's whole balance less that fee, `ONE` where custody held more than the fee, and its bit in the
    ///         parted set then
    ///         (`FLAMMStore.PARTED_TOKENS_SHIFT`): the entries and the rises wait for the token's lift, written off or
    ///         not. Every pair naming `t` closes, its bit in the curator's mask saved for
    ///         the token's reopening (`FLAMMStore.S.fenceTrades`); a scheduled opening stays as scheduled, and the
    ///         mask's writer drops the token's pairs from it if it applies while the record is open. Until the lift no
    ///         flow pays out `t`, and every exit leaves its share as a claim on the token's custody, less what it owes
    ///         in `t` (a kept share's debt, `FLAMMFlowLib.proRata`), which it pays from that claim first, at the lower
    ///         of the custody moved and what the record holds now (one try of the token's balance), and brings in only
    ///         where the claim falls short: only then does it move the token, and the custody it brings stays in the
    ///         book against that debt. That custody is the holders' who stay: a later exit takes no slice of it past
    ///         what it owes, as its net in the token is never an output, so each exit forfeits its share of it to
    ///         them. A token that refuses the pool holds such an exit: one where the pool's part of
    ///         the record and custody fall short of the kept debt, which needs no sale (a book that sold the token it
    ///         borrows, or the debt's interest while the record stands still), or where a unit of rounding is short.
    ///         It lands once the token moves again, with no lift. A kept share's abandon ends that hold only where no
    ///         junior claim stands, as the juniors' debt share stays owed, and the end of their hold needs a lender
    ///         that does not answer ({abandonFence}).
    function fenceToken(uint8 t) public {
        FLAMMStore.S storage $ = _s();
        _curatorOrGuardian($);
        FLAMMStore.checkToken($, t);
        uint256 w = $.fenceWord;
        if (t == 0 || (w >> (FLAMMStore.FENCED_TOKENS_SHIFT + t)) & 1 != 0) revert InvalidConfig();
        uint16[][4] memory orders = _orders($);
        uint256 np = $.pairCount;
        for (uint256 p; p < np; ++p) {
            FLAMMStore.PairCfg storage pc = $.pairs[p];
            if (pc.coll != t && pc.debt != t) continue;
            // read afresh at each turn: a frame venue's fence takes the frame's other venues, this pair's among them
            for (uint256 m; (m = pc.venues & ~uint256($.retiredVenues)) != 0;) {
                _open($, uint16(low(m)), orders, 0);
            }
        }
        uint256 fee = FLAMMStore.feeOwed($, t);
        if (fee != 0) _clearFee($, t);
        // the book's fee pass marks every book while a token's record is open: the flows read the fence word then
        $.poolBits |= FLAMMStore.POOL_SPREAD_OWED;
        uint256 h = FLAMMStore.heldOf($, t);
        FLAMMStore.setHeld($, t, 0);
        bool parted = h > fee;
        uint256 index = 32 + uint256(t);
        uint256 bits = (uint256(1) << (FLAMMStore.FENCED_TOKENS_SHIFT + t)) | (uint256(1) << (FLAMMStore.OUT_TOKENS_SHIFT + t));
        if (parted) {
            bits |= (uint256(1) << (FLAMMStore.UNWRITTEN_SHIFT + index))
                | (uint256(1) << (FLAMMStore.PARTED_TOKENS_SHIFT + t));
        }
        uint32 key = _newKey($, index, bits);
        FLAMMStore.Fence storage f = $.fences[index];
        (f.key, f.openedAt, f.live, f.fee) = (key, uint48(block.timestamp), parted ? uint128(ONE) : 0, fee);
        // a stranger's settlement pays a claim its part of the custody moved out at least (`FLAMMClaimLib.settleClaim`)
        if (parted) $.strangerFloor[key] = h - fee;
        // the pairs naming it close; those a token fenced before closed are kept already
        uint256 o = pairsOf(t) & ~closedPairs(w);
        uint256 cur = $.tradePairs;
        $.fenceTrades |= cur & o;
        if (cur & o != 0) {
            cur &= ~o;
            $.tradePairs = cur;
            emit TradePairsSet(cur, msg.sender);
        }
        $.swapBits |= FLAMMStore.SWAP_FENCE;
        FLAMMAdmitLib.syncSwapBits($, $.hookPairs, cur);
        emit TokenFenced(t, key, h, fee);
        ReentrancyGuardLib._unlockGuard();
    }

    /// @dev Fences live venue `id` (`InvalidConfig` where it is not) and, at a frame's account, every other live venue
    ///      there ({mates}), in slot order, each as {_openOne} fences it, with `orders` and `flags` alike: they share
    ///      one position at the lender, so a fence of one alone would leave the book counting venues that back a debt
    ///      it left out.
    function _open(FLAMMStore.S storage $, uint16 id, uint16[][4] memory orders, uint8 flags) private {
        _live($, id);
        for (uint256 m = matesOf($, id) & ~uint256($.retiredVenues); m != 0; m &= m - 1) {
            _openOne($, uint16(low(m)), orders, flags);
        }
    }

    /// @dev Fences live venue `id` (`InvalidConfig` where it is not): reads its position, locks it at the Router (both
    ///      switches off, out of the four orders, the others keeping theirs), marks its slot retired, and idle while
    ///      the pool holds a position there, takes it out of its pair's venue mask, sets `noLiveVenue` where no live
    ///      slot is left, and opens its record: a new key, the venue's index in each order of `orders` (read before any
    ///      lock of the same call, for the lift's re-insert), the pool's part `ONE` where it holds a position there
    ///      (its unwritten bit set: NAV and the entries refuse), else zero.
    function _openOne(FLAMMStore.S storage $, uint16 id, uint16[][4] memory orders, uint8 flags) private {
        IMMRouter r = _live($, id);
        IMMRouter.VenueView memory v = r.venue(address(this), id);
        uint8 pair = v.pair;
        if (v.borrowEnabled) flags |= BORROW_ON;
        if (v.supplyEnabled) flags |= SUPPLY_ON;
        r.lockVenue(id, true);
        (, uint256 coll,, uint256 sup, uint256 debt) = r.venuePosition(address(this), id);
        bool parted = (coll | sup | debt) != 0;
        uint32 bit = uint32(1) << id;
        uint32 retired = $.retiredVenues | bit;
        $.retiredVenues = retired;
        $.idleVenues = parted ? $.idleVenues | bit : $.idleVenues & ~bit;
        $.pairs[pair].venues &= ~bit;
        if (uint256(retired) + 1 == uint256(1) << r.venueCount(address(this))) $.noLiveVenue = true;
        uint256 bits = bit;
        if (parted) bits |= uint256(1) << (FLAMMStore.UNWRITTEN_SHIFT + id);
        uint32 key = _newKey($, id, bits);
        FLAMMStore.Fence storage f = $.fences[id];
        (f.key, f.openedAt, f.probeAt, f.flags) = (key, uint48(block.timestamp), 0, flags);
        (f.borrowAt, f.supplyAt, f.withdrawAt, f.repayAt) =
            (_at(orders[0], id), _at(orders[1], id), _at(orders[2], id), _at(orders[3], id));
        (f.live, f.claimed) = (parted ? uint128(ONE) : 0, 0);
        emit FenceOpened(id, key, parted ? ONE : 0, msg.sender);
    }

    /// @dev The Router, where slot `id` is a live venue of the pool's (`InvalidConfig` otherwise): admitted, neither
    ///      retired nor fenced.
    function _live(FLAMMStore.S storage $, uint16 id) private view returns (IMMRouter r) {
        r = $.router;
        if (id >= FLAMMStore.MAX_POOL_VENUES || id >= r.venueCount(address(this)) || ($.retiredVenues >> id) & 1 != 0) {
            revert InvalidConfig();
        }
    }

    /// @dev A new key for the record at `index`: the count of fences opened, past this one, over the index; the fence
    ///      word's count moved and `bits` set.
    function _newKey(FLAMMStore.S storage $, uint256 index, uint256 bits) private returns (uint32 key) {
        uint256 w = $.fenceWord;
        uint256 count = uint32(w >> FLAMMStore.FENCE_COUNT_SHIFT) + 1;
        if (count >= 1 << 26) revert InvalidConfig();
        key = uint32((count << 6) | index);
        uint256 mask = uint256(type(uint32).max) << FLAMMStore.FENCE_COUNT_SHIFT;
        $.fenceWord = (w & ~mask) | (count << FLAMMStore.FENCE_COUNT_SHIFT) | bits;
    }

    /// @dev The Router's four priority orders for the pool.
    function _orders(FLAMMStore.S storage $) private view returns (uint16[][4] memory o) {
        (o[0], o[1], o[2], o[3]) = $.router.priorities(address(this));
    }

    /// @dev `id`'s index in `order`, `NO_ORDER` where it is not in it.
    function _at(uint16[] memory order, uint16 id) private pure returns (uint8) {
        for (uint256 i; i < order.length; ++i) {
            if (order[i] == id) return uint8(i);
        }
        return NO_ORDER;
    }

    // ------------------------------------------------------------------ write-off and lifts
    /// @notice Writes off the pool's part of fence `key`, the curator's after D (the guardian cancels by hash): NAV
    ///         values it at zero, which it leaves out of the book already, and NAV (`totalAssets`, the conversions)
    ///         reopens once no fence holds a part not written off. NAV is then a lower bound: every share still owns
    ///         its slice of the part, so the entries, the rises of either fee rate and the skim's mints wait while the
    ///         part is out (`FLAMM.partedFences`), and so does every hand-off of shares priced at NAV in the periphery;
    ///         they reopen when the part returns at its price (the lift, an unwind of all of it, the token's lift) or
    ///         is given up ({abandonFence}). Exits keep recording claims there. `NotFenced` where the record has closed
    ///         or holds no part not written off.
    function writeOff(uint32 key) public {
        FLAMMStore.S storage $ = _s();
        _curator($);
        uint256 index = key & 63;
        uint256 bit = uint256(1) << (FLAMMStore.UNWRITTEN_SHIFT + index);
        uint256 w = $.fenceWord;
        if (index >= 48 || $.fences[index].key != key || w & bit == 0) revert NotFenced();
        if (_due($, abi.encode(WRITE_OFF, key))) {
            $.fenceWord = w & ~bit;
            emit FenceWrittenOff(key);
        }
        ReentrancyGuardLib._unlockGuard();
    }

    /// @notice Gives up the pool's part of fence `key` for good, the curator's, once the part is written off and D more
    ///         have passed (the guardian cancels by hash; the schedule names the key): the part becomes a claim held by
    ///         the void (`VOID`), whose settlement pays the void, never the pool, so no share owns it any more. The
    ///         fence stops closing the entries and holding the rises and the skim's mints, and NAV without the part is
    ///         exact again. `NotFenced` where the record has closed, holds no pool part or holds one not written off.
    /// @dev - For a part that will not come back: if it does, its recovery is lost to the pool's holders, who had the
    ///        write-off's D and this one's to exit and keep their claims. A venue's slot stays fenced while the void's
    ///        claim is open, and a token's record until its lift.
    ///      - The guard: at a venue the abandon is refused (`VenueRefusedLeg`), at the schedule and at the execution,
    ///        while the venue takes every leg an unwind of the part needs and the part is not given up as under water
    ///        ({_guard}): an unwind returns that part instead. A token's custody has no guard, but its record is not
    ///        given up while a kept share or its junior claims' debt share stands (`NotFenced`, at the schedule and at
    ///        the execution): exits pay their slices of that debt in the token from their parts of the record, which
    ///        stay in the pool's part till the lift (`FLAMMKeptLib.fromRecord`), and the void would take them
    ///        while the debt stays owed from custody. The refusal counts every kept share and every junior claims'
    ///        debt share, owed in this token or not, so it may hold an abandon no debt in the token needs: it costs
    ///        the abandon's liveness alone. Entries wait while a kept share stands; a junior debt share alone holds
    ///        none.
    ///      - Under water: a part whose debt past its supply is worth more than its collateral at the pool's prices,
    ///        and which its lender's own check reads unhealthy too (a lender that seized the collateral and kept the
    ///        debt), is given up after the same notice though the venue takes its repay: the lender keeps that debt,
    ///        which an unwind would repay from the custody every share owns. Where a price does not read, or the
    ///        lender reads the position healthy or its read reverts, the guard stays; a part that posts nothing reads
    ///        neither.
    ///      - The guard reads the venue's action bits, not a release. At a kind whose bits read no price
    ///        (`CTokenAccount`), a dead price at any market the position has entered, at a frame any market of the
    ///        frame, leaves every bit set while no release can land: an unwind refuses at its release and this abandon
    ///        refuses too (`VenueRefusedLeg`), so a part covered at the pool's prices stays fenced, neither returned
    ///        nor given up, until that price returns. Leaving the market does not help, as Venus's exit reads the same
    ///        price (`CTokenAccount.leave`). A part under water still goes: that kind's check reads unhealthy where it
    ///        cannot be read.
    ///      - A kept share (`FLAMMStore.KEPT_SHIFT`) has no guard. Its clear is open to anyone, and where a stranger's
    ///        clear lands in the abandon's delay the abandon then finds no part; but within
    ///        `FLAMMStore.KEPT_CLEAR_WAIT` of the unwind a stranger's clear refuses at a lender's ratio moved past the
    ///        floor, so the abandon may land first, and where the clear refuses for other reasons (a claim class under
    ///        water at the clear's prices, custody short of the debt, a price) the abandon ends the entries' pause
    ///        after the write-off's D and its own. NAV counts the share till the abandon gives it up, so it steps down
    ///        by at most the share's value then: depositors who disagree exit in the delay at a NAV that still counts
    ///        it, and the guardian may cancel. An operator clears a share a clear would take, rather than abandoning
    ///        it.
    ///      - Junior claims' debt (`FLAMMStore.JUNIOR_DEBT_SHIFT`): a kept share given up while junior claims stood
    ///        leaves their debt share owed from custody, which NAV reads at the venue till they settle. With no part
    ///        left, the same call again ends that hold after its own D, with no read: custody's share returns to the
    ///        holders, NAV reads the venue no more, and the junior claims settle bringing their debt share, as a
    ///        claim does. It is for a lender that stopped answering, where NAV and the flows refuse (`VenueFrozen`)
    ///        and no junior can settle, and it lands only while the venue's position does not read
    ///        (`VenueRefusedLeg` where it reads or where the read starves inside its cap, {_deadRead}): over a lender
    ///        that answers, the juniors settle as before. Known limit: a lender that stops answering and later answers again leaves the juniors who did
    ///        not settle before the hold ended paying their debt share twice, once at their exit and once at their
    ///        settlement.
    ///      - Each schedule logs the part's cover at the pool's prices (`FenceAbandonScheduled`), so the guardian can
    ///        weigh every scheduled abandon from the log alone.
    ///      - The guard does not hold while a token of the venue's pair is stuck out ({_pairOut}): its custody out, its
    ///        record standing for D when the abandon was scheduled, and the pool unable to move it. The venue's unwind
    ///        and lift wait for the token's lift then, and a token that never comes back would hold them for good, so
    ///        the venue's part is given up as the token's own is. A token the curator fences though the pool still
    ///        moves it leaves the guard in force: it is lifted, and an unwind returns the part. Where the token's
    ///        record has closed and the token still blocks the pool, the guardian or the curator fences the token again
    ///        first (its record then holds no part where the pool's custody of it is at most the fee), and the abandon
    ///        is scheduled D after that fence.
    ///      - Frames: at a frame's account the parts its fence holds at the frame's other venues ({mates}) go with it,
    ///        under this key's schedule, which names their slots, so a guardian reading it sees every part that goes,
    ///        as their fence took them together. Each must be written off, and the guard is the frame's, as an unwind
    ///        takes the same part of each venue there (`FLAMMClaimLib.unwindFence`): it holds while no token of their
    ///        pairs is stuck out, every venue takes every leg its part needs, and the frame is not given up as under
    ///        water summed, what its positions owe worth more than what they post and supply at the pool's prices
    ///        (with nothing posted or supplied, though no price reads) and their lender's own check of the frame, one
    ///        position there, reading it unhealthy too where they post anything ({_frameGuard}). The guard reads the
    ///        whole positions, so a part of any size reads as its frame does. The schedule logs the frame's cover
    ///        summed, every part's too.
    function abandonFence(uint32 key) public {
        FLAMMStore.S storage $ = _s();
        _curator($);
        uint256 index = key & 63;
        uint256 w = $.fenceWord;
        // a given-up kept share's junior debt: its own schedule ends custody's hold for it
        uint256 jd = ((w >> FLAMMStore.JUNIOR_DEBT_SHIFT) >> index) & 1;
        bool none = $.fences[index].live == 0;
        if (index >= 48 || $.fences[index].key != key || none && jd == 0) revert NotFenced();
        // a token's record while exits pay a kept debt from it
        if (index >= 32 && w >> FLAMMStore.KEPT_SHIFT != 0) revert NotFenced();
        uint256 m = uint256(1) << index;
        // the frame's other parts, read only where a fence holds a part at another venue
        uint256 others =
            index < 32 && jd == 0 ? (uint256($.retiredVenues & $.idleVenues) | w >> FLAMMStore.KEPT_SHIFT) & ~m : 0;
        if (others != 0) m |= matesOf($, uint16(index)) & others;
        // a frame's schedule names its parts
        bytes memory call = m & (m - 1) == 0 ? abi.encode(ABANDON, key) : abi.encode(ABANDON, key, m);
        for (uint256 k = m; k != 0; k &= k - 1) {
            uint256 i = low(k);
            if ($.fences[i].live == 0 && jd == 0 || (w >> (FLAMMStore.UNWRITTEN_SHIFT + i)) & 1 != 0) revert NotFenced();
        }
        uint256 cover = type(uint256).max;
        // a kept share's clear is anyone's (`FLAMMClaimLib.unwindFence`): where it takes, anyone returns the share in
        // the abandon's delay, so no guard holds the share's abandon where the clear refuses
        if (index < 32 && (w >> (FLAMMStore.KEPT_SHIFT + index)) & 1 == 0 && !none) {
            bool held;
            (held, cover) = _guarded($, w, m, call, _scheduledAt($, call) == block.timestamp);
            if (held) revert VenueRefusedLeg();
        }
        if (_due($, call)) {
            if (jd != 0) _deadRead($, index);
            for (; m != 0; m &= m - 1) {
                _giveUp($, low(m));
            }
        } else {
            emit FenceAbandonScheduled(key, cover);
        }
        ReentrancyGuardLib._unlockGuard();
    }

    /// @dev {abandonFence}'s guard for the written-off venue parts `m` under the abandon `call` (fence word `w`):
    ///      `held` where an unwind returns them, one venue's part as {_guard} reads it, a frame's parts as
    ///      {_frameGuard} reads them together, and no token of a part's pair is stuck out ({_pairOut}), read only where
    ///      the rest holds. `cover` is the parts', for the schedule's log: one venue's read where the guard needs it
    ///      and where the call `schedules` ({_guard}), a frame's always.
    function _guarded(FLAMMStore.S storage $, uint256 w, uint256 m, bytes memory call, bool schedules)
        private
        returns (bool held, uint256 cover)
    {
        uint256 i = low(m);
        if (m & (m - 1) != 0) {
            (held, cover) = _frameGuard($, m);
        } else {
            FLAMMStore.Fence storage f = $.fences[i];
            (uint256 live, uint256 claimed) = (f.live, f.claimed);
            (held, cover) = _guard($, uint16(i), live, live + claimed, schedules);
        }
        for (uint256 k = m; held && k != 0; k &= k - 1) {
            if (_pairOut($, w, uint16(low(k)), call)) held = false;
        }
    }

    /// @dev Gives up the pool's part of the record at `index` for good: a claim held by the void, its slot out of the
    ///      idle and kept sets or its token out of the parted set; a kept share's behind senior claims as a junior
    ///      part (`FLAMMStore.SENIORS`). A kept share's junior claims keep their debt share owed
    ///      (`FLAMMStore.JUNIOR_DEBT_SHIFT`): their exits paid it into custody (or into the pool's part of the record
    ///      of a token whose custody was out, which its lift returns there), and their settlements repay it from
    ///      custody. The void's debt share is the lender's to keep.
    function _giveUp(FLAMMStore.S storage $, uint256 index) private {
        FLAMMStore.Fence storage f = $.fences[index];
        (uint256 live, uint256 claimed, uint32 key) = (f.live, f.claimed, f.key);
        (f.live, f.claimed) = (0, uint128(claimed + live));
        if (index < 32) {
            uint256 w = $.fenceWord;
            uint256 k = uint256(1) << (FLAMMStore.KEPT_SHIFT + index);
            // the senior claims' part: a kept share's alone holds one
            uint256 cs = w & k != 0 ? f.fee & FLAMMStore.SENIORS : 0;
            // a kept share behind senior claims goes as a junior part, which stays their cover
            $.claims[key][VOID] += cs != 0 ? live << 128 : live;
            $.idleVenues &= ~(uint32(1) << index);
            uint256 jd = uint256(1) << (FLAMMStore.JUNIOR_DEBT_SHIFT + index);
            $.fenceWord = (w & ~(k | jd)) | (w & k != 0 && claimed > cs ? jd : 0);
        } else {
            $.claims[key][VOID] += live;
            $.fenceWord &= ~(uint256(1) << (FLAMMStore.PARTED_TOKENS_SHIFT + index - 32));
        }
        emit FenceAbandoned(key, live);
    }

    /// @dev {abandonFence}'s end of the junior claims' debt hold at venue `id` lands only while the venue's position
    ///      does not read (`VenueRefusedLeg` where it reads), with {DEAD_READ_GAS} to read in, which the call must
    ///      carry whole: a read starved of gas proves no dead lender, inside the cap too ({_notDead}), nor does the
    ///      Router's held lock (it passes on).
    function _deadRead(FLAMMStore.S storage $, uint256 id) private view {
        if (gasleft() < DEAD_READ_GAS * 64 / 63 + 10_000) revert VenueRefusedLeg();
        try $.router.venuePosition{gas: DEAD_READ_GAS}(address(this), uint16(id)) returns (
            uint256, uint256, uint256, uint256, uint256
        ) {
            revert VenueRefusedLeg();
        } catch (bytes memory reason) {
            _notDead(reason);
        }
    }

    /// @dev A capped read's revert `reason` that proves no dead lender: the Router's lock, passed on, and a read that
    ///      starved inside its {DEAD_READ_GAS} (`VenueReads.ReadStarved`, a kind's or the Router's own rule), refused
    ///      (`VenueRefusedLeg`). Starving is no death: a lender whose read needs more than {DEAD_READ_GAS}, as a
    ///      cToken frame's check across many entered markets may, is not given up through the guard.
    function _notDead(bytes memory reason) private pure {
        ReentrancyGuardLib._passOnLock(reason);
        if (reason.length == 4 && bytes4(reason) == VenueReads.ReadStarved.selector) revert VenueRefusedLeg();
    }

    /// @dev Whether a token of venue `id`'s pair is stuck out for the abandon `call`: its custody out in fence word `w`
    ///      (the unwind of the venue's part and its lift refuse then, `InvalidConfig`, whatever legs its lender takes),
    ///      its record open since D before the abandon's schedule at least ({_scheduledAt}), and the pool unable to
    ///      move it ({_moves}). A token fenced though the pool still moves it, or fenced less than D before, does not
    ///      count.
    function _pairOut(FLAMMStore.S storage $, uint256 w, uint16 id, bytes memory call) private returns (bool) {
        uint256 out = (w >> FLAMMStore.OUT_TOKENS_SHIFT) & 0xffff;
        if (out == 0) return false;
        IMMRouter.VenueView memory v = $.router.venue(address(this), id);
        if (((out >> v.coll) | (out >> v.debt)) & 1 == 0) return false;
        uint256 at = _scheduledAt($, call);
        return _stuck($, out, v.coll, at) || _stuck($, out, v.debt, at);
    }

    /// @dev Whether token `t` is out (bit `t` of `out`), its record opened D before `at` or earlier, and the pool
    ///      cannot move it.
    function _stuck(FLAMMStore.S storage $, uint256 out, uint256 t, uint256 at) private returns (bool) {
        if ((out >> t) & 1 == 0 || uint256($.fences[32 + t].openedAt) + $.governanceDelaySec > at) return false;
        return !_moves(FLAMMStore.tokenOf($, t));
    }

    /// @dev Whether the pool can still move `token`: a transfer of one unit to itself lands, or one of nothing where
    ///      the pool's balance reads exactly zero ({_holdsNone}), each as a try. A balance the pool holds and cannot
    ///      move, as under an issuer's freeze of it by amount, where a transfer of nothing still lands, reads stuck.
    function _moves(address token) private returns (bool) {
        return FLAMMStore.tryTransfer(token, address(this), 1)
            || (_holdsNone(token) && FLAMMStore.tryTransfer(token, address(this), 0));
    }

    /// @dev Whether the pool's balance of `token` reads exactly zero: a read that fails, or answers less than a word,
    ///      counts as a balance.
    function _holdsNone(address token) private view returns (bool none) {
        assembly ("memory-safe") {
            let m := mload(0x40)
            mstore(m, shl(224, 0x70a08231)) // balanceOf(address)
            mstore(add(m, 4), address())
            let ok := staticcall(gas(), token, m, 36, 0, 0x20)
            none := and(and(ok, gt(returndatasize(), 31)), iszero(mload(0)))
        }
    }

    /// @dev When the entry `call` was scheduled: where this call runs it (inside its window, `FLAMMAdmitLib.due`), its
    ///      due time less the delay; else now, as this call schedules it.
    function _scheduledAt(FLAMMStore.S storage $, bytes memory call) private view returns (uint256) {
        uint256 dueAt = $.pending[keccak256(call)];
        uint256 delay = $.governanceDelaySec;
        if (dueAt != 0 && block.timestamp >= dueAt && block.timestamp <= dueAt + FLAMMStore.executionWindow(delay)) return dueAt - delay;
        return block.timestamp;
    }

    /// @dev The abandon's guard at venue `id`, for `part` of `whole` of its position: `held` where the venue takes
    ///      every leg an unwind of the part needs (its repay where the part owes, its release where it posts, its
    ///      withdrawal where it supplies) and the position is not given up as under water: its cover ({_cover}) is at
    ///      least WAD, or it posts collateral and its lender's own check (`IMMRouter.venueHealthy`) reads it healthy or
    ///      reverts. A position under water at the pool's prices that posts nothing reads no lender. `cover` is the
    ///      position's, the part's too, every share of it being the same fraction, read where the guard needs it and
    ///      where the call `schedules`, for its log; `type(uint256).max` elsewhere, or where the position does not
    ///      read. Every kind's `healthy` reads false while the position owes and the lender's check cannot be read
    ///      (`IFinancingAccount.healthy`; a Morpho market's, its oracle), so the lender's half fails open on a lender
    ///      outage: the pool's prices alone decide then. A gift to the account counts at the lender, so one that brings
    ///      its check back to healthy keeps the guard; it must cover the debt at the lender's own price and threshold.
    ///      Not held where the position or capacity read reverts, as a refusal: the abandon is the curator's, after D,
    ///      so no caller starves the reads; a read that starved inside its cap refuses the abandon ({_notDead}). At a
    ///      cToken venue whose debt sub-account has entered six markets or more, a read inside {DEAD_READ_GAS} cannot
    ///      tell a dead lender from a starved read, so its abandon stays refused while that read fails.
    function _guard(FLAMMStore.S storage $, uint16 id, uint256 part, uint256 whole, bool schedules)
        private
        view
        returns (bool held, uint256 cover)
    {
        cover = type(uint256).max;
        IMMRouter r = $.router;
        (bool ok, uint256 coll, uint256 sup, uint256 debt) = _legsTaken(r, id, part, whole);
        // a position that does not read reads zero, so its cover reads `type(uint256).max`
        if (ok || schedules) cover = _cover($, r, id, coll, sup, debt);
        held = ok && (cover >= 1e18 || (coll != 0 && _lenderHealthy(r, id)));
    }

    /// @dev Venue `id`'s position, the Router's recognized collateral `coll`, supply `sup` and debt `debt`, and whether
    ///      the venue takes every leg an unwind of `part` of `whole` of it needs (`ok`): its repay where it owes, its
    ///      release where the part posts, its withdrawal where it supplies, the part's shares rounded down. Not `ok`
    ///      where either read reverts, as a refusal, the position reading zero where its own read does: the abandon is
    ///      the curator's, after D, so no caller starves the reads. Not a refusal where
    ///      the revert is the Router's lock (`ReentrancyGuardLib._passOnLock`), which another pool's Router call may
    ///      hold: it passes on, so a covered part is never given up through the lock; nor where the read starved
    ///      inside its cap (`VenueReads.ReadStarved`): the abandon reverts `VenueRefusedLeg` ({_notDead}).
    function _legsTaken(IMMRouter r, uint16 id, uint256 part, uint256 whole)
        private
        view
        returns (bool ok, uint256 coll, uint256 sup, uint256 debt)
    {
        // each read gets {DEAD_READ_GAS} and must find it in the call, so a call that stepped its gas to starve a read
        // into an out-of-gas revert cannot read a lender as dead
        if (gasleft() < DEAD_READ_GAS * 64 / 63 + 10_000) revert VenueRefusedLeg();
        try r.venuePosition{gas: DEAD_READ_GAS}(address(this), id) returns (uint256, uint256 c, uint256, uint256 s, uint256 d) {
            (coll, sup, debt) = (c, s, d);
            uint256 need = (d != 0 ? uint256(CAN_REPAY) : 0)
                | (Math.mulDiv(c, part, whole) != 0 ? uint256(CAN_RELEASE_COLLATERAL) : 0)
                | (Math.mulDiv(s, part, whole) != 0 ? uint256(CAN_WITHDRAW_SUPPLY) : 0);
            if (gasleft() < DEAD_READ_GAS * 64 / 63 + 10_000) revert VenueRefusedLeg();
            try r.venueCapacity{gas: DEAD_READ_GAS}(address(this), id) returns (IFinancingAccount.Capacity memory k) {
                ok = k.actions & need == need;
            } catch (bytes memory reason) {
                _notDead(reason);
            }
        } catch (bytes memory reason) {
            _notDead(reason);
        }
    }

    /// @dev Venue `id`'s lender's own check of its position (`IMMRouter.venueHealthy`); a read that reverts reads
    ///      healthy, so it keeps the guard.
    function _lenderHealthy(IMMRouter r, uint16 id) private view returns (bool) {
        try r.venueHealthy(address(this), id) returns (bool h) {
            return h;
        } catch (bytes memory reason) {
            ReentrancyGuardLib._passOnLock(reason);
            return true;
        }
    }

    /// @dev The WAD venue `id`'s position, posting `coll` of its collateral token, supplying `sup` of its debt token
    ///      and owing `debt` of it, covers its debt: its collateral's worth at the pool's prices, read as the unwind's
    ///      gate reads them (the feed's checked USD prices, none on a pool with no band) at the price of the venue's
    ///      pair (`FLAMMGateLib.frame`), rounded up, with its supply, over its debt, rounded down. Under WAD it is
    ///      under water: its debt past its supply is worth more than its collateral. The figures are the Router's
    ///      recognized ones, uncut by any haircut the venue reports, so a reported loss delays the abandon until the
    ///      position reads under water uncut. A gift to the account counts up to the Router's tracker of the units the
    ///      pool posted (`MMRouterLib.recognizedFrom`) and no further: none past it, but after a seizure that burns
    ///      units a refill up to it counts, and the position may read covered again. A position posting nothing reads
    ///      no price, its supply alone over its debt; `type(uint256).max` where its supply pays its debt, or a price
    ///      does not read.
    function _cover(FLAMMStore.S storage $, IMMRouter r, uint16 id, uint256 coll, uint256 sup, uint256 debt)
        private
        view
        returns (uint256)
    {
        if (debt <= sup) return type(uint256).max;
        if (coll != 0) {
            if (FLAMMStore.bandOff($)) return type(uint256).max;
            IMMRouter.VenueView memory v = r.venue(address(this), id);
            (bool ok, uint256 uc, uint256 ud,) =
                $.priceFeed.peekPair(FLAMMStore.tokenOf($, v.coll), FLAMMStore.tokenOf($, v.debt));
            uint256 f = ok ? FLAMMGateLib.frame(uc, ud, _scale($, v.coll), _scale($, v.debt)) : 0;
            if (f == 0) return type(uint256).max;
            sup += Math.mulDiv(coll, f, 1e36, Math.Rounding.Up);
        }
        return Math.mulDiv(sup, 1e18, debt);
    }

    /// @dev Token `t`'s scale: the pool asset's from the first word.
    function _scale(FLAMMStore.S storage $, uint256 t) private view returns (uint256) {
        return t == 0 ? $.shareScale : $.tokens[t].scale;
    }

    /// @dev {_guard} for a frame's written-off parts `m` ({mates}), which an unwind takes together, the same part of
    ///      each venue (`FLAMMClaimLib.unwindFence`): `held` where every venue takes every leg its part needs
    ///      ({_legsTaken}; a read that reverts is a refusal) and the frame is not given up as under water summed: its
    ///      cover is at least WAD, or one of its positions posts collateral and their lender's own check reads the
    ///      frame healthy or reverts ({_lenderHealthy}, at a venue whose position owes past its supply: one position at
    ///      the lender holds every venue's, and each kind's check at a frame's account reads the frame's). The cover is
    ///      what the positions post and supply over what they owe, summed in USD at the pool's prices ({_usdOf}), as
    ///      {_cover} reads one position's: `type(uint256).max` where none owes past its own supply, or a price does not
    ///      read; zero where none posts or supplies, which reads no price. It reads the whole positions, as {_guard}
    ///      does, so it is every part's too, every record of a frame holding the same fraction, and a part too small to
    ///      scale to a unit reads as its frame does.
    function _frameGuard(FLAMMStore.S storage $, uint256 m) private view returns (bool held, uint256 cover) {
        IMMRouter r = $.router;
        held = true;
        (bool backs, bool posts, bool priced) = (false, false, !FLAMMStore.bandOff($));
        // `debtor`: one past the slot of a position that owes past its supply, zero while none does
        (uint256 has, uint256 due, uint256 debtor) = (0, 0, 0);
        for (; m != 0; m &= m - 1) {
            uint16 id = uint16(low(m));
            FLAMMStore.Fence storage f = $.fences[id];
            (bool ok, uint256 c, uint256 s, uint256 d) = _legsTaken(r, id, f.live, uint256(f.live) + f.claimed);
            if (!ok) held = false;
            if (d > s) debtor = uint256(id) + 1;
            if (c != 0) posts = true;
            if (c | s != 0) backs = true;
            if (!priced) continue;
            (bool read, uint256 hc, uint256 dc) = _usdOf($, r, id, c, s, d);
            if (!read) priced = false;
            (has, due) = (has + hc, due + dc);
        }
        if (debtor == 0) cover = type(uint256).max;
        else if (!backs) cover = 0;
        else cover = priced && due != 0 ? Math.mulDiv(has, 1e18, due) : type(uint256).max;
        held = held && (cover >= 1e18 || (posts && _lenderHealthy(r, uint16(debtor - 1))));
    }

    /// @dev Venue `id`'s position, posting `c` of its collateral token, supplying `s` of its debt token and owing `d`
    ///      of it, in USD at the feed's checked prices of its pair, read as the unwind's gate reads them (none on a
    ///      pool with no band): what it posts and supplies (`has`), each rounded up, and what it owes (`due`), rounded
    ///      down; `read` false, and both zero, where a price does not read.
    function _usdOf(FLAMMStore.S storage $, IMMRouter r, uint16 id, uint256 c, uint256 s, uint256 d)
        private
        view
        returns (bool read, uint256 has, uint256 due)
    {
        IMMRouter.VenueView memory v = r.venue(address(this), id);
        (bool ok, uint256 uc, uint256 ud,) =
            $.priceFeed.peekPair(FLAMMStore.tokenOf($, v.coll), FLAMMStore.tokenOf($, v.debt));
        if (!ok || uc == 0 || ud == 0) return (false, 0, 0);
        (uint256 sc, uint256 sd) = (_scale($, v.coll), _scale($, v.debt));
        has = Math.mulDiv(c * sc, uc, 1e18, Math.Rounding.Up) + Math.mulDiv(s * sd, ud, 1e18, Math.Rounding.Up);
        (read, due) = (true, Math.mulDiv(d * sd, ud, 1e18));
    }

    /// @notice Lifts venue `id`'s fence, the curator's after D (the guardian cancels by hash; the schedule names the
    ///         fence's key, so it applies to no later fence of the slot). The whole position is the pool's again, as it
    ///         stands.
    /// @dev - At its execution no claim may be open (`ClaimsOpen`), the venue must take repays (`VenueRefusedLeg`), and
    ///        no token of its pair may have its custody out (`InvalidConfig`).
    ///      - The Router lifts the lock (refusing `DrawOutsideDrawnSet` where the unfenced venues would hold a token
    ///        owed and backing at once) and puts the venue last in each order; the pool clears the slot's retired and
    ///        idle bits, puts it back in its pair's mask and moves it back to its index in each order at the lock
    ///        ({_reinsert}).
    ///      - The venue's borrow and supply switches are what they were before the lock, borrowing where the Router
    ///        admits it (a threshold the lender cut under the pair's pin and gap leaves it off, for the curator's
    ///        `setVenueFlags` once it recovers, and supply returns alone).
    ///      - Where the venue owes, the debt-free proofs a read took during the fence, which left the venue out, end:
    ///        its debt token's flag and its pair's `pairsFree` bit clear, and only a read sets them again.
    ///      - Venues one token switch fenced together return to their places when lifted in index order (or each fence
    ///        lifted before the ones opened ahead of it); another order leaves a later one where the lift put it, which
    ///        `setPriorities` corrects.
    ///      - At a frame's account every venue the fence holds there ({mates}) is lifted with it, under this schedule,
    ///        which names their slots, each under the same checks, as their fence took them together, but for its
    ///        repays: a venue other than `id` that owes no more than the lenders' rounding
    ///        (`MMRouterLib.RELEASE_SLACK`) needs none. They return to their places in each order together.
    function liftFence(uint16 id) public {
        FLAMMStore.S storage $ = _s();
        _curator($);
        uint256 w = $.fenceWord;
        if (id >= 32 || (w >> id) & 1 == 0) revert NotFenced();
        // the frame's other fenced venues, read only where another venue is fenced; a frame's schedule names them
        uint256 m = uint256(1) << id;
        if (w & FLAMMStore.FENCE_VENUES & ~m != 0) m = matesOf($, id) & w & FLAMMStore.FENCE_VENUES;
        uint32 key = $.fences[id].key;
        bytes memory call = m & (m - 1) == 0 ? abi.encode(LIFT_FENCE, id, key) : abi.encode(LIFT_FENCE, id, key, m);
        if (_due($, call)) {
            IMMRouter r = $.router;
            uint256[32] memory lifted;
            for (uint256 k = m; k != 0; k &= k - 1) {
                uint256 i = low(k);
                lifted[i] = _lift($, r, uint16(i), i == id);
            }
            _reinsert(r, m, lifted);
            for (; m != 0; m &= m - 1) {
                uint256 i = low(m);
                emit FenceLifted(uint16(i), uint32(lifted[i] >> 32));
            }
        }
        ReentrancyGuardLib._unlockGuard();
    }

    /// @dev {liftFence}'s lift of fenced venue `id` but for its place in the orders: its checks, the Router's lift, the
    ///      debt-free proofs, the switches and the pool's bits, its record closed; the repay check where it is the
    ///      venue `named` or owes more than the lenders' rounding. Returns its index in each order at the lock, a byte
    ///      each from the lowest (borrow, supply, withdraw, repay), and its key past them.
    function _lift(FLAMMStore.S storage $, IMMRouter r, uint16 id, bool named) private returns (uint256 lifted) {
        FLAMMStore.Fence storage f = $.fences[id];
        if (f.claimed != 0) revert ClaimsOpen();
        IMMRouter.VenueView memory v = r.venue(address(this), id);
        uint256 w = $.fenceWord;
        uint256 out = w >> FLAMMStore.OUT_TOKENS_SHIFT;
        if (((out >> v.coll) | (out >> v.debt)) & 1 != 0) revert InvalidConfig();
        (,,,, uint256 owed) = r.venuePosition(address(this), id);
        if (
            (named || owed > MMRouterLib.RELEASE_SLACK)
                && r.venueActions(address(this), id) & CAN_REPAY == 0
        ) revert VenueRefusedLeg();
        r.lockVenue(id, false);
        if (owed != 0) {
            FLAMMStore.TokenCfg storage tc = $.tokens[v.debt];
            if (tc.debtFree) tc.debtFree = false;
            $.pairsFree &= ~uint32(1 << v.pair);
        }
        uint8 flags = f.flags;
        if (flags & (BORROW_ON | SUPPLY_ON) != 0) {
            bool supply = flags & SUPPLY_ON != 0;
            // borrowing returns only where the Router admits it; supply then returns alone
            try r.setVenueFlags(id, flags & BORROW_ON != 0, supply) {}
            catch (bytes memory reason) {
                ReentrancyGuardLib._passOnLock(reason);
                if (supply) r.setVenueFlags(id, false, true);
            }
        }
        uint32 bit = uint32(1) << id;
        $.retiredVenues &= ~bit;
        $.idleVenues &= ~bit;
        $.pairs[v.pair].venues |= bit;
        $.noLiveVenue = false;
        lifted = uint256(f.borrowAt) | uint256(f.supplyAt) << 8 | uint256(f.withdrawAt) << 16 | uint256(f.repayAt) << 24
            | uint256(f.key) << 32;
        delete $.fences[id];
        $.fenceWord = w & ~_slotBits(id);
    }

    /// @dev Venue slot `id`'s bits in the fence word, all of which its record's close clears: fenced, unwritten, kept
    ///      (`FLAMMStore.KEPT_SHIFT`) and junior debt (`FLAMMStore.JUNIOR_DEBT_SHIFT`).
    function _slotBits(uint256 id) private pure returns (uint256) {
        return (uint256(1) | uint256(1) << FLAMMStore.UNWRITTEN_SHIFT | uint256(1) << FLAMMStore.KEPT_SHIFT
                | uint256(1) << FLAMMStore.JUNIOR_DEBT_SHIFT) << id;
    }

    /// @dev After the Router's lifts put each venue of `m` last in each order, in turn: each back at its index there at
    ///      the lock (`lifted`, by slot, {_lift}), the lowest index first, so venues one fence took return to their
    ///      places, clamped to the order, in one `setPriorities` where any moves.
    function _reinsert(IMMRouter r, uint256 m, uint256[32] memory lifted) private {
        uint16[][4] memory o;
        (o[0], o[1], o[2], o[3]) = r.priorities(address(this));
        bool moved;
        for (uint256 k; k < 4; ++k) {
            uint16[] memory order = o[k];
            for (uint256 left = m; left != 0;) {
                // the venue left whose index at the lock is lowest
                (uint256 id, uint256 i) = (0, type(uint256).max);
                for (uint256 x = left; x != 0; x &= x - 1) {
                    uint256 j = low(x);
                    uint256 a = uint8(lifted[j] >> (8 * k));
                    if (a < i) (id, i) = (j, a);
                }
                left &= ~(uint256(1) << id);
                uint256 pos = order.length - 1;
                while (order[pos] != id) --pos;
                if (i >= pos) continue;
                for (uint256 j = pos; j > i; --j) {
                    order[j] = order[j - 1];
                }
                order[i] = uint16(id);
                moved = true;
            }
        }
        if (moved) r.setPriorities(o[0], o[1], o[2], o[3]);
    }

    /// @notice Returns token `t`'s custody and closes its record, the curator's after D (the guardian cancels by hash;
    ///         the schedule names the fence's key).
    /// @dev - Of the balance the pool holds past its tracked custody (`x`): the protocol's fee first, at most `x`, back
    ///        to the fee's record (the operator's share it holds with it, `FLAMMStore.shareOwed`, cut first by what a
    ///        short return leaves out); then the pool's part, `live` of `live + claimed` of the rest, rounded up, into
    ///        custody, and none where the record holds no pool part (none at the fence, or one given up,
    ///        {abandonFence}, which no share owns any more); then the rest, out of the pool to the key's vault
    ///        (`FLAMMClaimVault`, deployed here at {claimVault}).
    ///      - Where a claim is open the vault pays each its part of what it holds (`vaulted`), with no expiry
    ///        (`FLAMMClaimLib.settleClaim`); where none is, on a record with no pool part (a restore after the void's
    ///        claim settled, as that claim would have paid the void, or a balance on a record that never held a part),
    ///        it pays no one.
    ///      - So nothing of the token stays in the pool outside custody and the lift waits on no claim: the record
    ///        closes at once, the token leaves the parted set (the entries and the rises reopen where no other fence
    ///        holds a part) and can be fenced again, and its pairs' trade bits kept since its fence go back into the
    ///        curator's mask ({_reopen}).
    ///      - Any revert reverts the whole lift and the token stays fenced, to run again within the schedule's window:
    ///        a vault the token will not credit (one that admits listed holders only, until its issuer lists the key's
    ///        vault), or a pool the token blocks.
    ///      - Where custody comes back, the pool first moves one unit of the token to itself, so no lift returns
    ///        custody the pool cannot move, which every exit would then pay and fail on.
    function liftToken(uint8 t) public {
        FLAMMStore.S storage $ = _s();
        _curator($);
        FLAMMStore.checkToken($, t);
        uint256 w = $.fenceWord;
        if ((w >> (FLAMMStore.OUT_TOKENS_SHIFT + t)) & 1 == 0) revert NotFenced();
        uint256 index = 32 + uint256(t);
        FLAMMStore.Fence storage f = $.fences[index];
        uint32 key = f.key;
        if (_due($, abi.encode(LIFT_TOKEN, t, key))) {
            address token = FLAMMStore.tokenOf($, t);
            uint256 h = FLAMMStore.heldOf($, t);
            uint256 x = FLAMMStore.balanceOfThis(token);
            x = x > h ? x - h : 0;
            uint256 fee = Math.min(f.fee, x);
            // a short restore comes off the operator's share the record held first: the protocol's part is restored
            // first
            if (fee < f.fee) FLAMMStore.cutShare($, t, f.fee - fee);
            (uint256 live, uint256 claimed) = (f.live, f.claimed);
            uint256 own = x - fee;
            if (live == 0) own = 0;
            else if (claimed != 0) own = Math.mulDiv(own, live, live + claimed, Math.Rounding.Up);
            // custody comes back only where the pool still moves the token: one unit to itself first
            if (fee + own != 0) FLAMMStore.safeTransfer(token, address(this), 1);
            if (fee != 0) _restoreFee($, t, fee);
            h += fee + own;
            FLAMMStore.setHeld($, t, h);
            uint256 pot = x - fee - own;
            if (claimed != 0 || pot != 0) {
                address vault = address(new FLAMMClaimVault{salt: bytes32(uint256(key))}());
                ($.vaulted[key], $.vaults[key]) = (claimed, vault);
                // the floor of a stranger's draw: the pot per `ONE` of the claims it pays
                if (claimed != 0) $.strangerFloor[key] = Math.mulDiv(pot, ONE, claimed);
                if (pot != 0) FLAMMStore.safeTransfer(token, vault, pot);
                if (FLAMMStore.balanceOfThis(token) < h) revert CustodyMismatch();
                emit ClaimsVaulted(key, vault, pot, claimed);
            }
            emit TokenLifted(t, key, fee, own);
            delete $.fences[index];
            w &= ~(
                (uint256(1) << (FLAMMStore.FENCED_TOKENS_SHIFT + t)) | (uint256(1) << (FLAMMStore.OUT_TOKENS_SHIFT + t))
                    | (uint256(1) << (FLAMMStore.UNWRITTEN_SHIFT + index))
                    | (uint256(1) << (FLAMMStore.PARTED_TOKENS_SHIFT + t))
            );
            $.fenceWord = w;
            _reopen($, t, key, w);
        }
        ReentrancyGuardLib._unlockGuard();
    }

    /// @dev Token `t`'s pairs' trade bits kept since its fence back into the curator's mask, but for pairs naming
    ///      another token whose record is open (`w`, the fence word with `t`'s record closed), which that token's lift
    ///      restores. A closing of the mask while the record was open dropped the bits it left out, so it carries
    ///      through. `SWAP_FENCE` clears with the last open record, and the owed bit then where no record owes.
    function _reopen(FLAMMStore.S storage $, uint8 t, uint32 key, uint256 w) private {
        uint256 o = pairsOf(t) & ~closedPairs(w);
        uint256 kept = $.fenceTrades;
        uint256 back = kept & o;
        if (kept & o != 0) $.fenceTrades = kept & ~o;
        uint256 cur = $.tradePairs;
        if (back & ~cur != 0) {
            cur |= back;
            $.tradePairs = cur;
            emit TradePairsSet(cur, msg.sender);
        }
        bool open = (w >> FLAMMStore.FENCED_TOKENS_SHIFT) & 0xffff != 0;
        // the last open record's close clears the fence's bit, then the owed bit where no record owes
        if (!open) $.swapBits &= ~FLAMMStore.SWAP_FENCE;
        FLAMMAdmitLib.syncSwapBits($, $.hookPairs, cur);
        if (!open) FLAMMLane.clearOwed($);
        emit TokenReopened(t, key, back);
    }

    // ------------------------------------------------------------------ the pool's other units
    /// @notice A fenced slot's retirement (`FLAMMAdmitLib.retireVenue`, the Router having found it empty): its record
    ///         closes, so a claim left under its key settles for nothing.
    function onRetire(FLAMMStore.S storage $, uint16 id) internal {
        uint256 w = $.fenceWord;
        if ((w >> id) & 1 == 0) return;
        $.fenceWord = w & ~_slotBits(id);
        uint32 key = $.fences[id].key;
        delete $.fences[id];
        emit FenceLifted(id, key);
    }

    /// @notice The curator's trade mask `mask` while a token's record is open (`FLAMMStore.SWAP_FENCE`,
    ///         `FLAMMAdmitLib.setTradeMask`): the pairs naming such a token stay closed, an opening of one, at once or
    ///         scheduled, dropped; its reopening restores the bits its fence saved that no closing since left out (the
    ///         mask's writers drop those from `FLAMMStore.S.fenceTrades`, and naming a saved bit again opens nothing).
    function keepTrades(FLAMMStore.S storage $, uint256 mask) internal view returns (uint256) {
        return mask & ~closedPairs($.fenceWord);
    }

    /// @notice Whether a token's record holds the custody of token `t` out, its pair's venues fenced with it: the
    ///         curator's seed and a venue admitted on a pair naming it are refused then.
    function isOut(FLAMMStore.S storage $, uint256 t) internal view returns (bool) {
        return $.swapBits & FLAMMStore.SWAP_FENCE != 0 && ($.fenceWord >> (FLAMMStore.OUT_TOKENS_SHIFT + t)) & 1 != 0;
    }

    /// @notice Every pair naming token `t`, the trade masks' layout (bit `16 * i + j`: a swap of `i` for `j`).
    function pairsOf(uint256 t) internal pure returns (uint256) {
        return (uint256(0xffff) << (16 * t)) | (COLUMN << t);
    }

    /// @notice Every pair naming a token whose record is open in fence word `w`.
    function closedPairs(uint256 w) internal pure returns (uint256 o) {
        for (uint256 m = (w >> FLAMMStore.FENCED_TOKENS_SHIFT) & 0xffff; m != 0; m &= m - 1) {
            o |= pairsOf(low(m));
        }
    }

    /// @dev Moves the protocol's fee owed in token `t` out of its record (`FLAMMStore.feeOwed`): the cheap lane's
    ///      accrual of token 1's, and the hook fills' record. The record's bit stays: the token's fence keeps it set.
    function _clearFee(FLAMMStore.S storage $, uint256 t) private {
        if (t == 1 && $.swapBits & FLAMMStore.SWAP_LANE != 0) $.laneWord &= ~FLAMMStore.LANE_ACCRUED_MASK;
        if ($.poolBits & FLAMMStore.POOL_SPREAD_OWED != 0 && $.spreadFeeOwed[t] != 0) $.spreadFeeOwed[t] = 0;
    }

    /// @dev Returns `fee` of the protocol's to token `t`'s record: `laneWord`'s for token 1 on a cheap-lane pool (its
    ///      pairs closed, the cheap lane accrued none since), else the hook fills' record.
    function _restoreFee(FLAMMStore.S storage $, uint256 t, uint256 fee) private {
        if (t == 1 && $.swapBits & FLAMMStore.SWAP_LANE != 0) $.laneWord += fee;
        else FLAMMLane.record($, t, fee);
    }

    // ------------------------------------------------------------------ views
    /// @notice Fence `key`'s vault (`FLAMMClaimVault`): the one deployed, a token fence's by its lift where a claim is
    ///         open or a balance is left for the vault, and a venue fence's by the first payout a settlement parked for
    ///         a holder (`FLAMMClaimLib.drawParked`), else the CREATE2 address it would be deployed at, fixed from the
    ///         fence's opening (the key and the vault's creation code, which stays as it is), so an issuer that admits
    ///         listed holders only can list it during the delay before the lift.
    function claimVault(uint32 key) public view returns (address vault) {
        vault = _s().vaults[key];
        if (vault == address(0)) {
            bytes32 code = keccak256(type(FLAMMClaimVault).creationCode);
            vault = address(
                uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), bytes32(uint256(key)), code))))
            );
        }
    }

    /// @notice The venue slots at venue `id`'s lender account where it is a frame's (`FRAME_VENUE` in `IMMRouter.sol`),
    ///         which answers no collateral token (`IFinancingAccount.COLLATERAL_ASSET`): bit `i` for each slot the
    ///         Router lists there, `id`'s among them, retired and fenced ones too (`FLAMM.retiredVenues`); `id`'s bit
    ///         alone at a pair's own account, where each venue is its own health basis. A frame's venues share one
    ///         position at the lender, so the pool fences, lifts and gives them up together, its claims and unwinds
    ///         take the same part of each (`FLAMMClaimLib`), and its maintainer tops them up as one
    ///         (`FLAMMMaintainLib.maintainCollateral`). `InvalidConfig` where `id` names no slot.
    function mates(uint16 id) public view returns (uint256) {
        return matesOf(_s(), id);
    }

    /// @notice {mates} at the pool's storage `$`, inlined into the libraries that act on a frame's venues together.
    function matesOf(FLAMMStore.S storage $, uint16 id) internal view returns (uint256 m) {
        IMMRouter r = $.router;
        uint256 n = r.venueCount(address(this));
        if (id >= n) revert InvalidConfig();
        address a = r.venue(address(this), id).account;
        m = uint256(1) << id;
        if (IFinancingAccount(a).COLLATERAL_ASSET() != address(0)) return m;
        for (uint256 i; i < n; ++i) {
            if (i != id && r.venue(address(this), uint16(i)).account == a) m |= uint256(1) << i;
        }
    }

    /// @notice The fenced venues, bit `i` for venue `i`: each is in `FLAMM.retiredVenues` too, the walks' skip set.
    function fencedVenues() public view returns (uint256) {
        return _s().fenceWord & FLAMMStore.FENCE_VENUES;
    }

    /// @notice The fence word (`FLAMMStore.S.fenceWord`): the fenced venues, the tokens whose record is open, the
    ///         tokens whose custody is out, the fences whose pool part is not written off, the count of fences opened,
    ///         and the tokens whose custody's fence holds a pool part, written off or not (`FLAMM.partedFences` reads
    ///         the parts).
    function fences() public view returns (uint256) {
        return _s().fenceWord;
    }

    /// @notice The record at `index`: venue `i`'s at `i`, token `t`'s custody's at `32 + t`.
    function fenceOf(uint256 index) public view returns (FLAMMStore.Fence memory) {
        return _s().fences[index];
    }

    // ------------------------------------------------------------------ the exits' claims
    // The exits' side of the fences: an exit's claims at each fence that holds a pool part, which the pool's exit
    // records (`FLAMM.redeemProRata`) only where a marker says a fence may hold one (a slot both retired and idle,
    // which the exit's legs read beside the Router, `FLAMMFlowLib.redeem`, or `FLAMMStore.SWAP_FENCE`), so a pool with
    // none pays nothing for it. Compiled into the pool, its one caller: no entry of this library, so the pool's
    // fallback never reaches it.

    /// @dev Rounding dust: a part under this, `ONE / 1e12` of the fence, is not recorded and stays with the shares
    ///      that stay, so no exit makes a claim the lift would wait on for nothing.
    uint256 internal constant DUST = 1e24;

    /// @notice An exit of `shares` of `supply` (after the skim, before the burn) by `holder`, its receiver: at each
    ///         fence where the pool's part `live` is not zero, `part = live * shares / supply`, rounded down so the
    ///         shares that stay keep the dust, leaves `live` for `claimed` and is the holder's claim; a part under
    ///         {DUST} is none. On token `t`'s record the part is less `cuts[t]` (`cuts` empty where no token's custody
    ///         is out): what the exit paid from it of what it owed in the token (`FLAMMFlowLib.proRata`), which stays
    ///         with the pool's part. The fences read are {parts}'. A receiver of the zero address is refused
    ///         (`InvalidAmount`): no one could settle or move its claim, which would hold its fence's lift for good,
    ///         and an exit that pays nothing transfers nothing.
    function recordClaims(FLAMMStore.S storage $, address holder, uint256 shares, uint256 supply, uint256[] memory cuts)
        internal
    {
        if (holder == address(0)) revert InvalidAmount();
        uint256 w = $.fenceWord;
        uint256 m = parts($, w);
        for (; m != 0; m &= m - 1) {
            uint256 i = low(m);
            FLAMMStore.Fence storage f = $.fences[i];
            (uint256 live, uint256 claimed) = (f.live, f.claimed);
            uint256 part = Math.mulDiv(live, shares, supply);
            if (i >= 32 && cuts.length != 0) {
                uint256 c = cuts[i - 32];
                part = part > c ? part - c : 0;
            }
            if (part < DUST) continue;
            (f.live, f.claimed) = (uint128(live - part), uint128(claimed + part));
            uint32 key = f.key;
            // a slice of a kept share is junior: behind the senior claims (`FLAMMStore.SENIORS`), its debt share paid
            // by the exit (`FLAMMFlowLib.proRata`), into custody or, in a token whose custody is out, from its claim
            // on that token's record, which the pool's part keeps
            $.claims[key][holder] += i < 32 && (w >> (FLAMMStore.KEPT_SHIFT + i)) & 1 != 0 ? part << 128 : part;
            emit ClaimRecorded(key, holder, part);
        }
    }

    /// @notice The fences where an exit records a claim, bit `i` for venue `i`, `32 + t` for token `t`'s custody, in
    ///         fence word `w`: the venue slots both retired and idle (a pool part there) or holding a kept share
    ///         (`FLAMMStore.KEPT_SHIFT`), written off or not, and the tokens whose custody is out.
    function parts(FLAMMStore.S storage $, uint256 w) internal view returns (uint256) {
        return ((uint256($.retiredVenues & $.idleVenues) | (w >> FLAMMStore.KEPT_SHIFT)) & w & FLAMMStore.FENCE_VENUES)
            | (((w >> FLAMMStore.OUT_TOKENS_SHIFT) & 0xffff) << 32);
    }

    /// @notice The index of `m`'s lowest set bit; `m` is not zero. The fences' and their claims' walks read it
    ///         (here, `FLAMMClaimLib`, `FLAMMTopUpLib`).
    function low(uint256 m) internal pure returns (uint256 i) {
        while ((m >> i) & 1 == 0) ++i;
    }
}
Настройки компилятораПоказать
{
  "viaIR": true,
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {
    "src/core/mm/MMRouterLib.sol": {
      "MMRouterLib": "0x95b386d242c061ab2551a0d294c94dfe3948ef2c"
    },
    "src/core/flamm/FLAMMLane.sol": {
      "FLAMMLane": "0x5d81d4a7cfd40c3dfe9e009212545608be90de37"
    },
    "src/core/flamm/FLAMMRoute.sol": {
      "FLAMMRoute": "0xb1ffeae12c53f876aa0e495e9c00c829f47fb0fe"
    },
    "src/periphery/FLAMMMaxima.sol": {
      "FLAMMMaxima": "0x68546ce65986354c5394e4bc2f28027ef490a91b"
    },
    "src/core/flamm/FLAMMLawLib.sol": {
      "FLAMMLawLib": "0xf55c5807b6fbe5555443fd6ddbbd52079849cf45"
    },
    "src/core/flamm/FLAMMOpsLib.sol": {
      "FLAMMOpsLib": "0x0be7fdb3d611b05df90a61778a644654735ecc47"
    },
    "src/core/mm/AaveV3ReadsLib.sol": {
      "AaveV3ReadsLib": "0xa5db415d1af2158dd0a4a3c9c1eada277472803e"
    },
    "src/core/flamm/FLAMMFlowLib.sol": {
      "FLAMMFlowLib": "0x27957f4ddf818de39a1c9dba0bf273a5994cfb77"
    },
    "src/core/flamm/FLAMMGateLib.sol": {
      "FLAMMGateLib": "0x3a05779218510235badcbddcdd78732a16434368"
    },
    "src/core/flamm/FLAMMKeptLib.sol": {
      "FLAMMKeptLib": "0x70cace9076ac8dd6a691ced2f9aa62a5c360bee4"
    },
    "src/core/mm/CTokenMarketLib.sol": {
      "CTokenMarketLib": "0x60e4ab6b6ba72325c58924ee7753b14b37314010"
    },
    "src/core/flamm/FLAMMAdmitLib.sol": {
      "FLAMMAdmitLib": "0x0b107b1f0c64f3716554ccc83b53e492e51ce950"
    },
    "src/core/flamm/FLAMMBlindLib.sol": {
      "FLAMMBlindLib": "0x634d5a14c42fb5bec82a7aea32bf636a8d298fcd"
    },
    "src/core/flamm/FLAMMClaimLib.sol": {
      "FLAMMClaimLib": "0x5dc3bb30c60390ce9522b7e3ca315dd334aa7e91"
    },
    "src/core/flamm/FLAMMFenceLib.sol": {
      "FLAMMFenceLib": "0x9dbba0cbd9d7883f4eedd1c8e08780fac4798f1a"
    },
    "src/core/flamm/FLAMMFloatLib.sol": {
      "FLAMMFloatLib": "0x6b2b25ebba12e78afea697b9ac6d2167a6518935"
    },
    "src/core/flamm/FLAMMQuoteLib.sol": {
      "FLAMMQuoteLib": "0x99de54a108c64ebe23ac7766901c199a91929869"
    },
    "src/core/flamm/FLAMMTopUpLib.sol": {
      "FLAMMTopUpLib": "0xe4be161081d1c9aa91951ca347cc99da35cfac2e"
    },
    "src/core/mm/CTokenRewardsLib.sol": {
      "CTokenRewardsLib": "0x93ab647215a9f9f1050302a76506afcbc0262861"
    },
    "src/core/mm/MMRouterAdminLib.sol": {
      "MMRouterAdminLib": "0x6abb06b1e9cba80888992d366913bb9b7760ea7e"
    },
    "src/core/flamm/FLAMMPolicyLib.sol": {
      "FLAMMPolicyLib": "0x3858e2202cebcb6f12f36a596260dd2ed8f91f06"
    },
    "src/core/flamm/FLAMMSettleLib.sol": {
      "FLAMMSettleLib": "0x4551cddb1de95f5452f6a0f836e047e01833b301"
    },
    "src/core/flamm/FLAMMSharedLib.sol": {
      "FLAMMSharedLib": "0xb852d9cbdda85cbed7da0885bca2714ba1b71005"
    },
    "src/periphery/FLAMMExitMaxima.sol": {
      "FLAMMExitMaxima": "0x6a6a3ff1e834dbbf07dee472e07d1ca977798659"
    },
    "src/hooks/everlong/LeverageLib.sol": {
      "LeverageLib": "0x80396f9f894cc3060dfaa7468c4f576e8b16d055"
    },
    "src/core/flamm/FLAMMMaintainLib.sol": {
      "FLAMMMaintainLib": "0xaa5434e13eb54f37c577229efc981cceceb56417"
    },
    "src/core/flamm/FLAMMPairQuoteLib.sol": {
      "FLAMMPairQuoteLib": "0x3bc57bc05cc9dd1fe18106add8ffc060882055dd"
    },
    "src/hooks/everlong/EverlongOpsLib.sol": {
      "EverlongOpsLib": "0xf6d56f4ed6a7c441fd96c53a327026bac19dfeef"
    }
  },
  "optimizer": {
    "runs": 100,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable-compat/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-compat/contracts/",
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/src/"
  ]
}

Исходный код и метаданные: Sourcify.

Исходный код принадлежит авторам контракта.