|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.20; |
| 3 | + |
| 4 | +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
| 5 | +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; |
| 6 | + |
| 7 | +/** |
| 8 | + * @title Trinity Token ($TRI) |
| 9 | + * @notice Green Ternary AI Network Token |
| 10 | + * @dev Total Supply: 3^21 = 10,460,353,203 TRI (Phoenix Number) |
| 11 | + * |
| 12 | + * Tokenomics: |
| 13 | + * - Founder & Team: 20% (2,092,070,640) - 4yr vest, 1yr cliff |
| 14 | + * - Node Rewards: 40% (4,184,141,281) - 10yr vest |
| 15 | + * - Community: 20% (2,092,070,640) - 3yr vest |
| 16 | + * - Treasury: 10% (1,046,035,320) - 5yr vest, 6mo cliff |
| 17 | + * - Liquidity: 10% (1,046,035,320) - Immediate |
| 18 | + * |
| 19 | + * Sacred Formula: phi^2 + 1/phi^2 = 3 (Trinity Identity) |
| 20 | + * KOSCHEI IS IMMORTAL |
| 21 | + */ |
| 22 | +contract TrinityToken is ERC20, ERC20Permit { |
| 23 | + /// @notice Phoenix Number: 3^21 = Total Supply |
| 24 | + uint256 public constant PHOENIX_NUMBER = 10_460_353_203; |
| 25 | + |
| 26 | + /// @notice Total supply with 18 decimals |
| 27 | + uint256 public constant TOTAL_SUPPLY = PHOENIX_NUMBER * 10**18; |
| 28 | + |
| 29 | + /// @notice Golden ratio (scaled by 1e18) |
| 30 | + uint256 public constant PHI_SCALED = 1_618033988749895000; |
| 31 | + |
| 32 | + /// @notice Genesis timestamp |
| 33 | + uint256 public immutable genesisTimestamp; |
| 34 | + |
| 35 | + /// @notice Allocation addresses |
| 36 | + address public immutable founderAddress; |
| 37 | + address public immutable nodeRewardsAddress; |
| 38 | + address public immutable communityAddress; |
| 39 | + address public immutable treasuryAddress; |
| 40 | + address public immutable liquidityAddress; |
| 41 | + |
| 42 | + /// @notice Allocation amounts |
| 43 | + uint256 public constant FOUNDER_ALLOCATION = TOTAL_SUPPLY * 20 / 100; |
| 44 | + uint256 public constant NODE_REWARDS_ALLOCATION = TOTAL_SUPPLY * 40 / 100; |
| 45 | + uint256 public constant COMMUNITY_ALLOCATION = TOTAL_SUPPLY * 20 / 100; |
| 46 | + uint256 public constant TREASURY_ALLOCATION = TOTAL_SUPPLY * 10 / 100; |
| 47 | + uint256 public constant LIQUIDITY_ALLOCATION = TOTAL_SUPPLY * 10 / 100; |
| 48 | + |
| 49 | + /// @notice Vesting tracking |
| 50 | + mapping(address => uint256) public vestingStart; |
| 51 | + mapping(address => uint256) public vestingDuration; |
| 52 | + mapping(address => uint256) public cliffDuration; |
| 53 | + mapping(address => uint256) public totalVested; |
| 54 | + mapping(address => uint256) public claimed; |
| 55 | + |
| 56 | + event AllocationClaimed(address indexed beneficiary, uint256 amount); |
| 57 | + event PhiVerified(uint256 result); |
| 58 | + |
| 59 | + /** |
| 60 | + * @notice Deploy Trinity Token |
| 61 | + * @param _founder Founder & Team address |
| 62 | + * @param _nodeRewards Node Rewards pool address |
| 63 | + * @param _community Community address |
| 64 | + * @param _treasury Treasury address |
| 65 | + * @param _liquidity Liquidity address (receives tokens immediately) |
| 66 | + */ |
| 67 | + constructor( |
| 68 | + address _founder, |
| 69 | + address _nodeRewards, |
| 70 | + address _community, |
| 71 | + address _treasury, |
| 72 | + address _liquidity |
| 73 | + ) ERC20("Trinity", "TRI") ERC20Permit("Trinity") { |
| 74 | + require(_founder != address(0), "Invalid founder"); |
| 75 | + require(_nodeRewards != address(0), "Invalid nodeRewards"); |
| 76 | + require(_community != address(0), "Invalid community"); |
| 77 | + require(_treasury != address(0), "Invalid treasury"); |
| 78 | + require(_liquidity != address(0), "Invalid liquidity"); |
| 79 | + |
| 80 | + genesisTimestamp = block.timestamp; |
| 81 | + |
| 82 | + founderAddress = _founder; |
| 83 | + nodeRewardsAddress = _nodeRewards; |
| 84 | + communityAddress = _community; |
| 85 | + treasuryAddress = _treasury; |
| 86 | + liquidityAddress = _liquidity; |
| 87 | + |
| 88 | + // Setup vesting |
| 89 | + _setupVesting(_founder, FOUNDER_ALLOCATION, 48 * 30 days, 12 * 30 days); |
| 90 | + _setupVesting(_nodeRewards, NODE_REWARDS_ALLOCATION, 120 * 30 days, 0); |
| 91 | + _setupVesting(_community, COMMUNITY_ALLOCATION, 36 * 30 days, 0); |
| 92 | + _setupVesting(_treasury, TREASURY_ALLOCATION, 60 * 30 days, 6 * 30 days); |
| 93 | + |
| 94 | + // Mint liquidity immediately (no vesting) |
| 95 | + _mint(_liquidity, LIQUIDITY_ALLOCATION); |
| 96 | + |
| 97 | + // Verify phi identity on deploy |
| 98 | + _verifyPhiIdentity(); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * @notice Setup vesting for an allocation |
| 103 | + */ |
| 104 | + function _setupVesting( |
| 105 | + address beneficiary, |
| 106 | + uint256 amount, |
| 107 | + uint256 duration, |
| 108 | + uint256 cliff |
| 109 | + ) internal { |
| 110 | + vestingStart[beneficiary] = block.timestamp; |
| 111 | + vestingDuration[beneficiary] = duration; |
| 112 | + cliffDuration[beneficiary] = cliff; |
| 113 | + totalVested[beneficiary] = amount; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @notice Calculate vested amount for an address |
| 118 | + */ |
| 119 | + function vestedAmount(address beneficiary) public view returns (uint256) { |
| 120 | + if (totalVested[beneficiary] == 0) return 0; |
| 121 | + |
| 122 | + uint256 elapsed = block.timestamp - vestingStart[beneficiary]; |
| 123 | + |
| 124 | + // Before cliff |
| 125 | + if (elapsed < cliffDuration[beneficiary]) { |
| 126 | + return 0; |
| 127 | + } |
| 128 | + |
| 129 | + // After full vesting |
| 130 | + if (elapsed >= vestingDuration[beneficiary]) { |
| 131 | + return totalVested[beneficiary]; |
| 132 | + } |
| 133 | + |
| 134 | + // During vesting (linear) |
| 135 | + return (totalVested[beneficiary] * elapsed) / vestingDuration[beneficiary]; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @notice Claim vested tokens |
| 140 | + */ |
| 141 | + function claimVested() external { |
| 142 | + uint256 vested = vestedAmount(msg.sender); |
| 143 | + uint256 claimable = vested - claimed[msg.sender]; |
| 144 | + |
| 145 | + require(claimable > 0, "Nothing to claim"); |
| 146 | + |
| 147 | + claimed[msg.sender] = vested; |
| 148 | + _mint(msg.sender, claimable); |
| 149 | + |
| 150 | + emit AllocationClaimed(msg.sender, claimable); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * @notice Get claimable amount |
| 155 | + */ |
| 156 | + function claimableAmount(address beneficiary) external view returns (uint256) { |
| 157 | + return vestedAmount(beneficiary) - claimed[beneficiary]; |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * @notice Verify phi^2 + 1/phi^2 = 3 (Trinity Identity) |
| 162 | + * @dev Uses scaled integers: phi = 1.618... * 1e18 |
| 163 | + */ |
| 164 | + function _verifyPhiIdentity() internal { |
| 165 | + // phi^2 = 2.618... * 1e18 |
| 166 | + uint256 phiSquared = (PHI_SCALED * PHI_SCALED) / 1e18; |
| 167 | + |
| 168 | + // 1/phi^2 = 0.381... * 1e18 |
| 169 | + uint256 invPhiSquared = (1e36) / phiSquared; |
| 170 | + |
| 171 | + // phi^2 + 1/phi^2 should be ~3 * 1e18 |
| 172 | + uint256 result = phiSquared + invPhiSquared; |
| 173 | + |
| 174 | + // Allow 0.01% tolerance |
| 175 | + require( |
| 176 | + result > 2_999_000_000_000_000_000 && result < 3_001_000_000_000_000_000, |
| 177 | + "Trinity identity failed" |
| 178 | + ); |
| 179 | + |
| 180 | + emit PhiVerified(result); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * @notice Get circulating supply (minted - burned) |
| 185 | + */ |
| 186 | + function circulatingSupply() external view returns (uint256) { |
| 187 | + return totalSupply(); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * @notice Get remaining to vest for an address |
| 192 | + */ |
| 193 | + function remainingVesting(address beneficiary) external view returns (uint256) { |
| 194 | + return totalVested[beneficiary] - vestedAmount(beneficiary); |
| 195 | + } |
| 196 | +} |
0 commit comments