Smart Contract Architecture
ModePad comprises two key smart contracts:
A
LaunchPadFactory
contract; andA
Launchpad
contract
The former acts as a factory, deploying new instances of the latter, which represents individual launchpads.
You can find the contracts on ModePad's Contract GitHub Repo
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
Register
contract'sregister
function, associating the NFT with the owner.
deploy
:
Purpose: Creates a new
Launchpad
contract 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
createdLaunchPools
mapping and emits theLaunchPoolCreated
event.
View Functions:
getPadAddress
:Purpose: Retrieves the address of a specific launchpad.
Technical Details: Accepts a
padNumber
parameter and returns the corresponding address from thecreatedLaunchPools
mapping.
getNoOfLaunchPads
:Purpose: Retrieves the total number of launchpads created.
Technical Details: Simply returns the
poolCount
variable.
getPadName
:Purpose: Retrieves the name of a specific launchpad.
Technical Details: Accepts the
padAddress
parameter and calls thepoolName
function from theLaunchpad
contract at the specified address.
getPadDuration
:Purpose: Retrieves the duration of a specific launchpad's token sale.
Technical Details: Similar to
getPadName
, it calls thesaleDurationInSeconds
function from the targetedLaunchpad
contract.
getPadMaxCap
andgetPadMinCap
:Purpose: Retrieves the maximum and minimum investment caps of a specific launchpad.
Technical Details: Similar to previous functions, these retrieve values from the targeted
Launchpad
contract.
getUnsoldTokensAmount
:Purpose: Retrieves the amount of unsold tokens for a specific launchpad.
Technical Details: Calls the
getUnsoldTokens
function from the targetedLaunchpad
contract.
getUserTokenPurchase
:Purpose: Retrieves the number of tokens purchased by a specific user for a launchpad.
Technical Details: Calls the
getUserTokenPurchase
function from the targetedLaunchpad
contract.
getPadPrice
:Purpose: Retrieves the token price for a specific launchpad.
Technical Details: Calls the
tokenPrice
function from the targetedLaunchpad
contract.
getPadContractBalance
:Purpose: Retrieves the balance of Ether held by a specific launchpad contract.
Technical Details: Calls the
getContractBalance
function from the targetedLaunchpad
contract.
getPadSaleStatus
:Purpose: Retrieves the sale status of a specific launchpad.
Technical Details: Calls the
getIsSaleActive
function from the targetedLaunchpad
contract.
LaunchPad Contract:
initializer
:
Purpose: Initializes the
Launchpad
contract 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
tokensPurchased
mapping.
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
balance
property of the contract.
getIsSaleActive
:Purpose: Retrieves the sale status.
Technical Details: Returns the value of
isSaleActive
.
Sale Control Functions:
startSale
andstopSale
:Purpose: Start and stop the token sale.
Technical Details: Modify the
isSaleActive
status 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