Skip to content
Verified contractPartialMIT

FlaunchZap

Address0x37c71d412eeb80dce4eb098f2f93f8270911c2d8
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.26

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 777 runs
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,241,693
Creation transaction
0x3d5e252da3…7cc03a6466
Main copy (most transactions)
0x11666704…d64900fc

107 files

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

src/contracts/zaps/FlaunchZap.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {SafeTransferLib} from '@solady/utils/SafeTransferLib.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {Currency} from '@uniswap/v4-core/src/types/Currency.sol';
import {PoolId, PoolIdLibrary} from '@uniswap/v4-core/src/types/PoolId.sol';
import {PoolKey} from '@uniswap/v4-core/src/types/PoolKey.sol';

import {Flaunch} from '@flaunch/Flaunch.sol';
import {PositionManager} from '@flaunch/PositionManager.sol';
import {PairedTokenLib} from '@flaunch/libraries/PairedTokenLib.sol';
import {TokenSupply} from '@flaunch/libraries/TokenSupply.sol';

import {IFeeCalculator} from '@flaunch-interfaces/IFeeCalculator.sol';
import {IFeeCalculatorDispatcher} from '@flaunch-interfaces/IFeeCalculatorDispatcher.sol';
import {IFlaunchZap} from '@flaunch-interfaces/IFlaunchZap.sol';
import {IPairedTokenRegistry} from '@flaunch-interfaces/IPairedTokenRegistry.sol';
import {IPositionManager} from '@flaunch-interfaces/IPositionManager.sol';
import {ITreasuryManager} from '@flaunch-interfaces/ITreasuryManager.sol';
import {ITreasuryManagerFactory} from '@flaunch-interfaces/ITreasuryManagerFactory.sol';
import {ITrustedSignerFeeCalculator} from '@flaunch-interfaces/ITrustedSignerFeeCalculator.sol';

/**
 * Single-transaction entrypoint for flaunching a memecoin with optional extras that the
 * {PositionManager} alone cannot provide: registering a trusted fee signer against the new pool,
 * funding an ERC20-paired premine on behalf of the caller, and escrowing the Flaunch ERC721 into
 * a treasury manager.
 *
 * The zap holds no funds between transactions: any ETH, paired token or memecoin it handles during
 * a launch is forwarded or refunded before the call returns.
 */
