Проверенный контрактЧастичноеUNLICENSED
CoreInitV4
Адрес0x083bfeaeb242d29b6117c370f65eb3ca5555e89e
- Баланс
0 ETH
- Транзакций
0
- Компилятор
solc 0.8.30
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.30+commit.73712a01
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- UNLICENSED
- Совпадение
- Частичноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 399 370
- Транзакция создания
- 0xcc874bdefc…3ddb275cdb
99 файлов
Исходный код большой: показывается один файл. Выберите файл в списке.
- src/v4/bridge/launch/LaunchCoreV4.solглавный50,09 КБ
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3,1 КБ
- lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2,48 КБ
- lib/openzeppelin-contracts/contracts/interfaces/IERC1271.sol653 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4,45 КБ
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol636 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol739 Б
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol881 Б
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6,54 КБ
- lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol6,24 КБ
- lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol472 Б
- lib/openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol6,33 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10,9 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2,78 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Permit.sol2,77 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 Б
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol3,81 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9,44 КБ
- lib/openzeppelin-contracts/contracts/utils/Address.sol6,03 КБ
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 Б
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 Б
- lib/openzeppelin-contracts/contracts/utils/Nonces.sol1,49 КБ
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1,97 КБ
- lib/openzeppelin-contracts/contracts/utils/ReentrancyGuardTransient.sol2,06 КБ
- lib/openzeppelin-contracts/contracts/utils/ShortStrings.sol4,28 КБ
- lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4,18 КБ
- lib/openzeppelin-contracts/contracts/utils/Strings.sol3,93 КБ
- lib/openzeppelin-contracts/contracts/utils/TransientSlot.sol5,07 КБ
- lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol7,82 КБ
- lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol6,61 КБ
- lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol3,7 КБ
- lib/openzeppelin-contracts/contracts/utils/cryptography/SignatureChecker.sol2,34 КБ
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 Б
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol28,31 КБ
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34,94 КБ
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2,61 КБ
- lib/uniswap-v4-core/src/interfaces/IExtsload.sol1,02 КБ
- lib/uniswap-v4-core/src/interfaces/IExttload.sol699 Б
- lib/uniswap-v4-core/src/interfaces/IHooks.sol8,23 КБ
- lib/uniswap-v4-core/src/interfaces/IPoolManager.sol12,84 КБ
- lib/uniswap-v4-core/src/interfaces/IProtocolFees.sol2,49 КБ
- lib/uniswap-v4-core/src/interfaces/callback/IUnlockCallback.sol488 Б
- lib/uniswap-v4-core/src/interfaces/external/IERC20Minimal.sol3,04 КБ
- lib/uniswap-v4-core/src/interfaces/external/IERC6909Claims.sol3,16 КБ
- lib/uniswap-v4-core/src/libraries/BitMath.sol2,61 КБ
- lib/uniswap-v4-core/src/libraries/CustomRevert.sol5,17 КБ
- lib/uniswap-v4-core/src/libraries/FixedPoint128.sol297 Б
- lib/uniswap-v4-core/src/libraries/FixedPoint96.sol366 Б
- lib/uniswap-v4-core/src/libraries/FullMath.sol5,46 КБ
- lib/uniswap-v4-core/src/libraries/Hooks.sol16,51 КБ
- lib/uniswap-v4-core/src/libraries/LPFeeLibrary.sol3,6 КБ
- lib/uniswap-v4-core/src/libraries/LiquidityMath.sol742 Б
- lib/uniswap-v4-core/src/libraries/ParseBytes.sol1,2 КБ
- lib/uniswap-v4-core/src/libraries/Position.sol4,81 КБ
- lib/uniswap-v4-core/src/libraries/SafeCast.sol2,27 КБ
- lib/uniswap-v4-core/src/libraries/SqrtPriceMath.sol14,08 КБ
- lib/uniswap-v4-core/src/libraries/StateLibrary.sol16,03 КБ
- lib/uniswap-v4-core/src/libraries/TickMath.sol12,38 КБ
- lib/uniswap-v4-core/src/libraries/UnsafeMath.sol1,17 КБ
- lib/uniswap-v4-core/src/types/BalanceDelta.sol2,34 КБ
- lib/uniswap-v4-core/src/types/BeforeSwapDelta.sol1,47 КБ
- lib/uniswap-v4-core/src/types/Currency.sol5,46 КБ
- lib/uniswap-v4-core/src/types/PoolId.sol539 Б
- lib/uniswap-v4-core/src/types/PoolKey.sol805 Б
- lib/uniswap-v4-core/src/types/PoolOperation.sol907 Б
- src/FactoryList.sol3,63 КБ
- src/v3/V3Shared.sol9,72 КБ
- src/v3/gap/GapPriceLib.sol4,26 КБ
- src/v4/bridge/BridgeBuyerV4.sol5,41 КБ
- src/v4/bridge/BridgeCodecV4.sol5,82 КБ
- src/v4/bridge/BridgeRoleV4.sol30,82 КБ
- src/v4/bridge/BridgeRowsV4.sol3,32 КБ
- src/v4/bridge/BridgeStateV4.sol16,94 КБ
- src/v4/bridge/CoinCodeRegistryV4.sol7,5 КБ
- src/v4/bridge/CoinDeployerV4.sol5,48 КБ
- src/v4/bridge/CoinPreimageV4.sol2,56 КБ
- src/v4/bridge/ITransportV4.sol1,26 КБ
- src/v4/bridge/PangeaBridgeV4.sol30,22 КБ
- src/v4/bridge/PangeaCoinV4.sol13,15 КБ
- src/v4/bridge/PangeaDeployerV4.sol2,04 КБ
- src/v4/bridge/gap/BridgeGapV4.sol12,63 КБ
- src/v4/bridge/gap/GapOracleV4.sol17,13 КБ
- src/v4/bridge/gap/GapPriceSigV4.sol2,65 КБ
- src/v4/bridge/gap/IGapOracleV4.sol3,86 КБ
- src/v4/bridge/gap/UniV4PoolReaderV4.sol6,78 КБ
- src/v4/bridge/launch/FeeSplitterV4.sol36,57 КБ
- src/v4/bridge/launch/LaunchSettleV4.sol5,14 КБ
- src/v4/bridge/launch/OpenerLiquidityV4.sol11,75 КБ
- src/v4/factory/CodeStoreV4.sol1,43 КБ
- src/v4/gap/GapBlockV4.sol2,16 КБ
- src/v4/gap/GapMathV4.sol35,73 КБ
- src/v4/gap/GapRecorderV4.sol11,51 КБ
- src/v4/gap/IGapRegistryV4.sol20,77 КБ
- src/v4/gap/PangeaOFTV4Storage.sol3,31 КБ
- src/venues/LiquidityLocker.sol23,92 КБ
- src/venues/OpeningDust.sol3,4 КБ
- src/venues/SingleSidedMath.sol4,64 КБ
src/v4/bridge/launch/LaunchCoreV4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
import {Position} from "@uniswap/v4-core/src/libraries/Position.sol";
import {FullMath} from "@uniswap/v4-core/src/libraries/FullMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuardTransient} from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import {IPangeaLaunchHook} from "../../../v3/V3Shared.sol";
import {TermsV3} from "../../../v3/V3Shared.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {LiquidityLocker} from "../../../venues/LiquidityLocker.sol";
import {PangeaBridgeV4} from "../PangeaBridgeV4.sol";
import {BridgeStateV4} from "../BridgeStateV4.sol";
import {BridgeRoleV4} from "../BridgeRoleV4.sol";
import {CoinPreimageV4 as Pre} from "../CoinPreimageV4.sol";
import {CoinDeployerV4} from "../CoinDeployerV4.sol";
import {IPendingConfigV4} from "../PangeaDeployerV4.sol";
import {BridgeBuyerV4} from "../BridgeBuyerV4.sol";
import {SqrtPriceMath} from "@uniswap/v4-core/src/libraries/SqrtPriceMath.sol";
import {SingleSidedMath} from "../../../venues/SingleSidedMath.sol";
import {GapOracleV4} from "../gap/GapOracleV4.sol";
import {UniV4PoolReaderV4} from "../gap/UniV4PoolReaderV4.sol";
import {LaunchSettleV4} from "./LaunchSettleV4.sol";
import {OpenerLiquidityV4} from "./OpenerLiquidityV4.sol";
/// @notice UPGRADEABLE COIN CREATION: the proxy's one-time CREATEs, run by DELEGATECALL from LaunchCoreV4.initialize so
/// they are the PROXY's (nonce 1 = the buyer, PangeaFeeHookV4.buyerOf(core); nonce 2 = the own-liquidity adder),
/// with the proxy as their creator (BridgeBuyerV4.bridge / OpenerLiquidityV4.core). Stateless.
contract CoreInitV4 {
function make(address pm) external returns (BridgeBuyerV4 buyer, OpenerLiquidityV4 liq) {
buyer = new BridgeBuyerV4(pm);
liq = new OpenerLiquidityV4(pm);
}
}
/// @title LaunchCoreV4 -- opens a v4 coin on this chain (first launch or a listed chain later), IMMUTABLE (§11.5)
/// @notice One address on every EVM chain (PangeaDeployerV4; per-chain values from `pending()`). Every open:
/// 1. checks the names against the preimage hashes and deploys PangeaCoinV4 through CoinDeployerV4 (CREATE2,
/// salt = coinId): 1B minted here, once;
/// 2. bridge.registerCoin(pre, token, msg.sender): the bridge checks coinId, rowsHash vs its rows, the listing
/// and the §11.5.3 authorisation (home: the creator; other chains: the creator within 1 h of createdAt,
/// else a home-chain open authorisation naming the caller; never the admin);
/// 3. seeds ALL 1B single-sided from the opener's price (any price) into the locked launch position through
/// the live LiquidityLocker under the live hook (V2 unchanged), with a FeeSplitterV4 whose creator() reads
/// the bridge's role; names the pool as the coin's fallback reader pool;
/// 4. B2-M1: the quote dust the seed owes (token as currency1) is computed EXACTLY on chain (OpeningRouterV4's
/// owedDust: the locker's own maths) and pulled / offered exactly, never a fixed cap;
/// 5. B2-M2: buys on the coin's OFFICIAL pool only (BridgeBuyerV4, same tx, after the seed): the opener's own
/// cash (A2-D3: an opening buy), split dev buys (several recipients) and multi-wallet launch buys -- each a
/// Buy{payer, recipient, quoteAmount, minOut, deadline, nonce, sig}; a payer other than the caller authorises its
/// own buy by an EIP-712 LaunchBuy signature (EOA or ERC-1271; single use; ERC-20 quote pulled from it;
/// BUNDLE-1: a NATIVE quote is paid from the payer's own (payer, nonce) deposit, depositLaunchBuy).
/// Sponsored open (§11.5.3 (a)/(b), the platform-paid launch): `openSponsored` -- the caller (the sponsor) opens
/// as the preimage creator with the creator's EIP-712 authorisation (domain "PangeaOpenV4"/"1"/chainid/this
/// core; SponsoredOpen{coinId, sponsor = msg.sender, argsHash = keccak256(abi.encode(OpenArgs)), deadline}),
/// EOA or ERC-1271 creator; single use; the bridge then applies the creator rules (home any time, another
/// listed chain within 1 h of createdAt). The sponsor pays and receives what the caller receives.
/// Holds nothing after the call; no power over any coin.
/// @notice UPGRADEABLE (owner 2026-11-12): this is the IMPLEMENTATION behind a UUPS ERC1967Proxy (the core every other
/// contract names: bridge.core, the hook / locker factory lists, the coin deployer). Chain values stay immutables
/// of this code (read from the deployer at construction, as before); the proxy's `initialize` CREATEs the buyer
/// (proxy nonce 1: PangeaFeeHookV4.buyerOf(core)) and the own-liquidity adder (nonce 2) into ERC-7201 storage.
/// Upgrades: `upgradeToAndCall` by the bridge's owner (the v4 admin), no delay. A new implementation must keep
/// this storage order (append only). What a core can do to an EXISTING coin is bounded by the immutable bridge
/// and CoinCodeRegistryV4: it can never register a token of its own, re-point or re-open a coin, or mint / burn.
contract LaunchCoreV4 is ReentrancyGuardTransient, UUPSUpgradeable {
using SafeERC20 for IERC20;
using PoolIdLibrary for PoolKey;
uint16 public constant VENUE_UNI_V4 = 1;
uint8 internal constant TOKEN_DECIMALS = 9;
uint256 internal constant Q96 = 0x1000000000000000000000000;
PangeaBridgeV4 public immutable bridge;
CoinDeployerV4 public immutable coinDeployer;
LiquidityLocker public immutable locker;
/// @notice TOKENOMICS-V4: this chain's live v2.4 TokenomicsFactoryV24 (0 = no tokenomics on this chain).
address public immutable tokenomicsFactory;
/// @notice TOKENOMICS-V4 per-chain switch: the coin's vault on THIS chain (0 = off). While on, the coin's and the
/// splitter's creator() name it (the creator share is paid to it), whoever holds the creator role: bound to
/// the coin, never moved by a handover or renounce. On at the open (OpenArgs.tokenomics) or later by the
/// CURRENT non-renounced creator role (enableTokenomics), ONCE (G1d-M1: the creator never re-points a set
/// vault); off only by the platform admin (disableTokenomics; clearTokenomics for a stale-role pin).
/// RULING F2 + F3 (owner 2026-11-08 23:30): the ADMIN may turn it on (adminEnableTokenomics), off and on
/// again at any time, for any coin, renounced or not; nothing is final against the admin.
mapping(bytes32 => address) public tokenomicsOf;
/// @notice G1b-M2: the least gas left before the hook-redeem and the native settle steps.
uint256 public constant SETTLE_GAS_FLOOR = 300_000;
/// @notice G1d-L1: the least gas left before the ERC-20 settle step: FeeSplitterV4._release pays two sides, each
/// needing >= 243,174 left (_payToken), plus a first-time payee's SSTORE; 600k covers both with margin.
uint256 public constant TOKEN_SETTLE_GAS_FLOOR = 600_000;
/// @notice The switch moved (`vault` 0 = off). E4 keys each chain's snapshot / claims start on this block.
/// G-EVML I-1: `by` = who CHOSE the switch: at the open the opener (in a sponsored open the signing creator,
/// not the sponsor who sent the transaction); enableTokenomics the creator role; otherwise the admin.
event TokenomicsSwitched(bytes32 indexed coinId, address indexed token, address vault, address by, uint256 blockNumber, uint256 time);
/// @notice G1d-M1: the admin CLEARED a wrongly pinned vault (a stale-role pin; distinct from off: no settle to the
/// cleared vault). TokenomicsSwitched(vault 0) is emitted with it.
event TokenomicsCleared(bytes32 indexed coinId, address indexed vault, address by);
/// @dev v4-gap-A2 item 3 (A16): each coin's token + splitter on this chain, for the v2.4 tokenomics vault's bind.
mapping(bytes32 => address[2]) internal _launchOf;
IPangeaLaunchHook public immutable hook;
GapOracleV4 public immutable oracle;
address public immutable platform;
uint16 public immutable venueLpShareBps;
/// @notice A2-T (EIP-170): the stateless tokenomics helper this core deploys (vault check + settle steps).
LaunchSettleV4 public immutable switchHelper;
/// @notice LIQ-EVM (owner rule 11-07): the opener's OWN liquidity (openWithLiquidity): the adder this core deploys.
struct Buy {
address payer; // msg.sender (no signature) or a wallet that signed LaunchBuy
address recipient; // receives the coins bought
uint256 quoteAmount;
uint256 minOut;
uint64 deadline; // signed buys only
uint256 nonce; // signed buys only: single use per payer (B3-M1)
bytes sig; // EIP-712 LaunchBuy by `payer` when payer != msg.sender
}
struct OpenArgs {
address quote; // the pool's quote (address(0) native)
int24 tickSpacing;
int24 startTick; // the opener's price (the edge of the single-sided range)
uint256 quotePerTokenE18; // the same price, checked against the tick within toleranceBps
uint16 toleranceBps;
uint16 feeBps; // the hook fee (hook bounds)
Buy[] buys; // after the seed, in order, on the official pool
address tokenomics; // TOKENOMICS-V4: this chain's v2.4 vault (0 = off at the open; the creator may turn it on later)
string metadataURI; // META-EVM (owner Q1 1150, live): the coin's first metadataURI, <= 128 bytes (coin checks); may be empty
}
/// @notice B3-M1: a signed launch buy names WHAT it spends and at WHICH terms: the coin, the quote token, the amount
/// in, the minimum coins out (the price bound), the open terms (`openArgsHash` = openTermsHash(OpenArgs):
/// quote, tickSpacing, startTick, quotePerTokenE18, toleranceBps, feeBps -- the buys excluded), a deadline
/// and a per-payer nonce (single use; the payer may cancel it first, cancelLaunchBuyNonce).
bytes32 public constant LAUNCH_BUY_TYPEHASH = keccak256(
"LaunchBuy(bytes32 coinId,address payer,address recipient,address quote,uint256 quoteAmount,uint256 minOut,bytes32 openArgsHash,uint64 deadline,uint256 nonce)"
);
mapping(address => mapping(uint256 => bool)) public launchBuyNonceUsed;
/// @notice G-EVML L-1: the most gas ONE launch buy may use (signature check incl. an ERC-1271 wallet, the quote's
/// transfers, the swap, the payout; a plain signed buy ~136k, a heavy proxied quote ~380k). A hostile payer
/// or quote burns at most this and only its own buy is skipped.
uint256 public constant LAUNCH_BUY_GAS = 500_000;
/// @dev The least gas left before each buy: the full cap after the 63/64 rule, plus the open's tail. Less: the
/// open REVERTS (LaunchBuyGasShort), so no sender can starve a buy into a silent skip.
uint256 internal constant LAUNCH_BUY_GAS_NEED = (LAUNCH_BUY_GAS * 64) / 63 + 60_000;
// GAP-16e (owner ruling C + v4-buys-choice-0455): NO count cap on the buys of an open. The transaction's gas is the
// only limit (measured: ~136k a signed buy; ~80 fit beside the open in 2^24). The list is the opener's own calldata
// (or the sponsor's), so a longer list costs only its sender; every buy is still its own try/catch.
bytes32 internal constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 public constant SPONSORED_OPEN_TYPEHASH =
keccak256("SponsoredOpen(bytes32 coinId,address sponsor,bytes32 argsHash,uint64 deadline)");
mapping(bytes32 => bool) public sponsoredUsed;
error SponsorExpired(uint64 deadline);
error BadSponsorAuth();
/// @notice The coin opened on this chain. `by` = msg.sender (the sponsor in openSponsored). G-EVML I-2: `first`
/// (name kept for the ABI) means "this chain is the coin's HOME chain" (preimage homePcid == this chain's
/// pcid), NOT "the first chain to open": a coin opened on another chain first still reads true on home.
event Opened(bytes32 indexed coinId, address indexed token, address indexed by, bytes32 poolId, address splitter, int24 startTick, bool first);
/// @notice v4-gap-A2 item 1 (E1, explorer verification): the EXACT ABI-encoded constructor arguments of the coin
/// (PangeaCoinV4: name, symbol, coinId, creatorAtLaunch; CREATE2 by the coin deployer, salt coinId) and of its
/// fee splitter (FeeSplitterV4: factory = this core, bridge, coinId, platform, feeBps at the open,
/// venueLpShareBps, hook; CREATE by this core). The splitter's feeBps can change later (the hook), so its
/// constructor value is only here.
event CoinVerifyArgs(bytes32 indexed coinId, address indexed token, bytes tokenArgs, address splitter, bytes splitterArgs);
error NameMismatch();
error NotTokenomicsVault(address vault);
error TokenomicsAlreadyOn(bytes32 coinId);
error TokenomicsOff(bytes32 coinId);
error NotCurrentCreator();
/// @notice gate-evm2a M-1 (EVM twin of SB8-M1): a nonzero OpenArgs.tokenomics is the CURRENT creator role's choice
/// only (opener == bridge.creatorOf(coinId)); a rule-(c) opener or anyone after a renounce may not name it.
error TokenomicsNotCreators();
/// @notice G1b-M1: the vault's info() owner_ is not the creator who turns it on.
error VaultNotCreators(address vault, address owner);
/// @notice G1b-M2 / G1d-L1: less than the step's gas floor left for a settle step.
error SettleGasTooLow(uint256 left);
error NotAdmin();
error CoinNotOpenHere(bytes32 coinId);
error QuoteIsToken();
error LockedKeyMismatch();
error NativeRefundFailed();
error BadLaunchBuy(uint256 i);
error BuySlippage(uint256 i, uint256 out, uint256 minOut);
error NotSelf();
error LaunchBuyGasShort();
/// @notice B3-I3: a buy that fails (bad / used signature, expired, slippage, the payer's approval or balance gone,
/// the pool refusing) is SKIPPED: nothing of it happened (the payer keeps its quote; native value stays in
/// the core and goes back to the caller at the end); the open itself never reverts for a buy.
event LaunchBuySkipped(bytes32 indexed coinId, uint256 indexed i, address indexed payer, uint256 quoteAmount);
event LaunchBuyDone(bytes32 indexed coinId, uint256 indexed i, address indexed payer, address recipient, uint256 quoteAmount, uint256 tokensOut);
event LaunchBuyNonceCancelled(address indexed payer, uint256 nonce);
constructor() {
address bridge_;
address coinDeployer_;
address hook_;
address oracle_;
(bridge_, coinDeployer_, hook_, oracle_, platform, venueLpShareBps, tokenomicsFactory) =
abi.decode(IPendingConfigV4(msg.sender).pending(), (address, address, address, address, address, uint16, address));
bridge = PangeaBridgeV4(payable(bridge_));
coinDeployer = CoinDeployerV4(coinDeployer_);
hook = IPangeaLaunchHook(hook_);
locker = LiquidityLocker(hook.locker());
_checkHook(hook_);
oracle = GapOracleV4(oracle_);
switchHelper = new LaunchSettleV4(hook_);
_init = new CoreInitV4();
}
/// @dev EIP-170: the buyer / own-liquidity creation codes live in CoreInitV4, run by the proxy's DELEGATECALL.
CoreInitV4 internal immutable _init;
/// @custom:storage-location erc7201:pangea.v4.coreProxy
struct ProxyLayout {
BridgeBuyerV4 buyer;
OpenerLiquidityV4 ownLiquidity;
}
// keccak256(abi.encode(uint256(keccak256("pangea.v4.coreProxy")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PROXY_LAYOUT = 0xdb67c7d4902a7291a5d618ae24a4a339dc26e6ab4f7f3d87be76edadee281200;
error AlreadyInitialized();
function _p() private pure returns (ProxyLayout storage l) {
bytes32 s = PROXY_LAYOUT;
assembly ("memory-safe") {
l.slot := s
}
}
/// @notice Run once by the proxy's constructor: the buyer first (the proxy's nonce 1), then the own-liquidity adder.
function initialize() external onlyProxy {
ProxyLayout storage l = _p();
if (address(l.buyer) != address(0)) revert AlreadyInitialized();
(bool ok, bytes memory r) = address(_init).delegatecall(abi.encodeCall(CoreInitV4.make, (address(locker.poolManager()))));
if (!ok) revert AlreadyInitialized();
(l.buyer, l.ownLiquidity) = abi.decode(r, (BridgeBuyerV4, OpenerLiquidityV4));
}
/// @notice The core's own BridgeBuyerV4 (the proxy's first CREATE).
function buyer() public view returns (BridgeBuyerV4) {
return _p().buyer;
}
/// @notice LIQ-EVM (owner rule 11-07): the opener's OWN liquidity (openWithLiquidity): the adder this core deploys.
function ownLiquidity() public view returns (OpenerLiquidityV4) {
return _p().ownLiquidity;
}
function _authorizeUpgrade(address) internal view override {
if (msg.sender != bridge.owner()) revert NotAdmin();
}
receive() external payable {}
/// @notice PARPORT-1 (live parity U2): the live v3 factory's hook refusal (UniswapLaunchFactoryV3Joiner._allowLaunchHook),
/// same error and rule numbers. N/A here: 2 (the locker IS hook.locker()), 3 (no collector), 6 (no codehash
/// list: deploy verify), 7/9 (tokenomics impl: LaunchSettleV4._requireVault), 8 (retired), 10 (fee bounds:
/// REPLACED by owner "NO COMPILED BOUNDS", V4-INTERFACES.md:162), 11 (no gap registry). The hook's ADDRESS is
/// never pinned: any hook on this pool manager with the live flags (e.g. PangeaFeeHookV4) passes.
error HookRefused(uint256 rule);
/// @dev The allow-time rules, at construction (the hook is immutable): 1 its pool manager is the locker's; 4 its address
/// carries exactly the live flags (TermsV3.HOOK_FLAGS). Rule 5 (isFactory) at each open (_checkHookLists): the
/// hook lists the core only after its deploy.
function _checkHook(address hook_) internal view {
if (address(IPangeaLaunchHook(hook_).poolManager()) != address(locker.poolManager())) revert HookRefused(1);
if ((uint160(hook_) & Hooks.ALL_HOOK_MASK) != TermsV3.HOOK_FLAGS) revert HookRefused(4);
}
/// @dev Rule 5: the hook lists this core (`isFactory`), so it takes `register` from it.
function _checkHookLists() internal view {
if (!hook.isFactory(address(this))) revert HookRefused(5);
}
/// @notice v4-gap-A2 item 3 (A16): the launch record a TokenomicsVaultV24 binds to (ITokenomicsLaunchFactory.launches,
/// launchId = coinId): this chain's coin token and its FeeSplitterV4; launchOwner and liquidity are not
/// used by the bind (0). The vault's other checks hold as for a v3 launch: this core is a factory of the live
/// hook, the hook recorded the pool with this splitter and this core, the splitter's factory is this core, the
/// locker holds the pool's key and position.
function launches(bytes32 launchId)
external
view
returns (address token, address splitter, address launchOwner, address locker_, uint128 liquidity)
{
address[2] memory r = _launchOf[launchId];
return (r[0], r[1], address(0), address(locker), 0);
}
/// @notice The coin's launch id (vault config, Solana leg and FullLaunchSettlerV4 alike).
function launchIdOf(bytes32 coinId) public pure returns (bytes32) {
return keccak256(abi.encodePacked("pangea v4 full launch", coinId));
}
/// @dev A vault of this chain's pinned v2.4 factory, for THIS coin's launch id, owned (info().owner_) by `creator`
/// (G1b-M1: createVault is permissionless, so a vault naming another owner pays the creator share away);
/// `creator` 0 = any owner (the admin's enable, F2 + F3).
function _requireVault(address v, bytes32 coinId, address creator) internal view {
switchHelper.requireVault(tokenomicsFactory, v, launchIdOf(coinId), creator);
}
/// @dev Fees accrued so far are paid out under the payee of the moment (before the switch): G1b-M2 first the claims
/// the hook holds for the official pool (redeem -> the splitter), then the splitter's native and quote
/// balances. G1d-L1: each step has its gas floor; only "nothing owed / to release" is tolerated. Run by the
/// helper (LaunchSettleV4.settle; every target is permissionless), its reverts bubble.
function _settleSplitter(bytes32 coinId) internal {
address[2] memory r = _launchOf[launchIdOf(coinId)];
BridgeStateV4.OfficialPool memory op = BridgeRoleV4(address(bridge)).officialPool(coinId);
switchHelper.settle(r[0], r[1], op.quote, op.tickSpacing);
}
/// @notice TOKENOMICS-V4: the coin's CURRENT creator role turns this chain's tokenomics ON, any time while it holds
/// the role, ONCE (G1d-M1: while set, no creator action re-points it, a handover or a nonce bump included;
/// refused after a renounce, as the role is then 0xdEaD). Its own vault only (G1b-M1). Fees up to now go to
/// the previous payee first. Once on, only the admin turns it off (F2 + F3).
function enableTokenomics(bytes32 coinId, address vault) external nonReentrant {
address token = _tokenHere(coinId);
if (tokenomicsOf[coinId] != address(0)) revert TokenomicsAlreadyOn(coinId);
if (msg.sender != BridgeRoleV4(address(bridge)).creatorOf(coinId)) revert NotCurrentCreator();
_requireVault(vault, coinId, msg.sender);
_switchOn(coinId, token, vault, true);
}
/// @notice RULING F2 + F3: the platform ADMIN (the bridge's owner) turns this chain's tokenomics ON at any time, for
/// any coin open here, renounced or not, off or on (on: re-points the vault). `vault` must still be a vault
/// of the pinned v2.4 factory for THIS coin's launch id (any owner: the admin's choice, e.g. after a
/// renounce). `settle` true: fees up to now go to the payee of the moment first (as enableTokenomics);
/// false: nothing is settled (the held fees go to the payee of the next settle, i.e. the new vault), so a
/// quote whose balanceOf / transfer reverts can never block the admin (as clearTokenomics for off).
function adminEnableTokenomics(bytes32 coinId, address vault, bool settle) external nonReentrant {
if (msg.sender != bridge.owner()) revert NotAdmin();
address token = _tokenHere(coinId);
_requireVault(vault, coinId, address(0));
_switchOn(coinId, token, vault, settle);
}
function _tokenHere(bytes32 coinId) internal view returns (address token) {
token = _launchOf[launchIdOf(coinId)][0];
if (token == address(0)) revert CoinNotOpenHere(coinId);
}
function _switchOn(bytes32 coinId, address token, address vault, bool settle) internal {
if (settle) _settleSplitter(coinId);
tokenomicsOf[coinId] = vault;
emit TokenomicsSwitched(coinId, token, vault, msg.sender, block.number, block.timestamp);
}
/// @notice TOKENOMICS-V4: only the platform admin (the bridge's owner) turns it OFF; fees up to now go to the vault.
function disableTokenomics(bytes32 coinId) external nonReentrant {
_onlyAdminOn(coinId);
_settleSplitter(coinId);
delete tokenomicsOf[coinId];
emit TokenomicsSwitched(coinId, _launchOf[launchIdOf(coinId)][0], address(0), msg.sender, block.number, block.timestamp);
}
/// @notice G1d-M1 remedy for a stale-role pin (G1b-L1): only the platform admin CLEARS a wrongly pinned vault. Not
/// "off": nothing is settled to the cleared vault (fees since the pin stay in the hook / splitter and go to
/// the payee of the next settle, the current creator role). The current creator may then enable again.
function clearTokenomics(bytes32 coinId) external nonReentrant {
address v = _onlyAdminOn(coinId);
delete tokenomicsOf[coinId];
emit TokenomicsCleared(coinId, v, msg.sender);
emit TokenomicsSwitched(coinId, _launchOf[launchIdOf(coinId)][0], address(0), msg.sender, block.number, block.timestamp);
}
function _onlyAdminOn(bytes32 coinId) internal view returns (address v) {
if (msg.sender != bridge.owner()) revert NotAdmin();
v = tokenomicsOf[coinId];
if (v == address(0)) revert TokenomicsOff(coinId);
}
/// @notice The splitters' admin (FeeSplitterV4.admin() reads its factory): the bridge's admin.
function admin() external view returns (address) {
return bridge.owner();
}
function coinIdOf(Pre.Preimage calldata pre) external pure returns (bytes32) {
return Pre.coinId(pre);
}
/// @notice Opens `pre` on this chain (first launch or later), at the caller's price. See the contract notes.
function open(Pre.Preimage calldata pre, string calldata name, string calldata symbol, OpenArgs calldata a)
external
payable
nonReentrant
returns (bytes32 coinId, address token)
{
return _open(_defaults(pre), name, symbol, a, msg.sender, _noLiq());
}
/// @notice ELYHOME ruling B (owner 1047): the tids chain `pcid` has (bit t = transport t; LZ|HL = 6, Elysium HL = 4),
/// set by the admin at deploy like the routes; the defaulted open (_defaults) lists them per chain. 0 = unset.
mapping(uint32 => uint16) public chainTidMask;
error ChainTidsUnset(uint32 pcid);
error TokenAddressEndingWrong(address token);
event ChainTidMaskSet(uint32 indexed pcid, uint16 mask);
/// @notice The admin (the bridge's owner) sets chain `pcid`'s transport availability (bit 0 never; 0 unsets it).
function setChainTidMask(uint32 pcid, uint16 mask) external {
if (msg.sender != bridge.owner()) revert NotAdmin();
if (mask & 1 != 0) revert ChainTidsUnset(pcid);
chainTidMask[pcid] = mask;
emit ChainTidMaskSet(pcid, mask);
}
/// @notice PAUSE-EVM (owner ruling 1155 item 2; live v3 "version stop", LIVE-PARITY U6): while set, every NEW open
/// here (open, openSponsored, openWithLiquidity, the open-later legs: all via _open) reverts OpensPaused().
/// Admin-instant, no timelock. Swaps, bridge sends/receives, claims, launch-buy withdraws, creator handover
/// and everything on coins already open here are untouched.
bool public opensPaused;
error OpensPaused();
event OpensPausedSet(bool paused);
/// @notice The admin (the bridge's owner) pauses / resumes new opens on this core.
function setOpensPaused(bool paused) external {
if (msg.sender != bridge.owner()) revert NotAdmin();
opensPaused = paused;
emit OpensPausedSet(paused);
}
/// @notice LIQ-EVM (owner rule 11-07, v4-open-chain-any-price): `open` (empty `creatorSig`) or `openSponsored`
/// (the creator signs argsHash = keccak256(abi.encode(a, l))) PLUS the opener's own two-sided liquidity `l`
/// in the coin's official pool, in the same tx, after the seed and the buys (OpenerLiquidityV4.add: the
/// coins the caller's OWN unsigned buys delivered to `ownLiquidity` (M-1: any other buy to it, or one in a
/// plain open, is refused, BadLaunchBuy(6)), the quote pulled exactly from the sender -- ERC-20 approved to
/// `ownLiquidity`, native out of msg.value; unused coins and native to l.recipient; the position owned by
/// l.recipient, not locked). Its failure (range, slippage) reverts the open. `open` / `openSponsored`
/// are unchanged except that they refuse a buy to `ownLiquidity`.
function openWithLiquidity(
Pre.Preimage calldata pre,
string calldata name,
string calldata symbol,
OpenArgs calldata a,
OpenerLiquidityV4.OwnLiquidity calldata l,
uint64 deadline,
bytes calldata creatorSig
) external payable nonReentrant returns (bytes32, address) {
if (creatorSig.length == 0) return _open(_defaults(pre), name, symbol, a, msg.sender, l);
(Pre.Preimage memory p, address creator) = _sponsor(pre, keccak256(abi.encode(a, l)), deadline, creatorSig);
return _open(p, name, symbol, a, creator, l);
}
function _noLiq() internal pure returns (OpenerLiquidityV4.OwnLiquidity memory l) {}
/// @notice CDEF (CONTRACT-DEFAULTS spec 1-3): at the HOME open (the create, which fixes the coinId) an empty `chains`
/// becomes every pcid with a route row on this bridge, ascending (> MAX_CHAINS rows: never truncated, the
/// bridge's check refuses it, ListsInvalid(1)); transportMask 0 with chainTids 0 becomes per chain: chains[i]'s
/// tids = chainTidMask[chains[i]] (ELYHOME ruling B), mask = the tids >= 2 chains share; rowsHash 0
/// (only when something was defaulted) = this bridge's rowsHash of the result. Resolved BEFORE hashing: coinId =
/// that of the explicit resolved preimage. Anything given explicitly is kept as given; another chain's open is
/// never resolved (empty: still refused).
function _defaults(Pre.Preimage calldata pre) internal view returns (Pre.Preimage memory p) {
p = pre;
bool dm = p.transportMask == 0 && p.chainTids == 0;
if ((p.chains.length != 0 && !dm) || p.homePcid != bridge.localPcid()) return p;
if (p.chains.length == 0) {
uint32[] memory c = BridgeRoleV4(address(bridge)).pcids();
p.chains = c; // sorted in place below
if (c.length > Pre.MAX_CHAINS) return p; // never truncated: the bridge's Pre.check refuses it, ListsInvalid(1)
for (uint256 i = 1; i < c.length; i++) {
uint32 x = c[i];
uint256 j = i;
for (; j > 0 && c[j - 1] > x; j--) c[j] = c[j - 1];
c[j] = x;
}
}
if (dm) {
// ELYHOME ruling B (owner 1047): each listed chain's tids = its availability (chainTidMask, set by the admin at
// deploy: LZ|HL, HL only on Elysium), whatever this bridge's own adapters; mask = the tids >= 2 chains share
// (1 chain: its own); a chain's tids outside the mask are dropped. Unset availability refuses the default.
uint256 n = p.chains.length;
uint256 seen;
uint256 twice;
for (uint256 i = 0; i < n; i++) {
uint256 x = chainTidMask[p.chains[i]];
if (x == 0) revert ChainTidsUnset(p.chains[i]);
twice |= seen & x;
seen |= x;
}
uint256 m = n > 1 ? twice : seen;
uint256 ct;
for (uint256 i = 0; i < n; i++) {
ct |= (uint256(chainTidMask[p.chains[i]]) & m) << (16 * i);
}
p.transportMask = uint16(m);
p.chainTids = uint128(ct);
}
if (p.rowsHash == bytes32(0)) p.rowsHash = bridge.rowsHash(p.chains, p.transportMask, p.chainTids);
}
/// @notice The EIP-712 digest the creator signs for a sponsored open (see the contract notes).
function sponsoredOpenDigest(bytes32 coinId, address sponsor, bytes32 argsHash, uint64 deadline) public view returns (bytes32) {
bytes32 ds = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("PangeaOpenV4"), keccak256("1"), block.chainid, address(this)));
return keccak256(abi.encodePacked("\x19\x01", ds, keccak256(abi.encode(SPONSORED_OPEN_TYPEHASH, coinId, sponsor, argsHash, deadline))));
}
function openArgsHash(OpenArgs calldata a) public pure returns (bytes32) {
return keccak256(abi.encode(a));
}
/// @notice B3-M1: the open terms a signed LaunchBuy commits to (its `openArgsHash` field): OpenArgs without the buys.
function openTermsHash(OpenArgs calldata a) public pure returns (bytes32) {
return keccak256(abi.encode(a.quote, a.tickSpacing, a.startTick, a.quotePerTokenE18, a.toleranceBps, a.feeBps));
}
/// @notice The payer withdraws a signed launch buy before any open uses it.
function cancelLaunchBuyNonce(uint256 nonce) external {
launchBuyNonceUsed[msg.sender][nonce] = true;
emit LaunchBuyNonceCancelled(msg.sender, nonce);
}
// ------------------------------------------------------------------ BUNDLE-1 (G-EVML M-2, owner ruling C + 0455)
/// @notice BUNDLE-1: native money a wallet set aside for ONE signed native-quote launch buy (payer, nonce). The
/// open's sender (self-launch opener or our sponsor) never holds it: the buy signed with that nonce spends
/// up to its quoteAmount from here, in the open tx. Withdrawable by the payer at ANY time (the launch did not
/// happen, the buy was skipped, cancelled, or partly spent); nothing else can move it.
mapping(address => mapping(uint256 => uint256)) public launchBuyDeposit;
/// @notice BUNDLE-1: all deposits held; an open never spends them for its own native (seed dust, own buys, refund).
/// EIP-170 shave (EVM-ONE): internal (the deposits are readable per (payer, nonce): launchBuyDeposit).
uint256 internal launchBuyDepositTotal;
event LaunchBuyDeposited(address indexed payer, uint256 indexed nonce, uint256 amount, uint256 balance);
event LaunchBuyWithdrawn(address indexed payer, uint256 indexed nonce, address to, uint256 amount);
/// @notice BUNDLE-1: fund my signed native-quote launch buy `nonce` (an unused nonce; adds to it).
/// EIP-170 shave (EVM-ONE): no nonReentrant here (a deposit made inside an open adds the same amount to the balance
/// and to launchBuyDepositTotal, so the open's end check and refund are unchanged); withdraw keeps it.
function depositLaunchBuy(uint256 nonce) external payable {
if (msg.value == 0 || launchBuyNonceUsed[msg.sender][nonce]) revert BadLaunchBuy(4);
uint256 bal = launchBuyDeposit[msg.sender][nonce] + msg.value;
launchBuyDeposit[msg.sender][nonce] = bal;
launchBuyDepositTotal += msg.value;
emit LaunchBuyDeposited(msg.sender, nonce, msg.value, bal);
}
/// @notice BUNDLE-1: take back all of my deposit `nonce` (any time; never during an open: nonReentrant).
function withdrawLaunchBuy(uint256 nonce, address payable to) external nonReentrant {
uint256 amt = launchBuyDeposit[msg.sender][nonce];
if (amt == 0) revert BadLaunchBuy(4); // EIP-170 shave: was NoLaunchBuyDeposit()
delete launchBuyDeposit[msg.sender][nonce];
launchBuyDepositTotal -= amt;
(bool ok,) = to.call{value: amt}("");
if (!ok) revert NativeRefundFailed();
emit LaunchBuyWithdrawn(msg.sender, nonce, to, amt);
}
/// @notice The sponsor (msg.sender) opens `pre` here as its creator, with the creator's signed authorisation.
function openSponsored(
Pre.Preimage calldata pre,
string calldata name,
string calldata symbol,
OpenArgs calldata a,
uint64 deadline,
bytes calldata creatorSig
) external payable nonReentrant returns (bytes32 coinId, address token) {
(Pre.Preimage memory p, address creator) = _sponsor(pre, keccak256(abi.encode(a)), deadline, creatorSig);
return _open(p, name, symbol, a, creator, _noLiq());
}
function _sponsor(Pre.Preimage calldata pre, bytes32 argsHash, uint64 deadline, bytes calldata creatorSig)
internal
returns (Pre.Preimage memory p, address creator)
{
if (block.timestamp > deadline) revert SponsorExpired(deadline);
creator = address(uint160(uint256(pre.creatorEvm)));
if (creator == address(0) || uint256(pre.creatorEvm) >> 160 != 0) revert BadSponsorAuth();
p = _defaults(pre); // CDEF: the creator signs the resolved coinId
bytes32 dg = sponsoredOpenDigest(Pre.coinId(p), msg.sender, argsHash, deadline);
if (sponsoredUsed[dg] || !SignatureChecker.isValidSignatureNow(creator, dg, creatorSig)) revert BadSponsorAuth();
sponsoredUsed[dg] = true;
}
function _open(
Pre.Preimage memory pre,
string calldata name,
string calldata symbol,
OpenArgs calldata a,
address opener,
OpenerLiquidityV4.OwnLiquidity memory l
) internal returns (bytes32 coinId, address token) {
if (opensPaused) revert OpensPaused(); // PAUSE-EVM
// Owner no-name-limits 1200: NO length limit on name / symbol (EVM and Solana); only non-empty (same as Solana's is_empty checks).
if (bytes(name).length == 0 || bytes(symbol).length == 0) revert NameMismatch();
if (keccak256(bytes(name)) != pre.nameHash || keccak256(bytes(symbol)) != pre.symbolHash) revert NameMismatch();
coinId = Pre.coinId(pre);
token = coinDeployer.deploy(coinId, name, symbol, address(uint160(uint256(pre.creatorEvm))), a.metadataURI, pre.createdAt);
// OWNER 6ea (1105): like live, every coin's token address ends in 6ea (the opener grinds pre.salt; one address on
// every EVM chain). Checked on the deployed address: no extra cost on the success path; a revert undoes it.
if ((uint160(token) & 0xfff) != 0x6ea) revert TokenAddressEndingWrong(token);
BridgeRoleV4(address(bridge)).registerCoin(pre, token, opener, BridgeStateV4.OfficialPool(a.quote, 0, a.tickSpacing, address(hook)));
if (a.quote == token) revert QuoteIsToken();
// EIP-170 (EVM-SIZE): `new FeeSplitterV4(this core, bridge, coinId, platform, feeBps, venueLpShareBps, hook)` runs
// in the helper's code by DELEGATECALL, so the core still CREATEs the splitter (same address, nonce, arguments).
(bool sok, bytes memory sr) = address(switchHelper).delegatecall(
abi.encodeCall(LaunchSettleV4.newSplitter, (address(bridge), coinId, platform, a.feeBps, venueLpShareBps))
);
if (!sok) {
assembly ("memory-safe") {
revert(add(sr, 32), mload(sr))
}
}
address splitter = abi.decode(sr, (address));
_launchOf[launchIdOf(coinId)] = [token, splitter];
if (a.tokenomics != address(0)) {
// gate-evm2a M-1: only the current creator role picks the payee (0xdEaD after a renounce: always refused);
// a sponsored open passes the signing creator as opener (its signature covers a.tokenomics).
if (opener != BridgeRoleV4(address(bridge)).creatorOf(coinId)) revert TokenomicsNotCreators();
_requireVault(a.tokenomics, coinId, opener);
tokenomicsOf[coinId] = a.tokenomics;
emit TokenomicsSwitched(coinId, token, a.tokenomics, opener, block.number, block.timestamp);
}
emit CoinVerifyArgs(
coinId,
token,
abi.encode(name, symbol, coinId, address(uint160(uint256(pre.creatorEvm)))),
splitter,
abi.encode(address(this), address(bridge), coinId, platform, a.feeBps, venueLpShareBps, address(hook))
);
bool tokenIs0 = token < a.quote;
PoolKey memory key = PoolKey({
currency0: Currency.wrap(tokenIs0 ? token : a.quote),
currency1: Currency.wrap(tokenIs0 ? a.quote : token),
fee: 0,
tickSpacing: a.tickSpacing,
hooks: IHooks(address(hook))
});
_checkHookLists();
hook.register(key, splitter, !tokenIs0, a.feeBps, a.startTick);
bytes32 lockedKey = _seed(key, token, splitter, a, tokenIs0);
oracle.setCoinVenue(token, VENUE_UNI_V4, abi.encode(UniV4PoolReaderV4.PoolRef(a.quote, 0, a.tickSpacing, address(hook), lockedKey)));
bytes32 terms = openTermsHash(a);
for (uint256 i = 0; i < a.buys.length; i++) {
Buy calldata b = a.buys[i];
// LIQ-EVM M-1: coins bought TO the own-liquidity helper only by the caller's own (unsigned) buy, and only in
// an open that adds own liquidity (else another opener could take a signed buy's coins, or they would strand)
if (b.recipient == address(ownLiquidity()) && (l.recipient == address(0) || b.payer != msg.sender)) revert BadLaunchBuy(6);
if (gasleft() < LAUNCH_BUY_GAS_NEED) revert LaunchBuyGasShort();
try this.launchBuy{gas: LAUNCH_BUY_GAS}(coinId, key, token, a.quote, terms, b, msg.sender) returns (uint256 out) {
emit LaunchBuyDone(coinId, i, b.payer, b.recipient, b.quoteAmount, out);
} catch {
emit LaunchBuySkipped(coinId, i, b.payer, b.quoteAmount);
}
}
// LIQ-EVM: the opener's own liquidity, after the buys (l.recipient 0: none; nothing below changes then)
if (l.recipient != address(0)) {
uint256 v = a.quote == address(0) ? l.quoteAmount : 0;
if (address(this).balance < launchBuyDepositTotal + v) revert BadLaunchBuy(5); // never the deposits
ownLiquidity().add{value: v}(key, token, a.startTick, l, msg.sender);
}
// BUNDLE-1: the deposits stay; the sender gets back only its own unspent native (and never spent theirs).
uint256 bal = address(this).balance;
if (bal < launchBuyDepositTotal) revert BadLaunchBuy(5); // EIP-170 shave: was NativeShort(balance, deposits)
uint256 left = bal - launchBuyDepositTotal;
if (left != 0) {
(bool ok,) = msg.sender.call{value: left}("");
if (!ok) revert NativeRefundFailed();
}
emit Opened(coinId, token, msg.sender, keccak256(abi.encode(key)), splitter, a.startTick, pre.homePcid == bridge.localPcid());
}
function _seed(PoolKey memory key, address token, address splitter, OpenArgs calldata a, bool tokenIs0)
internal
returns (bytes32 lockedKey)
{
lockedKey = Position.calculatePositionKey(
address(locker),
tokenIs0 ? a.startTick : TickMath.minUsableTick(a.tickSpacing),
tokenIs0 ? TickMath.maxUsableTick(a.tickSpacing) : a.startTick,
keccak256(abi.encode(key))
);
uint256 supply = IERC20(token).balanceOf(address(this));
uint256 dust = tokenIs0 ? 0 : owedDust(supply, a.startTick, a.tickSpacing);
uint256 nativeOffer;
bool assetDust = dust != 0 && a.quote != address(0);
if (dust != 0) {
if (a.quote == address(0)) {
nativeOffer = dust;
} else {
_pullDust(a.quote, dust);
IERC20(a.quote).forceApprove(address(locker), dust);
}
}
IERC20(token).safeTransfer(address(locker), supply);
uint256 target = _targetPriceX96(token, a.quote, _quoteDecimals(a.quote), a.quotePerTokenE18);
locker.seed{value: nativeOffer}(key, token, splitter, supply, a.startTick, target, a.toleranceBps);
if (assetDust) {
IERC20(a.quote).forceApprove(address(locker), 0);
uint256 back = IERC20(a.quote).balanceOf(address(this));
if (back != 0) IERC20(a.quote).safeTransfer(msg.sender, back);
}
if (locker.positionKey(key.toId()) != lockedKey) revert LockedKeyMismatch();
}
/// @dev G-EVML M-1 (ruling E: any quote, fee-on-transfer / taxed included): the core must HOLD `dust` when the
/// live locker pulls it (LiquidityLocker._addLiquidity: safeTransferFrom(core, PM, dust) + settle). It pulls
/// `dust`, measures what arrived and pulls the shortfall again (doubling, at most 4 pulls) while it holds
/// less; a plain ERC-20 is ONE exact pull as before. Anything over `dust` goes back to the payer after the
/// seed. LIMIT (the live locker, immutable): a quote that also taxes the core -> PoolManager transfer leaves
/// the PM short and the open reverts there; such quotes open with the coin sorting BELOW the quote (dust 0),
/// which the web / SDK grind the preimage salt for.
function _pullDust(address q, uint256 dust) internal {
uint256 ask = dust;
for (uint256 k = 1; k <= 4; k++) {
IERC20(q).safeTransferFrom(msg.sender, address(this), ask);
uint256 have = IERC20(q).balanceOf(address(this));
if (have >= dust) return;
ask = (dust - have) << k;
}
}
/// @notice B2-M1: the exact quote (base units) a currency1 opening owes the pool: what LiquidityLocker.seed and
/// the PoolManager make of `supply` at `startTick` (OpeningRouterV4.owedDust, unchanged).
function owedDust(uint256 supply, int24 startTick, int24 tickSpacing) public pure returns (uint256) {
uint160 upper = TickMath.getSqrtPriceAtTick(startTick);
uint160 price = upper - 1;
uint128 liquidity = SingleSidedMath.liquidityForToken1(TickMath.getSqrtPriceAtTick(TickMath.minUsableTick(tickSpacing)), price, supply);
return SqrtPriceMath.getAmount0Delta(price, upper, liquidity, true);
}
/// @notice The EIP-712 digest a payer signs for a launch buy (domain "PangeaOpenV4"/"1"/chainid/this core).
function launchBuyDigest(
bytes32 coinId,
address payer,
address recipient,
address quote,
uint256 quoteAmount,
uint256 minOut,
bytes32 openArgsHash_,
uint64 deadline,
uint256 nonce
) public view returns (bytes32) {
bytes32 ds = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("PangeaOpenV4"), keccak256("1"), block.chainid, address(this)));
bytes32 sh = keccak256(abi.encode(LAUNCH_BUY_TYPEHASH, coinId, payer, recipient, quote, quoteAmount, minOut, openArgsHash_, deadline, nonce));
return keccak256(abi.encodePacked("\x19\x01", ds, sh));
}
/// @notice This core only (the open's try/catch, B3-I3): one buy on the official pool -- the caller's own (opening
/// buy / dev buy, native or ERC-20) or a signed launch buy of another wallet (ERC-20 only, pulled from that
/// wallet; B3-M1: the signature binds the quote, amount, minOut, the open terms, deadline and nonce).
/// Unspent quote back to the payer. Reverts on any failure (the open then skips this buy).
function launchBuy(bytes32 coinId, PoolKey calldata key, address token, address quote, bytes32 terms, Buy calldata b, address caller)
external
returns (uint256 out)
{
if (msg.sender != address(this)) revert NotSelf();
if (b.quoteAmount == 0 || b.recipient == address(0)) revert BadLaunchBuy(0);
if (b.payer != caller) {
if (block.timestamp > b.deadline || launchBuyNonceUsed[b.payer][b.nonce]) revert BadLaunchBuy(1);
// BUNDLE-1: a native buy is paid from the payer's (payer, nonce) deposit; checked before the signature.
uint256 dep = launchBuyDeposit[b.payer][b.nonce];
if (quote == address(0) && dep < b.quoteAmount) revert BadLaunchBuy(3);
bytes32 dg = launchBuyDigest(coinId, b.payer, b.recipient, quote, b.quoteAmount, b.minOut, terms, b.deadline, b.nonce);
if (!SignatureChecker.isValidSignatureNow(b.payer, dg, b.sig)) revert BadLaunchBuy(2);
launchBuyNonceUsed[b.payer][b.nonce] = true;
if (quote == address(0)) {
launchBuyDeposit[b.payer][b.nonce] = dep - b.quoteAmount; // the rest stays withdrawable
launchBuyDepositTotal -= b.quoteAmount;
}
} else if (quote == address(0) && address(this).balance < launchBuyDepositTotal + b.quoteAmount) {
revert BadLaunchBuy(3); // BUNDLE-1: the caller's own native buy never spends other wallets' deposits
}
if (quote != address(0)) IERC20(quote).safeTransferFrom(b.payer, address(buyer()), b.quoteAmount);
uint256 bal = IERC20(token).balanceOf(address(this));
buyer().buy{value: quote == address(0) ? b.quoteAmount : 0}(key, token, b.quoteAmount, b.payer);
out = IERC20(token).balanceOf(address(this)) - bal;
if (out < b.minOut) revert BuySlippage(0, out, b.minOut);
IERC20(token).safeTransfer(b.recipient, out);
}
function _quoteDecimals(address quote) internal view returns (uint8) {
if (quote == address(0)) return 18;
return IERC20Decimals(quote).decimals();
}
/// @dev LaunchFactoryBaseV4._targetPriceX96, unchanged: the opener's price as the locker checks it.
function _targetPriceX96(address token, address quote, uint8 quoteDecimals, uint256 quotePerToken) internal pure returns (uint256) {
uint256 tokenUnit = 10 ** TOKEN_DECIMALS;
uint256 quoteUnit = 10 ** quoteDecimals;
if (token < quote) return FullMath.mulDiv(quotePerToken * quoteUnit, Q96, 1e18 * tokenUnit);
return FullMath.mulDiv(1e18 * tokenUnit, Q96, quotePerToken * quoteUnit);
}
}
interface IERC20Decimals {
function decimals() external view returns (uint8);
}
Настройки компилятораПоказать
{
"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/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.