Skip to content
Verified contractPartialMIT

Launchpad

Address0x1a2ea2f59dfafa86f8c0a7cb0abd0db6f2911ad0
Balance

0 ETH

 

Transactions

4

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 1,000,000 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,900,395
Creation transaction
0x98603b08e3…b1fe8e07c9

78 files

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

src/Launchpad.sol

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

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { IHooks } from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import { IPoolManager } from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import { Hooks } from "@uniswap/v4-core/src/libraries/Hooks.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 { Chains } from "./Chains.sol";
import { LaunchpadCore } from "./LaunchpadCore.sol";
import { DividendTokenDeployer } from "./dividend/DividendTokenDeployer.sol";
import { HookDeployer } from "./hook/HookDeployer.sol";
import { LaunchMath } from "./libraries/LaunchMath.sol";
import { LaunchLpLocker } from "./lp/LaunchLpLocker.sol";

/// @title Launchpad
/// @author Dev
/// @notice Deploys a token, its taxing hook and its pool on Uniswap v4, and seeds the whole supply
///         single-sided, in one transaction.
/// @dev **One transaction is the point.** The pool does not exist until the transaction that creates it, so
///      there is no block in which somebody can buy before the launcher does. That property is what the dev
///      buy rests on.
///
///      **The hook's salt is mined off chain and checked here.** A v4 hook's permissions live in the low
///      fourteen bits of its address, so it must be CREATE2-mined to match. Mining on chain costs about
///      2.9M gas on average with a tail past 16M, which breaks gas estimation and can exceed a block; mining
///      off chain costs 78 milliseconds. So the caller brings a salt and this contract verifies the address
///      it produces rather than trusting it — a wrong salt is refused, not silently accepted.
///
///      The token's address is CREATE2 too, which is what makes the mining possible at all: the hook needs
///      the token's address in its constructor arguments, and the front end can compute that before either
///      contract exists.
///
///      **Everything that is not about v4 lives in `LaunchpadCore`** — the attestation, the valuation, the
///      dev-buy cap — because `CLLaunchpad` needs exactly the same rules on PancakeSwap Infinity and two
///      copies of them would be two things free to drift.
///
///      **The pool position is not here, and that is the point of `LaunchLpLocker`.** This contract has no
///      `modifyLiquidity` call and no unlock callback at all: it deploys, prices, initialises and then hands
///      the whole supply to a contract whose entire code surface is "add liquidity" and "compound fees into
///      that liquidity". The lock was already unbreakable when the position lived here — nothing ever passed
///      a negative delta — but proving that meant reading this file, which also verifies signatures, mines
///      hooks and carries an owner. An aggregator cannot read it and a holder will not.
///
///      That move drags the dev buy with it, unavoidably. v4 keys a position by `(msg.sender, tickLower,
///      tickUpper, salt)`, so the locker has to be the caller of `modifyLiquidity`; the dev buy has to run in
///      the same lock as the mint, because the pool it buys from is the one being created and nobody else can
///      trade inside that lock. Both cannot be satisfied with the position in one contract and the swap in
///      another, so the locker owns the whole `unlock` frame.
contract Launchpad is LaunchpadCore {
    using PoolIdLibrary for PoolKey;
    using SafeERC20 for IERC20;

    /// @notice The v4 singleton, which holds every pool and every pool's tokens.
    IPoolManager public immutable poolManager;

    /// @notice What deploys the launch hooks.
    /// @dev **Its address is baked into every mined salt**, because CREATE2 hashes the deployer. A front end
    ///      mines against this address, not against the launchpad, and a different deployer means every
    ///      previously computed salt is wrong.
    HookDeployer public immutable hookDeployer;

    /// @notice The flag set every launch hook must carry.
    /// @dev `beforeSwap | afterSwap | beforeSwapReturnDelta | afterSwapReturnDelta`. A hook address whose
    ///      low bits are anything else cannot serve this system, and `PoolManager.initialize` would refuse
    ///      it anyway — checking here means the error names the salt rather than coming from inside v4.
    uint160 public constant HOOK_FLAGS = uint160(
        Hooks.BEFORE_SWAP_FLAG | Hooks.AFTER_SWAP_FLAG | Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG
            | Hooks.AFTER_SWAP_RETURNS_DELTA_FLAG
    );

    /// @notice Where every launch position is minted, held and compounded.
    /// @dev **Immutable, ownerless and wired without a setter.** The launchpad needs the locker's address and
    ///      the locker needs the launchpad's, which a one-shot setter would resolve at the price of a
    ///      permanent privileged write on the contract whose whole value is that it has none. The deploy
    ///      script predicts this contract's CREATE address and hands it to the locker's constructor instead;
    ///      the check below is what turns a mis-predicted nonce into a failed deployment rather than into a
    ///      launchpad that reverts on its first launch.
    LaunchLpLocker public immutable lpLocker;

    /// @notice The supplied salt does not produce an address carrying the hook flags.
    /// @param produced What the salt would deploy to.
    error HookSaltWrong(address produced);

    /// @notice The locker was built against a different launchpad than this one.
    /// @dev **Deployment-time proof that the address prediction was right.** The locker's `launchpad` is
    ///      immutable and was set before this contract existed, so the only way it can be wrong is a nonce
    ///      that did not land where the script expected — and the cheapest moment to find that out is now,
    ///      not at the first launch, when a token and a hook have already been deployed.
    /// @param expected Who the locker will actually accept.
    error LockerNotBound(address expected);

    /// @param tokenDeployer_ What deploys the launch tokens.
    /// @param hookDeployer_ What deploys the launch hooks.
    /// @param owner_ Who may rotate the signer.
    /// @param priceSigner_ Who signs price attestations.
    /// @param platformRecipient_ Where the platform's share of swap fees is sent.
    /// @param lpLocker_ Where launch positions are minted and held, built against this address.
    constructor(
        DividendTokenDeployer tokenDeployer_,
        HookDeployer hookDeployer_,
        address owner_,
        address priceSigner_,
        address platformRecipient_,
        LaunchLpLocker lpLocker_
    ) LaunchpadCore(tokenDeployer_, owner_, priceSigner_, platformRecipient_) {
        hookDeployer = hookDeployer_;
        poolManager = IPoolManager(Chains.venue().poolManager);
        lpLocker = lpLocker_;

        if (lpLocker_.launchpad() != address(this)) revert LockerNotBound(lpLocker_.launchpad());
    }

    /// @inheritdoc LaunchpadCore
    /// @dev **The singleton, and that is the whole reason this matters.** Every v4 pool's tokens sit at one
    ///      address, so excluding it excludes the pool.
    function _tokenCustodian() internal view override returns (address) {
        return address(poolManager);
    }

    /// @inheritdoc LaunchpadCore
    /// @dev **The locker holds the entire supply transiently and would otherwise earn on it forever.** It
    ///      receives every launch token before the mint and keeps the compounding carries afterwards, so an
    ///      unexcluded locker takes a share of every distribution the token ever makes and never claims it —
    ///      diluting every real holder, with no revert anywhere to say so.
    ///
    ///      Appended in an override rather than added to the base list, because `CLLaunchpad` shares that
    ///      list and has no locker: adding a third entry there would put a wrong address into every
    ///      PancakeSwap Infinity launch, and those entries are part of the token's CREATE2 address.
    function _exclusions() internal view override returns (address[] memory list) {
        list = new address[](3);
        list[0] = _tokenCustodian();
        list[1] = address(this);
        list[2] = address(lpLocker);
    }

    /// @inheritdoc LaunchpadCore
    function _open(LaunchParams calldata p, LaunchResult memory result, address beneficiary) internal override {
        PoolKey memory key = _buildKey(p, result.token, result.vault, beneficiary);
        result.hook = address(key.hooks);

        bool tokenIsToken0 = Currency.unwrap(key.currency0) == result.token;
        LaunchMath.LaunchPlan memory plan = _derivePlan(p, result.quoteUsdWad, tokenIsToken0);

        // **Pulled here and forwarded, because the allowance is against this contract.** The launcher
        // approved the launchpad, not the locker, so the quote has to come through here — and it has to be
        // at the locker before `seed`, because the swap settles out of the locker's own balance inside a
        // lock, which is not a place to be pulling tokens through third-party allowances.
        if (p.devBuyQuoteAmount > 0) {
            IERC20(p.quoteToken).safeTransferFrom(msg.sender, address(this), p.devBuyQuoteAmount);
            IERC20(p.quoteToken).safeTransfer(address(lpLocker), p.devBuyQuoteAmount);
        }

        // **Outside the lock, and it has to be.** `initialize` is one of the few pool-manager calls that is
        // not lock-guarded, which is what lets the launchpad open the pool and the locker mint into it in
        // the same transaction without either of them being inside the other's frame.
        poolManager.initialize(key, plan.startSqrtPriceX96);

        // The whole balance rather than `plan.seedRaw`: the token minted its entire supply to this contract
        // and every unit of it is either seeded or burned as dust by the locker. Sending a computed figure
        // instead would leave any difference between the two stranded here, unburned and unaccounted for.
        IERC20(result.token).safeTransfer(address(lpLocker), IERC20(result.token).balanceOf(address(this)));

        lpLocker.seed(key, plan, tokenIsToken0, beneficiary, p.devBuyQuoteAmount);

        // Still correct after the move: it reads `balanceOf(beneficiary)`, and the locker `take`s the first
        // buy straight to the beneficiary rather than through itself.
        _checkDevBuy(p, result.token, plan.seedRaw, beneficiary);

        // No `_burnDust` here any more. The remainder is at the locker, so a balance check against this
        // contract would read zero and stop guarding without saying so; the locker burns its own, under the
        // same bound. `LaunchpadCore` keeps the original for `CLLaunchpad`, which still holds its own supply.

        result.poolId = PoolId.unwrap(key.toId());
        result.realizedMcapUsd = plan.realizedMcapUsd;
    }

    /// @notice Deploys the hook at the mined salt and assembles the pool key around it.
    /// @param p What to launch.
    /// @param token The launch token.
    /// @param sink Where the hook sweeps its tax, which is the token's vault.
    /// @param creator Who the creator's share of every swap belongs to.
    /// @return key The finished key, with the hook in place.
    function _buildKey(LaunchParams calldata p, address token, address sink, address creator)
        private
        returns (PoolKey memory key)
    {
        (address lower, address higher) = _sort(token, p.quoteToken);
        (Currency currency0, Currency currency1) = (Currency.wrap(lower), Currency.wrap(higher));

        address deployed = hookDeployer.deploy(
            p.hookSalt,
            HookDeployer.Params({
                poolManager: poolManager,
                currency0: currency0,
                currency1: currency1,
                lpFee: p.lpFee,
                tickSpacing: p.tickSpacing,
                quote: Currency.wrap(p.quoteToken),
                dividendBps: p.dividendBps,
                creatorBps: p.creatorBps,
                sink: sink,
                creator: creator,
                // Not `msg.sender`: the hook asks this contract where the platform's share goes, and it has
                // to keep asking the same one for the life of the launch.
                launchpad: address(this)
            })
        );

        // Belt and braces: `BaseHook` already refuses to construct at an address whose bits do not match its
        // declared permissions, so reaching here with the wrong flags is impossible. Asserted anyway, because
        // what it guards against is a launch whose pool cannot be swapped through.
        if (uint160(deployed) & Hooks.ALL_HOOK_MASK != HOOK_FLAGS) revert HookSaltWrong(deployed);

        return PoolKey({
            currency0: currency0,
            currency1: currency1,
            fee: p.lpFee,
            tickSpacing: p.tickSpacing,
            hooks: IHooks(deployed)
        });
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 1000000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=node_modules/forge-std/src/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
    "@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/",
    "v4-core/=node_modules/@uniswap/v4-core/",
    "v4-periphery/=node_modules/@uniswap/v4-periphery/",
    "openzeppelin-contracts/contracts/=node_modules/@openzeppelin/contracts/",
    "solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
    "permit2/=node_modules/@uniswap/v4-periphery/lib/permit2/",
    "infinity-core/=node_modules/infinity-core/",
    "base64-sol/=node_modules/base64-sol/",
    "ds-test/=node_modules/infinity-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=node_modules/infinity-core/lib/forge-gas-snapshot/src/",
    "hardhat/=node_modules/hardhat/",
    "pancake-create3-factory/=node_modules/infinity-core/lib/pancake-create3-factory/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.