Flaunch.sol Contract Overview
๐ Overall Contract Architectureโ
Flaunch is an ERC721 NFT contract where each NFT represents a proof of ownership for a Meme coin project. It brings together:
- ERC721: the holder owns the management rights to that Meme coin project
- Cross-chain bridging: supports bridging tokens between Superchain L2s
- Factory pattern: uses the Clone pattern to deploy Memecoin and Treasury contracts
๐ฏ Core Functional Modulesโ
1๏ธโฃ Token Launch System (Flaunch)โ
Function: flaunch(PositionManager.FlaunchParams calldata _params)
Flow:
-
โ Parameter validation
- Check that the launch time does not exceed the maximum schedule duration (30 days)
- Validate that the initial supply is within the allowed range
- Check that the premine amount does not exceed the initial supply
- Validate that the creator fee allocation does not exceed the maximum (100%)
-
๐ซ Mint the ownership NFT
- Mint the ERC721 NFT to the creator (
_params.creator) - Each NFT represents ownership of a Memecoin project
- Mint the ERC721 NFT to the creator (
-
๐ฐ Deploy the Memecoin contract
- Deploy the ERC20 Memecoin using
LibClone.cloneDeterministic - Use
tokenIdas the salt to guarantee a deterministic address - Initialize the token metadata (name, symbol, tokenUri)
- Deploy the ERC20 Memecoin using
-
๐ฆ Deploy the MemecoinTreasury contract
- Deploy the treasury contract using the same salt
- Used to manage the project's funds
-
๐ฆ Mint the initial supply
- Mint
TokenSupply.INITIAL_SUPPLYto thePositionManager - Used for the subsequent fair launch and liquidity provision
- Mint
Key code location: src/contracts/Flaunch.sol:146-192
2๏ธโฃ Cross-chain Bridging Systemโ
Initialize bridging: initializeBridge(uint _tokenId, uint _chainId)โ
Functionality:
- Validate that the destination chain is not the current chain
- Check that bridging has not already been completed
- Prevent re-triggering within the bridging window (1-hour window)
- Fetch the Memecoin metadata
- Send a cross-chain message via the
L2ToL2CrossDomainMessenger
Key code location: src/contracts/Flaunch.sol:334-387
Finalize bridging: finalizeBridge(uint _tokenId, MemecoinMetadata memory _metadata)โ
Functionality:
- Validate the cross-domain message source (can only be triggered by a message sent by itself)
- Deploy the Memecoin on the destination chain using the same salt (tokenId)
- Initialize the metadata, keeping cross-chain addresses consistent
- Mark bridging as completed
Key code location: src/contracts/Flaunch.sol:396-408
Cross-chain flow:
L2-A chain: initializeBridge()
โ
L2ToL2CrossDomainMessenger.sendMessage()
โ
L2-B chain: finalizeBridge() (triggered automatically)
โ
Deploy the Memecoin at the same address
3๏ธโฃ Access Control and Metadataโ
setMemecoinMetadata(address _memecoin, string calldata name_, string calldata symbol_)โ
- Allows the contract owner to fix improper metadata (malicious content, formatting errors, etc.)
setBaseURI(string memory _baseURI)โ
- Updates the base URI of the ERC721 NFT
setMemecoinImplementation(address _memecoinImplementation)โ
- Upgrades the Memecoin implementation contract address
setMemecoinTreasuryImplementation(address _memecoinTreasuryImplementation)โ
- Upgrades the MemecoinTreasury implementation contract address
Key code location: src/contracts/Flaunch.sol:203-239
4๏ธโฃ Query Interfaceโ
memecoin(uint _tokenId) โ addressโ
- Returns the corresponding Memecoin address for a given NFT tokenId
memecoinTreasury(uint _tokenId) โ address payableโ
- Returns the corresponding MemecoinTreasury address for a given NFT tokenId
poolId(uint _tokenId) โ PoolIdโ
- Returns the corresponding Uniswap V4 PoolId for a given NFT tokenId
tokenURI(uint _tokenId) โ stringโ
- Returns the NFT's metadata URI
- If the baseURI is empty, returns the Memecoin's tokenURI
- Otherwise returns
baseURI + tokenId
Key code location: src/contracts/Flaunch.sol:283-307
๐ Security Mechanismsโ
Access Controlโ
onlyPositionManager modifierโ
- Only the
PositionManagercontract can call theflaunch()function - Prevents unauthorized token launches
onlyCrossDomainCallback modifierโ
- Verifies that the message sender must be the
L2ToL2CrossDomainMessenger - Verifies that the cross-domain message source must be the contract itself
- Prevents malicious cross-chain calls
Key code location: src/contracts/Flaunch.sol:413-428
Parameter Limitsโ
uint public constant MAX_FAIR_LAUNCH_TOKENS = TokenSupply.INITIAL_SUPPLY;
uint public constant MAX_CREATOR_ALLOCATION = 100_00; // 100%
uint public constant MAX_SCHEDULE_DURATION = 30 days;
uint public constant MAX_BRIDGING_WINDOW = 1 hours;
๐ Key Design Patternsโ
1. Deterministic Deploymentโ
- Uses
LibClone.cloneDeterministic+tokenIdas the salt - Guarantees the same address across cross-chain deployments
- Facilitates cross-chain state synchronization
2. Proxy Pattern (Clone Pattern)โ
- Every Memecoin and Treasury is a minimal proxy
- Dramatically reduces deployment cost
- Makes unified upgrades easy
3. Ownership NFT Patternโ
- Holding the ERC721 NFT = owning control of the Memecoin project
- Ownership can be transferred
- Facilitates governance and revenue distribution
4. Retry Mechanismโ
- After a bridging failure, it can be retried once the 1-hour window has elapsed
- Prevents a permanently locked state
๐ Data Flow Summaryโ
User โ PositionManager.flaunch()
โ
Flaunch.flaunch()
โโ Mint the ERC721 NFT
โโ Deploy the Memecoin (ERC20)
โโ Deploy the MemecoinTreasury
โโ Mint the initial supply to the PositionManager
ERC721 holder โ initializeBridge()
โ
L2ToL2Messenger
โ
Destination chain finalizeBridge()
โโ Deploy the Memecoin at the same address
๐ Important Eventsโ
TokenBridging(uint _tokenId, uint _chainId, address _memecoin)- bridging startedTokenBridged(uint _tokenId, uint _chainId, address _memecoin, uint _messageSource)- bridging completedBaseURIUpdated(string _newBaseURI)- base URI updatedMemecoinImplementationUpdated(address _newImplementation)- implementation address updatedMemecoinTreasuryImplementationUpdated(address _newImplementation)- treasury implementation address updated
๐ Related Contractsโ
- PositionManager: calls
flaunch()to create a new token - Memecoin: the ERC20 token implementation
- MemecoinTreasury: the treasury contract implementation
- L2ToL2CrossDomainMessenger: Optimism cross-chain message passing
๐ก Design Highlightsโ
- Cross-chain consistency: deterministic deployment guarantees identical addresses across chains
- Cost optimization: the Clone pattern dramatically reduces deployment costs
- Flexible governance: NFT ownership enables transfer of project control
- Secure and reliable: multiple validation mechanisms prevent malicious operations