Verified contractExactUNLICENSED
PropAMMAdminRegistry
Address0xafb67cea346d8a0b7fa7589f647b07a6bb347205
- 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,443,243
- Creation transaction
- 0xdf70494b4d…a1ff51441c
- 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
27 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/propamm/PropAMMAdmin.solmain78.95 KB
- lib/openzeppelin-contracts-compat/contracts/token/ERC20/IERC20.sol2.77 KB
- lib/openzeppelin-contracts-compat/contracts/utils/Strings.sol2.25 KB
- lib/openzeppelin-contracts-compat/contracts/utils/cryptography/ECDSA.sol8.54 KB
- lib/openzeppelin-contracts-compat/contracts/utils/math/Math.sol12.51 KB
- lib/solady/src/utils/CREATE3.sol6.57 KB
- src/interfaces/core/IEverlongCore.sol889 B
- src/interfaces/core/flamm/IFLAMM.sol52.68 KB
- src/interfaces/core/flamm/IFLAMMHooks.sol8.36 KB
- src/interfaces/core/flamm/IFLAMMLane.sol16.57 KB
- src/interfaces/core/flamm/IPairHook.sol14.14 KB
- src/libraries/Constants.sol2.11 KB
- src/libraries/DelayLib.sol11.22 KB
- src/propamm/PropAMMAdminCold.sol45.15 KB
- src/propamm/PropAMMDeskCellCode.sol12.8 KB
- src/propamm/PropAMMShared.sol21.65 KB
- src/propamm/interfaces/IAssetModule.sol10.9 KB
- src/propamm/interfaces/IPriceSource.sol10.41 KB
- src/propamm/interfaces/IPropAMMFront.sol42.96 KB
- src/propamm/libraries/PropAMMAsset.sol5.95 KB
- src/propamm/libraries/PropAMMClock.sol5.26 KB
- src/propamm/libraries/PropAMMDue.sol8 KB
- src/propamm/libraries/PropAMMKeys.sol4.3 KB
- src/propamm/libraries/PropAMMLaneLib.sol2.31 KB
- src/propamm/libraries/PropAMMRegistryRule.sol3.57 KB
- src/propamm/libraries/PropAMMStore.sol16.13 KB
- src/propamm/libraries/PropAMMWords.sol38.16 KB
src/propamm/PropAMMAdmin.sol
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;
import {IFLAMM} from "src/interfaces/core/flamm/IFLAMM.sol";
import {IFLAMMLane} from "src/interfaces/core/flamm/IFLAMMLane.sol";
import {IEverlongCore} from "src/interfaces/core/IEverlongCore.sol";
import {IAssetSource} from "src/propamm/interfaces/IPriceSource.sol";
import {PropAMMStore} from "src/propamm/libraries/PropAMMStore.sol";
import {PropAMMWords as W} from "src/propamm/libraries/PropAMMWords.sol";
import {PropAMMKeys} from "src/propamm/libraries/PropAMMKeys.sol";
import {PropAMMLaneLib} from "src/propamm/libraries/PropAMMLaneLib.sol";
import {PropAMMDue} from "src/propamm/libraries/PropAMMDue.sol";
import {DelayLib} from "src/libraries/DelayLib.sol";
import {PropAMMAsset} from "src/propamm/libraries/PropAMMAsset.sol";
import {IPropAMMFrontTypes} from "src/propamm/interfaces/IPropAMMFront.sol";
import {
PropAMMAdminShared,
PropAMMAdminColdRegistry,
PropAMMAdminColdStorage,
PropAMMAdminColdBnb
} from "src/propamm/PropAMMAdminCold.sol";
/// @notice The hot part's rule for a listing's closed-phase settings, read through the proxy.
interface ISessionWord {
/// @notice `PropAMMFront.sessionWord`.
function sessionWord(uint24 listing, IPropAMMFrontTypes.SessionSettings calldata s)
external
view
returns (uint256 v, bool tighter);
}
/// @notice What `confirmPool` reads of `FLAMMFactory`.
interface IPoolFactoryView {
/// @notice Whether `FLAMMFactory` created `pool`.
function isPool(address pool) external view returns (bool);
}
/// @notice What `confirmPool` reads of a pool's core (`DelayedAuthority`).
interface IAuthorityView {
/// @notice The authority's delay, seconds.
function DELAY() external view returns (uint32);
/// @notice When a scheduled guardian may take office, zero for none or a lapsed one.
function guardianDueAt() external view returns (uint64);
/// @notice When a scheduled owner may take office, zero for none or a lapsed one.
function ownerDueAt() external view returns (uint64);
}
/// @notice The front's admin module, reached by DELEGATECALL from the hot implementation's fallback for every selector
/// the landing part does not serve, and sharing its ERC-7201 namespace: registration (pairs, price sources,
/// listing reservation and confirmation, retirement), each listing's settings and credit mode (one
/// scheduled change of each: loosenings wait the pool's own delay D), maker keys, the listing and global dark
/// states and who may set and clear them, each listing's binding to its price sources, the timelocked
/// setters, and raw storage reads for a lens. The module is two parts: this one, and its cold part
/// (`PropAMMAdminCold`, `COLD`), which this part's fallback hands every selector it does not serve, by
/// DELEGATECALL in the same context: the front-wide calls no listing's own call and no fill reaches (the
/// setup, the owner's setters, the opening of desks, the pairs, the price sources' registration and the
/// listing scan).
/// @dev D is a pool's `governanceDelaySec` (`PropAMMDue.poolDelay`).
///
/// Every pair is of one kind, holding any number of listings. One leaf per `LANE_KIND` (`PropAMMAdminRegistry`,
/// `PropAMMAdminStorage`, `PropAMMAdminBnb`) fixes the kind as a constant, so each build carries only its own
/// kind's branches, and creates its kind's cold leaf (`PropAMMAdminColdRegistry`, `PropAMMAdminColdStorage`,
/// `PropAMMAdminColdBnb`) in its constructor, so the admin leaf's address pins its cold leaf's code. A builder
/// build's landing part serves the desks and the ticket door; its cold leaf, the registry's 48 h path, the desks'
/// landing and the listings' leases (`refreshLease`, `cutLease`; `PropAMMAdminColdBuilder`).
///
/// Roles:
/// - Anyone adds a pair (`addPair`, its facts derived from its two tokens) and registers a price source
/// (`registerSource`, written once and never edited); neither moves a live listing.
/// - `owner()` is the front's timelock (10-day changes, logged by the timelock's own events). Besides the
/// upgrade and the guardian, it replaces the protocol's asset module and lists the quote assets, each read
/// only by pairs added later.
/// - The protocol owner (`instantOwner()`, `safe` in storage), which is the timelock's one proposer, and the
/// protocol guardian hold only what spans the front: a listing's retirement, under the front's published
/// delisting policy, the pause of every fill and its lift, the registry's path, the asset modules (a pair's
/// removal, and a listing's own: the protocol owner schedules it, it waits D, and only the pool's operator
/// applies it, `setAssetModule`; the protocol owner, the operator or the pool's guardian cancels it); no role
/// in any operator's pool.
/// - A listing's own stops are its operator's and its pool's guardian's, the guardian the operator names at launch
/// or none: either freezes and unfreezes it, darkens its live price source, cancels its scheduled changes and
/// lowers its credit mode.
/// - A pool's operator and guardian are read live from its core (`owner()`, `guardian()`).
///
/// No vendor's format or state sits in the front: a vendor arrives as a source anyone registers and a listing's
/// operator binds, never as an upgrade.
abstract contract PropAMMAdmin is PropAMMAdminShared {
using W for uint256;
/// @dev Build bound: the pull-price age ceiling at most 60 s.
uint256 internal constant AGE_CEIL_MAX_MS = 60_000;
/// @dev The most a listing's fence or ceiling may be, ppm: its 16-bit field of 0.1 bp units.
uint256 internal constant MAX_FENCE_PPM = 655_350;
/// @dev The most a listing's confidence multiplier may be, tenths (3x).
uint256 internal constant MAX_CONF_MUL = 30;
/// @dev Change kinds, one scheduled change each per listing: 0 the settings word, 11 the credit mode, 33 a further
/// listing of the pool (kept on its first listing). 1-10 and 12-32 are reserved.
uint256 internal constant KIND_SETTINGS = 0;
uint256 internal constant KIND_CREDIT = 11;
uint256 internal constant KIND_LISTING = 33;
/// @dev Change kind 34: a listing's price source and its backup. Kind 35, the taker tip cap, is the landing part's
/// (`setTipCap`); `cancel` takes it as any other.
uint256 internal constant KIND_SOURCE = 34;
/// @dev Change kind 36: a listing's own asset module (`setAssetModule`). Kind 37 is the stock module's listing
/// config, scheduled in the module's own storage (`StockModule.setConfig`), so no front build takes it.
uint256 internal constant KIND_ASSET = 36;
/// @dev Change kind 39: an operator's offer of a listing to a desk (`offerListing`), kept as a scheduled change is,
/// so `cancel` takes it as any other. Kind 38, a weakening of the operator's own binding, is the landing
/// part's (`bindListing`).
uint256 internal constant KIND_OFFER = 39;
/// @dev A SESSION listing's closed-phase settings (`setSession`).
uint256 internal constant KIND_SESSION = 40;
/// @dev P1's desk bits, as the landing part writes them: the desk (192-223) and its scopes (227-231).
uint256 internal constant P1_DESK_BITS = (uint256(W.M32) << 192) | (uint256(0x1f) << 227);
// ---------------------------------------------------------------- deployment
/// @notice The `FLAMMFactory`: a pool is confirmed only where it created the pool.
address public immutable FACTORY;
/// @notice The pull-price age ceiling, ms: the most a source's window and a listing's `maxAgeMs` may reach.
uint256 public immutable AGE_CEIL_MS;
/// @notice The runtime code hash of `DelayedAuthority`: a pool is confirmed only on a core of this code.
bytes32 public immutable AUTHORITY_CODEHASH;
/// @notice The admin module's cold part (`PropAMMAdminCold`), which this part's fallback hands every selector it
/// does not serve: created by this part's constructor from the same inputs, at this part's first CREATE
/// address, so this part's address pins its code.
address public immutable COLD;
/// @notice A build's fixed inputs.
struct Config {
/// @dev `FACTORY`.
address factory;
/// @dev `AGE_CEIL_MS`, at most `AGE_CEIL_MAX_MS`.
uint256 ageCeilMs;
/// @dev `AUTHORITY_CODEHASH`, never zero.
bytes32 authorityCodehash;
}
/// @notice Fixes the build's inputs, marks the module's own storage initialized (`BadConfig` where `ageCeilMs`
/// passes `AGE_CEIL_MAX_MS` or `authorityCodehash` is zero) and creates the cold part (`COLD`).
/// @param c The build's fixed inputs ({Config}).
constructor(Config memory c) {
if (c.ageCeilMs > AGE_CEIL_MAX_MS || c.authorityCodehash == bytes32(0)) revert BadConfig();
FACTORY = c.factory;
AGE_CEIL_MS = c.ageCeilMs;
AUTHORITY_CODEHASH = c.authorityCodehash;
// The module's own storage is never used: mark it initialized so it cannot be.
PropAMMStore.state().ids = 1 << 255;
COLD = _cold(c);
}
// ================================================================ a listing's price sources
/// @notice The listing's price source and its backup (0 none), its operator's: registered sources, distinct, no
/// backup on an asset-module pair, and on a PRINT listing a minimum fill of at least each one's floor
/// (`OutsideCeiling`). One change, which waits the pool's delay D and
/// applies on the identical call once due, within the execution window, unless the operator or the pool's
/// guardian cancels it (`cancel(listing, 34)`); on a quiet pool, in the block the pool went live, it
/// applies at once. A new binding goes live on its source with no lease (P2 bits 200-231 zero, until a
/// `refreshLease`). Two moves are at once on any pool: the backup the listing reads (`darkenSource`)
/// promoted to its source, with no backup after it, keeping its live copy and its lease; and the binding
/// the listing stands on, named again while it reads its backup or is dark, re-lit on its primary with no
/// lease, unless the pool's guardian made that darken or held it after (`P2_HELD`), which leaves it to D.
/// A stock listing's tags belong to the source that counts them, so a stock listing whose source changes
/// stays dark until its operator re-arms it.
function setSource(uint24 listing, uint32 id, uint32 backup) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
address pool = address(uint160(s0));
_onlyCurator(pool);
PropAMMStore.Layout storage $ = PropAMMStore.state();
uint256 pw = $.pairs[s0.sPairId()].cfg;
uint256 l = r.price;
uint256 w10 = r.sourceIds;
uint256 v = uint256(id) | (uint256(backup) << 32);
// the listing's backup made its source while the fills read it already (a listing on its backup has one)
bool promote = backup == 0 && id == (w10 >> 32) & W.M32 && l & W.P2_ON_BACKUP != 0;
// the binding the listing was darkened from, as it stands, re-lit after its operator's darken
bool restore = v == w10 && l & (W.P2_ON_BACKUP | W.P2_DARK) != 0 && l & W.P2_HELD == 0;
_bindable($, pw, id, backup);
uint256 s1 = r.p1;
// a tied listing binds guarded sources alone (a storage build's rule: a builder build binds none)
if (_laneKind() == LANE_STORAGE) {
if (s1.tied() && !_guarded($, v)) revert BadConfig();
}
// at the schedule and again at the apply: a PRINT listing's minimum fill at least each source's floor
if (s1.desk() != 0 && W.printed(s1.fenceKind()) && s1.minFill() < _srcFloor($, pw, v)) {
revert OutsideCeiling();
}
if (_due(listing, KIND_SOURCE, v, promote || restore, pool)) {
r.sourceIds = v;
r.price = promote ? l & ~(W.P2_ON_BACKUP | W.P2_HELD) : _live($, id);
emit SettingsSet(listing, uint8(KIND_SOURCE), v);
}
}
/// @notice Darkens the listing's primary price source at once, stop-only (its operator or its pool's guardian),
/// and fails the listing over to its backup, or to no source at all where it has none (`SourceDark` on
/// every fill that needs a print). Its lease ends either way. Only the operator undoes it
/// (`setSource`): the backup promoted at once; the same binding re-lit at once after its own darken, but
/// after D after the pool's guardian's, which holds it (`P2_HELD`); or another binding after D. A binding
/// scheduled before the darken still applies on its identical call once due: to hold the full D, cancel it
/// (`cancel(listing, 34)`) with the darken. An at-once move drops it.
/// - On a listing already on its backup or dark and not held, the pool's guardian's darken adds the hold
/// alone (`SourceDarkened` again, naming the backup it reads, else 0): the source, the backup and the
/// lease stay, and the operator re-lights the binding only after D, so its own darken never pre-empts
/// the guardian's. Its promote of the backup still applies at once and clears the hold.
/// - The operator's darken of such a listing, and anyone's of a held one, refuses (`BadConfig`): `freeze`
/// is the at-once stop there.
/// @dev The branch for a backup whose floor stands above a PRINT listing's minimum fill (dark, no backup) is
/// defensive only: every write of a PRINT binding, its minimum fill or its sources holds the minimum fill at
/// or above both sources' floors, so no path reaches it.
function darkenSource(uint24 listing) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
if (!_stopRole(address(uint160(s0)))) revert Unauthorized();
uint256 l = r.price;
if (l == 0) revert BadConfig();
uint256 b = (r.sourceIds >> 32) & W.M32;
bool op = msg.sender == _curator(address(uint160(s0)));
if (l & (W.P2_ON_BACKUP | W.P2_DARK) != 0) {
// on its backup or dark: the pool's guardian holds an unheld one, and nothing else moves
if (op || l & W.P2_HELD != 0) revert BadConfig();
r.price = l | W.P2_HELD;
emit SourceDarkened(listing, l & W.P2_ON_BACKUP != 0 ? uint32(b) : 0, msg.sender);
return;
}
uint256 nl = W.P2_DARK;
if (b != 0) {
uint256 s1 = r.p1;
PropAMMStore.Layout storage $ = PropAMMStore.state();
if (
s1.desk() == 0 || !W.printed(s1.fenceKind())
|| s1.minFill() >= _srcFloor($, $.pairs[s0.sPairId()].cfg, b)
) nl = _live($, b) | W.P2_ON_BACKUP;
else b = 0;
}
// the pool's guardian's darken holds: the operator re-lights that binding only after D
if (!op) nl |= W.P2_HELD;
r.price = nl;
emit SourceDarkened(listing, uint32(b), msg.sender);
}
/// @dev Whether a listing of pair word `pw` may bind source `id` and backup `b` (0 none), else `BadConfig`: both
/// registered (id 0 never is) and distinct, and no backup on an asset-module pair. On a storage build an
/// equity source (`E_EQUITY`) binds on an asset-module pair, its source must be one, and no other pair's
/// source or backup is one. On a builder build an asset-module pair's source also serves its base's record
/// outside a fill (`IAssetSource.assetRecord`, two words under `SOURCE_GAS`).
function _bindable(PropAMMStore.Layout storage $, uint256 pw, uint256 id, uint256 b) internal view {
uint256 e = $.sources[id];
bool asset = pw & W.PAIR_ASSET != 0;
if (e == 0 || id == b || (b != 0 && (asset || $.sources[b] == 0))) revert BadConfig();
if (_laneKind() == LANE_STORAGE) {
if ((e & W.E_EQUITY != 0) != asset || (b != 0 && $.sources[b] & W.E_EQUITY != 0)) revert BadConfig();
} else if (asset) {
_view(address(uint160(e)), IAssetSource.assetRecord.selector, 0, 0x40);
}
}
/// @dev Source `id`'s live copy, a listing's word 2 (`PropAMMWords`, P2): on a builder build the id, on a storage
/// build the lane and its two slots (entry bits 0-191), and the entry's window; no lease, on neither backup
/// nor dark.
function _live(PropAMMStore.Layout storage $, uint256 id) internal view returns (uint256) {
uint256 e = $.sources[id];
return (_laneKind() == LANE_STORAGE ? e & ((1 << 192) - 1) : id) | (e & (W.WIN_BITS | W.E_GUARD));
}
// ================================================================ the protocol owner, directly
/// @notice Lifts a listing's freeze: its pool's guardian or its operator.
function unfreeze(uint24 poolId) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
if (!_stopRole(address(uint160(s0)))) revert Unauthorized();
_status(r, poolId, s0 & ~W.F_FROZEN);
}
/// @notice Lifts the pause of every fill (g0 bit 160), set by `pauseAll` or a registry move's execution: the
/// protocol owner alone.
function unpauseAll() external {
PropAMMStore.Layout storage $ = _safe();
$.g0 = $.g0 & ~(uint256(1) << 160);
emit AllUnpaused();
}
// ================================================================ guardians
/// @notice Freezes a listing at once, its pool's guardian or its operator: the front's quote and swap, the pool's
/// own swap of the pair and the maker's posts refuse (`PoolFrozen`); redemptions pay. Either lifts it
/// (`unfreeze`).
function freeze(uint24 poolId) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
if (!_stopRole(address(uint160(s0)))) revert Unauthorized();
_status(r, poolId, s0 | W.F_FROZEN);
}
/// @notice The listing's scheduled change of `kind` (0 its settings, 11 its credit mode, 34 its
/// price source and backup, 35 its taker tip cap, 36 its own asset module, 38 a weakening of its desk
/// binding, 39 an offer of it to a desk, 40 its closed-phase settings; on a pool's first listing, 33 a
/// further listing): its operator or
/// its pool's guardian, and
/// for kind 36 also the protocol owner, who scheduled it.
function cancel(uint24 poolId, uint8 kind) external {
(, uint256 s0) = _pool(poolId);
PropAMMStore.Layout storage $ = PropAMMStore.state();
// the protocol owner also cancels its own scheduled asset module (kind 36): a cancel only stops a change
if (!(kind == KIND_ASSET && msg.sender == $.safe) && !_stopRole(address(uint160(s0)))) {
revert Unauthorized();
}
bytes32 id = keccak256(abi.encode(uint256(poolId), uint256(kind)));
if ($.pending[id] == 0) revert NotPending();
delete $.pending[id];
emit ChangeCancelled(id, msg.sender);
}
/// @notice Pauses every fill at once (g0 bit 160): the protocol guardian alone. The protocol owner lifts it
/// (`unpauseAll`).
function pauseAll() external {
PropAMMStore.Layout storage $ = _unlocked();
if (msg.sender != $.protocolGuardian) revert Unauthorized();
$.g0 = $.g0 | (1 << 160);
emit AllPaused(msg.sender);
}
// ================================================================ operators
/// @notice The listing's operator installs the maker key for a new epoch and bumps the listing's epoch at once:
/// pricing leaves the old key immediately. Records are append-only per epoch.
function setMakerKey(uint24 poolId, uint8 keyType, address key) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
_onlyCurator(address(uint160(s0)));
uint256 e = s0.sEpoch() + 1;
if (e > W.M32) revert BadConfig();
_writeKey(poolId, e, keyType, key);
r.p0 = (s0 & ~(uint256(W.M32) << 200)) | (e << 200);
}
// ================================================================ a listing on another party's desk
/// @notice The pool's operator offers a live listing to `desk`, any open desk, whose cold key need not be the
/// operator: a binding of two consents, this offer and that cold key's `acceptListing` of the same terms.
/// The offer binds nothing and moves no key, fence or epoch. One offer stands a listing (change kind 39),
/// of this form or `offerListingToKey`'s: a new one replaces it and restarts its wait.
/// @dev - The rules on `scopes` are `bindListing`'s, read here, so an offer that could never bind is refused
/// (`BadConfig`), and again as it is accepted.
/// - A weakening (ANY on, a higher fence kind, a longer carry life than the listing's now, an unbound listing
/// reading as the strongest) waits the pool's delay D from the offer, the operator's public act, logged
/// `ChangeScheduled` as every loosening is: the desk accepts it only from then, within the execution
/// window. Any other offer may be accepted at once, within that window from the offer. A quiet pool in the
/// block it went live gets no shortcut here, as the desk's accept comes in a later call.
/// - The offer names the listing's scopes as it was made and its operator: it is void once either differs, so
/// the wait it was given is the wait its accept needs, and no former operator's offer binds a pool.
/// - The maker key stays the operator's to name and rotate, as on its own desk (`setMakerKey`): the offer
/// names the next key epoch's key (zero keeps the key of the day) and the accept repeats it, so the desk
/// consents to the key it will price beside and never writes a key on a pool it does not operate.
/// - The operator or the pool's guardian drops it (`cancel(listing, 39)`). Either side ends a binding it makes
/// at once, by `unbindDesk`: the operator, or the bound desk's cold key.
/// @param listing The listing.
/// @param desk The desk.
/// @param scopes `bindListing`'s scopes.
/// @param wordIndex The listing's word in the desk's cell.
/// @param makerKey The next key epoch's maker key, an EOA; zero keeps the key of the day.
function offerListing(uint24 listing, uint32 desk, uint8 scopes, uint8 wordIndex, address makerKey) external {
_offer(listing, desk, address(0), scopes, wordIndex, makerKey);
}
/// @notice The pool's operator offers a live listing to whichever desk `coldKey` opens or has opened: the offer of
/// `offerListing`, its rules, wait, window and voiding alike, but for the desk, which the accept names
/// (`acceptListing` by `coldKey`, naming any desk whose cold key it is). So the operator may offer before
/// the desk exists, and a cold key that batches its calls (a multisig's batch, or an account delegated
/// under EIP-7702, either the caller of each call) opens its desk, sets its landing and accepts in one
/// transaction, naming the id its `openDesk` returns: desk ids are anyone's in order, so an id predicted
/// off chain may be taken first, and a batch that names it then reverts whole (the offer stands). A cold
/// key never changes, so every desk it opened is the same party's. `BadConfig` for a
/// zero `coldKey`, as for an offer `bindListing`'s rules refuse, but for the desk's word key that WORD,
/// NONE and SESSION need, read at the accept alone. Logged `ListingOfferedToKey`.
/// @param listing The listing.
/// @param coldKey The cold key whose desk may accept.
/// @param scopes `bindListing`'s scopes.
/// @param wordIndex The listing's word in the desk's cell.
/// @param makerKey The next key epoch's maker key, an EOA; zero keeps the key of the day.
function offerListingToKey(uint24 listing, address coldKey, uint8 scopes, uint8 wordIndex, address makerKey)
external
{
if (coldKey == address(0)) revert BadConfig();
_offer(listing, 0, coldKey, scopes, wordIndex, makerKey);
}
/// @dev An offer of `listing` to `desk` (`coldKey` zero) or to `coldKey`'s desk (`desk` zero), stored under its
/// tag (`_offerTag`) as change kind 39: due at once, or for a weakening the pool's delay D on.
function _offer(uint24 listing, uint32 desk, address coldKey, uint8 scopes, uint8 wordIndex, address makerKey)
internal
{
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
address pool = address(uint160(s0));
_onlyCurator(pool);
uint256 s1 = r.p1;
PropAMMStore.Layout storage $ = PropAMMStore.state();
PropAMMStore.Desk storage d = $.desks[desk];
// the desk's word key where the offer names a desk, which must be open; a key's offer leaves that rule to the
// accept
address wk = coldKey == address(0) ? d.wordKey : coldKey;
if ((coldKey == address(0) && uint160(d.w0) == 0) || _joinRefused(wk, s0, s1, r.sourceIds, scopes)) {
revert BadConfig();
}
uint256 v = _offerValue(desk, scopes, wordIndex, makerKey, s1);
uint256 tag = _offerTag(v, msg.sender, coldKey);
bytes32 id = keccak256(abi.encode(uint256(listing), KIND_OFFER));
if (_weaker(scopes, (s1 >> 227) & 0x1f)) PropAMMDue.schedule(listing, KIND_OFFER, v, tag, pool);
else $.pending[id] = DelayLib.word(tag, block.timestamp);
uint64 dueAt = uint64($.pending[id] >> 192);
if (coldKey == address(0)) emit ListingOffered(listing, desk, scopes, wordIndex, makerKey, dueAt);
else emit ListingOfferedToKey(listing, coldKey, scopes, wordIndex, makerKey, dueAt);
}
/// @notice The desk's cold key accepts the offer standing for `listing`, naming its terms exactly: one made to this
/// desk (`offerListing`), or to its cold key (`offerListingToKey`), which names no desk. The binding is
/// the one `bindListing` makes, written the same way. The listing moves to its next key epoch with
/// `makerKey` or, where the offer named none, its current key, so nothing signed under the earlier epoch
/// fills or posts again and its ANY list starts empty. `Unauthorized` for any other caller; `NotDue` where
/// no offer of these terms by the pool's operator of the day stands, or it still waits or has lapsed, or
/// the listing's scopes moved since; `BadConfig` where `bindListing`'s rules refuse it now.
function acceptListing(uint24 listing, uint32 desk, uint8 scopes, uint8 wordIndex, address makerKey) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
PropAMMStore.Desk storage d = PropAMMStore.state().desks[desk];
if (msg.sender != address(uint160(d.w0))) revert Unauthorized();
uint256 s1 = r.p1;
uint256 v = _offerValue(desk, scopes, wordIndex, makerKey, s1);
address op = _curator(address(uint160(s0)));
// the offer to this desk, else the one to its cold key, whose value names no desk
if (
!PropAMMDue.applyDue(listing, KIND_OFFER, _offerTag(v, op, address(0)))
&& !PropAMMDue.applyDue(listing, KIND_OFFER, _offerTag(v & ~uint256(W.M32), op, msg.sender))
) revert NotDue();
if (_joinRefused(d.wordKey, s0, s1, r.sourceIds, scopes)) revert BadConfig();
uint256 e = s0.sEpoch() + 1;
if (e > W.M32) revert BadConfig();
// the key as the landing part's binding writes it: the named one, else the epoch's, never none
_writeKey(
listing,
e,
PropAMMKeys.KEY_EOA,
makerKey != address(0) ? makerKey : address(uint160(PropAMMKeys.makerKey(listing, e - 1)))
);
r.p0 = (s0 & ~((uint256(W.M32) << 200) | (uint256(W.M8) << 232))) | (e << 200) | (uint256(wordIndex) << 232);
r.p1 = (s1 & ~P1_DESK_BITS) | (uint256(desk) << 192) | (uint256(scopes) << 227);
emit ListingBound(listing, desk, scopes, wordIndex, uint32(e));
emit ListingOfferAccepted(listing, desk);
}
/// @dev An offer's value, as `ChangeScheduled` logs a waiting one: [0-31] the desk (0 in an offer to a cold key) |
/// [32-39] the scopes | [40-47] the word index | [48-207] the maker key as named | [208-212] the listing's
/// scopes as the offer was made.
function _offerValue(uint32 desk, uint8 scopes, uint8 wordIndex, address makerKey, uint256 s1)
internal
pure
returns (uint256)
{
return uint256(desk) | (uint256(scopes) << 32) | (uint256(wordIndex) << 40) | (uint256(uint160(makerKey)) << 48)
| (((s1 >> 227) & 0x1f) << 208);
}
/// @dev An offer's tag, the top 192 bits of a hash: of its value and the operator who made it, and for an offer
/// to a cold key (`coldKey` not zero) that key too, three words, so neither form's tag is the other's.
function _offerTag(uint256 v, address operator, address coldKey) internal pure returns (uint256) {
if (coldKey == address(0)) return uint256(keccak256(abi.encode(v, operator))) >> 64;
return uint256(keccak256(abi.encode(v, operator, coldKey))) >> 64;
}
/// @dev The landing part's `_weaker`, copied whole: whether scopes `n` are weaker than the listing's `c` in any
/// field (ANY, the fence kind by its rank, the carry life).
function _weaker(uint256 n, uint256 c) internal pure returns (bool w) {
assembly ("memory-safe") {
// the fence kinds by rank (`PropAMMWords.FENCE_RANKS`): PRINT, SESSION, WORD, NONE
w := or(
gt(and(n, 1), and(c, 1)),
or(gt(and(shr(and(n, 6), 0x78), 3), and(shr(and(c, 6), 0x78), 3)), gt(and(n, 24), and(c, 24)))
)
}
}
/// @dev The landing part's `_bindRefused`, copied whole, the build's family read off its lane kind and the desk
/// given by its word key `wordKey`: whether `bindListing`'s rules refuse `scopes` on the listing of words `s0`
/// and `s1` and sources `w10` for that desk, the listing live (`NotLive` where it is not). A change to either
/// copy's rules is a change to both.
function _joinRefused(address wordKey, uint256 s0, uint256 s1, uint256 w10, uint256 scopes)
internal
view
returns (bool)
{
if (s0 & W.F_LIVE == 0) revert NotLive();
PropAMMStore.Layout storage $ = PropAMMStore.state();
uint256 fence = (scopes >> 1) & 3;
uint256 life = (scopes >> 3) & 3;
// a tied binding (scope bit 4 with no carry life under it, `PropAMMWords.tied`) is a PRINT one on a storage
// build, on guarded sources alone, and carries no life: any other use of the bit is a carry life past 1,
// refused below
if (life == 2 && fence == W.FENCE_PRINT && _laneKind() == LANE_STORAGE) {
if (!_guarded($, w10)) return true;
life = 0;
}
uint256 pw = $.pairs[s0.sPairId()].cfg;
return life > (pw & W.PAIR_ASSET != 0 ? 0 : 1) || scopes >> 5 != 0
|| (W.printed(fence) && (w10 == 0 || s1.minFill() < _srcFloor($, pw, w10)))
|| (fence != W.FENCE_PRINT && wordKey == address(0))
|| (scopes & 1 != 0 && (fence & 1 != 0 || pw & W.PAIR_ASSET != 0))
|| (_laneKind() == LANE_STORAGE && (scopes & 1 != 0 || life != 0))
|| (fence == W.FENCE_NONE && (life != 0 || IFLAMMLane(address(uint160(s0))).custodyBlind()));
}
/// @notice The listing's settings, one change: a word at least as tight in every field applies at once (dropping a
/// scheduled change), and so does any word on a quiet pool in the block it went live; any looser field
/// schedules the whole word for the pool's own delay D (`PropAMMDue`), and it applies when the operator
/// makes the identical call again once due, within the execution window. Its operator or its pool's
/// guardian may cancel it before. So a wider fence or ceiling, or a higher confidence multiplier, waits D,
/// and a lower one applies at once. On a pair with no price source `maxAgeMs` bounds nothing, as there is
/// no pull price to age: a maker word's own life (at most `MAX_TTL_MS`) and, on a builder build, its
/// landing block bound its age, and no band applies.
function setSettings(uint24 poolId, Settings calldata s) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
address pool = address(uint160(s0));
_onlyCurator(pool);
uint256 packed = _packSettings(s);
uint256 s1 = r.p1;
// the floor reads the listing's desk binding beside the new settings, and its sources (`_checkSettings`)
_checkSettings(s0, packed | (s1 & ~W.SETTINGS_BITS), r.sourceIds);
if (_due(poolId, KIND_SETTINGS, packed, _tighter(packed, s1), pool)) {
r.p1 = (s1 & ~W.SETTINGS_BITS) | packed;
emit SettingsSet(poolId, uint8(KIND_SETTINGS), packed);
}
}
/// @notice The listing's closed-phase settings (`SessionSettings`; record word 13, `PropAMMWords`' session word),
/// which a listing bound SESSION fills under while its kept print is at least `closedAfterMs` old
/// (`PropAMMFront`), under `setSettings`'s rule as change kind 40: a word at least as tight in every field
/// applies at once, and so does any word on a quiet pool in the block it went live; any looser field
/// schedules the whole word for the pool's delay D, applied on the identical call once due, unless its
/// operator or its pool's guardian cancels it (`cancel(listing, 40)`). A listing bound otherwise keeps the
/// word and never reads it.
/// @dev The word, its bounds (`OutsideCeiling`) and what counts as tighter are the hot part's
/// (`PropAMMFront.sessionWord`), asked through the proxy with this call's own arguments, so the rule sits
/// beside the fills that read the word; its revert passes on.
function setSession(uint24 listing, SessionSettings calldata) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
address pool = address(uint160(s0));
_onlyCurator(pool);
uint256 v;
bool tighter;
bytes4 sel = ISessionWord.sessionWord.selector;
assembly ("memory-safe") {
// this call's own data past the free pointer, under the hot part's selector, and the answer over it
let m := mload(0x40)
calldatacopy(m, 0, calldatasize())
mstore(m, or(sel, shr(32, shl(32, mload(m)))))
// Yul evaluates arguments right to left: the call first, in its own statement
let ok := staticcall(gas(), address(), m, calldatasize(), m, 0x40)
if iszero(and(ok, eq(returndatasize(), 0x40))) {
returndatacopy(m, 0, returndatasize())
revert(m, returndatasize())
}
v := mload(m)
tighter := mload(add(m, 0x20))
}
if (_due(listing, KIND_SESSION, v, tighter, pool)) {
r.session = v;
emit SettingsSet(listing, uint8(KIND_SESSION), v);
}
}
/// @notice The listing's credit mode (`PropAMMWords.CREDIT_*`, P1 bits 225-226), on every build, set at the
/// listing's launch (`PoolInit.creditMode`; no default): 0 the front fills from custody alone; where
/// custody cuts a fill short, 1 routes it to the pool's own swap if no pair of the pool may borrow the
/// output token, 2 whether or not one may; 3 routes every fill there. The pool's own switches cap it
/// (`PropAMMFront`). A lower mode is a tightening: it applies at once, from the operator or its pool's
/// guardian, dropping a scheduled change. A higher one is the operator's alone and waits the pool's delay D
/// (at once on a quiet pool in the block it went live): it applies on the identical call once due, within
/// the execution window, unless cancelled.
/// @dev A routing preference of the front's own entries, not a risk control: the pool's own swap is public and
/// priced by this front whatever the mode, so mode 0 or 1 stops no direct swap from paying out of lent supply
/// or by a borrow. Only the pool's credit-path switch and each pair's borrow switch bound that, so an operator
/// who wants no borrowing turns the pair's borrowing off.
function setCreditMode(uint24 poolId, uint8 mode) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
address pool = address(uint160(s0));
uint256 s1 = r.p1;
bool tighter = mode <= s1.creditMode();
if (msg.sender != _curator(pool) && !(tighter && msg.sender == IEverlongCore(IFLAMM(pool).core()).guardian())) {
revert Unauthorized();
}
if (mode > W.CREDIT_ALWAYS) revert BadConfig();
if (_due(poolId, KIND_CREDIT, mode, tighter, pool)) {
r.p1 = (s1 & ~(uint256(3) << W.CREDIT_SHIFT)) | (uint256(mode) << W.CREDIT_SHIFT);
emit SettingsSet(poolId, uint8(KIND_CREDIT), mode);
}
}
/// @notice Lifts the maker's pause (`pauseMaker`): the listing's operator alone. It also clears the status word's
/// `F_PAUSED` flag, which is reserved: nothing sets it.
function unpause(uint24 poolId) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
_onlyCurator(address(uint160(s0)));
_status(r, poolId, s0 & ~(W.F_PAUSED | W.F_MAKER_PAUSED));
}
/// @notice Retires a listing for good (its operator, or the protocol owner as the front's listing decision under
/// its published delisting policy: an abandoned listing, an operator's sanctions or lapsed checks, a token
/// its issuer can seize), at once: a pool's first listing or a further one, the pool's other listings
/// untouched.
/// @dev - The pool resyncs the pairs its own swap opens (`IFLAMMLane.syncListings`, best effort: a resync the pool
/// refuses is logged, `ListingResyncFailed`, and never stops the retirement; anyone resyncs).
/// - A resync the call's gas starved (under an eighth of the gas it began with left after it, a line well
/// above the 1/64 the 63/64 rule leaves) reverts the retirement instead (`ResyncOutOfGas`), so a wallet's
/// estimate budgets for it. A pool whose resync burned all the gas it was given would block its retirements,
/// which no pool of `FLAMMFactory`'s beacon does.
/// - While its first listing is live a pool may later take a further listing on a pair it left (`addListing`).
/// Once the first listing is retired the pool takes no listing again, its further listings filling on until
/// they retire.
/// - The protocol owner's retirement of a further listing is a delisting that sticks (`ListingDelisted`): the
/// pool's listing map keeps the listing, so the pool takes no listing on that pair again until the protocol
/// owner relists it (`relistListing`). The protocol owner marks a further listing its operator retired first
/// the same way, while the pool holds no listing on the pair, logging the delisting alone.
function retirePool(uint24 poolId) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(poolId);
PropAMMStore.Layout storage $ = PropAMMStore.state();
bool bySafe = msg.sender == $.safe;
if (!bySafe) _onlyCurator(address(uint160(s0)));
uint256 key = PropAMMStore.listingKey(address(uint160(s0)), s0.sPairId());
if (s0 & W.F_LIVE == 0) {
// the protocol owner delists a further listing its operator retired first: the map keeps it, logged once
// as a delisting
if (!bySafe || s0.sIndices() == 0 || $.listingOf[key] != 0) revert NotLive();
$.listingOf[key] = poolId;
emit ListingDelisted(poolId, msg.sender);
return;
}
r.p0 = s0 & ~W.F_LIVE;
if (s0.sIndices() != 0) {
if (bySafe) emit ListingDelisted(poolId, msg.sender);
else delete $.listingOf[key];
}
emit PoolRetired(poolId, msg.sender);
// the pool asks again, so its own swap closes the pair to the retired listing (`IFLAMMLane.syncListings`): best
// effort, as nothing the pool answers may stop a retirement (its answer is not even decoded); a refused resync
// is logged, and anyone resyncs. A starved one is the caller's short limit, not the pool's answer: it reverts,
// so the limit rises
uint256 g = gasleft();
try IFLAMMLane(address(uint160(s0))).syncListings() {} catch {
if (gasleft() < g / 8) revert ResyncOutOfGas();
emit ListingResyncFailed(poolId, address(uint160(s0)));
}
}
/// @notice The protocol owner relists a further listing it delisted (`retirePool`, `ListingDelisted`): the pool's
/// listing map drops the retired listing, so the pool may take a listing on the pair again (`addListing`,
/// its operator's, after D, or at once on a quiet pool in the block it went live).
function relistListing(uint24 poolId) external {
PropAMMStore.Layout storage $ = _safe();
PropAMMStore.Pool storage r = $.pools[poolId];
uint256 s0 = r.p0;
uint256 key = PropAMMStore.listingKey(address(uint160(s0)), s0.sPairId());
// a retired listing the map keeps, never a reserved one (its board words stay zero until it confirms)
if (s0 & W.F_LIVE != 0 || r.boardBid == 0 || $.listingOf[key] != poolId) revert NotLive();
delete $.listingOf[key];
emit ListingRelisted(poolId, msg.sender);
}
// ================================================================ asset modules
/// @notice A listing's own asset module in place of its pair's (`_assetInstaller`'s rule: the protocol owner
/// schedules, the pool's operator applies): one
/// of the pair's rules (`addPair`'s checks on the pair's base and family) that has never held a word for
/// the listing (`IAssetModule.isBound`), never the pair's own: a replaced module is never put back, so no
/// stale word of it rules the listing again. Only the protocol owner schedules a replacement, and it waits
/// the listing's pool delay D, quiet pool or not; only the pool's operator applies it, by the identical
/// call once due, within the execution window, while the module's code hash is the one scheduled. The
/// owner cannot apply, the operator cannot schedule, and any other caller can do neither, so the protocol
/// takes no role on a pool unless its operator opts in. The protocol owner, the listing's operator or
/// its pool's guardian cancels a scheduled replacement (`cancel(listing, 36)`).
function setAssetModule(uint24 listing, address module) external {
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
address pool = address(uint160(s0));
bool scheduling = _assetInstaller(pool);
PropAMMStore.Pair storage pr = PropAMMStore.state().pairs[s0.sPairId()];
uint256 a = pr.asset;
if (
a == 0 || module == address(uint160(a))
|| !_assetOk(module, pr.cfg & W.PAIR_BASE_IS_T0 != 0 ? pr.token0 : pr.token1, a >> 160, listing)
) revert BadConfig();
uint256 m = uint160(module);
uint256 tag = uint256(keccak256(abi.encode(m, module.codehash))) >> 64;
if (scheduling) {
PropAMMDue.schedule(listing, KIND_ASSET, m, tag, pool);
return;
}
// the operator applies only what is due: it never schedules
if (!PropAMMDue.applyDue(listing, KIND_ASSET, tag)) revert Unauthorized();
r.stockPolicy = m;
r.p0 = s0 | W.F_ASSET;
emit AssetModuleSet(uint32(s0.sPairId()), listing, module);
emit SettingsSet(listing, uint8(KIND_ASSET), m);
}
/// @notice Removes an asset-module pair's module for good (the protocol owner, at once: a tightening): every
/// listing of the pair, one with its own module included, refuses from then on (`AssetRefused(255)`).
function removeAssetModule(uint32 pairId) external {
PropAMMStore.Layout storage $ = _safe();
PropAMMStore.Pair storage pr = $.pairs[pairId];
if (pr.asset == 0) revert BadConfig();
pr.asset = 0;
// and the fills' copy (`addPair`): the pair's `pairIdOf` word back to its id and its pair word's facts
$.pairIdOf[_pairKey(pr.token0, pr.token1)] = pairId | W.entryFacts(pr.cfg);
emit AssetModuleSet(pairId, 0, address(0));
}
/// @notice A listing's asset module copies its word for the listing into the listing's record (word 12), on its
/// every write of it (`IAssetFront.setAssetWord`): only the module the listing resolves to
/// (`PropAMMAsset.moduleOf`, as `assetFacts` admits it), so no other module's word, and none from before a
/// listing's own module replaced its pair's, is ever read there. The named-door fill runs the stock rules on
/// it for a listing of its pair's module (`PropAMMStockRules`). No lock: a module may write mid-fill, as it
/// may write its own word then, and a fill reads the word once, at its check.
function setAssetWord(uint256 listing, uint256 word) external {
PropAMMStore.Layout storage $ = PropAMMStore.state();
PropAMMStore.Pool storage r = $.pools[listing];
uint256 s0 = r.p0;
// a listing never reserved reads pair 0, which never exists (ids start at 1), and a pair with no module
// resolves to none: neither matches a caller
if (msg.sender != PropAMMAsset.moduleOf($.pairs[s0.sPairId()].asset, s0, listing)) revert Unauthorized();
r.stockState = word;
}
/// @dev Who may act on a listing's own asset module: the protocol owner schedules it (returns true) and only the
/// owner; the pool's operator (`_onlyCurator(pool)`) applies it once due (returns false) and only the
/// operator. The owner is refused the apply and the operator the schedule, so the protocol takes no role on
/// an operator's pool unless the operator applies. A PRINT listing's price fence rests on the module an asset
/// pair scales its print by, which the operator now opts into; a custody-blind pool's law does not rest on
/// it, as its listings may bind WORD, fenced to no print.
function _assetInstaller(address pool) internal view returns (bool scheduling) {
if (msg.sender == PropAMMStore.state().safe) return true;
_onlyCurator(pool);
}
// ================================================================ the launcher
/// @notice The launcher reserves a pool at its predicted address before its genesis (so `boundPool` answers during
/// it): assigns its id (its listing on the pair) and records its key and settings, and the block, the
/// chain's own (`PropAMMDue.chainBlock`): the launch reserves, creates and confirms the pool in one
/// transaction, so this is the block the pool goes live, the only one in which its operator's loosenings
/// apply at once, on a quiet pool (`PropAMMDue.born`). The pair is its tokens' current one (`BadConfig`
/// for a retired pair, `retirePair`).
function reservePool(address pool, uint32 pairId, PoolInit calldata init) external returns (uint24 poolId) {
PropAMMStore.Layout storage $ = _launcher();
_currentPair($, pairId);
if (pool == address(0) || $.poolIdOf[pool] != 0) revert BadConfig();
uint256 packed = _initWord(init);
poolId = _nextListing($);
_writeListing(poolId, uint160(pool) | (uint256(pairId) << 160) | (uint256(1) << 200), packed, init);
$.poolIdOf[pool] = poolId | (PropAMMDue.chainBlock() << 24);
}
/// @notice Confirms a reserved, never-confirmed pool after its genesis: `FLAMMFactory` created it, its swap hook is
/// this front and it names no controller, its tokens are the pair's and its core is a `DelayedAuthority`
/// ({_authority}). Writes the pool's cheap lane config and its cheap lane past the hook pair, makes the
/// listing live and writes both board words.
/// @dev - The cheap lane config: `strict`, `creditPath`, `outflowCaps` (`IFLAMMLane.initLane`, which refuses a pool
/// owing anything).
/// - Right after it, the cheap lane past the hook pair: `tokens` (`IFLAMMLane.initLaneTokens`: one caps entry
/// per token past token 1, the pool refusing another count, and the custody-blind law).
/// - `creditPath` is the launch's own choice, no default: the pool's own swap of every pair this front prices
/// (the hook pair and each listing's pair), which a listing's credit route (`setCreditMode`) needs. Off,
/// only the operator turns it on, after the pool's delay, and a custody-blind pool keeps it off for good.
/// - A further listing reserved for the launch goes live in its own `confirmListing`, which resyncs the pool
/// (`IFLAMMLane.syncListings`), so after the launch's last listing the pool's cheap lane settles every
/// listing's pair within the launch's `tokens.lanePairs`.
///
/// The launch is one transaction (`PropAMMLauncher`): `reservePool`, `FLAMMFactory`'s `createPool` (the
/// pool-asset seed), then `confirmPool`. On a pool whose operator's fee cap is nonzero, every pro-rata entry
/// then refuses (`BasketNotRecorded`) until the operator's seed of token 1 (`FLAMM.seedLeg`) records the
/// deposit basket: a launch seeds both tokens, the pool asset at genesis and token 1 by the operator after it.
function confirmPool(uint24 poolId, bool strict, bool creditPath, uint96 outflowCaps, LaneTokens calldata tokens)
external
{
PropAMMStore.Layout storage $ = _launcher();
PropAMMStore.Pool storage r = $.pools[poolId];
uint256 s0 = r.p0;
// board words are nonzero from the confirmation on: a retired or confirmed pool never confirms again
if (s0 == 0 || r.boardBid != 0) revert NotLive();
address pool = address(uint160(s0));
uint256 pairId = s0.sPairId();
(address base, address quoteT) = _baseQuote($.pairs[pairId]);
IFLAMM.HookSet memory hk = IFLAMM(pool).hooks();
if (
!IPoolFactoryView(FACTORY).isPool(pool) || hk.hook != address(this) || hk.controller != address(0)
|| IFLAMM(pool).asset() != base || IFLAMM(pool).loanAsset() != quoteT
) revert BadConfig();
_authority(pool);
IFLAMMLane(pool).initLane(strict, creditPath, outflowCaps);
IFLAMMLane(pool).initLaneTokens(tokens.lanePairs, tokens.tokenCaps, tokens.maxDrawnTokens, tokens.custodyBlind);
_goLive(r, poolId, s0, pairId);
}
/// @dev A listing goes live on its pair: its board words (nonzero from now on, so it never confirms again). No list
/// or count of a pair's listings is kept: they are found by id (`listingsOn`).
function _goLive(PropAMMStore.Pool storage r, uint256 listingId, uint256 s0, uint256 pairId) internal {
r.p0 = s0 | W.F_LIVE;
uint256 b = W.board(0, 0, 0, block.timestamp * 1000, 0, 0);
r.boardBid = b;
r.boardAsk = b;
emit PoolRegistered(uint32(pairId), uint24(listingId), address(uint160(s0)));
}
/// @notice The launcher sets a listing's first taker tip cap at its birth (`PropAMMLauncher.launchWhole`, for its
/// caller, the pool's operator): at once on every build, though on a storage build `setTipCap` takes a
/// move from 0 as a loosening, as a listing born there fills nothing before its first cap.
/// Only in the block the pool went live (`PropAMMDue.born`), on a listing with no cap, and never zero
/// (`BadConfig`), so the launcher holds no setting of a listing past its launch. Logged as `setTipCap`'s.
function capAtBirth(uint24 listing, uint16 cap) external {
_launcher();
(PropAMMStore.Pool storage r, uint256 s0) = _pool(listing);
uint256 s1 = r.p1;
if (cap == 0 || s1.tipCap() != 0 || !PropAMMDue.born(address(uint160(s0)))) revert BadConfig();
r.p1 = s1 | (uint256(cap) << W.TIP_SHIFT);
emit SettingsSet(listing, 35, cap);
}
// ================================================================ listings: a pool on several pairs
/// @notice Reserves a further listing of a pool the launcher reserved and has not confirmed, before its genesis (so
/// its pair is one the pool's swap hook prices at birth, `pricesPair`): the pool's place on `pairId`, whose
/// base and quote must be the pool's tokens at `baseIndex` and `quoteIndex` (checked at `confirmListing`,
/// once the pool exists), with its own maker key and settings.
function reserveListing(address pool, uint32 pairId, uint8 baseIndex, uint8 quoteIndex, PoolInit calldata init)
external
returns (uint24 listingId)
{
PropAMMStore.Layout storage $ = _launcher();
uint256 home = $.poolIdOf[pool] & W.M24;
if (home == 0 || $.pools[home].boardBid != 0) revert NotLive();
listingId = _newListing($, pool, $.pools[home].p0.sPairId(), pairId, baseIndex, quoteIndex, init);
}
/// @notice Makes a reserved further listing live in its pool's launch, once the pool exists and its first listing
/// is confirmed: the pool's tokens at the listing's indices are the pair's base and quote.
function confirmListing(uint24 listingId) external {
PropAMMStore.Layout storage $ = _launcher();
PropAMMStore.Pool storage r = $.pools[listingId];
uint256 s0 = r.p0;
if (s0 == 0 || r.boardBid != 0 || s0.sIndices() == 0) revert NotLive();
if ($.pools[$.poolIdOf[address(uint160(s0))] & W.M24].p0 & W.F_LIVE == 0) revert NotLive();
_listingLive($, r, listingId, s0);
}
/// @notice A further listing of a live pool, its operator's: a loosening, so it waits the pool's delay D (at once
/// on a quiet pool in the block it went live) and applies on the identical call once due, within the
/// execution window, unless the operator or the pool's guardian cancels it (`cancel(homeId, 33)`); one such
/// change per pool at a time. Returns the listing, or zero while the change is only scheduled.
/// @dev - Through the launcher alone (`PropAMMLauncher.addListing`, which takes the listing's deposit and admits
/// the operator on the pair), naming `operator`, its caller, which must be the pool's operator, and
/// `deskWord`, the listing's desk at its birth ([0-31] the desk | [32-39] its scopes | [40-47] its word
/// index), in the scheduled value beside the rest: the binding the launcher makes as the listing goes live
/// (`bindAtBirth`) takes no wait of its own, so another word schedules again and the one delay covers the
/// listing and its scopes.
/// - `homeId` is the pool's first listing, live.
/// - The pair must be its tokens' current one (`BadConfig` for a retired pair, `retirePair`), and the pool
/// must hold no listing on it and its pair hook must not price it, at the schedule and when it applies;
/// when it applies, the pool must also list the pair's base and quote at `baseIndex` and `quoteIndex` (its
/// own admissions, under its own delays), which the schedule does not check.
/// - The listing's settings and credit mode are checked at the schedule as at a birth.
/// - Once live the pool resyncs the pairs its own swap opens (`IFLAMMLane.syncListings`), which opens the
/// listing's pair only where it is on the pool's cheap lane (`lanePairs`: the launch's, or a `setLanePairs`
/// opening, which resyncs the pairs it opens itself, so a listing live before it trades with no further
/// call).
/// - A pair the front did not price at the pool's birth also needs the pool's own trade-mask opening
/// (`setTradePairs`, the operator's, waiting the pool's delay), which the operator schedules beside this
/// call, as the pool's mask at birth opens only the pairs the front priced then.
/// - Removing a listing (`retirePool`) is at once.
function addListing(
address operator,
uint24 homeId,
uint32 pairId,
uint8 baseIndex,
uint8 quoteIndex,
PoolInit calldata init,
uint256 deskWord
) external returns (uint24 listingId) {
PropAMMStore.Layout storage $ = _launcher();
(, uint256 h0) = _pool(homeId);
address pool = address(uint160(h0));
if (h0 & W.F_LIVE == 0 || $.poolIdOf[pool] & W.M24 != homeId) revert NotLive();
if (operator != _curator(pool)) revert Unauthorized();
_listingArgs($, pool, h0.sPairId(), pairId, baseIndex, quoteIndex);
// one pricer a pair: never one the pool's pair hook prices (the pool refuses a pair hook over a live listing)
if (_hookPair(pool, uint256(baseIndex) | (uint256(quoteIndex) << 4))) revert BadConfig();
// the credit mode checked at the schedule as at a birth
_initWord(init);
uint256 v = uint256(keccak256(abi.encode(pairId, baseIndex, quoteIndex, init, deskWord)));
if (!_due(homeId, KIND_LISTING, v, false, pool)) return 0;
listingId = _newListing($, pool, h0.sPairId(), pairId, baseIndex, quoteIndex, init);
PropAMMStore.Pool storage r = $.pools[listingId];
_listingLive($, r, listingId, r.p0);
}
/// @dev A further listing's arguments: a registered pair other than the pool's first listing's, one the pool holds
/// no listing on, and two distinct token indices under 16.
function _listingArgs(
PropAMMStore.Layout storage $,
address pool,
uint256 homePair,
uint256 pairId,
uint8 b,
uint8 q
) internal view {
_currentPair($, pairId);
if (pairId == homePair || b > 15 || q > 15 || b == q || $.listingOf[PropAMMStore.listingKey(pool, pairId)] != 0)
{
revert BadConfig();
}
}
/// @dev `_pairWord` at a pool's or a listing's birth: the pair is still its tokens' own, `BadConfig` for a retired
/// one (`retirePair`), so none is born on a pair no fill resolves.
function _currentPair(PropAMMStore.Layout storage $, uint256 pairId) internal view {
_pairWord($, pairId);
PropAMMStore.Pair storage pr = $.pairs[pairId];
if ($.pairIdOf[_pairKey(pr.token0, pr.token1)] & W.M32 != pairId) revert BadConfig();
}
/// @dev Records a further listing, not yet live: its id, status (the token indices in P0's top byte), settings and
/// maker key at epoch 1, and the pool's listing map.
function _newListing(
PropAMMStore.Layout storage $,
address pool,
uint256 homePair,
uint32 pairId,
uint8 b,
uint8 q,
PoolInit calldata init
) internal returns (uint24 listingId) {
_listingArgs($, pool, homePair, pairId, b, q);
uint256 packed = _initWord(init);
listingId = _nextListing($);
uint256 s0 = uint160(pool) | (uint256(pairId) << 160) | (uint256(1) << 200)
| ((uint256(b) | (uint256(q) << 4)) << 248);
_writeListing(listingId, s0, packed, init);
$.listingOf[PropAMMStore.listingKey(pool, pairId)] = listingId;
$.poolIdOf[pool] |= PropAMMStore.LISTINGS_FLAG;
}
/// @dev A listing's record at its reservation: its settings checked, its price source and backup, its first maker
/// key, P0 (its word index 0) and P1 (unbound); logged, its birth values as their later changes are. The
/// sources' floor waits for the desk binding, which checks it.
function _writeListing(uint256 listingId, uint256 s0, uint256 packed, PoolInit calldata init) internal {
PropAMMStore.Layout storage $ = PropAMMStore.state();
uint256 sid = init.source;
uint256 bk = init.backup;
uint256 v = sid | (bk << 32);
_checkSettings(s0, packed, v);
PropAMMStore.Pool storage r = $.pools[listingId];
// the listing's price source, its operator's explicit choice among the registered sources (no default), and a
// backup or none; with no source the listing is unpriced, its words 2 and 10 zero
if (sid == 0) {
if (bk != 0) revert BadConfig();
} else {
_bindable($, $.pairs[s0.sPairId()].cfg, sid, bk);
r.sourceIds = v;
r.price = _live($, sid);
}
_writeKey(listingId, 1, init.makerKeyType, init.makerKey);
r.p0 = s0;
r.p1 = packed;
emit SettingsSet(uint24(listingId), uint8(KIND_SETTINGS), packed & W.SETTINGS_BITS);
emit SettingsSet(uint24(listingId), uint8(KIND_CREDIT), init.creditMode);
emit SettingsSet(uint24(listingId), uint8(KIND_SOURCE), v);
emit PoolReserved(uint32(s0.sPairId()), uint24(listingId), address(uint160(s0)));
}
/// @dev A further listing goes live: the pool lists the pair's base and quote at the listing's indices; then the
/// board words ({_goLive}) and the pool's resync.
function _listingLive(PropAMMStore.Layout storage $, PropAMMStore.Pool storage r, uint24 listingId, uint256 s0)
internal
{
address pool = address(uint160(s0));
uint256 pairId = s0.sPairId();
(address base, address quoteT) = _baseQuote($.pairs[pairId]);
uint256 ix = s0.sIndices();
if (_tokenAt(pool, ix & 15) != base || _tokenAt(pool, ix >> 4) != quoteT) revert BadConfig();
_goLive(r, listingId, s0, pairId);
// the pool asks the front again which of its cheap lane's pairs it prices (`IFLAMMLane.syncListings`, open to
// anyone), so its own swap opens the listing's pair where its trade mask does
IFLAMMLane(pool).syncListings();
}
/// @dev The next listing id (`ids` bits 32-55), taken; the last one, 2^24 - 1, is never handed out.
function _nextListing(PropAMMStore.Layout storage $) internal returns (uint24 id) {
uint256 ids = $.ids;
id = uint24(ids >> 32);
if (id == W.M24) revert BadConfig();
$.ids = ids + (uint256(1) << 32);
}
/// @dev A pair's base and quote tokens, sorted by its pair word's base flag.
function _baseQuote(PropAMMStore.Pair storage pr) internal view returns (address, address) {
return pr.cfg & W.PAIR_BASE_IS_T0 != 0 ? (pr.token0, pr.token1) : (pr.token1, pr.token0);
}
/// @dev The pool's token at index `t` (`IFLAMM.tokenConfig(t)`'s first word), zero where the pool lists none.
function _tokenAt(address pool, uint256 t) internal view returns (address a) {
(bool ok, bytes memory ret) = pool.staticcall(abi.encodeWithSelector(IFLAMM.tokenConfig.selector, uint8(t)));
if (ok && ret.length >= 32) a = address(uint160(uint256(bytes32(ret))));
}
// ================================================================ views
/// @notice The front's 10-day timelock, through which the protocol owner acts: who upgrades the front and lands
/// every 10-day change.
function owner() external view returns (address) {
return PropAMMStore.state().owner;
}
/// @notice The build's kind. 0: Ethereum's builder build (desk cells, landing by their own push or a builder lane
/// of the Flashbots registry); 1: the storage build (Base, Arbitrum One, Robinhood, HyperEVM), whose price
/// sources are stored price lanes; 2: BNB Chain's builder build (desk cells, landing by their own push or,
/// where the front's registry is a relayer adapter, a builder lane through it). The builder builds' (0 and
/// 2) price sources are pull checks. A constant of each leaf, so a build carries only its own kind's
/// branches.
function LANE_KIND() external pure returns (uint256) {
return _laneKind();
}
/// @notice The protocol owner: what it calls here takes effect at once. It acts through the 10-day timelock as
/// `owner()`.
function instantOwner() external view returns (address) {
return PropAMMStore.state().safe;
}
/// @notice The protocol guardian: it pauses every fill on every build; on the Ethereum and BNB Chain builds it
/// also cancels a registry move and cuts a listing's lease or every lease (`cutLease`), and on a storage
/// build (Base) its price lane's pin (`PythLane.cutPin`). It holds no role in any operator's pool: the
/// listing's own stops (`freeze`, `darkenSource`, the desk stop, `pauseMaker`) stay with the operator and
/// the pool's guardian. The owner rotates it (`setProtocolGuardian`).
function protocolGuardian() external view returns (address) {
return PropAMMStore.state().protocolGuardian;
}
/// @notice Raw storage words, for a lens that decodes the published slot formulas (`PropAMMStore`).
function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res) {
res = new bytes32[](slots.length);
for (uint256 i; i < slots.length; ++i) {
bytes32 s = slots[i];
bytes32 v;
assembly ("memory-safe") {
v := sload(s)
}
res[i] = v;
}
}
// ================================================================ the cold part
/// @notice Every selector this part does not serve, handed whole to the cold part (`COLD`) by DELEGATECALL, in
/// this call's context, the proxy's: its answer returned, or its revert passed on (an empty one for a
/// selector neither part serves, as the cold part has no fallback).
fallback() external {
address cold = COLD;
assembly ("memory-safe") {
let m := mload(0x40)
calldatacopy(m, 0, calldatasize())
let ok := delegatecall(gas(), cold, m, calldatasize(), 0, 0)
returndatacopy(m, 0, returndatasize())
if iszero(ok) { revert(m, returndatasize()) }
return(m, returndatasize())
}
}
/// @dev Creates the build's cold part, its leaf's own (`PropAMMAdminCold`), from the inputs the constructor
/// checked; called by the constructor alone.
function _cold(Config memory c) internal virtual returns (address);
// ================================================================ internals: roles
/// @dev The state, with the front unlocked and the caller its launcher; no one passes while none is set.
function _launcher() internal view returns (PropAMMStore.Layout storage $) {
$ = _unlocked();
if (msg.sender != $.launcher || $.launcher == address(0)) revert Unauthorized();
}
/// @dev A listing's record and word P0, with the front unlocked: reserved, live or retired; `NotLive` for an id no
/// listing took.
function _pool(uint24 poolId) internal view returns (PropAMMStore.Pool storage r, uint256 s0) {
r = _unlocked().pools[poolId];
s0 = r.p0;
if (s0 == 0) revert NotLive();
}
/// @dev The caller is the pool's operator, read live.
function _onlyCurator(address pool) internal view {
if (msg.sender != _curator(pool)) revert Unauthorized();
}
/// @dev Writes a listing's status flags and logs them.
function _status(PropAMMStore.Pool storage r, uint24 poolId, uint256 s0) internal {
r.p0 = s0;
emit PoolStatus(poolId, uint8(s0 >> 192), msg.sender);
}
// ================================================================ internals: pairs, keys, prices
/// @dev The pool's core is a `DelayedAuthority`, by its runtime code's hash (1), whose delay (`DELAY`) is at least
/// the pool's own D (2), with no guardian change scheduled (3): its guardian then changes only `DELAY` after
/// the operator asks, so the operator cannot name another guardian before the one it fears acts (a core that
/// rotates the guardian at once leaves the guardian's stop to the operator's goodwill). Nor an owner change
/// (4): the pool's operator, the core's owner, then changes only `DELAY` after it asks, a change its
/// depositors see from the ask on. The hash proves the code, not the storage a constructor wrote, hence (3)
/// and (4): a schedule written at creation could already be due. A lapsed schedule, which cannot run, reads as
/// none.
function _authority(address pool) internal view {
address core = IFLAMM(pool).core();
(, uint32 d) = IFLAMM(pool).switches();
if (core.codehash != AUTHORITY_CODEHASH) revert AuthorityRefused(1);
if (IAuthorityView(core).DELAY() < d) revert AuthorityRefused(2);
if (IAuthorityView(core).guardianDueAt() != 0) revert AuthorityRefused(3);
if (IAuthorityView(core).ownerDueAt() != 0) revert AuthorityRefused(4);
}
/// @dev An EOA maker key, the only kind the front takes (key type 1, P-256, is reserved; other types refused).
function _writeKey(uint256 poolId, uint256 epoch, uint256 keyType, address key) internal {
if (key == address(0) || keyType != PropAMMKeys.KEY_EOA) revert BadConfig();
PropAMMStore.state().makerKeys[PropAMMKeys.keyId(poolId, epoch)] = uint160(key);
emit MakerKeySet(uint24(poolId), uint32(epoch), uint8(keyType), key);
}
// ================================================================ internals: settings and the scheduled changes
/// @dev A listing's word 1 at its reservation, every field from `init`: the settings and the credit mode, each
/// checked as its setter checks it. At a launch's listings they wait nothing (the pool has no depositor yet);
/// a further listing's (`addListing`) wait the pool's delay D with the listing, checked here at the schedule
/// too.
function _initWord(PoolInit calldata init) internal pure returns (uint256) {
if (init.creditMode > W.CREDIT_ALWAYS) revert BadConfig();
return _packSettings(init.settings) | (uint256(init.creditMode) << W.CREDIT_SHIFT);
}
/// @dev The settings as P1's bits 0-191 and 232-239 (`PropAMMWords`, `SETTINGS_BITS`), in the struct's order: the
/// fences and the ceiling stored as ppm / 10, each refused (`OutsideCeiling`) off the 10 ppm step or over
/// `MAX_FENCE_PPM`, and the confidence multiplier refused over `MAX_CONF_MUL`.
function _packSettings(Settings calldata s) internal pure returns (uint256) {
uint256 fb = s.fenceBidPpm;
uint256 fa = s.fenceAskPpm;
uint256 c = s.ceilPpm;
if (
fb % 10 != 0 || fa % 10 != 0 || c % 10 != 0 || fb > MAX_FENCE_PPM || fa > MAX_FENCE_PPM
|| c > MAX_FENCE_PPM || s.confMul > MAX_CONF_MUL
) revert OutsideCeiling();
return (fb / 10) | ((fa / 10) << 16) | ((c / 10) << 32) | (uint256(s.maxAgeMs) << 48)
| (uint256(s.rateCeilBid) << 64) | (uint256(s.rateCeilAsk) << 88) | (uint256(s.burstCeilBid) << 112)
| (uint256(s.burstCeilAsk) << 136) | (uint256(s.minFill) << 160) | (uint256(s.splitDepth) << 184)
| (uint256(s.confMul) << W.CONF_MUL_SHIFT);
}
/// @dev Whether a change of `kind` applies now (`PropAMMDue`): a tightening at once, and so does any change on a
/// quiet pool in the block it went live (`PropAMMDue.born`; `PropAMMQuiet`: no one but its operator holds a
/// share or can be on the way to one), read here only for a loosening in that block, through the proxy from
/// the landing part's `quietOf` (a failed read is not quiet); else after the pool's own delay D.
function _due(uint24 poolId, uint256 kind, uint256 v, bool tighter, address pool) internal returns (bool) {
return PropAMMDue.due(poolId, kind, v, tighter || _quietAtBirth(pool), pool);
}
/// @dev Whether `pool` went live in this block (`PropAMMDue.born`) and is quiet: the landing part's `quietOf(pool)`,
/// read through the proxy only in that block, false on a failed call or another answer.
function _quietAtBirth(address pool) internal view returns (bool q) {
if (!PropAMMDue.born(pool)) return false;
assembly ("memory-safe") {
mstore(0, shl(224, 0xfe834078)) // quietOf(address)
mstore(4, pool)
// Yul evaluates arguments right to left: the call first, in its own statement
let ok := staticcall(gas(), address(), 0, 36, 0, 0x20)
q := and(and(ok, eq(returndatasize(), 0x20)), eq(mload(0), 1))
}
}
/// @dev Whether settings word `v` restricts at least as much as `cur` in every field: fences, ceiling and age no
/// wider, the rate and burst ceilings no higher, the minimum fill no lower, a split depth no deeper (0 reports
/// every rung, the loosest), and a confidence multiplier no higher.
function _tighter(uint256 v, uint256 cur) internal pure returns (bool) {
for (uint256 k; k < 4; ++k) {
if (((v >> (16 * k)) & W.M16) > ((cur >> (16 * k)) & W.M16)) return false;
}
for (uint256 k; k < 4; ++k) {
uint256 off = 64 + 24 * k;
if (PropAMMLaneLib.amount24((v >> off) & W.M24) > PropAMMLaneLib.amount24((cur >> off) & W.M24)) {
return false;
}
}
uint256 sd = v.splitDepth();
uint256 sdCur = cur.splitDepth();
return v.minFill() >= cur.minFill() && (sd == sdCur || (sd != 0 && (sdCur == 0 || sd < sdCur)))
&& v.confMul() <= cur.confMul();
}
/// @dev The settings rules: fences at most the listing's ceiling, the ceiling at most `MAX_FENCE_PPM`, the
/// confidence multiplier at most `MAX_CONF_MUL`, age at most the chain's ceiling, nonzero rate and burst
/// ceilings, a split depth of at most 10, a minimum fill under 2^128 quote units, never zero and, on a listing
/// bound to a desk as PRINT or SESSION, at least its sources' floor (`_srcFloor`, of the sources in `w10`, the
/// listing's word 10; `bindListing` holds a binding to it too). `s1` is the listing's P1 with the new
/// settings in bits 0-191, its desk binding read from the rest (a new listing is unbound).
function _checkSettings(uint256 s0, uint256 s1, uint256 w10) internal view {
PropAMMStore.Layout storage $ = PropAMMStore.state();
uint256 ceil = s1.ceil();
uint256 min = s1.minFill();
if (
s1.fence(true) > ceil || s1.fence(false) > ceil || ceil > MAX_FENCE_PPM || s1.confMul() > MAX_CONF_MUL
|| s1.maxAgeMs() > AGE_CEIL_MS
|| s1.rateCeil(true) == 0 || s1.rateCeil(false) == 0 || s1.burstCeil(true) == 0
|| s1.burstCeil(false) == 0 || s1.splitDepth() > 10 || min > type(uint128).max || min == 0
|| (
s1.desk() != 0 && W.printed(s1.fenceKind())
&& min < _srcFloor($, $.pairs[s0.sPairId()].cfg, w10)
)
) revert OutsideCeiling();
}
}
/// @notice Ethereum's builder build's admin: desk listings, pull checks as sources.
contract PropAMMAdminRegistry is PropAMMAdmin {
/// @param c The build's fixed inputs, which {PropAMMAdmin}'s constructor checks.
constructor(Config memory c) PropAMMAdmin(c) {}
/// @dev `LANE_KIND` 0: Ethereum's builder build.
function _laneKind() internal pure override returns (uint256) {
return 0;
}
/// @dev Its cold part: `PropAMMAdminColdRegistry`.
function _cold(Config memory c) internal override returns (address) {
return address(new PropAMMAdminColdRegistry(c.ageCeilMs, c.authorityCodehash));
}
}
/// @notice The storage build's admin (Base, Arbitrum One, Robinhood, HyperEVM): stored price lanes as sources, the
/// desks' storage cells; no registry.
contract PropAMMAdminStorage is PropAMMAdmin {
/// @param c The build's fixed inputs, which {PropAMMAdmin}'s constructor checks.
constructor(Config memory c) PropAMMAdmin(c) {}
/// @dev `LANE_KIND` 1: the storage build.
function _laneKind() internal pure override returns (uint256) {
return 1;
}
/// @dev Its cold part: `PropAMMAdminColdStorage`.
function _cold(Config memory c) internal override returns (address) {
return address(new PropAMMAdminColdStorage(c.ageCeilMs, c.authorityCodehash));
}
}
/// @notice BNB Chain's builder build's admin: desk listings, pull checks as sources.
contract PropAMMAdminBnb is PropAMMAdmin {
/// @param c The build's fixed inputs, which {PropAMMAdmin}'s constructor checks.
constructor(Config memory c) PropAMMAdmin(c) {}
/// @dev `LANE_KIND` 2: BNB Chain's builder build.
function _laneKind() internal pure override returns (uint256) {
return 2;
}
/// @dev Its cold part: `PropAMMAdminColdBnb`.
function _cold(Config memory c) internal override returns (address) {
return address(new PropAMMAdminColdBnb(c.ageCeilMs, c.authorityCodehash));
}
}
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.