Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- NFTMarketAuction
- Optimization enabled
- true
- Compiler version
- v0.8.12+commit.f00d7308
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2023-12-06T10:03:10.604518Z
Constructor Arguments
0x000000000000000000000000c176ba009608fddb71c8cdeee0efb0e72deaeeb30000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070499adebb11efd915e3b69e700c331778628707
src/NFTMarketAuction.sol
// contracts/Market.sol
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.12;
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/utils/cryptography/EIP712.sol';
import './MarketTools.sol';
/**
* @title Marketplace contract for auctions
*/
contract NFTMarketAuction is ReentrancyGuard, MarketTools {
using Counters for Counters.Counter;
using SafeERC20 for IERC20;
string private constant SIGNING_DOMAIN = 'HowToPulse-NFTMarketAuction';
string private constant SIGNATURE_VERSION = '1';
bytes32 private constant ACCEPT_BID_DATA_TYPEHASH = keccak256(bytes('acceptBid(uint256 listingId,uint256 bidIndex,bytes32[] royalties,uint256 expiration)'));
bytes32 private constant TERMINATE_AUCTION_DATA_TYPEHASH = keccak256(bytes('terminateAuction(uint256 listingId,bytes32[] royalties,uint256 expiration)'));
uint256 constant public MAX_AUCTION_EXTENDS = 100;
uint256 internal constant AUCTION_EXTENDED_TIME = 10 minutes;
// listingId -> item details
mapping(uint256 => AuctionMarketItem) public auctionListingIdToMarketItem;
// listingId => list of bids
mapping(uint256 => AuctionBid[]) public auctionBids;
// listingId => bidder address => bid index
mapping(uint256 => mapping(address => uint256)) internal auctionBidderToBidIndex;
// listingId => count of auction listing extentions per listingId
mapping(uint256 => uint256) public auctionExtends;
uint256 private constant MAX_INT = type(uint256).max;
struct AuctionMarketItem {
address nftContract;
uint256 nftTokenId;
address priceTokenAddress;
uint256 amount;
uint256 startPrice;
address ownerAddress;
uint256 deadline;
bool isClosed;
uint256 startTime;
}
struct AuctionBid {
uint256 bidAmount;
address bidder;
bool isCanceled;
uint256 timestamp;
}
event AuctionItemCreated(uint256 indexed listingId);
event AuctionBidCreated(
uint256 indexed listingId,
uint256 indexed bidIndex,
address indexed bidder,
uint256 bidAmount
);
event AuctionBidCancelled(
uint256 indexed listingId,
uint256 indexed bidIndex
);
event AuctionBidAccepted(uint256 indexed listingId, uint256 indexed bidIndex);
event AuctionTerminated(uint256 indexed listingId);
event AuctionCancelled(uint256 indexed listingId);
event AuctionExtended(uint256 indexed listingId, uint256 newDeadline);
error BidDoesNotExist();
error ListingDoesNotExist();
error PriceIsToLow();
error ListingIsClosed();
error AuctionHasEnded();
error InvalidPeriod();
error TokenAlreadyListed();
error InvalidPriceToken();
error SaleNotStarted();
/**
* @dev Initializes the contract
* @param signer_ a wallet address of NFTOnPulse backend, which will be signing the transactions to complete sales (accept bids & terminate auctions)
* @param erc20TokenAddresses List of ERC20 tokens to be whitelisted initially
*/
constructor(address signer_, address[] memory erc20TokenAddresses) MarketTools(signer_, erc20TokenAddresses) EIP712(SIGNING_DOMAIN, SIGNATURE_VERSION)
{}
/**
* @dev Gets all the bids for a given auction
* @param listingId ID of the listing
* @return AuctionBid[] All bids for the given auction
*/
function getAuctionBids(uint256 listingId)
public
view
returns (AuctionBid[] memory)
{
return auctionBids[listingId];
}
/**
* @dev Gets the bid for a given auction
* @param listingId ID of the listing
* @param bidIndex Index of the bid
* @return AuctionBid The bid for the given auction
*/
function getAuctionBid(uint256 listingId, uint256 bidIndex)
public
view
returns (AuctionBid memory)
{
AuctionBid[] storage _auctionBids = auctionBids[listingId];
if (_auctionBids.length <= bidIndex) revert BidDoesNotExist();
return _auctionBids[bidIndex];
}
/**
* @dev Creates a new auction item
* @param nftContract Address of the NFT contract
* @param nftTokenId Token ID of the NFT
* @param priceTokenAddress Address of the ERC20 token used for pricing
* @param amount Token amount
* @param startPrice Minimum bid price
* @param deadline Timestamp when the auction closes
* @param startTime Timestamp when the sale is starting
*/
function createAuctionMarketItem(
address nftContract,
uint256 nftTokenId,
address priceTokenAddress,
uint256 amount,
uint256 startPrice,
uint256 deadline,
uint256 startTime
) external nonReentrant whenNotPaused {
if (deadline <= block.timestamp) revert InvalidPeriod();
require(startTime < deadline, 'Sale start time must be before the deadline');
mapping(uint256 => uint256) storage listedTokens = userListedTokens[msg.sender][nftContract];
if (listedTokens[nftTokenId] != 0) revert TokenAlreadyListed();
bool is721;
if (
amount == 0 ||
((is721 = _is721Type(nftContract)) && amount != 1) ||
_getNFTOwnerAmount(is721, nftContract, nftTokenId, msg.sender) < amount
) revert InvalidAmount();
if (!whitelistedERC20[priceTokenAddress]) revert InvalidPriceToken();
// Make sure the owner has given allowance
_checkNFTAllowance(is721, nftContract, nftTokenId);
_listingIds.increment();
uint256 listingId = _listingIds.current();
auctionListingIdToMarketItem[listingId] = AuctionMarketItem(
nftContract,
nftTokenId,
priceTokenAddress,
amount,
startPrice,
msg.sender,
deadline,
false,
startTime
);
listedTokens[nftTokenId] = 1;
emit AuctionItemCreated(listingId);
}
/**
* @dev Returns active bid for a given listing and account
* @param listingId ID of the listing
* @param account Address of the bidder
* @return AuctionBid Returns auction bid info (uint256 bidAmount, address bidder, bool isCanceled, uint256 timestamp)
*/
function getAddressBid(uint256 listingId, address account) view external returns (AuctionBid memory) {
uint256 index = auctionBidderToBidIndex[listingId][account];
require(index > 0, "Bid not found");
return auctionBids[listingId][index - 1];
}
/**
* @dev Bid on an existing auction item
* @param listingId ID of the listing
* @param bidAmount Size of the bid, nominated in the auction's price ERC20 token
*/
function bid(uint256 listingId, uint256 bidAmount)
external
nonReentrant
whenNotPaused
{
if (listingId == 0 || listingId > _listingIds.current()) revert ListingDoesNotExist();
AuctionMarketItem storage marketItem = auctionListingIdToMarketItem[listingId];
if (marketItem.isClosed) revert ListingIsClosed();
if (marketItem.startTime > block.timestamp) revert SaleNotStarted();
uint256 deadline = marketItem.deadline;
if (msg.sender == marketItem.ownerAddress) revert InvalidCaller();
if (block.timestamp >= deadline) revert AuctionHasEnded();
uint256 index = auctionBidderToBidIndex[listingId][msg.sender];
AuctionBid[] storage _auctionBids = auctionBids[listingId];
if (index == 0) {
if (bidAmount < marketItem.startPrice) revert PriceIsToLow();
} else {
if (bidAmount <= _auctionBids[index - 1].bidAmount) revert PriceIsToLow();
}
// Make sure the bidder has given enough allowance
if (!_allowedBalance(marketItem.priceTokenAddress, msg.sender, bidAmount)) revert InsufficientBalance();
if (index == 0) {
auctionBids[listingId].push(AuctionBid(bidAmount, msg.sender, false, block.timestamp));
index = _auctionBids.length;
auctionBidderToBidIndex[listingId][msg.sender] = index;
} else {
_auctionBids[index - 1].bidAmount = bidAmount;
_auctionBids[index - 1].timestamp = block.timestamp;
_auctionBids[index - 1].isCanceled = false; //reenable bid
}
if (deadline < block.timestamp + AUCTION_EXTENDED_TIME && auctionExtends[listingId] < MAX_AUCTION_EXTENDS) {
auctionExtends[listingId]++;
// If deadline is within 10 mins extend it by 10 mins
marketItem.deadline = block.timestamp + AUCTION_EXTENDED_TIME;
emit AuctionExtended(listingId, marketItem.deadline);
}
emit AuctionBidCreated(
listingId,
index - 1, //set new amount for old bid for the same user
msg.sender,
bidAmount
);
}
/**
* @dev Cancels a bid created by the caller
* @param listingId ID of the listing
* @param bidIndex Index of the bid to cancel
*/
function cancelBid(uint256 listingId, uint256 bidIndex)
external
whenNotPaused
{
if (listingId == 0 || listingId > _listingIds.current()) revert ListingDoesNotExist();
AuctionMarketItem storage marketItem = auctionListingIdToMarketItem[listingId];
if (marketItem.isClosed) revert ListingIsClosed();
if (block.timestamp >= marketItem.deadline) revert AuctionHasEnded();
if (auctionBids[listingId].length <= bidIndex) revert BidDoesNotExist();
AuctionBid storage chosenBid = auctionBids[listingId][bidIndex];
if (chosenBid.bidder != msg.sender) revert InvalidCaller();
require(!chosenBid.isCanceled, 'Already canceled');
chosenBid.isCanceled = true;
emit AuctionBidCancelled(listingId, bidIndex);
}
/**
* @dev Calculates the best valid bid for a list of bids
* @param bids List of bids
* @param priceTokenAddress Address of the used ERC20 price token
* @return AuctionBid The best bid (empty struct if none found)
*/
function getBestBid(AuctionBid[] memory bids, address priceTokenAddress)
public
view
virtual
returns (AuctionBid memory)
{
if (bids.length > 0) {
uint256 highestBidIndex = MAX_INT; // use as "no valid bid found yet"
for (uint256 i = 0; i < bids.length; i++) {
if (
// Check balance and allowance and that it's not canceled
!bids[i].isCanceled && _allowedBalance(priceTokenAddress, bids[i].bidder, bids[i].bidAmount)
) {
// The bid is valid
if (
highestBidIndex == MAX_INT || // if no highest valid bid found yet
bids[i].bidAmount > bids[highestBidIndex].bidAmount
) {
highestBidIndex = i;
}
}
}
if (highestBidIndex != MAX_INT) {
return bids[highestBidIndex];
}
}
return AuctionBid(0, address(0x0), false, 0);
}
/**
* @dev Accepts a bid manually to the caller's auction
* @param listingId ID of the listing
* @param bidIndex Index of the bid to accept
* @param royalties A hashed array of royalties receivers and their shares from the sale
* @param expiration Expiration time of the signature (in UNIX timestamp)
* @param signature Signed sale info to confirm that the transaction data was generated by the NFTOnPulse backend and the royalty recipients are legitimate
*/
function acceptBid(uint256 listingId, uint256 bidIndex, bytes32[] calldata royalties, uint256 expiration, bytes calldata signature)
external
nonReentrant
whenNotPaused
{
if (listingId == 0 || listingId > _listingIds.current()) revert ListingDoesNotExist();
_checkSignature(_hashTypedDataV4(keccak256(
abi.encode(ACCEPT_BID_DATA_TYPEHASH, listingId, bidIndex, keccak256(abi.encodePacked(royalties)), expiration)
)), expiration, signature);
AuctionMarketItem storage marketItem = auctionListingIdToMarketItem[
listingId
];
if (marketItem.isClosed) revert ListingIsClosed();
if (marketItem.ownerAddress != msg.sender) revert InvalidCaller();
bool is721 = _is721Type(marketItem.nftContract);
require(
_getNFTOwnerAmount(
is721,
marketItem.nftContract,
marketItem.nftTokenId,
marketItem.ownerAddress
) >= marketItem.amount,
"Seller doesn't have the NFT"
);
if (auctionBids[listingId].length <= bidIndex) revert BidDoesNotExist();
AuctionBid memory chosenBid = auctionBids[listingId][bidIndex];
// Check balance and allowance
require(
!chosenBid.isCanceled && _allowedBalance(marketItem.priceTokenAddress, chosenBid.bidder, chosenBid.bidAmount),
'Not a valid bid'
);
marketItem.isClosed = true;
emit AuctionBidAccepted(listingId, bidIndex);
_sendRoyaltiesAndValue(listingId, chosenBid.bidder, marketItem.ownerAddress, chosenBid.bidAmount, royalties, marketItem.priceTokenAddress);
// transfer the nft from owner to buyer
_transferNFT(
is721,
marketItem.nftContract,
marketItem.ownerAddress,
chosenBid.bidder,
marketItem.nftTokenId,
marketItem.amount
);
userListedTokens[marketItem.ownerAddress][marketItem.nftContract][marketItem.nftTokenId] = 0;
}
/**
* @dev Terminates an auction and settles its result
* @param listingId ID of the listing
* @param royalties A hashed array of royalties receivers and their shares from the sale
* @param expiration Expiration time of the signature (in UNIX timestamp)
* @param signature Signed sale info to confirm that the transaction data was generated by the NFTOnPulse backend and the royalty recipients are legitimate
*/
function terminateAuction(uint256 listingId, bytes32[] calldata royalties, uint256 expiration, bytes calldata signature) external nonReentrant whenNotPaused {
if (listingId == 0 || listingId > _listingIds.current()) revert ListingDoesNotExist();
_checkSignature(_hashTypedDataV4(keccak256(
abi.encode(TERMINATE_AUCTION_DATA_TYPEHASH, listingId, keccak256(abi.encodePacked(royalties)), expiration)
)), expiration, signature);
AuctionMarketItem storage marketItem = auctionListingIdToMarketItem[listingId];
if (marketItem.isClosed) revert ListingIsClosed();
require(block.timestamp >= marketItem.deadline, "The auction hasn't ended");
bool is721 = _is721Type(marketItem.nftContract);
require(
_getNFTOwnerAmount(
is721,
marketItem.nftContract,
marketItem.nftTokenId,
marketItem.ownerAddress
) >= marketItem.amount,
"Seller doesn't have the NFT"
);
marketItem.isClosed = true;
AuctionBid[] storage bids = auctionBids[listingId];
userListedTokens[marketItem.ownerAddress][marketItem.nftContract][marketItem.nftTokenId] = 0;
if (bids.length > 0) {
uint256 bestBid = _lookingForBestBid(marketItem, bids);
if (bestBid != type(uint256).max) {
// If a best bid was found
emit AuctionBidAccepted(listingId, bestBid);
AuctionBid storage chosenBid = bids[bestBid];
_sendRoyaltiesAndValue(listingId, chosenBid.bidder, marketItem.ownerAddress, chosenBid.bidAmount, royalties, marketItem.priceTokenAddress);
// transfer the nft from owner to buyer
_transferNFT(
is721,
marketItem.nftContract,
marketItem.ownerAddress,
chosenBid.bidder,
marketItem.nftTokenId,
marketItem.amount
);
return;
}
}
// no valid bids
emit AuctionTerminated(listingId);
}
function _lookingForBestBid(AuctionMarketItem storage marketItem, AuctionBid[] storage bids) internal view returns (uint256) {
uint256 bestBid = type(uint256).max;
uint256 bestBidAmount = 0;
uint256 timestamp = block.timestamp;
address priceTokenAddress = marketItem.priceTokenAddress;
for (uint256 i = bids.length; i > 0; --i) {
uint256 index = i - 1;
AuctionBid storage _bid = bids[index];
if (_bid.isCanceled) continue;
uint256 bidAmount = _bid.bidAmount;
if (bidAmount < bestBidAmount) continue;
uint256 ts = _bid.timestamp;
if (bidAmount == bestBidAmount && ts >= timestamp) continue;
if (!_allowedBalance(priceTokenAddress, _bid.bidder, bidAmount)) continue;
bestBid = index;
bestBidAmount = bidAmount;
timestamp = ts;
}
return bestBid;
}
/**
* @dev Cancels an auction started by the caller
* @param listingId ID of the listing
*/
function cancelAuctionListing(uint256 listingId) external whenNotPaused {
if (listingId == 0 || listingId > _listingIds.current()) revert ListingDoesNotExist();
AuctionMarketItem storage marketItem = auctionListingIdToMarketItem[listingId];
if (marketItem.ownerAddress != msg.sender) revert InvalidCaller();
if (marketItem.isClosed) revert ListingIsClosed();
marketItem.isClosed = true;
userListedTokens[marketItem.ownerAddress][marketItem.nftContract][marketItem.nftTokenId] = 0;
emit AuctionCancelled(listingId);
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}
@openzeppelin/contracts/interfaces/IERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC2981.sol)
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165.sol";
/**
* @dev Interface for the NFT Royalty Standard.
*
* A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
* support for royalty payments across all NFT marketplaces and ecosystem participants.
*
* _Available since v4.5._
*/
interface IERC2981 is IERC165 {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*/
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view returns (address receiver, uint256 royaltyAmount);
}
@openzeppelin/contracts/interfaces/IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.0;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}
@openzeppelin/contracts/security/Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
@openzeppelin/contracts/token/ERC1155/ERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.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
*
* _Available since v3.1._
*/
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
// Mapping from token ID to account balances
mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping(address => mapping(address => 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) public view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: address zero is not a valid owner");
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 override returns (uint256[] memory) {
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev Transfers `amount` 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 `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 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, 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.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, 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 amounts 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 `amount` tokens of token 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 amount, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - 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 amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `amount` tokens of token type `id`.
*/
function _burn(address from, uint256 id, uint256 amount) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `ids` and `amounts` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
@openzeppelin/contracts/token/ERC1155/IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token 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 amount 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 `amount` tokens of token type `id` from `from` to `to`.
*
* 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 `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 amount, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` 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 amounts,
bytes calldata data
) external;
}
@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
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);
}
@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.0;
import "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
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);
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/utils/Context.sol
// 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;
}
}
@openzeppelin/contracts/utils/Counters.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
@openzeppelin/contracts/utils/ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.8;
import "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(_FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}
@openzeppelin/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @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(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
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
}
}
}
@openzeppelin/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
@openzeppelin/contracts/utils/cryptography/EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.8;
import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* _Available since v3.4._
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {EIP-5267}.
*
* _Available since v4.9._
*/
function eip712Domain()
public
view
virtual
override
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_name.toStringWithFallback(_nameFallback),
_version.toStringWithFallback(_versionFallback),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
}
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./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);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/utils/introspection/ERC165Checker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/introspection/ERC165Checker.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Library used to query support of an interface declared via {IERC165}.
*
* Note that these functions return the actual result of the query: they do not
* `revert` if an interface is not supported. It is up to the caller to decide
* what to do in these cases.
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
/**
* @dev Returns true if `account` supports the {IERC165} interface.
*/
function supportsERC165(address account) internal view returns (bool) {
// Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
}
/**
* @dev Returns true if `account` supports the interface defined by
* `interfaceId`. Support for {IERC165} itself is queried automatically.
*
* See {IERC165-supportsInterface}.
*/
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
// query support of both ERC165 as per the spec and support of _interfaceId
return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
}
/**
* @dev Returns a boolean array where each value corresponds to the
* interfaces passed in and whether they're supported or not. This allows
* you to batch check interfaces for a contract where your expectation
* is that some interfaces may not be supported.
*
* See {IERC165-supportsInterface}.
*
* _Available since v3.4._
*/
function getSupportedInterfaces(
address account,
bytes4[] memory interfaceIds
) internal view returns (bool[] memory) {
// an array of booleans corresponding to interfaceIds and whether they're supported or not
bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
// query support of ERC165 itself
if (supportsERC165(account)) {
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
}
}
return interfaceIdsSupported;
}
/**
* @dev Returns true if `account` supports all the interfaces defined in
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
*
* Batch-querying can lead to gas savings by skipping repeated checks for
* {IERC165} support.
*
* See {IERC165-supportsInterface}.
*/
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
// query support of ERC165 itself
if (!supportsERC165(account)) {
return false;
}
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
return false;
}
}
// all interfaces supported
return true;
}
/**
* @notice Query if a contract implements an interface, does not check ERC165 support
* @param account The address of the contract to query for support of an interface
* @param interfaceId The interface identifier, as specified in ERC-165
* @return true if the contract at account indicates support of the interface with
* identifier interfaceId, false otherwise
* @dev Assumes that account contains a contract that supports ERC165, otherwise
* the behavior of this method is undefined. This precondition can be checked
* with {supportsERC165}.
*
* Some precompiled contracts will falsely indicate support for a given interface, so caution
* should be exercised when using this function.
*
* Interface identification is specified in ERC-165.
*/
function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
// prepare call
bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
// perform static call
bool success;
uint256 returnSize;
uint256 returnValue;
assembly {
success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
returnSize := returndatasize()
returnValue := mload(0x00)
}
return success && returnSize >= 0x20 && returnValue > 0;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @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);
}
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @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 up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
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.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 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.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
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 (rounding == Rounding.Up && 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 down.
*
* 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
@openzeppelin/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
src/IPartialNFT.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;
interface IPartialNFT {
function isApprovedForAll(address account, address operator)
external
view
returns (bool);
}
src/MarketTools.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;
import '@openzeppelin/contracts/token/ERC1155/ERC1155.sol';
import '@openzeppelin/contracts/token/ERC1155/IERC1155.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/utils/Address.sol';
import '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/utils/cryptography/EIP712.sol';
import '@openzeppelin/contracts/access/Ownable2Step.sol';
import '@openzeppelin/contracts/security/Pausable.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';
import '@openzeppelin/contracts/interfaces/IERC2981.sol';
import './IPartialNFT.sol';
/**
@title Common functionality for all marketplace contracts
*/
abstract contract MarketTools is Ownable2Step, Pausable, ReentrancyGuard, EIP712 {
using Counters for Counters.Counter;
using ERC165Checker for address;
using SafeERC20 for IERC20;
using Address for address;
event AddedToWhitelist(address indexed erc20TokenAddress);
event RemovedFromWhitelist(address indexed erc20TokenAddress);
event ChangedCommissionPercent(uint16 commissionPercent);
event ChangedSimpleCommissionPercent(uint16 commissionPercentSimple);
event ChangedCommissionReceiver(address indexed commissionReceiver);
event ChangedSigner(address indexed signer);
event RoyaltiesDistribution(uint256 indexed listingId, address indexed buyer, address indexed receiver, uint256 amount);
error InvalidSignature();
error InvalidAddress();
error NotSupported();
error InvalidAmount();
error InvalidCaller();
error InsufficientBalance();
bytes4 constant internal InterfaceId_ERC721 = 0x80ac58cd; // The ERC-165 identifier for 721
bytes4 constant internal InterfaceId_ERC1155 = 0xd9b67a26; // The ERC-165 identifier for 1155
// representation of 100%
uint16 internal constant FULL_PERCENT = 10000; // 100.00%
// max commission percent
uint16 internal constant MAX_COMMISSION_PERCENT = 500; // 5.00%
// max total percent of royalties and commission for sale
uint16 internal constant MAX_ROYALTY_PERCENT = 9000; // 90.00%
// Amount of tokens a user has for sale, per contract and per tokenId
mapping(address => mapping(address => mapping(uint256 => uint256))) public userListedTokens;
Counters.Counter internal _listingIds;
// Commission percentage for auctions and offers sales
uint16 public commissionPercent = 200; // 2.00%
// List of ERC20 token addresses which are allowed to be used
mapping(address => bool) public whitelistedERC20;
// Address of the commission receiver
address public commissionReceiver;
// Signer of transactions data
address public marketSigner;
/**
* @dev Initializes the contract
* @param signer_ a wallet address of NFTOnPulse backend, which will be signing the transactions to complete sales
* @param erc20TokenAddresses List of ERC20 tokens to be whitelisted initially
*/
constructor(address signer_, address[] memory erc20TokenAddresses) {
for (uint256 i = 0; i < erc20TokenAddresses.length; i++) {
_addToWhitelist(erc20TokenAddresses[i]);
}
commissionReceiver = msg.sender;
_setSigner(signer_);
}
/**
* @dev Adds an ERC20 token to the whitelist
* @param erc20TokenAddress The address of the token
*/
function addToWhitelist(address erc20TokenAddress) public onlyOwner {
_addToWhitelist(erc20TokenAddress);
}
function _addToWhitelist(address erc20TokenAddress) private {
if (!erc20TokenAddress.isContract()) revert InvalidAddress();
whitelistedERC20[erc20TokenAddress] = true;
emit AddedToWhitelist(erc20TokenAddress);
}
/**
* @dev Removes an ERC20 token from the whitelist
* @param erc20TokenAddress The address of the token
*/
function removeFromWhitelist(address erc20TokenAddress) public onlyOwner {
whitelistedERC20[erc20TokenAddress] = false;
emit RemovedFromWhitelist(erc20TokenAddress);
}
/**
* @dev Gets the latest listingId used in the contract
* @return uint256 listingId
*/
function getLatestListItemId() public view returns (uint256) {
return _listingIds.current();
}
/**
* @dev Set new signer address
*/
function setSigner(address signer_) external onlyOwner {
_setSigner(signer_);
}
function _setSigner(address signer_) internal {
if (signer_ == address(0)) revert InvalidAddress();
marketSigner = signer_;
emit ChangedSigner(signer_);
}
/**
* @dev Makes sure the sender has given allowance for this contract to manage their NFTs
* @param is721Type Whether the NFT is ERC721 or ERC1155
* @param nftContract Address of the NFT contract for which to check for allowance
* @param tokenId an ID of the NFT on the collection contract, which was assign to the NFT when it was minted
*/
function _checkNFTAllowance(bool is721Type, address nftContract, uint256 tokenId) internal view {
// Make sure the owner has given allowance
bool givenAllowance = IPartialNFT(nftContract).isApprovedForAll(msg.sender, address(this));
if (!givenAllowance && is721Type) {
givenAllowance = IERC721(nftContract).getApproved(tokenId) == address(this);
}
require(givenAllowance, 'Not allowed to manage tokens');
}
/**
* @dev Checks how many NFTs the given owner has
* @param is721 Whether the NFT is ERC721 or ERC1155
* @param nftContract Address of the NFT contract for which to get the amount
* @param tokenId Which NFT token ID to check
* @param nftOwner Address of the owner
* @return uint256 The amount of NFTs the owner has. For ERC721, this is always 0 or 1.
*/
function _getNFTOwnerAmount(
bool is721,
address nftContract,
uint256 tokenId,
address nftOwner
) internal view returns (uint256) {
if (is721) {
return IERC721(nftContract).ownerOf(tokenId) == nftOwner ? 1 : 0;
} else {
return IERC1155(nftContract).balanceOf(nftOwner, tokenId);
}
}
/**
* @dev Transfers an NFT
* @param nftContract Address of the NFT contract
* @param sender Sender of the NFT
* @param receiver Receiver of the NFT
* @param nftTokenId NFT token ID
* @param amount How many NFTs to transfer
*/
function _transferNFT(
bool is721,
address nftContract,
address sender,
address receiver,
uint256 nftTokenId,
uint256 amount
) internal {
if (is721) {
IERC721(nftContract).safeTransferFrom(sender, receiver, nftTokenId);
} else {
IERC1155(nftContract).safeTransferFrom(
sender,
receiver,
nftTokenId,
amount,
''
);
}
}
/**
* @dev Checks the type of the given NFT. Reverts if it's not supported
* @param addr Address of the NFT contract
* @return bool true if it's ERC721, false if ERC1155
*/
function _is721Type(address addr) internal view returns (bool) {
bool is721 = addr.supportsInterface(InterfaceId_ERC721);
if (is721 != addr.supportsInterface(InterfaceId_ERC1155)) return is721;
revert NotSupported();
}
/**
* @dev Pauses market logic on the contract
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Resumes market logic on the contract
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @dev Sets commission percent for auctions and offers
* @param percent accepts value (200 = 2%)
*/
function setCommissionPercent(uint16 percent) external onlyOwner {
require(percent <= MAX_COMMISSION_PERCENT, "Service fee cannot be bigger than 500 (equals 5%)");
commissionPercent = percent;
emit ChangedCommissionPercent(percent);
}
/**
* @dev Sets commissions receiver of the Market Contract
* @param newCommissionReceiver the address of new commission receiver
*/
function setCommissionReceiver(address newCommissionReceiver) external onlyOwner {
if (newCommissionReceiver == address(0)) revert InvalidAddress();
commissionReceiver = newCommissionReceiver;
emit ChangedCommissionReceiver(newCommissionReceiver);
}
/**
* @dev Send value to seller and royalties to all recipients
* @param buyer Buyer' address of the NFT
* @param seller Seller of the NFT
* @param value How much to send to all recipients in total
* @param royalties Royalties to send (uint16 << 160 | address)
* @param token The address of the ERC20 token in which the NFT was listed and sold, and the sale value of which should be sent to the sale rewards receivers (seller, commission receiver, royalty receivers).
*/
function _sendRoyaltiesAndValue(uint256 listingId, address buyer, address seller, uint256 value, bytes32[] calldata royalties, address token) internal {
uint16 fullPercent = commissionPercent;
uint256 commission = value * fullPercent / FULL_PERCENT;
uint256 valueLeft = value - commission;
for (uint256 i = royalties.length; i > 0; --i) {
address receiver = address(uint160(uint256(royalties[i - 1])));
uint16 basisPoint = uint16(uint256(royalties[i - 1]) >> 160);
require(fullPercent + basisPoint <= MAX_ROYALTY_PERCENT, "Total commissions are too high"); // 90% royalties and commission is the maximum allowed
fullPercent += basisPoint;
uint256 royaltyAmount = value * basisPoint / FULL_PERCENT;
if (sendAssets(buyer, receiver, royaltyAmount, token, true)) {
valueLeft -= royaltyAmount;
emit RoyaltiesDistribution(listingId, buyer, receiver, royaltyAmount);
}
}
if (commission > 0) {
sendAssets(buyer, commissionReceiver, commission, token, false);
}
sendAssets(buyer, seller, valueLeft, token, false);
}
function _allowedBalance(address token, address owner, uint256 estimatedValue) internal view returns (bool) {
uint256 balance = IERC20(token).balanceOf(owner);
if (balance < estimatedValue) return false;
uint256 allowance = IERC20(token).allowance(owner, address(this));
if (allowance < estimatedValue) return false;
return true;
}
/**
* @dev Sends an amount of the asset to a receiver
* @param buyer Who sends the assets
* @param receiver Receiver of the assets
* @param amount How much to send
* @param token Address of the ERC20 token to send
*/
function sendAssets(address buyer, address receiver, uint256 amount, address token, bool silent) internal virtual returns (bool) {
(bool success, bytes memory returndata) = token.call(abi.encodeWithSelector(IERC20(token).transferFrom.selector, buyer, receiver, amount));
if (success && (returndata.length == 0 || abi.decode(returndata, (bool)))) return true;
if (!silent) revert("SafeERC20: ERC20 operation did not succeed");
return false;
}
function _checkSignature(bytes32 digest, uint256 expiration, bytes memory signature) internal view {
require(block.timestamp < expiration, "Signature expired");
(address recovered,) = ECDSA.tryRecover(digest, signature);
if (marketSigner != recovered) revert InvalidSignature();
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"signer_","internalType":"address"},{"type":"address[]","name":"erc20TokenAddresses","internalType":"address[]"}]},{"type":"error","name":"AuctionHasEnded","inputs":[]},{"type":"error","name":"BidDoesNotExist","inputs":[]},{"type":"error","name":"InsufficientBalance","inputs":[]},{"type":"error","name":"InvalidAddress","inputs":[]},{"type":"error","name":"InvalidAmount","inputs":[]},{"type":"error","name":"InvalidCaller","inputs":[]},{"type":"error","name":"InvalidPeriod","inputs":[]},{"type":"error","name":"InvalidPriceToken","inputs":[]},{"type":"error","name":"InvalidShortString","inputs":[]},{"type":"error","name":"InvalidSignature","inputs":[]},{"type":"error","name":"ListingDoesNotExist","inputs":[]},{"type":"error","name":"ListingIsClosed","inputs":[]},{"type":"error","name":"NotSupported","inputs":[]},{"type":"error","name":"PriceIsToLow","inputs":[]},{"type":"error","name":"SaleNotStarted","inputs":[]},{"type":"error","name":"StringTooLong","inputs":[{"type":"string","name":"str","internalType":"string"}]},{"type":"error","name":"TokenAlreadyListed","inputs":[]},{"type":"event","name":"AddedToWhitelist","inputs":[{"type":"address","name":"erc20TokenAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AuctionBidAccepted","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true},{"type":"uint256","name":"bidIndex","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"AuctionBidCancelled","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true},{"type":"uint256","name":"bidIndex","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"AuctionBidCreated","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true},{"type":"uint256","name":"bidIndex","internalType":"uint256","indexed":true},{"type":"address","name":"bidder","internalType":"address","indexed":true},{"type":"uint256","name":"bidAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"AuctionCancelled","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"AuctionExtended","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true},{"type":"uint256","name":"newDeadline","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"AuctionItemCreated","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"AuctionTerminated","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"ChangedCommissionPercent","inputs":[{"type":"uint16","name":"commissionPercent","internalType":"uint16","indexed":false}],"anonymous":false},{"type":"event","name":"ChangedCommissionReceiver","inputs":[{"type":"address","name":"commissionReceiver","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ChangedSigner","inputs":[{"type":"address","name":"signer","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ChangedSimpleCommissionPercent","inputs":[{"type":"uint16","name":"commissionPercentSimple","internalType":"uint16","indexed":false}],"anonymous":false},{"type":"event","name":"EIP712DomainChanged","inputs":[],"anonymous":false},{"type":"event","name":"OwnershipTransferStarted","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RemovedFromWhitelist","inputs":[{"type":"address","name":"erc20TokenAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoyaltiesDistribution","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256","indexed":true},{"type":"address","name":"buyer","internalType":"address","indexed":true},{"type":"address","name":"receiver","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_AUCTION_EXTENDS","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptBid","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"uint256","name":"bidIndex","internalType":"uint256"},{"type":"bytes32[]","name":"royalties","internalType":"bytes32[]"},{"type":"uint256","name":"expiration","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addToWhitelist","inputs":[{"type":"address","name":"erc20TokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}],"name":"auctionBids","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"auctionExtends","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"nftContract","internalType":"address"},{"type":"uint256","name":"nftTokenId","internalType":"uint256"},{"type":"address","name":"priceTokenAddress","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"startPrice","internalType":"uint256"},{"type":"address","name":"ownerAddress","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"isClosed","internalType":"bool"},{"type":"uint256","name":"startTime","internalType":"uint256"}],"name":"auctionListingIdToMarketItem","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"bid","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"uint256","name":"bidAmount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelAuctionListing","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelBid","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"uint256","name":"bidIndex","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint16","name":"","internalType":"uint16"}],"name":"commissionPercent","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"commissionReceiver","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"createAuctionMarketItem","inputs":[{"type":"address","name":"nftContract","internalType":"address"},{"type":"uint256","name":"nftTokenId","internalType":"uint256"},{"type":"address","name":"priceTokenAddress","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"startPrice","internalType":"uint256"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"uint256","name":"startTime","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes1","name":"fields","internalType":"bytes1"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"version","internalType":"string"},{"type":"uint256","name":"chainId","internalType":"uint256"},{"type":"address","name":"verifyingContract","internalType":"address"},{"type":"bytes32","name":"salt","internalType":"bytes32"},{"type":"uint256[]","name":"extensions","internalType":"uint256[]"}],"name":"eip712Domain","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct NFTMarketAuction.AuctionBid","components":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]}],"name":"getAddressBid","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct NFTMarketAuction.AuctionBid","components":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]}],"name":"getAuctionBid","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"uint256","name":"bidIndex","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct NFTMarketAuction.AuctionBid[]","components":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]}],"name":"getAuctionBids","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct NFTMarketAuction.AuctionBid","components":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]}],"name":"getBestBid","inputs":[{"type":"tuple[]","name":"bids","internalType":"struct NFTMarketAuction.AuctionBid[]","components":[{"type":"uint256","name":"bidAmount","internalType":"uint256"},{"type":"address","name":"bidder","internalType":"address"},{"type":"bool","name":"isCanceled","internalType":"bool"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]},{"type":"address","name":"priceTokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getLatestListItemId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"marketSigner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pendingOwner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeFromWhitelist","inputs":[{"type":"address","name":"erc20TokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCommissionPercent","inputs":[{"type":"uint16","name":"percent","internalType":"uint16"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCommissionReceiver","inputs":[{"type":"address","name":"newCommissionReceiver","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSigner","inputs":[{"type":"address","name":"signer_","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"terminateAuction","inputs":[{"type":"uint256","name":"listingId","internalType":"uint256"},{"type":"bytes32[]","name":"royalties","internalType":"bytes32[]"},{"type":"uint256","name":"expiration","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"userListedTokens","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"whitelistedERC20","inputs":[{"type":"address","name":"","internalType":"address"}]}]
Contract Creation Code
0x6101606040526007805461ffff191660c81790553480156200002057600080fd5b506040516200409a3803806200409a833981016040819052620000439162000507565b81816040518060400160405280601b81526020017f486f77546f50756c73652d4e46544d61726b657441756374696f6e0000000000815250604051806040016040528060018152602001603160f81b815250620000af620000a96200020360201b60201c565b62000207565b6001805460ff60a01b19168155600255620000d882600362000231602090811b62001e0d17901c565b61012052620000f581600462000231602090811b62001e0d17901c565b61014052815160208084019190912060e052815190820120610100524660a0526200018360e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c05260005b8151811015620001db57620001c6828281518110620001b257620001b2620005f0565b60200260200101516200028560201b60201c565b80620001d28162000606565b9150506200018f565b50600980546001600160a01b03191633179055620001f9826200030e565b50505050620006e7565b3390565b600180546001600160a01b03191690556200022e8162000380602090811b62001e4417901c565b50565b600060208351101562000251576200024983620003d0565b90506200027f565b8262000268836200041c60201b62001e941760201c565b81516200027992602001906200042e565b5060ff90505b92915050565b620002a4816001600160a01b03166200041f60201b62001e971760201c565b620002c25760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b038116600081815260086020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a250565b6001600160a01b038116620003365760405163e6c4247b60e01b815260040160405180910390fd5b600a80546001600160a01b0319166001600160a01b0383169081179091556040517f5cf1735f1350de7c05f30a25d6fc56e0cd343859cea70b63dafb8d35afb5bc0890600090a250565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080829050601f8151111562000407578260405163305a27a960e01b8152600401620003fe919062000630565b60405180910390fd5b8051620004148262000688565b179392505050565b90565b6001600160a01b03163b151590565b8280546200043c90620006b0565b90600052602060002090601f016020900481019282620004605760008555620004ab565b82601f106200047b57805160ff1916838001178555620004ab565b82800160010185558215620004ab579182015b82811115620004ab5782518255916020019190600101906200048e565b50620004b9929150620004bd565b5090565b5b80821115620004b95760008155600101620004be565b80516001600160a01b0381168114620004ec57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600080604083850312156200051b57600080fd5b6200052683620004d4565b602084810151919350906001600160401b03808211156200054657600080fd5b818601915086601f8301126200055b57600080fd5b815181811115620005705762000570620004f1565b8060051b604051601f19603f83011681018181108582111715620005985762000598620004f1565b604052918252848201925083810185019189831115620005b757600080fd5b938501935b82851015620005e057620005d085620004d4565b84529385019392850192620005bc565b8096505050505050509250929050565b634e487b7160e01b600052603260045260246000fd5b60006000198214156200062957634e487b7160e01b600052601160045260246000fd5b5060010190565b600060208083528351808285015260005b818110156200065f5785810183015185820160400152820162000641565b8181111562000672576000604083870101525b50601f01601f1916929092016040019392505050565b80516020808301519190811015620006aa576000198160200360031b1b821691505b50919050565b600181811c90821680620006c557607f821691505b60208210811415620006aa57634e487b7160e01b600052602260045260246000fd5b60805160a05160c05160e0516101005161012051610140516139586200074260003960006116c90152600061169e01526000612b5001526000612b2801526000612a8301526000612aad01526000612ad701526139586000f3fe608060405234801561001057600080fd5b50600436106102065760003560e01c806377d3550b1161011a5780639c9f39b0116100ad578063cddaa6711161007c578063cddaa67114610574578063e30c397814610587578063e43252d714610598578063f2fde38b146105ab578063f92aa57f146105be57600080fd5b80639c9f39b01461050a578063a576cf9d1461051d578063b370fa7114610530578063b5f0dcc21461056157600080fd5b80638ab1d681116100e95780638ab1d681146103f75780638da5cb5b1461040a57806396a168351461042f5780639ae8665d1461044257600080fd5b806377d3550b146103ab57806379ba5097146103cc5780638456cb59146103d457806384b0196e146103dc57600080fd5b806340a3a5051161019d5780635c975abb1161016c5780635c975abb1461031d5780635f93de491461032f5780636c19e7831461037057806370b4768e14610383578063715018a6146103a357600080fd5b806340a3a505146102d157806347c00039146102e45780634b393605146102f7578063598647f81461030a57600080fd5b80632a5a9435116101d95780632a5a94351461027b578063367005021461028e5780633f4ba83a146102c15780633f8992e5146102c957600080fd5b80630eb06ff11461020b578063112ae0341461022657806329fef827146102465780632a2231141461025b575b600080fd5b6102136105d1565b6040519081526020015b60405180910390f35b610213610234366004613058565b600e6020526000908152604090205481565b6102596102543660046130f8565b6105e1565b005b61026e61026936600461317b565b6109a4565b60405161021d919061319d565b610259610289366004613058565b610a4b565b6102b161029c3660046131f8565b60086020526000908152604090205460ff1681565b604051901515815260200161021d565b610259610b59565b610213606481565b61026e6102df366004613215565b610b6b565b6102596102f2366004613245565b610bfc565b61025961030536600461317b565b610f39565b61025961031836600461317b565b6110eb565b600154600160a01b900460ff166102b1565b61034261033d36600461317b565b6114e7565b604080519485526001600160a01b03909316602085015290151591830191909152606082015260800161021d565b61025961037e3660046131f8565b61153e565b610396610391366004613058565b611552565b60405161021d91906132aa565b6102596115f7565b6007546103b99061ffff1681565b60405161ffff909116815260200161021d565b610259611609565b610259611680565b6103e4611690565b60405161021d9796959493929190613379565b6102596104053660046131f8565b611719565b6000546001600160a01b03165b6040516001600160a01b03909116815260200161021d565b600a54610417906001600160a01b031681565b6104ad610450366004613058565b600b602052600090815260409020805460018201546002830154600384015460048501546005860154600687015460078801546008909801546001600160a01b0397881698969795861696949593949290931692909160ff169089565b604080516001600160a01b039a8b1681526020810199909952968916968801969096526060870194909452608086019290925290941660a084015260c083019390935291151560e08201526101008101919091526101200161021d565b61025961051836600461340f565b61176a565b61025961052b3660046131f8565b61182c565b61021361053e366004613433565b600560209081526000938452604080852082529284528284209052825290205481565b61025961056f366004613474565b6118a5565b61026e61058236600461357f565b611c40565b6001546001600160a01b0316610417565b6102596105a63660046131f8565b611d8b565b6102596105b93660046131f8565b611d9c565b600954610417906001600160a01b031681565b60006105dc60065490565b905090565b6105e9611ea6565b6105f1611efe565b8515806105ff575060065486115b1561061d576040516335aacf6560e11b815260040160405180910390fd5b6106e76106aa6040518060800160405280604a8152602001613885604a913980519060200120888888604051602001610657929190613683565b60408051601f1981840301815282825280516020918201209083019490945281019190915260608101919091526080810186905260a0015b60405160208183030381529060405280519060200120611f4b565b8484848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611f7892505050565b6000868152600b60205260409020600781015460ff161561071b5760405163cd029ba360e01b815260040160405180910390fd5b80600601544210156107745760405162461bcd60e51b815260206004820152601860248201527f5468652061756374696f6e206861736e277420656e646564000000000000000060448201526064015b60405180910390fd5b805460009061078b906001600160a01b0316611fff565b600383015483546001850154600586015493945091926107b99285926001600160a01b039081169216612061565b10156108075760405162461bcd60e51b815260206004820152601b60248201527f53656c6c657220646f65736e2774206861766520746865204e46540000000000604482015260640161076b565b60078201805460ff191660019081179091556000898152600c602090815260408083206005808801546001600160a01b0390811686529084528285208854909116855283528184209487015484529390915281205580541561096357600061086f8483612173565b905060001981146109615760405181908b907f2e3b770b986273dab692303c20bf314387cc7f86af8f2e2f289c8c2d4316c15690600090a360008282815481106108bb576108bb6136af565b906000526020600020906003020190506109238b8260010160009054906101000a90046001600160a01b03168760050160009054906101000a90046001600160a01b031684600001548e8e8b60020160009054906101000a90046001600160a01b031661226a565b845460058601546001838101549088015460038901546109579489946001600160a01b039182169490821693911691612446565b5050505050610992565b505b60405189907fcd92308c6a39b7531d0e2dc72e7cd0e3c97cead6167c2c5f33c4d360db118d5690600090a25050505b61099c6001600255565b505050505050565b6109ac612f8c565b6000838152600c60205260409020805483106109db5760405163ac96c2bd60e01b815260040160405180910390fd5b8083815481106109ed576109ed6136af565b6000918252602091829020604080516080810182526003939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1615159082015260029091015460608201529150505b92915050565b610a53611efe565b801580610a61575060065481115b15610a7f576040516335aacf6560e11b815260040160405180910390fd5b6000818152600b6020526040902060058101546001600160a01b03163314610aba576040516348f5c3ed60e01b815260040160405180910390fd5b600781015460ff1615610ae05760405163cd029ba360e01b815260040160405180910390fd5b60078101805460ff191660019081179091556005808301546001600160a01b0390811660009081526020928352604080822086549093168252918352818120938501548152929091528082208290555183917f2809c7e17bf978fbc7194c0a694b638c4215e9140cacc6c38ca36010b45697df91a25050565b610b61612542565b610b6961259c565b565b610b73612f8c565b6000838152600d602090815260408083206001600160a01b038616845290915290205480610bd35760405162461bcd60e51b815260206004820152600d60248201526c109a59081b9bdd08199bdd5b99609a1b604482015260640161076b565b6000848152600c60205260409020610bec6001836136db565b815481106109ed576109ed6136af565b610c04611ea6565b610c0c611efe565b428211610c2c576040516302e8f35960e31b815260040160405180910390fd5b818110610c8f5760405162461bcd60e51b815260206004820152602b60248201527f53616c652073746172742074696d65206d757374206265206265666f7265207460448201526a686520646561646c696e6560a81b606482015260840161076b565b3360009081526005602090815260408083206001600160a01b038b1684528252808320898452918290529091205415610cdb57604051636f555ee160e11b815260040160405180910390fd5b6000851580610cfe5750610cee89611fff565b9050808015610cfe575085600114155b80610d13575085610d11828b8b33612061565b105b15610d315760405163162908e360e11b815260040160405180910390fd5b6001600160a01b03871660009081526008602052604090205460ff16610d6a576040516305fe65f560e21b815260040160405180910390fd5b610d75818a8a6125f1565b610d83600680546001019055565b6000610d8e60065490565b90506040518061012001604052808b6001600160a01b031681526020018a8152602001896001600160a01b03168152602001888152602001878152602001336001600160a01b0316815260200186815260200160001515815260200185815250600b600083815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015560408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550606082015181600301556080820151816004015560a08201518160050160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e08201518160070160006101000a81548160ff021916908315150217905550610100820151816008015590505060018360008b815260200190815260200160002081905550807f254c646c6c0f4251485be1ae1b544a687cfa682ee3314d2c5a9d801691193e9a60405160405180910390a2505050610f306001600255565b50505050505050565b610f41611efe565b811580610f4f575060065482115b15610f6d576040516335aacf6560e11b815260040160405180910390fd5b6000828152600b60205260409020600781015460ff1615610fa15760405163cd029ba360e01b815260040160405180910390fd5b80600601544210610fc55760405163dda144a560e01b815260040160405180910390fd5b6000838152600c60205260409020548210610ff35760405163ac96c2bd60e01b815260040160405180910390fd5b6000838152600c60205260408120805484908110611013576110136136af565b600091825260209091206001600390920201908101549091506001600160a01b03163314611054576040516348f5c3ed60e01b815260040160405180910390fd5b6001810154600160a01b900460ff16156110a35760405162461bcd60e51b815260206004820152601060248201526f105b1c9958591e4818d85b98d95b195960821b604482015260640161076b565b60018101805460ff60a01b1916600160a01b179055604051839085907f2f308e24a5dcbe2c77ba79c28760736ec7158e5a7eef8556ec18503dccb1dfa290600090a350505050565b6110f3611ea6565b6110fb611efe565b811580611109575060065482115b15611127576040516335aacf6560e11b815260040160405180910390fd5b6000828152600b60205260409020600781015460ff161561115b5760405163cd029ba360e01b815260040160405180910390fd5b4281600801541115611180576040516316851a3760e11b815260040160405180910390fd5b600681015460058201546001600160a01b03163314156111b3576040516348f5c3ed60e01b815260040160405180910390fd5b8042106111d35760405163dda144a560e01b815260040160405180910390fd5b6000848152600d60209081526040808320338452825280832054878452600c90925290912081611227578360040154851015611222576040516356010c6b60e11b815260040160405180910390fd5b611274565b806112336001846136db565b81548110611243576112436136af565b9060005260206000209060030201600001548511611274576040516356010c6b60e11b815260040160405180910390fd5b600284015461128d906001600160a01b03163387612739565b6112aa57604051631e9acf1760e31b815260040160405180910390fd5b81611353576000868152600c602090815260408083208151608081018352898152338185018181528285018781524260608501908152855460018181018855968a52888a20955160039091029095019485559151948401805491511515600160a01b026001600160a81b03199092166001600160a01b03969096169590951717909355915160029091015584548a8552600d8452828520918552925290912081905591506113f9565b84816113606001856136db565b81548110611370576113706136af565b6000918252602090912060039091020155428161138e6001856136db565b8154811061139e5761139e6136af565b60009182526020822060026003909202010191909155816113c06001856136db565b815481106113d0576113d06136af565b906000526020600020906003020160010160146101000a81548160ff0219169083151502179055505b611405610258426136f2565b8310801561142157506000868152600e60205260409020546064115b1561148f576000868152600e602052604081208054916114408361370a565b909155506114529050610258426136f2565b6006850181905560405190815286907f6e912a3a9105bdd2af817ba5adc14e6c127c1035b5b648faa29ca0d58ab8ff4e9060200160405180910390a25b3361149b6001846136db565b877f53ae5fec6fc7d9b5f3a4419f25dd826d109b8c6eb49165fef6ebad278292f151886040516114cd91815260200190565b60405180910390a4505050506114e36001600255565b5050565b600c602052816000526040600020818154811061150357600080fd5b60009182526020909120600390910201805460018201546002909201549093506001600160a01b0382169250600160a01b90910460ff169084565b611546612542565b61154f81612853565b50565b6060600c6000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156115ec5760008481526020908190206040805160808101825260038602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff161515928401929092526002015460608301529083529092019101611587565b505050509050919050565b6115ff612542565b610b6960006128c4565b60015433906001600160a01b031681146116775760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b606482015260840161076b565b61154f816128c4565b611688612542565b610b696128dd565b6000606080828080836116c47f00000000000000000000000000000000000000000000000000000000000000006003612920565b6116ef7f00000000000000000000000000000000000000000000000000000000000000006004612920565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b611721612542565b6001600160a01b038116600081815260086020526040808220805460ff19169055517fcdd2e9b91a56913d370075169cefa1602ba36be5301664f752192bb1709df7579190a250565b611772612542565b6101f461ffff821611156117e25760405162461bcd60e51b815260206004820152603160248201527f53657276696365206665652063616e6e6f7420626520626967676572207468616044820152706e203530302028657175616c732035252960781b606482015260840161076b565b6007805461ffff191661ffff83169081179091556040519081527f73c039f9c4e58241e463c99d8943c1ba1d69631b8feb1d75f9adb5a84d4f32ee9060200160405180910390a150565b611834612542565b6001600160a01b03811661185b5760405163e6c4247b60e01b815260040160405180910390fd5b600980546001600160a01b0319166001600160a01b0383169081179091556040517fac519e193b7e6a77b060aa9ca9eea599673fe42e8ffc2551057f1f8163b4128d90600090a250565b6118ad611ea6565b6118b5611efe565b8615806118c3575060065487115b156118e1576040516335aacf6560e11b815260040160405180910390fd5b61195d6106aa6040518060800160405280605481526020016138cf60549139805190602001208989898960405160200161191c929190613683565b60408051601f198184030181528282528051602091820120908301959095528101929092526060820152608081019190915260a0810186905260c00161068f565b6000878152600b60205260409020600781015460ff16156119915760405163cd029ba360e01b815260040160405180910390fd5b60058101546001600160a01b031633146119be576040516348f5c3ed60e01b815260040160405180910390fd5b80546000906119d5906001600160a01b0316611fff565b60038301548354600185015460058601549394509192611a039285926001600160a01b039081169216612061565b1015611a515760405162461bcd60e51b815260206004820152601b60248201527f53656c6c657220646f65736e2774206861766520746865204e46540000000000604482015260640161076b565b6000898152600c60205260409020548810611a7f5760405163ac96c2bd60e01b815260040160405180910390fd5b6000898152600c6020526040812080548a908110611a9f57611a9f6136af565b6000918252602091829020604080516080810182526003939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff161580159183018290526002909301546060830152909250611b1e5750600283015460208201518251611b1e926001600160a01b03169190612739565b611b5c5760405162461bcd60e51b815260206004820152600f60248201526e139bdd0818481d985b1a5908189a59608a1b604482015260640161076b565b60078301805460ff1916600117905560405189908b907f2e3b770b986273dab692303c20bf314387cc7f86af8f2e2f289c8c2d4316c15690600090a36020810151600584015482516002860154611bc9938e9390926001600160a01b039182169290918e918e911661226a565b82546005840154602083015160018601546003870154611bfb9487946001600160a01b03918216949116929091612446565b50506005818101546001600160a01b03908116600090815260209283526040808220855490931682529183528181206001948501548252909252812055600255610f30565b611c48612f8c565b825115611d605760001960005b8451811015611d3257848181518110611c7057611c706136af565b602002602001015160400151158015611cc95750611cc984868381518110611c9a57611c9a6136af565b602002602001015160200151878481518110611cb857611cb86136af565b602002602001015160000151612739565b15611d2057600019821480611d175750848281518110611ceb57611ceb6136af565b602002602001015160000151858281518110611d0957611d096136af565b602002602001015160000151115b15611d20578091505b80611d2a8161370a565b915050611c55565b506000198114611d5e57838181518110611d4e57611d4e6136af565b6020026020010151915050610a45565b505b5060408051608081018252600080825260208201819052918101829052606081019190915292915050565b611d93612542565b61154f816129c4565b611da4612542565b600180546001600160a01b0383166001600160a01b03199091168117909155611dd56000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6000602083511015611e2957611e2283612a38565b9050610a45565b82828151611e3a9260200190612fbf565b5060ff9050610a45565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b90565b6001600160a01b03163b151590565b600280541415611ef85760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161076b565b60028055565b600154600160a01b900460ff1615610b695760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161076b565b6000610a45611f58612a76565b8360405161190160f01b8152600281019290925260228201526042902090565b814210611fbb5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b604482015260640161076b565b6000611fc78483612ba1565b50600a549091506001600160a01b03808316911614611ff957604051638baa579f60e01b815260040160405180910390fd5b50505050565b60008061201c6001600160a01b0384166380ac58cd60e01b612be7565b90506120386001600160a01b038416636cdb3d1360e11b612be7565b1515811515146120485792915050565b604051630280e1e560e61b815260040160405180910390fd5b600084156120f9576040516331a9108f60e11b8152600481018490526001600160a01b038084169190861690636352211e90602401602060405180830381865afa1580156120b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120d79190613725565b6001600160a01b0316146120ec5760006120ef565b60015b60ff16905061216b565b604051627eeac760e11b81526001600160a01b0383811660048301526024820185905285169062fdd58e90604401602060405180830381865afa158015612144573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121689190613742565b90505b949350505050565b6002820154815460009160001991839142916001600160a01b03909116905b801561225e5760006121a56001836136db565b905060008882815481106121bb576121bb6136af565b906000526020600020906003020190508060010160149054906101000a900460ff16156121e957505061224e565b8054868110156121fb5750505061224e565b6002820154818814801561220f5750868110155b1561221d575050505061224e565b60018301546122379087906001600160a01b031684612739565b612244575050505061224e565b9297509550909350505b6122578161375b565b9050612192565b50929695505050505050565b60075461ffff1660006127106122808388613772565b61228a9190613791565b9050600061229882886136db565b9050845b801561240757600087876122b16001856136db565b8181106122c0576122c06136af565b602002919091013591506000905060a089896122dd6001876136db565b8181106122ec576122ec6136af565b602002919091013590911c9150612328905061230882886137b3565b61ffff16111561235a5760405162461bcd60e51b815260206004820152601e60248201527f546f74616c20636f6d6d697373696f6e732061726520746f6f20686967680000604482015260640161076b565b61236481876137b3565b9550600061271061237961ffff84168d613772565b6123839190613791565b90506123938d84838b6001612c03565b156123f3576123a281866136db565b9450826001600160a01b03168d6001600160a01b03168f7f5f2c64619f2837957b829514d3f9b4e3882e8e746c945031d746ac2a5ba67927846040516123ea91815260200190565b60405180910390a45b505050806124009061375b565b905061229c565b50811561242b57600954612429908a906001600160a01b031684876000612c03565b505b612439898983876000612c03565b5050505050505050505050565b85156124bb57604051632142170760e11b81526001600160a01b0385811660048301528481166024830152604482018490528616906342842e0e90606401600060405180830381600087803b15801561249e57600080fd5b505af11580156124b2573d6000803e3d6000fd5b5050505061099c565b604051637921219560e11b81526001600160a01b0385811660048301528481166024830152604482018490526064820183905260a06084830152600060a483015286169063f242432a9060c401600060405180830381600087803b15801561252257600080fd5b505af1158015612536573d6000803e3d6000fd5b50505050505050505050565b6000546001600160a01b03163314610b695760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161076b565b6125a4612d55565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60405163e985e9c560e01b81523360048201523060248201526000906001600160a01b0384169063e985e9c590604401602060405180830381865afa15801561263e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061266291906137d9565b90508015801561266f5750835b156126ec5760405163020604bf60e21b81526004810183905230906001600160a01b0385169063081812fc90602401602060405180830381865afa1580156126bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126df9190613725565b6001600160a01b03161490505b80611ff95760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420616c6c6f77656420746f206d616e61676520746f6b656e7300000000604482015260640161076b565b6040516370a0823160e01b81526001600160a01b03838116600483015260009182918616906370a0823190602401602060405180830381865afa158015612784573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127a89190613742565b9050828110156127bc57600091505061284c565b604051636eb1769f60e11b81526001600160a01b0385811660048301523060248301526000919087169063dd62ed3e90604401602060405180830381865afa15801561280c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128309190613742565b9050838110156128455760009250505061284c565b6001925050505b9392505050565b6001600160a01b03811661287a5760405163e6c4247b60e01b815260040160405180910390fd5b600a80546001600160a01b0319166001600160a01b0383169081179091556040517f5cf1735f1350de7c05f30a25d6fc56e0cd343859cea70b63dafb8d35afb5bc0890600090a250565b600180546001600160a01b031916905561154f81611e44565b6128e5611efe565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586125d43390565b606060ff831461293357611e2283612da5565b81805461293f906137f6565b80601f016020809104026020016040519081016040528092919081815260200182805461296b906137f6565b80156129b85780601f1061298d576101008083540402835291602001916129b8565b820191906000526020600020905b81548152906001019060200180831161299b57829003601f168201915b50505050509050610a45565b6001600160a01b0381163b6129ec5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b038116600081815260086020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a250565b600080829050601f81511115612a63578260405163305a27a960e01b815260040161076b9190613831565b8051612a6e82613844565b179392505050565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015612acf57507f000000000000000000000000000000000000000000000000000000000000000046145b15612af957507f000000000000000000000000000000000000000000000000000000000000000090565b6105dc604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600080825160411415612bd85760208301516040840151606085015160001a612bcc87828585612de4565b94509450505050612be0565b506000905060025b9250929050565b6000612bf283612ea8565b801561284c575061284c8383612edb565b604080516001600160a01b0387811660248301528681166044830152606480830187905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17905291516000928392839291871691612c699190613868565b6000604051808303816000865af19150503d8060008114612ca6576040519150601f19603f3d011682016040523d82523d6000602084013e612cab565b606091505b5091509150818015612cd5575080511580612cd5575080806020019051810190612cd591906137d9565b15612ce557600192505050612d4c565b83612d455760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161076b565b6000925050505b95945050505050565b600154600160a01b900460ff16610b695760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161076b565b60606000612db283612f64565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115612e1b5750600090506003612e9f565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612e6f573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612e9857600060019250925050612e9f565b9150600090505b94509492505050565b6000612ebb826301ffc9a760e01b612edb565b8015610a455750612ed4826001600160e01b0319612edb565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015612f4d575060208210155b8015612f595750600081115b979650505050505050565b600060ff8216601f811115610a4557604051632cd44ac360e21b815260040160405180910390fd5b60405180608001604052806000815260200160006001600160a01b03168152602001600015158152602001600081525090565b828054612fcb906137f6565b90600052602060002090601f016020900481019282612fed5760008555613033565b82601f1061300657805160ff1916838001178555613033565b82800160010185558215613033579182015b82811115613033578251825591602001919060010190613018565b5061303f929150613043565b5090565b5b8082111561303f5760008155600101613044565b60006020828403121561306a57600080fd5b5035919050565b60008083601f84011261308357600080fd5b50813567ffffffffffffffff81111561309b57600080fd5b6020830191508360208260051b8501011115612be057600080fd5b60008083601f8401126130c857600080fd5b50813567ffffffffffffffff8111156130e057600080fd5b602083019150836020828501011115612be057600080fd5b6000806000806000806080878903121561311157600080fd5b86359550602087013567ffffffffffffffff8082111561313057600080fd5b61313c8a838b01613071565b909750955060408901359450606089013591508082111561315c57600080fd5b5061316989828a016130b6565b979a9699509497509295939492505050565b6000806040838503121561318e57600080fd5b50508035926020909101359150565b815181526020808301516001600160a01b0316908201526040808301511515908201526060808301519082015260808101610a45565b6001600160a01b038116811461154f57600080fd5b80356131f3816131d3565b919050565b60006020828403121561320a57600080fd5b813561284c816131d3565b6000806040838503121561322857600080fd5b82359150602083013561323a816131d3565b809150509250929050565b600080600080600080600060e0888a03121561326057600080fd5b873561326b816131d3565b9650602088013595506040880135613282816131d3565b969995985095966060810135965060808101359560a0820135955060c0909101359350915050565b6020808252825182820181905260009190848201906040850190845b8181101561331557613302838551805182526020808201516001600160a01b031690830152604080820151151590830152606090810151910152565b92840192608092909201916001016132c6565b50909695505050505050565b60005b8381101561333c578181015183820152602001613324565b83811115611ff95750506000910152565b60008151808452613365816020860160208601613321565b601f01601f19169290920160200192915050565b60ff60f81b881681526000602060e08184015261339960e084018a61334d565b83810360408501526133ab818a61334d565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b818110156133fd578351835292840192918401916001016133e1565b50909c9b505050505050505050505050565b60006020828403121561342157600080fd5b813561ffff8116811461284c57600080fd5b60008060006060848603121561344857600080fd5b8335613453816131d3565b92506020840135613463816131d3565b929592945050506040919091013590565b600080600080600080600060a0888a03121561348f57600080fd5b8735965060208801359550604088013567ffffffffffffffff808211156134b557600080fd5b6134c18b838c01613071565b909750955060608a0135945060808a01359150808211156134e157600080fd5b506134ee8a828b016130b6565b989b979a50959850939692959293505050565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff8111828210171561353a5761353a613501565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561356957613569613501565b604052919050565b801515811461154f57600080fd5b600080604080848603121561359357600080fd5b833567ffffffffffffffff808211156135ab57600080fd5b818601915086601f8301126135bf57600080fd5b81356020828211156135d3576135d3613501565b6135e1818360051b01613540565b828152818101935060079290921b84018101918983111561360157600080fd5b938101935b82851015613668576080858b03121561361f5760008081fd5b613627613517565b8535815282860135613638816131d3565b818401528587013561364981613571565b8188015260608681013590820152845260809094019392810192613606565b96506136758882016131e8565b955050505050509250929050565b60006001600160fb1b0383111561369957600080fd5b8260051b80858437600092019182525092915050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156136ed576136ed6136c5565b500390565b60008219821115613705576137056136c5565b500190565b600060001982141561371e5761371e6136c5565b5060010190565b60006020828403121561373757600080fd5b815161284c816131d3565b60006020828403121561375457600080fd5b5051919050565b60008161376a5761376a6136c5565b506000190190565b600081600019048311821515161561378c5761378c6136c5565b500290565b6000826137ae57634e487b7160e01b600052601260045260246000fd5b500490565b600061ffff8083168185168083038211156137d0576137d06136c5565b01949350505050565b6000602082840312156137eb57600080fd5b815161284c81613571565b600181811c9082168061380a57607f821691505b6020821081141561382b57634e487b7160e01b600052602260045260246000fd5b50919050565b60208152600061284c602083018461334d565b8051602080830151919081101561382b5760001960209190910360031b1b16919050565b6000825161387a818460208701613321565b919091019291505056fe7465726d696e61746541756374696f6e2875696e74323536206c697374696e6749642c627974657333325b5d20726f79616c746965732c75696e743235362065787069726174696f6e296163636570744269642875696e74323536206c697374696e6749642c75696e7432353620626964496e6465782c627974657333325b5d20726f79616c746965732c75696e743235362065787069726174696f6e29a2646970667358221220d94fc1f5ce5c1b33d12d1bcc84aa780fa634fb7d3c47b77c4e41a313308146cc64736f6c634300080c0033000000000000000000000000c176ba009608fddb71c8cdeee0efb0e72deaeeb30000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070499adebb11efd915e3b69e700c331778628707
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106102065760003560e01c806377d3550b1161011a5780639c9f39b0116100ad578063cddaa6711161007c578063cddaa67114610574578063e30c397814610587578063e43252d714610598578063f2fde38b146105ab578063f92aa57f146105be57600080fd5b80639c9f39b01461050a578063a576cf9d1461051d578063b370fa7114610530578063b5f0dcc21461056157600080fd5b80638ab1d681116100e95780638ab1d681146103f75780638da5cb5b1461040a57806396a168351461042f5780639ae8665d1461044257600080fd5b806377d3550b146103ab57806379ba5097146103cc5780638456cb59146103d457806384b0196e146103dc57600080fd5b806340a3a5051161019d5780635c975abb1161016c5780635c975abb1461031d5780635f93de491461032f5780636c19e7831461037057806370b4768e14610383578063715018a6146103a357600080fd5b806340a3a505146102d157806347c00039146102e45780634b393605146102f7578063598647f81461030a57600080fd5b80632a5a9435116101d95780632a5a94351461027b578063367005021461028e5780633f4ba83a146102c15780633f8992e5146102c957600080fd5b80630eb06ff11461020b578063112ae0341461022657806329fef827146102465780632a2231141461025b575b600080fd5b6102136105d1565b6040519081526020015b60405180910390f35b610213610234366004613058565b600e6020526000908152604090205481565b6102596102543660046130f8565b6105e1565b005b61026e61026936600461317b565b6109a4565b60405161021d919061319d565b610259610289366004613058565b610a4b565b6102b161029c3660046131f8565b60086020526000908152604090205460ff1681565b604051901515815260200161021d565b610259610b59565b610213606481565b61026e6102df366004613215565b610b6b565b6102596102f2366004613245565b610bfc565b61025961030536600461317b565b610f39565b61025961031836600461317b565b6110eb565b600154600160a01b900460ff166102b1565b61034261033d36600461317b565b6114e7565b604080519485526001600160a01b03909316602085015290151591830191909152606082015260800161021d565b61025961037e3660046131f8565b61153e565b610396610391366004613058565b611552565b60405161021d91906132aa565b6102596115f7565b6007546103b99061ffff1681565b60405161ffff909116815260200161021d565b610259611609565b610259611680565b6103e4611690565b60405161021d9796959493929190613379565b6102596104053660046131f8565b611719565b6000546001600160a01b03165b6040516001600160a01b03909116815260200161021d565b600a54610417906001600160a01b031681565b6104ad610450366004613058565b600b602052600090815260409020805460018201546002830154600384015460048501546005860154600687015460078801546008909801546001600160a01b0397881698969795861696949593949290931692909160ff169089565b604080516001600160a01b039a8b1681526020810199909952968916968801969096526060870194909452608086019290925290941660a084015260c083019390935291151560e08201526101008101919091526101200161021d565b61025961051836600461340f565b61176a565b61025961052b3660046131f8565b61182c565b61021361053e366004613433565b600560209081526000938452604080852082529284528284209052825290205481565b61025961056f366004613474565b6118a5565b61026e61058236600461357f565b611c40565b6001546001600160a01b0316610417565b6102596105a63660046131f8565b611d8b565b6102596105b93660046131f8565b611d9c565b600954610417906001600160a01b031681565b60006105dc60065490565b905090565b6105e9611ea6565b6105f1611efe565b8515806105ff575060065486115b1561061d576040516335aacf6560e11b815260040160405180910390fd5b6106e76106aa6040518060800160405280604a8152602001613885604a913980519060200120888888604051602001610657929190613683565b60408051601f1981840301815282825280516020918201209083019490945281019190915260608101919091526080810186905260a0015b60405160208183030381529060405280519060200120611f4b565b8484848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611f7892505050565b6000868152600b60205260409020600781015460ff161561071b5760405163cd029ba360e01b815260040160405180910390fd5b80600601544210156107745760405162461bcd60e51b815260206004820152601860248201527f5468652061756374696f6e206861736e277420656e646564000000000000000060448201526064015b60405180910390fd5b805460009061078b906001600160a01b0316611fff565b600383015483546001850154600586015493945091926107b99285926001600160a01b039081169216612061565b10156108075760405162461bcd60e51b815260206004820152601b60248201527f53656c6c657220646f65736e2774206861766520746865204e46540000000000604482015260640161076b565b60078201805460ff191660019081179091556000898152600c602090815260408083206005808801546001600160a01b0390811686529084528285208854909116855283528184209487015484529390915281205580541561096357600061086f8483612173565b905060001981146109615760405181908b907f2e3b770b986273dab692303c20bf314387cc7f86af8f2e2f289c8c2d4316c15690600090a360008282815481106108bb576108bb6136af565b906000526020600020906003020190506109238b8260010160009054906101000a90046001600160a01b03168760050160009054906101000a90046001600160a01b031684600001548e8e8b60020160009054906101000a90046001600160a01b031661226a565b845460058601546001838101549088015460038901546109579489946001600160a01b039182169490821693911691612446565b5050505050610992565b505b60405189907fcd92308c6a39b7531d0e2dc72e7cd0e3c97cead6167c2c5f33c4d360db118d5690600090a25050505b61099c6001600255565b505050505050565b6109ac612f8c565b6000838152600c60205260409020805483106109db5760405163ac96c2bd60e01b815260040160405180910390fd5b8083815481106109ed576109ed6136af565b6000918252602091829020604080516080810182526003939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff1615159082015260029091015460608201529150505b92915050565b610a53611efe565b801580610a61575060065481115b15610a7f576040516335aacf6560e11b815260040160405180910390fd5b6000818152600b6020526040902060058101546001600160a01b03163314610aba576040516348f5c3ed60e01b815260040160405180910390fd5b600781015460ff1615610ae05760405163cd029ba360e01b815260040160405180910390fd5b60078101805460ff191660019081179091556005808301546001600160a01b0390811660009081526020928352604080822086549093168252918352818120938501548152929091528082208290555183917f2809c7e17bf978fbc7194c0a694b638c4215e9140cacc6c38ca36010b45697df91a25050565b610b61612542565b610b6961259c565b565b610b73612f8c565b6000838152600d602090815260408083206001600160a01b038616845290915290205480610bd35760405162461bcd60e51b815260206004820152600d60248201526c109a59081b9bdd08199bdd5b99609a1b604482015260640161076b565b6000848152600c60205260409020610bec6001836136db565b815481106109ed576109ed6136af565b610c04611ea6565b610c0c611efe565b428211610c2c576040516302e8f35960e31b815260040160405180910390fd5b818110610c8f5760405162461bcd60e51b815260206004820152602b60248201527f53616c652073746172742074696d65206d757374206265206265666f7265207460448201526a686520646561646c696e6560a81b606482015260840161076b565b3360009081526005602090815260408083206001600160a01b038b1684528252808320898452918290529091205415610cdb57604051636f555ee160e11b815260040160405180910390fd5b6000851580610cfe5750610cee89611fff565b9050808015610cfe575085600114155b80610d13575085610d11828b8b33612061565b105b15610d315760405163162908e360e11b815260040160405180910390fd5b6001600160a01b03871660009081526008602052604090205460ff16610d6a576040516305fe65f560e21b815260040160405180910390fd5b610d75818a8a6125f1565b610d83600680546001019055565b6000610d8e60065490565b90506040518061012001604052808b6001600160a01b031681526020018a8152602001896001600160a01b03168152602001888152602001878152602001336001600160a01b0316815260200186815260200160001515815260200185815250600b600083815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015560408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550606082015181600301556080820151816004015560a08201518160050160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e08201518160070160006101000a81548160ff021916908315150217905550610100820151816008015590505060018360008b815260200190815260200160002081905550807f254c646c6c0f4251485be1ae1b544a687cfa682ee3314d2c5a9d801691193e9a60405160405180910390a2505050610f306001600255565b50505050505050565b610f41611efe565b811580610f4f575060065482115b15610f6d576040516335aacf6560e11b815260040160405180910390fd5b6000828152600b60205260409020600781015460ff1615610fa15760405163cd029ba360e01b815260040160405180910390fd5b80600601544210610fc55760405163dda144a560e01b815260040160405180910390fd5b6000838152600c60205260409020548210610ff35760405163ac96c2bd60e01b815260040160405180910390fd5b6000838152600c60205260408120805484908110611013576110136136af565b600091825260209091206001600390920201908101549091506001600160a01b03163314611054576040516348f5c3ed60e01b815260040160405180910390fd5b6001810154600160a01b900460ff16156110a35760405162461bcd60e51b815260206004820152601060248201526f105b1c9958591e4818d85b98d95b195960821b604482015260640161076b565b60018101805460ff60a01b1916600160a01b179055604051839085907f2f308e24a5dcbe2c77ba79c28760736ec7158e5a7eef8556ec18503dccb1dfa290600090a350505050565b6110f3611ea6565b6110fb611efe565b811580611109575060065482115b15611127576040516335aacf6560e11b815260040160405180910390fd5b6000828152600b60205260409020600781015460ff161561115b5760405163cd029ba360e01b815260040160405180910390fd5b4281600801541115611180576040516316851a3760e11b815260040160405180910390fd5b600681015460058201546001600160a01b03163314156111b3576040516348f5c3ed60e01b815260040160405180910390fd5b8042106111d35760405163dda144a560e01b815260040160405180910390fd5b6000848152600d60209081526040808320338452825280832054878452600c90925290912081611227578360040154851015611222576040516356010c6b60e11b815260040160405180910390fd5b611274565b806112336001846136db565b81548110611243576112436136af565b9060005260206000209060030201600001548511611274576040516356010c6b60e11b815260040160405180910390fd5b600284015461128d906001600160a01b03163387612739565b6112aa57604051631e9acf1760e31b815260040160405180910390fd5b81611353576000868152600c602090815260408083208151608081018352898152338185018181528285018781524260608501908152855460018181018855968a52888a20955160039091029095019485559151948401805491511515600160a01b026001600160a81b03199092166001600160a01b03969096169590951717909355915160029091015584548a8552600d8452828520918552925290912081905591506113f9565b84816113606001856136db565b81548110611370576113706136af565b6000918252602090912060039091020155428161138e6001856136db565b8154811061139e5761139e6136af565b60009182526020822060026003909202010191909155816113c06001856136db565b815481106113d0576113d06136af565b906000526020600020906003020160010160146101000a81548160ff0219169083151502179055505b611405610258426136f2565b8310801561142157506000868152600e60205260409020546064115b1561148f576000868152600e602052604081208054916114408361370a565b909155506114529050610258426136f2565b6006850181905560405190815286907f6e912a3a9105bdd2af817ba5adc14e6c127c1035b5b648faa29ca0d58ab8ff4e9060200160405180910390a25b3361149b6001846136db565b877f53ae5fec6fc7d9b5f3a4419f25dd826d109b8c6eb49165fef6ebad278292f151886040516114cd91815260200190565b60405180910390a4505050506114e36001600255565b5050565b600c602052816000526040600020818154811061150357600080fd5b60009182526020909120600390910201805460018201546002909201549093506001600160a01b0382169250600160a01b90910460ff169084565b611546612542565b61154f81612853565b50565b6060600c6000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b828210156115ec5760008481526020908190206040805160808101825260038602909201805483526001808201546001600160a01b03811685870152600160a01b900460ff161515928401929092526002015460608301529083529092019101611587565b505050509050919050565b6115ff612542565b610b6960006128c4565b60015433906001600160a01b031681146116775760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b606482015260840161076b565b61154f816128c4565b611688612542565b610b696128dd565b6000606080828080836116c47f486f77546f50756c73652d4e46544d61726b657441756374696f6e000000001b6003612920565b6116ef7f31000000000000000000000000000000000000000000000000000000000000016004612920565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b611721612542565b6001600160a01b038116600081815260086020526040808220805460ff19169055517fcdd2e9b91a56913d370075169cefa1602ba36be5301664f752192bb1709df7579190a250565b611772612542565b6101f461ffff821611156117e25760405162461bcd60e51b815260206004820152603160248201527f53657276696365206665652063616e6e6f7420626520626967676572207468616044820152706e203530302028657175616c732035252960781b606482015260840161076b565b6007805461ffff191661ffff83169081179091556040519081527f73c039f9c4e58241e463c99d8943c1ba1d69631b8feb1d75f9adb5a84d4f32ee9060200160405180910390a150565b611834612542565b6001600160a01b03811661185b5760405163e6c4247b60e01b815260040160405180910390fd5b600980546001600160a01b0319166001600160a01b0383169081179091556040517fac519e193b7e6a77b060aa9ca9eea599673fe42e8ffc2551057f1f8163b4128d90600090a250565b6118ad611ea6565b6118b5611efe565b8615806118c3575060065487115b156118e1576040516335aacf6560e11b815260040160405180910390fd5b61195d6106aa6040518060800160405280605481526020016138cf60549139805190602001208989898960405160200161191c929190613683565b60408051601f198184030181528282528051602091820120908301959095528101929092526060820152608081019190915260a0810186905260c00161068f565b6000878152600b60205260409020600781015460ff16156119915760405163cd029ba360e01b815260040160405180910390fd5b60058101546001600160a01b031633146119be576040516348f5c3ed60e01b815260040160405180910390fd5b80546000906119d5906001600160a01b0316611fff565b60038301548354600185015460058601549394509192611a039285926001600160a01b039081169216612061565b1015611a515760405162461bcd60e51b815260206004820152601b60248201527f53656c6c657220646f65736e2774206861766520746865204e46540000000000604482015260640161076b565b6000898152600c60205260409020548810611a7f5760405163ac96c2bd60e01b815260040160405180910390fd5b6000898152600c6020526040812080548a908110611a9f57611a9f6136af565b6000918252602091829020604080516080810182526003939093029091018054835260018101546001600160a01b03811694840194909452600160a01b90930460ff161580159183018290526002909301546060830152909250611b1e5750600283015460208201518251611b1e926001600160a01b03169190612739565b611b5c5760405162461bcd60e51b815260206004820152600f60248201526e139bdd0818481d985b1a5908189a59608a1b604482015260640161076b565b60078301805460ff1916600117905560405189908b907f2e3b770b986273dab692303c20bf314387cc7f86af8f2e2f289c8c2d4316c15690600090a36020810151600584015482516002860154611bc9938e9390926001600160a01b039182169290918e918e911661226a565b82546005840154602083015160018601546003870154611bfb9487946001600160a01b03918216949116929091612446565b50506005818101546001600160a01b03908116600090815260209283526040808220855490931682529183528181206001948501548252909252812055600255610f30565b611c48612f8c565b825115611d605760001960005b8451811015611d3257848181518110611c7057611c706136af565b602002602001015160400151158015611cc95750611cc984868381518110611c9a57611c9a6136af565b602002602001015160200151878481518110611cb857611cb86136af565b602002602001015160000151612739565b15611d2057600019821480611d175750848281518110611ceb57611ceb6136af565b602002602001015160000151858281518110611d0957611d096136af565b602002602001015160000151115b15611d20578091505b80611d2a8161370a565b915050611c55565b506000198114611d5e57838181518110611d4e57611d4e6136af565b6020026020010151915050610a45565b505b5060408051608081018252600080825260208201819052918101829052606081019190915292915050565b611d93612542565b61154f816129c4565b611da4612542565b600180546001600160a01b0383166001600160a01b03199091168117909155611dd56000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6000602083511015611e2957611e2283612a38565b9050610a45565b82828151611e3a9260200190612fbf565b5060ff9050610a45565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b90565b6001600160a01b03163b151590565b600280541415611ef85760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161076b565b60028055565b600154600160a01b900460ff1615610b695760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161076b565b6000610a45611f58612a76565b8360405161190160f01b8152600281019290925260228201526042902090565b814210611fbb5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b604482015260640161076b565b6000611fc78483612ba1565b50600a549091506001600160a01b03808316911614611ff957604051638baa579f60e01b815260040160405180910390fd5b50505050565b60008061201c6001600160a01b0384166380ac58cd60e01b612be7565b90506120386001600160a01b038416636cdb3d1360e11b612be7565b1515811515146120485792915050565b604051630280e1e560e61b815260040160405180910390fd5b600084156120f9576040516331a9108f60e11b8152600481018490526001600160a01b038084169190861690636352211e90602401602060405180830381865afa1580156120b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120d79190613725565b6001600160a01b0316146120ec5760006120ef565b60015b60ff16905061216b565b604051627eeac760e11b81526001600160a01b0383811660048301526024820185905285169062fdd58e90604401602060405180830381865afa158015612144573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121689190613742565b90505b949350505050565b6002820154815460009160001991839142916001600160a01b03909116905b801561225e5760006121a56001836136db565b905060008882815481106121bb576121bb6136af565b906000526020600020906003020190508060010160149054906101000a900460ff16156121e957505061224e565b8054868110156121fb5750505061224e565b6002820154818814801561220f5750868110155b1561221d575050505061224e565b60018301546122379087906001600160a01b031684612739565b612244575050505061224e565b9297509550909350505b6122578161375b565b9050612192565b50929695505050505050565b60075461ffff1660006127106122808388613772565b61228a9190613791565b9050600061229882886136db565b9050845b801561240757600087876122b16001856136db565b8181106122c0576122c06136af565b602002919091013591506000905060a089896122dd6001876136db565b8181106122ec576122ec6136af565b602002919091013590911c9150612328905061230882886137b3565b61ffff16111561235a5760405162461bcd60e51b815260206004820152601e60248201527f546f74616c20636f6d6d697373696f6e732061726520746f6f20686967680000604482015260640161076b565b61236481876137b3565b9550600061271061237961ffff84168d613772565b6123839190613791565b90506123938d84838b6001612c03565b156123f3576123a281866136db565b9450826001600160a01b03168d6001600160a01b03168f7f5f2c64619f2837957b829514d3f9b4e3882e8e746c945031d746ac2a5ba67927846040516123ea91815260200190565b60405180910390a45b505050806124009061375b565b905061229c565b50811561242b57600954612429908a906001600160a01b031684876000612c03565b505b612439898983876000612c03565b5050505050505050505050565b85156124bb57604051632142170760e11b81526001600160a01b0385811660048301528481166024830152604482018490528616906342842e0e90606401600060405180830381600087803b15801561249e57600080fd5b505af11580156124b2573d6000803e3d6000fd5b5050505061099c565b604051637921219560e11b81526001600160a01b0385811660048301528481166024830152604482018490526064820183905260a06084830152600060a483015286169063f242432a9060c401600060405180830381600087803b15801561252257600080fd5b505af1158015612536573d6000803e3d6000fd5b50505050505050505050565b6000546001600160a01b03163314610b695760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161076b565b6125a4612d55565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60405163e985e9c560e01b81523360048201523060248201526000906001600160a01b0384169063e985e9c590604401602060405180830381865afa15801561263e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061266291906137d9565b90508015801561266f5750835b156126ec5760405163020604bf60e21b81526004810183905230906001600160a01b0385169063081812fc90602401602060405180830381865afa1580156126bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126df9190613725565b6001600160a01b03161490505b80611ff95760405162461bcd60e51b815260206004820152601c60248201527f4e6f7420616c6c6f77656420746f206d616e61676520746f6b656e7300000000604482015260640161076b565b6040516370a0823160e01b81526001600160a01b03838116600483015260009182918616906370a0823190602401602060405180830381865afa158015612784573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127a89190613742565b9050828110156127bc57600091505061284c565b604051636eb1769f60e11b81526001600160a01b0385811660048301523060248301526000919087169063dd62ed3e90604401602060405180830381865afa15801561280c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128309190613742565b9050838110156128455760009250505061284c565b6001925050505b9392505050565b6001600160a01b03811661287a5760405163e6c4247b60e01b815260040160405180910390fd5b600a80546001600160a01b0319166001600160a01b0383169081179091556040517f5cf1735f1350de7c05f30a25d6fc56e0cd343859cea70b63dafb8d35afb5bc0890600090a250565b600180546001600160a01b031916905561154f81611e44565b6128e5611efe565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586125d43390565b606060ff831461293357611e2283612da5565b81805461293f906137f6565b80601f016020809104026020016040519081016040528092919081815260200182805461296b906137f6565b80156129b85780601f1061298d576101008083540402835291602001916129b8565b820191906000526020600020905b81548152906001019060200180831161299b57829003601f168201915b50505050509050610a45565b6001600160a01b0381163b6129ec5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b038116600081815260086020526040808220805460ff19166001179055517fa850ae9193f515cbae8d35e8925bd2be26627fc91bce650b8652ed254e9cab039190a250565b600080829050601f81511115612a63578260405163305a27a960e01b815260040161076b9190613831565b8051612a6e82613844565b179392505050565b6000306001600160a01b037f000000000000000000000000556b089c3c5c13cf48c805ff3d21e2447a0e405f16148015612acf57507f00000000000000000000000000000000000000000000000000000000000003af46145b15612af957507f9300fcf5c72f3b433cbeb3608460a729f3317cb84d288a6bf87484aef3f5185890565b6105dc604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527ffc83c1ba43991e9babdfee7251b329b0c57e3b35363df9b754e8f9bfc4d9d6b5918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600080825160411415612bd85760208301516040840151606085015160001a612bcc87828585612de4565b94509450505050612be0565b506000905060025b9250929050565b6000612bf283612ea8565b801561284c575061284c8383612edb565b604080516001600160a01b0387811660248301528681166044830152606480830187905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17905291516000928392839291871691612c699190613868565b6000604051808303816000865af19150503d8060008114612ca6576040519150601f19603f3d011682016040523d82523d6000602084013e612cab565b606091505b5091509150818015612cd5575080511580612cd5575080806020019051810190612cd591906137d9565b15612ce557600192505050612d4c565b83612d455760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161076b565b6000925050505b95945050505050565b600154600160a01b900460ff16610b695760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161076b565b60606000612db283612f64565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115612e1b5750600090506003612e9f565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612e6f573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612e9857600060019250925050612e9f565b9150600090505b94509492505050565b6000612ebb826301ffc9a760e01b612edb565b8015610a455750612ed4826001600160e01b0319612edb565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015612f4d575060208210155b8015612f595750600081115b979650505050505050565b600060ff8216601f811115610a4557604051632cd44ac360e21b815260040160405180910390fd5b60405180608001604052806000815260200160006001600160a01b03168152602001600015158152602001600081525090565b828054612fcb906137f6565b90600052602060002090601f016020900481019282612fed5760008555613033565b82601f1061300657805160ff1916838001178555613033565b82800160010185558215613033579182015b82811115613033578251825591602001919060010190613018565b5061303f929150613043565b5090565b5b8082111561303f5760008155600101613044565b60006020828403121561306a57600080fd5b5035919050565b60008083601f84011261308357600080fd5b50813567ffffffffffffffff81111561309b57600080fd5b6020830191508360208260051b8501011115612be057600080fd5b60008083601f8401126130c857600080fd5b50813567ffffffffffffffff8111156130e057600080fd5b602083019150836020828501011115612be057600080fd5b6000806000806000806080878903121561311157600080fd5b86359550602087013567ffffffffffffffff8082111561313057600080fd5b61313c8a838b01613071565b909750955060408901359450606089013591508082111561315c57600080fd5b5061316989828a016130b6565b979a9699509497509295939492505050565b6000806040838503121561318e57600080fd5b50508035926020909101359150565b815181526020808301516001600160a01b0316908201526040808301511515908201526060808301519082015260808101610a45565b6001600160a01b038116811461154f57600080fd5b80356131f3816131d3565b919050565b60006020828403121561320a57600080fd5b813561284c816131d3565b6000806040838503121561322857600080fd5b82359150602083013561323a816131d3565b809150509250929050565b600080600080600080600060e0888a03121561326057600080fd5b873561326b816131d3565b9650602088013595506040880135613282816131d3565b969995985095966060810135965060808101359560a0820135955060c0909101359350915050565b6020808252825182820181905260009190848201906040850190845b8181101561331557613302838551805182526020808201516001600160a01b031690830152604080820151151590830152606090810151910152565b92840192608092909201916001016132c6565b50909695505050505050565b60005b8381101561333c578181015183820152602001613324565b83811115611ff95750506000910152565b60008151808452613365816020860160208601613321565b601f01601f19169290920160200192915050565b60ff60f81b881681526000602060e08184015261339960e084018a61334d565b83810360408501526133ab818a61334d565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b818110156133fd578351835292840192918401916001016133e1565b50909c9b505050505050505050505050565b60006020828403121561342157600080fd5b813561ffff8116811461284c57600080fd5b60008060006060848603121561344857600080fd5b8335613453816131d3565b92506020840135613463816131d3565b929592945050506040919091013590565b600080600080600080600060a0888a03121561348f57600080fd5b8735965060208801359550604088013567ffffffffffffffff808211156134b557600080fd5b6134c18b838c01613071565b909750955060608a0135945060808a01359150808211156134e157600080fd5b506134ee8a828b016130b6565b989b979a50959850939692959293505050565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff8111828210171561353a5761353a613501565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561356957613569613501565b604052919050565b801515811461154f57600080fd5b600080604080848603121561359357600080fd5b833567ffffffffffffffff808211156135ab57600080fd5b818601915086601f8301126135bf57600080fd5b81356020828211156135d3576135d3613501565b6135e1818360051b01613540565b828152818101935060079290921b84018101918983111561360157600080fd5b938101935b82851015613668576080858b03121561361f5760008081fd5b613627613517565b8535815282860135613638816131d3565b818401528587013561364981613571565b8188015260608681013590820152845260809094019392810192613606565b96506136758882016131e8565b955050505050509250929050565b60006001600160fb1b0383111561369957600080fd5b8260051b80858437600092019182525092915050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156136ed576136ed6136c5565b500390565b60008219821115613705576137056136c5565b500190565b600060001982141561371e5761371e6136c5565b5060010190565b60006020828403121561373757600080fd5b815161284c816131d3565b60006020828403121561375457600080fd5b5051919050565b60008161376a5761376a6136c5565b506000190190565b600081600019048311821515161561378c5761378c6136c5565b500290565b6000826137ae57634e487b7160e01b600052601260045260246000fd5b500490565b600061ffff8083168185168083038211156137d0576137d06136c5565b01949350505050565b6000602082840312156137eb57600080fd5b815161284c81613571565b600181811c9082168061380a57607f821691505b6020821081141561382b57634e487b7160e01b600052602260045260246000fd5b50919050565b60208152600061284c602083018461334d565b8051602080830151919081101561382b5760001960209190910360031b1b16919050565b6000825161387a818460208701613321565b919091019291505056fe7465726d696e61746541756374696f6e2875696e74323536206c697374696e6749642c627974657333325b5d20726f79616c746965732c75696e743235362065787069726174696f6e296163636570744269642875696e74323536206c697374696e6749642c75696e7432353620626964496e6465782c627974657333325b5d20726f79616c746965732c75696e743235362065787069726174696f6e29a2646970667358221220d94fc1f5ce5c1b33d12d1bcc84aa780fa634fb7d3c47b77c4e41a313308146cc64736f6c634300080c0033