contract FlaunchZap is IFlaunchZap {
    using PoolIdLibrary for PoolKey;

    /// The buffer, in basis points, that {calculateFee} adds to its linear premine quote so the
    /// figure it returns is an UPPER bound on the settled cost and can be used directly as a cost
    /// cap. The premine is filled as a swap against the just-seeded launch position, so it always
    /// settles marginally above the market-cap ratio the quote is derived from; without a buffer
    /// the quote is a strict lower bound and reverts whenever a caller passes it back in.
    uint public constant PREMINE_PRICE_IMPACT_BUFFER = 1_00; // 1%

    /// The Flaunch {PositionManager} that launches are forwarded to
    PositionManager public immutable positionManager;

    /// The {PositionManager}'s paired-token registry, cached at deploy time. Safe to hold as an
    /// immutable because the {PositionManager} sets its registry in its constructor and exposes
    /// no setter, so the reference can never change underneath the zap.
    IPairedTokenRegistry public immutable pairedTokenRegistry;

    /// The {Flaunch} ERC721 that represents ownership of a flaunched pool
    Flaunch public immutable flaunchContract;

    /// The factory used to deploy / recognise treasury managers. May be `address(0)` on chains
    /// where no factory has been deployed yet: manager flaunches then fall through to the
    /// unknown-manager path (approve + best-effort deposit + transfer), and
    /// {deployAndInitializeManager} reverts.
    ITreasuryManagerFactory public immutable treasuryManagerFactory;

    /**
     * References the contract addresses for the Flaunch protocol.
     *
     * @param _positionManager The Flaunch {PositionManager} contract
     * @param _flaunchContract The {Flaunch} ERC721 contract
     * @param _treasuryManagerFactory The {ITreasuryManagerFactory}, or `address(0)` if none exists
     */
    constructor(
        PositionManager _positionManager,
        Flaunch _flaunchContract,
        ITreasuryManagerFactory _treasuryManagerFactory
    ) {
        positionManager = _positionManager;
        pairedTokenRegistry = _positionManager.pairedTokenRegistry();
        flaunchContract = _flaunchContract;
        treasuryManagerFactory = _treasuryManagerFactory;
    }

    /**
     * Flaunches a memecoin without any additional logic.
     *
     * This entrypoint funds any premine from the ETH sent with the call (`msg.value`) and is only
     * valid for ETH-funded (raw native ETH or native-wrapper paired) or no-premine launches. A
     * pull-funded premine (ERC20 wrapper or plain ERC20 pairing) cannot be funded from ETH; the
     * paired token has to be pulled from the caller against a cost cap, so those launches must use
     * the {maxPremineCost} overload instead. We reject them here with a specific error rather than
     * letting the {PositionManager} revert with a raw `TransferFromFailed`.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     */
    function flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        address _trustedFeeSigner
    ) external payable refundsEth returns (address memecoin_, uint ethSpent_) {
        if (_isErc20PairedPremine(_flaunchParams)) {
            revert Erc20PremineRequiresMaxCost();
        }

        return _flaunch(_flaunchParams, _trustedFeeSigner);
    }

    /**
     * Flaunches a memecoin, funding an ERC20-paired premine on behalf of the caller.
     *
     * For an ERC20-paired launch the {PositionManager} pulls the premine cost in the paired token
     * from `msg.sender` of its `flaunch` call, which is this zap. This overload makes the zap the
     * funder: it pulls up to `_maxPremineCost` of the paired token from the caller, approves the
     * {PositionManager} to pull exactly what the premine costs, forwards the launch, and refunds
     * the unspent remainder to the caller. `_maxPremineCost` doubles as the slippage / cost cap: if
     * the premine costs more than the cap the launch reverts (the {PositionManager} cannot pull
     * more than the zap was funded / approved for).
     *
     * Native (flETH-paired) and no-premine launches ignore `_maxPremineCost` and are routed through
     * the exact same code path as the {flaunch} entrypoint above, funded via `msg.value`.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     * @param _maxPremineCost The maximum paired-token cost the caller will pay for the premine
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     */
    function flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        address _trustedFeeSigner,
        uint _maxPremineCost
    ) external payable refundsEth returns (address memecoin_, uint ethSpent_) {
        // Native / no-premine launches don't require paired-token funding; route them through the
        // existing (byte-identical) path funded by `msg.value`.
        if (!_isErc20PairedPremine(_flaunchParams)) {
            return _flaunch(_flaunchParams, _trustedFeeSigner);
        }

        // A zero-value manager struct means no manager is wired for this launch
        TreasuryManagerParams memory noManagerParams;
        (memecoin_, ethSpent_,) = _flaunchErc20Premine(_flaunchParams, noManagerParams, _trustedFeeSigner, _maxPremineCost);
    }

    /**
     * Flaunches a memecoin and escrows it into a treasury manager.
     *
     * The zap flaunches with itself as the temporary creator so that it receives the Flaunch
     * ERC721, then wires the manager (see {_createWithManagerZap}) and deposits the token into it
     * on behalf of the original creator. Any premined memecoin is swept to the original creator.
     *
     * Like the plain entrypoint above, this overload cannot fund an ERC20-paired premine and
     * rejects those launches; use the `maxPremineCost` manager overload instead.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _treasuryManagerParams Optional manager wiring for the new pool
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     * @return deployedManager_ The manager the flaunch token was deposited into
     */
    function flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        TreasuryManagerParams calldata _treasuryManagerParams,
        address _trustedFeeSigner
    ) external payable refundsEth returns (address memecoin_, uint ethSpent_, address deployedManager_) {
        if (_isErc20PairedPremine(_flaunchParams)) {
            revert Erc20PremineRequiresMaxCost();
        }

        return _flaunch(_flaunchParams, _treasuryManagerParams, _trustedFeeSigner);
    }

    /**
     * Flaunches a memecoin into a treasury manager, funding an ERC20-paired premine on behalf of
     * the caller. Combines the manager overload above with the `maxPremineCost` funding path; for
     * native / no-premine launches `_maxPremineCost` is ignored.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _treasuryManagerParams Optional manager wiring for the new pool
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     * @param _maxPremineCost The maximum paired-token cost the caller will pay for the premine
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     * @return deployedManager_ The manager the flaunch token was deposited into
     */
    function flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        TreasuryManagerParams calldata _treasuryManagerParams,
        address _trustedFeeSigner,
        uint _maxPremineCost
    ) external payable refundsEth returns (address memecoin_, uint ethSpent_, address deployedManager_) {
        if (!_isErc20PairedPremine(_flaunchParams)) {
            return _flaunch(_flaunchParams, _treasuryManagerParams, _trustedFeeSigner);
        }

        return _flaunchErc20Premine(_flaunchParams, _treasuryManagerParams, _trustedFeeSigner, _maxPremineCost);
    }

    /**
     * Deploys and initializes a manager instance from an approved implementation, setting its
     * permissions before handing ownership to `_owner`.
     *
     * @param _managerImplementation The approved manager implementation to clone
     * @param _owner The final owner of the deployed manager
     * @param _data Initialization data passed to the manager
     * @param _permissions The permissions contract set against the manager
     *
     * @return manager_ The deployed manager instance
     */
    function deployAndInitializeManager(
        address _managerImplementation,
        address _owner,
        bytes calldata _data,
        address _permissions
    ) public returns (address payable manager_) {
        if (address(treasuryManagerFactory) == address(0)) {
            revert TreasuryManagerFactoryNotSet();
        }

        manager_ = treasuryManagerFactory.deployAndInitializeManager({
            _managerImplementation: _managerImplementation, _owner: address(this), _data: _data
        });

        ITreasuryManager(manager_).setPermissions(_permissions);
        ITreasuryManager(manager_).transferManagerOwnership(_owner);
    }

    /**
     * Quotes the funding a caller needs to supply for a launch.
     *
     * For a native (flETH or raw-ETH) launch the premine is funded from ETH, so its cost folds into
     * `ethRequired_` and `pairedPremineCost_` is zero.
     *
     * For an ERC20-paired launch the premine is paid in the paired token, not ETH, so `ethRequired_`
     * carries only the ETH the zap actually needs (the flaunch fee) and the premine cost is
     * surfaced separately in `pairedPremineCost_` (see VPT-11) — the latter is what a caller passes
     * as the `_maxPremineCost` argument to the {flaunch} overload.
     *
     * @dev Two properties are load-bearing and were both broken before this fix:
     *
     *  1. DENOMINATION. The premine is quoted through {IInitialPrice.getPairedMarketCap}, which
     *     returns the market cap in the units of the token the pool is actually paired against —
     *     the same figure the launch sqrtPrice is derived from. The older
     *     `PositionManager.getFlaunchingMarketCap` takes no paired-token argument and is always
     *     ETH-denominated, so an flUSDC quote came out wrong by both the ETH:USD rate and the
     *     18-vs-6 decimal gap (~3.3e8x), making the documented `_maxPremineCost` flow revert and
     *     the VPT-18 cost cap vacuous.
     *
     *  2. DIRECTION OF ERROR. A quote is only useful as a cap if it errs HIGH. The market-cap
     *     ratio prices the premine linearly at the launch tick, but the premine is actually filled
     *     as a swap against the freshly seeded position, so the settled cost is always slightly
     *     above the linear figure. Quoting the bare ratio therefore under-quotes and reverts every
     *     time it is used as a cap. We add {PREMINE_PRICE_IMPACT_BUFFER} on top of the ratio to
     *     cover that impact, and the caller's `_slippage` compounds on top of it. Over-quoting is
     *     free in both directions: unspent ETH is returned by {refundsEth} and unspent paired token
     *     is refunded by {_flaunchErc20Premine}. Note the buffer is sized for ordinary premines; a
     *     premine taking a large share of supply moves the price further and still needs the caller
     *     to supply `_slippage`.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _slippage Optional additional slippage buffer, in basis points (100_00 == 100%)
     *
     * @return ethRequired_ The ETH the caller must send with the launch
     * @return pairedPremineCost_ The paired-token cost of the premine (zero for a native launch)
     */
    function calculateFee(
        IPositionManager.FlaunchParams memory _flaunchParams,
        uint _slippage
    ) public view returns (uint ethRequired_, uint pairedPremineCost_) {
        uint flaunchFee = positionManager.getFlaunchingFee(_flaunchParams.initialPriceParams);

        // Quote the premine in the units of the pool's own paired token, then buffer it upward so
        // the figure is safe to hand straight back in as a cost cap (see the dev note above).
        uint premineCost;
        if (_flaunchParams.premineAmount != 0) {
            premineCost = positionManager.initialPrice().getPairedMarketCap(_flaunchParams.pairedToken, _flaunchParams.initialPriceParams)
                * _flaunchParams.premineAmount / TokenSupply.INITIAL_SUPPLY;

            premineCost += premineCost * PREMINE_PRICE_IMPACT_BUFFER / 100_00;
        }

        // The funding-mode classification only matters when a premine is being quoted: with no
        // premine both arms collapse to `ethRequired_ = flaunchFee`, so the registry read is
        // skipped entirely.
        if (_flaunchParams.premineAmount != 0 && _isPullFunded(_flaunchParams)) {
            // Pull-funded: the premine is paid in the paired token, so it is surfaced separately
            // and only the flaunch fee is needed in ETH.
            ethRequired_ = flaunchFee;
            pairedPremineCost_ = premineCost;
        } else {
            // ETH-funded (native / a native wrapper): the premine folds into the ETH figure.
            ethRequired_ = flaunchFee + premineCost;
        }

        if (_slippage != 0) {
            ethRequired_ += ethRequired_ * _slippage / 100_00;
            pairedPremineCost_ += pairedPremineCost_ * _slippage / 100_00;
        }
    }

    /**
     * Convenience wrapper for launches without a treasury manager.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     */
    function _flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        address _trustedFeeSigner
    ) internal returns (address memecoin_, uint ethSpent_) {
        // A zero-value manager struct means no manager is wired for this launch
        TreasuryManagerParams memory noManagerParams;
        (memecoin_, ethSpent_,) = _flaunch(_flaunchParams, noManagerParams, _trustedFeeSigner);
    }

    /**
     * The core launch routine that all entrypoints funnel into: flaunches the memecoin, reports
     * the ETH spent and, if requested, escrows the flaunched token into a treasury manager.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _treasuryManagerParams Optional manager wiring for the new pool
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     * @return deployedManager_ The manager the flaunch token was deposited into
     */
    function _flaunch(
        IPositionManager.FlaunchParams memory _flaunchParams,
        TreasuryManagerParams memory _treasuryManagerParams,
        address _trustedFeeSigner
    ) internal returns (address memecoin_, uint ethSpent_, address deployedManager_) {
        address originalCreator = _flaunchParams.creator;
        if (originalCreator == address(0)) {
            revert CreatorCannotBeZero();
        }

        // When a manager is requested, the zap becomes the temporary creator so that it receives
        // the Flaunch ERC721 (and any premine) and can deposit the token into the manager. The
        // trusted-signer path inside {_flaunchMemecoin} sees `creator == address(this)` and skips
        // its own NFT return / premine sweep, so both are handled exclusively below.
        bool hasManager = _treasuryManagerParams.manager != address(0);
        if (hasManager) {
            _flaunchParams.creator = address(this);
        }

        // Report the ETH actually consumed rather than re-deriving it from the (ETH-denominated,
        // linear, and for a non-native pool simply wrong) market-cap quote. `msg.value` is already
        // credited to this contract, and the {PositionManager} returns whatever it did not use, so
        // the balance delta across the launch is exactly the flaunch fee plus any ETH-funded
        // premine — and it is zero-cost to compute correctly for every paired token.
        uint ethBefore = payable(address(this)).balance;

        memecoin_ = _flaunchMemecoin(_flaunchParams, _trustedFeeSigner);

        ethSpent_ = ethBefore - payable(address(this)).balance;

        if (hasManager) {
            deployedManager_ = _createWithManagerZap(memecoin_, originalCreator, _treasuryManagerParams);

            // The manager takes only the ERC721; any premine was delivered to the zap as the
            // temporary creator, so sweep it to the original creator so it is not stranded.
            // (Whole-balance is exact: the memecoin was created inside this call, so the zap's
            // prior balance is zero by construction.)
            uint memecoinBalance = IERC20(memecoin_).balanceOf(address(this));
            if (memecoinBalance != 0) {
                SafeTransferLib.safeTransfer(memecoin_, originalCreator, memecoinBalance);
            }
        }
    }

    /**
     * Funds an ERC20-paired premine on behalf of the caller, then forwards the launch.
     *
     * The zap pulls up to `_maxPremineCost` of the paired token from the caller and approves the
     * {PositionManager} to spend it. During the launch the {PositionManager} pulls exactly the
     * premine cost (`spent`, computed inside its swap) from this zap. Whatever is left over
     * (`_maxPremineCost - spent`) is refunded to the caller, and the residual approval is cleared.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _treasuryManagerParams Optional manager wiring for the new pool
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     * @param _maxPremineCost The maximum paired-token cost the caller will pay for the premine
     *
     * @return memecoin_ The created ERC20 token address
     * @return ethSpent_ The amount of ETH spent during the premine
     * @return deployedManager_ The manager the flaunch token was deposited into
     */
    function _flaunchErc20Premine(
        IPositionManager.FlaunchParams memory _flaunchParams,
        TreasuryManagerParams memory _treasuryManagerParams,
        address _trustedFeeSigner,
        uint _maxPremineCost
    ) internal returns (address memecoin_, uint ethSpent_, address deployedManager_) {
        address paired = _flaunchParams.pairedToken;

        // Snapshot before pulling so the refund below is the DELTA of this launch, not the zap's
        // whole balance: any paired token that landed on the zap out-of-band must not ride a
        // stranger's refund.
        uint pairedBefore = SafeTransferLib.balanceOf(paired, address(this));

        // Pull the caller's cost cap in the paired token — 1:1 by policy, so the full amount
        // moves or the pull reverts inside `safeTransferFrom` — and approve the
        // {PositionManager} to pull up to that amount (retry-tolerant for USDC-style tokens).
        PairedTokenLib.pullFrom(Currency.wrap(paired), msg.sender, _maxPremineCost, 0);
        PairedTokenLib.ensureAllowance(paired, address(positionManager), _maxPremineCost);

        // Forward the launch; the {PositionManager} pulls exactly the premine cost from this zap.
        (memecoin_, ethSpent_, deployedManager_) = _flaunch(_flaunchParams, _treasuryManagerParams, _trustedFeeSigner);

        // Clear any residual allowance (the {PositionManager} pulled <= `_maxPremineCost`).
        PairedTokenLib.revokeAllowance(paired, address(positionManager));

        // Refund the unspent portion of what THIS call pulled back to the caller.
        uint refund = SafeTransferLib.balanceOf(paired, address(this)) - pairedBefore;
        if (refund != 0) {
            PairedTokenLib.pay(Currency.wrap(paired), msg.sender, refund);
        }
    }

    /**
     * Performs the {PositionManager} flaunch call, registering a trusted fee signer against the
     * created pool if one was supplied.
     *
     * Registering a signer can only be done by the pool creator, so the zap makes itself the
     * temporary creator for the launch and afterwards forwards the ERC721 and any premined
     * memecoin to the original creator. If the creator was already set to this zap by the manager
     * flow, that forwarding is skipped and ownership is handled by the caller instead.
     *
     * @param _flaunchParams The base flaunch parameters
     * @param _trustedFeeSigner Optional trusted fee signer for this memecoin
     *
     * @return memecoin_ The created ERC20 token address
     */
    function _flaunchMemecoin(
        IPositionManager.FlaunchParams memory _flaunchParams,
        address _trustedFeeSigner
    ) internal returns (address memecoin_) {
        // Without a signer there is nothing for the zap to do post-launch; forward the call as-is
        if (_trustedFeeSigner == address(0)) {
            memecoin_ = positionManager.flaunch{value: msg.value}(_flaunchParams);
            return memecoin_;
        }

        // Become the temporary creator so that the zap is allowed to register the signer
        address originalCreator = _flaunchParams.creator;
        if (originalCreator != address(this)) {
            _flaunchParams.creator = address(this);
        }

        memecoin_ = positionManager.flaunch{value: msg.value}(_flaunchParams);

        /**
         * Register the trusted signer against the pool that was just created, on the calculator
         * that actually serves it. When the hook's slot holds a {FeeCalculatorDispatcher} the
         * dispatcher itself has no signer surface — the registration must target the
         * sub-calculator the pool routed to at launch (via the caller's `feeCalculatorParams`
         * routing envelope).
         *
         * Deliberately FAIL-CLOSED: if the resolved calculator cannot accept the registration —
         * an unrouted pool on the static default, or a spend-gated pool whose signer authority
         * is its settler — the launch reverts rather than silently dropping the requested
         * signer, which would leave the caller believing a signer gates a pool that nothing
         * gates.
         */
        PoolKey memory createdPoolKey = positionManager.poolKey(memecoin_);
        ITrustedSignerFeeCalculator(_resolveSignerCalculator(createdPoolKey.toId()))
            .setTrustedPoolKeySigner({_poolKey: createdPoolKey, _signer: _trustedFeeSigner});

        // Forward the Flaunch ERC721 to the original creator
        if (originalCreator != address(this)) {
            flaunchContract.transferFrom(address(this), originalCreator, flaunchContract.tokenId(memecoin_));
        }

        // The premine is delivered to the flaunch `creator`, which is temporarily set to this
        // zap so it can register the trusted signer. Sweep any premined memecoin back to the
        // original creator so it is not stranded in the zap. (Whole-balance is exact here: the
        // memecoin was created inside this call, so the zap's prior balance is zero by
        // construction.)
        uint memecoinBalance = IERC20(memecoin_).balanceOf(address(this));
        if (memecoinBalance != 0 && originalCreator != address(this)) {
            SafeTransferLib.safeTransfer(memecoin_, originalCreator, memecoinBalance);
        }
    }

    /**
     * The calculator a signer registration for `_poolId` must target: the hook's installed
     * calculator, resolved THROUGH the {FeeCalculatorDispatcher} when one holds the slot — the
     * pool's routed sub-calculator, or the dispatcher's default for an unrouted pool. A bare
     * calculator (no `poolCalculator` selector) is returned as-is, preserving the
     * pre-dispatcher behaviour.
     *
     * @param _poolId The pool the signer is being registered against
     *
     * @return calculator_ The calculator to call `setTrustedPoolKeySigner` on
     */
    function _resolveSignerCalculator(
        PoolId _poolId
    ) internal view returns (address calculator_) {
        calculator_ = address(positionManager.feeCalculator());

        try IFeeCalculatorDispatcher(calculator_).poolCalculator(_poolId) returns (IFeeCalculator subCalculator) {
            calculator_ = address(subCalculator) != address(0)
                ? address(subCalculator)
                : address(IFeeCalculatorDispatcher(calculator_).defaultCalculator());
        } catch {}
    }

    /**
     * Escrows a freshly flaunched token (held by this zap as the temporary creator) into a
     * treasury manager, dispatching on what the manager address is:
     *
     *  1. An approved manager implementation -> deploy + initialize a fresh instance through the
     *     factory and deposit into it, optionally applying permissions before handing the manager
     *     ownership to the creator.
     *  2. An instance previously deployed by the factory -> deposit into it directly.
     *  3. An unknown address -> best-effort `deposit` and, if the zap still holds the ERC721
     *     afterwards, transfer it to the address directly.
     *
     * If no factory is bound to this zap (`address(0)`), every manager routes through (3).
     *
     * @param _memecoin The flaunched memecoin whose ERC721 is being escrowed
     * @param _creator The original creator that the deposit is made on behalf of
     * @param _treasuryManagerParams The manager wiring requested by the caller
     *
     * @return deployedManager_ The manager the flaunch token was deposited into
     */
    function _createWithManagerZap(
        address _memecoin,
        address _creator,
        TreasuryManagerParams memory _treasuryManagerParams
    ) internal returns (address deployedManager_) {
        uint tokenId = flaunchContract.tokenId(_memecoin);
        ITreasuryManager.FlaunchToken memory flaunchToken = ITreasuryManager.FlaunchToken({flaunch: flaunchContract, tokenId: tokenId});

        bool hasFactory = address(treasuryManagerFactory) != address(0);

        if (hasFactory && treasuryManagerFactory.approvedManagerImplementation(_treasuryManagerParams.manager)) {
            // If permissions will be applied, the zap must own the manager while it sets them, and
            // only hands ownership to the creator afterwards.
            address initialOwner = _treasuryManagerParams.permissions == address(0) ? _creator : address(this);
            deployedManager_ = treasuryManagerFactory.deployAndInitializeManager({
                _managerImplementation: _treasuryManagerParams.manager, _owner: initialOwner, _data: _treasuryManagerParams.initializeData
            });

            flaunchContract.approve(deployedManager_, tokenId);
            ITreasuryManager(deployedManager_)
                .deposit({_flaunchToken: flaunchToken, _creator: _creator, _data: _treasuryManagerParams.depositData});

            if (_treasuryManagerParams.permissions != address(0)) {
                ITreasuryManager(deployedManager_).setPermissions(_treasuryManagerParams.permissions);
                ITreasuryManager(deployedManager_).transferManagerOwnership(_creator);
            }
        } else if (hasFactory && treasuryManagerFactory.managerImplementation(_treasuryManagerParams.manager) != address(0)) {
            flaunchContract.approve(_treasuryManagerParams.manager, tokenId);
            deployedManager_ = _treasuryManagerParams.manager;
            ITreasuryManager(deployedManager_)
                .deposit({_flaunchToken: flaunchToken, _creator: _creator, _data: _treasuryManagerParams.depositData});
        } else {
            flaunchContract.approve(_treasuryManagerParams.manager, tokenId);

            try ITreasuryManager(_treasuryManagerParams.manager).deposit(flaunchToken, _creator, _treasuryManagerParams.depositData) {}
                catch {}

            if (flaunchContract.ownerOf(tokenId) == address(this)) {
                flaunchContract.transferFrom(address(this), _treasuryManagerParams.manager, tokenId);
            }

            deployedManager_ = _treasuryManagerParams.manager;
        }
    }

    /**
     * Whether a launch's premine must be funded by pulling the paired token from the caller
     * (against an allowance) rather than from the ETH sent with the call.
     *
     * @dev Resolved from the paired token's registered shape via {PairedTokenLib.isEthFunded} —
     * the same dispatch truth {FlaunchLibrary} uses to fill the premine — so the zap can never
     * disagree with the hook on a launch's funding mode. An unregistered token resolves to
     * `Unset`, which classifies as pull-funded; the launch itself then reverts
     * `PairedTokenNotApproved` in the {PositionManager} regardless.
     *
     * @param _flaunchParams The base flaunch parameters
     *
     * @return Whether the premine is funded in the paired token
     */
    function _isPullFunded(
        IPositionManager.FlaunchParams memory _flaunchParams
    ) internal view returns (bool) {
        return !PairedTokenLib.isEthFunded(
            pairedTokenRegistry.tokenConfig(_flaunchParams.pairedToken).tokenType
        );
    }

    /**
     * Whether a launch is a pull-funded premine (a pull-funded launch that also requests a
     * premine). These are the launches the zap must fund in the paired token.
     *
     * @param _flaunchParams The base flaunch parameters
     *
     * @return Whether the launch is a pull-funded premine
     */
    function _isErc20PairedPremine(
        IPositionManager.FlaunchParams memory _flaunchParams
    ) internal view returns (bool) {
        return _flaunchParams.premineAmount != 0 && _isPullFunded(_flaunchParams);
    }

    /**
     * Refunds any ETH left in the zap after the call to the caller, so nothing is stranded.
     */
    modifier refundsEth() {
        _;

        uint remainingBalance = payable(address(this)).balance;
        if (remainingBalance != 0) {
            SafeTransferLib.safeTransferETH(msg.sender, remainingBalance);
        }
    }

    /**
     * Allows the {FlaunchZap} to receive ETH during a launch.
     */
    receive() external payable {}
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 777,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@optimism/=lib/optimism/packages/contracts-bedrock/",
    "interfaces/=lib/optimism/packages/contracts-bedrock/interfaces/",
    "@solady/=lib/solady/src/",
    "solady-test/=lib/solady/test/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v4-core/=lib/v4-hooks-public/lib/v4-periphery/lib/v4-core/",
    "@uniswap-periphery/=lib/v4-hooks-public/lib/v4-periphery/src/",
    "@uniswap-hooks/=lib/v4-hooks-public/src/",
    "solmate/=lib/optimism/packages/contracts-bedrock/lib/solmate/",
    "@flaunch/=src/contracts/",
    "@flaunch-interfaces/=src/interfaces/",
    "@ensdomains/=lib/v4-hooks-public/lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
    "@uniswap/v4-periphery/=lib/v4-hooks-public/lib/v4-periphery/",
    "briefcase/=lib/v4-hooks-public/lib/briefcase/src/",
    "ds-test/=lib/vulcan/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/v4-hooks-public/lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/v4-hooks-public/lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
    "kontrol-cheatcodes/=lib/optimism/packages/contracts-bedrock/lib/kontrol-cheatcodes/src/",
    "lib-keccak/=lib/optimism/packages/contracts-bedrock/lib/lib-keccak/contracts/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts-v5/=lib/optimism/packages/contracts-bedrock/lib/openzeppelin-contracts-v5/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "optimism/=lib/optimism/",
    "permit2/=lib/v4-hooks-public/lib/v4-periphery/lib/permit2/",
    "safe-contracts/=lib/optimism/packages/contracts-bedrock/lib/safe-contracts/contracts/",
    "solady-v0.0.245/=lib/optimism/packages/contracts-bedrock/lib/solady-v0.0.245/src/",
    "solady/=lib/solady/src/",
    "v3-core/=lib/v3-core/",
    "v4-core/=lib/v4-hooks-public/lib/v4-periphery/lib/v4-core/src/",
    "v4-hooks-public/=lib/v4-hooks-public/",
    "v4-periphery/=lib/v4-hooks-public/lib/v4-periphery/",
    "vulcan/=lib/vulcan/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.