Address Contract Verified
Address
0x37CDF2a3f655B72550b7fEa53bC780436F9D068C
Balance
0 ETH
Nonce
1
Code Size
6616 bytes
Creator
0x4904Ba31...a4bd at tx 0x3a3ed787...c964d8
Indexed Transactions
0
Contract Bytecode
6616 bytes
0x608060405234801561001057600080fd5b506004361061025c5760003560e01c8063883356d911610145578063a9d86685116100bd578063dd62ed3e1161008c578063f2fde38b11610071578063f2fde38b14610543578063f820f56714610556578063ffa1ad741461056757600080fd5b8063dd62ed3e146104f7578063f19c4e3b1461053057600080fd5b8063a9d86685146104c0578063b7bda68f146104c8578063d48e4127146104db578063d8f67851146104e457600080fd5b806395d89b4111610114578063a457c2d7116100f9578063a457c2d714610487578063a476df611461049a578063a9059cbb146104ad57600080fd5b806395d89b4114610458578063a32f69761461046057600080fd5b8063883356d9146103e85780638da5cb5b146103f85780638dac71911461041d5780638e8c10a21461044457600080fd5b806339509351116101d85780634ac0bc32116101a75780635a3990ce1161018c5780635a3990ce146103a557806370a08231146103b7578063715018a6146103e057600080fd5b80634ac0bc3214610389578063542e96671461039c57600080fd5b8063395093511461034557806340c10f191461035857806342966c681461036b57806346b45af71461037e57600080fd5b806318160ddd1161022f5780632fa782eb116102145780632fa782eb146102e4578063313ce567146102ed578063378dc3dc1461031e57600080fd5b806318160ddd146102bf57806323b872dd146102d157600080fd5b806302252c4d14610261578063044ab74e1461027657806306fdde0314610294578063095ea7b31461029c575b600080fd5b61027461026f3660046115ec565b6105a3565b005b61027e610665565b60405161028b9190611605565b60405180910390f35b61027e6106f3565b6102af6102aa36600461166a565b610785565b604051901515815260200161028b565b6002545b60405190815260200161028b565b6102af6102df366004611694565b61079f565b6102c3600b5481565b60405160ff7f000000000000000000000000000000000000000000000000000000000000000816815260200161028b565b6102c37f00000000000000000000000000000000000000000000000000000002540be40081565b6102af61035336600461166a565b610887565b61027461036636600461166a565b6108c6565b6102746103793660046115ec565b610981565b60095460ff166102af565b600954640100000000900460ff166102af565b6102c3600c5481565b6009546301000000900460ff166102af565b6102c36103c53660046116d0565b6001600160a01b031660009081526020819052604090205490565b6102746109d7565b600954610100900460ff166102af565b6005546001600160a01b03165b6040516001600160a01b03909116815260200161028b565b6104057f0000000000000000000000008c1ebddf184469f510b61a020faa6a898089249481565b60095465010000000000900460ff166102af565b61027e6109e9565b6102c37f000000000000000000000000000000000000000000000000000000000000000081565b6102af61049536600461166a565b6109f8565b6102746104a8366004611701565b610aad565b6102af6104bb36600461166a565b610b33565b61027e610c14565b600a54610405906001600160a01b031681565b6102c360085481565b6102746104f23660046115ec565b610c21565b6102c36105053660046117b2565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61027461053e36600461166a565b610ce0565b6102746105513660046116d0565b610dd4565b60095462010000900460ff166102af565b61027e6040518060400160405280600881526020017f646566695f765f3100000000000000000000000000000000000000000000000081525081565b6105ab610e88565b6009546301000000900460ff166105ee576040517f6273340f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6008548111610629576040517fa43d2d7600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60088190556040518181527f2905481c6fd1a037492016c4760435a52203d82a6f34dc3de40f464c1bf42d59906020015b60405180910390a150565b60078054610672906117e5565b80601f016020809104026020016040519081016040528092919081815260200182805461069e906117e5565b80156106eb5780601f106106c0576101008083540402835291602001916106eb565b820191906000526020600020905b8154815290600101906020018083116106ce57829003601f168201915b505050505081565b606060038054610702906117e5565b80601f016020809104026020016040519081016040528092919081815260200182805461072e906117e5565b801561077b5780601f106107505761010080835404028352916020019161077b565b820191906000526020600020905b81548152906001019060200180831161075e57829003601f168201915b5050505050905090565b600033610793818585610ee2565b60019150505b92915050565b6000806107ac858461103b565b905060006107b984611085565b90506000816107c88487611835565b6107d29190611835565b6009549091506301000000900460ff1615610843576008548161080a886001600160a01b031660009081526020819052604090205490565b6108149190611848565b11156108435760405163f6202a8f60e01b81526001600160a01b03871660048201526024015b60405180910390fd5b821561086157600a546108619088906001600160a01b0316856110b4565b81156108715761087187836112a3565b61087c878783611409565b979650505050505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490919061079390829086906108c1908790611848565b610ee2565b6108ce610e88565b60095460ff1661090a576040517f3990ac6800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6009546301000000900460ff1615610973576008548161093f846001600160a01b031660009081526020819052604090205490565b6109499190611848565b11156109735760405163f6202a8f60e01b81526001600160a01b038316600482015260240161083a565b61097d8282611422565b5050565b610989610e88565b600954610100900460ff166109ca576040517f6cb5913900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109d433826112a3565b50565b6109df610e88565b6109e76114e1565b565b606060048054610702906117e5565b3360008181526001602090815260408083206001600160a01b038716845290915281205490919083811015610a955760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f000000000000000000000000000000000000000000000000000000606482015260840161083a565b610aa28286868403610ee2565b506001949350505050565b610ab5610e88565b60095462010000900460ff16610af7576040517f70a43fce00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6007610b0382826118a9565b507f4456a0b562609d67398ddb488f136db285cd3c92343e0a7ba684925669237ade8160405161065a9190611605565b600080610b40338461103b565b90506000610b4d84611085565b9050600081610b5c8487611835565b610b669190611835565b6009549091506301000000900460ff1615610bd25760085481610b9e886001600160a01b031660009081526020819052604090205490565b610ba89190611848565b1115610bd25760405163f6202a8f60e01b81526001600160a01b038716600482015260240161083a565b8215610bf057600a54610bf09033906001600160a01b0316856110b4565b8115610c0057610c0033836112a3565b610c0a86826114f3565b9695505050505050565b60068054610672906117e5565b610c29610e88565b60095465010000000000900460ff16610c6e576040517fcd9e529800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611388811115610cad576040517fbb7465200000000000000000000000000000000000000000000000000000000081526004810182905260240161083a565b600c81905560405181907fc1ff65ee907dc079b64ed9913d53f4bd593bd6ebd9b2a2708db2916d49e17ec390600090a250565b610ce8610e88565b600954640100000000900460ff16610d2c576040517fc8a478a500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611388811115610d6b576040517fcb400e960000000000000000000000000000000000000000000000000000000081526004810182905260240161083a565b610d7482610de5565b600a805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038416908117909155600b8290556040518291907facc44e32fd5ca4240f6dbe6e8cf4eb49349c17c5ce5f80f1919a9c97b50d398a90600090a35050565b610ddc610e88565b6109d481610dfb565b8060601b6109d45763d92e233d6000526004601cfd5b610e03610e88565b6001600160a01b038116610e7f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161083a565b6109d481611501565b6005546001600160a01b031633146109e75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161083a565b6001600160a01b038316610f5d5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f7265737300000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b038216610fd95760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f7373000000000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6000600b5460001415801561105e5750600a546001600160a01b03848116911614155b1561079957612710600b54836110749190611969565b61107e9190611980565b9392505050565b6000600c546000146110af57612710600c54836110a29190611969565b6110ac9190611980565b90505b919050565b6001600160a01b0383166111305760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f6472657373000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b0382166111ac5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f6573730000000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b0383166000908152602081905260409020548181101561123b5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e63650000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35b50505050565b6001600160a01b03821661131f5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f7300000000000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b038216600090815260208190526040902054818110156113ae5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f6365000000000000000000000000000000000000000000000000000000000000606482015260840161083a565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910161102e565b505050565b600033611417858285611560565b610aa28585856110b4565b6001600160a01b0382166114785760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161083a565b806002600082825461148a9190611848565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6114e9610e88565b6109e76000611501565b6000336107938185856110b4565b600580546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b03838116600090815260016020908152604080832093861683529290522054600019811461129d57818110156115df5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161083a565b61129d8484848403610ee2565b6000602082840312156115fe57600080fd5b5035919050565b600060208083528351808285015260005b8181101561163257858101830151858201604001528201611616565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b03811681146110af57600080fd5b6000806040838503121561167d57600080fd5b61168683611653565b946020939093013593505050565b6000806000606084860312156116a957600080fd5b6116b284611653565b92506116c060208501611653565b9150604084013590509250925092565b6000602082840312156116e257600080fd5b61107e82611653565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561171357600080fd5b813567ffffffffffffffff8082111561172b57600080fd5b818401915084601f83011261173f57600080fd5b813581811115611751576117516116eb565b604051601f8201601f19908116603f01168101908382118183101715611779576117796116eb565b8160405282815287602084870101111561179257600080fd5b826020860160208301376000928101602001929092525095945050505050565b600080604083850312156117c557600080fd5b6117ce83611653565b91506117dc60208401611653565b90509250929050565b600181811c908216806117f957607f821691505b60208210810361181957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b818103818111156107995761079961181f565b808201808211156107995761079961181f565b601f82111561140457600081815260208120601f850160051c810160208610156118825750805b601f850160051c820191505b818110156118a15782815560010161188e565b505050505050565b815167ffffffffffffffff8111156118c3576118c36116eb565b6118d7816118d184546117e5565b8461185b565b602080601f83116001811461190c57600084156118f45750858301515b600019600386901b1c1916600185901b1785556118a1565b600085815260208120601f198616915b8281101561193b5788860151825594840194600190910190840161191c565b50858210156119595787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80820281158282048414176107995761079961181f565b60008261199d57634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212204acce1e3f69ac548603093e2aec34261c26e17c8d1229abf947fe0222ac83f9964736f6c63430008110033
Verified Source Code Full Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (1337 runs)
DefiToken.sol 360 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { LibCommon } from "./lib/LibCommon.sol";
/// @title A Defi Token implementation with extended functionalities
/// @notice Implements ERC20 standards with additional features like tax and deflation
contract DefiToken is ERC20, Ownable {
// Constants
uint256 private constant MAX_BPS_AMOUNT = 10_000;
uint256 private constant MAX_ALLOWED_BPS = 5_000;
string public constant VERSION = "defi_v_1";
// State Variables
string public initialDocumentUri;
string public documentUri;
uint256 public immutable initialSupply;
uint256 public immutable initialMaxTokenAmountPerAddress;
uint256 public maxTokenAmountPerAddress;
/// @notice Configuration properties for the ERC20 token
struct ERC20ConfigProps {
bool _isMintable;
bool _isBurnable;
bool _isDocumentAllowed;
bool _isMaxAmountOfTokensSet;
bool _isTaxable;
bool _isDeflationary;
}
ERC20ConfigProps private configProps;
address public immutable initialTokenOwner;
uint8 private immutable _decimals;
address public taxAddress;
uint256 public taxBPS;
uint256 public deflationBPS;
// Events
event DocumentUriSet(string newDocUri);
event MaxTokenAmountPerSet(uint256 newMaxTokenAmount);
event TaxConfigSet(address indexed _taxAddress, uint256 indexed _taxBPS);
event DeflationConfigSet(uint256 indexed _deflationBPS);
// Custom Errors
error InvalidMaxTokenAmount(uint256 maxTokenAmount);
error InvalidDecimals(uint8 decimals);
error MaxTokenAmountPerAddrLtPrevious();
error DestBalanceExceedsMaxAllowed(address addr);
error MintingNotEnabled();
error BurningNotEnabled();
error DocumentUriNotAllowed();
error MaxTokenAmountNotAllowed();
error TokenIsNotTaxable();
error TokenIsNotDeflationary();
error InvalidTaxBPS(uint256 bps);
error InvalidDeflationBPS(uint256 bps);
/// @notice Constructor to initialize the DeFi token
/// @param name_ Name of the token
/// @param symbol_ Symbol of the token
/// @param initialSupplyToSet Initial supply of tokens
/// @param decimalsToSet Number of decimals for the token
/// @param tokenOwner Address of the initial token owner
/// @param customConfigProps Configuration properties for the token
/// @param maxTokenAmount Maximum token amount per address
/// @param newDocumentUri URI for the document associated with the token
/// @param _taxAddress Address where tax will be sent
/// @param _taxBPS Basis points for tax calculation
/// @param _deflationBPS Basis points for deflation calculation
constructor(
string memory name_,
string memory symbol_,
uint256 initialSupplyToSet,
uint8 decimalsToSet,
address tokenOwner,
ERC20ConfigProps memory customConfigProps,
uint256 maxTokenAmount,
string memory newDocumentUri,
address _taxAddress,
uint256 _taxBPS,
uint256 _deflationBPS
) ERC20(name_, symbol_) {
if (customConfigProps._isMaxAmountOfTokensSet) {
if (maxTokenAmount == 0) {
revert InvalidMaxTokenAmount(maxTokenAmount);
}
}
if (decimalsToSet > 18) {
revert InvalidDecimals(decimalsToSet);
}
if (customConfigProps._isTaxable) {
if (_taxBPS > MAX_ALLOWED_BPS) {
revert InvalidTaxBPS(_taxBPS);
}
LibCommon.validateAddress(_taxAddress);
taxAddress = _taxAddress;
taxBPS = _taxBPS;
}
if (customConfigProps._isDeflationary) {
if (_deflationBPS > MAX_ALLOWED_BPS) {
revert InvalidDeflationBPS(_deflationBPS);
}
deflationBPS = _deflationBPS;
}
LibCommon.validateAddress(tokenOwner);
initialSupply = initialSupplyToSet;
initialMaxTokenAmountPerAddress = maxTokenAmount;
initialDocumentUri = newDocumentUri;
initialTokenOwner = tokenOwner;
_decimals = decimalsToSet;
configProps = customConfigProps;
documentUri = newDocumentUri;
maxTokenAmountPerAddress = maxTokenAmount;
if (initialSupplyToSet != 0) {
_mint(tokenOwner, initialSupplyToSet * 10 ** decimalsToSet);
}
if (tokenOwner != msg.sender) {
transferOwnership(tokenOwner);
}
}
// Public and External Functions
/// @notice Checks if the token is mintable
/// @return True if the token can be minted
function isMintable() public view returns (bool) {
return configProps._isMintable;
}
/// @notice Checks if the token is burnable
/// @return True if the token can be burned
function isBurnable() public view returns (bool) {
return configProps._isBurnable;
}
/// @notice Checks if the maximum amount of tokens per address is set
/// @return True if there is a maximum limit for token amount per address
function isMaxAmountOfTokensSet() public view returns (bool) {
return configProps._isMaxAmountOfTokensSet;
}
/// @notice Checks if setting a document URI is allowed
/// @return True if setting a document URI is allowed
function isDocumentUriAllowed() public view returns (bool) {
return configProps._isDocumentAllowed;
}
/// @notice Returns the number of decimals used for the token
/// @return The number of decimals
function decimals() public view virtual override returns (uint8) {
return _decimals;
}
/// @notice Checks if the token is taxable
/// @return True if the token has tax applied on transfers
function isTaxable() public view returns (bool) {
return configProps._isTaxable;
}
/// @notice Checks if the token is deflationary
/// @return True if the token has deflation applied on transfers
function isDeflationary() public view returns (bool) {
return configProps._isDeflationary;
}
/// @notice Sets a new document URI
/// @dev Can only be called by the contract owner
/// @param newDocumentUri The new URI to be set
function setDocumentUri(string memory newDocumentUri) external onlyOwner {
if (!isDocumentUriAllowed()) {
revert DocumentUriNotAllowed();
}
documentUri = newDocumentUri;
emit DocumentUriSet(newDocumentUri);
}
/// @notice Sets a new maximum token amount per address
/// @dev Can only be called by the contract owner
/// @param newMaxTokenAmount The new maximum token amount per address
function setMaxTokenAmountPerAddress(
uint256 newMaxTokenAmount
) external onlyOwner {
if (!isMaxAmountOfTokensSet()) {
revert MaxTokenAmountNotAllowed();
}
if (newMaxTokenAmount <= maxTokenAmountPerAddress) {
revert MaxTokenAmountPerAddrLtPrevious();
}
maxTokenAmountPerAddress = newMaxTokenAmount;
emit MaxTokenAmountPerSet(newMaxTokenAmount);
}
/// @notice Sets a new tax configuration
/// @dev Can only be called by the contract owner
/// @param _taxAddress The address where tax will be sent
/// @param _taxBPS The tax rate in basis points
function setTaxConfig(
address _taxAddress,
uint256 _taxBPS
) external onlyOwner {
if (!isTaxable()) {
revert TokenIsNotTaxable();
}
if (_taxBPS > MAX_ALLOWED_BPS) {
revert InvalidTaxBPS(_taxBPS);
}
LibCommon.validateAddress(_taxAddress);
taxAddress = _taxAddress;
taxBPS = _taxBPS;
emit TaxConfigSet(_taxAddress, _taxBPS);
}
/// @notice Sets a new deflation configuration
/// @dev Can only be called by the contract owner
/// @param _deflationBPS The deflation rate in basis points
function setDeflationConfig(uint256 _deflationBPS) external onlyOwner {
if (!isDeflationary()) {
revert TokenIsNotDeflationary();
}
if (_deflationBPS > MAX_ALLOWED_BPS) {
revert InvalidDeflationBPS(_deflationBPS);
}
deflationBPS = _deflationBPS;
emit DeflationConfigSet(_deflationBPS);
}
/// @notice Transfers tokens to a specified address
/// @dev Overrides the ERC20 transfer function with added tax and deflation logic
/// @param to The address to transfer tokens to
/// @param amount The amount of tokens to be transferred
/// @return True if the transfer was successful
function transfer(
address to,
uint256 amount
) public virtual override returns (bool) {
uint256 taxAmount = _taxAmount(msg.sender, amount);
uint256 deflationAmount = _deflationAmount(amount);
uint256 amountToTransfer = amount - taxAmount - deflationAmount;
if (isMaxAmountOfTokensSet()) {
if (balanceOf(to) + amountToTransfer > maxTokenAmountPerAddress) {
revert DestBalanceExceedsMaxAllowed(to);
}
}
if (taxAmount != 0) {
_transfer(msg.sender, taxAddress, taxAmount);
}
if (deflationAmount != 0) {
_burn(msg.sender, deflationAmount);
}
return super.transfer(to, amountToTransfer);
}
/// @notice Transfers tokens from one address to another
/// @dev Overrides the ERC20 transferFrom function with added tax and deflation logic
/// @param from The address which you want to send tokens from
/// @param to The address which you want to transfer to
/// @param amount The amount of tokens to be transferred
/// @return True if the transfer was successful
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
uint256 taxAmount = _taxAmount(from, amount);
uint256 deflationAmount = _deflationAmount(amount);
uint256 amountToTransfer = amount - taxAmount - deflationAmount;
if (isMaxAmountOfTokensSet()) {
if (balanceOf(to) + amountToTransfer > maxTokenAmountPerAddress) {
revert DestBalanceExceedsMaxAllowed(to);
}
}
if (taxAmount != 0) {
_transfer(from, taxAddress, taxAmount);
}
if (deflationAmount != 0) {
_burn(from, deflationAmount);
}
return super.transferFrom(from, to, amountToTransfer);
}
/// @notice Mints new tokens to a specified address
/// @dev Can only be called by the contract owner and if minting is enabled
/// @param to The address to mint tokens to
/// @param amount The amount of tokens to mint
function mint(address to, uint256 amount) external onlyOwner {
if (!isMintable()) {
revert MintingNotEnabled();
}
if (isMaxAmountOfTokensSet()) {
if (balanceOf(to) + amount > maxTokenAmountPerAddress) {
revert DestBalanceExceedsMaxAllowed(to);
}
}
super._mint(to, amount);
}
/// @notice Burns a specific amount of tokens
/// @dev Can only be called by the contract owner and if burning is enabled
/// @param amount The amount of tokens to be burned
function burn(uint256 amount) external onlyOwner {
if (!isBurnable()) {
revert BurningNotEnabled();
}
_burn(msg.sender, amount);
}
/// @notice Renounces ownership of the contract
/// @dev Leaves the contract without an owner, disabling any functions that require the owner's authorization
function renounceOwnership() public override onlyOwner {
super.renounceOwnership();
}
/// @notice Transfers ownership of the contract to a new account
/// @dev Can only be called by the current owner
/// @param newOwner The address of the new owner
function transferOwnership(address newOwner) public override onlyOwner {
super.transferOwnership(newOwner);
}
// Internal Functions
/// @notice Calculates the tax amount for a transfer
/// @param sender The address initiating the transfer
/// @param amount The amount of tokens being transferred
/// @return taxAmount The calculated tax amount
function _taxAmount(
address sender,
uint256 amount
) internal view returns (uint256 taxAmount) {
taxAmount = 0;
if (taxBPS != 0 && sender != taxAddress) {
taxAmount = (amount * taxBPS) / MAX_BPS_AMOUNT;
}
}
/// @notice Calculates the deflation amount for a transfer
/// @param amount The amount of tokens being transferred
/// @return deflationAmount The calculated deflation amount
function _deflationAmount(
uint256 amount
) internal view returns (uint256 deflationAmount) {
deflationAmount = 0;
if (deflationBPS != 0) {
deflationAmount = (amount * deflationBPS) / MAX_BPS_AMOUNT;
}
}
}
LibCommon.sol 118 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
library LibCommon {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The address is the zero address.
error ZeroAddress();
/// @notice raised when an ERC20 transfer fails
error TransferFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ETH OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Taken from Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Sends `amount` (in wei) ETH to `to`.
/// Reverts upon failure.
function safeTransferETH(address to, uint256 amount) internal {
// solhint-disable-next-line no-inline-assembly
assembly {
// Transfer the ETH and check if it succeeded or not.
if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
// Store the function selector of `ETHTransferFailed()`.
// bytes4(keccak256(bytes("ETHTransferFailed()"))) = 0xb12d13eb
mstore(0x00, 0xb12d13eb)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
}
/// @notice Validates that the address is not the zero address using assembly.
/// @dev Reverts if the address is the zero address.
function validateAddress(address addr) internal pure {
// solhint-disable-next-line no-inline-assembly
assembly {
if iszero(shl(96, addr)) {
// Store the function selector of `ZeroAddress()`.
// bytes4(keccak256(bytes("ZeroAddress()"))) = 0xd92e233d
mstore(0x00, 0xd92e233d)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
}
/// @notice Helper function to transfer ERC20 tokens without the need for SafeERC20.
/// @dev Reverts if the ERC20 transfer fails.
/// @param tokenAddress The address of the ERC20 token.
/// @param from The address to transfer the tokens from.
/// @param to The address to transfer the tokens to.
/// @param amount The amount of tokens to transfer.
function safeTransferFrom(
address tokenAddress,
address from,
address to,
uint256 amount
) internal returns (bool) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory data) = tokenAddress.call(
abi.encodeWithSignature(
"transferFrom(address,address,uint256)",
from,
to,
amount
)
);
if (!success) {
if (data.length != 0) {
// bubble up error
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(data)
revert(add(32, data), returndata_size)
}
} else {
revert TransferFailed();
}
}
return true;
}
/// @notice Helper function to transfer ERC20 tokens without the need for SafeERC20.
/// @dev Reverts if the ERC20 transfer fails.
/// @param tokenAddress The address of the ERC20 token.
/// @param to The address to transfer the tokens to.
/// @param amount The amount of tokens to transfer.
function safeTransfer(
address tokenAddress,
address to,
uint256 amount
) internal returns (bool) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory data) = tokenAddress.call(
abi.encodeWithSignature("transfer(address,uint256)", to, amount)
);
if (!success) {
if (data.length != 0) {
// bubble up error
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(data)
revert(add(32, data), returndata_size)
}
} else {
revert TransferFailed();
}
}
return true;
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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;
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ERC20.sol 365 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.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}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* 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 ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => 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 override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override 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 override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override 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 `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` 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 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* 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 `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `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.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` 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.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount) external returns (bool);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
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);
}
Read Contract
VERSION 0xffa1ad74 → string
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
deflationBPS 0x542e9667 → uint256
documentUri 0x044ab74e → string
initialDocumentUri 0xa9d86685 → string
initialMaxTokenAmountPerAddress 0xa32f6976 → uint256
initialSupply 0x378dc3dc → uint256
initialTokenOwner 0x8dac7191 → address
isBurnable 0x883356d9 → bool
isDeflationary 0x8e8c10a2 → bool
isDocumentUriAllowed 0xf820f567 → bool
isMaxAmountOfTokensSet 0x5a3990ce → bool
isMintable 0x46b45af7 → bool
isTaxable 0x4ac0bc32 → bool
maxTokenAmountPerAddress 0xd48e4127 → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
symbol 0x95d89b41 → string
taxAddress 0xb7bda68f → address
taxBPS 0x2fa782eb → uint256
totalSupply 0x18160ddd → uint256
Write Contract 13 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
burn 0x42966c68
uint256 amount
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mint 0x40c10f19
address to
uint256 amount
renounceOwnership 0x715018a6
No parameters
setDeflationConfig 0xd8f67851
uint256 _deflationBPS
setDocumentUri 0xa476df61
string newDocumentUri
setMaxTokenAmountPerAddress 0x02252c4d
uint256 newMaxTokenAmount
setTaxConfig 0xf19c4e3b
address _taxAddress
uint256 _taxBPS
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address