Verified contractPartialMIT
HappiV2LaunchEconomics
Address0x8e2ca5bcce5a6fab6550482e83d6801666ee53fd
- 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,192,919
- Creation transaction
- 0x39d19f72a0…4db0660abe
- 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.solmain13.78 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2.48 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol193 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol182 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol216 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.8 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Burnable.sol1.18 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol13.96 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Create2.sol4.37 KB
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/LowLevelCall.sol5.55 KB
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol4.77 KB
- lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol32.66 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/v4-core/src/interfaces/IExtsload.sol1.02 KB
- lib/v4-core/src/interfaces/IExttload.sol699 B
- lib/v4-core/src/interfaces/IHooks.sol8.23 KB
- lib/v4-core/src/interfaces/IPoolManager.sol12.84 KB
- lib/v4-core/src/interfaces/IProtocolFees.sol2.49 KB
- lib/v4-core/src/interfaces/callback/IUnlockCallback.sol488 B
- lib/v4-core/src/interfaces/external/IERC20Minimal.sol3.04 KB
- lib/v4-core/src/interfaces/external/IERC6909Claims.sol3.16 KB
- lib/v4-core/src/libraries/BitMath.sol2.61 KB
- lib/v4-core/src/libraries/CustomRevert.sol5.17 KB
- lib/v4-core/src/libraries/FixedPoint128.sol297 B
- lib/v4-core/src/libraries/FixedPoint96.sol366 B
- lib/v4-core/src/libraries/FullMath.sol5.46 KB
- lib/v4-core/src/libraries/LPFeeLibrary.sol3.6 KB
- lib/v4-core/src/libraries/LiquidityMath.sol742 B
- lib/v4-core/src/libraries/Pool.sol30.04 KB
- lib/v4-core/src/libraries/Position.sol4.81 KB
- lib/v4-core/src/libraries/ProtocolFeeLibrary.sol2.11 KB
- lib/v4-core/src/libraries/SafeCast.sol2.27 KB
- lib/v4-core/src/libraries/SqrtPriceMath.sol14.08 KB
- lib/v4-core/src/libraries/SwapMath.sol6.97 KB
- lib/v4-core/src/libraries/TickBitmap.sol6.27 KB
- lib/v4-core/src/libraries/TickMath.sol12.38 KB
- lib/v4-core/src/libraries/UnsafeMath.sol1.17 KB
- lib/v4-core/src/types/BalanceDelta.sol2.34 KB
- lib/v4-core/src/types/BeforeSwapDelta.sol1.47 KB
- lib/v4-core/src/types/Currency.sol5.46 KB
- lib/v4-core/src/types/PoolId.sol539 B
- lib/v4-core/src/types/PoolKey.sol805 B
- lib/v4-core/src/types/PoolOperation.sol907 B
- lib/v4-core/src/types/Slot0.sol3.4 KB
- lib/v4-periphery/lib/permit2/src/interfaces/IAllowanceTransfer.sol7.7 KB
- lib/v4-periphery/lib/permit2/src/interfaces/IEIP712.sol144 B
- lib/v4-periphery/src/interfaces/IEIP712_v4.sol328 B
- lib/v4-periphery/src/interfaces/IERC721Permit_v4.sol2.14 KB
- lib/v4-periphery/src/interfaces/IImmutableState.sol365 B
- lib/v4-periphery/src/interfaces/IMulticall_v4.sol774 B
- lib/v4-periphery/src/interfaces/INotifier.sol3.2 KB
- lib/v4-periphery/src/interfaces/IPermit2Forwarder.sol1.44 KB
- lib/v4-periphery/src/interfaces/IPoolInitializer_v4.sol782 B
- lib/v4-periphery/src/interfaces/IPositionManager.sol3.93 KB
- lib/v4-periphery/src/interfaces/ISubscriber.sol2.27 KB
- lib/v4-periphery/src/interfaces/IUnorderedNonce.sol799 B
- lib/v4-periphery/src/libraries/LiquidityAmounts.sol3.8 KB
- lib/v4-periphery/src/libraries/PositionInfoLibrary.sol3.92 KB
- src/v2/HappiAntiFarmerProtection.sol3.75 KB
- src/v2/HappiV2BondingCurve.sol34.64 KB
- src/v2/HappiV2GraduationGuard.sol7.67 KB
- src/v2/HappiV2LaunchDeployer.sol9.04 KB
- src/v2/HappiV2LaunchFactory.sol70.04 KB
- src/v2/HappiV2LauncherToken.sol3.75 KB
- src/v2/HappiV2MMVault.sol8.98 KB
- src/v2/HappiV2MMVaultDeployer.sol2.75 KB
- src/v2/hooks/HappiHookFeeBase.sol26.63 KB
- src/v2/interfaces/IHappiDexAdapter.sol3.6 KB
- src/v2/interfaces/IHappiV2GraduationStrategy.sol4.79 KB
- src/v2/interfaces/IHappiV2LaunchLocker.sol933 B
- src/v2/interfaces/ILaunchpadV2.sol7.4 KB
- src/v2/interfaces/ILaunchpadV2Graduation.sol420 B
- src/v2/libraries/HappiAntiFarmerConfig.sol2.53 KB
- src/v2/libraries/HappiV2BondingCurveMath.sol3.53 KB
- src/v2/libraries/HappiV2GraduationMath.sol2.72 KB
- src/v2/libraries/HappiV2GraduationSeedLib.sol11.18 KB
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.