Verified contractExactMIT
Block0CurveToken
Address0x4236a2ede70cfef68d2ca0b45d7b764948722952
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,451,794
- Creation transaction
- 0xf57958c129…8cc848cb8b
src/Block0CurveToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
/*
* Block0 curve token for Ethereum: a virtual bonding curve that graduates to Uniswap V2.
*
* - Fixed supply of 1B, all minted to this contract. No mint function, no owner, no admin of any kind.
* - Trading starts at deploy on a virtual constant-product curve: no ETH is needed to launch. The price starts at
* the chosen market cap (virtual ETH reserve / 1B tokens) and rises as people buy. The deployer's dev buy is made
* inside the constructor, so nobody can buy before it.
* - The curve sells exactly as much supply as it takes to reach the chosen graduation market cap (e.g. 13.8× the
* start: $5K → $69K sells about 73%). When it sells out, the contract graduates in the same transaction: the
* ETH raised and enough of the remaining tokens to keep the price continuous go into a Uniswap V2 pool, the LP
* tokens are sent to 0x…dEaD (liquidity locked for ever) and any tokens left over are burned.
* - Curve trades pay a small fee (capped at 1%) to the fee wallet. After graduation it is a plain ERC-20: no tax,
* no limits.
* - Before graduation no tokens can be sent into the Uniswap pair, so nobody can seed it at a different price.
* - Links are stored on chain (website(), twitter(), telegram()).
*/
interface IUniswapV2Factory {
function getPair(address, address) external view returns (address);
function createPair(address, address) external returns (address);
}
interface IUniswapV2Pair {
function mint(address to) external returns (uint256 liquidity);
function sync() external;
}
interface IWETH {
function deposit() external payable;
function transfer(address to, uint256 value) external returns (bool);
}
contract Block0CurveToken {
string public name;
string public symbol;
uint8 public constant decimals = 18;
uint256 public constant totalSupply = 1_000_000_000 ether;
uint256 public immutable CURVE_SUPPLY; // sold on the curve; the price ends at gradMultiple × the start
uint256 public immutable gradMultipleX100;
uint16 public constant MAX_FEE_BPS = 100;
address public constant DEAD = 0x000000000000000000000000000000000000dEaD;
address public constant owner = address(0);
string public website;
string public twitter;
string public telegram;
IUniswapV2Factory public immutable factory;
address public immutable weth;
address public immutable pair;
address payable public immutable feeWallet;
uint16 public immutable feeBps;
uint256 public immutable virtualEth0;
uint256 public virtualEth; // curve reserves (virtual ETH includes the real ETH raised)
uint256 public virtualTokens;
uint256 public sold; // tokens bought off the curve and not sold back
bool public graduated;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
bool private locked;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Trade(address indexed trader, bool isBuy, uint256 eth, uint256 tokens, uint256 fee, uint256 virtualEth, uint256 virtualTokens);
event Graduated(address pair, uint256 eth, uint256 tokens, uint256 burned);
modifier lock() {
require(!locked, "busy");
locked = true;
_;
locked = false;
}
/// @param startMarketCapWei the market cap the curve opens at, in wei (e.g. 2.84 ETH)
constructor(
string memory name_,
string memory symbol_,
string memory website_,
string memory twitter_,
string memory telegram_,
address payable feeWallet_,
uint16 feeBps_,
uint256 startMarketCapWei,
uint256 gradMultipleX100_,
address factory_,
address weth_
) payable {
require(feeBps_ <= MAX_FEE_BPS, "fee too high");
require(feeWallet_ != address(0) && factory_ != address(0) && weth_ != address(0), "zero address");
require(startMarketCapWei >= 0.01 ether && startMarketCapWei <= 10_000 ether, "start market cap");
require(gradMultipleX100_ >= 200 && gradMultipleX100_ <= 10_000, "graduation 2x to 100x");
// Constant product: price = vEth²/k, so the price grows with (vTokens0 / vTokens)². Ending at m × the start
// means vTokens_end = 1B / sqrt(m); everything above that is sold on the curve.
gradMultipleX100 = gradMultipleX100_;
CURVE_SUPPLY = totalSupply - (totalSupply * 1e9) / _sqrt(gradMultipleX100_ * 1e16);
name = name_;
symbol = symbol_;
website = website_;
twitter = twitter_;
telegram = telegram_;
feeWallet = feeWallet_;
feeBps = feeBps_;
factory = IUniswapV2Factory(factory_);
weth = weth_;
// The V2 pair's address is fixed by CREATE2, so transfers into it can be refused before it exists.
(address t0, address t1) = address(this) < weth_ ? (address(this), weth_) : (weth_, address(this));
pair = address(uint160(uint256(keccak256(abi.encodePacked(hex"ff", factory_, keccak256(abi.encodePacked(t0, t1)), hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f")))));
virtualEth0 = startMarketCapWei;
virtualEth = startMarketCapWei;
virtualTokens = totalSupply;
balanceOf[address(this)] = totalSupply;
emit Transfer(address(0), address(this), totalSupply);
if (msg.value > 0) _buy(msg.sender, msg.value, 0);
}
// ------------------------------------------------------------ curve
/// Tokens out (after fee) for `ethIn`, and the ETH actually used (less than ethIn when the curve sells out).
function quoteBuy(uint256 ethIn) public view returns (uint256 tokensOut, uint256 used) {
require(!graduated, "graduated");
uint256 fee = (ethIn * feeBps) / 10_000;
uint256 net = ethIn - fee;
uint256 left = CURVE_SUPPLY - sold;
tokensOut = (virtualTokens * net) / (virtualEth + net);
used = ethIn;
if (tokensOut >= left) {
tokensOut = left;
net = (virtualEth * left) / (virtualTokens - left) + 1;
used = net + (net * feeBps) / (10_000 - feeBps) + 1;
if (used > ethIn) used = ethIn;
}
}
/// ETH out (after fee) for selling `tokensIn` back to the curve.
function quoteSell(uint256 tokensIn) public view returns (uint256 ethOut) {
require(!graduated, "graduated");
uint256 gross = (virtualEth * tokensIn) / (virtualTokens + tokensIn);
ethOut = gross - (gross * feeBps) / 10_000;
}
function buy(uint256 minTokens) external payable lock returns (uint256) {
return _buy(msg.sender, msg.value, minTokens);
}
function sell(uint256 tokensIn, uint256 minEth) external lock returns (uint256 ethOut) {
require(!graduated, "graduated");
require(tokensIn > 0 && tokensIn <= sold, "amount");
uint256 gross = (virtualEth * tokensIn) / (virtualTokens + tokensIn);
uint256 fee = (gross * feeBps) / 10_000;
ethOut = gross - fee;
require(ethOut >= minEth, "slippage");
_move(msg.sender, address(this), tokensIn);
virtualEth -= gross;
virtualTokens += tokensIn;
sold -= tokensIn;
emit Trade(msg.sender, false, ethOut, tokensIn, fee, virtualEth, virtualTokens);
_send(feeWallet, fee, false);
_send(payable(msg.sender), ethOut, true);
}
function _buy(address to, uint256 ethIn, uint256 minTokens) private returns (uint256 tokensOut) {
require(!graduated, "graduated");
require(ethIn > 0, "amount");
uint256 used;
(tokensOut, used) = quoteBuy(ethIn);
require(tokensOut > 0 && tokensOut >= minTokens, "slippage");
uint256 fee = (used * feeBps) / 10_000;
uint256 net = used - fee;
virtualEth += net;
virtualTokens -= tokensOut;
sold += tokensOut;
_move(address(this), to, tokensOut);
emit Trade(to, true, used, tokensOut, fee, virtualEth, virtualTokens);
_send(feeWallet, fee, false);
if (used < ethIn) _send(payable(to), ethIn - used, true);
if (sold == CURVE_SUPPLY) _graduate();
}
/// Pool the raised ETH with tokens at the curve's final price; LP to dead; burn the rest.
function _graduate() private {
graduated = true;
uint256 eth = address(this).balance;
uint256 held = balanceOf[address(this)];
uint256 tokens = (eth * virtualTokens) / virtualEth;
if (tokens > held) tokens = held;
if (factory.getPair(address(this), weth) == address(0)) factory.createPair(address(this), weth);
// Mint directly on the pair: works even if someone created it first or sent it WETH.
IWETH(weth).deposit{value: eth}();
IWETH(weth).transfer(pair, eth);
_move(address(this), pair, tokens);
IUniswapV2Pair(pair).mint(DEAD);
uint256 burned = balanceOf[address(this)];
if (burned > 0) _move(address(this), DEAD, burned);
emit Graduated(pair, eth, tokens, burned);
}
function _send(address payable to, uint256 v, bool must) private {
if (v == 0) return;
(bool ok, ) = to.call{value: v}("");
if (must) require(ok, "send");
}
/// Current curve price in wei per whole token, and progress to graduation in basis points.
function curveState() external view returns (uint256 priceWei, uint256 progressBps, uint256 raisedWei, bool done) {
priceWei = (virtualEth * 1 ether) / virtualTokens;
progressBps = (sold * 10_000) / CURVE_SUPPLY;
raisedWei = graduated ? 0 : address(this).balance;
done = graduated;
}
function _sqrt(uint256 x) private pure returns (uint256 y) {
uint256 z = (x + 1) / 2;
y = x;
while (z < y) { y = z; z = (x / z + z) / 2; }
}
// ------------------------------------------------------------ ERC-20
function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value) external returns (bool) {
_move(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
uint256 a = allowance[from][msg.sender];
if (a != type(uint256).max) {
require(a >= value, "allowance");
allowance[from][msg.sender] = a - value;
}
_move(from, to, value);
return true;
}
function _move(address from, address to, uint256 value) private {
require(to != address(0), "zero address");
if (!graduated) require(to != pair || from == address(this), "pool opens at graduation");
uint256 bal = balanceOf[from];
require(bal >= value, "balance");
unchecked {
balanceOf[from] = bal - value;
balanceOf[to] += value;
}
emit Transfer(from, to, value);
}
receive() external payable {
require(msg.sender == weth || !graduated, "use buy()");
if (msg.sender != weth && !locked) {
locked = true;
_buy(msg.sender, msg.value, 0);
locked = false;
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.