Launchpad
Overview
The Launchpad
contract is designed to facilitate the initial sale and distribution of tokens in a decentralized manner. It incorporates features like vesting, tier-based purchase limits, and support for various payment tokens including stablecoins and ETH.
Key Features
Token Sale Management: Handles the initiation, execution, and completion of token sales.
Vesting Support: Optional vesting of tokens post-purchase to manage distribution over time.
Whitelist Integration: Ensures only whitelisted addresses can participate.
Tier-Based Limits: Implements purchase limits based on the user's tier determined by their weighted average multiplier.
Multi-Token Payments: Supports payments in ETH and various stablecoins, automatically converting them to the base token.
Security: Utilizes OpenZeppelin's security libraries to prevent reentrancy attacks and manage ownership securely.
Contract Details
State Variables
FACTORY
: Address of the factory contract that deployed this launchpad.config
: Address of the configuration contract.isVestingEnabled
: Boolean indicating if vesting is enabled.vesting
: Address of the vesting contract.ETH_ADDRESS
: Placeholder for ETH address.TOKEN
: Address of the token being sold.saleStartTime
: Timestamp for the sale start.saleEndTime
: Timestamp for the sale end.tokenPrice
: Price of one token in terms of the base token.baseToken
: Address of the base token used for payments.totalTokensForSale
: Total number of tokens available for sale.totalTokensSold
: Total number of tokens sold so far.baseAmount
: Base amount for calculating purchase limits.minAmount
: Minimum amount required to participate in the sale.totalAmountRaised
: Total amount of base tokens raised from the sale.totalContributionsCount
: Total number of contributions made.MULTIPLIER_DECIMAL
: Multiplier for adjusting purchase limits.investedAmounts
: Mapping of user addresses to the amount they have invested.claimedTokens
: Mapping of user addresses to the amount of tokens they have claimed.
Modifiers
onlyFactory
: Ensures that only the factory contract can call the function.
Constructor
Initializes the contract with the following parameters:
_owner
: Address of the contract owner._configAddress
: Address of the configuration contract._tokenAddress
: Address of the token being sold._saleStartTime
: Start time of the sale._saleEndTime
: End time of the sale._tokenPrice
: Price of the token._baseToken
: Address of the base token used for payments._totalTokensForSale
: Total tokens available for sale._baseAmount
: Base amount for calculating purchase limits._minAmount
: Minimum amount required to participate._isVestingEnabled
: Boolean indicating if vesting is enabled.
Functions
isSaleActive
: Checks if the sale is currently active.hasSaleEnded
: Returns whether the sale has ended.setVestingContract
: Sets the vesting contract address (only callable by the factory).isWhitelisted
: Checks if a user is whitelisted.getTier
: Determines the tier of a user based on their weighted average multiplier.calculatePurchaseLimit
: Calculates the purchase limit for a user based on their tier.purchaseTokens
: Facilitates the purchase of tokens, accepts payments in ETH or stablecoins._purchaseTokens
: Internal function to handle token purchase logic.withdrawTokens
: Allows the owner to withdraw tokens (excluding base tokens).updateBaseAmount
: Updates the base amount for calculating purchase limits.updateMinAmount
: Updates the minimum amount required to participate.withdrawBaseTokens
: Allows the owner to withdraw the base tokens after the sale ends.sellTokensForStable
: Converts payment tokens to the base token using a DEX aggregator.calculateMinimumReturn
: Calculates the minimum return amount after accounting for slippage.
Events
TokensPurchased
: Emitted when tokens are purchased.TokensWithdrawn
: Emitted when tokens are withdrawn.BaseAmountUpdated
: Emitted when the base amount is updated.MinimumAmountUpdated
: Emitted when the minimum amount is updated.
Usage
Deployment: The contract is deployed by a factory contract which also sets initial parameters.
Purchasing Tokens: Users can purchase tokens by calling the
purchaseTokens
function with the required payment.Managing Sale: The owner can manage sale parameters and withdraw tokens using the provided functions.
Security Considerations
Reentrancy Protection: Utilizes the
ReentrancyGuard
to prevent reentrant calls.Ownership: Secure ownership management using OpenZeppelin's
Ownable
contract.Whitelist Enforcement: Ensures only whitelisted users can participate in the sale.
DEX Aggregation: Uses a DEX aggregator to convert various tokens to the base token securely.
Last updated