This project implements a token vesting system for the BTB Token on Optimism Sepolia. It features instant token purchases and vesting schedules represented by NFTs, offering a 50% discount for vested purchases.
- BTB Token:
0xdda696FAbB67F70064e86fC340b19C23225b3EAe
- TokenSale:
0x2B544ac963DC19E8474021edf3C56e5e3FB8D09d
- VestingNFT:
0x48110ef4449A4292172bd6bc88F77dcd507622d9
- BTB Token: Standard ERC20 token
- Instant Purchase: Buy tokens at 0.000001 ETH per token
- Vesting Purchase:
- 50% discount (0.0000005 ETH per token)
- 12-month linear vesting period
- NFT representation of vesting schedule
- NFT Features:
- Represents vesting schedules
- Contains metadata about vesting terms
- Transferable ownership
- Visual representation of vesting status
├── contracts/
│ ├── BTBToken.sol # ERC20 token contract
│ ├── TokenSale.sol # Handles token sales and vesting
│ └── VestingNFT.sol # NFT contract for vesting schedules
├── scripts/
│ ├── deploy-token.ts # Deploys BTB token
│ ├── deploy-token-sale.ts # Deploys sale and NFT contracts
│ ├── check-nft-zero.ts # Checks NFT #0 details
│ ├── claim-vested.ts # Claims vested tokens
│ └── test-all-operations.ts # Tests all main functions
├── test/
│ ├── AdminFunctions.test.ts # Tests admin functions
│ ├── InstantPurchase.test.ts # Tests instant buying
│ ├── VestingPurchase.test.ts # Tests vesting purchases
│ └── helpers.ts # Test helper functions
- Clone the repository
- Install dependencies:
npm install
- Create a
.env
file with the following:
OPTIMISM_SEPOLIA_RPC_URL=https://sepolia.optimism.io
PRIVATE_KEY=your_private_key
OPTIMISM_ETHERSCAN_API_KEY=your_etherscan_api_key
Run all tests:
npx hardhat test
Run specific test files:
npx hardhat test test/InstantPurchase.test.ts
npx hardhat test test/VestingPurchase.test.ts
npx hardhat test test/AdminFunctions.test.ts
- Deploy BTB Token:
npx hardhat run scripts/deploy-token.ts --network optimisticSepolia
- Deploy Sale Contracts:
npx hardhat run scripts/deploy-token-sale.ts --network optimisticSepolia
- Buy Tokens Instantly:
npx hardhat run scripts/test-all-operations.ts --network optimisticSepolia
- Check NFT Details:
npx hardhat run scripts/check-nft-zero.ts --network optimisticSepolia
- Claim Vested Tokens:
npx hardhat run scripts/claim-vested.ts --network optimisticSepolia
// Amount in ETH
const payment = ethers.parseEther("0.000001");
await tokenSale.buyTokensInstant({ value: payment });
// Amount in ETH (50% discount)
const payment = ethers.parseEther("0.0000005");
await tokenSale.buyTokensVesting({ value: payment });
// NFT ID of your vesting schedule
const nftId = 0;
await tokenSale.claimVestedTokens(nftId);
const schedule = await vestingNFT.getVestingSchedule(nftId);
console.log({
totalAmount: ethers.formatEther(schedule.totalAmount),
startTime: new Date(Number(schedule.startTime) * 1000),
endTime: new Date(Number(schedule.endTime) * 1000),
claimedAmount: ethers.formatEther(schedule.claimedAmount),
isActive: schedule.isActive
});
The test suite covers:
- Token deployment and initialization
- Instant purchase functionality
- Vesting purchase and NFT minting
- Vesting schedule calculations
- Token claiming process
- Admin functions and security
- Edge cases and error conditions
- Reentrancy protection using OpenZeppelin's ReentrancyGuard
- Ownable pattern for admin functions
- Safe math operations
- Event emission for tracking
- NFT-based vesting schedule representation
- Linear vesting implementation
MIT