A gas-optimized, secure smart contract implementation for managing Initial Coin Offerings on the Ethereum blockchain. This contract enables fair token distribution based on proportional bidding mechanisms.
The ICO contract provides a comprehensive solution for token sales with the following features:
- Proportional token distribution based on bid amounts
- Gas-optimized storage and execution
- Two-day fixed duration ICO periods
- Minimum bid requirements
- Secure token and ETH claiming mechanisms
- Comprehensive testing suite
- Owner-controlled start time and token allocation
The contract uses several gas optimization techniques while maintaining security:
- Struct packing for efficient storage
- Strategic use of immutable variables
- Optimized event emissions
- Storage slot management
- Memory caching for repeated operations
To work with this project, you'll need:
- Clone the repository:
git clone https://github.com/yourusername/ico-contract.git
cd ico-contract
- Install dependencies:
forge install
- Build the project:
forge build
- Run tests:
forge test
- Deploy the contract with treasury and token addresses:
constructor(address _treasury, address _tokenAddress)
- Allocate tokens for the ICO:
function allocateTokensForSale(uint256 _amount) external onlyOwner
- Start the ICO:
function startICO() external onlyOwner
- Place a bid:
function placeBid() external payable
- Claim tokens after ICO ends:
function claimTokens() external
The project includes a comprehensive test suite covering all major functionality:
# Run all tests
forge test
# Run tests with gas reporting
forge test --gas-report
# Run specific test
forge test --match-test testPlaceBid
- The contract implements checks for reentrancy and overflow protection
- Bidding and claiming mechanisms are protected against manipulation
- Treasury withdrawal is restricted to owner access
- Token transfers are validated and secured
The contract implements several gas optimization strategies:
-
Storage Packing
- Bid struct uses uint96 for amounts to pack with address
- Strategic use of immutable variables
-
Computation Optimization
- Efficient memory usage
- Optimized loop operations
- Storage cleanup for gas refunds
Please see CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions, please open an issue in the GitHub repository.