Verified contractPartialMIT
MilestoneMinter
Address0x9941b1becf2dca373fc3c7608de8a3883f309098
- Balance
0 ETH
- Transactions
12
- 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
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,450,947
- Creation transaction
- 0x8eb950283c…b936fb67fb
src/MilestoneMinter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/// @dev What the default minter needs from the registry and from MiniChain 1.
interface IMintableRegistry {
function totalSupply() external view returns (uint256);
function chainOf(uint256 id) external view returns (address);
function mint(address to) external returns (uint256 id);
function ownerOf(uint256 id) external view returns (address);
}
interface IFeeTotal {
function totalFees() external view returns (uint256);
}
/// @notice The default minting rule: fees that MiniChain 1 collects earn new MiniChains, in
/// steps of 50. Each of the first 50 needs 0.01 ether of fees, each of the next 50
/// needs 0.02 ether, and the amount doubles again with every further step. The owner
/// of MiniChain 1 may also give MiniChains away, up to the registry's limit of 512 in
/// all. An earned mint is free and open to anyone; whoever calls first gets it.
/// Earned mints are closed to begin with: fees count from the start, but nobody can
/// mint until the owner of MiniChain 1 opens minting.
/// @dev The registry's minter can be replaced by the owner of MiniChain 1, so this rule holds
/// only while this contract is the minter. The limit of 512 is the registry's own, and
/// holds whatever the minter.
contract MilestoneMinter {
/// @notice Fees MiniChain 1 must collect for each of the first `MINTS_PER_STEP` mints.
uint256 public constant FIRST_FEES_PER_MINT = 0.01 ether;
/// @notice How many mints are earned at one amount before the amount doubles.
uint256 public constant MINTS_PER_STEP = 50;
uint256 public constant MAX_SUPPLY = 512;
IMintableRegistry public immutable registry;
/// @notice How many MiniChains have been given away with `mintFor`.
uint256 public granted;
/// @notice Whether anyone can mint the MiniChains that fees have earned. Off to begin with;
/// the owner of MiniChain 1 turns it on and off. `mintFor` works either way.
bool public mintingOpen;
event MintingOpen(bool open);
error NothingToMint();
error NotGenesisOwner();
error LengthMismatch();
constructor(IMintableRegistry registry_) {
registry = registry_;
}
/// @notice Open or close the minting of earned MiniChains. Only the owner of MiniChain 1
/// may. What fees earn while minting is closed can be minted once it opens.
function setMintingOpen(bool open) external {
if (msg.sender != registry.ownerOf(1)) revert NotGenesisOwner();
mintingOpen = open;
emit MintingOpen(open);
}
/// @notice How many MiniChains `fees` of total fees on MiniChain 1 have earned, whether or
/// not they have been minted: 50 at 0.01 ether each, then 50 at 0.02 ether each,
/// and so on, doubling at every step. Never more than the 511 that can follow
/// MiniChain 1.
function earned(uint256 fees) public pure returns (uint256 count) {
uint256 each = FIRST_FEES_PER_MINT;
while (count < MAX_SUPPLY - 1 && fees >= each * MINTS_PER_STEP) {
fees -= each * MINTS_PER_STEP;
count += MINTS_PER_STEP;
each *= 2;
}
count += fees / each;
if (count > MAX_SUPPLY - 1) count = MAX_SUPPLY - 1;
}
/// @notice How many MiniChains anyone can mint right now: none while minting is closed. Those given away do not use up
/// the ones earned by fees, but they do count toward the 512.
function mintable() public view returns (uint256) {
if (!mintingOpen) return 0;
uint256 allowed = 1 + granted + earned(IFeeTotal(registry.chainOf(1)).totalFees());
if (allowed > MAX_SUPPLY) allowed = MAX_SUPPLY;
uint256 supply = registry.totalSupply();
return allowed > supply ? allowed - supply : 0;
}
/// @notice Mint the token of a new MiniChain to `to`, if one is available. Its owner then
/// launches the chain through the registry, whenever they choose.
function mint(address to) external returns (uint256 id) {
if (mintable() == 0) revert NothingToMint();
return registry.mint(to);
}
/// @notice Give `quantity[i]` new MiniChain tokens to `to[i]`, for each `i`. Only the owner
/// of MiniChain 1 may. The registry refuses a mint past 512 tokens in all.
function mintFor(address[] calldata to, uint256[] calldata quantity) external {
if (msg.sender != registry.ownerOf(1)) revert NotGenesisOwner();
if (to.length != quantity.length) revert LengthMismatch();
uint256 count;
for (uint256 i; i < to.length; ++i) {
count += quantity[i];
for (uint256 j; j < quantity[i]; ++j) {
registry.mint(to[i]);
}
}
granted += count;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"solady/=lib/solady/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.