// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @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
* ====
*/functionisContract(address account) internalviewreturns (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-assemblyassembly { 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].
*/functionsendValue(addresspayable 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._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
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._
*/functionfunctionCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value) internalreturns (bytesmemory) {
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._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value, stringmemory errorMessage) internalreturns (bytesmemory) {
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, bytesmemory 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._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
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._
*/functionfunctionStaticCall(address target, bytesmemory data, stringmemory errorMessage) internalviewreturns (bytesmemory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory 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._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
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._
*/functionfunctionDelegateCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function_verifyCallResult(bool success, bytesmemory returndata, stringmemory errorMessage) privatepurereturns(bytesmemory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assembly// solhint-disable-next-line no-inline-assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Contract Source Code
File 2 of 9: Amulet.sol
// SPDX-License-Identifier: MIT// Derived from OpenZeppelin's ERC721 implementation, with changes for gas-efficiency.pragmasolidity ^0.8.0;import"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import"@openzeppelin/contracts/utils/introspection/ERC165.sol";
import"@openzeppelin/contracts/utils/Address.sol";
import"./IAmulet.sol";
import"./ProxyRegistryWhitelist.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/contractAmuletisIAmulet, ERC165, ProxyRegistryWhitelist{
usingAddressforaddress;
// Mapping from token ID to token data// Values are packed in the form:// [score (32 bits)][blockRevealed (64 bits)][owner (160 bits)]// This is equivalent to the following Solidity structure,// but saves us about 4200 gas on mint, 3600 gas on reveal,// and 140 gas on transfer.// struct Token {// uint32 score;// uint64 blockRevealed;// address owner;// }mapping (uint256=>uint256) private _tokens;
// Mapping from owner to operator approvalsmapping (address=>mapping (address=>bool)) private _operatorApprovals;
constructor (address proxyRegistryAddress, MintData[] memory premineMints, MintAndRevealData[] memory premineReveals) ProxyRegistryWhitelist(proxyRegistryAddress) {
mintAll(premineMints);
mintAndRevealAll(premineReveals);
}
/**************************************************************************
* Opensea-specific methods
*************************************************************************/functioncontractURI() externalpurereturns (stringmemory) {
return"https://at.amulet.garden/contract.json";
}
/**
* @dev See {IERC721Metadata-name}.
*/functionname() publicviewvirtualreturns (stringmemory) {
return"Amulets";
}
/**
* @dev See {IERC721Metadata-symbol}.
*/functionsymbol() publicviewvirtualreturns (stringmemory) {
return"AMULET";
}
/**************************************************************************
* ERC721 methods
*************************************************************************//**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverride(ERC165, IERC165) returns (bool) {
return interfaceId ==type(IERC1155).interfaceId|| interfaceId ==type(IERC1155MetadataURI).interfaceId||super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155Metadata-uri}.
*/functionuri(uint256/*tokenId*/) publicviewvirtualoverridereturns (stringmemory) {
return"https://at.amulet.garden/token/{id}.json";
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/functionbalanceOf(address account, uint256 id) publicviewvirtualoverridereturns (uint256) {
require(account !=address(0), "ERC1155: balance query for the zero address");
(address owner,,) = getData(id);
if(owner == account) {
return1;
}
return0;
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/functionbalanceOfBatch(address[] memory accounts,
uint256[] memory ids
)
publicviewvirtualoverridereturns (uint256[] memory)
{
require(accounts.length== ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances =newuint256[](accounts.length);
for (uint256 i =0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/functionsetApprovalForAll(address operator, bool approved) publicvirtualoverride{
require(msg.sender!= operator, "ERC1155: setting approval status for self");
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/functionisApprovedForAll(address account, address operator) publicviewvirtualoverridereturns (bool) {
return _operatorApprovals[account][operator] || isProxyForOwner(account, operator);
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 id,
uint256 amount,
bytesmemory data
)
publicvirtualoverride{
require(to !=address(0), "ERC1155: transfer to the zero address");
require(
from==msg.sender|| isApprovedForAll(from, msg.sender),
"ERC1155: caller is not owner nor approved"
);
(address oldOwner, uint64 blockRevealed, uint32 score) = getData(id);
require(amount ==1&& oldOwner ==from, "ERC1155: Insufficient balance for transfer");
setData(id, to, blockRevealed, score);
emit TransferSingle(msg.sender, from, to, id, amount);
_doSafeTransferAcceptanceCheck(msg.sender, from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/functionsafeBatchTransferFrom(addressfrom,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytesmemory data
)
publicvirtualoverride{
require(ids.length== amounts.length, "ERC1155: ids and amounts length mismatch");
require(to !=address(0), "ERC1155: transfer to the zero address");
require(
from==msg.sender|| isApprovedForAll(from, msg.sender),
"ERC1155: transfer caller is not owner nor approved"
);
for (uint256 i =0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
(address oldOwner, uint64 blockRevealed, uint32 score) = getData(id);
require(amount ==1&& oldOwner ==from, "ERC1155: insufficient balance for transfer");
setData(id, to, blockRevealed, score);
}
emit TransferBatch(msg.sender, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(msg.sender, from, to, ids, amounts, data);
}
/**************************************************************************
* Amulet-specific methods
*************************************************************************//**
* @dev Returns the owner of the token with id `id`.
*/functionownerOf(uint256 id) externaloverrideviewreturns(address) {
(address owner,,) = getData(id);
return owner;
}
/**
* @dev Returns the score of an amulet.
* 0-3: Not an amulet
* 4: common
* 5: uncommon
* 6: rare
* 7: epic
* 8: legendary
* 9: mythic
* 10+: beyond mythic
*/functiongetScore(stringmemory amulet) publicoverridepurereturns(uint32) {
uint256 hash =uint256(sha256(bytes(amulet)));
uint maxlen =0;
uint len =0;
for(;hash >0; hash >>=4) {
if(hash &0xF==8) {
len +=1;
if(len > maxlen) {
maxlen = len;
}
} else {
len =0;
}
}
returnuint32(maxlen);
}
/**
* @dev Returns true if an amulet has been revealed.
* If this returns false, we cannot be sure the amulet even exists! Don't accept an amulet from someone
* if it's not revealed and they won't show you the text of the amulet.
*/functionisRevealed(uint256 tokenId) externaloverrideviewreturns(bool) {
(address owner, uint64 blockRevealed,) = getData(tokenId);
require(owner !=address(0), "ERC721: isRevealed query for nonexistent token");
return blockRevealed >0;
}
/**
* @dev Mint a new amulet.
* @param data The ID and owner for the new token.
*/functionmint(MintData memory data) publicoverride{
require(data.owner !=address(0), "ERC1155: mint to the zero address");
require(_tokens[data.tokenId] ==0, "ERC1155: mint of existing token");
_tokens[data.tokenId] =uint256(uint160(data.owner));
emit TransferSingle(msg.sender, address(0), data.owner, data.tokenId, 1);
_doSafeTransferAcceptanceCheck(msg.sender, address(0), data.owner, data.tokenId, 1, "");
}
/**
* @dev Mint new amulets.
* @param data The IDs and amulets for the new tokens.
*/functionmintAll(MintData[] memory data) publicoverride{
for(uint i =0; i < data.length; i++) {
mint(data[i]);
}
}
/**
* @dev Reveals an amulet.
* @param data The title, text, and offset URL for the amulet.
*/functionreveal(RevealData calldata data) publicoverride{
require(bytes(data.amulet).length<=64, "Amulet: Too long");
uint256 tokenId =uint256(keccak256(bytes(data.amulet)));
(address owner, uint64 blockRevealed, uint32 score) = getData(tokenId);
require(
owner ==msg.sender|| isApprovedForAll(owner, msg.sender),
"Amulet: reveal caller is not owner nor approved"
);
require(blockRevealed ==0, "Amulet: Already revealed");
score = getScore(data.amulet);
require(score >=4, "Amulet: Score too low");
setData(tokenId, owner, uint64(block.number), score);
emit AmuletRevealed(tokenId, msg.sender, data.title, data.amulet, data.offsetURL);
}
/**
* @dev Reveals multiple amulets
* @param data The titles, texts, and offset URLs for the amulets.
*/functionrevealAll(RevealData[] calldata data) externaloverride{
for(uint i =0; i < data.length; i++) {
reveal(data[i]);
}
}
/**
* @dev Mint and reveal an amulet.
* @param data The title, text, offset URL, and owner for the new amulet.
*/functionmintAndReveal(MintAndRevealData memory data) publicoverride{
require(bytes(data.amulet).length<=64, "Amulet: Too long");
uint256 tokenId =uint256(keccak256(bytes(data.amulet)));
(address owner,,) = getData(tokenId);
require(owner ==address(0), "ERC1155: mint of existing token");
require(data.owner !=address(0), "ERC1155: mint to the zero address");
uint32 score = getScore(data.amulet);
require(score >=4, "Amulet: Score too low");
setData(tokenId, data.owner, uint64(block.number), score);
emit TransferSingle(msg.sender, address(0), data.owner, tokenId, 1);
emit AmuletRevealed(tokenId, msg.sender, data.title, data.amulet, data.offsetURL);
}
/**
* @dev Mint and reveal amulets.
* @param data The titles, texts, offset URLs, and owners for the new amulets.
*/functionmintAndRevealAll(MintAndRevealData[] memory data) publicoverride{
for(uint i =0; i < data.length; i++) {
mintAndReveal(data[i]);
}
}
/**
* @dev Returns the Amulet's owner address, the block it was revealed in, and its score.
*/functiongetData(uint256 tokenId) publicoverrideviewreturns(address owner, uint64 blockRevealed, uint32 score) {
uint256 t = _tokens[tokenId];
owner =address(uint160(t));
blockRevealed =uint64(t >>160);
score =uint32(t >>224);
}
/**
* @dev Sets the amulet's owner address, reveal block, and score.
*/functionsetData(uint256 tokenId, address owner, uint64 blockRevealed, uint32 score) internal{
_tokens[tokenId] =uint256(uint160(owner)) | (uint256(blockRevealed) <<160) | (uint256(score) <<224);
}
/**************************************************************************
* Internal/private methods
*************************************************************************/function_doSafeTransferAcceptanceCheck(address operator,
addressfrom,
address to,
uint256 id,
uint256 amount,
bytesmemory data
)
private{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catchError(stringmemory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function_doSafeBatchTransferAcceptanceCheck(address operator,
addressfrom,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytesmemory data
)
private{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catchError(stringmemory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
}
Contract Source Code
File 3 of 9: ERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^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.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
Contract Source Code
File 4 of 9: IAmulet.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import"@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
interfaceIAmuletisIERC1155, IERC1155MetadataURI{
eventAmuletRevealed(uint256indexed tokenId, address revealedBy, string title, string amulet, string offsetUrl);
structMintData {
address owner;
uint256 tokenId;
}
structRevealData {
string title;
string amulet;
string offsetURL;
}
structMintAndRevealData {
string title;
string amulet;
string offsetURL;
address owner;
}
/**
* @dev Returns the owner of the token with id `id`.
*/functionownerOf(uint256 id) externalviewreturns(address);
/**
* @dev Returns the score of an amulet.
* 0-3: Not an amulet
* 4: common
* 5: uncommon
* 6: rare
* 7: epic
* 8: legendary
* 9: mythic
* 10+: beyond mythic
*/functiongetScore(stringcalldata amulet) externalpurereturns(uint32);
/**
* @dev Returns true if an amulet has been revealed.
* If this returns false, we cannot be sure the amulet even exists! Don't accept an amulet from someone
* if it's not revealed and they won't show you the text of the amulet.
*/functionisRevealed(uint256 tokenId) externalviewreturns(bool);
/**
* @dev Mint a new amulet.
* @param data The ID and owner for the new token.
*/functionmint(MintData calldata data) external;
/**
* @dev Mint new amulets.
* @param data The IDs and amulets for the new tokens.
*/functionmintAll(MintData[] calldata data) external;
/**
* @dev Reveals an amulet.
* @param data The title, text, and offset URL for the amulet.
*/functionreveal(RevealData calldata data) external;
/**
* @dev Reveals multiple amulets
* @param data The titles, texts, and offset URLs for the amulets.
*/functionrevealAll(RevealData[] calldata data) external;
/**
* @dev Mint and reveal an amulet.
* @param data The title, text, offset URL, and owner for the new amulet.
*/functionmintAndReveal(MintAndRevealData calldata data) external;
/**
* @dev Mint and reveal amulets.
* @param data The titles, texts, offset URLs, and owners for the new amulets.
*/functionmintAndRevealAll(MintAndRevealData[] calldata data) external;
/**
* @dev Returns the Amulet's owner address, the block it was revealed in, and its score.
*/functiongetData(uint256 tokenId) externalviewreturns(address owner, uint64 blockRevealed, uint32 score);
}
Contract Source Code
File 5 of 9: IERC1155.sol
// SPDX-License-Identifier: MITpragmasolidity ^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._
*/interfaceIERC1155isIERC165{
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/eventTransferSingle(addressindexed operator, addressindexedfrom, addressindexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/eventTransferBatch(addressindexed operator, addressindexedfrom, addressindexed to, uint256[] ids, uint256[] values);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/eventApprovalForAll(addressindexed account, addressindexed 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}.
*/eventURI(string value, uint256indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/functionbalanceOf(address account, uint256 id) externalviewreturns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/functionbalanceOfBatch(address[] calldata accounts, uint256[] calldata ids) externalviewreturns (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.
*/functionsetApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/functionisApprovedForAll(address account, address operator) externalviewreturns (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 be 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.
*/functionsafeTransferFrom(addressfrom, address to, uint256 id, uint256 amount, bytescalldata 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.
*/functionsafeBatchTransferFrom(addressfrom, address to, uint256[] calldata ids, uint256[] calldata amounts, bytescalldata data) external;
}
Contract Source Code
File 6 of 9: IERC1155MetadataURI.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/interfaceIERC1155MetadataURIisIERC1155{
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/functionuri(uint256 id) externalviewreturns (stringmemory);
}
Contract Source Code
File 7 of 9: IERC1155Receiver.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* _Available since v3.1._
*/interfaceIERC1155ReceiverisIERC165{
/**
@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.
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
*/functiononERC1155Received(address operator,
addressfrom,
uint256 id,
uint256 value,
bytescalldata data
)
externalreturns(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. 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
*/functiononERC1155BatchReceived(address operator,
addressfrom,
uint256[] calldata ids,
uint256[] calldata values,
bytescalldata data
)
externalreturns(bytes4);
}
Contract Source Code
File 8 of 9: IERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^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}.
*/interfaceIERC165{
/**
* @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.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 9 of 9: ProxyRegistryWhitelist.sol
// SPDX-License-Identifier: MIT// Derived from OpenZeppelin's ERC721 implementation, with changes for gas-efficiency.pragmasolidity ^0.8.0;contractProxyRegistry{
mapping(address=>address) public proxies;
}
contractProxyRegistryWhitelist{
ProxyRegistry public proxyRegistry;
constructor(address proxyRegistryAddress) {
proxyRegistry = ProxyRegistry(proxyRegistryAddress);
}
functionisProxyForOwner(address owner, address caller) internalviewreturns(bool) {
if(address(proxyRegistry) ==address(0)) {
returnfalse;
}
return proxyRegistry.proxies(owner) == caller;
}
}