Smart Contract Architecture
ModePad comprises two key smart contracts:
A
LaunchPadFactorycontract; andA
Launchpadcontract
The former acts as a factory, deploying new instances of the latter, which represents individual launchpads.
Let's delve into the architecture of these contracts.
LaunchPadFactory Contract:
constructor:
Purpose: Initializes the contract with the address of the contract owner and registers an NFT with a specific contract.
Technical Details:
Uses the constructor to set the owner's address.
Calls the
Registercontract'sregisterfunction, associating the NFT with the owner.
deploy:
Purpose: Creates a new
Launchpadcontract and initializes it with specified parameters.Technical Details:
Computes the bytecode, salt, and constructor parameters to determine the new contract's address.
Uses assembly code to deploy the contract using
create2.Initializes the newly created contract with the provided parameters.
Updates the
createdLaunchPoolsmapping and emits theLaunchPoolCreatedevent.
View Functions:
getPadAddress:Purpose: Retrieves the address of a specific launchpad.
Technical Details: Accepts a
padNumberparameter and returns the corresponding address from thecreatedLaunchPoolsmapping.
getNoOfLaunchPads:Purpose: Retrieves the total number of launchpads created.
Technical Details: Simply returns the
poolCountvariable.
getPadName:Purpose: Retrieves the name of a specific launchpad.
Technical Details: Accepts the
padAddressparameter and calls thepoolNamefunction from theLaunchpadcontract at the specified address.
getPadDuration:Purpose: Retrieves the duration of a specific launchpad's token sale.
Technical Details: Similar to
getPadName, it calls thesaleDurationInSecondsfunction from the targetedLaunchpadcontract.
getPadMaxCapandgetPadMinCap:Purpose: Retrieves the maximum and minimum investment caps of a specific launchpad.
Technical Details: Similar to previous functions, these retrieve values from the targeted
Launchpadcontract.
getUnsoldTokensAmount:Purpose: Retrieves the amount of unsold tokens for a specific launchpad.
Technical Details: Calls the
getUnsoldTokensfunction from the targetedLaunchpadcontract.
getUserTokenPurchase:Purpose: Retrieves the number of tokens purchased by a specific user for a launchpad.
Technical Details: Calls the
getUserTokenPurchasefunction from the targetedLaunchpadcontract.
getPadPrice:Purpose: Retrieves the token price for a specific launchpad.
Technical Details: Calls the
tokenPricefunction from the targetedLaunchpadcontract.
getPadContractBalance:Purpose: Retrieves the balance of Ether held by a specific launchpad contract.
Technical Details: Calls the
getContractBalancefunction from the targetedLaunchpadcontract.
getPadSaleStatus:Purpose: Retrieves the sale status of a specific launchpad.
Technical Details: Calls the
getIsSaleActivefunction from the targetedLaunchpadcontract.
LaunchPad Contract:
initializer:
Purpose: Initializes the
Launchpadcontract with essential parameters.Technical Details:
Validates that the contract has not been initialized before.
Sets contract parameters and initializes the ERC-20 token contract.
View Functions:
isSaleDurationElapsed:Purpose: Checks if the sale duration has elapsed.
Technical Details: Compares the current timestamp with the sum of the sale start time and duration.
getUserTokenPurchase:Purpose: Retrieves the number of tokens purchased by a specific user.
Technical Details: Calls the
tokensPurchasedmapping.
getUnsoldTokens:Purpose: Retrieves the amount of unsold tokens.
Technical Details: Computes the difference between the contract's total token balance and the total tokens sold.
getContractBalance:Purpose: Retrieves the Ether balance of the contract.
Technical Details: Calls the
balanceproperty of the contract.
getIsSaleActive:Purpose: Retrieves the sale status.
Technical Details: Returns the value of
isSaleActive.
Sale Control Functions:
startSaleandstopSale:Purpose: Start and stop the token sale.
Technical Details: Modify the
isSaleActivestatus and emit events accordingly.
buyTokens:Purpose: Allows users to purchase tokens by sending Ether.
Technical Details:
Validates sale and investment conditions.
Transfers tokens to the buyer and updates investment records.
participateInGame:Purpose: Specialized function for participants with a gas fee consideration.
Technical Details:
Calculates tokens to receive considering gas fees.
Transfers tokens to the participant and updates investment records.
Token Management Functions:
withdrawFunds:Purpose: Allows the owner to withdraw Ether funds from the contract.
Technical Details: Transfers the contract's balance to the owner.
withdrawUnsoldTokens:Purpose: Allows the owner to withdraw unsold tokens after the sale.
Technical Details: Transfers unsold tokens to the owner.
claimTokens:Purpose: Allows users to claim their purchased tokens after the sale.
Technical Details: Transfers purchased tokens to the caller and resets their token purchase record.
Overall Architecture:
LaunchPadFactory acts as a deployer and manager of individual Launchpad contracts, providing functions for deployment, retrieval of launchpad details, and management of associated contracts.
Launchpad represents an individual token sale, managing its own sale lifecycle, user interactions, and token-related operations. It ensures transparent and secure token sales.
This architecture enables secure, controlled, and transparent token sales on ModePad, catering to the diverse needs of both project owners and investors.
Last updated