Contract Name:
LootForEveryone
Contract Source Code:
<i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
// Check the signature length
if (signature.length != 65) {
revert("ECDSA: invalid signature length");
}
// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return recover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
require(signer != address(0), "ECDSA: invalid signature");
return signer;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* replicates the behavior of the
* https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
* JSON-RPC method.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <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);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "../../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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* 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 Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @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 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);
/**
* @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;
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <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 `IERC721.onERC721Received.selector`.
*/
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 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");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <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.
*/
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;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
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] = toDeleteIndex + 1; // All indexes are 1-based
// 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) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
// 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);
}
// 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))));
}
// 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 on 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));
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: AGPL-1.0
pragma solidity 0.7.6;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/introspection/IERC165.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
abstract contract ERC721Base is IERC165, IERC721 {
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;
bytes4 internal constant ERC165ID = 0x01ffc9a7;
uint256 internal constant OPERATOR_FLAG = (2**255);
mapping(uint256 => uint256) internal _owners;
mapping(address => EnumerableSet.UintSet) internal _holderTokens;
mapping(address => mapping(address => bool)) internal _operatorsForAll;
mapping(uint256 => address) internal _operators;
/// @notice Count NFTs tracked by this contract
/// @return A count of valid NFTs tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external pure returns (uint256) {
return 2**160 - 1; // do not count token with id zero whose owner would otherwise be the zero address
}
/// @notice Enumerate valid NFTs
/// @dev Throws if `index` >= `totalSupply()`.
/// @param index A counter less than `totalSupply()`
/// @return The token identifier for the `_index`th NFT,
/// (sort order not specified)
function tokenByIndex(uint256 index) external pure returns (uint256) {
require(index < 2**160 - 1, "NONEXISTENT_TOKEN");
return index + 1; // skip zero as we do not count token with id zero whose owner would otherwise be the zero address
}
/// @notice Enumerate NFTs assigned to an owner
/// @dev Throws if `index` >= `balanceOf(owner)` or if
/// `owner` is the zero address, representing invalid NFTs.
/// @param owner An address where we are interested in NFTs owned by them
/// @param index A counter less than `balanceOf(owner)`
/// @return The token identifier for the `index`th NFT assigned to `owner`,
/// (sort order not specified)
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256) {
require(owner != address(0), "ZERO_ADDRESS_OWNER");
(, bool registered) = _ownerOfAndRegistered(uint256(owner));
if (!registered) {
if (index == 0) {
return uint256(owner);
}
index--;
}
return _holderTokens[owner].at(index);
}
/// @notice Approve an operator to spend tokens on the senders behalf.
/// @param operator The address receiving the approval.
/// @param id The id of the token.
function approve(address operator, uint256 id) external override {
(address owner, bool registered) = _ownerOfAndRegistered(id);
require(owner != address(0), "NONEXISTENT_TOKEN");
require(owner == msg.sender || _operatorsForAll[owner][msg.sender], "UNAUTHORIZED_APPROVAL");
_approveFor(owner, operator, id, registered);
}
/// @notice Transfer a token between 2 addresses.
/// @param from The sender of the token.
/// @param to The recipient of the token.
/// @param id The id of the token.
function transferFrom(
address from,
address to,
uint256 id
) external override {
(address owner, bool operatorEnabled, bool registered) = _ownerRegisteredAndOperatorEnabledOf(id);
require(owner != address(0), "NONEXISTENT_TOKEN");
require(owner == from, "NOT_OWNER");
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
if (msg.sender != from) {
require(
_operatorsForAll[from][msg.sender] || (operatorEnabled && _operators[id] == msg.sender),
"UNAUTHORIZED_TRANSFER"
);
}
_transferFrom(from, to, id, registered);
}
/// @notice Transfer a token between 2 addresses letting the receiver know of the transfer.
/// @param from The send of the token.
/// @param to The recipient of the token.
/// @param id The id of the token.
function safeTransferFrom(
address from,
address to,
uint256 id
) external override {
safeTransferFrom(from, to, id, "");
}
/// @notice Set the approval for an operator to manage all the tokens of the sender.
/// @param operator The address receiving the approval.
/// @param approved The determination of the approval.
function setApprovalForAll(address operator, bool approved) external override {
_setApprovalForAll(msg.sender, operator, approved);
}
/// @notice Get the number of tokens owned by an address.
/// @param owner The address to look for.
/// @return balance The number of tokens owned by the address.
function balanceOf(address owner) external view override returns (uint256 balance) {
require(owner != address(0), "ZERO_ADDRESS_OWNER");
balance = _holderTokens[owner].length();
(, bool registered) = _ownerOfAndRegistered(uint256(owner));
if (!registered) {
// owned token was never registered
balance++;
}
}
/// @notice Get the owner of a token.
/// @param id The id of the token.
/// @return owner The address of the token owner.
function ownerOf(uint256 id) external view override returns (address owner) {
owner = _ownerOf(id);
require(owner != address(0), "NONEXISTANT_TOKEN");
}
/// @notice Get the approved operator for a specific token.
/// @param id The id of the token.
/// @return The address of the operator.
function getApproved(uint256 id) external view override returns (address) {
(address owner, bool operatorEnabled) = _ownerAndOperatorEnabledOf(id);
require(owner != address(0), "NONEXISTENT_TOKEN");
if (operatorEnabled) {
return _operators[id];
} else {
return address(0);
}
}
/// @notice Check if the sender approved the operator.
/// @param owner The address of the owner.
/// @param operator The address of the operator.
/// @return isOperator The status of the approval.
function isApprovedForAll(address owner, address operator) external view override returns (bool isOperator) {
return _operatorsForAll[owner][operator];
}
/// @notice Transfer a token between 2 addresses letting the receiver knows of the transfer.
/// @param from The sender of the token.
/// @param to The recipient of the token.
/// @param id The id of the token.
/// @param data Additional data.
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes memory data
) public override {
(address owner, bool operatorEnabled, bool registered) = _ownerRegisteredAndOperatorEnabledOf(id);
require(owner != address(0), "NONEXISTENT_TOKEN");
require(owner == from, "NOT_OWNER");
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
if (msg.sender != from) {
require(
_operatorsForAll[from][msg.sender] || (operatorEnabled && _operators[id] == msg.sender),
"UNAUTHORIZED_TRANSFER"
);
}
_safeTransferFrom(from, to, id, registered, data);
}
/// @notice Check if the contract supports an interface.
/// 0x01ffc9a7 is ERC165.
/// 0x80ac58cd is ERC721
/// 0x5b5e139f is for ERC721 metadata
/// 0x780e9d63 is for ERC721 enumerable
/// @param id The id of the interface.
/// @return Whether the interface is supported.
function supportsInterface(bytes4 id) public pure virtual override returns (bool) {
return id == 0x01ffc9a7 || id == 0x80ac58cd || id == 0x5b5e139f || id == 0x780e9d63;
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
bool alreadyRegistered,
bytes memory data
) internal {
_transferFrom(from, to, id, alreadyRegistered);
if (to.isContract()) {
require(_checkOnERC721Received(msg.sender, from, to, id, data), "ERC721_TRANSFER_REJECTED");
}
}
function _transferFrom(
address from,
address to,
uint256 id,
bool alreadyRegistered
) internal {
if (alreadyRegistered) {
_holderTokens[from].remove(id);
}
_holderTokens[to].add(id);
_owners[id] = uint256(to);
emit Transfer(from, to, id);
}
/// @dev See approve.
function _approveFor(
address owner,
address operator,
uint256 id,
bool alreadyRegistered
) internal {
if (operator == address(0)) {
_owners[id] = alreadyRegistered ? uint256(owner) : 0;
} else {
_owners[id] = OPERATOR_FLAG | (alreadyRegistered ? uint256(owner) : 0);
_operators[id] = operator;
}
emit Approval(owner, operator, id);
}
/// @dev See setApprovalForAll.
function _setApprovalForAll(
address sender,
address operator,
bool approved
) internal {
_operatorsForAll[sender][operator] = approved;
emit ApprovalForAll(sender, operator, approved);
}
/// @dev Check if receiving contract accepts erc721 transfers.
/// @param operator The address of the operator.
/// @param from The from address, may be different from msg.sender.
/// @param to The adddress we want to transfer to.
/// @param id The id of the token we would like to transfer.
/// @param _data Any additional data to send with the transfer.
/// @return Whether the expected value of 0x150b7a02 is returned.
function _checkOnERC721Received(
address operator,
address from,
address to,
uint256 id,
bytes memory _data
) internal returns (bool) {
bytes4 retval = IERC721Receiver(to).onERC721Received(operator, from, id, _data);
return (retval == ERC721_RECEIVED);
}
/// @dev See ownerOf
function _ownerOf(uint256 id) internal view returns (address owner) {
owner = address(_owners[id]);
if (owner == address(0) && id < 2**160) {
owner = address(id);
}
}
/// @dev Get the ownerand registered status of a token.
/// @param id The token to query.
/// @return owner The owner of the token.
/// @return registered whethe the token has been registered with an owner
function _ownerOfAndRegistered(uint256 id) internal view returns (address owner, bool registered) {
owner = address(_owners[id]);
if (owner == address(0) && id < 2**160) {
owner = address(id);
} else {
registered = true;
}
}
/// @dev Get the owner and operatorEnabled status of a token.
/// @param id The token to query.
/// @return owner The owner of the token.
/// @return operatorEnabled Whether or not operators are enabled for this token.
function _ownerAndOperatorEnabledOf(uint256 id) internal view returns (address owner, bool operatorEnabled) {
uint256 data = _owners[id];
owner = address(data);
if (owner == address(0) && id < 2**160) {
owner = address(id);
}
operatorEnabled = (data & OPERATOR_FLAG) == OPERATOR_FLAG;
}
/// @dev Get the owner, operatorEnabled and registered status of a token.
/// @param id The token to query.
/// @return owner The owner of the token.
/// @return operatorEnabled Whether or not operators are enabled for this token.
/// @return registered whethe the token has been registered with an owner
function _ownerRegisteredAndOperatorEnabledOf(uint256 id)
internal
view
returns (
address owner,
bool operatorEnabled,
bool registered
)
{
uint256 data = _owners[id];
owner = address(data);
if (owner == address(0) && id < 2**160) {
owner = address(id);
} else {
registered = true;
}
operatorEnabled = (data & OPERATOR_FLAG) == OPERATOR_FLAG;
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: AGPL-1.0
pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;
import "./ERC721Base.sol";
import "./interfaces/ISyntheticLoot.sol";
import "./interfaces/ILoot.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
contract LootForEveryone is ERC721Base {
using EnumerableSet for EnumerableSet.UintSet;
using ECDSA for bytes32;
struct TokenData {
uint256 id;
string tokenURI;
bool claimed;
}
ILoot private immutable _loot;
ISyntheticLoot private immutable _syntheticLoot;
constructor(ILoot loot, ISyntheticLoot syntheticLoot) {
_loot = loot;
_syntheticLoot = syntheticLoot;
}
/// @notice A descriptive name for a collection of NFTs in this contract
function name() external pure returns (string memory) {
return "Loot For Everyone";
}
/// @notice An abbreviated name for NFTs in this contract
function symbol() external pure returns (string memory) {
return "LOOT";
}
function tokenURI(uint256 id) external view returns (string memory) {
return _tokenURI(id);
}
///@notice get all info in the minimum calls
function getTokenDataOfOwner(
address owner,
uint256 start,
uint256 num
) external view returns (TokenData[] memory tokens) {
require(start < 2**160 && num < 2**160, "INVALID_RANGE");
EnumerableSet.UintSet storage allTokens = _holderTokens[owner];
uint256 balance = allTokens.length();
(, bool registered) = _ownerOfAndRegistered(uint256(owner));
if (!registered) {
// owned token was never registered, add balance
balance++;
}
require(balance >= start + num, "TOO_MANY_TOKEN_REQUESTED");
tokens = new TokenData[](num);
uint256 i = 0;
uint256 offset = 0;
if (start == 0 && !registered) {
// if start at zero consider unregistered token
tokens[0] = TokenData(uint256(owner), _tokenURI(uint256(owner)), false);
offset = 1;
i = 1;
}
while (i < num) {
uint256 id = allTokens.at(start + i - offset);
tokens[i] = TokenData(id, _tokenURI(id), true);
i++;
}
}
///@notice get all info in the minimum calls
function getTokenDataForIds(uint256[] memory ids) external view returns (TokenData[] memory tokens) {
tokens = new TokenData[](ids.length);
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
(, bool registered) = _ownerOfAndRegistered(id);
tokens[i] = TokenData(id, _tokenURI(id), registered);
}
}
/// @notice utility function to claim a token when you know the private key of an address, go hunt for your loot!
function pickLoot(address to, bytes memory signature) external {
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
bytes32 hashedData = keccak256(abi.encodePacked("LootForEveryone", to));
address signer = hashedData.toEthSignedMessageHash().recover(signature);
(, bool registered) = _ownerOfAndRegistered(uint256(signer));
require(!registered, "ALREADY_CALIMED");
_safeTransferFrom(signer, to, uint256(signer), false, "");
}
///@notice return true if the loot has been picked up or been transfered at least once
function isLootPicked(uint256 id) external view returns(bool) {
(address owner, bool registered) = _ownerOfAndRegistered(id);
require(owner != address(0), "NONEXISTENT_TOKEN");
return registered;
}
/// @notice lock your original but limited loot so that you get a LootForEveryone like everyone else
function transmute(uint256 id, address to) external {
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
_loot.transferFrom(msg.sender, address(this), id);
(address owner, bool registered) = _ownerOfAndRegistered(id);
if (registered) {
require(owner == address(this), "ALREADY_CLAIMED"); // unlikely to happen, would need to find the private key for its adresss (< 8001)
_safeTransferFrom(address(this), to, id, false, "");
} else {
_safeTransferFrom(address(id), to, id, false, "");
}
}
/// @notice unlock your original loot back
function transmuteBack(uint256 id, address to) external {
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
(address owner, bool registered) = _ownerOfAndRegistered(id);
require(msg.sender == owner, "NOT_OWNER");
_transferFrom(owner, address(this), id, registered);
_loot.transferFrom(address(this), to, id);
}
// -------------------------------------------------------------------------------------------------
// INTERNAL
// -------------------------------------------------------------------------------------------------
function _tokenURI(uint256 id) internal view returns (string memory) {
require(id > 0 && id < 2**160, "NONEXISTENT_TOKEN");
if (id < 8001) {
return _loot.tokenURI(id);
}
return _syntheticLoot.tokenURI(address(id));
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: Unlicense
pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol";
// solhint-disable-next-line no-empty-blocks
interface ILoot is IERC721Metadata{
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: Unlicense
pragma solidity 0.7.6;
interface ISyntheticLoot {
function weaponComponents(address walletAddress) external view returns (uint256[5] memory);
function chestComponents(address walletAddress) external view returns (uint256[5] memory);
function headComponents(address walletAddress) external view returns (uint256[5] memory);
function waistComponents(address walletAddress) external view returns (uint256[5] memory);
function footComponents(address walletAddress) external view returns (uint256[5] memory);
function handComponents(address walletAddress) external view returns (uint256[5] memory);
function neckComponents(address walletAddress) external view returns (uint256[5] memory);
function ringComponents(address walletAddress) external view returns (uint256[5] memory);
function getWeapon(address walletAddress) external view returns (string memory);
function getChest(address walletAddress) external view returns (string memory);
function getHead(address walletAddress) external view returns (string memory);
function getWaist(address walletAddress) external view returns (string memory);
function getFoot(address walletAddress) external view returns (string memory);
function getHand(address walletAddress) external view returns (string memory);
function getNeck(address walletAddress) external view returns (string memory);
function getRing(address walletAddress) external view returns (string memory);
function tokenURI(address walletAddress) external view returns (string memory);
}