Skip to content
Verified contractExactUNLICENSED

PropAMMLauncher

Address0x739c3d098d98ffbb6b40a2b40a9a946df0eb5a34
Balance

0.004 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,480,548
Creation transaction
0x6f5660ae4d…a28ae4b2af
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

71 files

The source code is large: one file is shown at a time. Choose a file in the list.

src/propamm/PropAMMLauncher.sol

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

import {SafeTransferLib} from "src/libraries/SafeTransferLib.sol";
import {FLAMMFactory} from "src/factory/FLAMMFactory.sol";
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 {IPropAMMFrontTypes} from "src/propamm/interfaces/IPropAMMFront.sol";
import {PropAMMWords as W} from "src/propamm/libraries/PropAMMWords.sol";
import {DelayedAuthority} from "src/propamm/DelayedAuthority.sol";
import {POOL_DELAY_FLOOR_SEC} from "src/libraries/Constants.sol";

/// @notice The front's registration entries the launcher calls, and its raw storage reads.
interface IFrontLaunch is IPropAMMFrontTypes {
    /// @notice The launcher reserves a pool before its genesis (`PropAMMAdmin.reservePool`).
    function reservePool(address pool, uint32 pairId, PoolInit calldata init) external returns (uint24 poolId);
    /// @notice The launcher confirms a pool after its genesis, its first listing live (`PropAMMAdmin.confirmPool`).
    function confirmPool(uint24 poolId, bool strict, bool creditPath, uint96 outflowCaps, LaneTokens calldata tokens)
        external;
    /// @notice The launcher reserves a further listing in a pool's launch (`PropAMMAdmin.reserveListing`).
    function reserveListing(address pool, uint32 pairId, uint8 baseIndex, uint8 quoteIndex, PoolInit calldata init)
        external
        returns (uint24 listingId);
    /// @notice The launcher makes a reserved further listing live (`PropAMMAdmin.confirmListing`).
    function confirmListing(uint24 listingId) external;
    /// @notice The launcher binds a listing to a desk at its birth (`PropAMMLandingDesk.bindAtBirth`).
    function bindAtBirth(uint24 listing, uint32 desk, uint8 scopes, uint8 wordIndex) external;
    /// @notice The launcher's call for a live pool's further listing (`PropAMMAdmin.addListing`): zero while the
    ///         change is only scheduled.
    function addListing(
        address operator,
        uint24 homeId,
        uint32 pairId,
        uint8 baseIndex,
        uint8 quoteIndex,
        PoolInit calldata init,
        uint256 deskWord
    ) external returns (uint24 listingId);
    /// @notice Raw words of the front's storage.
    function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory);
    /// @notice The launcher sets a listing's first taker tip cap in the block its pool went live
    ///         (`PropAMMAdmin.capAtBirth`).
    function capAtBirth(uint24 listing, uint16 cap) external;
    /// @notice Anyone renews a listing's lease on a builder build (`PropAMMAdminColdBuilder.refreshLease`).
    function refreshLease(uint24 listing) external;
    /// @notice The build's kind: 1 the storage build (`PropAMMAdmin.LANE_KIND`).
    function LANE_KIND() external pure returns (uint256);
}

/// @notice Permit2's signature transfer, as `launchWhole` takes a seed by it.
interface IPermit2 {
    /// @notice The token and the most a signature lets its spender take.
    struct TokenPermissions {
        address token;
        uint256 amount;
    }

    /// @notice What the owner signs: the permission, its nonce and its deadline, for the spender that calls.
    struct PermitTransferFrom {
        TokenPermissions permitted;
        uint256 nonce;
        uint256 deadline;
    }

    /// @notice Where the spender sends the tokens, and how many.
    struct SignatureTransferDetails {
        address to;
        uint256 requestedAmount;
    }

    /// @notice Moves `owner`'s tokens to `transferDetails.to` under `owner`'s signature over `permit` for the caller.
    function permitTransferFrom(
        PermitTransferFrom calldata permit,
        SignatureTransferDetails calldata transferDetails,
        address owner,
        bytes calldata signature
    ) external;
}

