Skip to content
Verified contractPartialMIT

HappiV2LaunchEconomics

Address0x6f0fffa5bd08190aa39fdf967f1910247b3873b7
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.35

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.35+commit.47b9dedd
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,193,156
Creation transaction
0x5a893799af…d6503a1fb6
Main copy (most transactions)
0x8e2ca5bc…66ee53fd
Libraries
src/v2/libraries/HappiGraduationPlanLib.sol:HappiGraduationPlanLib0x3f91…89798esrc/v2/libraries/HappiV2LaunchEconomics.sol:HappiV2LaunchEconomics0x8e2c…ee53fdsrc/v2/libraries/HappiV2GraduationSeedLib.sol:HappiV2GraduationSeedLib0xe965…2da9f8

86 files

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

src/v2/libraries/HappiV2LaunchEconomics.sol

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

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {HappiV2BondingCurveMath} from "./HappiV2BondingCurveMath.sol";
import {HappiV2LaunchFactory} from "../HappiV2LaunchFactory.sol";
import {HappiV2BondingCurve} from "../HappiV2BondingCurve.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SeedContext} from "../interfaces/IHappiV2GraduationStrategy.sol";
import {FeePolicySnapshot, IHappiV2LaunchFactory, GraduationPhase} from "../interfaces/ILaunchpadV2.sol";
import {HappiV2LaunchDeployer, LaunchDeployment} from "../HappiV2LaunchDeployer.sol";
import {IHappiV2GraduationStrategy} from "../interfaces/IHappiV2GraduationStrategy.sol";
import {IHappiDexAdapter} from "../interfaces/IHappiDexAdapter.sol";
import {HappiHookFeeBase} from "../hooks/HappiHookFeeBase.sol";
import {IHappiV2LaunchLocker} from "../interfaces/IHappiV2LaunchLocker.sol";

struct PresetEconomics {
    uint256 phantomQuote;
    uint256 graduationThreshold;
    uint256 startingMarketCap;
    uint256 graduationMarketCap;
}

