Skip to content

Presale is a complete DeFi mini-protocol for launching an ERC20 token, featuring multi-phase sales, ETH and stablecoin payments, Chainlink-based pricing, fee safeguards, and full Foundry test coverage.

Notifications You must be signed in to change notification settings

monipigr/presale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ™ Presale

Presale is a complete mini-protocol for managing the launch of a new ERC20 token, FlyToken. It allows users to buy tokens before they are listed on a DEX, across 3 phases with different prices and time limits, fee and blacklist mechanisms, with secure ETH/USD price conversion via Chainlink. It integrates several smart contracts (Presale, FlyToken, MockAggregator, MockTreasury) working together, everything fully covered by unit, fuzzing, invariant, and mainnet-fork tests on Arbitrum One.

✨ Features

  • πŸͺ™ New ERC20 Token: FlyToken is minted and allocated for sale during the presale.
  • πŸͺ™ Buy with Stablecoins: purchase FlyToken using USDT or USDC.
  • ⚑ Buy with ETH: ETH payments are automatically converted to USD using Chainlink oracles.
  • πŸ”— Chainlink oracle: data feed USDT/ETH price.
  • πŸ“ˆ Phased Presale: configurable supply, price, and duration for each phase.
  • 🚫 Blacklist Mechanism: owner can restrict malicious addresses.
  • πŸ›‘οΈ Claim Period: users claim tokens after the presale ends.
  • πŸ’Έ Fee System: protocol collects fees in both ERC20 and ETH.
  • πŸ”“ Fee Withdrawal: only the owner can withdraw accumulated fees (ERC20 or ETH) after the presale ends.
  • πŸ†˜ Emergency Withdraw: owner can rescue tokens or ETH if needed.

πŸ” Security Measures and Patterns

  • πŸͺ™ SafeERC20: all token transfers use SafeERC20 to handle non-standard ERC20 implementations safely
  • πŸ”‘ Access Control: onlyOwner modifier restricts privileged functions (blacklist, withdrawFees, emergencyWithdraw, etc.)
  • πŸ›‘οΈ Reentrancy Protection: critical functions (buyWithTokens, buyWithETH, claimTokens, withdrawFees) are protected with OpenZeppelin’s ReentrancyGuard
  • πŸ“’ Event Logging: all state mutations emit events (TokensBought, ETHBought, TokensClaimed, FeeWithdrawn, etc.) for transparency and off-chain monitoring
  • 🧩 CEI Pattern: all external functions follow the Checks-Effects-Interactions pattern to minimize vulnerabilities
  • πŸ”— Chainlink Oracle: secure ETH/USD price feed integration prevents manipulation of ETH payments
  • πŸ§ͺ Testing: complete unit tests, fuzzing test, and mocks ensure robustness
  • πŸ”„ Forked Mainnet Testing: validated on Arbitrum One with real USDT, USDC, and Chainlink feeds

πŸ§ͺ Tests

Complete suite test using Foundry, with forked Arbitrum RPC for integration and two mock contracts (MockAggregator.sol for the Chainlink price feed and MockTreasury.sol for ETH/stablecoin receiving).

The suite includes happy paths, negative paths, edge cases, and fuzzing tests to ensure robustness.

  • βœ… buyWithTokens() – happy path, invalid token, zero amount, blacklist, presale inactive, max supply, phase changes
  • βœ… buyWithETH() – happy path, zero amount, blacklist, presale inactive, oracle integration, max supply
  • βœ… claimTokens() – happy path, before claim period, nothing to claim, double claim
  • βœ… blacklist() / unBlacklist() – owner only, reverts for non-owners
  • βœ… withdrawFees() – ERC20 and ETH fees, reverts if not owner or before claim period
  • βœ… emergencyWithdrawTokens() – owner only, reverts for non-owners
  • βœ… emergencyWithdrawETH() – owner only, reverts for non-owners
  • βœ… Fuzzing tests for token and ETH purchases

Run tests with:

forge test --fork-url https://arb1.arbitrum.io/rpc --vvvv --match-test test_buyWithTokens

🧠 Technologies Used

  • βš™οΈ Solidity (^0.8.24) – smart contract programming language
  • πŸ§ͺ Foundry – framework for development, testing, fuzzing, invariants and deployment
  • πŸ“š OpenZeppelin Contracts – ERC20, Ownable, ReentrancyGuard, SafeERC20
  • πŸ”— Chainlink Oracles – secure ETH/USD price feed integration
  • 🌐 Arbitrum One – mainnet fork for realistic testing with live USDT, USDC and Chainlink feeds
  • πŸ› οΈ Mocks – custom MockAggregator and MockTreasury contracts for local testing

πŸ“œ License

This project is licensed under the MIT License.

About

Presale is a complete DeFi mini-protocol for launching an ERC20 token, featuring multi-phase sales, ETH and stablecoin payments, Chainlink-based pricing, fee safeguards, and full Foundry test coverage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published