/// @notice The front's launcher, fixed at the front's `initialize`: a pool's birth in one transaction, and a live
///         pool's further listing (`addListing`), with the checks the front leaves to it. Open to every operator on
///         every pair: no list of operators or pairs, and no role of the protocol's.
/// @dev D in this file is the pool's `governanceDelaySec`.
///      - The deposit: every listing carries a refundable deposit of `LISTING_DEPOSIT` native wei (the chain's own
///        amount, fixed at construction), its depositor's: it is credited back `REFUND_DELAY` after the listing's
///        retirement is noted (`noteRetired`, `refund`) and paid by a pull (`withdraw`), so one deposit cannot cycle
///        through the front's 2^24 listing ids.
///      - The launch: the operator, owner of the pool's core, calls `launch`: the front reserves the pool's first
///        listing, on its hook pair, and any further listings, one per further pair (a pair holds any number of
///        listings), the factory creates the pool, born paused, with the front as its hook set and the operator's
///        pool-asset seed, and the front confirms the first listing, initialises the pool's cheap lane, then confirms
///        each further listing.
///      - Refused unless the pool is born paused, D lies in [1 hour, 30 days], and its core and its allowlist are one
///        `DelayedAuthority` built here (`newAuthority`), whose `DELAY` lies in [D, 30 days], with no guardian rotation
///        and no owner's transfer scheduled, whose list is on and with no disable scheduled (a lapsed schedule, which
///        cannot run, reads as none), so the pool's guardian and its operator change and its list opens only after D,
///        as every loosening the guardian may cancel.
///      - The pool's price feed is its operator's own choice, never checked here (the protocol's is the off-chain
///        default): what that feed answers, and every loss it causes, falls on that pool's LPs alone. The pool's code
///        is the factory's beacon's, whose upgrades wait their own delay.
///      - The guardian is the operator's own choice at `newAuthority`, never a default and never the protocol's: no
///        protocol key of the front (the front itself, its timelock, the protocol owner or its protocol guardian),
///        which the authority refuses at birth and at each rotation and the launch refuses where its guardian has since
///        become one. The protocol takes no part in guarding any pool and keeps only what spans the front (its listing,
///        under its delisting policy, the pause of every fill, the fee schedules, upgrades). Zero names none: every
///        guardian power, at the pool and at the front, is then the operator's alone.
///      - The authority: built here, its storage is proven as its constructor wrote it; what its owner did with it
///        since, up to the launch, is checked here (the list's state, no guardian rotation or owner's transfer
///        scheduled) and at the front's `confirmPool` (the code, the delay, no guardian or owner change scheduled).
///      - The launcher changes only by an upgrade of the front, possible until its code freezes (`freezeCode`).
///      - A pool on a pair with no price source launches the same way and under the same checks: it borrows only where
///        core allows, on a pool with a band (core takes no borrowing pair, no third token and no performance fee on a
///        pool without one).
contract PropAMMLauncher {
    /// @notice A launcher entry refused, for `reason`.
    /// @dev 1 the caller not the owner of the pool's core; 2 and 3 reserved; 4 not born paused; 5 D outside [1 hour,
    ///      30 days]; 6 reserved; 7 the pool's core not an authority built here, its allowlist another, the authority's
    ///      delay under D or over 30 days, a guardian rotation or an owner's transfer scheduled, or its list off or its
    ///      disable scheduled (a lapsed schedule reads as none); 8 the pool's guardian one of the front's protocol keys
    ///      (the front, its timelock, the protocol owner or its protocol guardian); 9 reserved; 10 a payment other than
    ///      the listings' deposits; 11 a listing's retirement not to note (no deposit, not retired, noted already) or
    ///      its refund not due (not noted, the delay not run, refunded already); 12 a withdrawal the receiver refused;
    ///      13 a zero deposit at construction; 14 a listing's desk at birth naming NONE on a custody-blind pool
    ///      (`DeskInit`); 15 at `launchWhole`, a count of `births` other than the listings', or on a storage build a
    ///      listing given no taker tip cap.
    error Refused(uint8 reason);

    /// @dev The most a launched pool's delay D may be; the least is `POOL_DELAY_FLOOR_SEC`.
    uint32 internal constant MAX_POOL_DELAY = 30 days;
    /// @notice Each listing's refundable deposit, native wei: the chain's own amount, about the same dollar value on
    ///         every chain, never zero.
    uint256 public immutable LISTING_DEPOSIT;
    /// @notice A listing's deposit is refunded this long after its retirement is noted.
    uint256 public constant REFUND_DELAY = 30 days;
    /// @dev The front's namespace base and its pool table (`PropAMMStore`), read through `extSloads`.
    uint256 internal constant FRONT_BASE = 0xca023b73b2185d1ba92ba3c09f7870c56c9bdadd91407b68ebb408947da60b00;
    uint256 internal constant POOLS_INDEX = 18;
    /// @dev The front's `LANE_KIND` on a storage build, where no standing word fills a listing with no taker tip cap.
    uint256 internal constant LANE_STORAGE = 1;
    /// @notice Permit2, at its one address on every chain: `launchWhole` takes a signed seed through it.
    IPermit2 public constant PERMIT2 = IPermit2(0x000000000022D473030F116dDEE9F6B43aC78BA3);

    /// @notice The front this launcher serves.
    IFrontLaunch public immutable FRONT;
    /// @notice The factory that creates the pools.
    FLAMMFactory public immutable FACTORY;
    /// @notice The runtime codehash of the authorities built here; the front's `initialize` requires its own pin to
    ///         equal it, so every authority this launcher builds passes the front's `confirmPool`.
    bytes32 public immutable AUTHORITY_CODEHASH = keccak256(type(DelayedAuthority).runtimeCode);

    /// @notice The pool authorities built here (`newAuthority`): their code, and their storage as the constructor
    ///         wrote it at construction (not at launch: its owner's later moves are checked by `launch`).
    mapping(address => bool) public authorityBuilt;
    /// @notice Each listing's deposit: [0-159] its depositor | [160-223] when its retirement was noted, unix s (0 not
    ///         yet) | [255] refunded.
    mapping(uint24 => uint256) public deposits;
    /// @notice Native wei each account may withdraw (`withdraw`): refunds, and the deposit of an `addListing` that only
    ///         scheduled its listing.
    mapping(address => uint256) public withdrawable;

    /// @notice `newAuthority` built `authority` for `owner`, its delay `delaySec` seconds.
    event AuthorityBuilt(address indexed authority, address indexed owner, address guardian, uint32 delaySec);
    /// @notice A live listing's deposit recorded, `depositor` its owner.
    event ListingDeposited(uint24 indexed listing, address indexed depositor);
    /// @notice `noteRetired` noted a listing's retirement at `at`, unix seconds.
    event ListingRetiredNoted(uint24 indexed listing, uint64 at);
    /// @notice `refund` credited a listing's deposit back to `depositor`.
    event ListingRefunded(uint24 indexed listing, address indexed depositor);
    /// @notice The desk a further listing scheduled here binds at its birth (`addListing`; desk 0 for none), as its
    ///         schedule holds it: the front's change of kind 33 logs a hash, so this is where depositors read the
    ///         scopes the delay gives them to weigh.
    event ListingDeskScheduled(
        uint24 indexed homeId, uint32 indexed pairId, uint32 desk, uint8 scopes, uint8 wordIndex
    );
    /// @notice `withdraw` paid `to` its balance, `amount` native wei.
    event Withdrawn(address indexed to, uint256 amount);

    /// @param front The front, predicted where it is not yet deployed (`PropAMMFrontDeployer.predict`).
    /// @param factory The factory that creates the pools.
    /// @param listingDeposit Each listing's deposit, native wei, never zero.
    constructor(address front, FLAMMFactory factory, uint256 listingDeposit) {
        if (listingDeposit == 0) revert Refused(13);
        LISTING_DEPOSIT = listingDeposit;
        FRONT = IFrontLaunch(front);
        FACTORY = factory;
    }

    /// @notice Builds a pool authority (`DelayedAuthority`) owned by the caller, with `delaySec` its delay and
    ///         `guardian` its guardian, the caller's choice: its own key, a third party's, or zero for none, never one
    ///         of the front's protocol keys (`ProtocolKey`). The one core and allowlist `launch` accepts, for a pool
    ///         whose D is at most `delaySec` (itself at most 30 days). Open to anyone.
    function newAuthority(address guardian, address keeper, address feeReceiver, uint32 delaySec)
        external
        returns (address authority)
    {
        authority = _newAuthority(guardian, keeper, feeReceiver, delaySec);
    }

    /// @dev `newAuthority`'s body: the authority, the caller its owner, recorded as built here and logged.
    function _newAuthority(address guardian, address keeper, address feeReceiver, uint32 delaySec)
        internal
        returns (address authority)
    {
        authority = address(new DelayedAuthority(msg.sender, guardian, keeper, feeReceiver, delaySec, address(FRONT)));
        authorityBuilt[authority] = true;
        emit AuthorityBuilt(authority, msg.sender, guardian, delaySec);
    }

    /// @notice A listing's desk at its birth: the desk (0 for none, the listing then born unbound, to fill once its
    ///         operator binds it, `bindListing`), the binding's scopes and the listing's word index in the desk's cell,
    ///         as `bindListing` takes them. The desk is open and its cold key is the caller, the pool's operator; the
    ///         listing keeps its first key epoch and its maker key. Scopes naming NONE are refused on a custody-blind
    ///         pool (`Refused(14)`, whatever the desk), at a launch and at a further listing's schedule alike, so no
    ///         schedule names a binding that could never apply.
    struct DeskInit {
        /// @dev The desk, 0 for none.
        uint32 desk;
        /// @dev The binding's scopes, as `bindListing` takes them.
        uint8 scopes;
        /// @dev The listing's word index in the desk's cell.
        uint8 wordIndex;
    }

    /// @notice A further listing a pool takes at its birth: the pair, its base and quote tokens' indices in the pool,
    ///         the listing's maker key and settings, and its desk.
    struct ListingInit {
        /// @dev The pair.
        uint32 pairId;
        /// @dev The pair's base token's index in the pool.
        uint8 baseIndex;
        /// @dev The pair's quote token's index in the pool.
        uint8 quoteIndex;
        /// @dev The listing's maker key, settings and credit mode.
        IPropAMMFrontTypes.PoolInit init;
        /// @dev The listing's desk.
        DeskInit desk;
    }

    /// @notice Launches a pool on `pairId`, its first listing (the hook pair), with any further listings. The caller
    ///         approves this contract for the pool-asset seed, pays each listing's deposit, exactly `LISTING_DEPOSIT`
    ///         times the listings, and is recorded as each listing's depositor. Every argument is the operator's
    ///         choice, the pool's price feed among them: no default stands in.
    /// @dev Each listing given a desk is bound to it as it goes live (`bindAtBirth`), so the launch lists it ready to
    ///      fill: the pool is born paused, so until its operator unpauses it only the hook pair's ask fills, and on a
    ///      custody-blind pool nothing does. A listing added after the launch (`addListing`) opens its pair only where
    ///      the pair is on the pool's cheap lane (`lanePairs`, from `tokens` or a later `setLanePairs` opening, which
    ///      resyncs the pairs it opens); on a pair the front did not price at birth it also needs the pool's trade-mask
    ///      opening, the operator's, after D. On a pool born custody-blind (`tokens.custodyBlind`) no listing's desk
    ///      may name NONE: `Refused(14)`, before anything is made.
    /// @param pairId The first listing's pair.
    /// @param init The first listing's maker key, settings and credit mode at the front.
    /// @param strict With `outflowCaps`, the pool's cheap lane at birth.
    /// @param creditPath The pool's own swap of every pair the front prices (the hook pair and each listing's pair), on
    ///        or off at birth (a listing's credit route needs it on; off, only the operator turns it on, after D).
    /// @param outflowCaps With `strict`, the pool's cheap lane at birth.
    /// @param p The factory's parameters (the caller's authority as core and allowlist, its own price feed, born
    ///        paused).
    /// @param salt The caller's salt. The factory creates the pool under `keccak256(abi.encode(msg.sender, salt))`
    ///        (`FACTORY.predictPool(address(this), that, p)` is the pool's address), as the factory's own salt names
    ///        this contract as the creator for every caller: a caller's salts are its own, so no other caller's launch
    ///        reaches the pool address this one predicted, whatever arguments it repeats.
    /// @param venues The pool's venues at birth.
    /// @param listings The further listings, each reserved before the genesis and confirmed after the first.
    /// @param tokens The cheap lane past the hook pair: its pairs, one caps entry per token past token 1 (the pool
    ///        refuses another count) and the drawn-token limit, all zero with no caps entry for a pool of two tokens.
    /// @param desk The first listing's desk.
    /// @return pool The pool.
    /// @return poolId The first listing.
    function launch(
        uint32 pairId,
        IPropAMMFrontTypes.PoolInit calldata init,
        bool strict,
        bool creditPath,
        uint96 outflowCaps,
        FLAMMFactory.PoolParams calldata p,
        bytes32 salt,
        IFLAMM.VenueInit[] calldata venues,
        ListingInit[] calldata listings,
        IPropAMMFrontTypes.LaneTokens calldata tokens,
        DeskInit calldata desk
    ) external payable returns (address pool, uint24 poolId) {
        (pool, poolId,) =
            _launch(pairId, init, strict, creditPath, outflowCaps, p, salt, venues, listings, tokens, desk, false);
    }

    /// @notice The pool's authority at a `launchWhole`, as `newAuthority` takes it: built in the launch, the caller
    ///         its owner.
    struct AuthorityInit {
        /// @dev The pool's guardian, the caller's choice, zero for none, never one of the front's protocol keys.
        address guardian;
        /// @dev The pool's keeper.
        address keeper;
        /// @dev The pool's fee receiver, never zero.
        address feeReceiver;
        /// @dev The authority's delay, seconds, in [D, 30 days].
        uint32 delaySec;
    }

    /// @notice The caller's Permit2 signature for the pool-asset seed at a `launchWhole`: over the pool asset and
    ///         exactly the seed, this launcher its spender. An empty `signature` takes the seed by the caller's
    ///         approval of this contract, as `launch` does.
    struct SeedPermit {
        /// @dev The signature's Permit2 nonce.
        uint256 nonce;
        /// @dev The signature's deadline, unix seconds.
        uint256 deadline;
        /// @dev The signature, empty for none.
        bytes signature;
    }

    /// @notice What a `launchWhole` gives one listing past `launch`'s own: its taker tip cap and its first lease.
    struct ListingBirth {
        /// @dev The listing's taker tip cap as `setTipCap` takes it, the operator's own setting, no default: never 0
        ///      on a storage build; 0 for none on a builder build.
        uint16 tipCap;
        /// @dev Whether the launch renews the listing's lease (`refreshLease`, anyone's): builder builds only, on a
        ///      priced listing whose source confirms its trust; the front's refusal of it refuses the launch.
        bool lease;
    }

    /// @notice `launch` with three of the calls around it, in one: the caller's authority is built here first
    ///         (`newAuthority`'s, from `authority`), the seed may come by a Permit2 signature in place of an approval
    ///         (`permit`), and each listing takes its taker tip cap and, where asked, its first lease (`births`, one
    ///         entry per listing, the first listing's first, then `listings`' in their order). The launch itself is
    ///         `launch`'s, under every check it holds, with the same arguments; the old sequence stays open beside it.
    /// @dev - The authority is this contract's next creation, the caller its owner: `p.core` and `p.allowlist` must
    ///        name it (`Refused(7)`), so the caller predicts it, with the pool's address and its keeper gate's, from
    ///        this contract's nonce. A creation landing first moves it and the call reverts whole, to be sent again.
    ///      - The seed by Permit2 moves from the caller alone, who is the signature's owner: no one else's signature
    ///        is taken, and the caller's serves no other caller.
    ///      - On a storage build no standing word fills a listing with no taker tip cap, so a listing given none is
    ///        refused (`Refused(15)`) before anything is made. The cap is set through the front's `capAtBirth`, which
    ///        takes this contract's call only in the block the pool went live, on a listing with no cap: the launcher
    ///        holds no setting of a listing past its launch. `launch` and `addListing` set none, and their listings'
    ///        operators set it after (`setTipCap`): on a storage build a first cap is a loosening, at once only in the
    ///        block the pool went live while it is quiet, else after the pool's delay D.
    ///      - What stays the operator's own calls, which the pool takes from its core's owner alone: the seed of
    ///        token 1 (`seedLeg`, its shares the caller's) with its approval, a custody-blind pool's idle floor
    ///        (`setIdleFloor`) and the unpause (`setPaused`). So do the desk's opening and its landing (`openDesk`,
    ///        `setDeskLanding`), its cold key's.
    /// @param authority The pool's authority, built here.
    /// @param permit The seed's Permit2 signature, or none.
    /// @param births Each listing's tip cap and lease.
    /// @return built The authority.
    /// @return pool The pool.
    /// @return poolId The first listing.
    function launchWhole(
        AuthorityInit calldata authority,
        SeedPermit calldata permit,
        ListingBirth[] calldata births,
        uint32 pairId,
        IPropAMMFrontTypes.PoolInit calldata init,
        bool strict,
        bool creditPath,
        uint96 outflowCaps,
        FLAMMFactory.PoolParams calldata p,
        bytes32 salt,
        IFLAMM.VenueInit[] calldata venues,
        ListingInit[] calldata listings,
        IPropAMMFrontTypes.LaneTokens calldata tokens,
        DeskInit calldata desk
    ) external payable returns (address built, address pool, uint24 poolId) {
        if (births.length != 1 + listings.length) revert Refused(15);
        if (FRONT.LANE_KIND() == LANE_STORAGE) {
            for (uint256 i; i < births.length; ++i) {
                if (births[i].tipCap == 0) revert Refused(15);
            }
        }
        built = _newAuthority(authority.guardian, authority.keeper, authority.feeReceiver, authority.delaySec);
        if (built != p.core) revert Refused(7);
        bool held = permit.signature.length != 0;
        if (held) {
            // the caller is the signature's owner, this contract its spender and the seed's receiver
            PERMIT2.permitTransferFrom(
                IPermit2.PermitTransferFrom(
                    IPermit2.TokenPermissions(p.poolAsset, p.seedPoolAssets), permit.nonce, permit.deadline
                ),
                IPermit2.SignatureTransferDetails(address(this), p.seedPoolAssets),
                msg.sender,
                permit.signature
            );
        }
        uint24[] memory ids;
        (pool, poolId, ids) =
            _launch(pairId, init, strict, creditPath, outflowCaps, p, salt, venues, listings, tokens, desk, held);
        for (uint256 i; i < births.length; ++i) {
            uint24 id = i == 0 ? poolId : ids[i - 1];
            ListingBirth calldata b = births[i];
            if (b.tipCap != 0) FRONT.capAtBirth(id, b.tipCap);
            if (b.lease) FRONT.refreshLease(id);
        }
    }

    /// @dev `launch`'s body, for `launch` and `launchWhole`: `held` where the seed is in this contract already
    ///      (`launchWhole`'s Permit2 transfer), so it is not pulled again; `ids` the further listings, in their order.
    function _launch(
        uint32 pairId,
        IPropAMMFrontTypes.PoolInit calldata init,
        bool strict,
        bool creditPath,
        uint96 outflowCaps,
        FLAMMFactory.PoolParams calldata p,
        bytes32 salt,
        IFLAMM.VenueInit[] calldata venues,
        ListingInit[] calldata listings,
        IPropAMMFrontTypes.LaneTokens calldata tokens,
        DeskInit calldata desk,
        bool held
    ) internal returns (address pool, uint24 poolId, uint24[] memory ids) {
        uint32 d = p.pool.governanceDelaySec;
        // the caller's salts are its own (`launch`'s `salt`)
        salt = keccak256(abi.encode(msg.sender, salt));
        if (msg.value != LISTING_DEPOSIT * (1 + listings.length)) revert Refused(10);
        if (IEverlongCore(p.core).owner() != msg.sender) revert Refused(1);
        // the law the launch gives the pool, its one input that sets it (`confirmPool`), read before anything is made
        bool blind = tokens.custodyBlind;
        if (blind && _none(desk)) revert Refused(14);
        for (uint256 i; i < listings.length; ++i) {
            if (blind && _none(listings[i].desk)) revert Refused(14);
        }
        if (!p.pool.startPaused) revert Refused(4);
        if (d < POOL_DELAY_FLOOR_SEC || d > MAX_POOL_DELAY) revert Refused(5);
        address core = p.core;
        DelayedAuthority a = DelayedAuthority(core);
        if (!authorityBuilt[core] || p.allowlist != core) revert Refused(7);
        uint32 delay = a.DELAY();
        // no rotation or transfer standing (a lapsed one reads as none and can never run): none can complete inside
        // the launch, whatever the launch's calls run
        if (
            delay < d || delay > MAX_POOL_DELAY || a.guardianDueAt() != 0 || a.ownerDueAt() != 0 || !a.enabled()
                || a.disableDueAt() != 0
        ) revert Refused(7);
        // the authority refused a protocol key at its birth and at each rotation; the front's keys may have moved since
        if (a.protocolKey(a.guardian())) revert Refused(8);
        ids = new uint24[](listings.length);
        {
            address predicted = FACTORY.predictPool(address(this), salt, p);
            poolId = FRONT.reservePool(predicted, pairId, init);
            for (uint256 i; i < listings.length; ++i) {
                ListingInit calldata s = listings[i];
                ids[i] = FRONT.reserveListing(predicted, s.pairId, s.baseIndex, s.quoteIndex, s.init);
            }
        }
        if (!held) SafeTransferLib.safeTransferFrom(p.poolAsset, msg.sender, address(this), p.seedPoolAssets);
        SafeTransferLib.safeApprove(p.poolAsset, address(FACTORY), p.seedPoolAssets);
        address front = address(FRONT);
        pool = FACTORY.createPool(p, IFLAMM.HookSet(front, address(0)), salt, venues);
        // the cheap lane and, right after its birth, its pairs past the hook pair on every pool: the caps array names
        // each token past token 1, so none is left at zero by omission; nothing owed yet, as `initLane` requires
        FRONT.confirmPool(poolId, strict, creditPath, outflowCaps, tokens);
        _bind(poolId, desk);
        _deposit(poolId);
        for (uint256 i; i < ids.length; ++i) {
            FRONT.confirmListing(ids[i]);
            _bind(ids[i], listings[i].desk);
            _deposit(ids[i]);
        }
    }

    /// @notice A live pool's further listing, its operator's (the owner of its core, which the front checks): the
    ///         front's `addListing` under its rules (a loosening, so it waits D unless the pool is quiet in the block
    ///         it went live, and applies on the identical call once due), for exactly `LISTING_DEPOSIT`. `desk` is in
    ///         what waits, so one delay covers the listing and its scopes, and another desk, scopes or word index on
    ///         the later call schedules again. Where the front only schedules the listing (it returns 0) the deposit is
    ///         credited to the caller's withdrawable balance and `ListingDeskScheduled` names the desk; else the caller
    ///         is the new listing's depositor and the listing is bound to `desk` where one is given, as at a launch. A
    ///         `desk` naming NONE on a custody-blind pool (`IFLAMMLane.custodyBlind`, read at the pool) is refused,
    ///         `Refused(14)`, at the schedule as at the apply.
    function addListing(
        uint24 homeId,
        uint32 pairId,
        uint8 baseIndex,
        uint8 quoteIndex,
        IPropAMMFrontTypes.PoolInit calldata init,
        DeskInit calldata desk
    ) external payable returns (uint24 listingId) {
        if (msg.value != LISTING_DEPOSIT) revert Refused(10);
        uint256 w = uint256(desk.desk) | (uint256(desk.scopes) << 32) | (uint256(desk.wordIndex) << 40);
        listingId = FRONT.addListing(msg.sender, homeId, pairId, baseIndex, quoteIndex, init, w);
        // the pool's law read live once the front has taken the call (the home listing live, its operator the caller),
        // at the schedule, where no binding runs, as at the apply
        if (_none(desk) && IFLAMMLane(address(uint160(_frontWord(_poolSlot(homeId))))).custodyBlind()) {
            revert Refused(14);
        }
        if (listingId == 0) {
            withdrawable[msg.sender] += LISTING_DEPOSIT;
            emit ListingDeskScheduled(homeId, pairId, desk.desk, desk.scopes, desk.wordIndex);
        } else {
            _bind(listingId, desk);
            _deposit(listingId);
        }
    }

    /// @dev Binds a live listing to its desk at its birth, where one is given.
    function _bind(uint24 listing, DeskInit calldata d) internal {
        if (d.desk != 0) FRONT.bindAtBirth(listing, d.desk, d.scopes, d.wordIndex);
    }

    /// @dev Whether a desk at birth names NONE, the fence kind in its scopes' bits 1-2 (`bindListing`'s layout).
    function _none(DeskInit calldata d) internal pure returns (bool) {
        return (d.scopes >> 1) & 3 == W.FENCE_NONE;
    }

    /// @dev The first word of a listing's record at the front (its P0: the pool in bits 0-159, its flags from 192).
    function _poolSlot(uint24 listing) internal pure returns (uint256) {
        return uint256(keccak256(abi.encode(uint256(listing), FRONT_BASE + POOLS_INDEX)));
    }

    /// @notice Anyone notes a deposited listing's retirement, once: the listing reads retired at the front (its live
    ///         bit clear and its board words nonzero, so a listing reserved and never confirmed does not count).
    function noteRetired(uint24 listing) external {
        uint256 d = deposits[listing];
        uint256 slot = _poolSlot(listing);
        if (
            d == 0 || (d >> 160) & type(uint64).max != 0 || (_frontWord(slot) >> 192) & 1 != 0
                || _frontWord(slot + 8) == 0
        ) revert Refused(11);
        deposits[listing] = d | (block.timestamp << 160);
        emit ListingRetiredNoted(listing, uint64(block.timestamp));
    }

    /// @notice Anyone credits a listing's deposit back to its depositor's withdrawable balance, once, `REFUND_DELAY`
    ///         after its retirement was noted.
    function refund(uint24 listing) external {
        uint256 d = deposits[listing];
        uint256 at = (d >> 160) & type(uint64).max;
        if (d >> 255 != 0 || at == 0 || block.timestamp < at + REFUND_DELAY) revert Refused(11);
        deposits[listing] = d | (uint256(1) << 255);
        address to = address(uint160(d));
        withdrawable[to] += LISTING_DEPOSIT;
        emit ListingRefunded(listing, to);
    }

    /// @notice Pays the caller its withdrawable balance (a pull): zeroed before the send, so a receiver that refuses
    ///         native coin reverts only its own call and blocks no one else.
    function withdraw() external {
        uint256 a = withdrawable[msg.sender];
        withdrawable[msg.sender] = 0;
        (bool ok,) = msg.sender.call{value: a}("");
        if (!ok) revert Refused(12);
        emit Withdrawn(msg.sender, a);
    }

    /// @dev The caller's deposit of `listing`.
    function _deposit(uint24 listing) internal {
        deposits[listing] = uint160(msg.sender);
        emit ListingDeposited(listing, msg.sender);
    }

    /// @dev One raw word of the front's storage.
    function _frontWord(uint256 slot) internal view returns (uint256) {
        bytes32[] memory s = new bytes32[](1);
        s[0] = bytes32(slot);
        return uint256(FRONT.extSloads(s)[0]);
    }
}
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.