Source Code
Overview
ETH Balance
ETH Value
$0.00Cross-Chain Transactions
Loading...
Loading
Contract Name:
ListingsErc1155
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract ListingsErc1155 is Ownable(msg.sender) {
// Using struct packing optimization with two 256-bit slots:
// 1st slot: 256 bits = 128-bit id + 128-bit amount
// 2nd slot: 256 bits = 128-bit price + 120-bit expireTime + 8-bit comission percent
struct Listing {
uint128 id;
uint128 amount;
uint128 price;
uint120 expireTime;
uint8 commissionPercent;
}
// Maximum commission percent
uint8 public constant MAX_COMMISION_PERCENT = 10;
// Required to calculate the expiration time of a listing
uint256 private constant SECONDS_IN_HOUR = 3_600;
// Commission percent defines what part of the transaction's value the contract
// keeps for itself. Can be adjusted with setCommissionPercent function
uint8 public commissionPercent;
// Map keeps listings, so we can instantly find one with getListing externally
// or just via contract address, token id and seller address internally.
// We use the seller address here because several sellers can create listings
// for the same token id, since they own not the whole token but the amount of it
// contractAddress => tokenId => seller => Listing
mapping(address => mapping(uint256 => mapping(address => Listing))) private _listings;
// Track listing id, so each listing can have a unique number
uint128 private _idCounter = 1;
// Emits when a seller creates a new listing
event ListingCreated(
uint128 id,
address indexed seller,
address indexed contractAddress,
uint256 indexed tokenId,
uint128 amount,
uint128 price,
uint120 expireTime,
uint8 commissionPercent
);
// Emits when a seller cancels his listing
event ListingRemoved(
uint128 id,
address indexed seller,
address indexed contractAddress,
uint256 indexed tokenId,
uint128 amount,
uint128 price,
uint120 expireTime
);
// Emits when a token has been sold to a buyer
event TokenSold(
uint128 id,
address indexed seller,
address buyer,
address indexed contractAddress,
uint256 indexed tokenId,
uint128 amount,
uint128 price
);
// Emits when commissionPercent has been changed
event CommissionPercentChanged(uint8 indexed percent);
// Changes commission percent for purchases
// The higher the percentage, the larger part of the transaction's value will be
// kept by the contract. Can be changed only by the owner of the contract
function setCommissionPercent(uint8 percent) external onlyOwner {
require(percent <= MAX_COMMISION_PERCENT, "Max commission percent exceeded");
emit CommissionPercentChanged(percent);
commissionPercent = percent;
}
// Transfers all the weis of the contract to the owner
function withdraw() external onlyOwner {
(bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
require(success, "Transfer failed");
}
// Creates a listing for a token
function addListing(
address contractAddress,
uint256 tokenId,
uint128 amount,
uint128 price,
uint16 durationHours
) external {
// Do not allow empty listings
require(amount > 0, "Amount must be > 0");
// Forbid free listings
require(price > 0, "Price must be > 0");
// Forbid immediately expiring listings
require(durationHours > 0, "Duration must be > 0");
// Do not allow selling more tokens than one has
IERC1155 nftContract = IERC1155(contractAddress);
uint256 ownerTokenAmount = nftContract.balanceOf(msg.sender, tokenId);
require(amount <= ownerTokenAmount, "Not enough tokens");
// Forbid listings for unapproved tokens
bool isApproved = nftContract.isApprovedForAll(msg.sender, address(this));
require(isApproved, "Contract is not approved");
uint128 id = _idCounter;
// Calculate the time when this listing becomes unavailable
uint120 expireTime = uint120(block.timestamp + (durationHours * SECONDS_IN_HOUR));
uint8 listingCommissionPercent = commissionPercent;
// Add the listing to the map
_listings[contractAddress][tokenId][msg.sender] = Listing({
id: id,
amount: amount,
price: price,
expireTime: expireTime,
commissionPercent: listingCommissionPercent
});
emit ListingCreated(
id,
msg.sender,
contractAddress,
tokenId,
amount,
price,
expireTime,
listingCommissionPercent
);
// Increment the counter for the next listing
_idCounter = id + 1;
}
// Allows to manually cancel a listing
function cancelListing(address contractAddress, uint256 tokenId) external {
mapping(address => Listing) storage tokenListings =
_listings[contractAddress][tokenId];
Listing memory listing = tokenListings[msg.sender];
// Since free listings are forbidden, a found listing with 0 price
// basically means that there is no such listing
require(listing.price > 0, "Listing does not exist");
// Remove the listing from the map
_clearListing(tokenListings, msg.sender);
emit ListingRemoved(
listing.id,
msg.sender,
contractAddress,
tokenId,
listing.amount,
listing.price,
listing.expireTime
);
}
// Allows to buy a token
function buyToken(
address contractAddress,
uint256 tokenId,
address seller,
uint256 amount
) external payable {
mapping(address => Listing) storage tokenListings =
_listings[contractAddress][tokenId];
Listing memory listing = tokenListings[seller];
// Since free listings are forbidden, a found listing with 0 price
// basically means that there is no such listing
require(listing.price > 0, "Listing does not exist");
// Do not allow to buy a token via an expired listing
require(block.timestamp < listing.expireTime, "Listing is expired");
// Do not allow accounts to buy their own tokens
require(msg.sender != seller, "Seller can not buy his tokens");
// Check if the desired and saved amounts are the same
// Preventing possible race condition. See additional info here:
// https://github.com/Conft-dev/conft-contracts/issues/32
require(amount == listing.amount, "Incorrect amount");
// Check if the seller still owns his tokens
IERC1155 nftContract = IERC1155(contractAddress);
uint256 ownerTokenAmount = nftContract.balanceOf(seller, tokenId);
require(listing.amount <= ownerTokenAmount, "Not enough tokens");
// Check if the tokens are still approved for this contract
bool isApproved = nftContract.isApprovedForAll(seller, address(this));
require(isApproved, "Contract is not approved");
// Allow the buyer to buy at the price that the seller wants
// price check must be the last because of Atlas IDE bug
require(msg.value == listing.price * listing.amount, "Mismatch of funds");
emit TokenSold(
listing.id,
seller,
msg.sender,
contractAddress,
tokenId,
listing.amount,
listing.price
);
// Remove the listing from the map
_clearListing(tokenListings, seller);
// Transfer the tokens to the buyer
nftContract.safeTransferFrom(seller, msg.sender, tokenId, listing.amount, "");
// Calculate the commission for this transaction
uint256 commission = msg.value * listing.commissionPercent / 100;
uint256 valueWithoutCommission = msg.value - commission;
// Transfer money to the seller
(bool success, ) = payable(seller).call{value: valueWithoutCommission}("");
require(success, "Transfer failed");
}
// Instantly find a listing with a contract address and token id
function getListing(
address contractAddress,
uint256 tokenId,
address seller
) external view returns (Listing memory) {
return _listings[contractAddress][tokenId][seller];
}
// Remove a listing from the state
function _clearListing(
mapping(address => Listing) storage tokenListings,
address seller
) private {
delete tokenListings[seller];
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../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.
*
* The initial owner is set to the address provided by the deployer. 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;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @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 {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @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 {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_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);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 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 ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-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 ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "./IERC1155.sol";
import {IERC1155Receiver} from "./IERC1155Receiver.sol";
import {IERC1155MetadataURI} from "./extensions/IERC1155MetadataURI.sol";
import {Context} from "../../utils/Context.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {Arrays} from "../../utils/Arrays.sol";
import {IERC1155Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*/
abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
using Arrays for uint256[];
using Arrays for address[];
mapping(uint256 id => mapping(address account => uint256)) private _balances;
mapping(address account => mapping(address operator => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/**
* @dev See {_setURI}.
*/
constructor(string memory uri_) {
_setURI(uri_);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256 /* id */) public view virtual returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*/
function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
) public view virtual returns (uint256[] memory) {
if (accounts.length != ids.length) {
revert ERC1155InvalidArrayLength(ids.length, accounts.length);
}
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i));
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeTransferFrom(from, to, id, value, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeBatchTransferFrom(from, to, ids, values, data);
}
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
* (or `to`) is the zero address.
*
* Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received}
* or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value.
* - `ids` and `values` must have the same length.
*
* NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead.
*/
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual {
if (ids.length != values.length) {
revert ERC1155InvalidArrayLength(ids.length, values.length);
}
address operator = _msgSender();
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids.unsafeMemoryAccess(i);
uint256 value = values.unsafeMemoryAccess(i);
if (from != address(0)) {
uint256 fromBalance = _balances[id][from];
if (fromBalance < value) {
revert ERC1155InsufficientBalance(from, fromBalance, value, id);
}
unchecked {
// Overflow not possible: value <= fromBalance
_balances[id][from] = fromBalance - value;
}
}
if (to != address(0)) {
_balances[id][to] += value;
}
}
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
emit TransferSingle(operator, from, to, id, value);
} else {
emit TransferBatch(operator, from, to, ids, values);
}
}
/**
* @dev Version of {_update} that performs the token acceptance check by calling
* {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it
* contains code (eg. is a smart contract at the moment of execution).
*
* IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any
* update to the contract state after this function would break the check-effect-interaction pattern. Consider
* overriding {_update} instead.
*/
function _updateWithAcceptanceCheck(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal virtual {
_update(from, to, ids, values);
if (to != address(0)) {
address operator = _msgSender();
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
_doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
} else {
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
}
}
}
/**
* @dev Transfers a `value` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
* - `ids` and `values` must have the same length.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the values in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev Destroys a `value` amount of tokens of type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
*/
function _burn(address from, uint256 id, uint256 value) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
* - `ids` and `values` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC1155InvalidOperator(address(0));
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Performs an acceptance check by calling {IERC1155-onERC1155Received} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 value,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Performs a batch acceptance check by calling {IERC1155-onERC1155BatchReceived} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Creates an array in memory with only one value for each of the elements provided.
*/
function _asSingletonArrays(
uint256 element1,
uint256 element2
) private pure returns (uint256[] memory array1, uint256[] memory array2) {
/// @solidity memory-safe-assembly
assembly {
// Load the free memory pointer
array1 := mload(0x40)
// Set array length to 1
mstore(array1, 1)
// Store the single element at the next word after the length (where content starts)
mstore(add(array1, 0x20), element1)
// Repeat for next array locating it right after the first array
array2 := add(array1, 0x40)
mstore(array2, 1)
mstore(add(array2, 0x20), element2)
// Update the free memory pointer by pointing after the second array
mstore(0x40, add(array2, 0x40))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using StorageSlot for bytes32;
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* `array` is expected to be sorted in ascending order, and to contain no
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}{
"optimizer": {
"enabled": true,
"runs": 1000
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint8","name":"percent","type":"uint8"}],"name":"CommissionPercentChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"id","type":"uint128"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"price","type":"uint128"},{"indexed":false,"internalType":"uint120","name":"expireTime","type":"uint120"},{"indexed":false,"internalType":"uint8","name":"commissionPercent","type":"uint8"}],"name":"ListingCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"id","type":"uint128"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"price","type":"uint128"},{"indexed":false,"internalType":"uint120","name":"expireTime","type":"uint120"}],"name":"ListingRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"id","type":"uint128"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"price","type":"uint128"}],"name":"TokenSold","type":"event"},{"inputs":[],"name":"MAX_COMMISION_PERCENT","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint16","name":"durationHours","type":"uint16"}],"name":"addListing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"cancelListing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"commissionPercent","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"}],"name":"getListing","outputs":[{"components":[{"internalType":"uint128","name":"id","type":"uint128"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint120","name":"expireTime","type":"uint120"},{"internalType":"uint8","name":"commissionPercent","type":"uint8"}],"internalType":"struct ListingsErc1155.Listing","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"percent","type":"uint8"}],"name":"setCommissionPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6080604052600280546001600160801b031916600117905534801561002357600080fd5b50338061004a57604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b61005381610059565b506100a9565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b611511806100b86000396000f3fe6080604052600436106100bc5760003560e01c80638728371811610074578063b2ddee061161004e578063b2ddee06146102bf578063f2fde38b146102df578063fbcba78b146102ff57600080fd5b806387283718146102645780638da5cb5b146102775780638eefba6a1461029f57600080fd5b806347518c16116100a557806347518c1614610104578063715018a61461022e57806377d3550b1461024357600080fd5b806309ddd947146100c15780633ccfd60b146100ed575b600080fd5b3480156100cd57600080fd5b506100d6600a81565b60405160ff90911681526020015b60405180910390f35b3480156100f957600080fd5b5061010261031f565b005b34801561011057600080fd5b506101d861011f366004611264565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506001600160a01b039283166000908152600160208181526040808420958452948152848320939095168252918452829020825160a08101845281546001600160801b038082168352600160801b918290048116968301969096529190920154938416928201929092529082046001600160781b03166060820152600160f81b90910460ff16608082015290565b6040805182516001600160801b0390811682526020808501518216908301528383015116918101919091526060808301516001600160781b03169082015260809182015160ff169181019190915260a0016100e4565b34801561023a57600080fd5b506101026103c7565b34801561024f57600080fd5b506000546100d690600160a01b900460ff1681565b6101026102723660046112a0565b6103db565b34801561028357600080fd5b506000546040516001600160a01b0390911681526020016100e4565b3480156102ab57600080fd5b506101026102ba3660046112e4565b6109d7565b3480156102cb57600080fd5b506101026102da36600461130e565b610a9c565b3480156102eb57600080fd5b506101026102fa366004611338565b610c18565b34801561030b57600080fd5b5061010261031a36600461136a565b610c6c565b61032761119a565b604051600090339047908381818185875af1925050503d8060008114610369576040519150601f19603f3d011682016040523d82523d6000602084013e61036e565b606091505b50509050806103c45760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c6564000000000000000000000000000000000060448201526064015b60405180910390fd5b50565b6103cf61119a565b6103d960006111e0565b565b6001600160a01b0384811660009081526001602081815260408084208885528252808420948716845284825292839020835160a08101855281546001600160801b038082168352600160801b91829004811694830194909452919093015491821693830184905281046001600160781b03166060830152600160f81b900460ff166080820152906104ae5760405162461bcd60e51b815260206004820152601660248201527f4c697374696e6720646f6573206e6f742065786973740000000000000000000060448201526064016103bb565b80606001516001600160781b0316421061050a5760405162461bcd60e51b815260206004820152601260248201527f4c697374696e672069732065787069726564000000000000000000000000000060448201526064016103bb565b6001600160a01b03841633036105625760405162461bcd60e51b815260206004820152601d60248201527f53656c6c65722063616e206e6f74206275792068697320746f6b656e7300000060448201526064016103bb565b80602001516001600160801b031683146105be5760405162461bcd60e51b815260206004820152601060248201527f496e636f727265637420616d6f756e740000000000000000000000000000000060448201526064016103bb565b604051627eeac760e11b81526001600160a01b03858116600483015260248201879052879160009183169062fdd58e90604401602060405180830381865afa15801561060e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063291906113d3565b90508083602001516001600160801b031611156106915760405162461bcd60e51b815260206004820152601160248201527f4e6f7420656e6f75676820746f6b656e7300000000000000000000000000000060448201526064016103bb565b60405163e985e9c560e01b81526001600160a01b0387811660048301523060248301526000919084169063e985e9c590604401602060405180830381865afa1580156106e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070591906113ec565b9050806107545760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206973206e6f7420617070726f766564000000000000000060448201526064016103bb565b836020015184604001516107689190611424565b6001600160801b031634146107bf5760405162461bcd60e51b815260206004820152601160248201527f4d69736d61746368206f662066756e647300000000000000000000000000000060448201526064016103bb565b835160208086015160408088015181516001600160801b03958616815233948101949094529184168382015292166060820152905189916001600160a01b038c811692908b16917fec2d1ad7b25071481ab73189817e6c393b31b2f43d7ddca8f30a40955b6afbda919081900360800190a46001600160a01b03871660009081526020869052604081208181556001015560208401516040517ff242432a0000000000000000000000000000000000000000000000000000000081526001600160a01b038981166004830152336024830152604482018b90526001600160801b03909216606482015260a06084820152600060a48201529084169063f242432a9060c401600060405180830381600087803b1580156108dd57600080fd5b505af11580156108f1573d6000803e3d6000fd5b5050505060006064856080015160ff163461090c919061144f565b610916919061146c565b90506000610924823461148e565b90506000896001600160a01b03168260405160006040518083038185875af1925050503d8060008114610973576040519150601f19603f3d011682016040523d82523d6000602084013e610978565b606091505b50509050806109c95760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c6564000000000000000000000000000000000060448201526064016103bb565b505050505050505050505050565b6109df61119a565b600a60ff82161115610a335760405162461bcd60e51b815260206004820152601f60248201527f4d617820636f6d6d697373696f6e2070657263656e742065786365656465640060448201526064016103bb565b60405160ff8216907fd664cd5eaa7c9c9beb44548ab91d4ee4de2dcf83e43aa94be98f467bc0c675d390600090a26000805460ff909216600160a01b027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6001600160a01b0382166000908152600160208181526040808420858552825280842033855280835293819020815160a08101835281546001600160801b038082168352600160801b91829004811695830195909552919094015492831691840182905282046001600160781b03166060840152600160f81b90910460ff166080830152610b6c5760405162461bcd60e51b815260206004820152601660248201527f4c697374696e6720646f6573206e6f742065786973740000000000000000000060448201526064016103bb565b3360009081526020839052604081208181556001015582846001600160a01b0316336001600160a01b03167f5536ab552ca4bc7c34f4663d577fc5e8ed0dd88cdb5baf00c63208edfc1eb7108460000151856020015186604001518760600151604051610c0a94939291906001600160801b0394851681529284166020840152921660408201526001600160781b0391909116606082015260800190565b60405180910390a450505050565b610c2061119a565b6001600160a01b038116610c63576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024016103bb565b6103c4816111e0565b6000836001600160801b031611610cc55760405162461bcd60e51b815260206004820152601260248201527f416d6f756e74206d757374206265203e2030000000000000000000000000000060448201526064016103bb565b6000826001600160801b031611610d1e5760405162461bcd60e51b815260206004820152601160248201527f5072696365206d757374206265203e203000000000000000000000000000000060448201526064016103bb565b60008161ffff1611610d725760405162461bcd60e51b815260206004820152601460248201527f4475726174696f6e206d757374206265203e203000000000000000000000000060448201526064016103bb565b604051627eeac760e11b81523360048201526024810185905285906000906001600160a01b0383169062fdd58e90604401602060405180830381865afa158015610dc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de491906113d3565b905080856001600160801b03161115610e3f5760405162461bcd60e51b815260206004820152601160248201527f4e6f7420656e6f75676820746f6b656e7300000000000000000000000000000060448201526064016103bb565b60405163e985e9c560e01b81523360048201523060248201526000906001600160a01b0384169063e985e9c590604401602060405180830381865afa158015610e8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb091906113ec565b905080610eff5760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206973206e6f7420617070726f766564000000000000000060448201526064016103bb565b6002546001600160801b03166000610f1d610e1061ffff881661144f565b610f2790426114a1565b905060008060149054906101000a900460ff1690506040518060a00160405280846001600160801b031681526020018a6001600160801b03168152602001896001600160801b03168152602001836001600160781b031681526020018260ff16815250600160008d6001600160a01b03166001600160a01b0316815260200190815260200160002060008c81526020019081526020016000206000336001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a8154816001600160801b0302191690836001600160801b0316021790555060208201518160000160106101000a8154816001600160801b0302191690836001600160801b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b0316021790555060608201518160010160106101000a8154816001600160781b0302191690836001600160781b03160217905550608082015181600101601f6101000a81548160ff021916908360ff160217905550905050898b6001600160a01b0316336001600160a01b03167f140b13e6499f69444379a27c3e8c6065f3651d2f0dcd3757d8e5d338dfcc624a868d8d88886040516111429594939291906001600160801b03958616815293851660208501529190931660408301526001600160781b0392909216606082015260ff91909116608082015260a00190565b60405180910390a46111558360016114b4565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166001600160801b03929092169190911790555050505050505050505050565b6000546001600160a01b031633146103d9576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016103bb565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80356001600160a01b038116811461125f57600080fd5b919050565b60008060006060848603121561127957600080fd5b61128284611248565b92506020840135915061129760408501611248565b90509250925092565b600080600080608085870312156112b657600080fd5b6112bf85611248565b9350602085013592506112d460408601611248565b9396929550929360600135925050565b6000602082840312156112f657600080fd5b813560ff8116811461130757600080fd5b9392505050565b6000806040838503121561132157600080fd5b61132a83611248565b946020939093013593505050565b60006020828403121561134a57600080fd5b61130782611248565b80356001600160801b038116811461125f57600080fd5b600080600080600060a0868803121561138257600080fd5b61138b86611248565b9450602086013593506113a060408701611353565b92506113ae60608701611353565b9150608086013561ffff811681146113c557600080fd5b809150509295509295909350565b6000602082840312156113e557600080fd5b5051919050565b6000602082840312156113fe57600080fd5b8151801515811461130757600080fd5b634e487b7160e01b600052601160045260246000fd5b6001600160801b038181168382160280821691908281146114475761144761140e565b505092915050565b80820281158282048414176114665761146661140e565b92915050565b60008261148957634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156114665761146661140e565b808201808211156114665761146661140e565b6001600160801b038181168382160190808211156114d4576114d461140e565b509291505056fea2646970667358221220a5f10d98fde27690b85e80e99a1b740b547d5c80d267ef6df47812aea1afa57b64736f6c63430008140033
Deployed Bytecode
0x6080604052600436106100bc5760003560e01c80638728371811610074578063b2ddee061161004e578063b2ddee06146102bf578063f2fde38b146102df578063fbcba78b146102ff57600080fd5b806387283718146102645780638da5cb5b146102775780638eefba6a1461029f57600080fd5b806347518c16116100a557806347518c1614610104578063715018a61461022e57806377d3550b1461024357600080fd5b806309ddd947146100c15780633ccfd60b146100ed575b600080fd5b3480156100cd57600080fd5b506100d6600a81565b60405160ff90911681526020015b60405180910390f35b3480156100f957600080fd5b5061010261031f565b005b34801561011057600080fd5b506101d861011f366004611264565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506001600160a01b039283166000908152600160208181526040808420958452948152848320939095168252918452829020825160a08101845281546001600160801b038082168352600160801b918290048116968301969096529190920154938416928201929092529082046001600160781b03166060820152600160f81b90910460ff16608082015290565b6040805182516001600160801b0390811682526020808501518216908301528383015116918101919091526060808301516001600160781b03169082015260809182015160ff169181019190915260a0016100e4565b34801561023a57600080fd5b506101026103c7565b34801561024f57600080fd5b506000546100d690600160a01b900460ff1681565b6101026102723660046112a0565b6103db565b34801561028357600080fd5b506000546040516001600160a01b0390911681526020016100e4565b3480156102ab57600080fd5b506101026102ba3660046112e4565b6109d7565b3480156102cb57600080fd5b506101026102da36600461130e565b610a9c565b3480156102eb57600080fd5b506101026102fa366004611338565b610c18565b34801561030b57600080fd5b5061010261031a36600461136a565b610c6c565b61032761119a565b604051600090339047908381818185875af1925050503d8060008114610369576040519150601f19603f3d011682016040523d82523d6000602084013e61036e565b606091505b50509050806103c45760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c6564000000000000000000000000000000000060448201526064015b60405180910390fd5b50565b6103cf61119a565b6103d960006111e0565b565b6001600160a01b0384811660009081526001602081815260408084208885528252808420948716845284825292839020835160a08101855281546001600160801b038082168352600160801b91829004811694830194909452919093015491821693830184905281046001600160781b03166060830152600160f81b900460ff166080820152906104ae5760405162461bcd60e51b815260206004820152601660248201527f4c697374696e6720646f6573206e6f742065786973740000000000000000000060448201526064016103bb565b80606001516001600160781b0316421061050a5760405162461bcd60e51b815260206004820152601260248201527f4c697374696e672069732065787069726564000000000000000000000000000060448201526064016103bb565b6001600160a01b03841633036105625760405162461bcd60e51b815260206004820152601d60248201527f53656c6c65722063616e206e6f74206275792068697320746f6b656e7300000060448201526064016103bb565b80602001516001600160801b031683146105be5760405162461bcd60e51b815260206004820152601060248201527f496e636f727265637420616d6f756e740000000000000000000000000000000060448201526064016103bb565b604051627eeac760e11b81526001600160a01b03858116600483015260248201879052879160009183169062fdd58e90604401602060405180830381865afa15801561060e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063291906113d3565b90508083602001516001600160801b031611156106915760405162461bcd60e51b815260206004820152601160248201527f4e6f7420656e6f75676820746f6b656e7300000000000000000000000000000060448201526064016103bb565b60405163e985e9c560e01b81526001600160a01b0387811660048301523060248301526000919084169063e985e9c590604401602060405180830381865afa1580156106e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070591906113ec565b9050806107545760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206973206e6f7420617070726f766564000000000000000060448201526064016103bb565b836020015184604001516107689190611424565b6001600160801b031634146107bf5760405162461bcd60e51b815260206004820152601160248201527f4d69736d61746368206f662066756e647300000000000000000000000000000060448201526064016103bb565b835160208086015160408088015181516001600160801b03958616815233948101949094529184168382015292166060820152905189916001600160a01b038c811692908b16917fec2d1ad7b25071481ab73189817e6c393b31b2f43d7ddca8f30a40955b6afbda919081900360800190a46001600160a01b03871660009081526020869052604081208181556001015560208401516040517ff242432a0000000000000000000000000000000000000000000000000000000081526001600160a01b038981166004830152336024830152604482018b90526001600160801b03909216606482015260a06084820152600060a48201529084169063f242432a9060c401600060405180830381600087803b1580156108dd57600080fd5b505af11580156108f1573d6000803e3d6000fd5b5050505060006064856080015160ff163461090c919061144f565b610916919061146c565b90506000610924823461148e565b90506000896001600160a01b03168260405160006040518083038185875af1925050503d8060008114610973576040519150601f19603f3d011682016040523d82523d6000602084013e610978565b606091505b50509050806109c95760405162461bcd60e51b815260206004820152600f60248201527f5472616e73666572206661696c6564000000000000000000000000000000000060448201526064016103bb565b505050505050505050505050565b6109df61119a565b600a60ff82161115610a335760405162461bcd60e51b815260206004820152601f60248201527f4d617820636f6d6d697373696f6e2070657263656e742065786365656465640060448201526064016103bb565b60405160ff8216907fd664cd5eaa7c9c9beb44548ab91d4ee4de2dcf83e43aa94be98f467bc0c675d390600090a26000805460ff909216600160a01b027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6001600160a01b0382166000908152600160208181526040808420858552825280842033855280835293819020815160a08101835281546001600160801b038082168352600160801b91829004811695830195909552919094015492831691840182905282046001600160781b03166060840152600160f81b90910460ff166080830152610b6c5760405162461bcd60e51b815260206004820152601660248201527f4c697374696e6720646f6573206e6f742065786973740000000000000000000060448201526064016103bb565b3360009081526020839052604081208181556001015582846001600160a01b0316336001600160a01b03167f5536ab552ca4bc7c34f4663d577fc5e8ed0dd88cdb5baf00c63208edfc1eb7108460000151856020015186604001518760600151604051610c0a94939291906001600160801b0394851681529284166020840152921660408201526001600160781b0391909116606082015260800190565b60405180910390a450505050565b610c2061119a565b6001600160a01b038116610c63576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024016103bb565b6103c4816111e0565b6000836001600160801b031611610cc55760405162461bcd60e51b815260206004820152601260248201527f416d6f756e74206d757374206265203e2030000000000000000000000000000060448201526064016103bb565b6000826001600160801b031611610d1e5760405162461bcd60e51b815260206004820152601160248201527f5072696365206d757374206265203e203000000000000000000000000000000060448201526064016103bb565b60008161ffff1611610d725760405162461bcd60e51b815260206004820152601460248201527f4475726174696f6e206d757374206265203e203000000000000000000000000060448201526064016103bb565b604051627eeac760e11b81523360048201526024810185905285906000906001600160a01b0383169062fdd58e90604401602060405180830381865afa158015610dc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de491906113d3565b905080856001600160801b03161115610e3f5760405162461bcd60e51b815260206004820152601160248201527f4e6f7420656e6f75676820746f6b656e7300000000000000000000000000000060448201526064016103bb565b60405163e985e9c560e01b81523360048201523060248201526000906001600160a01b0384169063e985e9c590604401602060405180830381865afa158015610e8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb091906113ec565b905080610eff5760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206973206e6f7420617070726f766564000000000000000060448201526064016103bb565b6002546001600160801b03166000610f1d610e1061ffff881661144f565b610f2790426114a1565b905060008060149054906101000a900460ff1690506040518060a00160405280846001600160801b031681526020018a6001600160801b03168152602001896001600160801b03168152602001836001600160781b031681526020018260ff16815250600160008d6001600160a01b03166001600160a01b0316815260200190815260200160002060008c81526020019081526020016000206000336001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a8154816001600160801b0302191690836001600160801b0316021790555060208201518160000160106101000a8154816001600160801b0302191690836001600160801b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b0316021790555060608201518160010160106101000a8154816001600160781b0302191690836001600160781b03160217905550608082015181600101601f6101000a81548160ff021916908360ff160217905550905050898b6001600160a01b0316336001600160a01b03167f140b13e6499f69444379a27c3e8c6065f3651d2f0dcd3757d8e5d338dfcc624a868d8d88886040516111429594939291906001600160801b03958616815293851660208501529190931660408301526001600160781b0392909216606082015260ff91909116608082015260a00190565b60405180910390a46111558360016114b4565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166001600160801b03929092169190911790555050505050505050505050565b6000546001600160a01b031633146103d9576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016103bb565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80356001600160a01b038116811461125f57600080fd5b919050565b60008060006060848603121561127957600080fd5b61128284611248565b92506020840135915061129760408501611248565b90509250925092565b600080600080608085870312156112b657600080fd5b6112bf85611248565b9350602085013592506112d460408601611248565b9396929550929360600135925050565b6000602082840312156112f657600080fd5b813560ff8116811461130757600080fd5b9392505050565b6000806040838503121561132157600080fd5b61132a83611248565b946020939093013593505050565b60006020828403121561134a57600080fd5b61130782611248565b80356001600160801b038116811461125f57600080fd5b600080600080600060a0868803121561138257600080fd5b61138b86611248565b9450602086013593506113a060408701611353565b92506113ae60608701611353565b9150608086013561ffff811681146113c557600080fd5b809150509295509295909350565b6000602082840312156113e557600080fd5b5051919050565b6000602082840312156113fe57600080fd5b8151801515811461130757600080fd5b634e487b7160e01b600052601160045260246000fd5b6001600160801b038181168382160280821691908281146114475761144761140e565b505092915050565b80820281158282048414176114665761146661140e565b92915050565b60008261148957634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156114665761146661140e565b808201808211156114665761146661140e565b6001600160801b038181168382160190808211156114d4576114d461140e565b509291505056fea2646970667358221220a5f10d98fde27690b85e80e99a1b740b547d5c80d267ef6df47812aea1afa57b64736f6c63430008140033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$38.33
Net Worth in ETH
Token Allocations
ETH
99.79%
FRAX
0.21%
Multichain Portfolio | 35 Chains
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.