Address Contract Verified
Address
0x5078dd37ee699eB59c096b41C6415417fA02Ec8c
Balance
0 ETH
Nonce
1
Code Size
5779 bytes
Creator
0x965262c1...cCAB at tx 0x468b92f1...bad068
Indexed Transactions
0
Contract Bytecode
5779 bytes
0x608060405234801561001057600080fd5b50600436106101c45760003560e01c8063613255ab116100f9578063af9e65d011610097578063d850020611610071578063d8500206146103f2578063d9d98ce414610419578063dd62ed3e1461042c578063f0292a031461046557600080fd5b8063af9e65d01461039b578063cf665443146103c2578063cf9e8e69146103cb57600080fd5b806395d89b41116100d357806395d89b41146103465780639f80434a1461034e578063a457c2d714610375578063a9059cbb1461038857600080fd5b8063613255ab146102e257806370a08231146102f557806377097fc81461031e57600080fd5b8063313ce567116101665780633fa21806116101405780633fa2180614610292578063598391971461029b57806359a7715a146102c65780635cffe9de146102cf57600080fd5b8063313ce5671461024a578063355274ea14610259578063395093511461027f57600080fd5b8063219ee89c116101a2578063219ee89c1461021c578063237b64791461022557806323b872dd1461022e5780632552317c1461024157600080fd5b806306fdde03146101c9578063095ea7b3146101e757806318160ddd1461020a575b600080fd5b6101d161048c565b6040516101de91906112d1565b60405180910390f35b6101fa6101f5366004611300565b61051e565b60405190151581526020016101de565b6008545b6040519081526020016101de565b61020e60015481565b61020e60025481565b6101fa61023c36600461132c565b610534565b61020e60035481565b604051601281526020016101de565b7fffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de00000061020e565b6101fa61028d366004611300565b6105f8565b61020e60045481565b6005546102ae906001600160a01b031681565b6040516001600160a01b0390911681526020016101de565b61020e600b5481565b6101fa6102dd36600461136d565b610634565b61020e6102f036600461140c565b610860565b61020e61030336600461140c565b6001600160a01b031660009081526006602052604090205490565b61033161032c36600461143f565b61088e565b604080519283529015156020830152016101de565b6101d161090a565b61020e7f000000000000000000000000000000000000000000000000000000000000070881565b6101fa610383366004611300565b610919565b6101fa610396366004611300565b6109ca565b61020e7f000000000000000000000000000000000000000000000000000000000000002581565b61020e60005481565b61020e7fffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de00000081565b61020e7fffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de00000081565b61020e610427366004611300565b6109d7565b61020e61043a3660046114fa565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205490565b61020e7f000000000000000000000000000000000000000000000000100000000000000081565b60606009805461049b90611533565b80601f01602080910402602001604051908101604052809291908181526020018280546104c790611533565b80156105145780601f106104e957610100808354040283529160200191610514565b820191906000526020600020905b8154815290600101906020018083116104f757829003601f168201915b5050505050905090565b600061052b338484610a3b565b50600192915050565b6000610541848484610b94565b6001600160a01b0384166000908152600760209081526040808320338452909152902054828110156105e05760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206160448201527f6c6c6f77616e636500000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b6105ed8533858403610a3b565b506001949350505050565b3360008181526007602090815260408083206001600160a01b0387168452909152812054909161052b91859061062f908690611584565b610a3b565b60008061064186866109d7565b905061064d8786610dac565b6040517f23e30c8b0000000000000000000000000000000000000000000000000000000081527f439148f0bbc682ca079e46d6e2c2f0c1e3b820f1a291b069d8882abf8cf18dd9906001600160a01b038916906323e30c8b906106be9033908b908b9088908c908c9060040161159c565b602060405180830381600087803b1580156106d857600080fd5b505af11580156106ec573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061071091906115f7565b146107825760405162461bcd60e51b8152602060048201526024808201527f4552433230466c6173684d696e743a20696e76616c69642072657475726e207660448201527f616c75650000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b03871660009081526007602090815260408083203084529091529020546107b08287611584565b8110156108255760405162461bcd60e51b815260206004820152602f60248201527f4552433230466c6173684d696e743a20616c6c6f77616e636520646f6573206e60448201527f6f7420616c6c6f7720726566756e64000000000000000000000000000000000060648201526084016105d7565b61083f8830846108358a86611610565b61062f9190611610565b6108528861084d8489611584565b610e8b565b506001979650505050505050565b60006001600160a01b0382163014610879576000610888565b60085461088890600019611610565b92915050565b60008061089b8484611008565b600b5491935091507fffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000000906108d0908490611584565b11156108db57600091505b81156109035781600b60008282546108f39190611584565b9091555061090390503383610dac565b9250929050565b6060600a805461049b90611533565b3360009081526007602090815260408083206001600160a01b0386168452909152812054828110156109b35760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f00000000000000000000000000000000000000000000000000000060648201526084016105d7565b6109c03385858403610a3b565b5060019392505050565b600061052b338484610b94565b60006001600160a01b0383163014610a315760405162461bcd60e51b815260206004820152601b60248201527f4552433230466c6173684d696e743a2077726f6e6720746f6b656e000000000060448201526064016105d7565b5060005492915050565b6001600160a01b038316610ab65760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b038216610b325760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f737300000000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b0383811660008181526007602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316610c105760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f647265737300000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b038216610c8c5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f657373000000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b03831660009081526006602052604090205481811015610d1b5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e6365000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b03808516600090815260066020526040808220858503905591851681529081208054849290610d52908490611584565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610d9e91815260200190565b60405180910390a350505050565b6001600160a01b038216610e025760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016105d7565b8060086000828254610e149190611584565b90915550506001600160a01b03821660009081526006602052604081208054839290610e41908490611584565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160a01b038216610f075760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f730000000000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b03821660009081526006602052604090205481811015610f965760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f636500000000000000000000000000000000000000000000000000000000000060648201526084016105d7565b6001600160a01b0383166000908152600660205260408120838303905560088054849290610fc5908490611610565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001610b87565b6000806110417fffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de00000061103a600143611610565b4017611056565b61104b848461115f565b909590945092505050565b60025442111561115c577f000000000000000000000000000000000000000000000000000000000000002560015410156110f7576000805460011b908190556110a357600160005561112b565b7f000000000000000000000000000000000000000000000000100000000000000060005411156110f2577f00000000000000000000000000000000000000000000000010000000000000006000555b61112b565b7f0000000000000000000000000000000000000000000000000000000000000025600154111561112b576000805460011c90555b60006001556004819055427f0000000000000000000000000000000000000000000000000000000000000708016002555b50565b60008060008433600454604051602001611195939291909283526001600160a01b03919091166020830152604082015260600190565b604051602081830303815290604052805190602001209050600454811080156111bf575060035443115b15611277576001805481019081905560045460005460405133937f5d0de1f766ffaf66be1e22a6cdc0fe72bf858307b85f07592c7b175433f577839361120c939192909187918b90611627565b60405180910390a26004555050600580547fffffffffffffffffffffffff0000000000000000000000000000000000000000163317905543600355427f0000000000000000000000000000000000000000000000000000000000000708016002556000546001610903565b6000809250925050610903565b6000815180845260005b818110156112aa5760208185018101518683018201520161128e565b818111156112bc576000602083870101525b50601f01601f19169290920160200192915050565b6020815260006112e46020830184611284565b9392505050565b6001600160a01b038116811461115c57600080fd5b6000806040838503121561131357600080fd5b823561131e816112eb565b946020939093013593505050565b60008060006060848603121561134157600080fd5b833561134c816112eb565b9250602084013561135c816112eb565b929592945050506040919091013590565b60008060008060006080868803121561138557600080fd5b8535611390816112eb565b945060208601356113a0816112eb565b935060408601359250606086013567ffffffffffffffff808211156113c457600080fd5b818801915088601f8301126113d857600080fd5b8135818111156113e757600080fd5b8960208285010111156113f957600080fd5b9699959850939650602001949392505050565b60006020828403121561141e57600080fd5b81356112e4816112eb565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561145257600080fd5b82359150602083013567ffffffffffffffff8082111561147157600080fd5b818501915085601f83011261148557600080fd5b81358181111561149757611497611429565b604051601f8201601f19908116603f011681019083821181831017156114bf576114bf611429565b816040528281528860208487010111156114d857600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000806040838503121561150d57600080fd5b8235611518816112eb565b91506020830135611528816112eb565b809150509250929050565b600181811c9082168061154757607f821691505b6020821081141561156857634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156115975761159761156e565b500190565b60006001600160a01b03808916835280881660208401525085604083015284606083015260a060808301528260a0830152828460c0840137600060c0848401015260c0601f19601f8501168301019050979650505050505050565b60006020828403121561160957600080fd5b5051919050565b6000828210156116225761162261156e565b500390565b85815284602082015283604082015282606082015260a06080820152600061165260a0830184611284565b97965050505050505056fea2646970667358221220acc8b73183a29a75d059a75141c2013fcf890a8f5151ee1ac4bb19270c299fab64736f6c63430008090033
Verified Source Code Full Match
Compiler: v0.8.9+commit.e5eed63a
EVM: london
Optimization: Yes (1000 runs)
NuPoW.sol 105 lines
/*
* Copyright (C) 2022 Christian Felde
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
pragma solidity ^0.8.0;
abstract contract NuPoW {
bytes32 public constant CFELDE = 0xffff000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000cfe1de000000;
uint public immutable CHAIN_LENGTH_TARGET;
uint public immutable MAX_MINT;
uint public immutable STALLED_DURATION;
uint public nextMint;
uint public chainLength;
uint public stalledTimestamp;
uint public lastBlockNumber;
bytes32 public lastHash;
address public lastChallenger;
event ChainProgress(address indexed challenger, uint chainLength, bytes32 oldHash, bytes32 newHash, uint nextMint, string tag);
constructor(
uint _CHAIN_LENGTH_TARGET,
uint8 _MAX_MINT_OFFSET,
uint _STALLED_DURATION
) {
CHAIN_LENGTH_TARGET = _CHAIN_LENGTH_TARGET;
MAX_MINT = 1 << _MAX_MINT_OFFSET;
STALLED_DURATION = _STALLED_DURATION;
nextMint = MAX_MINT;
}
// Manage stalled and nextMint
function _manage(
bytes32 stalledDifficulty
) internal {
unchecked {
if (block.timestamp > stalledTimestamp) {
if (chainLength < CHAIN_LENGTH_TARGET) {
nextMint = nextMint << 1;
if (nextMint == 0) nextMint = 1;
else if (nextMint > MAX_MINT) nextMint = MAX_MINT;
} else if (chainLength > CHAIN_LENGTH_TARGET) {
nextMint = nextMint >> 1;
}
chainLength = 0;
lastHash = stalledDifficulty;
stalledTimestamp = block.timestamp + STALLED_DURATION;
}
}
}
// Manage hash and progress
function _challenge(
uint seed,
string memory tag
) internal returns (uint, bool) {
unchecked {
bytes32 hash = keccak256(abi.encode(seed, msg.sender, lastHash));
if (hash < lastHash && block.number > lastBlockNumber) {
chainLength++;
emit ChainProgress(msg.sender, chainLength, lastHash, hash, nextMint, tag);
lastHash = hash;
lastChallenger = msg.sender;
lastBlockNumber = block.number;
stalledTimestamp = block.timestamp + STALLED_DURATION;
return (nextMint, true);
} else {
return (0, false);
}
}
}
// Base implementation of mint (actual minting left to inheriting contract)
function mint(
uint seed,
string memory tag
) public virtual returns (
uint mintValue,
bool progress
) {
_manage(blockhash(block.number - 1) | CFELDE);
(mintValue, progress) = _challenge(seed, tag);
}
}
Crystal.sol 65 lines
/*
* Copyright (C) 2022 Christian Felde
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
pragma solidity ^0.8.0;
import "./NuPoW.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol";
contract Crystal is NuPoW, ERC20FlashMint {
uint public immutable MAX_TOTAL_MINT;
uint public totalMint;
constructor(
string memory _NAME,
string memory _SYMBOL,
uint _MAX_TOTAL_MINT
) ERC20(_NAME, _SYMBOL) NuPoW(37, 60, 30 minutes) {
MAX_TOTAL_MINT = _MAX_TOTAL_MINT;
}
function flashFee(
address token,
uint amount
) public view virtual override returns (uint) {
require(token == address(this), "ERC20FlashMint: wrong token");
amount;
return nextMint;
}
function cap() public view virtual returns (uint) {
return MAX_TOTAL_MINT;
}
function mint(
uint seed,
string memory tag
) public override returns (
uint mintValue,
bool progress
) {
(mintValue, progress) = super.mint(seed, tag);
if (totalMint + mintValue > MAX_TOTAL_MINT) mintValue = 0;
if (mintValue > 0) {
totalMint += mintValue;
_mint(msg.sender, mintValue);
}
}
}
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;
}
}
ERC20.sol 356 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* 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}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* 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 value {ERC20} uses, unless this function is
* 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:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, 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}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), 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}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - 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) {
_approve(_msgSender(), spender, _allowances[_msgSender()][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) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* 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:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
_afterTokenTransfer(sender, recipient, 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;
_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;
}
_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 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 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}
IERC3156.sol 7 lines
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156.sol) pragma solidity ^0.8.0; import "./IERC3156FlashBorrower.sol"; import "./IERC3156FlashLender.sol";
IERC3156FlashLender.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashLender.sol)
pragma solidity ^0.8.0;
import "./IERC3156FlashBorrower.sol";
/**
* @dev Interface of the ERC3156 FlashLender, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/
interface IERC3156FlashLender {
/**
* @dev The amount of currency available to be lended.
* @param token The loan currency.
* @return The amount of `token` that can be borrowed.
*/
function maxFlashLoan(address token) external view returns (uint256);
/**
* @dev The fee to be charged for a given loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @return The amount of `token` to be charged for the loan, on top of the returned principal.
*/
function flashFee(address token, uint256 amount) external view returns (uint256);
/**
* @dev Initiate a flash loan.
* @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
*/
function flashLoan(
IERC3156FlashBorrower receiver,
address token,
uint256 amount,
bytes calldata data
) external returns (bool);
}
IERC3156FlashBorrower.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashBorrower.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC3156 FlashBorrower, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/
interface IERC3156FlashBorrower {
/**
* @dev Receive a flash loan.
* @param initiator The initiator of the loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param fee The additional amount of tokens to repay.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
* @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
*/
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external returns (bytes32);
}
ERC20FlashMint.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20FlashMint.sol)
pragma solidity ^0.8.0;
import "../../../interfaces/IERC3156.sol";
import "../ERC20.sol";
/**
* @dev Implementation of the ERC3156 Flash loans extension, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* Adds the {flashLoan} method, which provides flash loan support at the token
* level. By default there is no fee, but this can be changed by overriding {flashFee}.
*
* _Available since v4.1._
*/
abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
bytes32 private constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
/**
* @dev Returns the maximum amount of tokens available for loan.
* @param token The address of the token that is requested.
* @return The amont of token that can be loaned.
*/
function maxFlashLoan(address token) public view override returns (uint256) {
return token == address(this) ? type(uint256).max - ERC20.totalSupply() : 0;
}
/**
* @dev Returns the fee applied when doing flash loans. By default this
* implementation has 0 fees. This function can be overloaded to make
* the flash loan mechanism deflationary.
* @param token The token to be flash loaned.
* @param amount The amount of tokens to be loaned.
* @return The fees applied to the corresponding flash loan.
*/
function flashFee(address token, uint256 amount) public view virtual override returns (uint256) {
require(token == address(this), "ERC20FlashMint: wrong token");
// silence warning about unused variable without the addition of bytecode.
amount;
return 0;
}
/**
* @dev Performs a flash loan. New tokens are minted and sent to the
* `receiver`, who is required to implement the {IERC3156FlashBorrower}
* interface. By the end of the flash loan, the receiver is expected to own
* amount + fee tokens and have them approved back to the token contract itself so
* they can be burned.
* @param receiver The receiver of the flash loan. Should implement the
* {IERC3156FlashBorrower.onFlashLoan} interface.
* @param token The token to be flash loaned. Only `address(this)` is
* supported.
* @param amount The amount of tokens to be loaned.
* @param data An arbitrary datafield that is passed to the receiver.
* @return `true` is the flash loan was successful.
*/
function flashLoan(
IERC3156FlashBorrower receiver,
address token,
uint256 amount,
bytes calldata data
) public virtual override returns (bool) {
uint256 fee = flashFee(token, amount);
_mint(address(receiver), amount);
require(
receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE,
"ERC20FlashMint: invalid return value"
);
uint256 currentAllowance = allowance(address(receiver), address(this));
require(currentAllowance >= amount + fee, "ERC20FlashMint: allowance does not allow refund");
_approve(address(receiver), address(this), currentAllowance - amount - fee);
_burn(address(receiver), amount + fee);
return true;
}
}
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
CFELDE 0xd8500206 → bytes32
CHAIN_LENGTH_TARGET 0xaf9e65d0 → uint256
MAX_MINT 0xf0292a03 → uint256
MAX_TOTAL_MINT 0xcf9e8e69 → uint256
STALLED_DURATION 0x9f80434a → uint256
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
cap 0x355274ea → uint256
chainLength 0x219ee89c → uint256
decimals 0x313ce567 → uint8
flashFee 0xd9d98ce4 → uint256
lastBlockNumber 0x2552317c → uint256
lastChallenger 0x59839197 → address
lastHash 0x3fa21806 → bytes32
maxFlashLoan 0x613255ab → uint256
name 0x06fdde03 → string
nextMint 0xcf665443 → uint256
stalledTimestamp 0x237b6479 → uint256
symbol 0x95d89b41 → string
totalMint 0x59a7715a → uint256
totalSupply 0x18160ddd → uint256
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
flashLoan 0x5cffe9de
address receiver
address token
uint256 amount
bytes data
returns: bool
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mint 0x77097fc8
uint256 seed
string tag
returns: uint256, bool
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool
Recent Transactions
No transactions found for this address