Verified contractExactMIT
BurnableTokenDeployer
Address0x99ad28484fbcb432fe5c6013c45a04ebfa0c5a3e
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- 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,501,082
- Creation transaction
- 0xbdf5f65af7…895a22273a
14 files
- src/deployers/BurnableTokenDeployer.solmain1.54 KB
- node_modules/@openzeppelin/contracts/interfaces/draft-IERC6093.sol6.54 KB
- node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol10.9 KB
- node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol2.78 KB
- node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol1.18 KB
- node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- node_modules/@openzeppelin/contracts/utils/Context.sol963 B
- src/deployers/base/TokenDeployerBase.sol2.18 KB
- src/interfaces/ITokenConfigs.sol5.41 KB
- src/interfaces/ITokenDeployer.sol2.26 KB
- src/libraries/ConfigChecks.sol5.93 KB
- src/libraries/FeatureIds.sol2.03 KB
- src/libraries/TemplateRules.sol7.19 KB
- src/tokens/BurnableToken.sol806 B
src/deployers/BurnableTokenDeployer.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {TokenParams} from "../interfaces/ITokenDeployer.sol";
import {TemplateRules} from "../libraries/TemplateRules.sol";
import {BurnableToken} from "../tokens/BurnableToken.sol";
import {TokenDeployerBase} from "./base/TokenDeployerBase.sol";
/// @notice Typed CREATE2 deployer for `BurnableToken`. Callable only by its factory. Holds nothing.
/// No options: `cap` must be 0 and `config` empty.
contract BurnableTokenDeployer is TokenDeployerBase {
constructor(address factory_) TokenDeployerBase(factory_) {}
function features(TokenParams calldata p, bytes calldata config) external pure returns (bytes32[] memory ids) {
TemplateRules.plain(p, config);
return ids;
}
function deploy(bytes32 salt, TokenParams calldata p, bytes calldata config, address creator)
external
onlyFactory
returns (address token)
{
TemplateRules.plain(p, config);
try new BurnableToken{salt: salt}(p.name, p.symbol, p.decimals, p.supply, creator) returns (BurnableToken t) {
token = address(t);
} catch {
revert DeployFailed();
}
}
function computeAddress(bytes32 salt, TokenParams calldata p, bytes calldata, address creator)
external
view
returns (address)
{
return _predict(
salt,
abi.encodePacked(type(BurnableToken).creationCode, abi.encode(p.name, p.symbol, p.decimals, p.supply, creator))
);
}
}
node_modules/@openzeppelin/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Burnable.sol)
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
import {Context} from "../../../utils/Context.sol";
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is Context, ERC20 {
/**
* @dev Destroys a `value` amount of tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 value) public virtual {
_burn(_msgSender(), value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, deducting from
* the caller's allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `value`.
*/
function burnFrom(address account, uint256 value) public virtual {
_spendAllowance(account, _msgSender(), value);
_burn(account, value);
}
}
node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
node_modules/@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/deployers/base/TokenDeployerBase.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ITokenDeployer} from "../../interfaces/ITokenDeployer.sol";
import {DexConfig} from "../../interfaces/ITokenConfigs.sol";
/// @notice Shared parts of the typed deployers: the factory binding and the CREATE2 address formula.
/// Deployers hold nothing, have no owner and emit nothing (the factory emits).
abstract contract TokenDeployerBase is ITokenDeployer {
/// @inheritdoc ITokenDeployer
address public immutable factory;
constructor(address factory_) {
factory = factory_;
}
modifier onlyFactory() {
if (msg.sender != factory) revert NotFactory();
_;
}
function _predict(bytes32 salt, bytes memory initCode) internal view returns (address) {
return address(uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(initCode))))));
}
}
/// @notice A deployer for the exchange-aware templates. The router, factory, wrapped native token, pair
/// init code hash and the rules contract are immutables of the deployer, so the registered codehash pins
/// them; every token gets the exchange settings as constructor arguments and keeps them in storage.
abstract contract DexTokenDeployerBase is TokenDeployerBase {
address public immutable router;
address public immutable dexFactory;
address public immutable wrappedNative;
bytes32 public immutable pairInitCodeHash;
/// @notice The `TaxTemplateRules` contract that checks configs.
address public immutable rules;
constructor(address factory_, DexConfig memory dex, address rules_) TokenDeployerBase(factory_) {
router = dex.router;
dexFactory = dex.factory;
wrappedNative = dex.wrappedNative;
pairInitCodeHash = dex.pairInitCodeHash;
rules = rules_;
}
/// @notice The exchange settings every token of this deployer receives.
function dexConfig() public view returns (DexConfig memory) {
return DexConfig({
router: router,
factory: dexFactory,
wrappedNative: wrappedNative,
pairInitCodeHash: pairInitCodeHash
});
}
}
src/interfaces/ITokenConfigs.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice One initial allocation minted at creation, next to the creator's remainder. An unused entry
/// of a fixed-size list is all zero.
struct Allocation {
address account;
uint256 amount;
}
/// @notice Tax of one side (buy, sell or wallet-to-wallet transfer) in basis points of the moved amount.
/// The four parts of one side add up to at most 1000 (10%).
struct TaxRates {
/// @dev To the tax wallets, in tokens or swapped to native.
uint16 wallets;
/// @dev Auto-liquidity: half swapped to native, both halves added to the pool, LP tokens to the dead address.
uint16 liquidity;
/// @dev Burned (total supply goes down).
uint16 burn;
/// @dev Holder rewards: reflection (Reflection) or dividends (Dividend). Zero for Launch.
uint16 holders;
}
/// @notice Taxes of a Launch, Reflection or Dividend token.
struct TaxConfig {
TaxRates buy;
TaxRates sell;
TaxRates transfer;
/// @dev 0 to 5 wallets from index 0, unused entries zero; at least one is required when any side has
/// a wallets part or a launch tax is set.
address[5] wallets;
/// @dev Share of each used wallet in basis points, each above 0, summing to 10000; 0 for unused entries.
uint16[5] shares;
/// @dev Swap the wallets part to native on sells (Launch, Dividend). False pays wallets in tokens.
bool walletsInNative;
}
/// @notice Exchange-side controls of a Launch, Reflection or Dividend token.
struct TradeConfig {
/// @dev Pool trades stay closed until the owner calls `enableTrading()` (one way).
bool tradingSwitch;
/// @dev Launch protection window after trading opens, 0 to 100 blocks. Needs the trading switch.
uint8 antiBotBlocks;
/// @dev Decaying launch tax: total buy and sell tax right at opening, 0 to 1000 bps, falls linearly
/// to the normal tax over `launchTaxSeconds`. Needs the trading switch and at least one tax wallet.
uint16 launchTaxBps;
/// @dev 1 to 1800 seconds when a launch tax is set, else 0.
uint32 launchTaxSeconds;
/// @dev 0 (none) or at least 1% of the supply.
uint256 maxWallet;
/// @dev 0 (none) or at least 0.1% of the supply.
uint256 maxTx;
/// @dev Tokens swapped per tax swap. 0 picks 0.05% of the supply, else 0.01% to 0.5% of the supply.
/// Must be 0 for Reflection (it never swaps).
uint256 swapThreshold;
/// @dev Up to 5 accounts exempt from taxes, limits, the trading switch and launch protection, next
/// to the creator; zero entries are ignored. Adding more is possible only before trading opens.
address[5] exempt;
}
/// @notice Router, factory and wrapped native token of the exchange the tax templates use. Fixed per
/// deployer (immutables of the deployer) and copied into token storage at creation.
struct DexConfig {
address router;
address factory;
address wrappedNative;
bytes32 pairInitCodeHash;
}
/// @notice Config of the `utility` and `utility-mintable` templates.
struct UtilityConfig {
bool burnable;
/// @dev EIP-2612 permit.
bool permit;
/// @dev Delegated voting with a timestamp clock (EIP-5805, EIP-6372).
bool votes;
/// @dev Metadata URI (ERC-7572 `contractURI`), at most 256 bytes, owner can update it.
string contractURI;
/// @dev Up to 10 initial allocations; the creator receives the rest of the supply.
Allocation[10] allocations;
}
/// @notice Config of the `managed` and `managed-mintable` templates. At least one of `pausable` and
/// `blacklist` must be set.
struct ManagedConfig {
UtilityConfig utility;
bool pausable;
bool blacklist;
/// @dev Seconds after creation during which pause and blacklist work at all, 1 hour to 30 days.
uint32 controlWindow;
}
/// @notice Config of the `launch` template.
struct LaunchConfig {
bool burnable;
bool permit;
string contractURI;
Allocation[10] allocations;
TaxConfig tax;
TradeConfig trade;
}
/// @notice Config of the `reflection` template. `tax.*.holders` is the reflection part; `liquidity`
/// must be zero and `walletsInNative` false (the template never swaps).
struct ReflectionConfig {
string contractURI;
Allocation[10] allocations;
TaxConfig tax;
TradeConfig trade;
}
/// @notice Config of the `dividend` template. `tax.*.holders` is the dividend part.
struct DividendConfig {
bool burnable;
string contractURI;
Allocation[10] allocations;
TaxConfig tax;
TradeConfig trade;
/// @dev Zero for native rewards, else one of the deployer's allowed reward tokens.
address rewardToken;
/// @dev Smallest balance that earns dividends, at most 1% of the supply.
uint256 minBalance;
}
/// @notice ABI anchor for the config structs: clients encode `config` as `abi.encode(<struct>)` with the
/// parameter type of these functions. Nothing implements this interface. Lists are fixed-size arrays so
/// every config except the metadata URI is a static ABI type, which keeps the decoders small.
interface ITokenConfigs {
function utilityConfig(UtilityConfig calldata c) external;
function managedConfig(ManagedConfig calldata c) external;
function launchConfig(LaunchConfig calldata c) external;
function reflectionConfig(ReflectionConfig calldata c) external;
function dividendConfig(DividendConfig calldata c) external;
}
src/interfaces/ITokenDeployer.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice Parameters every template shares.
/// @dev `cap` is read only by the capped templates (capped-mintable, utility-mintable, managed-mintable)
/// and must be zero for the others.
struct TokenParams {
string name;
string symbol;
uint8 decimals;
uint256 supply;
uint256 cap;
}
/// @notice A typed deployer for one fixed token template. Only its factory may deploy.
/// @dev `config` is the ABI encoding of the template's config struct (see `ITokenConfigs`), or empty
/// for the templates without options. The deployer checks it in full before the factory charges the
/// fee, and again when it deploys.
interface ITokenDeployer {
error NotFactory();
error InvalidCap();
error DeployFailed();
/// @dev The config is empty where one is required, not empty where none is allowed, or selects
/// no feature where the template needs one.
error InvalidConfig();
error InvalidAllocations();
error InvalidMetadata();
error InvalidTaxRates();
error InvalidTaxWallets();
error InvalidLimits();
error InvalidLaunchSettings();
error InvalidSwapThreshold();
error InvalidRewardSettings();
error InvalidControlWindow();
/// @notice The only address allowed to call `deploy`.
function factory() external view returns (address);
/// @notice Checks `p` and `config` for this template and returns the price items of the selected
/// optional features, in a fixed order. Reverts with the errors above on an invalid input.
function features(TokenParams calldata p, bytes calldata config) external view returns (bytes32[] memory priceIds);
/// @notice Deploys one token with CREATE2. The creator receives the initial supply (minus any
/// initial allocations) and, for the templates that have one, the owner role.
function deploy(bytes32 salt, TokenParams calldata p, bytes calldata config, address creator)
external
returns (address token);
/// @notice The address `deploy` produces for the same arguments.
function computeAddress(bytes32 salt, TokenParams calldata p, bytes calldata config, address creator)
external
view
returns (address);
}
src/libraries/ConfigChecks.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ITokenDeployer} from "../interfaces/ITokenDeployer.sol";
import {Allocation, TaxConfig, TaxRates, TradeConfig} from "../interfaces/ITokenConfigs.sol";
/// @notice Bound checks of the template configs, shared by the deployers and by the token setters that
/// accept the same kind of value later.
library ConfigChecks {
uint256 internal constant BPS = 10_000;
/// @dev Hard cap of one side's total tax, launch tax included.
uint256 internal constant MAX_TAX_BPS = 1_000;
uint256 internal constant MAX_ALLOCATIONS = 10;
uint256 internal constant MAX_TAX_WALLETS = 5;
uint256 internal constant MAX_ANTI_BOT_BLOCKS = 100;
uint256 internal constant MAX_LAUNCH_TAX_SECONDS = 30 minutes;
uint256 internal constant MIN_MAX_WALLET_BPS = 100;
uint256 internal constant MIN_MAX_TX_BPS = 10;
uint256 internal constant MIN_SWAP_THRESHOLD_BPS = 1;
uint256 internal constant MAX_SWAP_THRESHOLD_BPS = 50;
uint256 internal constant MAX_URI_BYTES = 256;
/// @dev Bits of the tax parts a config uses, and of the parts a template allows.
uint256 internal constant WALLETS = 1;
uint256 internal constant LIQUIDITY = 2;
uint256 internal constant BURN = 4;
uint256 internal constant HOLDERS = 8;
/// @dev Allowed-mask bit only: the wallets part may be swapped to native.
uint256 internal constant NATIVE_WALLETS = 16;
/// @dev Each entry is unused (all zero) or has an account and an amount; the sum is at most the
/// supply. Returns whether any entry is used.
function allocations(Allocation[MAX_ALLOCATIONS] memory list, uint256 supply) internal pure returns (bool used) {
uint256 total = 0;
for (uint256 i = 0; i < MAX_ALLOCATIONS; ++i) {
uint256 amount = list[i].amount;
if ((list[i].account == address(0)) != (amount == 0) || amount > supply) {
revert ITokenDeployer.InvalidAllocations();
}
total += amount;
}
if (total > supply) revert ITokenDeployer.InvalidAllocations();
return total != 0;
}
function metadata(string memory uri) internal pure {
if (bytes(uri).length > MAX_URI_BYTES) revert ITokenDeployer.InvalidMetadata();
}
/// @dev Checks the three sides against the 10% cap and the parts `allowed` permits, then the wallets.
/// Returns the bits of the parts used on any side.
function taxes(TaxConfig memory t, uint256 allowed, uint256 launchTaxBps) internal pure returns (uint256 used) {
used = _side(t.buy) | _side(t.sell) | _side(t.transfer);
if ((used & ~allowed) != 0) revert ITokenDeployer.InvalidTaxRates();
if (t.walletsInNative && (allowed & NATIVE_WALLETS) == 0) revert ITokenDeployer.InvalidTaxRates();
wallets(t.wallets, t.shares, (used & WALLETS) != 0 || launchTaxBps != 0);
}
/// @dev Wallets from index 0, each with a share above 0; unused entries zero with share 0; shares of
/// the used wallets sum to 10000. `required` asks for at least one. Returns the number of wallets.
function wallets(address[MAX_TAX_WALLETS] memory list, uint16[MAX_TAX_WALLETS] memory shares, bool required)
internal
pure
returns (uint256 n)
{
while (n < MAX_TAX_WALLETS && list[n] != address(0)) ++n;
uint256 sum = 0;
for (uint256 i = 0; i < MAX_TAX_WALLETS; ++i) {
bool used = i < n;
if (used != (shares[i] != 0) || (!used && list[i] != address(0))) revert ITokenDeployer.InvalidTaxWallets();
sum += shares[i];
}
if ((required && n == 0) || (n != 0 && sum != BPS)) revert ITokenDeployer.InvalidTaxWallets();
}
/// @dev Checks launch settings, limits and the swap threshold. `swaps` is false for
/// templates without a tax swap. Returns whether launch protection and limits are selected.
function trade(TradeConfig memory c, uint256 supply, bool swaps)
internal
pure
returns (bool antiBot, bool antiWhale)
{
if (c.antiBotBlocks > MAX_ANTI_BOT_BLOCKS || (c.antiBotBlocks != 0 && !c.tradingSwitch)) {
revert ITokenDeployer.InvalidLaunchSettings();
}
if (c.launchTaxBps == 0) {
if (c.launchTaxSeconds != 0) revert ITokenDeployer.InvalidLaunchSettings();
} else if (
c.launchTaxBps > MAX_TAX_BPS || !c.tradingSwitch || c.launchTaxSeconds == 0
|| c.launchTaxSeconds > MAX_LAUNCH_TAX_SECONDS
) {
revert ITokenDeployer.InvalidLaunchSettings();
}
if (c.maxWallet != 0 && (c.maxWallet > supply || c.maxWallet * BPS < supply * MIN_MAX_WALLET_BPS)) {
revert ITokenDeployer.InvalidLimits();
}
if (c.maxTx != 0 && (c.maxTx > supply || c.maxTx * BPS < supply * MIN_MAX_TX_BPS)) {
revert ITokenDeployer.InvalidLimits();
}
if (c.swapThreshold != 0 && (!swaps || !swapThresholdInRange(c.swapThreshold, supply))) {
revert ITokenDeployer.InvalidSwapThreshold();
}
antiBot = c.antiBotBlocks != 0;
antiWhale = c.maxWallet != 0 || c.maxTx != 0;
}
/// @dev 0.01% to 0.5% of `supply`.
function swapThresholdInRange(uint256 threshold, uint256 supply) internal pure returns (bool) {
return threshold <= supply && threshold * BPS >= supply * MIN_SWAP_THRESHOLD_BPS
&& threshold * BPS <= supply * MAX_SWAP_THRESHOLD_BPS;
}
function _side(TaxRates memory r) private pure returns (uint256 used) {
if (uint256(r.wallets) + r.liquidity + r.burn + r.holders > MAX_TAX_BPS) {
revert ITokenDeployer.InvalidTaxRates();
}
if (r.wallets != 0) used |= WALLETS;
if (r.liquidity != 0) used |= LIQUIDITY;
if (r.burn != 0) used |= BURN;
if (r.holders != 0) used |= HOLDERS;
}
}
src/libraries/FeatureIds.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice Price items of the optional token features, charged by the factory on top of the template's
/// own item. `keccak256("evm-create-token/feature/<name>")`.
library FeatureIds {
bytes32 internal constant MINTABLE = keccak256("evm-create-token/feature/mintable");
bytes32 internal constant BURNABLE = keccak256("evm-create-token/feature/burnable");
/// @dev Permit and votes, one item for either or both.
bytes32 internal constant ADVANCED_ERC20 = keccak256("evm-create-token/feature/advanced-erc20");
bytes32 internal constant MULTI_WALLET = keccak256("evm-create-token/feature/multi-wallet");
bytes32 internal constant PAUSABLE = keccak256("evm-create-token/feature/pausable");
bytes32 internal constant BLACKLIST = keccak256("evm-create-token/feature/blacklist");
bytes32 internal constant REFLECTION = keccak256("evm-create-token/feature/reflection");
bytes32 internal constant DIVIDEND = keccak256("evm-create-token/feature/dividend");
bytes32 internal constant BURN_TAX = keccak256("evm-create-token/feature/burn-tax");
bytes32 internal constant AUTO_LIQUIDITY = keccak256("evm-create-token/feature/auto-liquidity");
bytes32 internal constant ANTI_BOT = keccak256("evm-create-token/feature/anti-bot");
/// @dev Max wallet and/or max transaction.
bytes32 internal constant ANTI_WHALE = keccak256("evm-create-token/feature/anti-whale");
/// @dev Appends `id` to a list built with spare capacity. `count` is the number of used slots.
function push(bytes32[] memory list, uint256 count, bytes32 id) internal pure returns (uint256) {
list[count] = id;
return count + 1;
}
/// @dev Copies the first `count` entries into an exactly sized array.
function trim(bytes32[] memory list, uint256 count) internal pure returns (bytes32[] memory out) {
out = new bytes32[](count);
for (uint256 i = 0; i < count; ++i) {
out[i] = list[i];
}
}
}
src/libraries/TemplateRules.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ITokenDeployer, TokenParams} from "../interfaces/ITokenDeployer.sol";
import {
DividendConfig,
LaunchConfig,
ManagedConfig,
ReflectionConfig,
TradeConfig,
UtilityConfig
} from "../interfaces/ITokenConfigs.sol";
import {ConfigChecks} from "./ConfigChecks.sol";
import {FeatureIds} from "./FeatureIds.sol";
/// @notice Per-template input rules and the priced features each config selects. Every deployer uses one
/// of these from both `features` (before the fee) and `deploy`. Feature ids come back in this fixed order:
/// mintable, burnable, advanced-erc20, multi-wallet, pausable, blacklist, reflection, dividend, burn-tax,
/// auto-liquidity, anti-bot, anti-whale.
library TemplateRules {
uint256 internal constant MAX_SUPPLY = type(uint112).max;
uint256 internal constant MIN_CONTROL_WINDOW = 1 hours;
uint256 internal constant MAX_CONTROL_WINDOW = 30 days;
uint256 internal constant MAX_FEATURES = 12;
/// @dev Largest dividend minimum balance, in basis points of the supply.
uint256 internal constant MAX_MIN_BALANCE_BPS = 100;
/// @dev Standard, burnable: no cap, no config.
function plain(TokenParams calldata p, bytes calldata config) internal pure {
if (p.cap != 0) revert ITokenDeployer.InvalidCap();
if (config.length != 0) revert ITokenDeployer.InvalidConfig();
}
/// @dev Capped mintable: supply <= cap <= 2^112 - 1, no config.
function capped(TokenParams calldata p, bytes calldata config) internal pure {
checkCap(p, true);
if (config.length != 0) revert ITokenDeployer.InvalidConfig();
}
function checkCap(TokenParams calldata p, bool mintable) internal pure {
if (mintable ? (p.cap < p.supply || p.cap > MAX_SUPPLY) : p.cap != 0) revert ITokenDeployer.InvalidCap();
}
function utility(TokenParams calldata p, UtilityConfig memory c, bool mintable)
internal
pure
returns (bytes32[] memory)
{
bytes32[] memory ids = new bytes32[](MAX_FEATURES);
uint256 n = _utility(p, c, mintable, ids);
return FeatureIds.trim(ids, n);
}
function managed(TokenParams calldata p, ManagedConfig memory c, bool mintable)
internal
pure
returns (bytes32[] memory)
{
if (!c.pausable && !c.blacklist) revert ITokenDeployer.InvalidConfig();
if (c.controlWindow < MIN_CONTROL_WINDOW || c.controlWindow > MAX_CONTROL_WINDOW) {
revert ITokenDeployer.InvalidControlWindow();
}
bytes32[] memory ids = new bytes32[](MAX_FEATURES);
uint256 n = _utility(p, c.utility, mintable, ids);
if (c.pausable) n = FeatureIds.push(ids, n, FeatureIds.PAUSABLE);
if (c.blacklist) n = FeatureIds.push(ids, n, FeatureIds.BLACKLIST);
return FeatureIds.trim(ids, n);
}
function launch(TokenParams calldata p, LaunchConfig memory c) internal pure returns (bytes32[] memory) {
checkCap(p, false);
ConfigChecks.metadata(c.contractURI);
bytes32[] memory ids = new bytes32[](MAX_FEATURES);
uint256 n = 0;
if (c.burnable) n = FeatureIds.push(ids, n, FeatureIds.BURNABLE);
if (c.permit) n = FeatureIds.push(ids, n, FeatureIds.ADVANCED_ERC20);
if (ConfigChecks.allocations(c.allocations, p.supply)) n = FeatureIds.push(ids, n, FeatureIds.MULTI_WALLET);
uint256 used = ConfigChecks.taxes(
c.tax,
ConfigChecks.WALLETS | ConfigChecks.LIQUIDITY | ConfigChecks.BURN | ConfigChecks.NATIVE_WALLETS,
c.trade.launchTaxBps
);
n = _taxAndTrade(p, c.trade, used, true, ids, n);
return FeatureIds.trim(ids, n);
}
function reflection(TokenParams calldata p, ReflectionConfig memory c) internal pure returns (bytes32[] memory) {
checkCap(p, false);
ConfigChecks.metadata(c.contractURI);
bytes32[] memory ids = new bytes32[](MAX_FEATURES);
uint256 n = 0;
if (ConfigChecks.allocations(c.allocations, p.supply)) n = FeatureIds.push(ids, n, FeatureIds.MULTI_WALLET);
uint256 used = ConfigChecks.taxes(
c.tax, ConfigChecks.WALLETS | ConfigChecks.BURN | ConfigChecks.HOLDERS, c.trade.launchTaxBps
);
if ((used & ConfigChecks.HOLDERS) == 0) revert ITokenDeployer.InvalidTaxRates();
n = FeatureIds.push(ids, n, FeatureIds.REFLECTION);
n = _taxAndTrade(p, c.trade, used, false, ids, n);
return FeatureIds.trim(ids, n);
}
/// @param allowedReward Whether `c.rewardToken` (non-zero) is on the deployer's list.
function dividend(TokenParams calldata p, DividendConfig memory c, bool allowedReward)
internal
pure
returns (bytes32[] memory)
{
checkCap(p, false);
ConfigChecks.metadata(c.contractURI);
if (
(c.rewardToken != address(0) && !allowedReward) || c.minBalance > p.supply
|| c.minBalance * ConfigChecks.BPS > p.supply * MAX_MIN_BALANCE_BPS
) revert ITokenDeployer.InvalidRewardSettings();
bytes32[] memory ids = new bytes32[](MAX_FEATURES);
uint256 n = 0;
if (c.burnable) n = FeatureIds.push(ids, n, FeatureIds.BURNABLE);
if (ConfigChecks.allocations(c.allocations, p.supply)) n = FeatureIds.push(ids, n, FeatureIds.MULTI_WALLET);
uint256 used = ConfigChecks.taxes(
c.tax,
ConfigChecks.WALLETS | ConfigChecks.LIQUIDITY | ConfigChecks.BURN | ConfigChecks.HOLDERS
| ConfigChecks.NATIVE_WALLETS,
c.trade.launchTaxBps
);
if ((used & ConfigChecks.HOLDERS) == 0) revert ITokenDeployer.InvalidTaxRates();
n = FeatureIds.push(ids, n, FeatureIds.DIVIDEND);
n = _taxAndTrade(p, c.trade, used, true, ids, n);
return FeatureIds.trim(ids, n);
}
function _utility(TokenParams calldata p, UtilityConfig memory c, bool mintable, bytes32[] memory ids)
private
pure
returns (uint256 n)
{
checkCap(p, mintable);
ConfigChecks.metadata(c.contractURI);
if (mintable) n = FeatureIds.push(ids, n, FeatureIds.MINTABLE);
if (c.burnable) n = FeatureIds.push(ids, n, FeatureIds.BURNABLE);
if (c.permit || c.votes) n = FeatureIds.push(ids, n, FeatureIds.ADVANCED_ERC20);
if (ConfigChecks.allocations(c.allocations, p.supply)) n = FeatureIds.push(ids, n, FeatureIds.MULTI_WALLET);
}
function _taxAndTrade(
TokenParams calldata p,
TradeConfig memory t,
uint256 used,
bool swaps,
bytes32[] memory ids,
uint256 n
) private pure returns (uint256) {
(bool antiBot, bool antiWhale) = ConfigChecks.trade(t, p.supply, swaps);
if ((used & ConfigChecks.BURN) != 0) n = FeatureIds.push(ids, n, FeatureIds.BURN_TAX);
if ((used & ConfigChecks.LIQUIDITY) != 0) n = FeatureIds.push(ids, n, FeatureIds.AUTO_LIQUIDITY);
if (antiBot) n = FeatureIds.push(ids, n, FeatureIds.ANTI_BOT);
if (antiWhale) n = FeatureIds.push(ids, n, FeatureIds.ANTI_WHALE);
return n;
}
}
src/tokens/BurnableToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
/// @notice Fixed-supply ERC20 whose holders can burn their own tokens. No owner, no admin role.
/// @dev No immutables, so every token of this template has the same runtime bytecode.
contract BurnableToken is ERC20Burnable {
uint8 private _decimals;
constructor(string memory name_, string memory symbol_, uint8 decimals_, uint256 supply_, address initialHolder)
ERC20(name_, symbol_)
{
_decimals = decimals_;
_mint(initialHolder, supply_);
}
function decimals() public view override returns (uint8) {
return _decimals;
}
}
Compiler settingsShow
{
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/=node_modules/@openzeppelin/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"forge-std/=node_modules/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.