Verified contractExactUNLICENSED
DelayedAuthority
Address0xcde92c0be2b5f9faa2eef21987b6f098ef29f1af
- Balance
0 ETH
- Transactions
1
- 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,499,742
- Creation transaction
- 0x8f31ede981…5d6c887946
- Libraries
- src/core/mm/MMRouterLib.sol:MMRouterLib0x95b3…48ef2csrc/core/flamm/FLAMMLane.sol:FLAMMLane0x5d81…90de37src/core/flamm/FLAMMRoute.sol:FLAMMRoute0xb1ff…7fb0fesrc/periphery/FLAMMMaxima.sol:FLAMMMaxima0x6854…90a91bsrc/core/flamm/FLAMMLawLib.sol:FLAMMLawLib0xf55c…49cf45src/core/flamm/FLAMMOpsLib.sol:FLAMMOpsLib0x0be7…5ecc47src/core/mm/AaveV3ReadsLib.sol:AaveV3ReadsLib0xa5db…72803esrc/core/flamm/FLAMMFlowLib.sol:FLAMMFlowLib0x2795…4cfb77src/core/flamm/FLAMMGateLib.sol:FLAMMGateLib0x3a05…434368src/core/flamm/FLAMMKeptLib.sol:FLAMMKeptLib0x70ca…60bee4src/core/mm/CTokenMarketLib.sol:CTokenMarketLib0x60e4…314010src/core/flamm/FLAMMAdmitLib.sol:FLAMMAdmitLib0x0b10…1ce950src/core/flamm/FLAMMBlindLib.sol:FLAMMBlindLib0x634d…298fcdsrc/core/flamm/FLAMMClaimLib.sol:FLAMMClaimLib0x5dc3…aa7e91src/core/flamm/FLAMMFenceLib.sol:FLAMMFenceLib0x9dbb…798f1asrc/core/flamm/FLAMMFloatLib.sol:FLAMMFloatLib0x6b2b…518935src/core/flamm/FLAMMQuoteLib.sol:FLAMMQuoteLib0x99de…929869src/core/flamm/FLAMMTopUpLib.sol:FLAMMTopUpLib0xe4be…cfac2esrc/core/mm/CTokenRewardsLib.sol:CTokenRewardsLib0x93ab…262861src/core/mm/MMRouterAdminLib.sol:MMRouterAdminLib0x6abb…60ea7esrc/core/flamm/FLAMMPolicyLib.sol:FLAMMPolicyLib0x3858…f91f06src/core/flamm/FLAMMSettleLib.sol:FLAMMSettleLib0x4551…33b301src/core/flamm/FLAMMSharedLib.sol:FLAMMSharedLib0xb852…b71005src/periphery/FLAMMExitMaxima.sol:FLAMMExitMaxima0x6a6a…798659src/hooks/everlong/LeverageLib.sol:LeverageLib0x8039…16d055src/core/flamm/FLAMMMaintainLib.sol:FLAMMMaintainLib0xaa54…b56417src/core/flamm/FLAMMPairQuoteLib.sol:FLAMMPairQuoteLib0x3bc5…2055ddsrc/hooks/everlong/EverlongOpsLib.sol:EverlongOpsLib0xf6d5…9dfeef
6 files
src/propamm/DelayedAuthority.sol
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IDepositAllowlist} from "src/interfaces/core/IDepositAllowlist.sol";
import {POOL_DELAY_FLOOR_SEC, CHANGE_WINDOW_SEC} from "src/libraries/Constants.sol";
import {DelayLib} from "src/libraries/DelayLib.sol";
/// @notice What an authority reads of its PropAMM front: the front's protocol keys, none of which may be its guardian.
interface IFrontKeys {
/// @notice The front's owner, its timelock.
function owner() external view returns (address);
/// @notice The protocol owner, who acts on the front without the timelock.
function instantOwner() external view returns (address);
/// @notice The front's protocol guardian.
function protocolGuardian() external view returns (address);
}
/// @notice One pool's authority record and depositor allowlist, bound as both its core and its allowlist: as
/// `EverlongCore` and `DepositAllowlist`, except that three changes wait `DELAY`, the authority's delay, at
/// least the pool's `governanceDelaySec` at launch and at least 1 hour: a new owner (the pool's operator), a new
/// guardian and the list's disable. Readers reach the record through `IEverlongCore`, which its getters answer.
/// @dev The rules of the record:
/// - Schedules: the owner schedules each change; once due and within `EXECUTION_WINDOW_SEC` after, the scheduled
/// owner takes office (`acceptOwnership`) and anyone executes the other two; a schedule not run in its window
/// lapses, reads as none (its getters answer zero) and is scheduled again with its full delay. Each is one
/// entry of `DelayLib`'s table, under `OWNER_CHANGE`, `GUARDIAN_CHANGE` or `DISABLE_CHANGE`, its tag the
/// scheduled owner or guardian: a schedule logs `DelayLib.ChangeScheduled` (its data the scheduled address,
/// none for the disable), a cancel or a dropped disable `DelayLib.ChangeCancelled`, and an execute or accept
/// out of turn reverts `DelayLib.NotScheduled`, `DelayLib.NotDue` or `DelayLib.Lapsed`.
/// - Cancels: only the owner cancels the guardian's rotation, so a guardian being replaced cannot keep itself in
/// place; the owner or the guardian cancels an owner's transfer or the disable. No protocol role takes part in
/// any of them.
/// - Instant: the keeper, the fee receiver, naming or dropping a depositor, and enabling the list; enabling drops
/// a scheduled disable.
/// - The list is born enabled; disabled means everyone may deposit. Ownership is never renounced.
/// - Protocol keys: a protocol key of the authority's front (`front`: the front itself, its owner the timelock,
/// the protocol owner or its protocol guardian) is refused as the guardian at birth and at each rotation's
/// schedule (`ProtocolKey`), so no protocol role is handed a pool's guardian powers, its veto of an operator
/// change among them. The test runs at those two points and at `launch`: a guardian the front names as a key
/// later stays in office here, and one it names between a rotation's schedule and its execute takes office.
/// - No immutable: every authority runs one runtime code, whose hash the PropAMM front pins when it confirms a
/// pool (`confirmPool`), with `DELAY` at least the pool's `governanceDelaySec` and no guardian or owner change
/// standing.
contract DelayedAuthority is Ownable, IDepositAllowlist {
/// @notice The least `DELAY` an authority may take, core's minimum `governanceDelaySec`.
uint32 public constant MIN_DELAY_SEC = POOL_DELAY_FLOOR_SEC;
/// @notice How long after its due time a schedule may run, seconds; past it the schedule lapses.
uint32 public constant EXECUTION_WINDOW_SEC = CHANGE_WINDOW_SEC;
/// @notice The owner's transfer's id in `DelayLib`'s table, the id its logs and reverts carry.
bytes32 public constant OWNER_CHANGE = keccak256("DelayedAuthority.owner");
/// @notice The guardian's rotation's id in `DelayLib`'s table.
bytes32 public constant GUARDIAN_CHANGE = keccak256("DelayedAuthority.guardian");
/// @notice The list's disable's id in `DelayLib`'s table.
bytes32 public constant DISABLE_CHANGE = keccak256("DelayedAuthority.disable");
/// @notice The authority's delay, seconds, set at construction and never changed.
// forge-lint: disable-next-line(mixed-case-variable)
uint32 public DELAY;
/// @notice The pool's guardian; zero for none.
address public guardian;
/// @notice The pool's keeper, the owner's to set at once.
address public keeper;
/// @notice The pool's fee receiver, never zero, the owner's to set at once.
address public feeReceiver;
/// @notice The PropAMM front whose protocol keys this authority's guardian may never be, set at construction and
/// never changed; zero checks none (an authority no launcher built, which no front confirms through one).
address public front;
/// @notice Whether the list names `depositor`.
mapping(address depositor => bool) public isDepositorAllowed;
/// @notice Whether the list is on; off, everyone may deposit.
bool public enabled;
/// @notice Whether the list has ever named a depositor other than the owner of the day, or been disabled: once
/// set, never cleared, so its pool's front treats the pool as one others may hold, whose loosenings wait
/// its `governanceDelaySec`. Read with the shares by the front's quiet test (`PropAMMQuiet`).
bool public opened;
/// @notice `guardian` took office, at construction or by `executeGuardian`.
event GuardianSet(address indexed guardian);
/// @notice The keeper was set, at construction or by `setKeeper`.
event KeeperSet(address indexed keeper);
/// @notice The fee receiver was set, at construction or by `setFeeReceiver`.
event FeeReceiverSet(address indexed feeReceiver);
/// @notice OpenZeppelin's two-step event, logged beside the transfer's `DelayLib.ChangeScheduled` so standard
/// tooling sees a transfer from its schedule on; a cancel logs it with zero, as OpenZeppelin's own cancel
/// does.
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/// @notice `renounceOwnership`, on every call.
error OwnershipCannotBeRenounced();
/// @notice A construction with a delay under `MIN_DELAY_SEC`.
error InvalidDelay();
/// @notice A call that would make a delayed change at once: `setGuardian`, or `setEnabled(false)`.
error Delayed();
/// @notice A cancel from neither the owner nor the guardian.
error NotOwnerOrGuardian();
/// @notice `acceptOwnership` from any caller but the scheduled owner.
error NotPendingOwner();
/// @notice A guardian that is one of the front's protocol keys (`protocolKey`).
error ProtocolKey();
/// @param owner_ The pool's operator, never zero.
/// @param guardian_ The pool's guardian, zero for none, never a protocol key of `front_`.
/// @param keeper_ The pool's keeper.
/// @param feeReceiver_ The pool's fee receiver, never zero.
/// @param delaySec The authority's delay, seconds, at least `MIN_DELAY_SEC`.
/// @param front_ The PropAMM front whose protocol keys the guardian may never be; zero checks none.
constructor(
address owner_,
address guardian_,
address keeper_,
address feeReceiver_,
uint32 delaySec,
address front_
) {
if (owner_ == address(0) || feeReceiver_ == address(0)) revert ZeroAddress();
if (delaySec < MIN_DELAY_SEC) revert InvalidDelay();
_transferOwnership(owner_);
DELAY = delaySec;
front = front_;
if (protocolKey(guardian_)) revert ProtocolKey();
guardian = guardian_;
keeper = keeper_;
feeReceiver = feeReceiver_;
enabled = true;
emit GuardianSet(guardian_);
emit KeeperSet(keeper_);
emit FeeReceiverSet(feeReceiver_);
emit AllowlistEnabledSet(true);
}
// ------------------------------------------------------------------ the owner, after the delay
/// @notice Schedules `owner_` as the owner for `DELAY` from now; a rescheduling replaces the pending one and
/// restarts it. The scheduled owner takes office with `acceptOwnership`, once due and within its window;
/// zero is refused (`cancelOwnership` drops a transfer).
/// @dev While it is scheduled and after:
/// - Until it accepts nothing moves: the owner keeps every power it holds as the pool's operator, here (the
/// keeper, the fee receiver, depositors and enabling the list at once; the guardian's and the disable's
/// schedules; this transfer's rescheduling or cancel), at the pool (its operator's calls) and at the front
/// (its listings' keys, settings, credit modes, freezes, unpauses and retirement), and the
/// scheduled owner holds none.
/// - What the owner set survives the accept, for the new owner to replace or cancel: the listings' maker keys,
/// the keeper, the fee receiver and every change it scheduled.
/// - Depositors read the scheduled change on chain from the schedule on (`pendingOwner`, `ownerDueAt`,
/// `DelayLib.ChangeScheduled` under `OWNER_CHANGE` and OpenZeppelin's `OwnershipTransferStarted`), `DELAY`
/// before the new operator can act.
function transferOwnership(address owner_) public override onlyOwner {
if (owner_ == address(0)) revert ZeroAddress();
DelayLib.schedule(DelayLib.table(), OWNER_CHANGE, uint160(owner_), DELAY, abi.encode(owner_));
emit OwnershipTransferStarted(owner(), owner_);
}
/// @notice The scheduled owner takes office, once due and within `EXECUTION_WINDOW_SEC` after. Anyone else, and
/// everyone where none is scheduled, is refused `NotPendingOwner`; a lapsed schedule still names its owner,
/// who is refused as lapsed.
function acceptOwnership() external {
mapping(bytes32 => uint256) storage t = DelayLib.table();
uint256 e = t[OWNER_CHANGE];
if (e == 0 || msg.sender != address(uint160(e))) revert NotPendingOwner();
DelayLib.take(t, OWNER_CHANGE, EXECUTION_WINDOW_SEC);
// the outgoing owner, if named, becomes another depositor
if (isDepositorAllowed[owner()]) opened = true;
_transferOwnership(msg.sender);
}
/// @notice The owner or the guardian drops the scheduled transfer, lapsed or not.
function cancelOwnership() external {
if (msg.sender != owner() && msg.sender != guardian) revert NotOwnerOrGuardian();
DelayLib.cancel(DelayLib.table(), OWNER_CHANGE);
emit OwnershipTransferStarted(owner(), address(0));
}
// ------------------------------------------------------------------ the guardian, after the delay
/// @notice Refused: the guardian changes through `scheduleGuardian`, then `executeGuardian`.
function setGuardian(address) external pure {
revert Delayed();
}
/// @notice Schedules `guardian_` for `DELAY` from now; a rescheduling replaces the pending one and restarts it.
/// Never one of the front's protocol keys (`ProtocolKey`).
function scheduleGuardian(address guardian_) external onlyOwner {
if (protocolKey(guardian_)) revert ProtocolKey();
DelayLib.schedule(DelayLib.table(), GUARDIAN_CHANGE, uint160(guardian_), DELAY, abi.encode(guardian_));
}
/// @notice Anyone: installs the scheduled guardian, once due and within `EXECUTION_WINDOW_SEC` after.
function executeGuardian() external {
address guardian_ = address(uint160(DelayLib.take(DelayLib.table(), GUARDIAN_CHANGE, EXECUTION_WINDOW_SEC)));
guardian = guardian_;
emit GuardianSet(guardian_);
}
/// @notice Drops the scheduled rotation: the owner's alone, never the guardian's; it also clears a lapsed schedule.
function cancelGuardian() external onlyOwner {
DelayLib.cancel(DelayLib.table(), GUARDIAN_CHANGE);
}
// ------------------------------------------------------------------ instant: keeper, fee receiver, depositors
/// @notice The owner sets the keeper, at once.
function setKeeper(address keeper_) external onlyOwner {
keeper = keeper_;
emit KeeperSet(keeper_);
}
/// @notice The owner sets the fee receiver, at once; zero is refused (`ZeroAddress`).
function setFeeReceiver(address feeReceiver_) external onlyOwner {
if (feeReceiver_ == address(0)) revert ZeroAddress();
feeReceiver = feeReceiver_;
emit FeeReceiverSet(feeReceiver_);
}
/// @notice The owner names or drops a depositor, at once. Naming anyone but the owner of the day sets `opened`.
function setDepositorAllowed(address depositor, bool allowed) external onlyOwner {
isDepositorAllowed[depositor] = allowed;
if (allowed && depositor != owner()) opened = true;
emit DepositorAllowedSet(depositor, allowed);
}
// ------------------------------------------------------------------ the list's disable, after the delay
/// @notice Enables the list at once and drops a scheduled disable. A disable is refused here (`Delayed`): it goes
/// through `scheduleDisable`, then `executeDisable`.
function setEnabled(bool enabled_) external onlyOwner {
if (!enabled_) revert Delayed();
DelayLib.drop(DelayLib.table(), DISABLE_CHANGE);
enabled = true;
emit AllowlistEnabledSet(true);
}
/// @notice Schedules the disable for `DELAY` from now; a rescheduling restarts the delay.
function scheduleDisable() external onlyOwner {
DelayLib.schedule(DelayLib.table(), DISABLE_CHANGE, 0, DELAY, "");
}
/// @notice Anyone: disables the list, once due and within `EXECUTION_WINDOW_SEC` after, and sets `opened`.
function executeDisable() external {
DelayLib.take(DelayLib.table(), DISABLE_CHANGE, EXECUTION_WINDOW_SEC);
enabled = false;
opened = true;
emit AllowlistEnabledSet(false);
}
/// @notice The owner or the guardian drops the scheduled disable, lapsed or not.
function cancelDisable() external {
if (msg.sender != owner() && msg.sender != guardian) revert NotOwnerOrGuardian();
DelayLib.cancel(DelayLib.table(), DISABLE_CHANGE);
}
// ------------------------------------------------------------------ the schedules, a lapsed one read as none
/// @notice The scheduled owner; zero for none or a lapsed one.
function pendingOwner() external view returns (address) {
(uint256 tag,) = _entry(OWNER_CHANGE);
return address(uint160(tag));
}
/// @notice When the scheduled owner may take office; zero for none or a lapsed one.
function ownerDueAt() external view returns (uint64) {
(, uint256 dueAt) = _entry(OWNER_CHANGE);
return uint64(dueAt);
}
/// @notice The scheduled guardian (zero also where the rotation removes the guardian); zero for none or a lapsed
/// one.
function pendingGuardian() external view returns (address) {
(uint256 tag,) = _entry(GUARDIAN_CHANGE);
return address(uint160(tag));
}
/// @notice When anyone may install the scheduled guardian; zero for none or a lapsed one.
function guardianDueAt() external view returns (uint64) {
(, uint256 dueAt) = _entry(GUARDIAN_CHANGE);
return uint64(dueAt);
}
/// @notice When anyone may disable the list; zero for none or a lapsed one.
function disableDueAt() external view returns (uint64) {
(, uint256 dueAt) = _entry(DISABLE_CHANGE);
return uint64(dueAt);
}
/// @notice Whether `who` is one of the front's protocol keys: the front itself, its owner (the timelock), the
/// protocol owner or its protocol guardian, read live. Zero (no guardian) is none, and so is everyone where
/// `front` is zero.
function protocolKey(address who) public view returns (bool) {
address f = front;
if (f == address(0) || who == address(0)) return false;
return who == f || who == IFrontKeys(f).owner() || who == IFrontKeys(f).instantOwner()
|| who == IFrontKeys(f).protocolGuardian();
}
/// @inheritdoc IDepositAllowlist
function isDepositAllowed(address depositor) external view returns (bool) {
return !enabled || isDepositorAllowed[depositor];
}
/// @notice Refused: a pool always has an owner (`OwnershipCannotBeRenounced`).
function renounceOwnership() public pure override {
revert OwnershipCannotBeRenounced();
}
/// @dev The schedule under `id` as its getters read it: its tag and due time, a lapsed one as none.
function _entry(bytes32 id) internal view returns (uint256 tag, uint256 dueAt) {
return DelayLib.entry(DelayLib.table(), id, EXECUTION_WINDOW_SEC);
}
}
lib/openzeppelin-contracts-compat/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts-compat/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
src/interfaces/core/IDepositAllowlist.sol
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;
/// @notice A pool's depositor allowlist: what the pool asks of each deposit, and the events and errors its two
/// implementers share (`DepositAllowlist`, and `DelayedAuthority`, which keeps the list beside the pool's
/// roles).
interface IDepositAllowlist {
/// @notice The curator named or dropped `depositor`.
event DepositorAllowedSet(address indexed depositor, bool allowed);
/// @notice The list was turned on or off.
event AllowlistEnabledSet(bool enabled);
/// @notice The caller is not the pool's curator (`DepositAllowlist`).
error NotOwner();
/// @notice An address that must be set is zero.
error ZeroAddress();
/// @notice Whether `depositor` may deposit: everyone while the list is disabled, else a listed depositor. The
/// list's own views and setters live on its implementers.
function isDepositAllowed(address depositor) external view returns (bool);
}
src/libraries/Constants.sol
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;
// The protocol's shared units and delay values, each written once. A contract that names one of its own (a public
// getter, or a constant other files read through it) declares it as this file's value, at its own type, so a change
// of a value here reaches every rule that shares it, and a rule that must differ changes its own line alone. The
// pool's own delay names keep their literal values, as a constant read through another can compile to other code:
// `DelayLib.GRACE`, `PriceFeed.REPLACE_DELAY`, `FLAMMFactory.MIN_FEE_DELAY_SEC` and the pool store's three
// `MIN_*_DELAY_SEC`. The shared-constants test holds each of them to its value here.
// ---------------------------------------------------------------- units
/// @dev One in 18 decimals: the unit of every `*Wad` ratio, of LTVs, bands, rates and USD prices.
uint256 constant WAD = 1e18;
/// @dev Parts per million: the unit of a rate, a rung's offset and a word's skew.
uint256 constant PPM = 1e6;
/// @dev The first amount past 128 bits: an output cap, and the first amount past a door's grid.
uint256 constant CAP_128 = 1 << 128;
// ---------------------------------------------------------------- delays
/// @dev The least delay a pool may take for its operator's own changes: a pool's `governanceDelaySec` at birth, a
/// launched pool's delay, its authority's delay, and the least a listing's change reads as the pool's own.
uint32 constant POOL_DELAY_FLOOR_SEC = 1 hours;
/// @dev What a protocol-level loosening waits: the front's timelock, a feed's replacement, a protocol fee's rise, a
/// band ceiling's raise, the beacon delay a cheap lane asks for, a credit door's config, and a listing's change
/// where its pool's own delay cannot be read.
uint32 constant PROTOCOL_DELAY_SEC = 10 days;
/// @dev How long a due change stays applicable outside the pool, whose own window is its delay or a day, whichever
/// is longer: past it the change has lapsed.
uint32 constant CHANGE_WINDOW_SEC = 7 days;
src/libraries/DelayLib.sol
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2025-2026 Everlong Labs Limited
pragma solidity ^0.8.26;
/// @notice The clock of a delayed change, one rule for the contracts that use it, `FLAMMFactory` and `PriceFeed` (a
/// pool's own delayed entries keep their table and window, `FLAMMAdmitLib.due`). A change is one entry under
/// an id its contract derives, `keccak256(abi.encode(selector, subject))`: the setter's selector and the token,
/// pool or kind it sets (zero for a contract-wide setting; a setting of several fields adds the field), so a
/// new change of the same setting replaces the last and restarts its delay.
/// The entry keeps a tag, which commits to the value (the value itself where it fits in 192 bits, else
/// {tagOf} of its encoding; a tag is read modulo 2^192), and the time it falls due. It applies only from that
/// time until `GRACE` after it; later it has lapsed, applies no more and reads as none, and the next schedule
/// overwrites it. The scheduler applies a change by repeating the identical call ({stage}); a change anyone may
/// execute is spent by {consume}. Who may schedule, apply and cancel is the calling contract's check: the
/// library keeps the clock, the tag and the log.
/// The clock itself is one rule, {phase}: a change waits until its due time, is due from that second until
/// its window after it, both ends included, and has lapsed from the next second on. The contracts outside a
/// pool that keep a schedule in storage of their own, under their own events, errors and roles, read their
/// verdict there, each with its own window: a listing's changes, `PropAMMDue`; the front's registry path; the
/// stock module's override. `DelayedAuthority` and `PropAMMDoorConfig` keep their schedules as entries here,
/// under these events and errors and their own windows ({entry} and {take}, each with a window): the
/// authority's `EXECUTION_WINDOW_SEC`, and for the door config a window without end, as its scheduled calls
/// never lapse. The entries under `GRACE`, which `FLAMMFactory` and `PriceFeed` keep, and the failed feed's
/// shorter window in `PriceFeed`, keep their own comparisons, so the pool's code is unchanged: {phase} gives
/// the same verdict at every edge of a window.
/// @dev The entry word: tag (bits 0-191) | due time, unix seconds (bits 192-255); zero is none, and a due time is never
/// zero. The table is one mapping in the ERC-7201 namespace `everlong.storage.delay` ({table}), so in every
/// contract that uses it the entry of `id` sits at `keccak256(abi.encode(id, LOCATION))`; a contract may pass
/// another mapping of the same shape instead. Every function is internal: nothing is deployed for it.
library DelayLib {
/// @notice How long a due change stays applicable: one rule for every change.
uint256 internal constant GRACE = 7 days;
/// @dev keccak256(abi.encode(uint256(keccak256("everlong.storage.delay")) - 1)) & ~bytes32(uint256(0xff))
bytes32 internal constant LOCATION = 0x2a4f7cf5e765882922ccc94a8378a7f0a1255cce43305f000a2a2e7c1fb9d500;
/// @dev The entry's tag bits.
uint256 private constant TAG_MASK = (1 << 192) - 1;
/// @notice The clock's verdict on a scheduled change ({phase}): none stands; it waits its due time; it is due,
/// from its due second until its window after it; it has lapsed.
enum Phase {
None,
Waiting,
Due,
Lapsed
}
/// @notice A change scheduled under `id`, applicable from `dueAt` until its window after it: `GRACE` for the entries
/// that keep it, the caller's own window for {entry} and {take}, which the door config's entries never
/// reach, as its scheduled calls never lapse. `data` is the change as its contract encodes it, for
/// readers: the entry keeps only the tag.
event ChangeScheduled(bytes32 indexed id, uint256 dueAt, address indexed by, bytes data);
/// @notice The change under `id` dropped: cancelled, replaced by a tightening that applied at once, or spent
/// unapplied by its contract (`PriceFeed.executeOracle`).
event ChangeCancelled(bytes32 indexed id, address indexed by);
/// @notice No change stands under `id`, or another tag does.
error NotScheduled(bytes32 id);
/// @notice The change under `id` falls due only at `dueAt`.
error NotDue(bytes32 id, uint256 dueAt);
/// @notice The change under `id` passed its window unapplied: `GRACE` ({consume}), or the caller's own ({take}). The
/// door config's entries have no end and never raise it.
error Lapsed(bytes32 id);
/// @dev The namespace's layout: the table, from its base.
struct Table {
mapping(bytes32 => uint256) entries;
}
/// @notice The table in the namespace.
function table() internal pure returns (mapping(bytes32 => uint256) storage t) {
assembly ("memory-safe") {
t.slot := LOCATION
}
}
/// @notice The one clock rule of a delayed change due at `dueAt`, unix seconds (zero: none), which stays
/// applicable for `window` seconds after it: `Waiting` before `dueAt`, `Due` from `dueAt` to
/// `dueAt + window`, both included, `Lapsed` after. A window of `type(uint256).max` never lapses.
function phase(uint256 dueAt, uint256 window) internal view returns (Phase) {
if (dueAt == 0) return Phase.None;
if (block.timestamp < dueAt) return Phase.Waiting;
return block.timestamp - dueAt > window ? Phase.Lapsed : Phase.Due;
}
/// @notice {phase} of `tag` under the entry word `e`, as a table keeps one ({word}): `None` where the word is
/// empty or keeps another tag. `tag` is the entry's own 192 bits.
function phaseOf(uint256 e, uint256 tag, uint256 window) internal view returns (Phase) {
if (e == 0 || e & TAG_MASK != tag) return Phase.None;
return phase(e >> 192, window);
}
/// @notice The entry word of `tag`, 192 bits, due at `dueAt`.
function word(uint256 tag, uint256 dueAt) internal pure returns (uint256) {
return tag | (dueAt << 192);
}
/// @notice The tag of a value too wide for the entry: the top 192 bits of its encoding's hash.
function tagOf(bytes memory data) internal pure returns (uint256) {
return uint256(keccak256(data)) >> 64;
}
/// @notice The change standing under `id`, its tag and due time; a lapsed one, or none, reads (0, 0).
function entry(mapping(bytes32 => uint256) storage t, bytes32 id) internal view returns (uint256 tag, uint256 dueAt) {
uint256 e = t[id];
dueAt = e >> 192;
if (dueAt != 0 && block.timestamp <= dueAt + GRACE) tag = e & TAG_MASK;
else dueAt = 0;
}
/// @notice {entry} under the caller's own `window` in place of `GRACE`.
function entry(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 window)
internal
view
returns (uint256 tag, uint256 dueAt)
{
uint256 e = t[id];
dueAt = e >> 192;
Phase p = phase(dueAt, window);
if (p == Phase.Waiting || p == Phase.Due) tag = e & TAG_MASK;
else dueAt = 0;
}
/// @notice Schedules `tag` under `id` for `delay` from now, replacing whatever stood there; logs `data`. Every
/// caller's delay fits 32 bits of seconds, so the due time fits its 64.
function schedule(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 tag, uint256 delay, bytes memory data)
internal
returns (uint256 dueAt)
{
dueAt = block.timestamp + delay;
t[id] = (tag & TAG_MASK) | (dueAt << 192);
emit ChangeScheduled(id, dueAt, msg.sender, data);
}
/// @notice The identical call's rule: true where `tag` stands under `id`, due and not lapsed, which it clears so
/// the caller applies it now; `NotDue` while that same tag waits; otherwise (none, another tag, or one
/// lapsed) it schedules `tag` for `delay`, replacing what stood, and returns false. So an apply that comes
/// after its change lapsed or was cancelled does not fail: it schedules the change afresh, for the full
/// delay, and applies nothing; the change's applied event, not the call's success, shows it landed.
function stage(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 tag, uint256 delay, bytes memory data)
internal
returns (bool)
{
uint256 e = t[id];
tag &= TAG_MASK;
if (e != 0 && e & TAG_MASK == tag) {
uint256 dueAt = e >> 192;
if (block.timestamp < dueAt) revert NotDue(id, dueAt);
if (block.timestamp <= dueAt + GRACE) {
delete t[id];
return true;
}
}
schedule(t, id, tag, delay, data);
return false;
}
/// @notice An explicit execution of `tag` under `id`: clears it once due and before it lapses, else reverts
/// (`NotScheduled` for none or another tag, `NotDue`, `Lapsed`).
function consume(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 tag) internal {
uint256 e = t[id];
if (e == 0 || e & TAG_MASK != tag & TAG_MASK) revert NotScheduled(id);
uint256 dueAt = e >> 192;
if (block.timestamp < dueAt) revert NotDue(id, dueAt);
if (block.timestamp > dueAt + GRACE) revert Lapsed(id);
delete t[id];
}
/// @notice An explicit execution of whatever stands under `id`, under the caller's `window`: clears it once due
/// and before it lapses, and returns its tag; else reverts (`NotScheduled` for none, `NotDue`, `Lapsed`).
function take(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 window) internal returns (uint256 tag) {
uint256 e = t[id];
if (e == 0) revert NotScheduled(id);
_spend(t, id, e, window);
tag = e & TAG_MASK;
}
/// @dev Clears the entry `e` under `id` where it is due under `window`; `NotDue` earlier, `Lapsed` later.
function _spend(mapping(bytes32 => uint256) storage t, bytes32 id, uint256 e, uint256 window) private {
Phase p = phase(e >> 192, window);
if (p == Phase.Waiting) revert NotDue(id, e >> 192);
if (p != Phase.Due) revert Lapsed(id);
delete t[id];
}
/// @notice Cancels the change under `id`, a lapsed one included; `NotScheduled` where none stands.
function cancel(mapping(bytes32 => uint256) storage t, bytes32 id) internal {
if (t[id] == 0) revert NotScheduled(id);
delete t[id];
emit ChangeCancelled(id, msg.sender);
}
/// @notice A tightening's drop: clears the change under `id` where one stands, logged as a cancel.
function drop(mapping(bytes32 => uint256) storage t, bytes32 id) internal returns (bool dropped) {
if (t[id] != 0) {
delete t[id];
emit ChangeCancelled(id, msg.sender);
dropped = true;
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {
"src/core/mm/MMRouterLib.sol": {
"MMRouterLib": "0x95b386d242c061ab2551a0d294c94dfe3948ef2c"
},
"src/core/flamm/FLAMMLane.sol": {
"FLAMMLane": "0x5d81d4a7cfd40c3dfe9e009212545608be90de37"
},
"src/core/flamm/FLAMMRoute.sol": {
"FLAMMRoute": "0xb1ffeae12c53f876aa0e495e9c00c829f47fb0fe"
},
"src/periphery/FLAMMMaxima.sol": {
"FLAMMMaxima": "0x68546ce65986354c5394e4bc2f28027ef490a91b"
},
"src/core/flamm/FLAMMLawLib.sol": {
"FLAMMLawLib": "0xf55c5807b6fbe5555443fd6ddbbd52079849cf45"
},
"src/core/flamm/FLAMMOpsLib.sol": {
"FLAMMOpsLib": "0x0be7fdb3d611b05df90a61778a644654735ecc47"
},
"src/core/mm/AaveV3ReadsLib.sol": {
"AaveV3ReadsLib": "0xa5db415d1af2158dd0a4a3c9c1eada277472803e"
},
"src/core/flamm/FLAMMFlowLib.sol": {
"FLAMMFlowLib": "0x27957f4ddf818de39a1c9dba0bf273a5994cfb77"
},
"src/core/flamm/FLAMMGateLib.sol": {
"FLAMMGateLib": "0x3a05779218510235badcbddcdd78732a16434368"
},
"src/core/flamm/FLAMMKeptLib.sol": {
"FLAMMKeptLib": "0x70cace9076ac8dd6a691ced2f9aa62a5c360bee4"
},
"src/core/mm/CTokenMarketLib.sol": {
"CTokenMarketLib": "0x60e4ab6b6ba72325c58924ee7753b14b37314010"
},
"src/core/flamm/FLAMMAdmitLib.sol": {
"FLAMMAdmitLib": "0x0b107b1f0c64f3716554ccc83b53e492e51ce950"
},
"src/core/flamm/FLAMMBlindLib.sol": {
"FLAMMBlindLib": "0x634d5a14c42fb5bec82a7aea32bf636a8d298fcd"
},
"src/core/flamm/FLAMMClaimLib.sol": {
"FLAMMClaimLib": "0x5dc3bb30c60390ce9522b7e3ca315dd334aa7e91"
},
"src/core/flamm/FLAMMFenceLib.sol": {
"FLAMMFenceLib": "0x9dbba0cbd9d7883f4eedd1c8e08780fac4798f1a"
},
"src/core/flamm/FLAMMFloatLib.sol": {
"FLAMMFloatLib": "0x6b2b25ebba12e78afea697b9ac6d2167a6518935"
},
"src/core/flamm/FLAMMQuoteLib.sol": {
"FLAMMQuoteLib": "0x99de54a108c64ebe23ac7766901c199a91929869"
},
"src/core/flamm/FLAMMTopUpLib.sol": {
"FLAMMTopUpLib": "0xe4be161081d1c9aa91951ca347cc99da35cfac2e"
},
"src/core/mm/CTokenRewardsLib.sol": {
"CTokenRewardsLib": "0x93ab647215a9f9f1050302a76506afcbc0262861"
},
"src/core/mm/MMRouterAdminLib.sol": {
"MMRouterAdminLib": "0x6abb06b1e9cba80888992d366913bb9b7760ea7e"
},
"src/core/flamm/FLAMMPolicyLib.sol": {
"FLAMMPolicyLib": "0x3858e2202cebcb6f12f36a596260dd2ed8f91f06"
},
"src/core/flamm/FLAMMSettleLib.sol": {
"FLAMMSettleLib": "0x4551cddb1de95f5452f6a0f836e047e01833b301"
},
"src/core/flamm/FLAMMSharedLib.sol": {
"FLAMMSharedLib": "0xb852d9cbdda85cbed7da0885bca2714ba1b71005"
},
"src/periphery/FLAMMExitMaxima.sol": {
"FLAMMExitMaxima": "0x6a6a3ff1e834dbbf07dee472e07d1ca977798659"
},
"src/hooks/everlong/LeverageLib.sol": {
"LeverageLib": "0x80396f9f894cc3060dfaa7468c4f576e8b16d055"
},
"src/core/flamm/FLAMMMaintainLib.sol": {
"FLAMMMaintainLib": "0xaa5434e13eb54f37c577229efc981cceceb56417"
},
"src/core/flamm/FLAMMPairQuoteLib.sol": {
"FLAMMPairQuoteLib": "0x3bc57bc05cc9dd1fe18106add8ffc060882055dd"
},
"src/hooks/everlong/EverlongOpsLib.sol": {
"EverlongOpsLib": "0xf6d56f4ed6a7c441fd96c53a327026bac19dfeef"
}
},
"optimizer": {
"runs": 100,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable-compat/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts-compat/contracts/",
"forge-std/=lib/forge-std/src/",
"solady/=lib/solady/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.