Skip to content

Foundry-based implementation of a secure Initial Coin Offering (ICO) smart contract featuring proportional token distribution, optimized gas usage through strategic storage packing, and extensive test coverage. Built with modern Solidity patterns and best practices for maximum efficiency and security.

License

Notifications You must be signed in to change notification settings

bhivgadearav/InitialCoinOffering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Initial Coin Offering (ICO) Smart Contract

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.

Features

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

Technical Architecture

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

Prerequisites

To work with this project, you'll need:

  • Foundry - Installation instructions can be found in their documentation
  • Solidity ^0.8.0
  • Git

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ico-contract.git
cd ico-contract
  1. Install dependencies:
forge install
  1. Build the project:
forge build
  1. Run tests:
forge test

Usage

Contract Deployment

  1. Deploy the contract with treasury and token addresses:
constructor(address _treasury, address _tokenAddress)
  1. Allocate tokens for the ICO:
function allocateTokensForSale(uint256 _amount) external onlyOwner
  1. Start the ICO:
function startICO() external onlyOwner

Participating in the ICO

  1. Place a bid:
function placeBid() external payable
  1. Claim tokens after ICO ends:
function claimTokens() external

Testing

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

Security Considerations

  • 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

Gas Optimization

The contract implements several gas optimization strategies:

  1. Storage Packing

    • Bid struct uses uint96 for amounts to pack with address
    • Strategic use of immutable variables
  2. Computation Optimization

    • Efficient memory usage
    • Optimized loop operations
    • Storage cleanup for gas refunds

Contributing

Please see CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support and questions, please open an issue in the GitHub repository.

About

Foundry-based implementation of a secure Initial Coin Offering (ICO) smart contract featuring proportional token distribution, optimized gas usage through strategic storage packing, and extensive test coverage. Built with modern Solidity patterns and best practices for maximum efficiency and security.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published