Verified contractExactUNLICENSED
FLAMMMaxima
Address0x4a997343d91c981bf63274fc222aa96d32d6259c
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 100 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,396,580
- Creation transaction
- 0x9a13833ab6…70e810177a
- Libraries
- src/core/mm/MMRouterLib.sol:MMRouterLib0xa474…d2b4e5src/core/flamm/FLAMMLane.sol:FLAMMLane0x0988…d22e98src/core/flamm/FLAMMRoute.sol:FLAMMRoute0x312e…0fdaa9src/periphery/FLAMMMaxima.sol:FLAMMMaxima0x4a99…d6259csrc/core/flamm/FLAMMLawLib.sol:FLAMMLawLib0x5d47…27cc62src/core/flamm/FLAMMOpsLib.sol:FLAMMOpsLib0x0bfe…043753src/core/mm/AaveV3ReadsLib.sol:AaveV3ReadsLib0xd53f…ed5983src/core/flamm/FLAMMFlowLib.sol:FLAMMFlowLib0x2577…4e3473src/core/flamm/FLAMMGateLib.sol:FLAMMGateLib0xf0be…2b9555src/core/flamm/FLAMMKeptLib.sol:FLAMMKeptLib0x7a11…58517bsrc/core/mm/CTokenMarketLib.sol:CTokenMarketLib0x18c5…b2071csrc/core/flamm/FLAMMAdmitLib.sol:FLAMMAdmitLib0xa6db…bdcbcbsrc/core/flamm/FLAMMBlindLib.sol:FLAMMBlindLib0x0b8d…2e7e5csrc/core/flamm/FLAMMClaimLib.sol:FLAMMClaimLib0x02b4…731ccesrc/core/flamm/FLAMMFenceLib.sol:FLAMMFenceLib0xa16d…a201e8src/core/flamm/FLAMMFloatLib.sol:FLAMMFloatLib0x539e…a79737src/core/flamm/FLAMMQuoteLib.sol:FLAMMQuoteLib0xa4d3…d5ce2esrc/core/flamm/FLAMMTopUpLib.sol:FLAMMTopUpLib0x7c55…d233dfsrc/core/mm/CTokenRewardsLib.sol:CTokenRewardsLib0xcda6…a4dcf7src/core/mm/MMRouterAdminLib.sol:MMRouterAdminLib0x8423…7adc96src/core/flamm/FLAMMPolicyLib.sol:FLAMMPolicyLib0xa6b4…0c67f9src/core/flamm/FLAMMSettleLib.sol:FLAMMSettleLib0xb489…d3c7cbsrc/core/flamm/FLAMMSharedLib.sol:FLAMMSharedLib0xfaae…2511basrc/periphery/FLAMMExitMaxima.sol:FLAMMExitMaxima0x480f…4e0a81src/hooks/everlong/LeverageLib.sol:LeverageLib0x1b1d…40ad11src/core/flamm/FLAMMMaintainLib.sol:FLAMMMaintainLib0x9499…409cc2src/core/flamm/FLAMMPairQuoteLib.sol:FLAMMPairQuoteLib0x0775…d94cbesrc/hooks/everlong/EverlongOpsLib.sol:EverlongOpsLib0xabe4…7426f7
55 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/periphery/FLAMMMaxima.solmain44.38 KB
- lib/openzeppelin-contracts-compat/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts-compat/contracts/token/ERC20/IERC20.sol2.77 KB
- lib/openzeppelin-contracts-compat/contracts/token/ERC20/extensions/IERC20Metadata.sol683 B
- lib/openzeppelin-contracts-compat/contracts/utils/math/Math.sol12.51 KB
- lib/openzeppelin-contracts-compat/contracts/utils/math/SafeCast.sol35.08 KB
- lib/openzeppelin-contracts-upgradeable-compat/contracts/proxy/utils/Initializable.sol8.91 KB
- lib/openzeppelin-contracts-upgradeable-compat/contracts/token/ERC20/ERC20Upgradeable.sol12.23 KB
- lib/openzeppelin-contracts-upgradeable-compat/contracts/utils/ContextUpgradeable.sol1.19 KB
- src/core/PriceFeed.sol19.12 KB
- src/core/flamm/FLAMM.sol54.32 KB
- src/core/flamm/FLAMMAdmitLib.sol37.26 KB
- src/core/flamm/FLAMMBlindLib.sol41.3 KB
- src/core/flamm/FLAMMClaimLib.sol49.42 KB
- src/core/flamm/FLAMMClaimVault.sol1.65 KB
- src/core/flamm/FLAMMFenceLib.sol72.83 KB
- src/core/flamm/FLAMMFloatLib.sol57.91 KB
- src/core/flamm/FLAMMFlowLib.sol55.24 KB
- src/core/flamm/FLAMMGateLib.sol87.39 KB
- src/core/flamm/FLAMMKeptLib.sol45.59 KB
- src/core/flamm/FLAMMLane.sol70.27 KB
- src/core/flamm/FLAMMLawLib.sol60.67 KB
- src/core/flamm/FLAMMMaintainLib.sol41.67 KB
- src/core/flamm/FLAMMOpsLib.sol32.2 KB
- src/core/flamm/FLAMMPolicyLib.sol39.49 KB
- src/core/flamm/FLAMMQuoteLib.sol16.89 KB
- src/core/flamm/FLAMMRoute.sol16.45 KB
- src/core/flamm/FLAMMSettleLib.sol42.92 KB
- src/core/flamm/FLAMMSharedLib.sol13.11 KB
- src/core/flamm/FLAMMStore.sol135.42 KB
- src/core/flamm/FLAMMSwapLib.sol55.65 KB
- src/core/flamm/FLAMMTopUpLib.sol48.97 KB
- src/core/mm/MMRouterAdminLib.sol24.07 KB
- src/core/mm/MMRouterLib.sol72.71 KB
- src/core/mm/VenueAccountBase.sol15.61 KB
- src/core/mm/VenueReads.sol2.05 KB
- src/interfaces/core/IDepositAllowlist.sol1.06 KB
- src/interfaces/core/IEverlongCore.sol889 B
- src/interfaces/core/IPriceFeed.sol3.71 KB
- src/interfaces/core/flamm/IFLAMM.sol52.68 KB
- src/interfaces/core/flamm/IFLAMMFence.sol17.71 KB
- src/interfaces/core/flamm/IFLAMMHooks.sol8.36 KB
- src/interfaces/core/flamm/IHookCapabilities.sol2.63 KB
- src/interfaces/core/flamm/IPairHook.sol14.14 KB
- src/interfaces/core/mm/IAccountDeployer.sol2.99 KB
- src/interfaces/core/mm/IFinancingAccount.sol46.04 KB
- src/interfaces/core/mm/IHeldRepay.sol2.61 KB
- src/interfaces/core/mm/IMMRouter.sol70.37 KB
- src/interfaces/utils/integrations/IAggregatorV3Interface.sol818 B
- src/libraries/Constants.sol2.11 KB
- src/libraries/DelayLib.sol11.22 KB
- src/libraries/ReentrancyGuardLib.sol2.52 KB
- src/libraries/SafeTransferLib.sol5.11 KB
- src/periphery/FLAMMExitMaxima.sol23.75 KB
- src/propamm/libraries/PropAMMLaneLib.sol2.31 KB
src/periphery/FLAMMMaxima.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, VenueFrozen, WAD} from "src/core/flamm/FLAMMStore.sol";
import {FLAMMGateLib} from "src/core/flamm/FLAMMGateLib.sol";
import {FLAMMFlowLib} from "src/core/flamm/FLAMMFlowLib.sol";
import {IFLAMM, IFLAMMProtocolFee} from "src/interfaces/core/flamm/IFLAMM.sol";
import {IFLAMMFence} from "src/interfaces/core/flamm/IFLAMMFence.sol";
import {IMMRouter} from "src/interfaces/core/mm/IMMRouter.sol";
import {
IFinancingAccount,
CAN_SUPPLY,
CAP_ACTION_GATES,
CAP_REPORTED_LOSS,
CAP_SHARED_LIQUIDITY,
CAP_REDEMPTION_FEE,
CAP_HELD_REPAY,
CAP_ACCRUING_COLLATERAL
} from "src/interfaces/core/mm/IFinancingAccount.sol";
import {IPriceFeed} from "src/interfaces/core/IPriceFeed.sol";
import {IDepositAllowlist} from "src/interfaces/core/IDepositAllowlist.sol";
import {IEverlongCore} from "src/interfaces/core/IEverlongCore.sol";
import {ReentrancyGuardLib} from "src/libraries/ReentrancyGuardLib.sol";
import {FLAMMExitMaxima} from "src/periphery/FLAMMExitMaxima.sol";
/// @notice The pool views the maxima read through this interface: the cheap lane's words, whose config word's version
/// bits are nonzero once the cheap lane is on (`FLAMMStore.LANE_VERSION_SHIFT`); the deposit basket, every
/// token's entry (`FLAMMFloatLib`); and the spread fee owed in a token (`FLAMM`).
interface IFLAMMBasketViews {
/// @notice The cheap-lane word and the config word as they stand; the third word reads zero.
function lane() external view returns (uint256 laneWord, uint256 laneConfig, uint256 pending);
/// @notice A cheap-lane pool's deposit basket per 1e18 shares, one entry per listed token in its base units.
function basketTokens() external view returns (uint256[] memory e);
/// @notice The spread fee the pool owes the protocol in token `t`, native units.
function spreadFeeOwed(uint8 t) external view returns (uint256);
}
/// @notice The pro-rata maxima of any pool, outside it: the largest `depositProRata`, `mintProRata` and `redeemProRata`
/// a holder may make now, recomputed from the pool's public views and the Router's with the pool's own
/// arithmetic (`FLAMMGateLib`'s and `FLAMMFlowLib`'s pure helpers) on the pool book (its `position` of every
/// token) and the entry's own legs (its previews). Deployed once and read like a contract (its entries are
/// views): each entry takes the pool.
/// @dev Where it reads other than the pool's flows would size:
/// - A venue the pool holds idle (found empty at its last read) that has since taken a gift or kept share dust
/// bounds this getter's sizes and none of the pool's, as no view tells the pool's idle record, so it reads lower
/// there.
/// - Venues sharing one reserve's cash are netted by token, so where such venues of one token sit on different
/// reserves (two markets of one lender) the least room or cash of them bounds them all and it reads lower, far
/// where a strict rate ceiling leaves one of them little room.
/// - Past a lender's borrow index of 2 RAY an entry at its maximum with two borrow legs at one pair's venues can
/// be refused at the pair's debt cap (`FLAMMGateLib.READ_BACK_UNITS`).
/// - Where the deposit preview at the pool asset's whole legs does not answer (a pool book that owes the pool
/// asset, or an entry of that size its preview refuses), the shares the fee's skim mints first (none while a
/// fence holds a pool part, as the pool mints none then) are rebuilt from `limits()`, whose fee mark is the
/// pool's divided by the share scale, and the maxima take the end of that rounding that sizes lower, but the
/// record of what exits forfeited at frozen venue marks, which raises the pool's fee mark until the next skim,
/// is not read there: in that window, with a fee rate on, the mint and exit maxima can read up to about the fee
/// on the forfeited value higher than the flows would size.
/// - An entry whose borrow or supply leg would leave a venue holding a minimum position under it (one whose
/// minimum rose past its debt, or whose supply a payout or an exit left under its minimum) reads 0, as its
/// preview refuses it (`FLAMMSharedLib.heldLegsCheck`) and no smaller entry passes: a safe under-report, which a
/// supply batch of at least such a venue's minimum and the lenders' rounding avoids (a supply leg under the
/// batch moves through custody), though a dust entry whose borrow leg rounds to nothing can pass, and where a
/// debt cap's room lands within a unit of the minimum the rounding can read 0 though a slightly larger entry
/// within the cap passes (the bound can be the mint cap, a pair's debt cap, which `borrowRoom` applies after the
/// minimum's check, or a venue cap's rounding edge).
/// - At a venue whose collateral accrues and whose margin at its threshold, read at the lower of the lender's own
/// price and the pool's price, covers one unit neither over the pin nor over the venue's own debt (a venue of a
/// few units), an entry whose post there credits no unit still borrows its slice, which the lender refuses past
/// what the units the venue holds carry, while a larger entry, whose post credits one, passes: the entry maxima
/// read at most the size whose slice the lender takes with nothing credited at that threshold, so every smaller
/// entry passes too, and read lower there than the largest entry the lender takes.
/// - Where an entry's preview refuses a restoring leg custody cannot fill (`IMMRouter.Unhealthy`) at the first
/// size the bounds give, that size is halved up to eight times and the maximum reads 0 past them, though a
/// smaller entry can still pass there.
///
/// The legs are read as the flows take them:
/// - An entry's or an exit's supply leg under its token's batch (`minSupplyBatch`) moves through custody, not the
/// venue, so no venue room bounds it.
/// - An exit's collateral a venue releases short is paid from the pool's custody of that token, one budget per
/// token with the exiter's own custody slice and the supply legs it moves, where that token is owed nowhere or
/// stays net debt-free after the exit, as the exit's ledger gate allows.
/// - An exit's repay a venue may take short is read where its kind reports the hold (a minimum position, a
/// lender's bound per market, spent across the venues borrowing there in the exit's order: `FLAMMExitMaxima`),
/// the dust the exit allows there counted only where that venue's slice is its token's only short release, and
/// a repay that leaves a venue owing nothing holds nothing (an accruing lender taking a whole repay a scaled
/// unit short).
/// - Venues sharing one reserve are bounded by that reserve's own room or cash, not by one venue's cap at the
/// Router, and each one's cap there holds back a share's assets and a unit per venue, which earlier legs can
/// move it by.
library FLAMMMaxima {
/// @dev {_legs}' refusals: a restoring leg custody cannot fill (`IMMRouter.Unhealthy`), and a borrow leg that
/// leaves a venue under its minimum position, or a supply leg that does (`IMMRouter.InsufficientLiquidity`).
uint256 private constant REFUSED_UNHEALTHY = 1;
uint256 private constant REFUSED_MINIMUM = 2;
/// @dev How often {_fitVenues} halves its first size while the preview refuses a restoring leg there.
uint256 private constant RESTORE_HALVINGS = 8;
/// @dev The facts every maximum reads once: the share supply; the pool's lock (`locked`: a flow holds it, where
/// every maximum reads 0), its frozen venue mark (`VenueFrozen`) and its NAV, as `totalAssets` answers; its
/// `limits()`; `bandOff`, whether token 1 has no swap band, where the pool reads no price; `lane`, whether the
/// pool's cheap lane is on; `m`, the token count; `n`, the venue count; `retired`, the slots the pool's walks
/// skip (`IFLAMM.retiredVenues`); the venues past those, by the capabilities their accounts declare (`gated`:
/// `CAP_ACTION_GATES`; `shared`: `CAP_SHARED_LIQUIDITY`; `fee`: `CAP_REDEMPTION_FEE`; `lossy`:
/// `CAP_REPORTED_LOSS`; `held`: `CAP_HELD_REPAY`; `accruing`: `CAP_ACCRUING_COLLATERAL`), each one's view as
/// the Router records it (`v`); `batch`, each token's supply batch, read on first use (one past it, zero
/// unread).
struct Ctx {
IFLAMM p;
IMMRouter r;
uint256 supply;
bool locked;
bool frozen;
bool navOk;
uint256 nav;
IFLAMM.Limits lim;
bool bandOff;
bool lane;
uint256 m;
uint256 n;
uint256 retired;
uint256 gated;
uint256 shared;
uint256 fee;
uint256 lossy;
uint256 held;
uint256 accruing;
IMMRouter.VenueView[] v;
uint256[] batch;
}
/// @notice The largest `depositProRata` for `receiver` now, in the pool asset: zero where the entry refuses (the
/// lock, the pause, the switch, the allowlist, no supply, a frozen venue mark, a fence holding a pool part,
/// written off or not, a cheap-lane pool waiting for its deposit basket, a pool book that owes the pool
/// asset, an unpriced debt, a pool book the fee cannot price, a spread fee owed past custody), else bounded
/// by the venue legs alone, each within its venue's room, one pair's borrow legs together within its debt
/// cap and one token's supply legs together within its supply cap, and `type(uint256).max` where none
/// bounds it short of custody's 128 bits.
function maxDepositProRata(address pool, address receiver) public view returns (uint256) {
Ctx memory c = _ctx(pool);
if (c.locked || !_entryOpen(c, receiver)) return 0;
(FLAMMGateLib.Book memory b, address[] memory tok) = _priced(c);
if (!_priceable(c, b, tok) || _feePastCustody(c)) return 0;
FLAMMGateLib.Leg memory L0 = b.legs[0];
if (L0.owed != 0) return 0;
uint256 den = L0.held + L0.supplied + L0.posted;
if (den == 0) return 0;
// the legs are sized at most at what keeps the gross within 128 bits, as the pool sizes them, and the pull of
// tokens 0 and 1 within their custody's 128 bits ({_pullRoom})
uint256 room = _pullRoom(c, b, den < type(uint128).max ? type(uint128).max - den : 0, den);
uint256 got = _fitVenues(c, b, room, den, true);
return got == room ? type(uint256).max : got;
}
/// @notice The largest `mintProRata` for `receiver` now, in shares, at the supply the mint is sliced at (after its
/// fee skim): zero where the entry refuses, also at the cap and on a pool book that holds nothing; else
/// bounded by `mintProRataCap`, custody's 128 bits and the venue legs, as the deposit's are.
function maxMintProRata(address pool, address receiver) public view returns (uint256) {
Ctx memory c = _ctx(pool);
if (c.locked || !_entryOpen(c, receiver)) return 0;
(FLAMMGateLib.Book memory b, address[] memory tok) = _priced(c);
// the supply after the skim, bounded both ways where rebuilt: each bound read on the side it under-reports
(uint256 lo, uint256 hi) = _pendingFeeShares(c, b);
uint256 cap = c.lim.mintProRataCap;
if (cap <= c.supply + hi) return 0;
if (!_priceable(c, b, tok) || _feePastCustody(c)) return 0;
if (!FLAMMFlowLib.holds(b)) return 0;
uint256 room = cap - c.supply - hi;
uint256 supply = c.supply + lo;
return _fitVenues(c, b, _pullRoom(c, b, room, supply), supply, false);
}
/// @dev `room`, in `base`'s units of the entry, cut to what keeps tokens 0 and 1 within their custody's 128 bits:
/// an entry pulls the whole of each token's slice (custody, supply and collateral legs alike, `held + supplied
/// + posted` of it per `base`, rounded up) into tracked custody, the fee kept in it included, before its legs
/// leave. Every later token's custody is a full word.
function _pullRoom(Ctx memory c, FLAMMGateLib.Book memory b, uint256 room, uint256 base)
private
view
returns (uint256)
{
for (uint256 t; t < 2; ++t) {
FLAMMGateLib.Leg memory L = b.legs[t];
uint256 g = L.held + L.supplied + L.posted;
if (g == 0) continue;
uint256 kept = c.p.tokenConfig(uint8(t)).held;
uint256 r = kept + 1 < type(uint128).max ? Math.mulDiv(type(uint128).max - kept - 1, base, g) : 0;
if (r < room) room = r;
}
return room;
}
/// @notice The largest `redeemProRata` of `owner`'s shares now: `FLAMMExitMaxima.maxRedeemProRata`, which this
/// runs (a library apart, linked here, so the entry maxima and the exit maximum each fit a contract).
function maxRedeemProRata(address pool, address owner) public view returns (uint256) {
return FLAMMExitMaxima.maxRedeemProRata(pool, owner);
}
/// @dev Token `t`'s supply batch in `c.batch`, read once: one past the batch, so zero reads as unread.
function _batch(Ctx memory c, uint256 t) internal view returns (uint256) {
uint256 k = c.batch[t];
if (k == 0) {
k = c.p.tokenConfig(uint8(t)).minSupplyBatch + 1;
c.batch[t] = k;
}
return k;
}
// ------------------------------------------------------------------ the pool's facts
/// @dev The pool's facts ({Ctx}), read once per maximum.
function _ctx(address pool) internal view returns (Ctx memory c) {
(c.p, c.r) = (IFLAMM(pool), IMMRouter(IFLAMM(pool).router()));
c.supply = c.p.totalSupply();
// `totalAssets` takes the read guard first and refuses a frozen venue mark before it prices:
// one call tells both
try c.p.totalAssets() returns (uint256 a) {
(c.navOk, c.nav) = (true, a);
} catch (bytes memory e) {
bytes4 s = bytes4(e);
(c.locked, c.frozen) = (s == ReentrancyGuardLib.Reentrant.selector, s == VenueFrozen.selector);
}
c.lim = c.p.limits();
c.bandOff = c.p.tokenConfig(1).swapPriceBandWad == 0;
(, uint256 cfg,) = IFLAMMBasketViews(pool).lane();
c.lane = (cfg >> FLAMMStore.LANE_VERSION_SHIFT) & 0x7f != 0;
(c.m, c.n, c.retired) = (c.p.tokenCount(), c.r.venueCount(pool), c.p.retiredVenues());
(c.v, c.batch) = (new IMMRouter.VenueView[](c.n), new uint256[](c.m));
for (uint16 i; i < c.n; ++i) {
if ((c.retired >> i) & 1 != 0) continue;
IMMRouter.VenueView memory w = c.r.venue(pool, i);
c.v[i] = w;
uint256 caps = IFinancingAccount(w.account).capabilities();
if (caps & CAP_ACTION_GATES != 0) c.gated |= uint256(1) << i;
if (caps & CAP_SHARED_LIQUIDITY != 0) c.shared |= uint256(1) << i;
if (caps & CAP_REDEMPTION_FEE != 0) c.fee |= uint256(1) << i;
if (caps & CAP_REPORTED_LOSS != 0) c.lossy |= uint256(1) << i;
if (caps & CAP_HELD_REPAY != 0) c.held |= uint256(1) << i;
if (caps & CAP_ACCRUING_COLLATERAL != 0) c.accruing |= uint256(1) << i;
}
}
/// @dev The entry's gates: the pause, a bootstrapped supply, `FEATURE_DEPOSITS`, a cheap-lane pool's deposit basket
/// where the curator's fee cap is nonzero, the allowlist on the receiver, no frozen venue mark and no fence
/// holding a pool part, written off or not (`IFLAMMFence.partedFences`; a pool that serves no fence reads
/// none).
function _entryOpen(Ctx memory c, address receiver) private view returns (bool) {
try IFLAMMFence(address(c.p)).partedFences() returns (uint256 parts) {
if (parts != 0) return false;
} catch {}
(uint256 features,) = c.p.switches();
if (c.p.paused() || c.supply == 0 || features & FLAMMStore.FEATURE_DEPOSITS == 0) return false;
if (c.lane && c.lim.maxPerformanceFeeBp != 0 && IFLAMMBasketViews(address(c.p)).basketTokens()[0] == 0) {
return false;
}
address list = c.p.depositAllowlist();
if (list != address(0) && !IDepositAllowlist(list).isDepositAllowed(receiver)) return false;
return !c.frozen;
}
/// @dev The pool book as the pool reads it (`FLAMMGateLib.bookOf`): every token's legs from its `position` (custody
/// net of the spread fee custody keeps, and the Router's book past the venues it passes over); the part of the
/// fee owed past custody ({FLAMMGateLib.feeOf}); each scale; and each owed token's partner as the per-pair
/// read finds it (`FLAMMLawLib.splitRead`): `MANY` where two or more of its live pairs owe it, else the
/// collateral of the one that does. `tok`: each token's address.
function _book(Ctx memory c) internal view returns (FLAMMGateLib.Book memory b, address[] memory tok) {
uint256 m = c.m;
(b.legs, b.usd, tok) = (new FLAMMGateLib.Leg[](m), new uint256[](m), new address[](m));
for (uint256 t; t < m; ++t) {
IFLAMM.TokenConfig memory k = c.p.tokenConfig(uint8(t));
FLAMMGateLib.Leg memory L = b.legs[t];
(L.held, L.supplied, L.posted, L.owed) = c.p.position(uint8(t));
(L.scale, L.partner, tok[t]) = (10 ** (18 - k.decimals), k.partner, k.token);
uint256 f = IFLAMMBasketViews(address(c.p)).spreadFeeOwed(uint8(t));
if (f > k.held) L.fee = f - k.held;
}
_split(c, b);
}
/// @dev {_book} priced as the pool prices it (`FLAMMGateLib.priceIn`): none with no band; the pool asset and
/// token 1 from one read of their pair, every later token from its own, the pool asset alone first where the
/// pair does not answer and a later token is read; then each token's `price36`, the pool asset's price scale
/// against it (`FLAMMGateLib.frameAll`).
function _priced(Ctx memory c) private view returns (FLAMMGateLib.Book memory b, address[] memory tok) {
(b, tok) = _book(c);
if (c.bandOff) return (b, tok);
IPriceFeed feed = IPriceFeed(c.p.priceFeed());
(bool ok, uint256 u0, uint256 u1,) = feed.peekPair(tok[0], tok[1]);
if (ok) (b.usd[0], b.usd[1]) = (u0, u1);
if (c.m > 2 && !ok) {
(bool ok0, uint256 v0,) = feed.peekUsd(tok[0]);
if (ok0) b.usd[0] = v0;
}
for (uint256 t = 2; t < c.m; ++t) {
(bool okT, uint256 v,) = feed.peekUsd(tok[t]);
if (okT) b.usd[t] = v;
}
FLAMMGateLib.frameAll(b);
}
/// @dev Each owed token's partner where two or more live pairs owe it: each such pair's debt read apart (the
/// Router's book of its venues alone), `MANY` where two or more owe, else the collateral of the one that does;
/// where two or more owe, their collateral tokens in `b.backs`, as the pool's per-pair read records them
/// (`FLAMMLawLib.splitRead`), so `FLAMMGateLib.backsDebt` reads this pool book as the pool reads its own.
function _split(Ctx memory c, FLAMMGateLib.Book memory b) private view {
uint256 np = c.p.pairCount();
IFLAMM.PairConfig[] memory pc = new IFLAMM.PairConfig[](np);
uint256[] memory live = new uint256[](b.legs.length);
for (uint256 r; r < np; ++r) {
pc[r] = c.p.pairConfig(uint8(r));
if (pc[r].live) ++live[pc[r].debt];
}
for (uint256 t; t < b.legs.length; ++t) {
if (b.legs[t].owed == 0 || live[t] < 2) continue;
(uint256 owing, uint8 coll, uint256 backs) = (0, 0, 0);
for (uint256 r; r < np; ++r) {
if (!pc[r].live || pc[r].debt != t) continue;
uint256 keep;
for (uint16 i; i < c.n; ++i) {
if ((c.retired >> i) & 1 == 0 && c.v[i].pair == r) keep |= uint256(1) << i;
}
if (keep == 0) continue;
(,, uint256[] memory o,) = c.r.book(address(c.p), ~uint64(keep));
if (o[t] != 0) (owing, coll, backs) = (owing + 1, pc[r].coll, backs | uint256(1) << pc[r].coll);
}
b.legs[t].partner = owing >= 2 ? FLAMMStore.MANY : coll;
if (owing >= 2) b.backs |= backs;
}
}
/// @dev Whether a spread fee is owed past custody in any token, which an entry refuses.
function _feePastCustody(Ctx memory c) private view returns (bool) {
for (uint256 t; t < c.m; ++t) {
if (IFLAMMBasketViews(address(c.p)).spreadFeeOwed(uint8(t)) > c.p.tokenConfig(uint8(t)).held) return true;
}
return false;
}
/// @dev As an entry runs: a pool book whose fee mark cannot read enters only with no fee rate on (`totalAssets`
/// refuses exactly then, while a rate is on: `FLAMMGateLib.markedAt`, the cheap-lane basket's and the forfeit
/// record's prices included), and only while no token with debt is unpriced at a pair that owes it; and every
/// borrow leg needs both tokens of its pair on peg.
function _priceable(Ctx memory c, FLAMMGateLib.Book memory b, address[] memory tok) private view returns (bool) {
bool feeOn = (c.lim.performanceFeeBp | c.lim.protocolFeeBp) != 0 && !c.bandOff;
if (feeOn && !c.navOk) return false;
IPriceFeed feed = IPriceFeed(c.p.priceFeed());
uint256 np;
for (uint256 t; t < b.legs.length; ++t) {
FLAMMGateLib.Leg memory L = b.legs[t];
if (L.owed == 0) continue;
if (L.partner == FLAMMStore.NO_PARTNER || !feed.pegOk(tok[t])) return false;
if (L.partner != FLAMMStore.MANY) {
if (FLAMMGateLib.frameOf(b, L.partner, t) == 0 || !feed.pegOk(tok[L.partner])) return false;
continue;
}
if (np == 0) np = c.p.pairCount();
for (uint256 r; r < np; ++r) {
IFLAMM.PairConfig memory q = c.p.pairConfig(uint8(r));
if (!q.live || q.debt != t) continue;
if (FLAMMGateLib.frameOf(b, q.coll, t) == 0 || !feed.pegOk(tok[q.coll])) return false;
}
}
return true;
}
/// @dev The shares the skim before a flow mints at the supply, both parts (`FLAMMMaintainLib.pendingFeeShares`), as
/// a lower and an upper bound. None while a fence holds a pool part, written off or not
/// (`IFLAMMFence.partedFences`), as the pool's skim mints none then. Exact, the two equal, from the deposit
/// preview at the pool asset's whole legs, which sizes its shares at the supply after the skim; where it does
/// not answer (a pool book that owes the pool asset reads no deposit, or the preview refuses an entry of that
/// size), rebuilt from `limits()`, whose fee mark is the pool's divided by the share scale: the bounds are the
/// fee at that rounding's two ends, and the forfeit record is not read.
function _pendingFeeShares(Ctx memory c, FLAMMGateLib.Book memory b) internal view returns (uint256 lo, uint256 hi) {
(uint256 bp, uint256 pbp) = (c.lim.performanceFeeBp, c.lim.protocolFeeBp);
if ((bp == 0 && pbp == 0) || c.bandOff) return (0, 0);
// the skim mints nothing while a fence holds a pool part (`FLAMMMaintainLib.pendingFeeShares`)
try IFLAMMFence(address(c.p)).partedFences() returns (uint256 parts) {
if (parts != 0) return (0, 0);
} catch {}
FLAMMGateLib.Leg memory L0 = b.legs[0];
uint256 gross0 = L0.held + L0.supplied + L0.posted;
if (gross0 != 0 && L0.owed == 0) {
try c.p.previewDepositProRata(gross0) returns (
uint256 shares, IFLAMM.VenueLeg[] memory, uint256[] memory, uint256[] memory
) {
if (shares >= c.supply) return (shares - c.supply, shares - c.supply);
} catch {}
}
if (!c.navOk) return (0, 0);
uint256 scale = L0.scale;
uint256 assets = c.nav * scale;
if (c.lane) {
uint256[] memory e = IFLAMMBasketViews(address(c.p)).basketTokens();
if (e[0] != 0) {
(FLAMMGateLib.Book memory q,) = _priced(c);
uint256 basket = e[0];
for (uint256 t = 1; t < q.legs.length; ++t) {
if (e[t] == 0 && t != 1) continue;
uint256 p = q.legs[t].price36;
if (p == 0) return (0, 0);
basket += Math.mulDiv(e[t], 1e36, p, Math.Rounding.Up);
}
assets = Math.mulDiv(c.nav, WAD * scale, basket);
}
}
uint256 cur = Math.mulDiv(assets, WAD, c.supply);
if (cur > type(uint128).max) return (0, 0);
if (bp != 0) {
try IEverlongCore(c.p.core()).feeReceiver() returns (address to) {
if (to == address(0)) bp = 0;
} catch {
bp = 0;
}
}
if (pbp != 0) {
try IFLAMMProtocolFee(c.p.factory()).protocolFeeReceiver() returns (address to) {
if (to == address(0)) pbp = 0;
} catch {
pbp = 0;
}
}
// the pool's fee mark lies in [q * scale, (q + 1) * scale - 1]
uint256 floorPeak = uint256(c.lim.peakSharePriceWad) * scale;
lo = _fee(c.supply, cur, floorPeak + scale - 1, bp, pbp);
hi = _fee(c.supply, cur, floorPeak, bp, pbp);
}
/// @dev Both parts of the fee at the fee mark `peak` (`FLAMMFlowLib.split`), none at or under it.
function _fee(uint256 supply, uint256 cur, uint256 peak, uint256 bp, uint256 pbp) private pure returns (uint256) {
if (cur <= peak) return 0;
(uint256 f, uint256 g) = FLAMMFlowLib.split(supply, cur, peak, bp, pbp);
return f + g;
}
// ------------------------------------------------------------------ the venue legs
/// @dev The largest size up to `size` (of `den`: the deposit's pool-asset base, or the mint's supply) whose venue
/// legs every venue takes now (`FLAMMQuoteLib`'s fit, restated):
/// - Each supply leg lies within its supply room, or under its token's batch, where it stays in custody
/// ({_under}), and one token's together within its supply cap.
/// - The legs of venues sharing one reserve's room, what they lend and post of one token in proportion to what
/// they hold, lie together within the least room any of their accounts reports for the reserve (not a
/// venue's own cap at the Router, which bounds its own leg), and their borrow legs of one token within the
/// least any of them can lend.
/// - Then over two passes each collateral leg lies within its post room, each borrow leg within the Router's
/// `borrowRoom`, the shared legs within their least room, one pair's borrow legs together within its debt
/// cap and one token's supply legs past custody within its supply cap; trimmed once.
/// - The legs are the entry's own (its preview at the size, a leg under its batch in custody).
/// - Where the preview refuses a restoring leg the fit cut past rounding dust (`IMMRouter.Unhealthy`), the
/// first size is halved up to `RESTORE_HALVINGS` times, as a smaller entry needs less, and reads 0 where
/// every one is refused.
/// - One whose borrow or supply leg leaves a venue under its minimum position
/// (`IMMRouter.InsufficientLiquidity`) reads 0.
function _fitVenues(Ctx memory c, FLAMMGateLib.Book memory b, uint256 size, uint256 den, bool deposit)
private
view
returns (uint256)
{
address pool = address(c.p);
uint256[] memory debts = new uint256[](c.n);
// venues sharing one reserve's room: their legs per token, the supply they lend and the collateral they post,
// and the least room any reports; past the tokens, apart, what they owe of each and the least any can lend
uint256 m = c.shared == 0 ? 0 : c.m;
(uint256[] memory pooled, uint256[] memory least) = (new uint256[](2 * m), new uint256[](2 * m));
// per token, the most size at which every supply leg of it stays in custody
uint256[] memory under = _maxed(c.m);
for (uint16 i; i < c.n; ++i) {
if ((c.retired >> i) & 1 != 0) continue;
(, uint256 coll,, uint256 sup, uint256 debt) = c.r.venuePosition(pool, i);
debts[i] = debt;
IMMRouter.VenueView memory v = c.v[i];
if (sup != 0) {
uint256 u = _under(c, v, i, sup, den);
if (u < under[v.debt]) under[v.debt] = u;
size = _roomFit(c, i, sup, den, size, u);
}
if ((c.shared >> i) & 1 == 0 || (sup | coll | debt) == 0) continue;
IFinancingAccount.Capacity memory k = c.r.venueCapacity(pool, i);
if (sup != 0) _pool(v.debt, sup, k.suppliable, pooled, least);
if (coll != 0) _pool(v.coll, coll, k.collateralPostable, pooled, least);
if (debt != 0) _pool(m + v.debt, debt, _lendable(v), pooled, least);
}
for (uint256 t; t < pooled.length; ++t) {
uint256 u = pooled[t];
if (u == 0 || least[t] == type(uint256).max) continue;
uint256 k = t < m ? c.n : c.n * FLAMMGateLib.READ_BACK_UNITS;
if (k > least[t]) k = least[t];
size = Math.min(size, Math.mulDiv(least[t] - k, den, u));
}
size = _tokenCapFit(c, b, den, size, under);
for (uint256 pass; pass < 2; ++pass) {
if (size == 0) return 0;
(uint256 refused, IFLAMM.VenueLeg[] memory legs) = _legs(c, size, deposit);
// a restoring leg custody cannot fill grows with the entry, so a smaller one may pass: the first size,
// halved up to `RESTORE_HALVINGS` times until its preview takes it
for (uint256 k; refused == REFUSED_UNHEALTHY && pass == 0 && k < RESTORE_HALVINGS && size > 1; ++k) {
size /= 2;
(refused, legs) = _legs(c, size, deposit);
}
if (refused != 0) return 0;
uint256 next = size;
for (uint16 i; i < legs.length; ++i) {
IFLAMM.VenueLeg memory v = legs[i];
uint256 p = v.collateral == 0 ? 0 : c.r.venueCapacity(pool, i).collateralPostable;
if (v.collateral > p) {
if (pass == 1) return 0;
next = Math.min(next, Math.mulDiv(size, p, v.collateral));
}
if (v.owed == 0) continue;
if ((c.accruing >> i) & 1 != 0) {
next = Math.min(
next, _unitBound(c, i, debts[i], den, FLAMMGateLib.frameOf(b, c.v[i].coll, c.v[i].debt))
);
}
uint256 room = c.r.borrowRoom(pool, i, v.collateral, b.usd);
if (v.owed <= room) continue;
if (pass == 1) return 0;
next = Math.min(next, Math.mulDiv(room, den, debts[i]));
}
if (c.shared != 0) next = _sharedFit(c, legs, pooled, least, size, next, pass);
next = _pairCapFit(c, legs, debts, den, next, pass);
next = _tokenCapPass(c, b, legs, size, next, pass);
if (next == 0) return 0;
if (next == size) return size;
size = next;
}
return size;
}
/// @dev The most size (of `den`) every smaller entry also takes at venue `i`, whose collateral accrues and which
/// owes `debt`. Zero where `frame` cannot be read.
/// - The lender credits a post in its own units, rounded down (a post under one unit's assets, none: the Venus
/// kind holds it for a later post), and checks its own threshold on what it credits, at its own price, which
/// the Router lets sit under the pool's price by up to the pair's venue-oracle band.
/// - So the threshold is read at the lower of the two (`frame`, the pair's at the pool's prices, and the
/// venue's `oraclePrice`), as the maintainer reads it (`FLAMMMaintainLib`).
/// - An entry's legs are pro rata, so it keeps the venue's ratio, and its post loses at most one unit's assets
/// and one to the lender's rounding.
/// - Where that threshold's margin over the pin covers that unit, or the venue's own margin there, its
/// collateral at that threshold over its debt, covers the unit's worth (the margin that counts where the
/// lender's price takes the threshold to the pin or under it, at a venue under its pin), a borrow the pin
/// allows passes the lender at any size (none: `type(uint256).max`).
/// - Where it holds fewer, an entry whose post credits nothing still borrows its slice, which the lender
/// refuses past what the units the venue holds carry, while a larger entry, whose post credits a unit,
/// passes: such an entry is held to the size whose slice the lender takes with nothing credited, that same
/// margin. More credit only helps, and the Router allows a post's rounding on its own side
/// (`MMRouterLib.requireSliceFits`).
/// - The collateral is read at the rate the next accrual sets, which a lender checking its stored rate reads a
/// little lower, so a venue within that drift of its threshold can refuse an entry the maximum advertises.
function _unitBound(Ctx memory c, uint16 i, uint256 debt, uint256 den, uint256 frame)
private
view
returns (uint256)
{
IMMRouter.VenueView memory v = c.v[i];
address pool = address(c.p);
uint256 one = IFinancingAccount(v.account).collateralUnitsToAssets(v.id, 1) + 1;
uint256 pin = c.r.pair(pool, v.pair).pinLtvWad;
if (frame == 0) return 0;
(bool ok, uint256 q) = IFinancingAccount(v.account).oraclePrice(v.id);
uint256 l = v.lltvWad;
if (ok && q != 0 && q < frame) l = Math.mulDiv(l, q, frame);
(, uint256 coll,,,) = c.r.venuePosition(pool, i);
if (l > pin && (l - pin) * coll >= l * one) return type(uint256).max;
// what the lender takes with nothing credited, at that threshold, and what a post's rounding loses there
uint256 cap = Math.mulDiv(Math.mulDiv(coll, frame, 1e36), l, WAD);
uint256 loss = Math.mulDiv(Math.mulDiv(one, frame, 1e36, Math.Rounding.Up), l, WAD, Math.Rounding.Up);
// a margin past that loss, a borrow leg's rounding beside it, takes every pro-rata entry
if (cap > debt + loss) return type(uint256).max;
return cap > debt ? Math.mulDiv(cap - debt, den, debt) : 0;
}
/// @dev The most size (of `den`) at which venue `i`'s entry supply leg of `sup` stays in custody: under its token's
/// batch, rounded up as the entry's is, where the venue allows the leg's action or cannot refuse one
/// (`FLAMMFlowLib.proRata`); zero where none does.
function _under(Ctx memory c, IMMRouter.VenueView memory v, uint16 i, uint256 sup, uint256 den)
private
view
returns (uint256)
{
uint256 k = _batch(c, v.debt);
if (k < 3) return 0;
if ((c.gated >> i) & 1 != 0 && c.r.venueCapacity(address(c.p), i).actions & CAN_SUPPLY == 0) return 0;
return Math.mulDiv(k - 2, den, sup);
}
/// @dev {_fitVenues}' bound from venue `i`'s supply room on its leg of `sup`: within the room, or up to `u`, where
/// the leg stays in custody. At a reserve it shares, a share's assets and a unit are held back per venue: the
/// entry's earlier legs there run first, and each supply's shares, rounded down, leave the rest of a share's
/// assets to every holder, which raises what this venue recognizes against its cap by up to that much.
function _roomFit(Ctx memory c, uint16 i, uint256 sup, uint256 den, uint256 size, uint256 u)
private
view
returns (uint256)
{
uint256 room = c.r.supplyRoom(address(c.p), i);
if (room == type(uint256).max) return size;
if ((c.shared >> i) & 1 != 0) {
IMMRouter.VenueView memory v = c.v[i];
uint256 k = c.n * (IFinancingAccount(v.account).supplySharesToAssets(v.id, 1) + 1);
room = room > k ? room - k : 0;
}
return Math.min(size, Math.max(Math.mulDiv(room, den, sup), u));
}
/// @dev `n` words, each `type(uint256).max`.
function _maxed(uint256 n) private pure returns (uint256[] memory a) {
a = new uint256[](n);
for (uint256 t; t < n; ++t) {
a[t] = type(uint256).max;
}
}
/// @dev {_fitVenues}' bound on the legs at `size` past custody against each token's supply cap at the Router:
/// their supply legs together within the cap less what its venues lend, a unit over its share each of the
/// venues, as {_tokenCapFit} reads it from the pool book.
function _tokenCapPass(
Ctx memory c,
FLAMMGateLib.Book memory b,
IFLAMM.VenueLeg[] memory legs,
uint256 size,
uint256 next,
uint256 pass
) private view returns (uint256) {
uint256[] memory sum = new uint256[](c.m);
for (uint256 i; i < legs.length; ++i) {
if (legs[i].supplied != 0) sum[c.v[i].debt] += legs[i].supplied;
}
for (uint256 t; t < c.m; ++t) {
if (sum[t] == 0) continue;
uint256 cap = c.r.token(address(c.p), uint8(t)).supplyCap;
if (cap == 0) continue;
uint256 k = b.legs[t].supplied + c.n;
if (sum[t] + k <= cap) continue;
if (pass == 1) return 0;
next = Math.min(next, cap > k ? Math.mulDiv(size, cap - k, sum[t]) : 0);
}
return next;
}
/// @dev {_fitVenues}' bound on the legs at `size` at the shared venues: each token's collateral and supply legs
/// there together within the least room any of them holding a leg of it reports.
function _sharedFit(
Ctx memory c,
IFLAMM.VenueLeg[] memory legs,
uint256[] memory pooled,
uint256[] memory least,
uint256 size,
uint256 next,
uint256 pass
) private pure returns (uint256) {
uint256[] memory sum = new uint256[](least.length);
for (uint256 i; i < legs.length; ++i) {
if ((c.shared >> i) & 1 == 0) continue;
IFLAMM.VenueLeg memory v = legs[i];
sum[c.v[i].coll] += v.collateral;
sum[c.v[i].debt] += v.supplied;
}
for (uint256 t; t < sum.length; ++t) {
if (pooled[t] == 0 || sum[t] <= least[t]) continue;
if (pass == 1) return 0;
next = Math.min(next, Math.mulDiv(size, least[t], sum[t]));
}
return next;
}
/// @dev {_fitVenues}' bound on the borrow legs at the venues of one pair, where two or more draw: together within
/// the pair's debt cap less what its venues owe and less `FLAMMGateLib.READ_BACK_UNITS` per leg after the
/// first.
function _pairCapFit(
Ctx memory c,
IFLAMM.VenueLeg[] memory legs,
uint256[] memory debts,
uint256 den,
uint256 next,
uint256 pass
) private view returns (uint256) {
uint256 m = c.p.pairCount();
(uint256[] memory owed, uint256[] memory used, uint256[] memory count) =
(new uint256[](m), new uint256[](m), new uint256[](m));
for (uint256 i; i < legs.length; ++i) {
IFLAMM.VenueLeg memory v = legs[i];
used[v.pair] += debts[i];
if (v.owed == 0) continue;
owed[v.pair] += v.owed;
++count[v.pair];
}
for (uint256 p; p < m; ++p) {
if (count[p] < 2) continue;
uint256 cap = c.r.pair(address(c.p), uint8(p)).debtCap;
uint256 k = used[p] + (count[p] - 1) * FLAMMGateLib.READ_BACK_UNITS;
if (cap == 0 || owed[p] + k <= cap) continue;
if (pass == 1) return 0;
next = Math.min(next, cap > k ? Math.mulDiv(cap - k, den, used[p]) : 0);
}
return next;
}
/// @dev {_fitVenues}' bound on the size from each token's supply cap at the Router: its supply legs together within
/// the cap less what its venues lend, a unit over its share each of the venues; up to the size at which every
/// supply leg of the token stays in custody (`under`), which no cap bounds ({_tokenCapPass} reads the legs).
function _tokenCapFit(
Ctx memory c,
FLAMMGateLib.Book memory b,
uint256 den,
uint256 size,
uint256[] memory under
) private view returns (uint256) {
for (uint256 t; t < b.legs.length; ++t) {
uint256 used = b.legs[t].supplied;
if (used == 0) continue;
uint256 cap = c.r.token(address(c.p), uint8(t)).supplyCap;
if (cap == 0) continue;
uint256 k = used + c.n;
size = Math.min(size, Math.max(cap > k ? Math.mulDiv(cap - k, den, used) : 0, under[t]));
}
return size;
}
/// @dev What venue `v` can lend now, within its borrow-rate ceiling (`IFinancingAccount.ceilingBorrowSlice`).
function _lendable(IMMRouter.VenueView memory v) private view returns (uint256 lend) {
lend = IFinancingAccount(v.account).borrowable(v.id);
if (v.maxBorrowRateWad != 0) {
lend = IFinancingAccount(v.account).ceilingBorrowSlice(v.id, 0, 0, lend, v.maxBorrowRateWad);
}
}
/// @dev The entry's venue legs at `size`, from its preview; `refused` nonzero where the preview refuses a restoring
/// leg (`IMMRouter.Unhealthy`: `REFUSED_UNHEALTHY`, which a smaller entry may pass) or a borrow or supply leg
/// that leaves a venue under its minimum position (`IMMRouter.InsufficientLiquidity`: `REFUSED_MINIMUM`, which
/// only `FLAMMSharedLib.heldLegsCheck` raises on a preview, and which no smaller entry passes, the leg
/// shrinking with it). Any other refusal bubbles.
function _legs(Ctx memory c, uint256 size, bool deposit)
private
view
returns (uint256 refused, IFLAMM.VenueLeg[] memory legs)
{
bytes memory e;
if (deposit) {
try c.p.previewDepositProRata(size) returns (
uint256, IFLAMM.VenueLeg[] memory l, uint256[] memory, uint256[] memory
) {
return (0, l);
} catch (bytes memory x) {
e = x;
}
} else {
try c.p.previewMintProRata(size) returns (IFLAMM.VenueLeg[] memory l, uint256[] memory, uint256[] memory) {
return (0, l);
} catch (bytes memory x) {
e = x;
}
}
bytes4 s = bytes4(e);
if (s == IMMRouter.Unhealthy.selector) return (REFUSED_UNHEALTHY, legs);
if (s == IMMRouter.InsufficientLiquidity.selector) return (REFUSED_MINIMUM, legs);
assembly ("memory-safe") {
revert(add(e, 0x20), mload(e))
}
}
/// @dev Adds a venue's `units` of token `t` to that token's sum, and its `free` to the least.
function _pool(uint256 t, uint256 units, uint256 free, uint256[] memory sums, uint256[] memory least)
private
pure
{
if (sums[t] == 0 || free < least[t]) least[t] = free;
sums[t] += units;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {
"src/core/mm/MMRouterLib.sol": {
"MMRouterLib": "0xA4749766934833DfBeaF4Fc0d79c150A1Dd2B4E5"
},
"src/core/flamm/FLAMMLane.sol": {
"FLAMMLane": "0x0988077AB06F1efd8cFa3f08FC60CAf3e6d22e98"
},
"src/core/flamm/FLAMMRoute.sol": {
"FLAMMRoute": "0x312ee92ecd113F925dD513d450b062C8740fDaA9"
},
"src/periphery/FLAMMMaxima.sol": {
"FLAMMMaxima": "0x4A997343D91c981BF63274fc222AA96D32d6259c"
},
"src/core/flamm/FLAMMLawLib.sol": {
"FLAMMLawLib": "0x5D473B15E032756Cd81fc66B8F1e9BE2f427cc62"
},
"src/core/flamm/FLAMMOpsLib.sol": {
"FLAMMOpsLib": "0x0BFe60fB1f5223F1A2b7B02Ef18f5C33fb043753"
},
"src/core/mm/AaveV3ReadsLib.sol": {
"AaveV3ReadsLib": "0xD53F6170226A74D453e84414Ffc2FFcE5ded5983"
},
"src/core/flamm/FLAMMFlowLib.sol": {
"FLAMMFlowLib": "0x2577D707D41209489b2EF53101a4f6baDd4E3473"
},
"src/core/flamm/FLAMMGateLib.sol": {
"FLAMMGateLib": "0xF0BE115A2D6F27274F2e9EE50B89Ed42db2B9555"
},
"src/core/flamm/FLAMMKeptLib.sol": {
"FLAMMKeptLib": "0x7a11899232dd9F17c28bF062Ec2ee2267158517b"
},
"src/core/mm/CTokenMarketLib.sol": {
"CTokenMarketLib": "0x18c53F2aCAbcDEEdb575A136f49fa4C43EB2071c"
},
"src/core/flamm/FLAMMAdmitLib.sol": {
"FLAMMAdmitLib": "0xA6dBD8cD5Cd10F8a5857cbeD54a28405ffbDcBCb"
},
"src/core/flamm/FLAMMBlindLib.sol": {
"FLAMMBlindLib": "0x0b8d436F1a7AE25C5d16955ed4CDa781E42e7E5C"
},
"src/core/flamm/FLAMMClaimLib.sol": {
"FLAMMClaimLib": "0x02b4354a56630ab165A880B1198a603E62731cCE"
},
"src/core/flamm/FLAMMFenceLib.sol": {
"FLAMMFenceLib": "0xA16ddA83f47a42F875f141b6954595D584a201e8"
},
"src/core/flamm/FLAMMFloatLib.sol": {
"FLAMMFloatLib": "0x539EfC2b17cF0fdF254AAaB925b3A7c360A79737"
},
"src/core/flamm/FLAMMQuoteLib.sol": {
"FLAMMQuoteLib": "0xa4D34f4882a529574840881e755BCFae2bd5ce2e"
},
"src/core/flamm/FLAMMTopUpLib.sol": {
"FLAMMTopUpLib": "0x7C55a535Ce298b1e5e6d00F645088F777ad233DF"
},
"src/core/mm/CTokenRewardsLib.sol": {
"CTokenRewardsLib": "0xcda63d7eCCF838F2732Bff676706BDE5abA4DcF7"
},
"src/core/mm/MMRouterAdminLib.sol": {
"MMRouterAdminLib": "0x8423744b3F304ED0B43043d7ad4E7d8A247aDc96"
},
"src/core/flamm/FLAMMPolicyLib.sol": {
"FLAMMPolicyLib": "0xa6B495B2BdcDcf4F327844d9aaA0eD4C550c67F9"
},
"src/core/flamm/FLAMMSettleLib.sol": {
"FLAMMSettleLib": "0xB4890a27205505BDAA05717B6c3aB38b2dd3C7Cb"
},
"src/core/flamm/FLAMMSharedLib.sol": {
"FLAMMSharedLib": "0xFaAEd38962aEb6c282Ac36E0cdE9313AbA2511ba"
},
"src/periphery/FLAMMExitMaxima.sol": {
"FLAMMExitMaxima": "0x480f51866554e92649c9d3502bA31AA4234e0a81"
},
"src/hooks/everlong/LeverageLib.sol": {
"LeverageLib": "0x1B1D1C42d26c169dB59D8681d0FD4C9a2840Ad11"
},
"src/core/flamm/FLAMMMaintainLib.sol": {
"FLAMMMaintainLib": "0x94998f13fc5d5D2271c90b835c6a805dad409cC2"
},
"src/core/flamm/FLAMMPairQuoteLib.sol": {
"FLAMMPairQuoteLib": "0x077523D1427aE408105fe8592F907ECDa0D94cbE"
},
"src/hooks/everlong/EverlongOpsLib.sol": {
"EverlongOpsLib": "0xAbe4447C954E3C7a405f8E75116BF9f5787426F7"
}
},
"optimizer": {
"runs": 100,
"enabled": true
},
"viaSSACFG": false,
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts-compat/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable-compat/contracts/",
"solady/=lib/solady/src/",
"forge-std/=lib/forge-std/src/"
],
"experimental": false
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.