// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title Set implementation with enumeration functions
* @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT license)
*/libraryEnumerableSet{
structSet {
bytes32[] _values;
// 1-indexed to allow 0 to signify nonexistencemapping (bytes32=>uint) _indexes;
}
structBytes32Set {
Set _inner;
}
structAddressSet {
Set _inner;
}
structUintSet {
Set _inner;
}
functionat (
Bytes32Set storage set,
uint index
) internalviewreturns (bytes32) {
return _at(set._inner, index);
}
functionat (
AddressSet storage set,
uint index
) internalviewreturns (address) {
returnaddress(uint160(uint(_at(set._inner, index))));
}
functionat (
UintSet storage set,
uint index
) internalviewreturns (uint) {
returnuint(_at(set._inner, index));
}
functioncontains (
Bytes32Set storage set,
bytes32 value
) internalviewreturns (bool) {
return _contains(set._inner, value);
}
functioncontains (
AddressSet storage set,
address value
) internalviewreturns (bool) {
return _contains(set._inner, bytes32(uint(uint160(value))));
}
functioncontains (
UintSet storage set,
uint value
) internalviewreturns (bool) {
return _contains(set._inner, bytes32(value));
}
functionindexOf (
Bytes32Set storage set,
bytes32 value
) internalviewreturns (uint) {
return _indexOf(set._inner, value);
}
functionindexOf (
AddressSet storage set,
address value
) internalviewreturns (uint) {
return _indexOf(set._inner, bytes32(uint(uint160(value))));
}
functionindexOf (
UintSet storage set,
uint value
) internalviewreturns (uint) {
return _indexOf(set._inner, bytes32(value));
}
functionlength (
Bytes32Set storage set
) internalviewreturns (uint) {
return _length(set._inner);
}
functionlength (
AddressSet storage set
) internalviewreturns (uint) {
return _length(set._inner);
}
functionlength (
UintSet storage set
) internalviewreturns (uint) {
return _length(set._inner);
}
functionadd (
Bytes32Set storage set,
bytes32 value
) internalreturns (bool) {
return _add(set._inner, value);
}
functionadd (
AddressSet storage set,
address value
) internalreturns (bool) {
return _add(set._inner, bytes32(uint(uint160(value))));
}
functionadd (
UintSet storage set,
uint value
) internalreturns (bool) {
return _add(set._inner, bytes32(value));
}
functionremove (
Bytes32Set storage set,
bytes32 value
) internalreturns (bool) {
return _remove(set._inner, value);
}
functionremove (
AddressSet storage set,
address value
) internalreturns (bool) {
return _remove(set._inner, bytes32(uint(uint160(value))));
}
functionremove (
UintSet storage set,
uint value
) internalreturns (bool) {
return _remove(set._inner, bytes32(value));
}
function_at (
Set storage set,
uint index
) privateviewreturns (bytes32) {
require(set._values.length> index, 'EnumerableSet: index out of bounds');
return set._values[index];
}
function_contains (
Set storage set,
bytes32 value
) privateviewreturns (bool) {
return set._indexes[value] !=0;
}
function_indexOf (
Set storage set,
bytes32 value
) privateviewreturns (uint) {
unchecked {
return set._indexes[value] -1;
}
}
function_length (
Set storage set
) privateviewreturns (uint) {
return set._values.length;
}
function_add (
Set storage set,
bytes32 value
) privatereturns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
returntrue;
} else {
returnfalse;
}
}
function_remove (
Set storage set,
bytes32 value
) privatereturns (bool) {
uint valueIndex = set._indexes[value];
if (valueIndex !=0) {
uint index = valueIndex -1;
bytes32 last = set._values[set._values.length-1];
// move last value to now-vacant index
set._values[index] = last;
set._indexes[last] = index +1;
// clear last index
set._values.pop();
delete set._indexes[value];
returntrue;
} else {
returnfalse;
}
}
}
Contract Source Code
File 3 of 10: IERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title ERC165 interface registration interface
* @dev see https://eips.ethereum.org/EIPS/eip-165
*/interfaceIERC165{
/**
* @notice query whether contract has registered support for given interface
* @param interfaceId interface id
* @return bool whether interface is supported
*/functionsupportsInterface (bytes4 interfaceId
) externalviewreturns (bool);
}
Contract Source Code
File 4 of 10: IERC20.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import {IERC20Internal} from'./IERC20Internal.sol';
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/interfaceIERC20isIERC20Internal{
/**
* @notice query the total minted token supply
* @return token supply
*/functiontotalSupply () externalviewreturns (uint256);
/**
* @notice query the token balance of given account
* @param account address to query
* @return token balance
*/functionbalanceOf (address account
) externalviewreturns (uint256);
/**
* @notice query the allowance granted from given holder to given spender
* @param holder approver of allowance
* @param spender recipient of allowance
* @return token allowance
*/functionallowance (address holder,
address spender
) externalviewreturns (uint256);
/**
* @notice grant approval to spender to spend tokens
* @dev prefer ERC20Extended functions to avoid transaction-ordering vulnerability (see https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729)
* @param spender recipient of allowance
* @param amount quantity of tokens approved for spending
* @return success status (always true; otherwise function should revert)
*/functionapprove (address spender,
uint256 amount
) externalreturns (bool);
/**
* @notice transfer tokens to given recipient
* @param recipient beneficiary of token transfer
* @param amount quantity of tokens to transfer
* @return success status (always true; otherwise function should revert)
*/functiontransfer (address recipient,
uint256 amount
) externalreturns (bool);
/**
* @notice transfer tokens to given recipient on behalf of given holder
* @param holder holder of tokens prior to transfer
* @param recipient beneficiary of token transfer
* @param amount quantity of tokens to transfer
* @return success status (always true; otherwise function should revert)
*/functiontransferFrom (address holder,
address recipient,
uint256 amount
) externalreturns (bool);
}
Contract Source Code
File 5 of 10: IERC20Internal.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title Partial ERC20 interface needed by internal functions
*/interfaceIERC20Internal{
eventTransfer(addressindexedfrom,
addressindexed to,
uint256 value
);
eventApproval(addressindexed owner,
addressindexed spender,
uint256 value
);
}
Contract Source Code
File 6 of 10: IERC721.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import {IERC165} from'../../introspection/IERC165.sol';
import {IERC721Internal} from'./IERC721Internal.sol';
/**
* @notice ERC721 interface
* @dev see https://eips.ethereum.org/EIPS/eip-721
*/interfaceIERC721isIERC721Internal, IERC165{
/**
* @notice query the balance of given address
* @return balance quantity of tokens held
*/functionbalanceOf (address account
) externalviewreturns (uint256 balance);
/**
* @notice query the owner of given token
* @param tokenId token to query
* @return owner token owner
*/functionownerOf (uint256 tokenId
) externalviewreturns (address owner);
/**
* @notice transfer token between given addresses, checking for ERC721Receiver implementation if applicable
* @param from sender of token
* @param to receiver of token
* @param tokenId token id
*/functionsafeTransferFrom (addressfrom,
address to,
uint256 tokenId
) externalpayable;
/**
* @notice transfer token between given addresses, checking for ERC721Receiver implementation if applicable
* @param from sender of token
* @param to receiver of token
* @param tokenId token id
* @param data data payload
*/functionsafeTransferFrom (addressfrom,
address to,
uint256 tokenId,
bytescalldata data
) externalpayable;
/**
* @notice transfer token between given addresses, without checking for ERC721Receiver implementation if applicable
* @param from sender of token
* @param to receiver of token
* @param tokenId token id
*/functiontransferFrom (addressfrom,
address to,
uint256 tokenId
) externalpayable;
/**
* @notice grant approval to given account to spend token
* @param operator address to be approved
* @param tokenId token to approve
*/functionapprove (address operator,
uint256 tokenId
) externalpayable;
/**
* @notice get approval status for given token
* @param tokenId token to query
* @return operator address approved to spend token
*/functiongetApproved (uint256 tokenId
) externalviewreturns (address operator);
/**
* @notice grant approval to or revoke approval from given account to spend all tokens held by sender
* @param operator address to be approved
* @param status approval status
*/functionsetApprovalForAll (address operator,
bool status
) external;
/**
* @notice query approval status of given operator with respect to given address
* @param account address to query for approval granted
* @param operator address to query for approval received
* @return status whether operator is approved to spend tokens held by account
*/functionisApprovedForAll (address account,
address operator
) externalviewreturns (bool status);
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Standard math utilities missing in the Solidity language.
*/libraryMath{
/**
* @dev Returns the largest of two numbers.
*/functionmax(uint256 a, uint256 b) internalpurereturns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/functionmin(uint256 a, uint256 b) internalpurereturns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/functionaverage(uint256 a, uint256 b) internalpurereturns (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.
*/functionceilDiv(uint256 a, uint256 b) internalpurereturns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.return a / b + (a % b ==0 ? 0 : 1);
}
}