/// @notice Fixed size multipliers preserve the approved quote asset's curve shape.
/// @dev Linked to keep the factory below the EIP-170 runtime size limit.
library HappiV2LaunchEconomics {
    error InvalidLaunchPreset();
    error InvalidLaunchEconomics();
    error LaunchDependenciesNotWired();

    function scale(uint256 phantom, uint256 threshold, uint256 supply, uint256 feeBps, uint8 presetId)
        external pure returns (PresetEconomics memory terms)
    {
        if (presetId > 2) revert InvalidLaunchPreset();
        uint256 numerator = presetId == 0 ? 1 : presetId == 1 ? 84 : 1600;
        uint256 denominator = presetId == 0 ? 1 : presetId == 1 ? 5 : 49;
        phantom = Math.mulDiv(phantom, numerator, denominator, Math.Rounding.Ceil);
        threshold = Math.mulDiv(threshold, numerator, denominator, Math.Rounding.Ceil);
        uint256 maximum = uint256(uint128(type(int128).max));
        if (phantom == 0 || threshold == 0 || phantom > maximum || threshold > maximum || supply == 0 || supply > maximum) {
            revert InvalidLaunchEconomics();
        }
        uint256 reserved = Math.mulDiv(supply, phantom, phantom + threshold);
        if (reserved == 0 || reserved >= supply ||
            HappiV2BondingCurveMath.quoteAmountOut(phantom / 1_000_000, phantom, supply, feeBps) == 0) {
            revert InvalidLaunchEconomics();
        }
        terms = PresetEconomics(phantom, threshold, phantom, Math.mulDiv(phantom + threshold, supply, reserved));
    }

    function requireWired(
        HappiV2LaunchDeployer deployer, IHappiV2GraduationStrategy strategy, IHappiDexAdapter adapter,
        HappiHookFeeBase hook, IHappiV2LaunchLocker locker, address feeEscrow, address positionManager
    ) external view {
        // Per-strategy core-dependency wiring is checked once in addStrategy, so
        // here it is enough to confirm the default is still present and bound to
        // this factory. A launch that chooses a different approved strategy is
        // held to the same guarantee by that earlier add-time check.
        if (deployer.factory() != address(this) || strategy.factory() != address(this)) {
            revert LaunchDependenciesNotWired();
        }
        // The adapter is the factory's sole DEX caller and the hook's
        // privileged caller in turn, so the wired stack is: adapter bound back
        // to this factory, the hook bound to the adapter, and the adapter's
        // pool manager / fee escrow matching the hook the curve prices against.
        if (adapter.factory() != address(this)) {
            revert LaunchDependenciesNotWired();
        }
        if (adapter.hook() != address(hook) || hook.factory() != address(adapter)) {
            revert LaunchDependenciesNotWired();
        }
        if (locker.factory() != address(this)) {
            revert LaunchDependenciesNotWired();
        }
        // The adapter's own constructor already asserts the hook is bound to the
        // adapter's pool manager (V4: hook.poolManager()==poolManager; Infinity:
        // hook.clPoolManager()==clPoolManager + vault consistency), so the
        // factory only has to confirm the hook shares its fee escrow. Checking
        // hook.poolManager() here would be DEX-specific and is now redundant.
        if (address(hook.feeEscrow()) != address(feeEscrow)) {
            revert LaunchDependenciesNotWired();
        }
        if (adapter.feeEscrow() != address(feeEscrow)) revert LaunchDependenciesNotWired();
        if (locker.positionManager() != address(positionManager)) revert LaunchDependenciesNotWired();
    }
    /// @dev Deployment and initialization run in the factory's delegatecall context.
    function _deploy(
        HappiV2LaunchFactory.TokenParams calldata params, HappiV2LaunchFactory.LaunchRequest memory request,
        HappiV2LaunchFactory.LaunchConfig memory config, FeePolicySnapshot memory policy,
        uint256 phantomQuote, uint256 graduationThreshold, address creatorFeeRecipient
    ) private returns (address token, address curve) {
        HappiV2LaunchFactory factory = HappiV2LaunchFactory(payable(address(this)));
        (token, curve) = factory.launchDeployer().deployLaunch(
            LaunchDeployment({
                antiFarmerDurationDays: params.antiFarmerDurationDays,
                pairToken: request.pairToken,
                creatorFeeRecipient: creatorFeeRecipient,
                originalDeployer: request.originalDeployer,
                feePolicy: factory.hook(),
                policy: policy,
                feeEscrow: factory.feeEscrow(),
                phantomQuote: phantomQuote,
                curveFeeBps: config.curveFeeBps,
                creatorTaxBps: params.creatorTaxBps,
                graduationThreshold: graduationThreshold,
                supply: config.supply,
                salt: params.salt,
                name: params.name,
                symbol: params.symbol,
                logo: params.logo,
                description: params.description,
                socials: params.socials
            })
        );
        HappiV2BondingCurve(curve).initialize(token);

        // The creator's own addresses never count as snipers on their own
        // launch: an atomic dev buy lands in the launch second, exactly when
        // the tax peaks, and would otherwise be consumed by it.
        HappiV2BondingCurve(curve).exemptFromSnipeTax(request.originalDeployer);
        if (creatorFeeRecipient != request.originalDeployer) {
            HappiV2BondingCurve(curve).exemptFromSnipeTax(creatorFeeRecipient);
        }

    }
    /// @notice Shared launch execution. Storage references belong to the factory.
    function launch(
        HappiV2LaunchFactory.TokenParams calldata params, HappiV2LaunchFactory.LaunchRequest memory request,
        mapping(address => IHappiV2LaunchFactory.LaunchedToken) storage _launchedTokens,
        mapping(address => FeePolicySnapshot) storage _launchFeePolicies,
        mapping(address => bool) storage launchMMTokenAllocationEnabled
    ) external returns (address token, address curve) {
        HappiV2LaunchFactory factory = HappiV2LaunchFactory(payable(address(this)));
        if (!factory.canLaunch(request.originalDeployer)) revert HappiV2LaunchFactory.NotWhitelisted();
        if (msg.value != factory.launchFee()) revert HappiV2LaunchFactory.LaunchFeeNotPaid();
        if (request.launchConfigId >= factory.launchConfigCount()) revert HappiV2LaunchFactory.InvalidLaunchConfigId();
        if (params.antiFarmerDurationDays > factory.MAX_ANTI_FARMER_DURATION_DAYS()) revert HappiV2LaunchFactory.InvalidTokenParams();
        if (bytes(params.name).length == 0 || bytes(params.symbol).length == 0) revert HappiV2LaunchFactory.InvalidTokenParams();
        if (params.creatorTaxBps > factory.maxCreatorTaxBps()) revert HappiV2LaunchFactory.CreatorTaxTooHigh();
        if (request.pairToken != address(0) && !factory.approvedPairTokens(request.pairToken)) revert HappiV2LaunchFactory.PairTokenNotApproved();
        if (request.strategyId >= factory.strategyCount() || !factory.strategyApproved(request.strategyId)) revert HappiV2LaunchFactory.StrategyNotApproved();
        IHappiV2GraduationStrategy strategy = factory.getStrategy(request.strategyId);

        HappiV2LaunchFactory.LaunchConfig memory config = factory.getLaunchConfig(request.launchConfigId);
        FeePolicySnapshot memory policy = factory.adapter().currentFeePolicy();
        uint256 phantomQuote = config.phantomQuote;
        uint256 graduationThreshold = config.graduationThreshold;
        if (request.pairToken != address(0)) {
            uint8 decimals;
            (phantomQuote, graduationThreshold, decimals) = factory.pairTokenEconomics(request.pairToken);
            try IERC20Metadata(request.pairToken).decimals() returns (uint8 actual) {
                if (actual != decimals) revert HappiV2LaunchFactory.PairTokenDecimalsMismatch(decimals, actual);
            } catch { revert HappiV2LaunchFactory.PairTokenDecimalsUnavailable(); }
        }
        bytes32 economics;
        if (request.presetId != type(uint8).max) {
            PresetEconomics memory terms;
            (terms, economics) = factory.previewLaunchPreset(request.launchConfigId, request.pairToken, request.presetId);
            phantomQuote = terms.phantomQuote;
            graduationThreshold = terms.graduationThreshold;
        } else {
            economics = factory.previewLaunchEconomics(request.launchConfigId, request.pairToken);
        }
        if (params.expectedEconomics != bytes32(0) && params.expectedEconomics != economics) {
            revert HappiV2LaunchFactory.LaunchEconomicsMismatch(params.expectedEconomics, economics);
        }
        if (!config.enabled) revert HappiV2LaunchFactory.LaunchConfigDisabled();
        // Unreachable while the individual ceilings stay where they are, since
        // each leg caps at 1000 bps against a 2000 bps combined limit. Kept as
        // the check that would actually bind if either ceiling were raised, so
        // the combined limit does not depend on arithmetic between constants
        // declared far apart.
        if (config.curveFeeBps + params.creatorTaxBps > 2_000) {
            revert HappiV2LaunchFactory.CombinedFeeTooHigh();
        }
        if (policy.hookFeeBps + params.creatorTaxBps > 2_000) {
            revert HappiV2LaunchFactory.CombinedFeeTooHigh();
        }
        // A config and a quote asset are validated separately but graduate as
        // a pair, and it is the pair that fixes the seed. The chosen strategy
        // refuses terms that imply a position V4 will not mint here, while the
        // creator still has their fee and nothing has been deployed.
        strategy.assertSeedableTerms(config.tickSpacing, config.supply, phantomQuote, graduationThreshold, request.strategyData);

        address creatorFeeRecipient =
            params.creatorFeeRecipient == address(0) ? request.originalDeployer : params.creatorFeeRecipient;

        (token, curve) = _deploy(params, request, config, policy, phantomQuote, graduationThreshold, creatorFeeRecipient);

        uint16 snapMMQuoteBps = uint16(factory.mmQuoteBps());
        uint16 snapMMFeeShareBps = uint16(factory.mmFeeShareBps());
        if ((snapMMQuoteBps != 0 || snapMMFeeShareBps != 0) && address(factory.mmVaultDeployer()) == address(0)) {
            revert HappiV2LaunchFactory.MMNotWired();
        }

        _launchedTokens[token] = IHappiV2LaunchFactory.LaunchedToken({
            token: token,
            curve: curve,
            deployer: request.originalDeployer,
            creatorFeeRecipient: creatorFeeRecipient,
            pairToken: request.pairToken,
            graduationThreshold: graduationThreshold,
            poolFee: config.poolFee,
            tickSpacing: config.tickSpacing,
            creatorTaxBps: params.creatorTaxBps,
            graduationStrategy: address(strategy),
            strategyData: request.strategyData,
            mmQuoteBps: snapMMQuoteBps,
            mmFeeShareBps: snapMMFeeShareBps,
            mmVault: address(0),
            phase: GraduationPhase.NotGraduated,
            sweptQuote: 0,
            sweptTokens: 0,
            sweptAt: 0,
            exists: true
        });
        if (request.presetId != type(uint8).max) {
            strategy.planSeed(SeedContext({
                token: token, pairToken: request.pairToken, tickSpacing: config.tickSpacing, poolFee: config.poolFee,
                hook: address(factory.hook()), sweptQuote: graduationThreshold,
                sweptTokens: HappiV2BondingCurve(curve).reservedTokens(), phantomQuote: phantomQuote,
                seedScaleBps: uint16(10_000 - snapMMQuoteBps), strategyData: request.strategyData
            }));
        }
        _launchFeePolicies[token] = policy;
        launchMMTokenAllocationEnabled[token] = factory.mmTokenAllocationEnabled();

        // Last, after the launch is fully recorded: this forwards ETH to the
        // protocol recipient, which may be a contract that calls back in.
        if (factory.launchFee() != 0) {
            address recipient = factory.hook().protocolFeeRecipient();
            if (recipient == address(0)) revert HappiV2LaunchFactory.ZeroAddress();
            (bool sent,) = payable(recipient).call{value: factory.launchFee()}("");
            if (!sent) revert HappiV2LaunchFactory.FeeTransferFailed();
        }

        emit HappiV2LaunchFactory.TokenLaunched(token, curve, request.originalDeployer, request.pairToken, request.launchConfigId, graduationThreshold);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {
    "src/v2/libraries/HappiGraduationPlanLib.sol": {
      "HappiGraduationPlanLib": "0x3F919750ae5F337741EF1a2F910812796b89798e"
    },
    "src/v2/libraries/HappiV2LaunchEconomics.sol": {
      "HappiV2LaunchEconomics": "0x8e2CA5BccE5A6fAb6550482E83D6801666EE53fD"
    },
    "src/v2/libraries/HappiV2GraduationSeedLib.sol": {
      "HappiV2GraduationSeedLib": "0xe96581f84E31B0231A52d0F4F5B51a07F82Da9F8"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "@uniswap/v4-hooks-public/=lib/v4-hooks-public/",
    "v4-core/=lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/src/",
    "v4-hooks-public/=lib/v4-hooks-public/src/",
    "permit2/=lib/v4-periphery/lib/permit2/",
    "forge-std/=lib/forge-std/src/",
    "infinity-core/=lib/infinity-core/",
    "infinity-periphery/=lib/infinity-periphery/",
    "solmate/=lib/solmate/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.