Overview
ETH Balance
More Info
ContractCreator
Multichain Info
Latest 25 from a total of 28 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
Amount
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Create Vault | 23014549 | 332 days ago | IN | 0 ETH | 0.00000256 | ||||
| Create Vault | 22990897 | 333 days ago | IN | 0 ETH | 0.00235889 | ||||
| Create Vault | 22990839 | 333 days ago | IN | 0 ETH | 0.00235889 | ||||
| Create Vault | 22990744 | 333 days ago | IN | 0 ETH | 0.00235889 | ||||
| Create Vault | 22990627 | 333 days ago | IN | 0 ETH | 0.00235888 | ||||
| Create Vault | 22988514 | 333 days ago | IN | 0 ETH | 0.00000236 | ||||
| Create Vault | 22986686 | 333 days ago | IN | 0 ETH | 0.00000283 | ||||
| Create Vault | 22940562 | 334 days ago | IN | 0 ETH | 0.00000265 | ||||
| Create Vault | 20441305 | 392 days ago | IN | 0 ETH | 0.00000257 | ||||
| Create Vault | 20441288 | 392 days ago | IN | 0 ETH | 0.00000377 | ||||
| Create Vault | 20441273 | 392 days ago | IN | 0 ETH | 0.00000256 | ||||
| Create Vault | 20441058 | 392 days ago | IN | 0 ETH | 0.00000253 | ||||
| Create Vault | 20440656 | 392 days ago | IN | 0 ETH | 0.00000245 | ||||
| Create Vault | 20440637 | 392 days ago | IN | 0 ETH | 0.00000246 | ||||
| Create Vault | 20440618 | 392 days ago | IN | 0 ETH | 0.00000363 | ||||
| Create Vault | 20440592 | 392 days ago | IN | 0 ETH | 0.00000246 | ||||
| Create Vault | 20440456 | 392 days ago | IN | 0 ETH | 0.00000246 | ||||
| Create Vault | 20440375 | 392 days ago | IN | 0 ETH | 0.00000248 | ||||
| Create Vault | 20440324 | 392 days ago | IN | 0 ETH | 0.00000249 | ||||
| Create Vault | 20440290 | 392 days ago | IN | 0 ETH | 0.00000247 | ||||
| Create Vault | 20440190 | 392 days ago | IN | 0 ETH | 0.00000248 | ||||
| Create Vault | 20440110 | 392 days ago | IN | 0 ETH | 0.0000024 | ||||
| Create Vault | 20276589 | 395 days ago | IN | 0 ETH | 0.00000279 | ||||
| Create Vault | 20276458 | 395 days ago | IN | 0 ETH | 0.00000284 | ||||
| Create Vault | 19631159 | 410 days ago | IN | 0 ETH | 0.00000182 |
Latest 25 internal transactions (View All)
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
import "lib/openzeppelin-contracts/contracts/utils/Strings.sol";
import "./INftVaultFactory.sol";
import "./NftVault.sol";
contract NftVaultFactory is INftVaultFactory {
using EnumerableSet for EnumerableSet.AddressSet;
using Strings for uint256;
EnumerableSet.AddressSet private vaults;
mapping(bytes32 => INftVault) public vaultHashMap;
mapping(INftVault => uint256) public vaultIdMap;
/// @inheritdoc INftVaultFactory
function getAllVaults() external view returns (address[] memory) {
return vaults.values();
}
/// @inheritdoc INftVaultFactory
function getVaultAt(uint256 _index) external view returns (address) {
return vaults.at(_index);
}
/// @inheritdoc INftVaultFactory
function getVaultLength() external view returns (uint256) {
return vaults.length();
}
/// @inheritdoc INftVaultFactory
function isVault(address _vault) external view returns (bool) {
return vaults.contains(_vault);
}
/// @inheritdoc INftVaultFactory
function getVault(INftVault.CollectionData[] memory _collections) public view returns (INftVault vault) {
vault = vaultHashMap[hashVault(_collections)];
if (address(vault) == address(0)) revert VaultDoesNotExist();
}
/// @inheritdoc INftVaultFactory
function exists(INftVault.CollectionData[] memory _collections) public view returns (bool) {
return address(vaultHashMap[hashVault(_collections)]) != address(0);
}
/// @inheritdoc INftVaultFactory
function hashVault(INftVault.CollectionData[] memory _collections) public pure returns (bytes32) {
return keccak256(abi.encode(_collections));
}
/// @inheritdoc INftVaultFactory
function createVault(INftVault.CollectionData[] memory _collections) external returns (INftVault vault) {
bytes32 vaultHash = hashVault(_collections);
vault = INftVault(vaultHashMap[vaultHash]);
// if vault with _collections alredy exists, revert
if (address(vault) != address(0)) revert VaultAlreadyDeployed();
uint256 vaultId;
string memory name;
string memory symbol;
vaultId = vaults.length();
name = string.concat("Magic Vault ", vaultId.toString());
symbol = string.concat("MagicVault", vaultId.toString());
vault = INftVault(address(new NftVault(name, symbol)));
vault.init(_collections);
vaults.add(address(vault));
vaultHashMap[vaultHash] = vault;
vaultIdMap[vault] = vaultId;
emit VaultCreated(name, symbol, vault, vaultId, _collections, msg.sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import "./INftVault.sol";
/// @title Vault factory contract
interface INftVaultFactory {
/// @notice Emitted when new vault is deployed
/// @param name vault's name
/// @param symbol vault's name
/// @param vault vault's address as INftVault
/// @param vaultId vault's index in `vaults` AddressSet
/// @param collections configuration used for vault creation
/// @param creator address of vault creator
event VaultCreated(
string name,
string symbol,
INftVault indexed vault,
uint256 indexed vaultId,
INftVault.CollectionData[] collections,
address creator
);
/// @dev Vault does not exist
error VaultDoesNotExist();
/// @dev Vault with identical configuration is already deployed
error VaultAlreadyDeployed();
/// @notice Get vault by its config hash
/// @param hash vault's config hash
/// @return vault address
function vaultHashMap(bytes32 hash) external view returns (INftVault vault);
/// @return all deployed vaults
function getAllVaults() external view returns (address[] memory);
/// @notice Get vault by its EnumerableSet vaultId
/// @param index vaultId or index in NftVaultFactory.vaults array
/// @return vault address
function getVaultAt(uint256 index) external view returns (address);
/// @return length of vault's EnumerableSet
function getVaultLength() external view returns (uint256);
/// @notice Returns true if vault has been deployed by factory
/// @param vault address
/// @return true if vault is deployed by the factory
function isVault(address vault) external view returns (bool);
/// @notice Get vault by it's config
/// @param collections vault's config
/// @return vault address
function getVault(INftVault.CollectionData[] memory collections) external view returns (INftVault vault);
/// @notice Returns true if vault with given config exists
/// @param collections vault's config
/// @return true if vault with given config exists
function exists(INftVault.CollectionData[] memory collections) external view returns (bool);
/// @notice Get config hash
/// @param collections vault's config
/// @return config hash
function hashVault(INftVault.CollectionData[] memory collections) external pure returns (bytes32);
/// @notice Create new vault
/// @dev If vault already exists, function reverts
/// @param collections vault's config
/// @return vault address of deployed vault
function createVault(INftVault.CollectionData[] memory collections) external returns (INftVault vault);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableMap.sol";
import "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165Checker.sol";
import "lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import "lib/openzeppelin-contracts/contracts/utils/Address.sol";
import "./INftVault.sol";
import "./INftVaultFactory.sol";
contract NftVault is INftVault, ERC20, ERC721Holder, ERC1155Holder {
using EnumerableMap for EnumerableMap.AddressToUintMap;
/// @notice value of 1 token, including decimals
uint256 public immutable ONE;
/// @notice amount of token required for last NFT to be redeemed
uint256 public immutable LAST_NFT_AMOUNT;
/// @notice unique ID of the vault generated using its configuration
bytes32 public VAULT_HASH;
/// @notice maps collection address to nft type
EnumerableMap.AddressToUintMap private allowedCollections;
/// @notice maps collection address to allowed tokens
mapping(address => AllowedTokenIds) private allowedTokenIds;
/// @notice maps collection address to tokenId to amount wrapped
mapping(address => mapping(uint256 => uint256)) public balances;
/// @param _name name of ERC20 Vault token
/// @param _symbol symbol of ERC20 Vault token
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {
ONE = 10 ** decimals();
/// @dev last NFT can be redeemed for 99.9%
LAST_NFT_AMOUNT = ONE * 999 / 1000;
}
/// @inheritdoc INftVault
function init(CollectionData[] memory _collections) external {
if (_collections.length == 0) revert InvalidCollections();
if (allowedCollections.length() > 0) revert Initialized();
VAULT_HASH = hashVault(_collections);
for (uint256 i = 0; i < _collections.length; i++) {
CollectionData memory collection = _collections[i];
/// @dev if all Ids are allowed tokenIds must be empty, otherwise VAULT_HASH will not be correct
if (collection.allowAllIds && collection.tokenIds.length > 0) revert TokenIdsMustBeEmpty();
uint256 nftType = validateNftType(collection.addr, collection.nftType);
if (!allowedCollections.set(collection.addr, nftType)) revert DuplicateCollection();
allowedTokenIds[collection.addr].allowAllIds = collection.allowAllIds;
emit CollectionAllowed(collection);
if (collection.allowAllIds) continue;
if (collection.tokenIds.length == 0) revert MissingTokenIds();
uint256 lastTokenId = 0;
for (uint256 j = 0; j < collection.tokenIds.length; j++) {
uint256 tokenId = collection.tokenIds[j];
/// @dev Make sure `uint256[] tokenIds` array is sorted,
/// otherwise VAULT_HASH will not be correct
if (tokenId < lastTokenId) {
revert TokenIdsMustBeSorted();
} else {
lastTokenId = tokenId;
}
/// @dev Check for duplicates
if (allowedTokenIds[collection.addr].tokenIds[tokenId]) revert TokenIdAlreadySet();
allowedTokenIds[collection.addr].tokenIds[tokenId] = true;
allowedTokenIds[collection.addr].tokenIdList.push(tokenId);
}
}
}
/// @inheritdoc INftVault
function hashVault(INftVault.CollectionData[] memory _collections) public pure returns (bytes32) {
return keccak256(abi.encode(_collections));
}
/// @inheritdoc INftVault
function getAllowedCollections() external view returns (address[] memory collections) {
collections = new address[](allowedCollections.length());
for (uint256 i = 0; i < collections.length; i++) {
(address addr,) = allowedCollections.at(i);
collections[i] = addr;
}
}
/// @inheritdoc INftVault
function getAllowedCollectionsLength() external view returns (uint256) {
return allowedCollections.length();
}
/// @inheritdoc INftVault
function getAllowedCollectionData(address _collectionAddr) external view returns (CollectionData memory) {
return CollectionData({
addr: _collectionAddr,
nftType: NftType(allowedCollections.get(_collectionAddr)),
allowAllIds: allowedTokenIds[_collectionAddr].allowAllIds,
tokenIds: allowedTokenIds[_collectionAddr].tokenIdList
});
}
/// @inheritdoc INftVault
function validateNftType(address _collectionAddr, NftType _nftType) public view returns (uint256 nftType) {
bool supportsERC721 = ERC165Checker.supportsInterface(_collectionAddr, type(IERC721).interfaceId);
bool supportsERC1155 = ERC165Checker.supportsInterface(_collectionAddr, type(IERC1155).interfaceId);
/// @dev if `_collectionAddr` supports both or neither token standard, trust user input
/// if `_collectionAddr` supports one of the token standards, NftType must match it
if (supportsERC721 && !supportsERC1155 && _nftType != NftType.ERC721) revert ExpectedERC721();
if (supportsERC1155 && !supportsERC721 && _nftType != NftType.ERC1155) revert ExpectedERC1155();
nftType = uint256(_nftType);
}
/// @inheritdoc INftVault
function isTokenAllowed(address _collection, uint256 _tokenId) public view returns (bool) {
(bool isCollectionAllowed,) = allowedCollections.tryGet(_collection);
return isCollectionAllowed
&& (allowedTokenIds[_collection].allowAllIds || allowedTokenIds[_collection].tokenIds[_tokenId]);
}
/// @inheritdoc INftVault
function getSentTokenBalance(address _collection, uint256 _tokenId) public view returns (uint256) {
uint256 currentBalance = balances[_collection][_tokenId];
NftType nftType = NftType(allowedCollections.get(_collection));
if (nftType == NftType.ERC721) {
if (currentBalance == 0 && IERC721(_collection).ownerOf(_tokenId) == address(this)) {
return 1;
} else {
return 0;
}
} else if (nftType == NftType.ERC1155) {
return IERC1155(_collection).balanceOf(address(this), _tokenId) - currentBalance;
} else {
revert UnsupportedNft();
}
}
/// @inheritdoc INftVault
function deposit(address _to, address _collection, uint256 _tokenId, uint256 _amount)
public
returns (uint256 amountMinted)
{
if (!isTokenAllowed(_collection, _tokenId)) revert DisallowedToken();
uint256 sentTokenBalance = getSentTokenBalance(_collection, _tokenId);
if (_amount == 0 || sentTokenBalance < _amount) revert WrongAmount();
balances[_collection][_tokenId] += _amount;
emit Deposit(_to, _collection, _tokenId, _amount);
amountMinted = ONE * _amount;
uint256 totalSupply_ = totalSupply();
/// @dev If vault ERC20 supply is "0 < totalSupply <= 0.01" it means that vault has been emptied and there
/// is leftover ERC20 token (most likely) locked in the univ2 pair. To prevent minting small amounts
/// of unbacked ERC20 tokens in a loop, which can lead to unexpected behaviour, vault mints
/// `ONE - totalSupply` amount of ERC20 token for the first NFT that is deposited after the vault was
/// emptied. This allows for the vault and univ2 pair to be reused safely.
if (totalSupply_ > 0 && totalSupply_ <= ONE - LAST_NFT_AMOUNT) {
amountMinted -= totalSupply_;
}
_mint(_to, amountMinted);
}
/// @inheritdoc INftVault
function depositBatch(
address _to,
address[] memory _collection,
uint256[] memory _tokenId,
uint256[] memory _amount
) external returns (uint256 amountMinted) {
for (uint256 i = 0; i < _collection.length; i++) {
amountMinted += deposit(_to, _collection[i], _tokenId[i], _amount[i]);
}
}
/// @inheritdoc INftVault
function withdraw(address _to, address _collection, uint256 _tokenId, uint256 _amount)
public
returns (uint256 amountBurned)
{
if (_amount == 0 || balances[_collection][_tokenId] < _amount) revert WrongAmount();
balances[_collection][_tokenId] -= _amount;
amountBurned = ONE * _amount;
// when withdrawing the last NFT from the vault, allow redeemeing for LAST_NFT_AMOUNT instead of ONE
if (totalSupply() == amountBurned && balanceOf(address(this)) >= amountBurned - ONE + LAST_NFT_AMOUNT) {
amountBurned = balanceOf(address(this));
}
_burn(address(this), amountBurned);
NftType nftType = NftType(allowedCollections.get(_collection));
if (nftType == NftType.ERC721) {
if (_amount != 1) revert WrongERC721Amount();
IERC721(_collection).safeTransferFrom(address(this), _to, _tokenId);
} else if (nftType == NftType.ERC1155) {
IERC1155(_collection).safeTransferFrom(address(this), _to, _tokenId, _amount, bytes(""));
} else {
revert UnsupportedNft();
}
emit Withdraw(_to, _collection, _tokenId, _amount);
}
/// @inheritdoc INftVault
function withdrawBatch(
address _to,
address[] memory _collection,
uint256[] memory _tokenId,
uint256[] memory _amount
) external returns (uint256 amountBurned) {
for (uint256 i = 0; i < _collection.length; i++) {
amountBurned += withdraw(_to, _collection[i], _tokenId[i], _amount[i]);
}
}
/// @inheritdoc INftVault
function skim(address _to, NftType nftType, address _collection, uint256 _tokenId, uint256 _amount) external {
// Cannot skim supported token
if (isTokenAllowed(_collection, _tokenId)) revert MustBeDisallowedToken();
if (nftType == NftType.ERC721) {
IERC721(_collection).safeTransferFrom(address(this), _to, _tokenId);
} else if (nftType == NftType.ERC1155) {
IERC1155(_collection).safeTransferFrom(address(this), _to, _tokenId, _amount, bytes(""));
} else {
revert UnsupportedNft();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
/// @title Vault contract for wrapping NFTs (ERC721/ERC1155) to ERC20
interface INftVault {
enum NftType {
ERC721,
ERC1155
}
/// @notice Vault configuration struct that specifies which NFTs are accepted in vault.
/// @param addr address of nft contract
/// @param nftType standard that NFT supports { ERC721, ERC1155 }
/// @param allowAllIds if true, all tokens are allowed in the vault. If false, tokenIds must be
/// listed one by one.
/// @param tokenIds list of tokens supported by vault. If allowAllIds is true, list must be empty.
struct CollectionData {
address addr;
NftType nftType;
bool allowAllIds;
uint256[] tokenIds;
}
/// @notice Struct for allowed tokens. Stores data in an optimized way to read it in vault.
/// @param tokenIds mapping from tokenid to is-allowed
/// @param tokenIdList list of all tokens that are allowed
/// @param allowAllIds if true, all tokens are allowed
struct AllowedTokenIds {
mapping(uint256 => bool) tokenIds;
uint256[] tokenIdList;
bool allowAllIds;
}
/// @notice Emitted during initiation when collection added to allowed list
/// @param collection collection details
event CollectionAllowed(CollectionData collection);
/// @notice Emitted on depositing NFT to vault
/// @param to address that gets vault ERC20 tokens
/// @param collection NFT address that is deposited
/// @param tokenId token id that is deposited
/// @param amount amount of token that is deposited, for ERC721 always 1
event Deposit(address indexed to, address indexed collection, uint256 tokenId, uint256 amount);
/// @notice Emitted on withdrawing NFT from vault
/// @param to address that gets withdrawn NFTs
/// @param collection NFT address that is withdrawn
/// @param tokenId token id that is withdrawn
/// @param amount amount of token that is withdrawn, for ERC721 always 1
event Withdraw(address indexed to, address indexed collection, uint256 tokenId, uint256 amount);
/// @dev Contract is already initialized
error Initialized();
/// @dev Collection data is empty
error InvalidCollections();
/// @dev Collection already added
error DuplicateCollection();
/// @dev Token id is listed twice in CollectionData.tokenIds array
error TokenIdAlreadySet();
/// @dev Token ids in CollectionData.tokenIds array are not sorted
error TokenIdsMustBeSorted();
/// @dev ERC165 suggests that NFT is supporting ERC721 but ERC1155 is claimed
error ExpectedERC721();
/// @dev ERC165 suggests that NFT is supporting ERC1155 but ERC721 is claimed
error ExpectedERC1155();
/// @dev Collection does not support all token IDs however list of IDs is empty.
/// CollectionData.tokenIds is empty and CollectionData.allowAllIds is false.
error MissingTokenIds();
/// @dev CollectionData.tokenIds is not empty however Collection supports all token IDs.
error TokenIdsMustBeEmpty();
/// @dev Token is not allowed in vault
error DisallowedToken();
/// @dev Token amount is invalid eg. amount == 0
error WrongAmount();
/// @dev Token amount is invalid for ERC721, amount != 1
error WrongERC721Amount();
/// @dev Trying to interact with token that does not support ERC721 nor ERC1155
error UnsupportedNft();
/// @dev Token is allowed in vault but must not be
error MustBeDisallowedToken();
/// @notice value of 1 token, including decimals
function ONE() external view returns (uint256);
/// @notice amount of token required for last NFT to be redeemed
function LAST_NFT_AMOUNT() external view returns (uint256);
/// @notice unique id of the vault generated using its configuration
function VAULT_HASH() external view returns (bytes32);
/// @notice Initialize Vault with collection config
/// @dev Called by factory during deployment
/// @param collections struct array of allowed collections and token IDs
function init(CollectionData[] memory collections) external;
/// @notice Returns hash of vault configuration
/// @param collections struct array of allowed collections and token IDs
/// @return configuration hash
function hashVault(CollectionData[] memory collections) external pure returns (bytes32);
/// @notice Returns balances of NFT deposited to the vault
/// @param collectionAddr NFT address
/// @param tokenId NFT's token ID
/// @return amount amount of NFT deposited to the vault
function balances(address collectionAddr, uint256 tokenId) external view returns (uint256 amount);
/// @notice Get array of NFT addresses that are allowed to be deposited to the vault
/// @dev Keep in mind that returned address(es) can be further restricted on token ID level
/// @return collections array of NFT addresses that are allowed to be deposited to the vault
function getAllowedCollections() external view returns (address[] memory collections);
/// @return number of NFT addresses that are allowed to be deposited to the vault
function getAllowedCollectionsLength() external view returns (uint256);
/// @notice Get details of allowed collection
/// @return struct with details of allowed collection
function getAllowedCollectionData(address collectionAddr) external view returns (CollectionData memory);
/// @notice Validates type of collection (ERC721 or ERC1155)
/// @dev It uses ERC165 to check interface support. If support can not be detected without doubt, user input is trusted.
/// @param collectionAddr NFT address
/// @param nftType NFT type, ERC721 or ERC1155
/// @return validatedNftType returns validated enum NftType as uint256
function validateNftType(address collectionAddr, NftType nftType)
external
view
returns (uint256 validatedNftType);
/// @notice Returns if true token can be deposited
/// @param collection NFT address
/// @param tokenId NFT token ID
/// @return true if allowed
function isTokenAllowed(address collection, uint256 tokenId) external view returns (bool);
/// @notice Returns balance of token sent to the vault
/// @dev Reads balance of tokens freshy sent to the vault
/// @param collection NFT address
/// @param tokenId NFT token ID
/// @return balance of sent token, for ERC721 it's always 1
function getSentTokenBalance(address collection, uint256 tokenId) external view returns (uint256);
/// @notice Deposit NFT to vault
/// @dev This low-level function should be called from a contract which performs important safety checks
/// @param to address that gets minted ERC20 token
/// @param collection address of deposited NFT
/// @param tokenId token ID of deposited NFT
/// @param amount amount of deposited NFT, for ERC721 it's always 1
/// @return amountMinted amount of minted ERC20 token
function deposit(address to, address collection, uint256 tokenId, uint256 amount)
external
returns (uint256 amountMinted);
/// @notice Deposit NFTs to vault
/// @dev This low-level function should be called from a contract which performs important safety checks
/// @param to address that gets minted ERC20 token
/// @param collection array of addresses of deposited NFTs
/// @param tokenId array of token IDs of deposited NFTs
/// @param amount array if amounts of deposited NFTs, for ERC721 it's always 1
/// @return amountMinted amount of minted ERC20 token
function depositBatch(address to, address[] memory collection, uint256[] memory tokenId, uint256[] memory amount)
external
returns (uint256 amountMinted);
/// @notice Withdraw NFT from vault
/// @dev This low-level function should be called from a contract which performs important safety checks
/// @param to address that gets NFT
/// @param collection address of NFT to withdraw
/// @param tokenId token ID of NFT to withdraw
/// @param amount amount of NFT to withdraw, for ERC721 it's always 1
/// @return amountBurned amount of burned ERC20
function withdraw(address to, address collection, uint256 tokenId, uint256 amount)
external
returns (uint256 amountBurned);
/// @notice Withdraw NFTs from vault
/// @dev This low-level function should be called from a contract which performs important safety checks
/// @param to address that gets NFT
/// @param collection array of addresses of NFTs to withdraw
/// @param tokenId array of token IDs of NFTs to withdraw
/// @param amount array of amounts of NFTs to withdraw, for ERC721 it's always 1
/// @return amountBurned amount of burned ERC20
function withdrawBatch(address to, address[] memory collection, uint256[] memory tokenId, uint256[] memory amount)
external
returns (uint256 amountBurned);
/// @notice Allow anyone to withdraw tokens sent to this vault by accident
/// Only unsupported NFTs can be skimmed.
/// @param to address that gets NFT
/// @param nftType NftType of skimmed NFT
/// @param collection address of NFT to skim
/// @param tokenId token ID of NFT to skim
/// @param amount amount of NFT to skim, for ERC721 it's always 1
function skim(address to, NftType nftType, address collection, uint256 tokenId, uint256 amount) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.0;
import "./ERC1155Receiver.sol";
/**
* Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*
* @dev _Available since v3.1._
*/
contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableMap.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.
pragma solidity ^0.8.0;
import "./EnumerableSet.sol";
/**
* @dev Library for managing an enumerable variant of Solidity's
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
* type.
*
* Maps have the following properties:
*
* - Entries are added, removed, and checked for existence in constant time
* (O(1)).
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableMap for EnumerableMap.UintToAddressMap;
*
* // Declare a set state variable
* EnumerableMap.UintToAddressMap private myMap;
* }
* ```
*
* The following map types are supported:
*
* - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
* - `address -> uint256` (`AddressToUintMap`) since v4.6.0
* - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
* - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
* - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableMap.
* ====
*/
library EnumerableMap {
using EnumerableSet for EnumerableSet.Bytes32Set;
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Map type with
// bytes32 keys and values.
// The Map implementation uses private functions, and user-facing
// implementations (such as Uint256ToAddressMap) are just wrappers around
// the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit
// in bytes32.
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(
Bytes32ToBytes32Map storage map,
bytes32 key,
bytes32 value
) internal returns (bool) {
map._values[key] = value;
return map._keys.add(key);
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
delete map._values[key];
return map._keys.remove(key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
return map._keys.contains(key);
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
return map._keys.length();
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {
bytes32 key = map._keys.at(index);
return (key, map._values[key]);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
bytes32 value = map._values[key];
if (value == bytes32(0)) {
return (contains(map, key), bytes32(0));
} else {
return (true, value);
}
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), "EnumerableMap: nonexistent key");
return value;
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToBytes32Map storage map,
bytes32 key,
string memory errorMessage
) internal view returns (bytes32) {
bytes32 value = map._values[key];
require(value != 0 || contains(map, key), errorMessage);
return value;
}
// UintToUintMap
struct UintToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(
UintToUintMap storage map,
uint256 key,
uint256 value
) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToUintMap storage map, uint256 index) internal view returns (uint256, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key)));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
UintToUintMap storage map,
uint256 key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key), errorMessage));
}
// UintToAddressMap
struct UintToAddressMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(
UintToAddressMap storage map,
uint256 key,
address value
) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
UintToAddressMap storage map,
uint256 key,
string memory errorMessage
) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));
}
// AddressToUintMap
struct AddressToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(
AddressToUintMap storage map,
address key,
uint256 value
) internal returns (bool) {
return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(AddressToUintMap storage map, address key) internal returns (bool) {
return remove(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
return contains(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(AddressToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (address(uint160(uint256(key))), uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
AddressToUintMap storage map,
address key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));
}
// Bytes32ToUintMap
struct Bytes32ToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(
Bytes32ToUintMap storage map,
bytes32 key,
uint256 value
) internal returns (bool) {
return set(map._inner, key, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToUintMap storage map, bytes32 key) internal returns (bool) {
return remove(map._inner, key);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool) {
return contains(map._inner, key);
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the set. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32, uint256) {
(bytes32 key, bytes32 value) = at(map._inner, index);
return (key, uint256(value));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
(bool success, bytes32 value) = tryGet(map._inner, key);
return (success, uint256(value));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
return uint256(get(map._inner, key));
}
/**
* @dev Same as {get}, with a custom error message when `key` is not in the map.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryGet}.
*/
function get(
Bytes32ToUintMap storage map,
bytes32 key,
string memory errorMessage
) internal view returns (uint256) {
return uint256(get(map._inner, key, errorMessage));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/introspection/ERC165Checker.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Library used to query support of an interface declared via {IERC165}.
*
* Note that these functions return the actual result of the query: they do not
* `revert` if an interface is not supported. It is up to the caller to decide
* what to do in these cases.
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
/**
* @dev Returns true if `account` supports the {IERC165} interface.
*/
function supportsERC165(address account) internal view returns (bool) {
// Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
}
/**
* @dev Returns true if `account` supports the interface defined by
* `interfaceId`. Support for {IERC165} itself is queried automatically.
*
* See {IERC165-supportsInterface}.
*/
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
// query support of both ERC165 as per the spec and support of _interfaceId
return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
}
/**
* @dev Returns a boolean array where each value corresponds to the
* interfaces passed in and whether they're supported or not. This allows
* you to batch check interfaces for a contract where your expectation
* is that some interfaces may not be supported.
*
* See {IERC165-supportsInterface}.
*
* _Available since v3.4._
*/
function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)
internal
view
returns (bool[] memory)
{
// an array of booleans corresponding to interfaceIds and whether they're supported or not
bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
// query support of ERC165 itself
if (supportsERC165(account)) {
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
}
}
return interfaceIdsSupported;
}
/**
* @dev Returns true if `account` supports all the interfaces defined in
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
*
* Batch-querying can lead to gas savings by skipping repeated checks for
* {IERC165} support.
*
* See {IERC165-supportsInterface}.
*/
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
// query support of ERC165 itself
if (!supportsERC165(account)) {
return false;
}
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
return false;
}
}
// all interfaces supported
return true;
}
/**
* @notice Query if a contract implements an interface, does not check ERC165 support
* @param account The address of the contract to query for support of an interface
* @param interfaceId The interface identifier, as specified in ERC-165
* @return true if the contract at account indicates support of the interface with
* identifier interfaceId, false otherwise
* @dev Assumes that account contains a contract that supports ERC165, otherwise
* the behavior of this method is undefined. This precondition can be checked
* with {supportsERC165}.
* Interface identification is specified in ERC-165.
*/
function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
// prepare call
bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
// perform static call
bool success;
uint256 returnSize;
uint256 returnValue;
assembly {
success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
returnSize := returndatasize()
returnValue := mload(0x00)
}
return success && returnSize >= 0x20 && returnValue > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() external {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://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 functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// 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;
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../IERC1155Receiver.sol";
import "../../../utils/introspection/ERC165.sol";
/**
* @dev _Available since v3.1._
*/
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}{
"remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/src/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false,
"libraries": {}
}Contract ABI
API[{"inputs":[],"name":"VaultAlreadyDeployed","type":"error"},{"inputs":[],"name":"VaultDoesNotExist","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"symbol","type":"string"},{"indexed":true,"internalType":"contract INftVault","name":"vault","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"indexed":false,"internalType":"struct INftVault.CollectionData[]","name":"collections","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"creator","type":"address"}],"name":"VaultCreated","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"createVault","outputs":[{"internalType":"contract INftVault","name":"vault","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllVaults","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"getVault","outputs":[{"internalType":"contract INftVault","name":"vault","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getVaultAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVaultLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"hashVault","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"isVault","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"vaultHashMap","outputs":[{"internalType":"contract INftVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INftVault","name":"","type":"address"}],"name":"vaultIdMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b506138d5806100206000396000f3fe60806040523480156200001157600080fd5b5060043610620000ab5760003560e01c806397331bf9116200006e57806397331bf914620001685780639ac246871462000181578063d126fc191462000198578063f396455114620001bb578063f68790c714620001d257600080fd5b806354af84a114620000b0578063652b9b4114620000e457806374449c60146200010c5780637a98742d1462000138578063812617c7146200014f575b600080fd5b620000c7620000c1366004620008cf565b620001e9565b6040516001600160a01b0390911681526020015b60405180910390f35b620000fb620000f536600462000a0f565b620003e0565b6040519015158152602001620000db565b620000c76200011d36600462000a2f565b6002602052600090815260409020546001600160a01b031681565b620000c76200014936600462000a2f565b620003f4565b6200015962000402565b604051908152602001620000db565b6200017262000415565b604051620000db919062000a49565b6200015962000192366004620008cf565b62000423565b62000159620001a936600462000a0f565b60036020526000908152604090205481565b620000c7620001cc366004620008cf565b62000455565b620000fb620001e3366004620008cf565b620004a6565b600080620001f78362000423565b6000818152600260205260409020546001600160a01b0316925090508115620002335760405163674c951b60e11b815260040160405180910390fd5b6000606080620002446000620004d9565b92506200025183620004e4565b60405160200162000263919062000abe565b60405160208183030381529060405291506200027f83620004e4565b60405160200162000291919062000af4565b60405160208183030381529060405290508181604051620002b29062000798565b620002bf92919062000b56565b604051809103906000f080158015620002dc573d6000803e3d6000fd5b50604051633e66176160e11b81529095506001600160a01b03861690637ccc2ec2906200030e90899060040162000c62565b600060405180830381600087803b1580156200032957600080fd5b505af11580156200033e573d6000803e3d6000fd5b50505050620003588560006200057e90919063ffffffff16565b50600084815260026020908152604080832080546001600160a01b0319166001600160a01b038a1690811790915580845260039092529182902085905590518491907fcb0452bbe0e1599038236fd7a1588dd53cef35a83f2c1a6aeb71f42c3160b98290620003cf90869086908c90339062000c77565b60405180910390a350505050919050565b6000620003ee81836200059c565b92915050565b6000620003ee8183620005bf565b6000620004106000620004d9565b905090565b6060620004106000620005cd565b60008160405160200162000438919062000c62565b604051602081830303815290604052805190602001209050919050565b600060026000620004668462000423565b81526020810191909152604001600020546001600160a01b0316905080620004a157604051634d827f1760e01b815260040160405180910390fd5b919050565b600080600281620004b78562000423565b81526020810191909152604001600020546001600160a01b0316141592915050565b6000620003ee825490565b60606000620004f383620005dc565b600101905060008167ffffffffffffffff811115620005165762000516620007a6565b6040519080825280601f01601f19166020018201604052801562000541576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846200054b57509392505050565b600062000595836001600160a01b038416620006bb565b9392505050565b6001600160a01b0381166000908152600183016020526040812054151562000595565b60006200059583836200070d565b6060600062000595836200073a565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106200061c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef8100000000831062000649576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106200066857662386f26fc10000830492506010015b6305f5e100831062000681576305f5e100830492506008015b61271083106200069657612710830492506004015b60648310620006a9576064830492506002015b600a8310620003ee5760010192915050565b60008181526001830160205260408120546200070457508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620003ee565b506000620003ee565b600082600001828154811062000727576200072762000cd0565b9060005260206000200154905092915050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156200078c57602002820191906000526020600020905b81548152602001906001019080831162000777575b50505050509050919050565b612be28062000ce783390190565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff81118282101715620007e257620007e2620007a6565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715620008145762000814620007a6565b604052919050565b600067ffffffffffffffff821115620008395762000839620007a6565b5060051b60200190565b6001600160a01b03811681146200085957600080fd5b50565b600082601f8301126200086e57600080fd5b813560206200088762000881836200081c565b620007e8565b82815260059290921b84018101918181019086841115620008a757600080fd5b8286015b84811015620008c45780358352918301918301620008ab565b509695505050505050565b60006020808385031215620008e357600080fd5b823567ffffffffffffffff80821115620008fc57600080fd5b818501915085601f8301126200091157600080fd5b81356200092262000881826200081c565b81815260059190911b830184019084810190888311156200094257600080fd5b8585015b8381101562000a0257803585811115620009605760008081fd5b86016080818c03601f1901811315620009795760008081fd5b62000983620007bc565b89830135620009928162000843565b815260408381013560028110620009a95760008081fd5b828c01526060848101358015158114620009c35760008081fd5b83830152928401359289841115620009dd57600091508182fd5b620009ed8f8d868801016200085c565b90830152508552505091860191860162000946565b5098975050505050505050565b60006020828403121562000a2257600080fd5b8135620005958162000843565b60006020828403121562000a4257600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101562000a8c5783516001600160a01b03168352928401929184019160010162000a65565b50909695505050505050565b60005b8381101562000ab557818101518382015260200162000a9b565b50506000910152565b6b026b0b3b4b1902b30bab63a160a51b81526000825162000ae781600c85016020870162000a98565b91909101600c0192915050565b69135859da58d5985d5b1d60b21b81526000825162000b1b81600a85016020870162000a98565b91909101600a0192915050565b6000815180845262000b4281602086016020860162000a98565b601f01601f19169290920160200192915050565b60408152600062000b6b604083018562000b28565b828103602084015262000b7f818562000b28565b95945050505050565b600081518084526020808501808196508360051b8101915082860160005b8581101562000c55578284038952815180516001600160a01b0316855285810151608090818701906002811062000bed57634e487b7160e01b600052602160045260246000fd5b87890152604083810151151590880152606092830151928701919091528151908190529086019060a08601906000905b8082101562000c3f578351835292880192918801916001919091019062000c1d565b5050998601999450509084019060010162000ba6565b5091979650505050505050565b60208152600062000595602083018462000b88565b60808152600062000c8c608083018762000b28565b828103602084015262000ca0818762000b28565b9050828103604084015262000cb6818662000b88565b91505060018060a01b038316606083015295945050505050565b634e487b7160e01b600052603260045260246000fdfe60c06040523480156200001157600080fd5b5060405162002be238038062002be2833981016040819052620000349162000161565b818160036200004483826200025a565b5060046200005382826200025a565b5062000060915050601290565b6200006d90600a6200043b565b60808190526103e89062000084906103e762000453565b6200009091906200046d565b60a05250620004909050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620000c457600080fd5b81516001600160401b0380821115620000e157620000e16200009c565b604051601f8301601f19908116603f011681019082821181831017156200010c576200010c6200009c565b816040528381526020925086838588010111156200012957600080fd5b600091505b838210156200014d57858201830151818301840152908201906200012e565b600093810190920192909252949350505050565b600080604083850312156200017557600080fd5b82516001600160401b03808211156200018d57600080fd5b6200019b86838701620000b2565b93506020850151915080821115620001b257600080fd5b50620001c185828601620000b2565b9150509250929050565b600181811c90821680620001e057607f821691505b6020821081036200020157634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200025557600081815260208120601f850160051c81016020861015620002305750805b601f850160051c820191505b8181101562000251578281556001016200023c565b5050505b505050565b81516001600160401b038111156200027657620002766200009c565b6200028e81620002878454620001cb565b8462000207565b602080601f831160018114620002c65760008415620002ad5750858301515b600019600386901b1c1916600185901b17855562000251565b600085815260208120601f198616915b82811015620002f757888601518255948401946001909101908401620002d6565b5085821015620003165787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b808511156200037d57816000190482111562000361576200036162000326565b808516156200036f57918102915b93841c939080029062000341565b509250929050565b600082620003965750600162000435565b81620003a55750600062000435565b8160018114620003be5760028114620003c957620003e9565b600191505062000435565b60ff841115620003dd57620003dd62000326565b50506001821b62000435565b5060208310610133831016604e8410600b84101617156200040e575081810a62000435565b6200041a83836200033c565b806000190482111562000431576200043162000326565b0290505b92915050565b60006200044c60ff84168362000385565b9392505050565b808202811582820484141762000435576200043562000326565b6000826200048b57634e487b7160e01b600052601260045260246000fd5b500490565b60805160a051612702620004e0600039600081816103d501528181610a720152610d3901526000818161046f01528181610a2f01528181610a9301528181610cff0152610d5d01526127026000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c80637bfe950c1161010f578063a457c2d7116100a2578063c2ee3a0811610071578063c2ee3a081461046a578063cbf1304d14610491578063dd62ed3e146104bc578063f23a6e61146104cf57600080fd5b8063a457c2d714610412578063a9059cbb14610425578063b58d775014610438578063bc197c811461044b57600080fd5b806386937eb4116100de57806386937eb4146103bd5780638b878cb2146103d057806395d89b41146103f75780639ac24687146103ff57600080fd5b80637bfe950c146103795780637cc253701461038c5780637ccc2ec2146103955780637ddc2cd1146103aa57600080fd5b806320e8c565116101875780633a51f383116101565780633a51f383146103205780634c4c45de1461033557806356359baa1461034857806370a082311461035057600080fd5b806320e8c565146102d857806323b872dd146102eb578063313ce567146102fe578063395093511461030d57600080fd5b80630c7056b8116101c35780630c7056b814610265578063139f114414610286578063150b7a021461029957806318160ddd146102d057600080fd5b806301ffc9a7146101f557806306d81bf41461021d57806306fdde031461023d578063095ea7b314610252575b600080fd5b610208610203366004611d1b565b6104ee565b60405190151581526020015b60405180910390f35b61023061022b366004611d5d565b610525565b6040516102149190611e25565b61024561061f565b6040516102149190611e7e565b610208610260366004611e91565b6106b1565b610278610273366004611ed1565b6106c9565b604051908152602001610214565b610278610294366004611e91565b61079d565b6102b76102a7366004611fe6565b630a85bd0160e11b949350505050565b6040516001600160e01b03199091168152602001610214565b600254610278565b6102786102e6366004612052565b610947565b6102086102f9366004612098565b610ae1565b60405160128152602001610214565b61020861031b366004611e91565b610b05565b610328610b27565b60405161021491906120d9565b6102786103433660046121aa565b610bd5565b610278610c60565b61027861035e366004611d5d565b6001600160a01b031660009081526020819052604090205490565b610278610387366004612052565b610c71565b61027860055481565b6103a86103a3366004612299565b610f40565b005b6103a86103b83660046123be565b6111f1565b6102786103cb3660046121aa565b611300565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b610245611382565b61027861040d366004612299565b611391565b610208610420366004611e91565b6113c1565b610208610433366004611e91565b611441565b610208610446366004611e91565b61144f565b6102b7610459366004612417565b63bc197c8160e01b95945050505050565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b61027861049f366004611e91565b600a60209081526000928352604080842090915290825290205481565b6102786104ca3660046124c5565b6114bd565b6102b76104dd3660046124fe565b63f23a6e6160e01b95945050505050565b60006001600160e01b03198216630271189760e51b148061051f57506301ffc9a760e01b6001600160e01b03198316145b92915050565b604080516080810182526000808252602082018190529181019190915260608082015260408051608081019091526001600160a01b03831681526020810161056e6006856114e8565b600181111561057f5761057f611d7a565b600181111561059057610590611d7a565b81526001600160a01b0384166000818152600960208181526040808420600281015460ff16151583880152949093529081526001909201805482518185028101850184528181529290940193919290919083018282801561061057602002820191906000526020600020905b8154815260200190600101908083116105fc575b50505050508152509050919050565b60606003805461062e90612567565b80601f016020809104026020016040519081016040528092919081815260200182805461065a90612567565b80156106a75780601f1061067c576101008083540402835291602001916106a7565b820191906000526020600020905b81548152906001019060200180831161068a57829003601f168201915b5050505050905090565b6000336106bf818585611504565b5060019392505050565b6000806106dd846380ac58cd60e01b611629565b905060006106f285636cdb3d1360e11b611629565b90508180156106ff575080155b801561071d5750600084600181111561071a5761071a611d7a565b14155b1561073b57604051630617a45f60e21b815260040160405180910390fd5b808015610746575081155b80156107645750600184600181111561076157610761611d7a565b14155b1561078257604051632905a02760e11b815260040160405180910390fd5b83600181111561079457610794611d7a565b95945050505050565b6001600160a01b0382166000908152600a60209081526040808320848452909152812054816107cd6006866114e8565b60018111156107de576107de611d7a565b905060008160018111156107f4576107f4611d7a565b03610893578115801561087857506040516331a9108f60e11b81526004810185905230906001600160a01b03871690636352211e90602401602060405180830381865afa158015610849573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086d91906125a1565b6001600160a01b0316145b156108885760019250505061051f565b60009250505061051f565b60018160018111156108a7576108a7611d7a565b0361092e57604051627eeac760e11b81523060048201526024810185905282906001600160a01b0387169062fdd58e90604401602060405180830381865afa1580156108f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091b91906125be565b61092591906125ed565b9250505061051f565b6040516349f157c160e01b815260040160405180910390fd5b6000610953848461144f565b6109705760405163edcb51b160e01b815260040160405180910390fd5b600061097c858561079d565b905082158061098a57508281105b156109a8576040516349986e7360e01b815260040160405180910390fd5b6001600160a01b0385166000908152600a60209081526040808320878452909152812080548592906109db908490612600565b909155505060408051858152602081018590526001600160a01b0380881692908916917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3610a53837f0000000000000000000000000000000000000000000000000000000000000000612613565b91506000610a6060025490565b9050600081118015610abb5750610ab77f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006125ed565b8111155b15610acd57610aca81846125ed565b92505b610ad78784611645565b5050949350505050565b600033610aef858285611704565b610afa85858561177e565b506001949350505050565b6000336106bf818585610b1883836114bd565b610b229190612600565b611504565b6060610b336006611922565b67ffffffffffffffff811115610b4b57610b4b611f06565b604051908082528060200260200182016040528015610b74578160200160208202803683370190505b50905060005b8151811015610bd1576000610b9060068361192d565b50905080838381518110610ba657610ba661262a565b6001600160a01b03909216602092830291909101909101525080610bc981612640565b915050610b7a565b5090565b6000805b8451811015610c5757610c3986868381518110610bf857610bf861262a565b6020026020010151868481518110610c1257610c1261262a565b6020026020010151868581518110610c2c57610c2c61262a565b6020026020010151610947565b610c439083612600565b915080610c4f81612640565b915050610bd9565b50949350505050565b6000610c6c6006611922565b905090565b6000811580610ca257506001600160a01b0384166000908152600a6020908152604080832086845290915290205482115b15610cc0576040516349986e7360e01b815260040160405180910390fd5b6001600160a01b0384166000908152600a6020908152604080832086845290915281208054849290610cf39084906125ed565b90915550610d239050827f0000000000000000000000000000000000000000000000000000000000000000612613565b905080610d2f60025490565b148015610d9f57507f0000000000000000000000000000000000000000000000000000000000000000610d827f0000000000000000000000000000000000000000000000000000000000000000836125ed565b610d8c9190612600565b3060009081526020819052604090205410155b15610db65750306000908152602081905260409020545b610dc0308261194b565b6000610dcd6006866114e8565b6001811115610dde57610dde611d7a565b90506000816001811115610df457610df4611d7a565b03610e885782600114610e1a5760405163545c577160e01b815260040160405180910390fd5b604051632142170760e11b81523060048201526001600160a01b038781166024830152604482018690528616906342842e0e906064015b600060405180830381600087803b158015610e6b57600080fd5b505af1158015610e7f573d6000803e3d6000fd5b50505050610ee1565b6001816001811115610e9c57610e9c611d7a565b0361092e5760408051602081018252600081529051637921219560e11b81526001600160a01b0387169163f242432a91610e519130918b918a918a9190600401612659565b846001600160a01b0316866001600160a01b03167ff341246adaac6f497bc2a656f546ab9e182111d630394f0c57c710a59a2cb5678686604051610f2f929190918252602082015260400190565b60405180910390a350949350505050565b8051600003610f625760405163400277cd60e11b815260040160405180910390fd5b6000610f6e6006611922565b1115610f8d576040516302ed543d60e51b815260040160405180910390fd5b610f9681611391565b60055560005b81518110156111ed576000828281518110610fb957610fb961262a565b6020026020010151905080604001518015610fd957506000816060015151115b15610ff757604051634cdbbbef60e11b815260040160405180910390fd5b600061100b826000015183602001516106c9565b825190915061101d9060069083611a75565b61103a57604051630cc656b760e21b815260040160405180910390fd5b60408281015183516001600160a01b031660009081526009602052829020600201805460ff1916911515919091179055517f2ebca503d1d899889b8a6d039632aa576bbff8cb8233491fbaece7f7773c341790611098908490611e25565b60405180910390a18160400151156110b15750506111db565b8160600151516000036110d7576040516390f22bf160e01b815260040160405180910390fd5b6000805b8360600151518110156111d6576000846060015182815181106111005761110061262a565b602002602001015190508281101561112b57604051631f13bcf760e21b815260040160405180910390fd5b80925084516001600160a01b0316600090815260096020908152604080832084845290915290205460ff16156111745760405163403b2b6760e01b815260040160405180910390fd5b84516001600160a01b0390811660009081526009602081815260408084208685528252808420805460ff191660019081179091558a519095168452918152908220830180549384018155825290200155806111ce81612640565b9150506110db565b505050505b806111e581612640565b915050610f9c565b5050565b6111fb838361144f565b156112195760405163578d6bb760e11b815260040160405180910390fd5b600084600181111561122d5761122d611d7a565b036112a057604051632142170760e11b81523060048201526001600160a01b038681166024830152604482018490528416906342842e0e906064015b600060405180830381600087803b15801561128357600080fd5b505af1158015611297573d6000803e3d6000fd5b505050506112f9565b60018460018111156112b4576112b4611d7a565b0361092e5760408051602081018252600081529051637921219560e11b81526001600160a01b0385169163f242432a916112699130918a918891889190600401612659565b5050505050565b6000805b8451811015610c5757611364868683815181106113235761132361262a565b602002602001015186848151811061133d5761133d61262a565b60200260200101518685815181106113575761135761262a565b6020026020010151610c71565b61136e9083612600565b91508061137a81612640565b915050611304565b60606004805461062e90612567565b6000816040516020016113a49190612693565b604051602081830303815290604052805190602001209050919050565b600033816113cf82866114bd565b9050838110156114345760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610afa8286868403611504565b6000336106bf81858561177e565b60008061145d600685611a8b565b5090508080156114b557506001600160a01b03841660009081526009602052604090206002015460ff16806114b557506001600160a01b038416600090815260096020908152604080832086845290915290205460ff165b949350505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006114fd836001600160a01b038416611aa3565b9392505050565b6001600160a01b0383166115665760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161142b565b6001600160a01b0382166115c75760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161142b565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b600061163483611b13565b80156114fd57506114fd8383611b46565b6001600160a01b03821661169b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161142b565b80600260008282546116ad9190612600565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600061171084846114bd565b90506000198114611778578181101561176b5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161142b565b6117788484848403611504565b50505050565b6001600160a01b0383166117e25760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161142b565b6001600160a01b0382166118445760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161142b565b6001600160a01b038316600090815260208190526040902054818110156118bc5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161142b565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3611778565b600061051f82611bcf565b600080808061193c8686611bda565b909450925050505b9250929050565b6001600160a01b0382166119ab5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161142b565b6001600160a01b03821660009081526020819052604090205481811015611a1f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161142b565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910161161c565b60006114b5846001600160a01b03851684611c05565b600080808061193c866001600160a01b038716611c22565b600081815260028301602052604081205480151580611ac75750611ac78484611c5c565b6114fd5760405162461bcd60e51b815260206004820152601e60248201527f456e756d657261626c654d61703a206e6f6e6578697374656e74206b65790000604482015260640161142b565b6000611b26826301ffc9a760e01b611b46565b801561051f5750611b3f826001600160e01b0319611b46565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015611bb8575060208210155b8015611bc45750600081115b979650505050505050565b600061051f82611c68565b60008080611be88585611c72565b600081815260029690960160205260409095205494959350505050565b600082815260028401602052604081208290556114b58484611c7e565b6000818152600283016020526040812054819080611c5157611c448585611c5c565b9250600091506119449050565b600192509050611944565b60006114fd8383611c8a565b600061051f825490565b60006114fd8383611ca2565b60006114fd8383611ccc565b600081815260018301602052604081205415156114fd565b6000826000018281548110611cb957611cb961262a565b9060005260206000200154905092915050565b6000818152600183016020526040812054611d135750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561051f565b50600061051f565b600060208284031215611d2d57600080fd5b81356001600160e01b0319811681146114fd57600080fd5b6001600160a01b0381168114611d5a57600080fd5b50565b600060208284031215611d6f57600080fd5b81356114fd81611d45565b634e487b7160e01b600052602160045260246000fd5b80516001600160a01b03168252602080820151600091608085019160028110611dc957634e487b7160e01b600052602160045260246000fd5b8582015260408481015115159086015260608085015160809187019190915280519283905281019160009060a08701905b80831015611e1a5784518252938301936001929092019190830190611dfa565b509695505050505050565b6020815260006114fd6020830184611d90565b6000815180845260005b81811015611e5e57602081850181015186830182015201611e42565b506000602082860101526020601f19601f83011685010191505092915050565b6020815260006114fd6020830184611e38565b60008060408385031215611ea457600080fd5b8235611eaf81611d45565b946020939093013593505050565b803560028110611ecc57600080fd5b919050565b60008060408385031215611ee457600080fd5b8235611eef81611d45565b9150611efd60208401611ebd565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff81118282101715611f3f57611f3f611f06565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611f6e57611f6e611f06565b604052919050565b600082601f830112611f8757600080fd5b813567ffffffffffffffff811115611fa157611fa1611f06565b611fb4601f8201601f1916602001611f45565b818152846020838601011115611fc957600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215611ffc57600080fd5b843561200781611d45565b9350602085013561201781611d45565b925060408501359150606085013567ffffffffffffffff81111561203a57600080fd5b61204687828801611f76565b91505092959194509250565b6000806000806080858703121561206857600080fd5b843561207381611d45565b9350602085013561208381611d45565b93969395505050506040820135916060013590565b6000806000606084860312156120ad57600080fd5b83356120b881611d45565b925060208401356120c881611d45565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b8181101561211a5783516001600160a01b0316835292840192918401916001016120f5565b50909695505050505050565b600067ffffffffffffffff82111561214057612140611f06565b5060051b60200190565b600082601f83011261215b57600080fd5b8135602061217061216b83612126565b611f45565b82815260059290921b8401810191818101908684111561218f57600080fd5b8286015b84811015611e1a5780358352918301918301612193565b600080600080608085870312156121c057600080fd5b84356121cb81611d45565b935060208581013567ffffffffffffffff808211156121e957600080fd5b818801915088601f8301126121fd57600080fd5b813561220b61216b82612126565b81815260059190911b8301840190848101908b83111561222a57600080fd5b938501935b8285101561225157843561224281611d45565b8252938501939085019061222f565b97505050604088013592508083111561226957600080fd5b61227589848a0161214a565b9450606088013592508083111561228b57600080fd5b50506120468782880161214a565b600060208083850312156122ac57600080fd5b823567ffffffffffffffff808211156122c457600080fd5b818501915085601f8301126122d857600080fd5b81356122e661216b82612126565b81815260059190911b8301840190848101908883111561230557600080fd5b8585015b838110156123b1578035858111156123215760008081fd5b86016080818c03601f19018113156123395760008081fd5b612341611f1c565b8983013561234e81611d45565b8152604061235d848201611ebd565b8b83015260608085013580151581146123765760008081fd5b8383015292840135928984111561238f57600091508182fd5b61239d8f8d8688010161214a565b908301525085525050918601918601612309565b5098975050505050505050565b600080600080600060a086880312156123d657600080fd5b85356123e181611d45565b94506123ef60208701611ebd565b935060408601356123ff81611d45565b94979396509394606081013594506080013592915050565b600080600080600060a0868803121561242f57600080fd5b853561243a81611d45565b9450602086013561244a81611d45565b9350604086013567ffffffffffffffff8082111561246757600080fd5b61247389838a0161214a565b9450606088013591508082111561248957600080fd5b61249589838a0161214a565b935060808801359150808211156124ab57600080fd5b506124b888828901611f76565b9150509295509295909350565b600080604083850312156124d857600080fd5b82356124e381611d45565b915060208301356124f381611d45565b809150509250929050565b600080600080600060a0868803121561251657600080fd5b853561252181611d45565b9450602086013561253181611d45565b93506040860135925060608601359150608086013567ffffffffffffffff81111561255b57600080fd5b6124b888828901611f76565b600181811c9082168061257b57607f821691505b60208210810361259b57634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156125b357600080fd5b81516114fd81611d45565b6000602082840312156125d057600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561051f5761051f6125d7565b8082018082111561051f5761051f6125d7565b808202811582820484141761051f5761051f6125d7565b634e487b7160e01b600052603260045260246000fd5b600060018201612652576126526125d7565b5060010190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090611bc490830184611e38565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156126e857603f198886030184526126d6858351611d90565b945092850192908501906001016126ba565b509297965050505050505056fea164736f6c6343000812000aa164736f6c6343000812000a
Deployed Bytecode
0x60806040523480156200001157600080fd5b5060043610620000ab5760003560e01c806397331bf9116200006e57806397331bf914620001685780639ac246871462000181578063d126fc191462000198578063f396455114620001bb578063f68790c714620001d257600080fd5b806354af84a114620000b0578063652b9b4114620000e457806374449c60146200010c5780637a98742d1462000138578063812617c7146200014f575b600080fd5b620000c7620000c1366004620008cf565b620001e9565b6040516001600160a01b0390911681526020015b60405180910390f35b620000fb620000f536600462000a0f565b620003e0565b6040519015158152602001620000db565b620000c76200011d36600462000a2f565b6002602052600090815260409020546001600160a01b031681565b620000c76200014936600462000a2f565b620003f4565b6200015962000402565b604051908152602001620000db565b6200017262000415565b604051620000db919062000a49565b6200015962000192366004620008cf565b62000423565b62000159620001a936600462000a0f565b60036020526000908152604090205481565b620000c7620001cc366004620008cf565b62000455565b620000fb620001e3366004620008cf565b620004a6565b600080620001f78362000423565b6000818152600260205260409020546001600160a01b0316925090508115620002335760405163674c951b60e11b815260040160405180910390fd5b6000606080620002446000620004d9565b92506200025183620004e4565b60405160200162000263919062000abe565b60405160208183030381529060405291506200027f83620004e4565b60405160200162000291919062000af4565b60405160208183030381529060405290508181604051620002b29062000798565b620002bf92919062000b56565b604051809103906000f080158015620002dc573d6000803e3d6000fd5b50604051633e66176160e11b81529095506001600160a01b03861690637ccc2ec2906200030e90899060040162000c62565b600060405180830381600087803b1580156200032957600080fd5b505af11580156200033e573d6000803e3d6000fd5b50505050620003588560006200057e90919063ffffffff16565b50600084815260026020908152604080832080546001600160a01b0319166001600160a01b038a1690811790915580845260039092529182902085905590518491907fcb0452bbe0e1599038236fd7a1588dd53cef35a83f2c1a6aeb71f42c3160b98290620003cf90869086908c90339062000c77565b60405180910390a350505050919050565b6000620003ee81836200059c565b92915050565b6000620003ee8183620005bf565b6000620004106000620004d9565b905090565b6060620004106000620005cd565b60008160405160200162000438919062000c62565b604051602081830303815290604052805190602001209050919050565b600060026000620004668462000423565b81526020810191909152604001600020546001600160a01b0316905080620004a157604051634d827f1760e01b815260040160405180910390fd5b919050565b600080600281620004b78562000423565b81526020810191909152604001600020546001600160a01b0316141592915050565b6000620003ee825490565b60606000620004f383620005dc565b600101905060008167ffffffffffffffff811115620005165762000516620007a6565b6040519080825280601f01601f19166020018201604052801562000541576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846200054b57509392505050565b600062000595836001600160a01b038416620006bb565b9392505050565b6001600160a01b0381166000908152600183016020526040812054151562000595565b60006200059583836200070d565b6060600062000595836200073a565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106200061c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef8100000000831062000649576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106200066857662386f26fc10000830492506010015b6305f5e100831062000681576305f5e100830492506008015b61271083106200069657612710830492506004015b60648310620006a9576064830492506002015b600a8310620003ee5760010192915050565b60008181526001830160205260408120546200070457508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620003ee565b506000620003ee565b600082600001828154811062000727576200072762000cd0565b9060005260206000200154905092915050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156200078c57602002820191906000526020600020905b81548152602001906001019080831162000777575b50505050509050919050565b612be28062000ce783390190565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff81118282101715620007e257620007e2620007a6565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715620008145762000814620007a6565b604052919050565b600067ffffffffffffffff821115620008395762000839620007a6565b5060051b60200190565b6001600160a01b03811681146200085957600080fd5b50565b600082601f8301126200086e57600080fd5b813560206200088762000881836200081c565b620007e8565b82815260059290921b84018101918181019086841115620008a757600080fd5b8286015b84811015620008c45780358352918301918301620008ab565b509695505050505050565b60006020808385031215620008e357600080fd5b823567ffffffffffffffff80821115620008fc57600080fd5b818501915085601f8301126200091157600080fd5b81356200092262000881826200081c565b81815260059190911b830184019084810190888311156200094257600080fd5b8585015b8381101562000a0257803585811115620009605760008081fd5b86016080818c03601f1901811315620009795760008081fd5b62000983620007bc565b89830135620009928162000843565b815260408381013560028110620009a95760008081fd5b828c01526060848101358015158114620009c35760008081fd5b83830152928401359289841115620009dd57600091508182fd5b620009ed8f8d868801016200085c565b90830152508552505091860191860162000946565b5098975050505050505050565b60006020828403121562000a2257600080fd5b8135620005958162000843565b60006020828403121562000a4257600080fd5b5035919050565b6020808252825182820181905260009190848201906040850190845b8181101562000a8c5783516001600160a01b03168352928401929184019160010162000a65565b50909695505050505050565b60005b8381101562000ab557818101518382015260200162000a9b565b50506000910152565b6b026b0b3b4b1902b30bab63a160a51b81526000825162000ae781600c85016020870162000a98565b91909101600c0192915050565b69135859da58d5985d5b1d60b21b81526000825162000b1b81600a85016020870162000a98565b91909101600a0192915050565b6000815180845262000b4281602086016020860162000a98565b601f01601f19169290920160200192915050565b60408152600062000b6b604083018562000b28565b828103602084015262000b7f818562000b28565b95945050505050565b600081518084526020808501808196508360051b8101915082860160005b8581101562000c55578284038952815180516001600160a01b0316855285810151608090818701906002811062000bed57634e487b7160e01b600052602160045260246000fd5b87890152604083810151151590880152606092830151928701919091528151908190529086019060a08601906000905b8082101562000c3f578351835292880192918801916001919091019062000c1d565b5050998601999450509084019060010162000ba6565b5091979650505050505050565b60208152600062000595602083018462000b88565b60808152600062000c8c608083018762000b28565b828103602084015262000ca0818762000b28565b9050828103604084015262000cb6818662000b88565b91505060018060a01b038316606083015295945050505050565b634e487b7160e01b600052603260045260246000fdfe60c06040523480156200001157600080fd5b5060405162002be238038062002be2833981016040819052620000349162000161565b818160036200004483826200025a565b5060046200005382826200025a565b5062000060915050601290565b6200006d90600a6200043b565b60808190526103e89062000084906103e762000453565b6200009091906200046d565b60a05250620004909050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620000c457600080fd5b81516001600160401b0380821115620000e157620000e16200009c565b604051601f8301601f19908116603f011681019082821181831017156200010c576200010c6200009c565b816040528381526020925086838588010111156200012957600080fd5b600091505b838210156200014d57858201830151818301840152908201906200012e565b600093810190920192909252949350505050565b600080604083850312156200017557600080fd5b82516001600160401b03808211156200018d57600080fd5b6200019b86838701620000b2565b93506020850151915080821115620001b257600080fd5b50620001c185828601620000b2565b9150509250929050565b600181811c90821680620001e057607f821691505b6020821081036200020157634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200025557600081815260208120601f850160051c81016020861015620002305750805b601f850160051c820191505b8181101562000251578281556001016200023c565b5050505b505050565b81516001600160401b038111156200027657620002766200009c565b6200028e81620002878454620001cb565b8462000207565b602080601f831160018114620002c65760008415620002ad5750858301515b600019600386901b1c1916600185901b17855562000251565b600085815260208120601f198616915b82811015620002f757888601518255948401946001909101908401620002d6565b5085821015620003165787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b808511156200037d57816000190482111562000361576200036162000326565b808516156200036f57918102915b93841c939080029062000341565b509250929050565b600082620003965750600162000435565b81620003a55750600062000435565b8160018114620003be5760028114620003c957620003e9565b600191505062000435565b60ff841115620003dd57620003dd62000326565b50506001821b62000435565b5060208310610133831016604e8410600b84101617156200040e575081810a62000435565b6200041a83836200033c565b806000190482111562000431576200043162000326565b0290505b92915050565b60006200044c60ff84168362000385565b9392505050565b808202811582820484141762000435576200043562000326565b6000826200048b57634e487b7160e01b600052601260045260246000fd5b500490565b60805160a051612702620004e0600039600081816103d501528181610a720152610d3901526000818161046f01528181610a2f01528181610a9301528181610cff0152610d5d01526127026000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c80637bfe950c1161010f578063a457c2d7116100a2578063c2ee3a0811610071578063c2ee3a081461046a578063cbf1304d14610491578063dd62ed3e146104bc578063f23a6e61146104cf57600080fd5b8063a457c2d714610412578063a9059cbb14610425578063b58d775014610438578063bc197c811461044b57600080fd5b806386937eb4116100de57806386937eb4146103bd5780638b878cb2146103d057806395d89b41146103f75780639ac24687146103ff57600080fd5b80637bfe950c146103795780637cc253701461038c5780637ccc2ec2146103955780637ddc2cd1146103aa57600080fd5b806320e8c565116101875780633a51f383116101565780633a51f383146103205780634c4c45de1461033557806356359baa1461034857806370a082311461035057600080fd5b806320e8c565146102d857806323b872dd146102eb578063313ce567146102fe578063395093511461030d57600080fd5b80630c7056b8116101c35780630c7056b814610265578063139f114414610286578063150b7a021461029957806318160ddd146102d057600080fd5b806301ffc9a7146101f557806306d81bf41461021d57806306fdde031461023d578063095ea7b314610252575b600080fd5b610208610203366004611d1b565b6104ee565b60405190151581526020015b60405180910390f35b61023061022b366004611d5d565b610525565b6040516102149190611e25565b61024561061f565b6040516102149190611e7e565b610208610260366004611e91565b6106b1565b610278610273366004611ed1565b6106c9565b604051908152602001610214565b610278610294366004611e91565b61079d565b6102b76102a7366004611fe6565b630a85bd0160e11b949350505050565b6040516001600160e01b03199091168152602001610214565b600254610278565b6102786102e6366004612052565b610947565b6102086102f9366004612098565b610ae1565b60405160128152602001610214565b61020861031b366004611e91565b610b05565b610328610b27565b60405161021491906120d9565b6102786103433660046121aa565b610bd5565b610278610c60565b61027861035e366004611d5d565b6001600160a01b031660009081526020819052604090205490565b610278610387366004612052565b610c71565b61027860055481565b6103a86103a3366004612299565b610f40565b005b6103a86103b83660046123be565b6111f1565b6102786103cb3660046121aa565b611300565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b610245611382565b61027861040d366004612299565b611391565b610208610420366004611e91565b6113c1565b610208610433366004611e91565b611441565b610208610446366004611e91565b61144f565b6102b7610459366004612417565b63bc197c8160e01b95945050505050565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b61027861049f366004611e91565b600a60209081526000928352604080842090915290825290205481565b6102786104ca3660046124c5565b6114bd565b6102b76104dd3660046124fe565b63f23a6e6160e01b95945050505050565b60006001600160e01b03198216630271189760e51b148061051f57506301ffc9a760e01b6001600160e01b03198316145b92915050565b604080516080810182526000808252602082018190529181019190915260608082015260408051608081019091526001600160a01b03831681526020810161056e6006856114e8565b600181111561057f5761057f611d7a565b600181111561059057610590611d7a565b81526001600160a01b0384166000818152600960208181526040808420600281015460ff16151583880152949093529081526001909201805482518185028101850184528181529290940193919290919083018282801561061057602002820191906000526020600020905b8154815260200190600101908083116105fc575b50505050508152509050919050565b60606003805461062e90612567565b80601f016020809104026020016040519081016040528092919081815260200182805461065a90612567565b80156106a75780601f1061067c576101008083540402835291602001916106a7565b820191906000526020600020905b81548152906001019060200180831161068a57829003601f168201915b5050505050905090565b6000336106bf818585611504565b5060019392505050565b6000806106dd846380ac58cd60e01b611629565b905060006106f285636cdb3d1360e11b611629565b90508180156106ff575080155b801561071d5750600084600181111561071a5761071a611d7a565b14155b1561073b57604051630617a45f60e21b815260040160405180910390fd5b808015610746575081155b80156107645750600184600181111561076157610761611d7a565b14155b1561078257604051632905a02760e11b815260040160405180910390fd5b83600181111561079457610794611d7a565b95945050505050565b6001600160a01b0382166000908152600a60209081526040808320848452909152812054816107cd6006866114e8565b60018111156107de576107de611d7a565b905060008160018111156107f4576107f4611d7a565b03610893578115801561087857506040516331a9108f60e11b81526004810185905230906001600160a01b03871690636352211e90602401602060405180830381865afa158015610849573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061086d91906125a1565b6001600160a01b0316145b156108885760019250505061051f565b60009250505061051f565b60018160018111156108a7576108a7611d7a565b0361092e57604051627eeac760e11b81523060048201526024810185905282906001600160a01b0387169062fdd58e90604401602060405180830381865afa1580156108f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091b91906125be565b61092591906125ed565b9250505061051f565b6040516349f157c160e01b815260040160405180910390fd5b6000610953848461144f565b6109705760405163edcb51b160e01b815260040160405180910390fd5b600061097c858561079d565b905082158061098a57508281105b156109a8576040516349986e7360e01b815260040160405180910390fd5b6001600160a01b0385166000908152600a60209081526040808320878452909152812080548592906109db908490612600565b909155505060408051858152602081018590526001600160a01b0380881692908916917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a3610a53837f0000000000000000000000000000000000000000000000000000000000000000612613565b91506000610a6060025490565b9050600081118015610abb5750610ab77f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006125ed565b8111155b15610acd57610aca81846125ed565b92505b610ad78784611645565b5050949350505050565b600033610aef858285611704565b610afa85858561177e565b506001949350505050565b6000336106bf818585610b1883836114bd565b610b229190612600565b611504565b6060610b336006611922565b67ffffffffffffffff811115610b4b57610b4b611f06565b604051908082528060200260200182016040528015610b74578160200160208202803683370190505b50905060005b8151811015610bd1576000610b9060068361192d565b50905080838381518110610ba657610ba661262a565b6001600160a01b03909216602092830291909101909101525080610bc981612640565b915050610b7a565b5090565b6000805b8451811015610c5757610c3986868381518110610bf857610bf861262a565b6020026020010151868481518110610c1257610c1261262a565b6020026020010151868581518110610c2c57610c2c61262a565b6020026020010151610947565b610c439083612600565b915080610c4f81612640565b915050610bd9565b50949350505050565b6000610c6c6006611922565b905090565b6000811580610ca257506001600160a01b0384166000908152600a6020908152604080832086845290915290205482115b15610cc0576040516349986e7360e01b815260040160405180910390fd5b6001600160a01b0384166000908152600a6020908152604080832086845290915281208054849290610cf39084906125ed565b90915550610d239050827f0000000000000000000000000000000000000000000000000000000000000000612613565b905080610d2f60025490565b148015610d9f57507f0000000000000000000000000000000000000000000000000000000000000000610d827f0000000000000000000000000000000000000000000000000000000000000000836125ed565b610d8c9190612600565b3060009081526020819052604090205410155b15610db65750306000908152602081905260409020545b610dc0308261194b565b6000610dcd6006866114e8565b6001811115610dde57610dde611d7a565b90506000816001811115610df457610df4611d7a565b03610e885782600114610e1a5760405163545c577160e01b815260040160405180910390fd5b604051632142170760e11b81523060048201526001600160a01b038781166024830152604482018690528616906342842e0e906064015b600060405180830381600087803b158015610e6b57600080fd5b505af1158015610e7f573d6000803e3d6000fd5b50505050610ee1565b6001816001811115610e9c57610e9c611d7a565b0361092e5760408051602081018252600081529051637921219560e11b81526001600160a01b0387169163f242432a91610e519130918b918a918a9190600401612659565b846001600160a01b0316866001600160a01b03167ff341246adaac6f497bc2a656f546ab9e182111d630394f0c57c710a59a2cb5678686604051610f2f929190918252602082015260400190565b60405180910390a350949350505050565b8051600003610f625760405163400277cd60e11b815260040160405180910390fd5b6000610f6e6006611922565b1115610f8d576040516302ed543d60e51b815260040160405180910390fd5b610f9681611391565b60055560005b81518110156111ed576000828281518110610fb957610fb961262a565b6020026020010151905080604001518015610fd957506000816060015151115b15610ff757604051634cdbbbef60e11b815260040160405180910390fd5b600061100b826000015183602001516106c9565b825190915061101d9060069083611a75565b61103a57604051630cc656b760e21b815260040160405180910390fd5b60408281015183516001600160a01b031660009081526009602052829020600201805460ff1916911515919091179055517f2ebca503d1d899889b8a6d039632aa576bbff8cb8233491fbaece7f7773c341790611098908490611e25565b60405180910390a18160400151156110b15750506111db565b8160600151516000036110d7576040516390f22bf160e01b815260040160405180910390fd5b6000805b8360600151518110156111d6576000846060015182815181106111005761110061262a565b602002602001015190508281101561112b57604051631f13bcf760e21b815260040160405180910390fd5b80925084516001600160a01b0316600090815260096020908152604080832084845290915290205460ff16156111745760405163403b2b6760e01b815260040160405180910390fd5b84516001600160a01b0390811660009081526009602081815260408084208685528252808420805460ff191660019081179091558a519095168452918152908220830180549384018155825290200155806111ce81612640565b9150506110db565b505050505b806111e581612640565b915050610f9c565b5050565b6111fb838361144f565b156112195760405163578d6bb760e11b815260040160405180910390fd5b600084600181111561122d5761122d611d7a565b036112a057604051632142170760e11b81523060048201526001600160a01b038681166024830152604482018490528416906342842e0e906064015b600060405180830381600087803b15801561128357600080fd5b505af1158015611297573d6000803e3d6000fd5b505050506112f9565b60018460018111156112b4576112b4611d7a565b0361092e5760408051602081018252600081529051637921219560e11b81526001600160a01b0385169163f242432a916112699130918a918891889190600401612659565b5050505050565b6000805b8451811015610c5757611364868683815181106113235761132361262a565b602002602001015186848151811061133d5761133d61262a565b60200260200101518685815181106113575761135761262a565b6020026020010151610c71565b61136e9083612600565b91508061137a81612640565b915050611304565b60606004805461062e90612567565b6000816040516020016113a49190612693565b604051602081830303815290604052805190602001209050919050565b600033816113cf82866114bd565b9050838110156114345760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610afa8286868403611504565b6000336106bf81858561177e565b60008061145d600685611a8b565b5090508080156114b557506001600160a01b03841660009081526009602052604090206002015460ff16806114b557506001600160a01b038416600090815260096020908152604080832086845290915290205460ff165b949350505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006114fd836001600160a01b038416611aa3565b9392505050565b6001600160a01b0383166115665760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161142b565b6001600160a01b0382166115c75760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161142b565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b600061163483611b13565b80156114fd57506114fd8383611b46565b6001600160a01b03821661169b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161142b565b80600260008282546116ad9190612600565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600061171084846114bd565b90506000198114611778578181101561176b5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161142b565b6117788484848403611504565b50505050565b6001600160a01b0383166117e25760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161142b565b6001600160a01b0382166118445760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161142b565b6001600160a01b038316600090815260208190526040902054818110156118bc5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161142b565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3611778565b600061051f82611bcf565b600080808061193c8686611bda565b909450925050505b9250929050565b6001600160a01b0382166119ab5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161142b565b6001600160a01b03821660009081526020819052604090205481811015611a1f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161142b565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910161161c565b60006114b5846001600160a01b03851684611c05565b600080808061193c866001600160a01b038716611c22565b600081815260028301602052604081205480151580611ac75750611ac78484611c5c565b6114fd5760405162461bcd60e51b815260206004820152601e60248201527f456e756d657261626c654d61703a206e6f6e6578697374656e74206b65790000604482015260640161142b565b6000611b26826301ffc9a760e01b611b46565b801561051f5750611b3f826001600160e01b0319611b46565b1592915050565b604080516001600160e01b03198316602480830191909152825180830390910181526044909101909152602080820180516001600160e01b03166301ffc9a760e01b178152825160009392849283928392918391908a617530fa92503d91506000519050828015611bb8575060208210155b8015611bc45750600081115b979650505050505050565b600061051f82611c68565b60008080611be88585611c72565b600081815260029690960160205260409095205494959350505050565b600082815260028401602052604081208290556114b58484611c7e565b6000818152600283016020526040812054819080611c5157611c448585611c5c565b9250600091506119449050565b600192509050611944565b60006114fd8383611c8a565b600061051f825490565b60006114fd8383611ca2565b60006114fd8383611ccc565b600081815260018301602052604081205415156114fd565b6000826000018281548110611cb957611cb961262a565b9060005260206000200154905092915050565b6000818152600183016020526040812054611d135750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561051f565b50600061051f565b600060208284031215611d2d57600080fd5b81356001600160e01b0319811681146114fd57600080fd5b6001600160a01b0381168114611d5a57600080fd5b50565b600060208284031215611d6f57600080fd5b81356114fd81611d45565b634e487b7160e01b600052602160045260246000fd5b80516001600160a01b03168252602080820151600091608085019160028110611dc957634e487b7160e01b600052602160045260246000fd5b8582015260408481015115159086015260608085015160809187019190915280519283905281019160009060a08701905b80831015611e1a5784518252938301936001929092019190830190611dfa565b509695505050505050565b6020815260006114fd6020830184611d90565b6000815180845260005b81811015611e5e57602081850181015186830182015201611e42565b506000602082860101526020601f19601f83011685010191505092915050565b6020815260006114fd6020830184611e38565b60008060408385031215611ea457600080fd5b8235611eaf81611d45565b946020939093013593505050565b803560028110611ecc57600080fd5b919050565b60008060408385031215611ee457600080fd5b8235611eef81611d45565b9150611efd60208401611ebd565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff81118282101715611f3f57611f3f611f06565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611f6e57611f6e611f06565b604052919050565b600082601f830112611f8757600080fd5b813567ffffffffffffffff811115611fa157611fa1611f06565b611fb4601f8201601f1916602001611f45565b818152846020838601011115611fc957600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215611ffc57600080fd5b843561200781611d45565b9350602085013561201781611d45565b925060408501359150606085013567ffffffffffffffff81111561203a57600080fd5b61204687828801611f76565b91505092959194509250565b6000806000806080858703121561206857600080fd5b843561207381611d45565b9350602085013561208381611d45565b93969395505050506040820135916060013590565b6000806000606084860312156120ad57600080fd5b83356120b881611d45565b925060208401356120c881611d45565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b8181101561211a5783516001600160a01b0316835292840192918401916001016120f5565b50909695505050505050565b600067ffffffffffffffff82111561214057612140611f06565b5060051b60200190565b600082601f83011261215b57600080fd5b8135602061217061216b83612126565b611f45565b82815260059290921b8401810191818101908684111561218f57600080fd5b8286015b84811015611e1a5780358352918301918301612193565b600080600080608085870312156121c057600080fd5b84356121cb81611d45565b935060208581013567ffffffffffffffff808211156121e957600080fd5b818801915088601f8301126121fd57600080fd5b813561220b61216b82612126565b81815260059190911b8301840190848101908b83111561222a57600080fd5b938501935b8285101561225157843561224281611d45565b8252938501939085019061222f565b97505050604088013592508083111561226957600080fd5b61227589848a0161214a565b9450606088013592508083111561228b57600080fd5b50506120468782880161214a565b600060208083850312156122ac57600080fd5b823567ffffffffffffffff808211156122c457600080fd5b818501915085601f8301126122d857600080fd5b81356122e661216b82612126565b81815260059190911b8301840190848101908883111561230557600080fd5b8585015b838110156123b1578035858111156123215760008081fd5b86016080818c03601f19018113156123395760008081fd5b612341611f1c565b8983013561234e81611d45565b8152604061235d848201611ebd565b8b83015260608085013580151581146123765760008081fd5b8383015292840135928984111561238f57600091508182fd5b61239d8f8d8688010161214a565b908301525085525050918601918601612309565b5098975050505050505050565b600080600080600060a086880312156123d657600080fd5b85356123e181611d45565b94506123ef60208701611ebd565b935060408601356123ff81611d45565b94979396509394606081013594506080013592915050565b600080600080600060a0868803121561242f57600080fd5b853561243a81611d45565b9450602086013561244a81611d45565b9350604086013567ffffffffffffffff8082111561246757600080fd5b61247389838a0161214a565b9450606088013591508082111561248957600080fd5b61249589838a0161214a565b935060808801359150808211156124ab57600080fd5b506124b888828901611f76565b9150509295509295909350565b600080604083850312156124d857600080fd5b82356124e381611d45565b915060208301356124f381611d45565b809150509250929050565b600080600080600060a0868803121561251657600080fd5b853561252181611d45565b9450602086013561253181611d45565b93506040860135925060608601359150608086013567ffffffffffffffff81111561255b57600080fd5b6124b888828901611f76565b600181811c9082168061257b57607f821691505b60208210810361259b57634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156125b357600080fd5b81516114fd81611d45565b6000602082840312156125d057600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561051f5761051f6125d7565b8082018082111561051f5761051f6125d7565b808202811582820484141761051f5761051f6125d7565b634e487b7160e01b600052603260045260246000fd5b600060018201612652576126526125d7565b5060010190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090611bc490830184611e38565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156126e857603f198886030184526126d6858351611d90565b945092850192908501906001016126ba565b509297965050505050505056fea164736f6c6343000812000aa164736f6c6343000812000a
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.