🔥
BurnHookBNB Chain

Contract Source

Full source of every core contract, identical to the version deployed and verified on BscScan. All contracts are non-upgradeable with no admin after launch.

src/BurnToken.sol

BURN token: fair mint, referrals, dev share, refunds, pre-trading transfer lock

351 linessolc 0.8.26 · via-ir · optimizer 200sha256 e50eb01d19148874…On-chain 0x2A81F0A9406f6dCef691bF6Ba78524b520Fd0093 · BscScan ↗ · Sourcify (verified source) ↗
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.26;
3
4import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
6import {Address} from "@openzeppelin/contracts/utils/Address.sol";
7import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
8import {IBurnToken} from "./interfaces/IBurnToken.sol";
9
10/// @title BurnToken
11/// @notice Fair Launch token + automatic pool creation + refund on failure + two-tier referral rewards
12/// @dev The single deployer relinquishes all privileges right after launch, fully autonomous thereafter
13contract BurnToken is ERC20, ReentrancyGuard, IBurnToken {
14 using Address for address payable;
16 // ============ Constants ============
18 uint256 public constant TOTAL_SUPPLY = 21_000_000 ether;
19 uint256 public constant MINT_AMOUNT = 1_000 ether;
20 uint256 public constant MINT_PRICE = 0.005 ether;
21 uint256 public constant MAX_MINTS = 14_000;
22 uint256 public constant MAX_MINTS_PER_WALLET = 100;
23 uint256 public constant MINT_DURATION = 3 days;
24 uint256 public constant LP_RESERVE = 7_000_000 ether; // TOTAL_SUPPLY - MAX_MINTS * MINT_AMOUNT
26 // Referral rewards
27 uint256 public constant DIRECT_REWARD_BPS = 1000; // 10%
28 uint256 public constant INDIRECT_REWARD_BPS = 500; // 5%
29 uint256 public constant BPS_DENOM = 10000;
30 uint256 public constant MIN_MINTS_TO_INVITE = 10;
32 // Dev share: 20% of every mint, withdrawable to DEV only after MINT_SUCCESS (voided on MINT_FAILED)
33 uint256 public constant DEV_REWARD_BPS = 2000; // 20%
35 uint256 public immutable override BLOCK_DELAY;
37 /// @notice Binance Agent ID (.ai identity, SPACE ID soulbound ERC721). Every minter must hold one;
38 /// address(0) disables the gate (local / non-BSC deployments).
39 address public immutable override AGENT_ID;
41 /// @notice Recipient of the dev share. Fixed at deploy time, cannot be changed.
42 address public immutable override DEV;
44 address public constant DEAD = 0x000000000000000000000000000000000000dEaD;
46 // ============ State ============
48 address public deployer; // Only valid before startMint; set to zero afterwards
49 address public bonder; // Contract (BurnHook) responsible for finalize/pool creation; set once by deployer before startMint
51 uint256 public override mintStartTime;
52 uint256 public override mintCount;
53 uint256 public override ethRaised;
54 uint256 public override bondedBlock;
56 Phase private _phase;
58 mapping(address => uint256) public override mintsOf;
60 // Referral / promotion
61 address public override firstMinter; // The first account to mint; has no inviter
62 mapping(address => address) public override inviter; // user → inviter (recorded on first mint, immutable afterwards)
63 mapping(address => uint256) public override referralReward; // user → accrued withdrawable reward (wei)
64 uint256 public override totalReferralReward; // Global total, used to reserve ETH at finalize
66 // Dev share (accrued per mint, reserved at finalize, withdrawable after MINT_SUCCESS)
67 uint256 public override devReward;
69 // ============ Errors ============
71 error NotDeployer();
72 error AlreadyStarted();
73 error AlreadyBonderSet();
74 error BonderNotSet();
75 error NotMinting();
76 error MintEnded();
77 error MintNotEnded();
78 error WrongValue();
79 error WalletLimit();
80 error SoldOut();
81 error NotFailed();
82 error InvalidAmount();
83 error InsufficientBalance();
84 error NotBonder();
85 error AlreadyBonded();
86 error TransfersLocked();
87 error TransferFailed();
88 // Referral-related
89 error InviterRequired();
90 error InviterNotQualified();
91 error SelfInvite();
92 error AgentIdRequired();
93 error NoReward();
94 error RewardNotAvailable();
96 // ============ Constructor ============
98 constructor(uint256 _blockDelay, address _agentId, address _dev) ERC20("Burn Hook", "BURN") {
99 require(_dev != address(0), "dev=0");
100 deployer = msg.sender;
101 DEV = _dev;
102 BLOCK_DELAY = _blockDelay;
103 AGENT_ID = _agentId;
104 _phase = Phase.PENDING;
105 }
107 function setBonder(address _bonder) external {
108 if (msg.sender != deployer) revert NotDeployer();
109 if (bonder != address(0)) revert AlreadyBonderSet();
110 require(_bonder != address(0), "bonder=0");
111 bonder = _bonder;
112 }
114 // ============ Phase Logic ============
116 function currentPhase() public view override returns (Phase) {
117 Phase p = _phase;
118 if (p == Phase.MINT_FAILED) return Phase.MINT_FAILED;
119 if (p == Phase.MINTING) {
120 if (block.timestamp >= mintStartTime + MINT_DURATION) return Phase.MINT_FAILED;
121 return Phase.MINTING;
122 }
123 if (p == Phase.BONDED) {
124 if (block.number >= bondedBlock + BLOCK_DELAY) return Phase.TRADING;
125 return Phase.BONDED;
126 }
127 return p;
128 }
130 // ============ Deployer: startMint ============
132 function startMint() external override {
133 if (msg.sender != deployer) revert NotDeployer();
134 if (_phase != Phase.PENDING) revert AlreadyStarted();
135 if (bonder == address(0)) revert BonderNotSet();
136 _phase = Phase.MINTING;
137 mintStartTime = block.timestamp;
138 deployer = address(0);
139 emit MintStarted(block.timestamp, block.timestamp + MINT_DURATION);
140 }
142 // ============ Mint ============
144 /// @notice Mint one batch of BURN at a time (0.005 ETH → 1000 BURN).
145 /// - The first mint (mintCount==0) requires no inviter; that account becomes `firstMinter` and never has an inviter
146 /// - firstMinter's subsequent mints also require no inviter
147 /// - Any other account's first mint **must** pass a valid inviter who has already minted at least 10 times
148 /// - For an account that already has a recorded inviter, subsequent mints ignore any value passed (0 or otherwise)
149 /// - Every minter (firstMinter included) must hold a Binance Agent ID when AGENT_ID is set
150 function mint(address inviterAddr) external payable override nonReentrant {
151 Phase p = currentPhase();
152 if (p != Phase.MINTING) {
153 if (p == Phase.MINT_FAILED && _phase == Phase.MINTING) {
154 _phase = Phase.MINT_FAILED;
155 emit MintFailed(mintCount);
156 }
157 revert NotMinting();
158 }
160 if (!hasAgentId(msg.sender)) revert AgentIdRequired();
161 if (msg.value != MINT_PRICE) revert WrongValue();
162 if (mintsOf[msg.sender] >= MAX_MINTS_PER_WALLET) revert WalletLimit();
163 if (mintCount >= MAX_MINTS) revert SoldOut();
165 // ─── Inviter logic ───
166 if (mintCount == 0) {
167 // The very first mint ever: this account becomes firstMinter, the inviter field is ignored
168 firstMinter = msg.sender;
169 } else if (msg.sender != firstMinter && inviter[msg.sender] == address(0)) {
170 // Not firstMinter and this account has no recorded inviter yet → require a valid inviter
171 if (inviterAddr == address(0)) revert InviterRequired();
172 if (inviterAddr == msg.sender) revert SelfInvite();
173 if (mintsOf[inviterAddr] < MIN_MINTS_TO_INVITE) revert InviterNotQualified();
174 inviter[msg.sender] = inviterAddr;
175 emit InviterSet(msg.sender, inviterAddr);
176 }
177 // else: firstMinter minting again, or user already has a recorded inviter → no check needed
179 mintsOf[msg.sender] += 1;
180 unchecked {
181 mintCount += 1;
182 ethRaised += msg.value;
183 }
185 _mint(msg.sender, MINT_AMOUNT);
186 emit Minted(msg.sender, MINT_AMOUNT, mintCount);
188 // ─── Accrue dev share (bookkeeping only, withdrawable after MINT_SUCCESS) ───
189 unchecked { devReward += (msg.value * DEV_REWARD_BPS) / BPS_DENOM; }
191 // ─── Accrue referral rewards (bookkeeping only, withdrawable after MINT_SUCCESS) ───
192 address direct = inviter[msg.sender];
193 if (direct != address(0)) {
194 uint256 directReward = (msg.value * DIRECT_REWARD_BPS) / BPS_DENOM;
195 referralReward[direct] += directReward;
196 unchecked { totalReferralReward += directReward; }
197 emit ReferralRewardAccrued(direct, msg.sender, directReward, true);
199 address indirectAddr = inviter[direct];
200 if (indirectAddr != address(0)) {
201 uint256 indirectReward = (msg.value * INDIRECT_REWARD_BPS) / BPS_DENOM;
202 referralReward[indirectAddr] += indirectReward;
203 unchecked { totalReferralReward += indirectReward; }
204 emit ReferralRewardAccrued(indirectAddr, msg.sender, indirectReward, false);
205 }
206 }
208 if (mintCount == MAX_MINTS) {
209 _phase = Phase.MINT_SUCCESS;
210 }
211 }
213 /// @notice Inviter withdraws accrued rewards, **callable only during MINT_SUCCESS / BONDED / TRADING phases**;
214 /// locked during MINTING; permanently voided on MINT_FAILED (funds return to the refund pool).
215 function withdrawReferralReward() external override nonReentrant {
216 Phase p = currentPhase();
217 if (p != Phase.MINT_SUCCESS && p != Phase.BONDED && p != Phase.TRADING) {
218 revert RewardNotAvailable();
219 }
220 uint256 amount = referralReward[msg.sender];
221 if (amount == 0) revert NoReward();
222 referralReward[msg.sender] = 0;
223 unchecked { totalReferralReward -= amount; }
224 payable(msg.sender).sendValue(amount);
225 emit ReferralRewardClaimed(msg.sender, amount);
226 }
228 /// @notice Pay the accrued dev share to DEV. Anyone may call; funds always go to DEV.
229 /// Callable only during MINT_SUCCESS / BONDED / TRADING; voided on MINT_FAILED (refunds stay 100%).
230 function withdrawDevReward() external override nonReentrant {
231 Phase p = currentPhase();
232 if (p != Phase.MINT_SUCCESS && p != Phase.BONDED && p != Phase.TRADING) {
233 revert RewardNotAvailable();
234 }
235 uint256 amount = devReward;
236 if (amount == 0) revert NoReward();
237 devReward = 0;
238 payable(DEV).sendValue(amount);
239 emit DevRewardClaimed(DEV, amount);
240 }
242 function checkTimeout() external override {
243 if (_phase != Phase.MINTING) revert NotMinting();
244 if (block.timestamp < mintStartTime + MINT_DURATION) revert MintNotEnded();
245 _phase = Phase.MINT_FAILED;
246 emit MintFailed(mintCount);
247 }
249 // ============ Refund ============
251 /// @notice After a failed mint, holders burn BURN to reclaim ETH (100% full amount, unaffected by referral rewards)
252 function refund(uint256 amount) external override nonReentrant {
253 if (currentPhase() != Phase.MINT_FAILED) revert NotFailed();
254 if (_phase == Phase.MINTING) {
255 _phase = Phase.MINT_FAILED;
256 emit MintFailed(mintCount);
257 }
259 if (amount == 0 || amount % MINT_AMOUNT != 0) revert InvalidAmount();
260 if (balanceOf(msg.sender) < amount) revert InsufficientBalance();
262 uint256 units = amount / MINT_AMOUNT;
263 uint256 refundETH = units * MINT_PRICE;
265 _burn(msg.sender, amount);
266 unchecked { ethRaised -= refundETH; }
267 payable(msg.sender).sendValue(refundETH);
268 emit Refunded(msg.sender, amount, refundETH);
269 }
271 // ============ Finalize (called by BurnHook) ============
273 /// @return ethForLP ETH to deposit into the pool = balance − reserved referral rewards − unwithdrawn dev share (no finalize reward)
274 function bondingFinalize()
275 external
276 nonReentrant
277 returns (uint256 ethForLP, uint256 tokenForLP)
278 {
279 if (msg.sender != bonder) revert NotBonder();
280 if (_phase != Phase.MINT_SUCCESS) revert AlreadyBonded();
282 _phase = Phase.BONDED;
283 bondedBlock = block.number;
285 _mint(bonder, LP_RESERVE);
287 // Reserve totalReferralReward + unwithdrawn devReward inside the contract for inviters to later withdrawReferralReward();
288 // everything else (including the original finalize reward) goes into the pool
289 ethForLP = address(this).balance - totalReferralReward - devReward;
290 tokenForLP = LP_RESERVE;
292 payable(bonder).sendValue(ethForLP);
294 emit Bonded(ethForLP, tokenForLP, 0);
295 }
297 // ============ Transfer Lock ============
299 function _update(address from, address to, uint256 value) internal override {
300 if (from == address(0) || to == address(0)) {
301 super._update(from, to, value);
302 return;
303 }
304 if (from == bonder) {
305 super._update(from, to, value);
306 return;
307 }
308 Phase p = currentPhase();
309 if (p != Phase.TRADING) {
310 // During the launch cooldown (BONDED) the only transfer allowed is burning to DEAD, which is
311 // what XBurn.deposit does. Everything else stays locked until TRADING.
312 if (!(p == Phase.BONDED && to == DEAD)) revert TransfersLocked();
313 }
314 super._update(from, to, value);
315 }
317 // ============ Views ============
319 function mintsRemaining() external view override returns (uint256) {
320 return MAX_MINTS - mintCount;
321 }
323 function timeRemaining() external view override returns (uint256) {
324 if (_phase != Phase.MINTING) return 0;
325 uint256 deadline = mintStartTime + MINT_DURATION;
326 if (block.timestamp >= deadline) return 0;
327 return deadline - block.timestamp;
328 }
330 function progress() external view override returns (uint256) {
331 return (mintCount * 10_000) / MAX_MINTS;
332 }
334 function mintDeadline() external view override returns (uint256) {
335 if (mintStartTime == 0) return 0;
336 return mintStartTime + MINT_DURATION;
337 }
339 /// @notice Whether `user` passes the Agent ID gate (always true when the gate is disabled).
340 /// The Agent ID NFT is soulbound, so one identity cannot be passed around to mint from many wallets.
341 function hasAgentId(address user) public view override returns (bool) {
342 return AGENT_ID == address(0) || IERC721(AGENT_ID).balanceOf(user) > 0;
343 }
345 /// @notice Whether an address already qualifies as an inviter (>= MIN_MINTS_TO_INVITE mints)
346 function canInvite(address user) external view override returns (bool) {
347 return mintsOf[user] >= MIN_MINTS_TO_INVITE;
348 }
350 receive() external payable {}