Skip to content
Verified contractPartialUNLICENSED

TokenomicsFactoryV24F1

Address0x5d2cda40f29e0bffd6f63d8cb6b0dc7459654eb9
Balance

0 ETH

 

Transactions

7

 

Compiler

solc 0.8.30

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
UNLICENSED
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,399,326
Creation transaction
0x060518f7e7…5f0f810325

84 files

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

src/tokenomics/v24f1/TokenomicsFactoryV24F1.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;

import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

import {TokenomicsLiquidityV23} from "../v23/TokenomicsLiquidityV23.sol";
import {TokenomicsChainParams, ITokenomicsHook, ITokenomicsLocker} from "../ITokenomics.sol";
import {TokenomicsConfigV22} from "../v2/TokenomicsV22Config.sol";
import {TokenomicsLegV24, TokenomicsV24Config} from "../v24/TokenomicsV24Config.sol";
import {TokenomicsV22Gas} from "../v22/ITokenomicsV22.sol";

import {ITokenomicsVaultV24Init} from "../v24/TokenomicsFactoryV24.sol";

/// @notice TK-COOLDOWN (owner 2026-10-29 "EVM tokenomics never queue"): its vault is TokenomicsVaultV24F1 (the swap
///        cooldown `swapCooldown`, default 0, and the impact cap `impactCapBps`, default the pool fee, both this
///        factory's admin's, read live) and its burn module TokenomicsVaultV24BurnModuleF1 (`buyBurnUnrepaid`).
/// @title TokenomicsFactoryV24F1 (HOLDER-MIN-1BPS, owner 2026-11-10): TokenomicsFactoryV24 with ONE change, the
///        holder-reward floor `MIN_HOLDER_BPS` at 1 bps (0.01%) instead of 10, for NEW launches; its `module` is a
///        TokenomicsVaultV24ModuleF1 (setEligibility floor 1 too). Same vault, burn module, adder and swapper code;
///        VERSION_NAME stays "2.4" (same calls, same config hash). Its own CREATE2 salt, so a new address.
///        `diff src/tokenomics/v24/TokenomicsFactoryV24.sol` shows only this. v2.4's notes follow.
/// @notice (v2.4) TokenomicsFactoryV24 (version 2.4: v2.3's factory taking the v2.4 config -- a token per payout
///        wallet, committed by the leg hash (TokenomicsV24Config) -- for TokenomicsVaultV24. v2.3's notes follow.)
/// @notice (v2.3) TokenomicsFactoryV23 (version 2.3)
/// @notice TokenomicsFactoryV22 with v2.3's contracts (TokenomicsVaultV24 and its modules,
///         TokenomicsLiquidityV23, RewardSwapperV23: a vault serves a pool quoted in native, exactly
///         as v2.2, or in a listed ERC-20 such as a tokenized stock) and one more admin setting,
///         `quoteRateCap(quote)`: the most base units of `quote` one native coin may count as when a
///         vault quoted in it repays its operator (the operator names the rate per call; zero: no
///         repay for that quote). Its own salt: a new address on every chain. v2.2's notes follow.
/// v2.2: TokenomicsFactoryV22 (version 2.2)
/// @notice TokenomicsFactoryV21 with the BURN TOKENS bucket (docs/tokenomics-v22-spec.md): the v2.2
///         config (its hash tagged "pangea tokenomics v2.2", each leg's hash with three more fields),
///         the leg rules 14-19 for burn targets, a fifth contract made at `initialize` (the vault's
///         burn module, CREATE 5) and the chain's two v2.2 gas overheads (`gas()`), fixed then for
///         good. The live v2 / v2.1 factories and their vaults are not touched. Everything else is
///         v2.1's; its notes follow (read "the five contracts" for "the four"):
///
/// @notice TokenomicsFactoryV2 with two changes. First, the execute minimum every vault of this factory
///         uses is this factory's `minExecuteWei`, set by its admin (`setMinExecuteWei`) at any
///         time, zero allowed, at most `MAX_MIN_EXECUTE_WEI` -- and read live by the vaults, so a
///         change reaches every existing vault at once. It starts at the chain params' value (zero
///         by default). The live v2 factory and its vaults are not touched.
///
///         Second (owner 2026-10-27, option d), who runs `execute` and what it repays, also the admin's,
///         also read live by every vault:
///           - `execute` is the OPERATOR's (`operator`), and anyone's only once a vault has seen no
///             operator run for `fallbackDelay` (default 7 days, 1 to 90 days); a fallback run is
///             repaid nothing.
///           - the operator is repaid its run's actual gas at the capped price, plus
///             `refundMarginBps` of it (default 1,000 = 10%, at most 5,000), taken pro rata from
///             what the run pays out -- and a run whose refund would exceed `refundCapBps` of what
///             it pays out (default 500 = 5%, at most 1,000) reverts. No fixed 10% reserve.
///           - an operator run with a gas hint of 0 is repaid nothing and checks no cap; with
///             `refundCapBps` at 0 that is the only way the operator can run `execute` (audit TK21-E2
///             L-1). v2.2: at 0, `buyBurn`, `buyRewards` and `rollBurnTargetRepaid` run unrepaid (no
///             revert); above 0 they revert above the cap of what they spend or roll.
/// The v2 notes follow.
///
/// @notice Makes each v2 tokenomics launch's vault on this chain, at an address fixed by its config
///         hash and the same on every EVM chain, and holds the platform's two v2 roles.
///
/// ONE ADDRESS EVERYWHERE (as v1). This factory is deployed through the canonical CREATE2 proxy
/// with the same init code on every chain (its constructor arguments -- the initializer and five
/// code hashes -- are the same everywhere). Its `initialize` then deploys, as its CREATEs 1 to 5:
/// the liquidity adder (TokenomicsLiquidity, v1's code), the vault implementation
/// (TokenomicsVaultV24), the RewardSwapperV23, the vault module (TokenomicsVaultV24Module) and the burn module (TokenomicsVaultV24BurnModule), so they
/// too share one address everywhere while each carries its own chain's wiring. Their creation code
/// comes with the call and must match the hashes fixed in the constructor. A vault is an EIP-1167
/// clone of the implementation at CREATE2 under its config hash (TokenomicsV22Config).
///
/// ROLES. `admin` (two-step hand-over) sets `operator`. Vaults read both from here: the operator
/// buys reward tokens, pays holders and signs holder vouchers; the admin sets the most a native
/// holder payout may charge its holder for gas (`maxFeePerRecipient`, under a cap fixed at
/// initialize), and may change a vault's
/// eligibility settings and recover holders money or unbooked tokens (TokenomicsVaultV24Module); since v2.2 it alone changes or disables a burn target (TokenomicsVaultV24BurnModule).
///
/// ANYONE MAY MAKE A VAULT: its address commits to the whole config.
contract TokenomicsFactoryV24F1 {
    uint256 public constant VERSION = 2;
    /// @notice "2.2": v2.1 plus the BURN TOKENS bucket.
    string public constant VERSION_NAME = "2.4";
    /// @notice The highest execute minimum the admin may set: one native coin, a bound against a
    ///         typo, not a policy.
    uint256 public constant MAX_MIN_EXECUTE_WEI = 1 ether;
    /// @notice The bounds of `fallbackDelay`, `refundMarginBps` and `refundCapBps`.
    uint256 public constant MIN_FALLBACK_DELAY = 1 days;
    uint256 public constant MAX_FALLBACK_DELAY = 90 days;
    uint256 public constant MAX_REFUND_MARGIN_BPS = 5_000;
    uint256 public constant MAX_REFUND_CAP_BPS = 1_000;
    uint256 internal constant BPS = 10_000;
    uint256 public constant MAX_LEGS = 8;
    uint256 public constant MAX_WALLETS = 10;
    uint256 public constant MAX_REWARDS = 5;
    /// @notice v2.2: the most burn targets one leg may name (owner 2026-10-28).
    uint256 public constant MAX_BURN_TARGETS = 5;
    /// @dev The native coin's placeholder some routers use; refused as a burn target (rule 16).
    bytes32 internal constant NATIVE_PLACEHOLDER = bytes32(uint256(uint160(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)));
    /// @notice HOLDER-MIN-1BPS: the lowest `minHolderBps` a config may have (v2.4: 10). Web reads it per factory.
    uint16 public constant MIN_HOLDER_BPS = 1;
    /// @notice TK-COOLDOWN: the bounds of `swapCooldown` (0 to a day) and `impactCapBps` (0 to 5,000): against a typo.
    uint256 public constant MAX_SWAP_COOLDOWN = 1 days;
    uint256 public constant MAX_IMPACT_CAP_BPS = 5_000;

    address public immutable initializer;
    bytes32 public immutable vaultCodeHash;
    bytes32 public immutable moduleCodeHash;
    bytes32 public immutable burnModuleCodeHash;
    bytes32 public immutable liquidityCodeHash;
    bytes32 public immutable swapperCodeHash;

    bool public initialized;
    /// @dev v2.4: `initialize` ran (step 1 of 2); `initializeBurnModule` completes it (EIP-7825: the five
    ///      contracts do not fit one transaction's 16,777,216 gas on every chain any more).
    bool internal _started;
    /// @notice The execute minimum of every vault of this factory, in native wei: what a bucket, or
    ///         the wallets' accrued total, must reach before `execute` spends it. Zero allowed (any
    ///         non-empty one is due). The admin's (`setMinExecuteWei`); read live by the vaults.
    uint256 public minExecuteWei;
    /// @notice How long a vault must go without an operator run before anyone may run `execute`
    ///         (unrepaid). The admin's; read live.
    uint256 public fallbackDelay = 7 days;
    /// @notice What the operator is repaid beyond its run's gas, in bps of that gas's cost. The
    ///         admin's; read live.
    uint256 public refundMarginBps = 1_000;
    /// @notice The most a run may repay its operator, in bps of what the run pays out; a run that
    ///         would repay more reverts. The admin's; read live.
    uint256 public refundCapBps = 500;
    TokenomicsChainParams internal _params;
    address public implementation;
    address public module;
    address public burnModule;
    TokenomicsV22Gas internal _gas;
    address public swapper;
    TokenomicsLiquidityV23 public liquidityAdder;
    /// @notice GAS-REPAY-SWAP (v4: no quote caps): the routers a vault's gas-repay swap may call (quote -> native).
    ///         The admin's (`setRouter`); a vault refuses any other (no repay, the call still runs).
    mapping(address => bool) public isRouter;

    address public admin;
    address public pendingAdmin;
    address public operator;
    /// @notice The most a native holder payout may charge its holder for gas (`payHolders`' fee),
    ///         in wei; set by the admin, never above `maxFeeCap`.
    uint256 public maxFeePerRecipient;
    /// @notice The hard cap on `maxFeePerRecipient`, fixed at `initialize` for good.
    uint256 public maxFeeCap;

    mapping(address => bool) public isVault;

    /// @notice TK-COOLDOWN (owner 2026-10-29 "EVM tokenomics never queue"): the least time between two of a vault's
    ///         buy stages, in seconds, for every vault of this factory. The admin's (`setSwapCooldown`); read live.
    ///         Default 0 (v2.4: a constant 15 minutes): back-to-back executes may each buy.
    uint256 public swapCooldown;
    /// @notice TK-COOLDOWN: the most one execute's swap may move the coin's price, in bps, for every vault of this
    ///         factory. The admin's (`setImpactCapBps`); read live. 0 (the default) = the pool's own fee, v2.4's cap.
    uint256 public impactCapBps;

    event Initialized(address implementation, address module, address burnModule, address swapper, address liquidityAdder, uint32 localEid, uint256 gasOverheadBurn, uint256 gasOverheadRewards, uint256 gasOverheadRoll);
    event VaultCreated(address indexed vault, bytes32 indexed launchId, address indexed owner, bytes32 configHash, bool ownLeg);
    event AdminProposed(address indexed from, address indexed to);
    event AdminChanged(address indexed from, address indexed to);
    event OperatorSet(address indexed from, address indexed to);
    event MaxFeePerRecipientSet(uint256 from, uint256 to);
    event MinExecuteWeiSet(uint256 from, uint256 to);
    event FallbackDelaySet(uint256 from, uint256 to);
    event RefundMarginSet(uint256 from, uint256 to);
    event RefundCapSet(uint256 from, uint256 to);
    event RouterSet(address indexed router, bool on);
    event SwapCooldownSet(uint256 from, uint256 to);
    event ImpactCapSet(uint256 from, uint256 to);

    error NotInitializer();
    error AlreadyInitialized();
    error NotInitialized();
    error ZeroAddress();
    error WiringMismatch();
    error BadParams();
    error WrongCode();
    error DeployFailed();
    error NotAdmin();
    error NotPending();
    error FeeAboveCap(uint256 fee, uint256 cap);
    error MinExecuteAboveCap(uint256 minimum, uint256 cap);
    error OutOfBounds(uint256 value, uint256 lo, uint256 hi);
    // Config rules (web/lib/tokenomics/v2-config.mjs checkConfig).
    error ZeroLaunchId();
    error BadOwner();
    error BadEligibility();
    error BadLegCount(uint256 n);
    error LegsNotAscending(uint32 eid);
    error LegHashMismatch(uint32 eid);
    error BadLeg(uint32 eid, uint256 rule);

    constructor(
        address initializer_,
        bytes32 vaultCodeHash_,
        bytes32 moduleCodeHash_,
        bytes32 burnModuleCodeHash_,
        bytes32 liquidityCodeHash_,
        bytes32 swapperCodeHash_
    ) {
        if (initializer_ == address(0)) revert ZeroAddress();
        initializer = initializer_;
        vaultCodeHash = vaultCodeHash_;
        moduleCodeHash = moduleCodeHash_;
        burnModuleCodeHash = burnModuleCodeHash_;
        liquidityCodeHash = liquidityCodeHash_;
        swapperCodeHash = swapperCodeHash_;
    }

    /// @notice The five creation codes `initialize` deploys (hashes fixed in the constructor).
    struct Codes {
        bytes vault;
        bytes module;
        bytes burnModule;
        bytes liquidity;
        bytes swapper;
    }

    /// @notice Fix this chain's wiring, its v2.2 gas overheads and the two roles, and deploy the
    ///         adder, the implementation, the swapper, the module and the burn module (CREATEs 1-5).
    ///         Once, by `initializer`. The wiring is checked against itself as v1 does.
    function initialize(
        TokenomicsChainParams calldata p,
        TokenomicsV22Gas calldata g,
        address admin_,
        address operator_,
        uint256 maxFeeCap_,
        Codes calldata k
    ) external {
        if (msg.sender != initializer) revert NotInitializer();
        if (initialized || _started) revert AlreadyInitialized();
        if (
            keccak256(k.vault) != vaultCodeHash || keccak256(k.module) != moduleCodeHash
                || keccak256(k.burnModule) != burnModuleCodeHash || keccak256(k.liquidity) != liquidityCodeHash
                || keccak256(k.swapper) != swapperCodeHash
        ) revert WrongCode();
        if (
            p.poolManager == address(0) || p.hook == address(0) || p.locker == address(0) || p.collector == address(0)
                || admin_ == address(0) || operator_ == address(0)
        ) revert ZeroAddress();
        if (
            address(ITokenomicsHook(p.hook).poolManager()) != p.poolManager || ITokenomicsHook(p.hook).locker() != p.locker
                || address(ITokenomicsLocker(p.locker).poolManager()) != p.poolManager
                || ITokenomicsHook(p.hook).devBuyer() != p.collector
        ) revert WiringMismatch();
        // v2.1: a zero minimum is allowed (the owner's default); one above the cap is a typo.
        if (p.localEid == 0 || p.maxGasUnits == 0 || maxFeeCap_ == 0) revert BadParams();
        if (g.burn > p.maxGasUnits || g.rewards > p.maxGasUnits || g.roll > p.maxGasUnits) revert BadParams();
        if (p.minExecuteWei > MAX_MIN_EXECUTE_WEI) revert MinExecuteAboveCap(p.minExecuteWei, MAX_MIN_EXECUTE_WEI);

        _started = true; // initialized: at initializeBurnModule (step 2)
        _params = p;
        _gas = g;
        admin = admin_;
        operator = operator_;
        // The fee starts at the cap; the admin may lower it (or raise it back to the cap).
        maxFeeCap = maxFeeCap_;
        maxFeePerRecipient = maxFeeCap_;
        minExecuteWei = p.minExecuteWei;
        address adder = _create(bytes.concat(k.liquidity, abi.encode(p.poolManager, address(this))));
        address swapperAt = _createdAt(3);
        address moduleAt = _createdAt(4);
        address burnAt = _createdAt(5);
        TokenomicsV22Gas memory gm = g;
        address impl = _create(bytes.concat(k.vault, abi.encode(p, adder, swapperAt, gm, moduleAt)));
        address sw = _create(bytes.concat(k.swapper, abi.encode(address(this))));
        address mod = _create(bytes.concat(k.module, abi.encode(p, adder, sw, gm, burnAt)));
        if (sw != swapperAt || mod != moduleAt) revert DeployFailed();
        liquidityAdder = TokenomicsLiquidityV23(payable(adder));
        implementation = impl;
        swapper = sw;
        module = mod;
        emit AdminChanged(address(0), admin_);
        emit OperatorSet(address(0), operator_);
        emit MaxFeePerRecipientSet(0, maxFeeCap_);
        emit MinExecuteWeiSet(0, p.minExecuteWei);
        emit FallbackDelaySet(0, fallbackDelay);
        emit RefundMarginSet(0, refundMarginBps);
        emit RefundCapSet(0, refundCapBps);
    }

    /// @notice v2.4, step 2 of 2 (the initializer): deploy the burn module at the address the module and
    ///         the implementation were made with (CREATE nonce 5) and open the factory. Until then no vault
    ///         can be made (`predict` refuses: NotInitialized).
    function initializeBurnModule(bytes calldata burnModuleCode) external {
        if (msg.sender != initializer) revert NotInitializer();
        if (initialized) revert AlreadyInitialized();
        if (!_started) revert NotInitialized();
        if (keccak256(burnModuleCode) != burnModuleCodeHash) revert WrongCode();
        TokenomicsChainParams memory p = _params;
        TokenomicsV22Gas memory g = _gas;
        address bm = _create(bytes.concat(burnModuleCode, abi.encode(p, address(liquidityAdder), swapper, g)));
        if (bm != _createdAt(5)) revert DeployFailed();
        burnModule = bm;
        initialized = true;
        emit Initialized(implementation, module, bm, swapper, address(liquidityAdder), p.localEid, g.burn, g.rewards, g.roll);
    }

    function _create(bytes memory initCode) internal returns (address a) {
        assembly ("memory-safe") {
            a := create(0, add(initCode, 0x20), mload(initCode))
        }
        if (a == address(0)) revert DeployFailed();
    }

    /// @dev This contract's CREATE address at `nonce` (1..127).
    function _createdAt(uint256 nonce) internal view returns (address) {
        return address(uint160(uint256(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), address(this), uint8(nonce))))));
    }

    /// @notice This chain's wiring, with `minExecuteWei` the LIVE minimum (what the vaults use).
    function params() external view returns (TokenomicsChainParams memory p) {
        p = _params;
        p.minExecuteWei = minExecuteWei;
    }

    /// @notice v2.2: the gas overheads `buyBurn`, `buyRewards` and `rollBurnTargetRepaid` add to what they measure.
    function gas() external view returns (TokenomicsV22Gas memory) {
        return _gas;
    }

    // ------------------------------------------------------------------------------ roles

    function proposeAdmin(address to) external {
        if (msg.sender != admin) revert NotAdmin();
        if (to == address(0)) revert ZeroAddress();
        pendingAdmin = to;
        emit AdminProposed(admin, to);
    }

    function acceptAdmin() external {
        if (msg.sender != pendingAdmin) revert NotPending();
        emit AdminChanged(admin, msg.sender);
        admin = msg.sender;
        pendingAdmin = address(0);
    }

    /// @notice The most a native holder payout may charge its holder for gas. The admin; never
    ///         above `maxFeeCap`.
    function setMaxFeePerRecipient(uint256 fee) external {
        if (msg.sender != admin) revert NotAdmin();
        if (fee > maxFeeCap) revert FeeAboveCap(fee, maxFeeCap);
        emit MaxFeePerRecipientSet(maxFeePerRecipient, fee);
        maxFeePerRecipient = fee;
    }

    /// @notice Set the execute minimum of every vault of this factory, at once. The admin; zero
    ///         allowed, at most `MAX_MIN_EXECUTE_WEI`.
    function setMinExecuteWei(uint256 minimum) external {
        if (msg.sender != admin) revert NotAdmin();
        if (minimum > MAX_MIN_EXECUTE_WEI) revert MinExecuteAboveCap(minimum, MAX_MIN_EXECUTE_WEI);
        emit MinExecuteWeiSet(minExecuteWei, minimum);
        minExecuteWei = minimum;
    }

    /// @notice How long a vault waits without an operator run before anyone may execute it,
    ///         unrepaid. The admin; 1 to 90 days.
    function setFallbackDelay(uint256 delay) external {
        if (msg.sender != admin) revert NotAdmin();
        if (delay < MIN_FALLBACK_DELAY || delay > MAX_FALLBACK_DELAY) revert OutOfBounds(delay, MIN_FALLBACK_DELAY, MAX_FALLBACK_DELAY);
        emit FallbackDelaySet(fallbackDelay, delay);
        fallbackDelay = delay;
    }

    /// @notice The operator's refund margin over its run's gas cost, in bps. The admin; 0 to 5,000.
    function setRefundMarginBps(uint256 bps) external {
        if (msg.sender != admin) revert NotAdmin();
        if (bps > MAX_REFUND_MARGIN_BPS) revert OutOfBounds(bps, 0, MAX_REFUND_MARGIN_BPS);
        emit RefundMarginSet(refundMarginBps, bps);
        refundMarginBps = bps;
    }

    /// @notice The most a run may repay, in bps of what it pays out (execute) or spends / rolls (the
    ///         v2.2 buys and the repaid roll). The admin; 0 to 1,000. At 0 a repaid `execute` reverts
    ///         and the operator runs it unrepaid (gas hint 0), while `buyBurn`, `buyRewards` and
    ///         `rollBurnTargetRepaid` run unrepaid without reverting.
    function setRefundCapBps(uint256 bps) external {
        if (msg.sender != admin) revert NotAdmin();
        if (bps > MAX_REFUND_CAP_BPS) revert OutOfBounds(bps, 0, MAX_REFUND_CAP_BPS);
        emit RefundCapSet(refundCapBps, bps);
        refundCapBps = bps;
    }

    /// @notice GAS-REPAY-SWAP: allow (or remove) a router for the vaults' quote -> native gas-repay swaps. The admin.
    function setRouter(address router, bool on) external {
        if (msg.sender != admin) revert NotAdmin();
        if (router == address(0)) revert ZeroAddress();
        isRouter[router] = on;
        emit RouterSet(router, on);
    }

    /// @notice GAS-REPAY-SWAP: this factory's vaults repay an ERC-20 quote's gas by a swap to native (no rate cap).
    function repayBySwap() external pure returns (bool) {
        return true;
    }

    /// @notice TK-COOLDOWN: the swap cooldown of every vault of this factory, at once. The admin; 0 to a day.
    function setSwapCooldown(uint256 seconds_) external {
        if (msg.sender != admin) revert NotAdmin();
        if (seconds_ > MAX_SWAP_COOLDOWN) revert OutOfBounds(seconds_, 0, MAX_SWAP_COOLDOWN);
        emit SwapCooldownSet(swapCooldown, seconds_);
        swapCooldown = seconds_;
    }

    /// @notice TK-COOLDOWN: the buy stage's price-impact cap of every vault of this factory, in bps, at once. The
    ///         admin; 0 (the pool's fee) to 5,000.
    function setImpactCapBps(uint256 bps) external {
        if (msg.sender != admin) revert NotAdmin();
        if (bps > MAX_IMPACT_CAP_BPS) revert OutOfBounds(bps, 0, MAX_IMPACT_CAP_BPS);
        emit ImpactCapSet(impactCapBps, bps);
        impactCapBps = bps;
    }

    function setOperator(address to) external {
        if (msg.sender != admin) revert NotAdmin();
        if (to == address(0)) revert ZeroAddress();
        emit OperatorSet(operator, to);
        operator = to;
    }

    // ------------------------------------------------------------------------------ vaults

    function configHash(TokenomicsConfigV22 calldata c) public pure returns (bytes32) {
        return TokenomicsV24Config.configHash(c);
    }

    function legHash(TokenomicsLegV24 calldata l) external pure returns (bytes32) {
        return TokenomicsV24Config.legHash(l);
    }

    /// @notice Where the vault for `c` is, or will be, on this chain -- and on every other EVM one.
    function predict(TokenomicsConfigV22 calldata c) public view returns (address) {
        if (!initialized) revert NotInitialized();
        return Clones.predictDeterministicAddress(implementation, configHash(c), address(this));
    }

    /// @notice Check a config and this chain's leg: the rules every vault is made under (exactly
    ///         v2-config.mjs `checkConfig`, for the launch-wide fields and this chain's leg; the
    ///         other legs are committed only by their hashes). One rule more: an EVM vault needs an
    ///         EVM owner (`ownerEvm` nonzero), the creator its factory-v2 coin must name.
    /// @return ownLeg Whether this chain has a leg (else the vault pays everything to ownerEvm).
    function check(TokenomicsConfigV22 calldata c, TokenomicsLegV24 calldata localLeg) public view returns (bool ownLeg) {
        if (c.launchId == 0) revert ZeroLaunchId();
        if (c.ownerEvm == 0 || uint256(c.ownerEvm) >> 160 != 0) revert BadOwner();
        if (
            c.minHolderBps < MIN_HOLDER_BPS || c.minHolderBps > BPS || c.selectMode > 2
                || (c.selectMode == 0) != (c.selectCount == 0)
        ) revert BadEligibility();
        uint256 n = c.legEids.length;
        if (n == 0 || n > MAX_LEGS || c.legHashes.length != n) revert BadLegCount(n);
        uint32 here = _params.localEid;
        uint256 at = n;
        for (uint256 i = 0; i < n; i++) {
            if (i > 0 && c.legEids[i] <= c.legEids[i - 1]) revert LegsNotAscending(c.legEids[i]);
            if (c.legEids[i] == here) at = i;
        }
        if (at == n) return false;
        if (localLeg.eid != here || TokenomicsV24Config.legHash(localLeg) != c.legHashes[at]) revert LegHashMismatch(here);
        _checkLeg(localLeg);
        // v2.4 rule 22 (audit r2 I2): the chain's swapper is no payout wallet (a buy for it would leave
        // the token in the swapper, for the next buy of that token to sweep).
        bytes32 sw = bytes32(uint256(uint160(swapper)));
        for (uint256 i = 0; i < localLeg.wallets.length; i++) {
            if (localLeg.wallets[i] == sw) revert BadLeg(here, 22);
        }
        return true;
    }

    /// @dev One EVM leg's rules; `BadLeg(eid, rule)` names the rule broken.
    function _checkLeg(TokenomicsLegV24 calldata l) internal pure {
        uint32 eid = l.eid;
        uint256 nw = l.wallets.length;
        uint256 nr = l.rewardTokens.length;
        if (nw > MAX_WALLETS || l.walletBps.length != nw) revert BadLeg(eid, 1);
        uint256 sum = uint256(l.burnBps) + l.buyHoldBps + l.liquidityBps + l.holdersBps + l.burnTargetsBps;
        for (uint256 i = 0; i < nw; i++) {
            bytes32 w = l.wallets[i];
            if (w == 0 || uint256(w) >> 160 != 0) revert BadLeg(eid, 2);
            for (uint256 j = 0; j < i; j++) {
                if (l.wallets[j] == w) revert BadLeg(eid, 3);
            }
            if (l.walletBps[i] == 0) revert BadLeg(eid, 4);
            sum += l.walletBps[i];
        }
        if (sum != BPS) revert BadLeg(eid, 5);
        if (uint256(l.treasury) >> 160 != 0 || (l.buyHoldBps != 0) != (l.treasury != 0)) revert BadLeg(eid, 6);
        if (l.rewardBps.length != nr) revert BadLeg(eid, 7);
        if (l.holdersBps != 0) {
            if (nr == 0 || nr > MAX_REWARDS) revert BadLeg(eid, 8);
            uint256 rsum;
            for (uint256 i = 0; i < nr; i++) {
                bytes32 t = l.rewardTokens[i];
                if (uint256(t) >> 160 != 0) revert BadLeg(eid, 9);
                for (uint256 j = 0; j < i; j++) {
                    if (l.rewardTokens[j] == t) revert BadLeg(eid, 10);
                }
                if (l.rewardBps[i] == 0) revert BadLeg(eid, 11);
                rsum += l.rewardBps[i];
            }
            if (rsum != BPS) revert BadLeg(eid, 12);
        } else if (nr != 0) {
            revert BadLeg(eid, 13);
        }
        _checkBurnTargets(l);
        _checkWalletTokens(l);
    }

    /// @dev v2.4 rules 20-21: the wallets' tokens are none, or one per wallet; each zero (the pair
    ///      token) or an EVM address, never the native placeholder (native on a native-paired leg is
    ///      zero; on a stock-paired one the chain's wrapped coin, an ordinary ERC-20).
    function _checkWalletTokens(TokenomicsLegV24 calldata l) internal pure {
        uint256 nt = l.walletTokens.length;
        if (nt != 0 && nt != l.wallets.length) revert BadLeg(l.eid, 20);
        for (uint256 i = 0; i < nt; i++) {
            bytes32 t = l.walletTokens[i];
            if (uint256(t) >> 160 != 0 || t == NATIVE_PLACEHOLDER) revert BadLeg(l.eid, 21);
        }
    }

    /// @dev v2.2's leg rules 14-19: the BURN TOKENS bucket (docs/tokenomics-v22-spec.md section 1).
    ///      The coin itself is not known here (a vault is made before its launch): `buyBurn` refuses
    ///      it and `rollBurnTarget` rolls it into the own-coin burn at once.
    function _checkBurnTargets(TokenomicsLegV24 calldata l) internal pure {
        uint32 eid = l.eid;
        uint256 nb = l.burnTokens.length;
        if (l.burnTokenBps.length != nb) revert BadLeg(eid, 14);
        if (l.burnTargetsBps == 0) {
            if (nb != 0) revert BadLeg(eid, 15);
            return;
        }
        if (nb == 0 || nb > MAX_BURN_TARGETS) revert BadLeg(eid, 15);
        uint256 bsum;
        for (uint256 i = 0; i < nb; i++) {
            bytes32 t = l.burnTokens[i];
            if (t == 0 || t == NATIVE_PLACEHOLDER || uint256(t) >> 160 != 0) revert BadLeg(eid, 16);
            for (uint256 j = 0; j < i; j++) {
                if (l.burnTokens[j] == t) revert BadLeg(eid, 17);
            }
            if (l.burnTokenBps[i] == 0) revert BadLeg(eid, 18);
            bsum += l.burnTokenBps[i];
        }
        if (bsum != BPS) revert BadLeg(eid, 19);
    }

    /// @notice Make the vault for `c` on this chain, or return it if it is already there.
    ///         `localLeg` is this chain's leg in full (ignored when this chain has none).
    function createVault(TokenomicsConfigV22 calldata c, TokenomicsLegV24 calldata localLeg)
        public
        returns (address vault)
    {
        vault = predict(c);
        if (vault.code.length != 0) return vault;
        bool ownLeg = check(c, localLeg);
        bytes32 h = configHash(c);
        Clones.cloneDeterministic(implementation, h);
        isVault[vault] = true;
        ITokenomicsVaultV24Init(vault).initialize(c, localLeg, ownLeg);
        emit VaultCreated(vault, c.launchId, address(uint160(uint256(c.ownerEvm))), h, ownLeg);
    }

    /// @notice Make the vault if need be and pay the launch fee through it (v1's path). The caller
    ///         must be the config's EVM owner. FACTORY V2: pass a dev buy of zero (see the vault).
    function payLaunchFee(TokenomicsConfigV22 calldata c, TokenomicsLegV24 calldata localLeg, uint256 devBuyAmount)
        external
        payable
        returns (address vault)
    {
        vault = createVault(c, localLeg);
        ITokenomicsVaultV24Init(vault).payLaunchFee{value: msg.value}(msg.sender, devBuyAmount);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@layerzerolabs/oft-evm/=lib/layerzero/oft-evm/",
    "@layerzerolabs/oapp-evm/=lib/layerzero/oapp-evm/",
    "@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero/protocol-v2/",
    "@uniswap/v4-core/=lib/uniswap-v4-core/",
    "solmate/=lib/solmate/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "layerzero/=lib/layerzero/",
    "uniswap-v4-core/=lib/uniswap-v4-core/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.