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

  1. Token Sale Management: Handles the initiation, execution, and completion of token sales.

  2. Vesting Support: Optional vesting of tokens post-purchase to manage distribution over time.

  3. Whitelist Integration: Ensures only whitelisted addresses can participate.

  4. Tier-Based Limits: Implements purchase limits based on the user's tier determined by their weighted average multiplier.

  5. Multi-Token Payments: Supports payments in ETH and various stablecoins, automatically converting them to the base token.

  6. 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

  1. isSaleActive: Checks if the sale is currently active.

  2. hasSaleEnded: Returns whether the sale has ended.

  3. setVestingContract: Sets the vesting contract address (only callable by the factory).

  4. isWhitelisted: Checks if a user is whitelisted.

  5. getTier: Determines the tier of a user based on their weighted average multiplier.

  6. calculatePurchaseLimit: Calculates the purchase limit for a user based on their tier.

  7. purchaseTokens: Facilitates the purchase of tokens, accepts payments in ETH or stablecoins.

  8. _purchaseTokens: Internal function to handle token purchase logic.

  9. withdrawTokens: Allows the owner to withdraw tokens (excluding base tokens).

  10. updateBaseAmount: Updates the base amount for calculating purchase limits.

  11. updateMinAmount: Updates the minimum amount required to participate.

  12. withdrawBaseTokens: Allows the owner to withdraw the base tokens after the sale ends.

  13. sellTokensForStable: Converts payment tokens to the base token using a DEX aggregator.

  14. 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

  1. Deployment: The contract is deployed by a factory contract which also sets initial parameters.

  2. Purchasing Tokens: Users can purchase tokens by calling the purchaseTokens function with the required payment.

  3. 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