Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- OffersLogic
- Optimization enabled
- true
- Compiler version
- v0.8.18+commit.87f61d96
- Optimization runs
- 1000
- EVM Version
- default
- Verified at
- 2023-07-27T04:36:55.053175Z
contracts/marketplace/offers/OffersLogic.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;
/// @author thirdweb
import "./OffersStorage.sol";
// ====== External imports ======
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
// ====== Internal imports ======
import "@thirdweb-dev/contracts/extension/plugin/ERC2771ContextConsumer.sol";
import "@thirdweb-dev/contracts/extension/interface/IPlatformFee.sol";
import "@thirdweb-dev/contracts/extension/plugin/ReentrancyGuardLogic.sol";
import "@thirdweb-dev/contracts/extension/plugin/PermissionsEnumerableLogic.sol";
import { CurrencyTransferLib } from "@thirdweb-dev/contracts/lib/CurrencyTransferLib.sol";
import "../../Constants.sol";
/**
* @author thirdweb.com
*/
contract OffersLogic is IOffers, ReentrancyGuardLogic, ERC2771ContextConsumer, Constants {
/*///////////////////////////////////////////////////////////////
Constants / Immutables
//////////////////////////////////////////////////////////////*/
/// @dev Can create offer for only assets from NFT contracts with asset role, when offers are restricted by asset address.
bytes32 private constant ASSET_ROLE = keccak256("ASSET_ROLE");
/// @dev The max bps of the contract. So, 10_000 == 100 %
uint64 private constant MAX_BPS = 10_000;
/*///////////////////////////////////////////////////////////////
Modifiers
//////////////////////////////////////////////////////////////*/
modifier onlyAssetRole(address _asset) {
require(PermissionsLogic(address(this)).hasRoleWithSwitch(ASSET_ROLE, _asset), "!ASSET_ROLE");
_;
}
/// @dev Checks whether caller is a offer creator.
modifier onlyOfferor(uint256 _offerId) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
require(data.offers[_offerId].offeror == _msgSender(), "!Offeror");
_;
}
/// @dev Checks whether an auction exists.
modifier onlyExistingOffer(uint256 _offerId) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
require(data.offers[_offerId].status == IOffers.Status.CREATED, "Marketplace: invalid offer.");
_;
}
/*///////////////////////////////////////////////////////////////
Constructor logic
//////////////////////////////////////////////////////////////*/
constructor() {}
/*///////////////////////////////////////////////////////////////
External functions
//////////////////////////////////////////////////////////////*/
function makeOffer(OfferParams memory _params)
external
onlyAssetRole(_params.assetContract)
returns (uint256 _offerId)
{
_offerId = _getNextOfferId();
address _offeror = _msgSender();
TokenType _tokenType = _getTokenType(_params.assetContract);
_validateNewOffer(_params, _tokenType);
Offer memory _offer = Offer({
offerId: _offerId,
offeror: _offeror,
assetContract: _params.assetContract,
tokenId: _params.tokenId,
tokenType: _tokenType,
quantity: _params.quantity,
currency: _params.currency,
totalPrice: _params.totalPrice,
expirationTimestamp: _params.expirationTimestamp,
status: IOffers.Status.CREATED
});
OffersStorage.Data storage data = OffersStorage.offersStorage();
data.offers[_offerId] = _offer;
emit NewOffer(_offeror, _offerId, _params.assetContract, _params.tokenId, _offer);
}
function cancelOffer(uint256 _offerId) external onlyExistingOffer(_offerId) onlyOfferor(_offerId) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
data.offers[_offerId].status = IOffers.Status.CANCELLED;
Offer memory offer = data.offers[_offerId];
emit CancelledOffer(_msgSender(), _offerId, offer.assetContract, offer.tokenId);
}
function acceptOffer(uint256 _offerId) external nonReentrant onlyExistingOffer(_offerId) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
Offer memory _targetOffer = data.offers[_offerId];
require(_targetOffer.expirationTimestamp > block.timestamp, "EXPIRED");
require(
_validateERC20BalAndAllowance(_targetOffer.offeror, _targetOffer.currency, _targetOffer.totalPrice),
"Marketplace: insufficient currency balance."
);
_validateOwnershipAndApproval(
_msgSender(),
_targetOffer.assetContract,
_targetOffer.tokenId,
_targetOffer.quantity,
_targetOffer.tokenType
);
data.offers[_offerId].status = IOffers.Status.COMPLETED;
_payout(_targetOffer.offeror, _msgSender(), _targetOffer.currency, _targetOffer.totalPrice, _targetOffer);
_transferOfferTokens(_msgSender(), _targetOffer.offeror, _targetOffer.quantity, _targetOffer);
emit AcceptedOffer(
_targetOffer.offeror,
_targetOffer.offerId,
_targetOffer.assetContract,
_targetOffer.tokenId,
_msgSender(),
_targetOffer.quantity,
_targetOffer.totalPrice,
_targetOffer.currency
);
}
/*///////////////////////////////////////////////////////////////
View functions
//////////////////////////////////////////////////////////////*/
/// @dev Returns total number of offers
function totalOffers() public view returns (uint256) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
return data.totalOffers;
}
/// @dev Returns existing offer with the given uid.
function getOffer(uint256 _offerId) external view returns (Offer memory _offer) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
_offer = data.offers[_offerId];
}
/// @dev Returns all existing offers within the specified range.
function getAllOffers(uint256 _startId, uint256 _endId) external view returns (Offer[] memory _allOffers) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
require(_startId <= _endId && _endId < data.totalOffers, "invalid range");
_allOffers = new Offer[](_endId - _startId + 1);
for (uint256 i = _startId; i <= _endId; i += 1) {
_allOffers[i - _startId] = data.offers[i];
}
}
/// @dev Returns offers within the specified range, where offeror has sufficient balance.
function getAllValidOffers(uint256 _startId, uint256 _endId) external view returns (Offer[] memory _validOffers) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
require(_startId <= _endId && _endId < data.totalOffers, "invalid range");
Offer[] memory _offers = new Offer[](_endId - _startId + 1);
uint256 _offerCount;
for (uint256 i = _startId; i <= _endId; i += 1) {
uint256 j = i - _startId;
_offers[j] = data.offers[i];
if (_validateExistingOffer(_offers[j])) {
_offerCount += 1;
}
}
_validOffers = new Offer[](_offerCount);
uint256 index = 0;
uint256 count = _offers.length;
for (uint256 i = 0; i < count; i += 1) {
if (_validateExistingOffer(_offers[i])) {
_validOffers[index++] = _offers[i];
}
}
}
/*///////////////////////////////////////////////////////////////
Internal functions
//////////////////////////////////////////////////////////////*/
/// @dev Returns the next offer Id.
function _getNextOfferId() internal returns (uint256 id) {
OffersStorage.Data storage data = OffersStorage.offersStorage();
id = data.totalOffers;
data.totalOffers += 1;
}
/// @dev Returns the interface supported by a contract.
function _getTokenType(address _assetContract) internal view returns (TokenType tokenType) {
if (IERC165(_assetContract).supportsInterface(type(IERC1155).interfaceId)) {
tokenType = TokenType.ERC1155;
} else if (IERC165(_assetContract).supportsInterface(type(IERC721).interfaceId)) {
tokenType = TokenType.ERC721;
} else {
revert("Marketplace: token must be ERC1155 or ERC721.");
}
}
/// @dev Checks whether the auction creator owns and has approved marketplace to transfer auctioned tokens.
function _validateNewOffer(OfferParams memory _params, TokenType _tokenType) internal view {
require(_params.totalPrice > 0, "zero price.");
require(_params.quantity > 0, "Marketplace: wanted zero tokens.");
require(_params.quantity == 1 || _tokenType == TokenType.ERC1155, "Marketplace: wanted invalid quantity.");
require(
_params.expirationTimestamp + 60 minutes > block.timestamp,
"Marketplace: invalid expiration timestamp."
);
require(
_validateERC20BalAndAllowance(_msgSender(), _params.currency, _params.totalPrice),
"Marketplace: insufficient currency balance."
);
}
/// @dev Checks whether the offer exists, is active, and if the offeror has sufficient balance.
function _validateExistingOffer(Offer memory _targetOffer) internal view returns (bool isValid) {
isValid =
_targetOffer.expirationTimestamp > block.timestamp &&
_targetOffer.status == IOffers.Status.CREATED &&
_validateERC20BalAndAllowance(_targetOffer.offeror, _targetOffer.currency, _targetOffer.totalPrice);
}
/// @dev Validates that `_tokenOwner` owns and has approved Marketplace to transfer NFTs.
function _validateOwnershipAndApproval(
address _tokenOwner,
address _assetContract,
uint256 _tokenId,
uint256 _quantity,
TokenType _tokenType
) internal view {
address market = address(this);
bool isValid;
if (_tokenType == TokenType.ERC1155) {
isValid =
IERC1155(_assetContract).balanceOf(_tokenOwner, _tokenId) >= _quantity &&
IERC1155(_assetContract).isApprovedForAll(_tokenOwner, market);
} else if (_tokenType == TokenType.ERC721) {
isValid =
IERC721(_assetContract).ownerOf(_tokenId) == _tokenOwner &&
(IERC721(_assetContract).getApproved(_tokenId) == market ||
IERC721(_assetContract).isApprovedForAll(_tokenOwner, market));
}
require(isValid, "Marketplace: not owner or approved tokens.");
}
/// @dev Validates that `_tokenOwner` owns and has approved Markeplace to transfer the appropriate amount of currency
function _validateERC20BalAndAllowance(
address _tokenOwner,
address _currency,
uint256 _amount
) internal view returns (bool isValid) {
isValid =
IERC20(_currency).balanceOf(_tokenOwner) >= _amount &&
IERC20(_currency).allowance(_tokenOwner, address(this)) >= _amount;
}
/// @dev Transfers tokens.
function _transferOfferTokens(
address _from,
address _to,
uint256 _quantity,
Offer memory _offer
) internal {
if (_offer.tokenType == TokenType.ERC1155) {
IERC1155(_offer.assetContract).safeTransferFrom(_from, _to, _offer.tokenId, _quantity, "");
} else if (_offer.tokenType == TokenType.ERC721) {
IERC721(_offer.assetContract).safeTransferFrom(_from, _to, _offer.tokenId, "");
}
}
/// @dev Pays out stakeholders in a sale.
function _payout(
address _payer,
address _payee,
address _currencyToUse,
uint256 _totalPayoutAmount,
Offer memory _offer
) internal {
(address platformFeeRecipient, uint16 platformFeeBps) = IPlatformFee(address(this)).getPlatformFeeInfo();
if(_currencyToUse == HOC_DIME_ADDRESS)
platformFeeBps = 0;
uint256 platformFeeCut = (_totalPayoutAmount * platformFeeBps) / MAX_BPS;
uint256 royaltyCut;
address royaltyRecipient;
// Distribute royalties. See Sushiswap's https://github.com/sushiswap/shoyu/blob/master/contracts/base/BaseExchange.sol#L296
try IERC2981(_offer.assetContract).royaltyInfo(_offer.tokenId, _totalPayoutAmount) returns (
address royaltyFeeRecipient,
uint256 royaltyFeeAmount
) {
if (royaltyFeeRecipient != address(0) && royaltyFeeAmount > 0) {
require(royaltyFeeAmount + platformFeeCut <= _totalPayoutAmount, "fees exceed the price");
royaltyRecipient = royaltyFeeRecipient;
royaltyCut = royaltyFeeAmount;
}
} catch {}
if(platformFeeCut > 0) {
CurrencyTransferLib.transferCurrencyWithWrapper(
_currencyToUse,
_payer,
platformFeeRecipient,
platformFeeCut,
address(0)
);
}
CurrencyTransferLib.transferCurrencyWithWrapper(
_currencyToUse,
_payer,
royaltyRecipient,
royaltyCut,
address(0)
);
CurrencyTransferLib.transferCurrencyWithWrapper(
_currencyToUse,
_payer,
_payee,
_totalPayoutAmount - (platformFeeCut + royaltyCut),
address(0)
);
}
uint8 constant FILTER_CREATOR = 0x80;
uint8 constant FILTER_ASSET_CONTRACT = 0x40;
uint8 constant FILTER_TOKEN_ID = 0x20;
uint8 constant FILTER_ONLY_CREATED = 0x04;
uint8 constant FILTER_ONLY_COMPLETED = 0x02;
uint8 constant FILTER_ONLY_VALID = 0x01;
function selectOffers(
uint256 _startId,
uint8 _filterFlags,
address _filterCreator,
address _filterAssetContract,
uint256 _filterTokenId,
uint32 _maxScannedItems,
uint32 _maxOutputItems)
external
view
returns (Offer[] memory _offers, uint256 _nextStartId)
{
OffersStorage.Data storage data = OffersStorage.offersStorage();
uint256 totalItems = data.totalOffers;
uint256[] memory matchedItems = new uint256[](_maxOutputItems);
uint32 matchedItemsCount = 0;
while (_startId < totalItems && _maxScannedItems > 0 && _maxOutputItems > 0) {
Offer memory item = data.offers[_startId];
if ((_filterFlags & FILTER_CREATOR) == 0 || item.offeror == _filterCreator) {
if ((_filterFlags & FILTER_ASSET_CONTRACT) == 0 || item.assetContract == _filterAssetContract) {
if ((_filterFlags & FILTER_TOKEN_ID) == 0 || item.tokenId == _filterTokenId) {
if ((_filterFlags & FILTER_ONLY_CREATED) == 0 || item.status == IOffers.Status.CREATED) {
if ((_filterFlags & FILTER_ONLY_COMPLETED) == 0 || item.status == IOffers.Status.COMPLETED) {
if ((_filterFlags & FILTER_ONLY_VALID) == 0 || _validateExistingOffer(item)) {
matchedItems[matchedItemsCount] = _startId;
unchecked { ++matchedItemsCount; --_maxOutputItems; }
}
}
}
}
}
}
unchecked { ++_startId; --_maxScannedItems; }
}
_nextStartId = _startId < totalItems ? _startId : 0;
_offers = new Offer[](matchedItemsCount);
for (uint32 i = 0; i < matchedItemsCount; ) {
_offers[i] = data.offers[matchedItems[i]];
unchecked { ++i; }
}
}
}
@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/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/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/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/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/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);
}
@thirdweb-dev/contracts/eip/interface/IERC20.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
@thirdweb-dev/contracts/extension/interface/IPermissions.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IPermissions {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
@thirdweb-dev/contracts/extension/interface/IPermissionsEnumerable.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./IPermissions.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IPermissionsEnumerable is IPermissions {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* [forum post](https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296)
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
@thirdweb-dev/contracts/extension/interface/IPlatformFee.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* Thirdweb's `PlatformFee` is a contract extension to be used with any base contract. It exposes functions for setting and reading
* the recipient of platform fee and the platform fee basis points, and lets the inheriting contract perform conditional logic
* that uses information about platform fees, if desired.
*/
interface IPlatformFee {
/// @dev Fee type variants: percentage fee and flat fee
enum PlatformFeeType {
Bps,
Flat
}
/// @dev Returns the platform fee bps and recipient.
function getPlatformFeeInfo() external view returns (address, uint16);
/// @dev Lets a module admin update the fees on primary sales.
function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external;
/// @dev Emitted when fee on primary sales is updated.
event PlatformFeeInfoUpdated(address indexed platformFeeRecipient, uint256 platformFeeBps);
/// @dev Emitted when the flat platform fee is updated.
event FlatPlatformFeeUpdated(address platformFeeRecipient, uint256 flatFee);
/// @dev Emitted when the platform fee type is updated.
event PlatformFeeTypeUpdated(PlatformFeeType feeType);
}
@thirdweb-dev/contracts/extension/plugin/ERC2771ContextConsumer.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./ERC2771ContextLogic.sol";
interface IERC2771Context {
function isTrustedForwarder(address forwarder) external view returns (bool);
}
/**
* @dev Context variant with ERC2771 support.
*/
abstract contract ERC2771ContextConsumer {
function _msgSender() public view virtual returns (address sender) {
if (IERC2771Context(address(this)).isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return msg.sender;
}
}
function _msgData() public view virtual returns (bytes calldata) {
if (IERC2771Context(address(this)).isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return msg.data;
}
}
}
@thirdweb-dev/contracts/extension/plugin/ERC2771ContextLogic.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./ERC2771ContextStorage.sol";
/**
* @dev Context variant with ERC2771 support.
*/
abstract contract ERC2771ContextLogic {
constructor(address[] memory trustedForwarder) {
ERC2771ContextStorage.Data storage data = ERC2771ContextStorage.erc2771ContextStorage();
for (uint256 i = 0; i < trustedForwarder.length; i++) {
data._trustedForwarder[trustedForwarder[i]] = true;
}
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
ERC2771ContextStorage.Data storage data = ERC2771ContextStorage.erc2771ContextStorage();
return data._trustedForwarder[forwarder];
}
function _msgSender() internal view virtual returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return msg.sender;
}
}
function _msgData() internal view virtual returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return msg.data;
}
}
}
@thirdweb-dev/contracts/extension/plugin/ERC2771ContextStorage.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
library ERC2771ContextStorage {
bytes32 public constant ERC2771_CONTEXT_STORAGE_POSITION = keccak256("erc2771.context.storage");
struct Data {
mapping(address => bool) _trustedForwarder;
}
function erc2771ContextStorage() internal pure returns (Data storage erc2771ContextData) {
bytes32 position = ERC2771_CONTEXT_STORAGE_POSITION;
assembly {
erc2771ContextData.slot := position
}
}
}
@thirdweb-dev/contracts/extension/plugin/PermissionsEnumerableLogic.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./PermissionsEnumerableStorage.sol";
import "./PermissionsLogic.sol";
/**
* @author thirdweb.com
*
* @title PermissionsEnumerable
* @dev This contracts provides extending-contracts with role-based access control mechanisms.
* Also provides interfaces to view all members with a given role, and total count of members.
*/
contract PermissionsEnumerableLogic is IPermissionsEnumerable, PermissionsLogic {
/**
* @notice Returns the role-member from a list of members for a role,
* at a given index.
* @dev Returns `member` who has `role`, at `index` of role-members list.
* See struct {RoleMembers}, and mapping {roleMembers}
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param index Index in list of current members for the role.
*
* @return member Address of account that has `role`
*/
function getRoleMember(bytes32 role, uint256 index) external view override returns (address member) {
PermissionsEnumerableStorage.Data storage data = PermissionsEnumerableStorage.permissionsEnumerableStorage();
uint256 currentIndex = data.roleMembers[role].index;
uint256 check;
for (uint256 i = 0; i < currentIndex; i += 1) {
if (data.roleMembers[role].members[i] != address(0)) {
if (check == index) {
member = data.roleMembers[role].members[i];
return member;
}
check += 1;
} else if (hasRole(role, address(0)) && i == data.roleMembers[role].indexOf[address(0)]) {
check += 1;
}
}
}
/**
* @notice Returns total number of accounts that have a role.
* @dev Returns `count` of accounts that have `role`.
* See struct {RoleMembers}, and mapping {roleMembers}
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
*
* @return count Total number of accounts that have `role`
*/
function getRoleMemberCount(bytes32 role) external view override returns (uint256 count) {
PermissionsEnumerableStorage.Data storage data = PermissionsEnumerableStorage.permissionsEnumerableStorage();
uint256 currentIndex = data.roleMembers[role].index;
for (uint256 i = 0; i < currentIndex; i += 1) {
if (data.roleMembers[role].members[i] != address(0)) {
count += 1;
}
}
if (hasRole(role, address(0))) {
count += 1;
}
}
/// @dev Revokes `role` from `account`, and removes `account` from {roleMembers}
/// See {_removeMember}
function _revokeRole(bytes32 role, address account) internal override {
super._revokeRole(role, account);
_removeMember(role, account);
}
/// @dev Grants `role` to `account`, and adds `account` to {roleMembers}
/// See {_addMember}
function _setupRole(bytes32 role, address account) internal override {
super._setupRole(role, account);
_addMember(role, account);
}
/// @dev adds `account` to {roleMembers}, for `role`
function _addMember(bytes32 role, address account) internal {
PermissionsEnumerableStorage.Data storage data = PermissionsEnumerableStorage.permissionsEnumerableStorage();
uint256 idx = data.roleMembers[role].index;
data.roleMembers[role].index += 1;
data.roleMembers[role].members[idx] = account;
data.roleMembers[role].indexOf[account] = idx;
}
/// @dev removes `account` from {roleMembers}, for `role`
function _removeMember(bytes32 role, address account) internal {
PermissionsEnumerableStorage.Data storage data = PermissionsEnumerableStorage.permissionsEnumerableStorage();
uint256 idx = data.roleMembers[role].indexOf[account];
delete data.roleMembers[role].members[idx];
delete data.roleMembers[role].indexOf[account];
}
}
@thirdweb-dev/contracts/extension/plugin/PermissionsEnumerableStorage.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "../../extension/interface/IPermissionsEnumerable.sol";
/**
* @author thirdweb.com
*/
library PermissionsEnumerableStorage {
bytes32 public constant PERMISSIONS_ENUMERABLE_STORAGE_POSITION = keccak256("permissions.enumerable.storage");
/**
* @notice A data structure to store data of members for a given role.
*
* @param index Current index in the list of accounts that have a role.
* @param members map from index => address of account that has a role
* @param indexOf map from address => index which the account has.
*/
struct RoleMembers {
uint256 index;
mapping(uint256 => address) members;
mapping(address => uint256) indexOf;
}
struct Data {
/// @dev map from keccak256 hash of a role to its members' data. See {RoleMembers}.
mapping(bytes32 => RoleMembers) roleMembers;
}
function permissionsEnumerableStorage() internal pure returns (Data storage permissionsEnumerableData) {
bytes32 position = PERMISSIONS_ENUMERABLE_STORAGE_POSITION;
assembly {
permissionsEnumerableData.slot := position
}
}
}
@thirdweb-dev/contracts/extension/plugin/PermissionsLogic.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "../../extension/interface/IPermissions.sol";
import "./PermissionsStorage.sol";
import "../../lib/TWStrings.sol";
/**
* @author thirdweb.com
*
* @title Permissions
* @dev This contracts provides extending-contracts with role-based access control mechanisms
*/
contract PermissionsLogic is IPermissions {
/// @dev Default admin role for all roles. Only accounts with this role can grant/revoke other roles.
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/// @dev Modifier that checks if an account has the specified role; reverts otherwise.
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @notice Checks whether an account has a particular role.
* @dev Returns `true` if `account` has been granted `role`.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param account Address of the account for which the role is being checked.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
return data._hasRole[role][account];
}
/**
* @notice Checks whether an account has a particular role;
* role restrictions can be swtiched on and off.
*
* @dev Returns `true` if `account` has been granted `role`.
* Role restrictions can be swtiched on and off:
* - If address(0) has ROLE, then the ROLE restrictions
* don't apply.
* - If address(0) does not have ROLE, then the ROLE
* restrictions will apply.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param account Address of the account for which the role is being checked.
*/
function hasRoleWithSwitch(bytes32 role, address account) public view returns (bool) {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
if (!data._hasRole[role][address(0)]) {
return data._hasRole[role][account];
}
return true;
}
/**
* @notice Returns the admin role that controls the specified role.
* @dev See {grantRole} and {revokeRole}.
* To change a role's admin, use {_setRoleAdmin}.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
*/
function getRoleAdmin(bytes32 role) external view override returns (bytes32) {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
return data._getRoleAdmin[role];
}
/**
* @notice Grants a role to an account, if not previously granted.
* @dev Caller must have admin role for the `role`.
* Emits {RoleGranted Event}.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param account Address of the account to which the role is being granted.
*/
function grantRole(bytes32 role, address account) public virtual override {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
_checkRole(data._getRoleAdmin[role], _msgSender());
if (data._hasRole[role][account]) {
revert("Can only grant to non holders");
}
_setupRole(role, account);
}
/**
* @notice Revokes role from an account.
* @dev Caller must have admin role for the `role`.
* Emits {RoleRevoked Event}.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param account Address of the account from which the role is being revoked.
*/
function revokeRole(bytes32 role, address account) public virtual override {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
_checkRole(data._getRoleAdmin[role], _msgSender());
_revokeRole(role, account);
}
/**
* @notice Revokes role from the account.
* @dev Caller must have the `role`, with caller being the same as `account`.
* Emits {RoleRevoked Event}.
*
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
* @param account Address of the account from which the role is being revoked.
*/
function renounceRole(bytes32 role, address account) public virtual override {
if (_msgSender() != account) {
revert("Can only renounce for self");
}
_revokeRole(role, account);
}
/// @dev Sets `adminRole` as `role`'s admin role.
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
bytes32 previousAdminRole = data._getRoleAdmin[role];
data._getRoleAdmin[role] = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/// @dev Sets up `role` for `account`
function _setupRole(bytes32 role, address account) internal virtual {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
data._hasRole[role][account] = true;
emit RoleGranted(role, account, _msgSender());
}
/// @dev Revokes `role` from `account`
function _revokeRole(bytes32 role, address account) internal virtual {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
_checkRole(role, account);
delete data._hasRole[role][account];
emit RoleRevoked(role, account, _msgSender());
}
/// @dev Checks `role` for `account`. Reverts with a message including the required role.
function _checkRole(bytes32 role, address account) internal view virtual {
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
if (!data._hasRole[role][account]) {
revert(
string(
abi.encodePacked(
"Permissions: account ",
TWStrings.toHexString(uint160(account), 20),
" is missing role ",
TWStrings.toHexString(uint256(role), 32)
)
)
);
}
}
/// @dev Checks `role` for `account`. Reverts with a message including the required role.
function _checkRoleWithSwitch(bytes32 role, address account) internal view virtual {
if (!hasRoleWithSwitch(role, account)) {
revert(
string(
abi.encodePacked(
"Permissions: account ",
TWStrings.toHexString(uint160(account), 20),
" is missing role ",
TWStrings.toHexString(uint256(role), 32)
)
)
);
}
}
function _msgSender() internal view virtual returns (address sender) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
@thirdweb-dev/contracts/extension/plugin/PermissionsStorage.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* @author thirdweb.com
*/
library PermissionsStorage {
bytes32 public constant PERMISSIONS_STORAGE_POSITION = keccak256("permissions.storage");
struct Data {
/// @dev Map from keccak256 hash of a role => a map from address => whether address has role.
mapping(bytes32 => mapping(address => bool)) _hasRole;
/// @dev Map from keccak256 hash of a role to role admin. See {getRoleAdmin}.
mapping(bytes32 => bytes32) _getRoleAdmin;
}
function permissionsStorage() internal pure returns (Data storage permissionsData) {
bytes32 position = PERMISSIONS_STORAGE_POSITION;
assembly {
permissionsData.slot := position
}
}
}
@thirdweb-dev/contracts/extension/plugin/ReentrancyGuardLogic.sol
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./ReentrancyGuardStorage.sol";
/**
* @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 ReentrancyGuardLogic {
// 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;
function __ReentrancyGuard_init() internal {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal {
ReentrancyGuardStorage.Data storage data = ReentrancyGuardStorage.reentrancyGuardStorage();
data._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() {
ReentrancyGuardStorage.Data storage data = ReentrancyGuardStorage.reentrancyGuardStorage();
// On the first call to nonReentrant, _notEntered will be true
require(data._status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
data._status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
data._status = _NOT_ENTERED;
}
}
@thirdweb-dev/contracts/extension/plugin/ReentrancyGuardStorage.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
library ReentrancyGuardStorage {
bytes32 public constant REENTRANCY_GUARD_STORAGE_POSITION = keccak256("reentrancy.guard.storage");
struct Data {
uint256 _status;
}
function reentrancyGuardStorage() internal pure returns (Data storage reentrancyGuardData) {
bytes32 position = REENTRANCY_GUARD_STORAGE_POSITION;
assembly {
reentrancyGuardData.slot := position
}
}
}
@thirdweb-dev/contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
interface IWETH {
function deposit() external payable;
function withdraw(uint256 amount) external;
function transfer(address to, uint256 value) external returns (bool);
}
@thirdweb-dev/contracts/lib/CurrencyTransferLib.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
// Helper interfaces
import { IWETH } from "../interfaces/IWETH.sol";
import "../openzeppelin-presets/token/ERC20/utils/SafeERC20.sol";
library CurrencyTransferLib {
using SafeERC20 for IERC20;
/// @dev The address interpreted as native token of the chain.
address public constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/// @dev Transfers a given amount of currency.
function transferCurrency(
address _currency,
address _from,
address _to,
uint256 _amount
) internal {
if (_amount == 0) {
return;
}
if (_currency == NATIVE_TOKEN) {
safeTransferNativeToken(_to, _amount);
} else {
safeTransferERC20(_currency, _from, _to, _amount);
}
}
/// @dev Transfers a given amount of currency. (With native token wrapping)
function transferCurrencyWithWrapper(
address _currency,
address _from,
address _to,
uint256 _amount,
address _nativeTokenWrapper
) internal {
if (_amount == 0) {
return;
}
if (_currency == NATIVE_TOKEN) {
if (_from == address(this)) {
// withdraw from weth then transfer withdrawn native token to recipient
IWETH(_nativeTokenWrapper).withdraw(_amount);
safeTransferNativeTokenWithWrapper(_to, _amount, _nativeTokenWrapper);
} else if (_to == address(this)) {
// store native currency in weth
require(_amount == msg.value, "msg.value != amount");
IWETH(_nativeTokenWrapper).deposit{ value: _amount }();
} else {
safeTransferNativeTokenWithWrapper(_to, _amount, _nativeTokenWrapper);
}
} else {
safeTransferERC20(_currency, _from, _to, _amount);
}
}
/// @dev Transfer `amount` of ERC20 token from `from` to `to`.
function safeTransferERC20(
address _currency,
address _from,
address _to,
uint256 _amount
) internal {
if (_from == _to) {
return;
}
if (_from == address(this)) {
IERC20(_currency).safeTransfer(_to, _amount);
} else {
IERC20(_currency).safeTransferFrom(_from, _to, _amount);
}
}
/// @dev Transfers `amount` of native token to `to`.
function safeTransferNativeToken(address to, uint256 value) internal {
// solhint-disable avoid-low-level-calls
// slither-disable-next-line low-level-calls
(bool success, ) = to.call{ value: value }("");
require(success, "native token transfer failed");
}
/// @dev Transfers `amount` of native token to `to`. (With native token wrapping)
function safeTransferNativeTokenWithWrapper(
address to,
uint256 value,
address _nativeTokenWrapper
) internal {
// solhint-disable avoid-low-level-calls
// slither-disable-next-line low-level-calls
(bool success, ) = to.call{ value: value }("");
if (!success) {
IWETH(_nativeTokenWrapper).deposit{ value: value }();
IERC20(_nativeTokenWrapper).safeTransfer(to, value);
}
}
}
@thirdweb-dev/contracts/lib/TWAddress.sol
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* @dev Collection of functions related to the address type
*/
library TWAddress {
/**
* @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
* ====
*
* [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.
*
* [EIP1884](https://eips.ethereum.org/EIPS/eip-1884) 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return verifyCallResult(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) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(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) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason 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 {
// 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
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
@thirdweb-dev/contracts/lib/TWStrings.sol
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* @dev String operations.
*/
library TWStrings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @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] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
@thirdweb-dev/contracts/openzeppelin-presets/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../../../../eip/interface/IERC20.sol";
import "../../../../lib/TWAddress.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 TWAddress for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
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");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @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");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contracts/Constants.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.11;
contract Constants {
address internal constant HOC_DIME_ADDRESS = 0x716992D45Bc60E9Ead5f59206c0d049afbFf429F; // TODO: Mainnet
}
contracts/marketplace/IMarketplace.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;
/// @author thirdweb
/**
* @author thirdweb.com
*
* The `DirectListings` extension smart contract lets you buy and sell NFTs (ERC-721 or ERC-1155) for a fixed price.
*/
interface IDirectListings {
enum TokenType {
ERC721,
ERC1155
}
enum Status {
UNSET,
CREATED,
COMPLETED,
CANCELLED
}
/**
* @notice The parameters a seller sets when creating or updating a listing.
*
* @param assetContract The address of the smart contract of the NFTs being listed.
* @param tokenId The tokenId of the NFTs being listed.
* @param quantity The quantity of NFTs being listed. This must be non-zero, and is expected to
* be `1` for ERC-721 NFTs.
* @param currency The currency in which the price must be paid when buying the listed NFTs.
* @param pricePerToken The price to pay per unit of NFTs listed.
* @param startTimestamp The UNIX timestamp at and after which NFTs can be bought from the listing.
* @param endTimestamp The UNIX timestamp at and after which NFTs cannot be bought from the listing.
* @param reserved Whether the listing is reserved to be bought from a specific set of buyers.
*/
struct ListingParameters {
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 pricePerToken;
uint128 startTimestamp;
uint128 endTimestamp;
bool reserved;
}
/**
* @notice The information stored for a listing.
*
* @param listingId The unique ID of the listing.
* @param listingCreator The creator of the listing.
* @param assetContract The address of the smart contract of the NFTs being listed.
* @param tokenId The tokenId of the NFTs being listed.
* @param quantity The quantity of NFTs being listed. This must be non-zero, and is expected to
* be `1` for ERC-721 NFTs.
* @param currency The currency in which the price must be paid when buying the listed NFTs.
* @param pricePerToken The price to pay per unit of NFTs listed.
* @param startTimestamp The UNIX timestamp at and after which NFTs can be bought from the listing.
* @param endTimestamp The UNIX timestamp at and after which NFTs cannot be bought from the listing.
* @param reserved Whether the listing is reserved to be bought from a specific set of buyers.
* @param tokenType The type of token listed (ERC-721 or ERC-1155)
*/
struct Listing {
uint256 listingId;
address listingCreator;
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 pricePerToken;
uint128 startTimestamp;
uint128 endTimestamp;
bool reserved;
TokenType tokenType;
Status status;
}
/// @notice Emitted when a new listing is created.
event NewListing(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId,
Listing listing
);
/// @notice Emitted when a listing is updated.
event UpdatedListing(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId,
Listing listing
);
/// @notice Emitted when a listing is cancelled.
event CancelledListing(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId
);
/// @notice Emitted when a buyer is approved to buy from a reserved listing.
event BuyerApprovedForListing(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId,
address buyer,
bool approved
);
/// @notice Emitted when a currency is approved as a form of payment for the listing.
event CurrencyApprovedForListing(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId,
uint256 pricePerToken,
address currency
);
/// @notice Emitted when NFTs are bought from a listing.
event NewSale(
address indexed listingCreator,
uint256 listingId,
address indexed assetContract,
uint256 indexed tokenId,
address buyer,
uint256 quantityBought,
uint256 totalPricePaid,
address currency
);
/**
* @notice List NFTs (ERC721 or ERC1155) for sale at a fixed price.
*
* @param _params The parameters of a listing a seller sets when creating a listing.
*
* @return listingId The unique integer ID of the listing.
*/
function createListing(ListingParameters memory _params) external returns (uint256 listingId);
/**
* @notice Update parameters of a listing of NFTs.
*
* @param _listingId The ID of the listing to update.
* @param _params The parameters of a listing a seller sets when updating a listing.
*/
function updateListing(uint256 _listingId, ListingParameters memory _params) external;
/**
* @notice Cancel a listing.
*
* @param _listingId The ID of the listing to cancel.
*/
function cancelListing(uint256 _listingId) external;
/**
* @notice Approve a buyer to buy from a reserved listing.
*
* @param _listingId The ID of the listing to update.
* @param _buyer The address of the buyer to approve to buy from the listing.
* @param _toApprove Whether to approve the buyer to buy from the listing.
*/
function approveBuyerForListing(
uint256 _listingId,
address _buyer,
bool _toApprove
) external;
/**
* @notice Approve a currency as a form of payment for the listing.
*
* @param _listingId The ID of the listing to update.
* @param _currency The address of the currency to approve as a form of payment for the listing.
* @param _pricePerTokenInCurrency The price per token for the currency to approve.
*/
function approveCurrencyForListing(
uint256 _listingId,
address _currency,
uint256 _pricePerTokenInCurrency
) external;
/**
* @notice Buy NFTs from a listing.
*
* @param _listingId The ID of the listing to update.
* @param _buyFor The recipient of the NFTs being bought.
* @param _quantity The quantity of NFTs to buy from the listing.
* @param _currency The currency to use to pay for NFTs.
* @param _expectedTotalPrice The expected total price to pay for the NFTs being bought.
*/
function buyFromListing(
uint256 _listingId,
address _buyFor,
uint256 _quantity,
address _currency,
uint256 _expectedTotalPrice
) external payable;
/**
* @notice Returns the total number of listings created.
* @dev At any point, the return value is the ID of the next listing created.
*/
function totalListings() external view returns (uint256);
/// @notice Returns all listings between the start and end Id (both inclusive) provided.
function getAllListings(uint256 _startId, uint256 _endId) external view returns (Listing[] memory listings);
/**
* @notice Returns all valid listings between the start and end Id (both inclusive) provided.
* A valid listing is where the listing creator still owns and has approved Marketplace
* to transfer the listed NFTs.
*/
function getAllValidListings(uint256 _startId, uint256 _endId) external view returns (Listing[] memory listings);
/**
* @notice Returns a listing at the provided listing ID.
*
* @param _listingId The ID of the listing to fetch.
*/
function getListing(uint256 _listingId) external view returns (Listing memory listing);
}
/**
* The `EnglishAuctions` extension smart contract lets you sell NFTs (ERC-721 or ERC-1155) in an english auction.
*/
interface IEnglishAuctions {
enum TokenType {
ERC721,
ERC1155
}
enum Status {
UNSET,
CREATED,
COMPLETED,
CANCELLED
}
/**
* @notice The parameters a seller sets when creating an auction listing.
*
* @param assetContract The address of the smart contract of the NFTs being auctioned.
* @param tokenId The tokenId of the NFTs being auctioned.
* @param quantity The quantity of NFTs being auctioned. This must be non-zero, and is expected to
* be `1` for ERC-721 NFTs.
* @param currency The currency in which the bid must be made when bidding for the auctioned NFTs.
* @param minimumBidAmount The minimum bid amount for the auction.
* @param buyoutBidAmount The total bid amount for which the bidder can directly purchase the auctioned items and close the auction as a result.
* @param timeBufferInSeconds This is a buffer e.g. x seconds. If a new winning bid is made less than x seconds before expirationTimestamp, the
* expirationTimestamp is increased by x seconds.
* @param bidBufferBps This is a buffer in basis points e.g. x%. To be considered as a new winning bid, a bid must be at least x% greater than
* the current winning bid.
* @param startTimestamp The timestamp at and after which bids can be made to the auction
* @param endTimestamp The timestamp at and after which bids cannot be made to the auction.
*/
struct AuctionParameters {
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 minimumBidAmount;
uint256 buyoutBidAmount;
uint64 timeBufferInSeconds;
uint64 bidBufferBps;
uint64 startTimestamp;
uint64 endTimestamp;
}
/**
* @notice The information stored for an auction.
*
* @param auctionId The unique ID of the auction.
* @param auctionCreator The creator of the auction.
* @param assetContract The address of the smart contract of the NFTs being auctioned.
* @param tokenId The tokenId of the NFTs being auctioned.
* @param quantity The quantity of NFTs being auctioned. This must be non-zero, and is expected to
* be `1` for ERC-721 NFTs.
* @param currency The currency in which the bid must be made when bidding for the auctioned NFTs.
* @param minimumBidAmount The minimum bid amount for the auction.
* @param buyoutBidAmount The total bid amount for which the bidder can directly purchase the auctioned items and close the auction as a result.
* @param timeBufferInSeconds This is a buffer e.g. x seconds. If a new winning bid is made less than x seconds before expirationTimestamp, the
* expirationTimestamp is increased by x seconds.
* @param bidBufferBps This is a buffer in basis points e.g. x%. To be considered as a new winning bid, a bid must be at least x% greater than
* the current winning bid.
* @param startTimestamp The timestamp at and after which bids can be made to the auction
* @param endTimestamp The timestamp at and after which bids cannot be made to the auction.
* @param tokenType The type of NFTs auctioned (ERC-721 or ERC-1155)
*/
struct Auction {
uint256 auctionId;
address auctionCreator;
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 minimumBidAmount;
uint256 buyoutBidAmount;
uint64 timeBufferInSeconds;
uint64 bidBufferBps;
uint64 startTimestamp;
uint64 endTimestamp;
TokenType tokenType;
Status status;
}
/**
* @notice The information stored for a bid made in an auction.
*
* @param auctionId The unique ID of the auction.
* @param bidder The address of the bidder.
* @param bidAmount The total bid amount (in the currency specified by the auction).
*/
struct Bid {
uint256 auctionId;
address bidder;
uint256 bidAmount;
}
struct AuctionPayoutStatus {
bool paidOutAuctionTokens;
bool paidOutBidAmount;
}
/// @dev Emitted when a new auction is created.
event NewAuction(
address indexed auctionCreator,
uint256 auctionId,
address indexed assetContract,
uint256 indexed tokenId,
Auction auction
);
/// @dev Emitted when a new bid is made in an auction.
event NewBid(
address indexed bidder,
uint256 auctionId,
address indexed assetContract,
uint256 indexed tokenId,
uint256 bidAmount,
Auction auction
);
/// @notice Emitted when a auction is cancelled.
event CancelledAuction(
address indexed auctionCreator,
uint256 auctionId,
address indexed assetContract,
uint256 indexed tokenId
);
/// @dev Emitted when an auction is closed.
event AuctionClosed(
address indexed winningBidder,
uint256 auctionId,
address indexed assetContract,
uint256 indexed tokenId,
address closer,
uint256 winningAmount,
address currency
);
/**
* @notice Put up NFTs (ERC721 or ERC1155) for an english auction.
*
* @param _params The parameters of an auction a seller sets when creating an auction.
*
* @return auctionId The unique integer ID of the auction.
*/
function createAuction(AuctionParameters memory _params) external returns (uint256 auctionId);
/**
* @notice Cancel an auction.
*
* @param _auctionId The ID of the auction to cancel.
*/
function cancelAuction(uint256 _auctionId) external;
/**
* @notice Distribute the winning bid amount to the auction creator.
*
* @param _auctionId The ID of an auction.
*/
function collectAuctionPayout(uint256 _auctionId) external;
/**
* @notice Distribute the auctioned NFTs to the winning bidder.
*
* @param _auctionId The ID of an auction.
*/
function collectAuctionTokens(uint256 _auctionId) external;
/**
* @notice Bid in an active auction.
*
* @param _auctionId The ID of the auction to bid in.
* @param _bidAmount The bid amount in the currency specified by the auction.
*/
function bidInAuction(uint256 _auctionId, uint256 _bidAmount) external payable;
/**
* @notice Returns whether a given bid amount would make for a winning bid in an auction.
*
* @param _auctionId The ID of an auction.
* @param _bidAmount The bid amount to check.
*/
function isNewWinningBid(uint256 _auctionId, uint256 _bidAmount) external view returns (bool);
/// @notice Returns the auction of the provided auction ID.
function getAuction(uint256 _auctionId) external view returns (Auction memory auction);
/// @notice Returns all non-cancelled auctions.
function getAllAuctions(uint256 _startId, uint256 _endId) external view returns (Auction[] memory auctions);
/// @notice Returns all active auctions.
function getAllValidAuctions(uint256 _startId, uint256 _endId) external view returns (Auction[] memory auctions);
/// @notice Returns the winning bid of an active auction.
function getWinningBid(uint256 _auctionId)
external
view
returns (
address bidder,
address currency,
uint256 bidAmount
);
/// @notice Returns whether an auction is active.
function isAuctionExpired(uint256 _auctionId) external view returns (bool);
}
/**
* The `Offers` extension smart contract lets you make and accept offers made for NFTs (ERC-721 or ERC-1155).
*/
interface IOffers {
enum TokenType {
ERC721,
ERC1155,
ERC20
}
enum Status {
UNSET,
CREATED,
COMPLETED,
CANCELLED
}
/**
* @notice The parameters an offeror sets when making an offer for NFTs.
*
* @param assetContract The contract of the NFTs for which the offer is being made.
* @param tokenId The tokenId of the NFT for which the offer is being made.
* @param quantity The quantity of NFTs wanted.
* @param currency The currency offered for the NFTs.
* @param totalPrice The total offer amount for the NFTs.
* @param expirationTimestamp The timestamp at and after which the offer cannot be accepted.
*/
struct OfferParams {
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 totalPrice;
uint256 expirationTimestamp;
}
/**
* @notice The information stored for the offer made.
*
* @param offerId The ID of the offer.
* @param offeror The address of the offeror.
* @param assetContract The contract of the NFTs for which the offer is being made.
* @param tokenId The tokenId of the NFT for which the offer is being made.
* @param quantity The quantity of NFTs wanted.
* @param currency The currency offered for the NFTs.
* @param totalPrice The total offer amount for the NFTs.
* @param expirationTimestamp The timestamp at and after which the offer cannot be accepted.
* @param tokenType The type of token (ERC-721 or ERC-1155) the offer is made for.
*/
struct Offer {
uint256 offerId;
address offeror;
address assetContract;
uint256 tokenId;
uint256 quantity;
address currency;
uint256 totalPrice;
uint256 expirationTimestamp;
TokenType tokenType;
Status status;
}
/// @dev Emitted when a new offer is created.
event NewOffer(
address indexed offeror,
uint256 offerId,
address indexed assetContract,
uint256 indexed tokenId,
Offer offer
);
/// @dev Emitted when an offer is cancelled.
event CancelledOffer(
address indexed offeror,
uint256 offerId,
address indexed assetContract,
uint256 indexed tokenId
);
/// @dev Emitted when an offer is accepted.
event AcceptedOffer(
address indexed offeror,
uint256 offerId,
address indexed assetContract,
uint256 indexed tokenId,
address seller,
uint256 quantityBought,
uint256 totalPricePaid,
address currency
);
/**
* @notice Make an offer for NFTs (ERC-721 or ERC-1155)
*
* @param _params The parameters of an offer.
*
* @return offerId The unique integer ID assigned to the offer.
*/
function makeOffer(OfferParams memory _params) external returns (uint256 offerId);
/**
* @notice Cancel an offer.
*
* @param _offerId The ID of the offer to cancel.
*/
function cancelOffer(uint256 _offerId) external;
/**
* @notice Accept an offer.
*
* @param _offerId The ID of the offer to accept.
*/
function acceptOffer(uint256 _offerId) external;
/// @notice Returns an offer for the given offer ID.
function getOffer(uint256 _offerId) external view returns (Offer memory offer);
/// @notice Returns all active (i.e. non-expired or cancelled) offers.
function getAllOffers(uint256 _startId, uint256 _endId) external view returns (Offer[] memory offers);
/// @notice Returns all valid offers. An offer is valid if the offeror owns and has approved Marketplace to transfer the offer amount of currency.
function getAllValidOffers(uint256 _startId, uint256 _endId) external view returns (Offer[] memory offers);
}
contracts/marketplace/offers/OffersStorage.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;
/// @author thirdweb
import { IOffers } from "../IMarketplace.sol";
/**
* @author thirdweb.com
*/
library OffersStorage {
bytes32 public constant OFFERS_STORAGE_POSITION = keccak256("offers.storage");
struct Data {
uint256 totalOffers;
mapping(uint256 => IOffers.Offer) offers;
}
function offersStorage() internal pure returns (Data storage offersData) {
bytes32 position = OFFERS_STORAGE_POSITION;
assembly {
offersData.slot := position
}
}
}
Compiler Settings
{"viaIR":true,"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":1000,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes","name":"","internalType":"bytes"}],"name":"_msgData","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"sender","internalType":"address"}],"name":"_msgSender","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOffer","inputs":[{"type":"uint256","name":"_offerId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelOffer","inputs":[{"type":"uint256","name":"_offerId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"_allOffers","internalType":"struct IOffers.Offer[]","components":[{"type":"uint256"},{"type":"address"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"uint8"},{"type":"uint8"}]}],"name":"getAllOffers","inputs":[{"type":"uint256","name":"_startId","internalType":"uint256"},{"type":"uint256","name":"_endId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"_validOffers","internalType":"struct IOffers.Offer[]","components":[{"type":"uint256"},{"type":"address"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"uint8"},{"type":"uint8"}]}],"name":"getAllValidOffers","inputs":[{"type":"uint256","name":"_startId","internalType":"uint256"},{"type":"uint256","name":"_endId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"_offer","internalType":"struct IOffers.Offer","components":[{"type":"uint256"},{"type":"address"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"uint8"},{"type":"uint8"}]}],"name":"getOffer","inputs":[{"type":"uint256","name":"_offerId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"_offerId","internalType":"uint256"}],"name":"makeOffer","inputs":[{"type":"tuple","name":"_params","internalType":"struct IOffers.OfferParams","components":[{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"_offers","internalType":"struct IOffers.Offer[]","components":[{"type":"uint256"},{"type":"address"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"uint8"},{"type":"uint8"}]},{"type":"uint256","name":"_nextStartId","internalType":"uint256"}],"name":"selectOffers","inputs":[{"type":"uint256","name":"_startId","internalType":"uint256"},{"type":"uint8","name":"_filterFlags","internalType":"uint8"},{"type":"address","name":"_filterCreator","internalType":"address"},{"type":"address","name":"_filterAssetContract","internalType":"address"},{"type":"uint256","name":"_filterTokenId","internalType":"uint256"},{"type":"uint32","name":"_maxScannedItems","internalType":"uint32"},{"type":"uint32","name":"_maxOutputItems","internalType":"uint32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalOffers","inputs":[]},{"type":"event","name":"AcceptedOffer","inputs":[{"type":"address","name":"offeror","indexed":true},{"type":"uint256","name":"offerId","indexed":false},{"type":"address","name":"assetContract","indexed":true},{"type":"uint256","name":"tokenId","indexed":true},{"type":"address","name":"seller","indexed":false},{"type":"uint256","name":"quantityBought","indexed":false},{"type":"uint256","name":"totalPricePaid","indexed":false},{"type":"address","name":"currency","indexed":false}],"anonymous":false},{"type":"event","name":"CancelledOffer","inputs":[{"type":"address","name":"offeror","indexed":true},{"type":"uint256","name":"offerId","indexed":false},{"type":"address","name":"assetContract","indexed":true},{"type":"uint256","name":"tokenId","indexed":true}],"anonymous":false},{"type":"event","name":"NewOffer","inputs":[{"type":"address","name":"offeror","indexed":true},{"type":"uint256","name":"offerId","indexed":false},{"type":"address","name":"assetContract","indexed":true},{"type":"uint256","name":"tokenId","indexed":true},{"type":"tuple","name":"offer","indexed":false,"components":[{"type":"uint256"},{"type":"address"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"address"},{"type":"uint256"},{"type":"uint256"},{"type":"uint8"},{"type":"uint8"}]}],"anonymous":false}]
Contract Creation Code
0x6080806040523461001657612828908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8063016767fa146100b7578063119df25f146100b257806316a29807146100ad5780634579268a146100a85780638b49d47e146100a357806391940b3e1461009e578063a9fd8ed114610099578063c1edcfbe14610094578063c815729d1461008f5763ef706adf1461008a57600080fd5b6109ae565b6106fa565b610621565b6105e4565b610471565b610416565b6103c5565b610354565b6101d9565b3461012a5760c036600319011261012a576100d3610140604052565b6004356100df816101bd565b60805260243560a05260443560c0526064356100fa816101bd565b60e0526084356101005260a43561012052610126610116610b99565b6040519081529081906020820190565b0390f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161015957604052565b61012f565b6040810190811067ffffffffffffffff82111761015957604052565b90601f8019910116810190811067ffffffffffffffff82111761015957604052565b60405190610140820182811067ffffffffffffffff82111761015957604052565b6001600160a01b0381160361012a57565b600091031261012a57565b3461012a57600036600319011261012a5760206101f4610a99565b6001600160a01b0360405191168152f35b60c4359063ffffffff8216820361012a57565b634e487b7160e01b600052602160045260246000fd5b6003111561023857565b610218565b9060038210156102385752565b6004111561023857565b9060048210156102385752565b805182526020808201516001600160a01b0316908301526102f491906040818101516001600160a01b03169083015260608101516060830152608081015160808301526102be60a082015160a08401906001600160a01b03169052565b60c081015160c083015260e081015160e08301526102e5610100808301519084019061023d565b61012080910151910190610254565b565b90815180825260208080930193019160005b828110610316575050505090565b90919293826101408261032c6001948951610261565b01950193929101610308565b92919061034f6020916040865260408601906102f6565b930152565b3461012a5760e036600319011261012a5760243560ff8116810361012a5760443561037e816101bd565b6064359161038b836101bd565b60a4359063ffffffff8216820361012a576103b5936103a8610205565b9360843592600435612570565b9061012660405192839283610338565b3461012a57602036600319011261012a576103de6111ad565b506004356000526000805160206127d38339815191526020526101406104076040600020610f9f565b6104146040518092610261565bf35b3461012a57600036600319011261012a576040610431610b30565b919082825193849260208452816020850152848401376000828201840152601f01601f19168101030190f35b90602061046e9281815201906102f6565b90565b3461012a57604036600319011261012a5760243560043581811115806105ba575b61049b9061120b565b6104b56104b06104ab8385610b23565b611256565b611298565b90600090805b8481111561053d57836104cd84611298565b81516000805b8281106104e85760405180610126868261045d565b806104ff6104f961050893886112e8565b516116c6565b61050d57611256565b6104d3565b61053761051a82886112e8565b519361052581611312565b9461053082896112e8565b52866112e8565b50611256565b6105926104f961054d8484610b23565b610576610571856000526000805160206127d3833981519152602052604060002090565b610f9f565b61058082896112e8565b5261058b81886112e8565b50866112e8565b6105a5575b6105a090611256565b6104bb565b916105b26105a091611256565b929050610597565b507fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9548210610492565b3461012a57600036600319011261012a5760207fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca954604051908152f35b3461012a5760408060031936011261012a576004356024359182821115806106d0575b61064d9061120b565b8183038381116106cb576001908181018091116106cb5761066d90611298565b92805b8581111561068557835180610126878261045d565b6106be8460008381526000805160206127d3833981519152602052206106b46106ae8585610b23565b91610f9f565b61053082896112e8565b5082810180911115610670575b610b0d565b507fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9548310610644565b3461012a57602036600319011261012a576004357fbbf78d3411d42a81effd97bb8c69faae4e77e75cec462245c1001191a0634c6f600281541461096a5760029055806000526000805160206127d383398151915260205260ff60086040600020015460081c1660048110156102385760011461077690610f54565b610797816000526000805160206127d3833981519152602052604060002090565b6107a090610f9f565b60e081015142106107b0906110f1565b602081019182516107c7906001600160a01b031690565b60a083019384516107de906001600160a01b031690565b9160c08501928351906107f092611a8d565b6107f99061113c565b610801610a99565b9060408501908151610819906001600160a01b031690565b94606087019384519660808901978851906101008b01519261083a8461022e565b610843946117b3565b610864906000526000805160206127d3833981519152602052604060002090565b600801805461ff00191661020017905580516001600160a01b031686610888610a99565b89516001600160a01b031687519161089f94611ddd565b6108a7610a99565b815187906001600160a01b03168751906108c093611b9a565b516001600160a01b0316945190516001600160a01b03169151956108e2610a99565b945193519051604080519384526001600160a01b03968716602085015283019490945260608201529183166080830152821692909116907f31ee722dd5481cc30d4c84372f2191d02befbafed3a623224f133e60fe67bd419060a090a461096860017fbbf78d3411d42a81effd97bb8c69faae4e77e75cec462245c1001191a0634c6f55565b005b606460405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b3461012a57602036600319011261012a576004356000908082526000805160206127d38339815191528060205260ff600860408520015460081c1660048110156102385760016109fe9114610f54565b8183526020526001600160a01b038060016040852001541690610a1f610a99565b1603610a3157610a2e90611071565b80f35b606460405162461bcd60e51b815260206004820152600860248201527f214f666665726f720000000000000000000000000000000000000000000000006044820152fd5b9081602091031261012a5751801515810361012a5790565b6040513d6000823e3d90fd5b60405163572b6c0560e01b8152336004820152602081602481305afa908115610b0857600091610ada575b5015610ad65736601319013560601c90565b3390565b610afb915060203d8111610b01575b610af3818361017a565b810190610a75565b38610ac4565b503d610ae9565b610a8d565b634e487b7160e01b600052601160045260246000fd5b919082039182116106cb57565b60405163572b6c0560e01b8152336004820152602081602481305afa908115610b0857600091610b7b575b5015610b74576013193601903682116106cb5760009190565b6000903690565b610b93915060203d8111610b0157610af3818361017a565b38610b5b565b6001600160a01b0360805116604051907fa32fa5b30000000000000000000000000000000000000000000000000000000082527f86d5cf0a6bdc8d859ba3bdc97043337c82a0e609035f378e419298b6a3e00ae660048301526024820152602081604481305afa908115610b0857600091610c61575b5015610c1d5761046e610e0f565b606460405162461bcd60e51b815260206004820152600b60248201527f2141535345545f524f4c450000000000000000000000000000000000000000006044820152fd5b610c79915060203d8111610b0157610af3818361017a565b38610c0f565b60038210156102385752565b60048210156102385752565b9060038110156102385760ff80198354169116179055565b9060048110156102385761ff0082549160081b169061ff001916179055565b9061012060086102f49383518155610d1f610cf360208601516001600160a01b031690565b60018301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b610d62610d3660408601516001600160a01b031690565b60028301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b6060840151600382015560808401516004820155610db9610d8d60a08601516001600160a01b031690565b60058301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b60c0840151600682015560e084015160078201550191610de7610100820151610de18161022e565b84610c97565b015190610df38261024a565b610caf565b908152610160810192916102f49160200190610261565b610e17611321565b90610e20610a99565b6080516001600160a01b0316610e3590611355565b90610e3f826115f9565b6080516001600160a01b03169160a0519060c0519160e051610e67906001600160a01b031690565b906101009182519061012095865193610e7e61019c565b8c81526001600160a01b038a166020820152996001600160a01b031660408b015260608a015260808901526001600160a01b031660a088015260c087015260e0860152840190610ecd91610c7f565b60019083015281610ef5856000526000805160206127d3833981519152602052604060002090565b90610eff91610cce565b6080516001600160a01b03169160a0519260405180916001600160a01b03809116941692610f2e908883610df8565b037fe5f7d2ca9b939cd61d1b80107f4733d6552e26d08e899e8b27d99b4bb01466da91a4565b15610f5b57565b606460405162461bcd60e51b815260206004820152601b60248201527f4d61726b6574706c6163653a20696e76616c6964206f666665722e00000000006044820152fd5b906102f460ff6008610faf61019c565b9480548652610fdb610fcb60018301546001600160a01b031690565b6001600160a01b03166020880152565b611002610ff260028301546001600160a01b031690565b6001600160a01b03166040880152565b600381015460608701526004810154608087015261103d61102d60058301546001600160a01b031690565b6001600160a01b031660a0880152565b600681015460c0870152600781015460e087015201546110638282166101008701610c7f565b60081c166101208401610c8b565b806000526000805160206127d38339815191526020526110a560406000206008810161030061ff0019825416179055610f9f565b6110ad610a99565b917f656fae5ac58099f1303c3dd53bbc9e4b0f000700d538d81ef7f5716ab1a34b9060206001600160a01b03606081604087015116950151956040519485521692a4565b156110f857565b606460405162461bcd60e51b815260206004820152600760248201527f45585049524544000000000000000000000000000000000000000000000000006044820152fd5b1561114357565b608460405162461bcd60e51b815260206004820152602b60248201527f4d61726b6574706c6163653a20696e73756666696369656e742063757272656e60448201527f63792062616c616e63652e0000000000000000000000000000000000000000006064820152fd5b60405190610140820182811067ffffffffffffffff82111761015957604052816101206000918281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e0820152826101008201520152565b1561121257565b606460405162461bcd60e51b815260206004820152600d60248201527f696e76616c69642072616e6765000000000000000000000000000000000000006044820152fd5b90600182018092116106cb57565b90610e1082018092116106cb57565b919082018092116106cb57565b67ffffffffffffffff81116101595760051b60200190565b906112a282611280565b6112af604051918261017a565b82815280926112c0601f1991611280565b019060005b8281106112d157505050565b6020906112dc6111ad565b828285010152016112c5565b80518210156112fc5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b60001981146106cb5760010190565b7fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca99081549160018301908184116106cb5755565b6040517f01ffc9a7000000000000000000000000000000000000000000000000000000008082527fd9b67a260000000000000000000000000000000000000000000000000000000060048301526020926001600160a01b0316918381602481865afa908115610b08576000916114af575b50156113d457505050600190565b6040519081527f80ac58cd000000000000000000000000000000000000000000000000000000006004820152908290829060249082905afa918215610b0857600092611492575b50501561142757600090565b60405162461bcd60e51b815260206004820152602d60248201527f4d61726b6574706c6163653a20746f6b656e206d75737420626520455243313160448201527f3535206f72204552433732312e000000000000000000000000000000000000006064820152608490fd5b6114a89250803d10610b0157610af3818361017a565b388061141b565b6114c69150843d8611610b0157610af3818361017a565b386113c6565b156114d357565b606460405162461bcd60e51b815260206004820152602060248201527f4d61726b6574706c6163653a2077616e746564207a65726f20746f6b656e732e6044820152fd5b1561151e57565b608460405162461bcd60e51b815260206004820152602560248201527f4d61726b6574706c6163653a2077616e74656420696e76616c6964207175616e60448201527f746974792e0000000000000000000000000000000000000000000000000000006064820152fd5b1561158f57565b608460405162461bcd60e51b815260206004820152602a60248201527f4d61726b6574706c6163653a20696e76616c69642065787069726174696f6e2060448201527f74696d657374616d702e000000000000000000000000000000000000000000006064820152fd5b61010090815115611682576102f4916116306116699261161c60c05115156114cc565b600160c0511490811561166e575b50611517565b61164661163f61012051611264565b4210611588565b61164e610a99565b9061166160e0516001600160a01b031690565b905191611a8d565b61113c565b6001915061167b8161022e565b143861162a565b606460405162461bcd60e51b815260206004820152600b60248201527f7a65726f2070726963652e0000000000000000000000000000000000000000006044820152fd5b60e081015142109081611704575b816116dd575090565b61046e91506001600160a01b039060c0826020830151169260a08301511691015191611a8d565b9050610120810151600481101561023857600114906116d4565b9081602091031261012a575161046e816101bd565b9081602091031261012a575190565b1561174957565b608460405162461bcd60e51b815260206004820152602a60248201527f4d61726b6574706c6163653a206e6f74206f776e6572206f7220617070726f7660448201527f656420746f6b656e732e000000000000000000000000000000000000000000006064820152fd5b9291936000906117c28161022e565b600181036118d75750506040517efdd58e0000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301526024820195909552931692602091908281604481885afa908115610b08576000916118aa575b501015918261183d575b50506102f49150611742565b60405163e985e9c560e01b81526001600160a01b0391909116600482015230602482015290929091508290829060449082905afa908115610b08576102f49260009261188d575b50503880611831565b6118a39250803d10610b0157610af3818361017a565b3880611884565b6118ca9150833d85116118d0575b6118c2818361017a565b810190611733565b38611827565b503d6118b8565b9093919492506118e68161022e565b156118f75750506102f49150611742565b6040517f6352211e000000000000000000000000000000000000000000000000000000008152600481018390526001600160a01b03948516949293919260209182816024818a5afa908115610b08578491611a70575b50811684821614948561196c575b50505050506102f491503880611831565b6040517f081812fc0000000000000000000000000000000000000000000000000000000081526004810191909152939450919290918282602481895afa918215610b08578492611a41575b501630149283156119d5575b5050506102f49150388080808061195b565b60405163e985e9c560e01b81526001600160a01b0391909116600482015230602482015291939092508290829060449082905afa918215610b08576102f49392611a24575b50503880806119c3565b611a3a9250803d10610b0157610af3818361017a565b3880611a1a565b611a62919250833d8511611a69575b611a5a818361017a565b81019061171e565b90386119b7565b503d611a50565b611a879150833d8511611a6957611a5a818361017a565b3861194d565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038281166004830152929092169290916020908181602481885afa8015610b08578391600091611b7d575b5010159283611af7575b505050905090565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081526001600160a01b0391909116600482015230602482015291939092508290829060449082905afa918215610b0857600092611b60575b5050101580388080611aef565b611b769250803d106118d0576118c2818361017a565b3880611b53565b611b949150833d85116118d0576118c2818361017a565b38611ae5565b9192610100810160018151611bae8161022e565b611bb78161022e565b03611c8157506060611be5611bd9611bd960408501516001600160a01b031690565b6001600160a01b031690565b91015191813b1561012a5760008094611c5d604051978896879586947ff242432a00000000000000000000000000000000000000000000000000000000865260048601929060c094926001600160a01b0380921685521660208401526040830152606082015260a06080820152600060a08201520190565b03925af18015610b0857611c6e5750565b80611c7b6102f492610145565b806101ce565b9091935051611c8f8161022e565b611c988161022e565b15611ca257505050565b6060611cbe611bd9611bd960408501516001600160a01b031690565b91015190803b1561012a576040517fb88d4fde0000000000000000000000000000000000000000000000000000000081526001600160a01b03938416600482015293909216602484015260448301526080606483015260006084830181905290829060a490829084905af18015610b0857611c6e5750565b919082604091031261012a5760208251611d4f816101bd565b92015161ffff8116810361012a5790565b818102929181159184041417156106cb57565b919082604091031261012a5760208251611d8c816101bd565b92015190565b15611d9957565b606460405162461bcd60e51b815260206004820152601560248201527f66656573206578636565642074686520707269636500000000000000000000006044820152fd5b909192936040948551957fd45573f60000000000000000000000000000000000000000000000000000000087528087600481305afa8015610b08576102f497611f1694611f1093611edf936000938491611fc0575b50918a6001600160a01b039373716992d45bc60e9ead5f59206c0d049afbff429f85831614611fb8575b611e6d61ffff611e7592168a611d60565b612710900490565b80956000978589968c88976060611e9b611bd9611bd9868501516001600160a01b031690565b91015183518096819482937f2a55205a0000000000000000000000000000000000000000000000000000000084526004840160209093929193604081019481520152565b03915afa8792839282611f85575b5050611f2e575b5050611f0b95508b82611f1c575b9291505061203e565b611273565b90610b23565b9261203e565b611f259361203e565b8a84388b611f02565b925092945092948116151580611f7c575b611f50575b84928794928792611ef4565b859650611f0b9450611f7089611f698885969795611273565b1115611d92565b91958193929450611f44565b50811515611f3f565b8091929450611fa99350903d10611fb1575b611fa1818361017a565b810190611d73565b913880611eed565b503d611f97565b506000611e5c565b905081611fe39294503d8511611fec575b611fdb818361017a565b810190611d36565b92909238611e32565b503d611fd1565b15611ffa57565b606460405162461bcd60e51b815260206004820152601360248201527f6d73672e76616c756520213d20616d6f756e74000000000000000000000000006044820152fd5b90831561213b576001600160a01b039180831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0361212f5750811630036120e3575090600091823b156120df576040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815260048101839052928360248183805af1928315610b08576102f4936120cc575b50612258565b80611c7b6120d992610145565b386120c6565b8280fd5b8116300361212557506120f7348214611ff3565b60003b1561012a57600060049160405192838092630d0e30db60e41b8252845af18015610b0857611c6e5750565b906102f491612258565b6102f494939250612141565b50505050565b92916001600160a01b03918216828216818114612210573082036121aa57505060405163a9059cbb60e01b60208201526001600160a01b03909116602482015260448101929092526102f4926121a483606481015b03601f19810185528461017a565b1661241c565b90939150604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526024850152604484015260648301526064825260a082019282841067ffffffffffffffff851117610159576102f4936040521661241c565b505050505050565b3d15612253573d9067ffffffffffffffff82116101595760405191612247601f8201601f19166020018461017a565b82523d6000602084013e565b606090565b60008080808086865af161226a612218565b501561227557505050565b803b156123a857604051630d0e30db60e41b8152818160048187845af18015610b0857612399575b5060405163a9059cbb60e01b60208083019182526001600160a01b039094166024830152604482019490945291926122d88360648101612196565b604051926122e58461015e565b8484527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656485850152823b15612355579180916123309493519082805af161232a612218565b906124c3565b8051908161233d57505050565b826102f493612350938301019101610a75565b6123ab565b6064856040519062461bcd60e51b82526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b6123a290610145565b3861229d565b80fd5b156123b257565b608460405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b6001600160a01b031690604051906124338261015e565b6020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b1561247f57600082819282876123309796519301915af161232a612218565b6064846040519062461bcd60e51b82526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b909190156124cf575090565b8151156124df5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b828510612525575050604492506000838284010152601f80199101168101030190fd5b8481018201518686016044015293810193859350612502565b9061254882611280565b612555604051918261017a565b8281528092612566601f1991611280565b0190602036910137565b90919692969593957fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9549663ffffffff986125ac8a881661253e565b956000945b8a8110806127c7575b806127bc575b1561272857806125eb6105718e936000526000805160206127d3833981519152602052604060002090565b6080891615801561270f575b61260c575b50600101996000190116986125b1565b6040808a16159081156126f6575b50612625575b6125fc565b602089161580156126e9575b156125fc57600489161580156126c8575b156125fc576002808a16159081156126a7575b50156125fc57600190818a1615908115612697575b50156126205782809189846126876001969f9c8f908616906112e8565b52011697600019011699906125fc565b6126a191506116c6565b3861266a565b90506101208201516126b88161024a565b6126c18161024a565b1438612655565b5060016101208201516126da8161024a565b6126e38161024a565b14612642565b5085606082015114612631565b8201516001600160a01b0387811691161490503861261a565b5060208101516001600160a01b038881169116146125f7565b9550975050505095948592935060009082106000146127b557505b94169061274f82611298565b9460005b858116848110156127ad5786916127a5826127946105716127766001968a6112e8565b516000526000805160206127d3833981519152602052604060002090565b61279e828d6112e8565b528a6112e8565b500116612753565b505093505050565b9050612743565b508b891615156125c0565b508b8a1615156125ba56fee4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624caaa264697066735822122072e78c56bf4a0b6b2028f58b7e06d58d0d2d2897106bd00d609ccc411f60047964736f6c63430008120033
Deployed ByteCode
0x6080604052600436101561001257600080fd5b60003560e01c8063016767fa146100b7578063119df25f146100b257806316a29807146100ad5780634579268a146100a85780638b49d47e146100a357806391940b3e1461009e578063a9fd8ed114610099578063c1edcfbe14610094578063c815729d1461008f5763ef706adf1461008a57600080fd5b6109ae565b6106fa565b610621565b6105e4565b610471565b610416565b6103c5565b610354565b6101d9565b3461012a5760c036600319011261012a576100d3610140604052565b6004356100df816101bd565b60805260243560a05260443560c0526064356100fa816101bd565b60e0526084356101005260a43561012052610126610116610b99565b6040519081529081906020820190565b0390f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161015957604052565b61012f565b6040810190811067ffffffffffffffff82111761015957604052565b90601f8019910116810190811067ffffffffffffffff82111761015957604052565b60405190610140820182811067ffffffffffffffff82111761015957604052565b6001600160a01b0381160361012a57565b600091031261012a57565b3461012a57600036600319011261012a5760206101f4610a99565b6001600160a01b0360405191168152f35b60c4359063ffffffff8216820361012a57565b634e487b7160e01b600052602160045260246000fd5b6003111561023857565b610218565b9060038210156102385752565b6004111561023857565b9060048210156102385752565b805182526020808201516001600160a01b0316908301526102f491906040818101516001600160a01b03169083015260608101516060830152608081015160808301526102be60a082015160a08401906001600160a01b03169052565b60c081015160c083015260e081015160e08301526102e5610100808301519084019061023d565b61012080910151910190610254565b565b90815180825260208080930193019160005b828110610316575050505090565b90919293826101408261032c6001948951610261565b01950193929101610308565b92919061034f6020916040865260408601906102f6565b930152565b3461012a5760e036600319011261012a5760243560ff8116810361012a5760443561037e816101bd565b6064359161038b836101bd565b60a4359063ffffffff8216820361012a576103b5936103a8610205565b9360843592600435612570565b9061012660405192839283610338565b3461012a57602036600319011261012a576103de6111ad565b506004356000526000805160206127d38339815191526020526101406104076040600020610f9f565b6104146040518092610261565bf35b3461012a57600036600319011261012a576040610431610b30565b919082825193849260208452816020850152848401376000828201840152601f01601f19168101030190f35b90602061046e9281815201906102f6565b90565b3461012a57604036600319011261012a5760243560043581811115806105ba575b61049b9061120b565b6104b56104b06104ab8385610b23565b611256565b611298565b90600090805b8481111561053d57836104cd84611298565b81516000805b8281106104e85760405180610126868261045d565b806104ff6104f961050893886112e8565b516116c6565b61050d57611256565b6104d3565b61053761051a82886112e8565b519361052581611312565b9461053082896112e8565b52866112e8565b50611256565b6105926104f961054d8484610b23565b610576610571856000526000805160206127d3833981519152602052604060002090565b610f9f565b61058082896112e8565b5261058b81886112e8565b50866112e8565b6105a5575b6105a090611256565b6104bb565b916105b26105a091611256565b929050610597565b507fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9548210610492565b3461012a57600036600319011261012a5760207fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca954604051908152f35b3461012a5760408060031936011261012a576004356024359182821115806106d0575b61064d9061120b565b8183038381116106cb576001908181018091116106cb5761066d90611298565b92805b8581111561068557835180610126878261045d565b6106be8460008381526000805160206127d3833981519152602052206106b46106ae8585610b23565b91610f9f565b61053082896112e8565b5082810180911115610670575b610b0d565b507fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9548310610644565b3461012a57602036600319011261012a576004357fbbf78d3411d42a81effd97bb8c69faae4e77e75cec462245c1001191a0634c6f600281541461096a5760029055806000526000805160206127d383398151915260205260ff60086040600020015460081c1660048110156102385760011461077690610f54565b610797816000526000805160206127d3833981519152602052604060002090565b6107a090610f9f565b60e081015142106107b0906110f1565b602081019182516107c7906001600160a01b031690565b60a083019384516107de906001600160a01b031690565b9160c08501928351906107f092611a8d565b6107f99061113c565b610801610a99565b9060408501908151610819906001600160a01b031690565b94606087019384519660808901978851906101008b01519261083a8461022e565b610843946117b3565b610864906000526000805160206127d3833981519152602052604060002090565b600801805461ff00191661020017905580516001600160a01b031686610888610a99565b89516001600160a01b031687519161089f94611ddd565b6108a7610a99565b815187906001600160a01b03168751906108c093611b9a565b516001600160a01b0316945190516001600160a01b03169151956108e2610a99565b945193519051604080519384526001600160a01b03968716602085015283019490945260608201529183166080830152821692909116907f31ee722dd5481cc30d4c84372f2191d02befbafed3a623224f133e60fe67bd419060a090a461096860017fbbf78d3411d42a81effd97bb8c69faae4e77e75cec462245c1001191a0634c6f55565b005b606460405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b3461012a57602036600319011261012a576004356000908082526000805160206127d38339815191528060205260ff600860408520015460081c1660048110156102385760016109fe9114610f54565b8183526020526001600160a01b038060016040852001541690610a1f610a99565b1603610a3157610a2e90611071565b80f35b606460405162461bcd60e51b815260206004820152600860248201527f214f666665726f720000000000000000000000000000000000000000000000006044820152fd5b9081602091031261012a5751801515810361012a5790565b6040513d6000823e3d90fd5b60405163572b6c0560e01b8152336004820152602081602481305afa908115610b0857600091610ada575b5015610ad65736601319013560601c90565b3390565b610afb915060203d8111610b01575b610af3818361017a565b810190610a75565b38610ac4565b503d610ae9565b610a8d565b634e487b7160e01b600052601160045260246000fd5b919082039182116106cb57565b60405163572b6c0560e01b8152336004820152602081602481305afa908115610b0857600091610b7b575b5015610b74576013193601903682116106cb5760009190565b6000903690565b610b93915060203d8111610b0157610af3818361017a565b38610b5b565b6001600160a01b0360805116604051907fa32fa5b30000000000000000000000000000000000000000000000000000000082527f86d5cf0a6bdc8d859ba3bdc97043337c82a0e609035f378e419298b6a3e00ae660048301526024820152602081604481305afa908115610b0857600091610c61575b5015610c1d5761046e610e0f565b606460405162461bcd60e51b815260206004820152600b60248201527f2141535345545f524f4c450000000000000000000000000000000000000000006044820152fd5b610c79915060203d8111610b0157610af3818361017a565b38610c0f565b60038210156102385752565b60048210156102385752565b9060038110156102385760ff80198354169116179055565b9060048110156102385761ff0082549160081b169061ff001916179055565b9061012060086102f49383518155610d1f610cf360208601516001600160a01b031690565b60018301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b610d62610d3660408601516001600160a01b031690565b60028301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b6060840151600382015560808401516004820155610db9610d8d60a08601516001600160a01b031690565b60058301906001600160a01b031673ffffffffffffffffffffffffffffffffffffffff19825416179055565b60c0840151600682015560e084015160078201550191610de7610100820151610de18161022e565b84610c97565b015190610df38261024a565b610caf565b908152610160810192916102f49160200190610261565b610e17611321565b90610e20610a99565b6080516001600160a01b0316610e3590611355565b90610e3f826115f9565b6080516001600160a01b03169160a0519060c0519160e051610e67906001600160a01b031690565b906101009182519061012095865193610e7e61019c565b8c81526001600160a01b038a166020820152996001600160a01b031660408b015260608a015260808901526001600160a01b031660a088015260c087015260e0860152840190610ecd91610c7f565b60019083015281610ef5856000526000805160206127d3833981519152602052604060002090565b90610eff91610cce565b6080516001600160a01b03169160a0519260405180916001600160a01b03809116941692610f2e908883610df8565b037fe5f7d2ca9b939cd61d1b80107f4733d6552e26d08e899e8b27d99b4bb01466da91a4565b15610f5b57565b606460405162461bcd60e51b815260206004820152601b60248201527f4d61726b6574706c6163653a20696e76616c6964206f666665722e00000000006044820152fd5b906102f460ff6008610faf61019c565b9480548652610fdb610fcb60018301546001600160a01b031690565b6001600160a01b03166020880152565b611002610ff260028301546001600160a01b031690565b6001600160a01b03166040880152565b600381015460608701526004810154608087015261103d61102d60058301546001600160a01b031690565b6001600160a01b031660a0880152565b600681015460c0870152600781015460e087015201546110638282166101008701610c7f565b60081c166101208401610c8b565b806000526000805160206127d38339815191526020526110a560406000206008810161030061ff0019825416179055610f9f565b6110ad610a99565b917f656fae5ac58099f1303c3dd53bbc9e4b0f000700d538d81ef7f5716ab1a34b9060206001600160a01b03606081604087015116950151956040519485521692a4565b156110f857565b606460405162461bcd60e51b815260206004820152600760248201527f45585049524544000000000000000000000000000000000000000000000000006044820152fd5b1561114357565b608460405162461bcd60e51b815260206004820152602b60248201527f4d61726b6574706c6163653a20696e73756666696369656e742063757272656e60448201527f63792062616c616e63652e0000000000000000000000000000000000000000006064820152fd5b60405190610140820182811067ffffffffffffffff82111761015957604052816101206000918281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e0820152826101008201520152565b1561121257565b606460405162461bcd60e51b815260206004820152600d60248201527f696e76616c69642072616e6765000000000000000000000000000000000000006044820152fd5b90600182018092116106cb57565b90610e1082018092116106cb57565b919082018092116106cb57565b67ffffffffffffffff81116101595760051b60200190565b906112a282611280565b6112af604051918261017a565b82815280926112c0601f1991611280565b019060005b8281106112d157505050565b6020906112dc6111ad565b828285010152016112c5565b80518210156112fc5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b60001981146106cb5760010190565b7fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca99081549160018301908184116106cb5755565b6040517f01ffc9a7000000000000000000000000000000000000000000000000000000008082527fd9b67a260000000000000000000000000000000000000000000000000000000060048301526020926001600160a01b0316918381602481865afa908115610b08576000916114af575b50156113d457505050600190565b6040519081527f80ac58cd000000000000000000000000000000000000000000000000000000006004820152908290829060249082905afa918215610b0857600092611492575b50501561142757600090565b60405162461bcd60e51b815260206004820152602d60248201527f4d61726b6574706c6163653a20746f6b656e206d75737420626520455243313160448201527f3535206f72204552433732312e000000000000000000000000000000000000006064820152608490fd5b6114a89250803d10610b0157610af3818361017a565b388061141b565b6114c69150843d8611610b0157610af3818361017a565b386113c6565b156114d357565b606460405162461bcd60e51b815260206004820152602060248201527f4d61726b6574706c6163653a2077616e746564207a65726f20746f6b656e732e6044820152fd5b1561151e57565b608460405162461bcd60e51b815260206004820152602560248201527f4d61726b6574706c6163653a2077616e74656420696e76616c6964207175616e60448201527f746974792e0000000000000000000000000000000000000000000000000000006064820152fd5b1561158f57565b608460405162461bcd60e51b815260206004820152602a60248201527f4d61726b6574706c6163653a20696e76616c69642065787069726174696f6e2060448201527f74696d657374616d702e000000000000000000000000000000000000000000006064820152fd5b61010090815115611682576102f4916116306116699261161c60c05115156114cc565b600160c0511490811561166e575b50611517565b61164661163f61012051611264565b4210611588565b61164e610a99565b9061166160e0516001600160a01b031690565b905191611a8d565b61113c565b6001915061167b8161022e565b143861162a565b606460405162461bcd60e51b815260206004820152600b60248201527f7a65726f2070726963652e0000000000000000000000000000000000000000006044820152fd5b60e081015142109081611704575b816116dd575090565b61046e91506001600160a01b039060c0826020830151169260a08301511691015191611a8d565b9050610120810151600481101561023857600114906116d4565b9081602091031261012a575161046e816101bd565b9081602091031261012a575190565b1561174957565b608460405162461bcd60e51b815260206004820152602a60248201527f4d61726b6574706c6163653a206e6f74206f776e6572206f7220617070726f7660448201527f656420746f6b656e732e000000000000000000000000000000000000000000006064820152fd5b9291936000906117c28161022e565b600181036118d75750506040517efdd58e0000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301526024820195909552931692602091908281604481885afa908115610b08576000916118aa575b501015918261183d575b50506102f49150611742565b60405163e985e9c560e01b81526001600160a01b0391909116600482015230602482015290929091508290829060449082905afa908115610b08576102f49260009261188d575b50503880611831565b6118a39250803d10610b0157610af3818361017a565b3880611884565b6118ca9150833d85116118d0575b6118c2818361017a565b810190611733565b38611827565b503d6118b8565b9093919492506118e68161022e565b156118f75750506102f49150611742565b6040517f6352211e000000000000000000000000000000000000000000000000000000008152600481018390526001600160a01b03948516949293919260209182816024818a5afa908115610b08578491611a70575b50811684821614948561196c575b50505050506102f491503880611831565b6040517f081812fc0000000000000000000000000000000000000000000000000000000081526004810191909152939450919290918282602481895afa918215610b08578492611a41575b501630149283156119d5575b5050506102f49150388080808061195b565b60405163e985e9c560e01b81526001600160a01b0391909116600482015230602482015291939092508290829060449082905afa918215610b08576102f49392611a24575b50503880806119c3565b611a3a9250803d10610b0157610af3818361017a565b3880611a1a565b611a62919250833d8511611a69575b611a5a818361017a565b81019061171e565b90386119b7565b503d611a50565b611a879150833d8511611a6957611a5a818361017a565b3861194d565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038281166004830152929092169290916020908181602481885afa8015610b08578391600091611b7d575b5010159283611af7575b505050905090565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081526001600160a01b0391909116600482015230602482015291939092508290829060449082905afa918215610b0857600092611b60575b5050101580388080611aef565b611b769250803d106118d0576118c2818361017a565b3880611b53565b611b949150833d85116118d0576118c2818361017a565b38611ae5565b9192610100810160018151611bae8161022e565b611bb78161022e565b03611c8157506060611be5611bd9611bd960408501516001600160a01b031690565b6001600160a01b031690565b91015191813b1561012a5760008094611c5d604051978896879586947ff242432a00000000000000000000000000000000000000000000000000000000865260048601929060c094926001600160a01b0380921685521660208401526040830152606082015260a06080820152600060a08201520190565b03925af18015610b0857611c6e5750565b80611c7b6102f492610145565b806101ce565b9091935051611c8f8161022e565b611c988161022e565b15611ca257505050565b6060611cbe611bd9611bd960408501516001600160a01b031690565b91015190803b1561012a576040517fb88d4fde0000000000000000000000000000000000000000000000000000000081526001600160a01b03938416600482015293909216602484015260448301526080606483015260006084830181905290829060a490829084905af18015610b0857611c6e5750565b919082604091031261012a5760208251611d4f816101bd565b92015161ffff8116810361012a5790565b818102929181159184041417156106cb57565b919082604091031261012a5760208251611d8c816101bd565b92015190565b15611d9957565b606460405162461bcd60e51b815260206004820152601560248201527f66656573206578636565642074686520707269636500000000000000000000006044820152fd5b909192936040948551957fd45573f60000000000000000000000000000000000000000000000000000000087528087600481305afa8015610b08576102f497611f1694611f1093611edf936000938491611fc0575b50918a6001600160a01b039373716992d45bc60e9ead5f59206c0d049afbff429f85831614611fb8575b611e6d61ffff611e7592168a611d60565b612710900490565b80956000978589968c88976060611e9b611bd9611bd9868501516001600160a01b031690565b91015183518096819482937f2a55205a0000000000000000000000000000000000000000000000000000000084526004840160209093929193604081019481520152565b03915afa8792839282611f85575b5050611f2e575b5050611f0b95508b82611f1c575b9291505061203e565b611273565b90610b23565b9261203e565b611f259361203e565b8a84388b611f02565b925092945092948116151580611f7c575b611f50575b84928794928792611ef4565b859650611f0b9450611f7089611f698885969795611273565b1115611d92565b91958193929450611f44565b50811515611f3f565b8091929450611fa99350903d10611fb1575b611fa1818361017a565b810190611d73565b913880611eed565b503d611f97565b506000611e5c565b905081611fe39294503d8511611fec575b611fdb818361017a565b810190611d36565b92909238611e32565b503d611fd1565b15611ffa57565b606460405162461bcd60e51b815260206004820152601360248201527f6d73672e76616c756520213d20616d6f756e74000000000000000000000000006044820152fd5b90831561213b576001600160a01b039180831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0361212f5750811630036120e3575090600091823b156120df576040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815260048101839052928360248183805af1928315610b08576102f4936120cc575b50612258565b80611c7b6120d992610145565b386120c6565b8280fd5b8116300361212557506120f7348214611ff3565b60003b1561012a57600060049160405192838092630d0e30db60e41b8252845af18015610b0857611c6e5750565b906102f491612258565b6102f494939250612141565b50505050565b92916001600160a01b03918216828216818114612210573082036121aa57505060405163a9059cbb60e01b60208201526001600160a01b03909116602482015260448101929092526102f4926121a483606481015b03601f19810185528461017a565b1661241c565b90939150604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526024850152604484015260648301526064825260a082019282841067ffffffffffffffff851117610159576102f4936040521661241c565b505050505050565b3d15612253573d9067ffffffffffffffff82116101595760405191612247601f8201601f19166020018461017a565b82523d6000602084013e565b606090565b60008080808086865af161226a612218565b501561227557505050565b803b156123a857604051630d0e30db60e41b8152818160048187845af18015610b0857612399575b5060405163a9059cbb60e01b60208083019182526001600160a01b039094166024830152604482019490945291926122d88360648101612196565b604051926122e58461015e565b8484527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656485850152823b15612355579180916123309493519082805af161232a612218565b906124c3565b8051908161233d57505050565b826102f493612350938301019101610a75565b6123ab565b6064856040519062461bcd60e51b82526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b6123a290610145565b3861229d565b80fd5b156123b257565b608460405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b6001600160a01b031690604051906124338261015e565b6020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b1561247f57600082819282876123309796519301915af161232a612218565b6064846040519062461bcd60e51b82526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b909190156124cf575090565b8151156124df5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b828510612525575050604492506000838284010152601f80199101168101030190fd5b8481018201518686016044015293810193859350612502565b9061254882611280565b612555604051918261017a565b8281528092612566601f1991611280565b0190602036910137565b90919692969593957fe4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624ca9549663ffffffff986125ac8a881661253e565b956000945b8a8110806127c7575b806127bc575b1561272857806125eb6105718e936000526000805160206127d3833981519152602052604060002090565b6080891615801561270f575b61260c575b50600101996000190116986125b1565b6040808a16159081156126f6575b50612625575b6125fc565b602089161580156126e9575b156125fc57600489161580156126c8575b156125fc576002808a16159081156126a7575b50156125fc57600190818a1615908115612697575b50156126205782809189846126876001969f9c8f908616906112e8565b52011697600019011699906125fc565b6126a191506116c6565b3861266a565b90506101208201516126b88161024a565b6126c18161024a565b1438612655565b5060016101208201516126da8161024a565b6126e38161024a565b14612642565b5085606082015114612631565b8201516001600160a01b0387811691161490503861261a565b5060208101516001600160a01b038881169116146125f7565b9550975050505095948592935060009082106000146127b557505b94169061274f82611298565b9460005b858116848110156127ad5786916127a5826127946105716127766001968a6112e8565b516000526000805160206127d3833981519152602052604060002090565b61279e828d6112e8565b528a6112e8565b500116612753565b505093505050565b9050612743565b508b891615156125c0565b508b8a1615156125ba56fee4435c80c9874d455ad2136af47d67165644bb851fd208179d93e973f0624caaa264697066735822122072e78c56bf4a0b6b2028f58b7e06d58d0d2d2897106bd00d609ccc411f60047964736f6c63430008120033