Created
August 10, 2021 16:56
-
-
Save kingassune/629cfb1c0d923de589ecd761768953e9 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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() { | |
_setOwner(_msgSender()); | |
} | |
/** | |
* @dev Returns the address of the current owner. | |
*/ | |
function owner() public view virtual returns (address) { | |
return _owner; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
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 { | |
_setOwner(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"); | |
_setOwner(newOwner); | |
} | |
function _setOwner(address newOwner) private { | |
address oldOwner = _owner; | |
_owner = newOwner; | |
emit OwnershipTransferred(oldOwner, newOwner); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "../IERC721.sol"; | |
/** | |
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension | |
* @dev See https://eips.ethereum.org/EIPS/eip-721 | |
*/ | |
interface IERC721Enumerable is IERC721 { | |
/** | |
* @dev Returns the total amount of tokens stored by the contract. | |
*/ | |
function totalSupply() external view returns (uint256); | |
/** | |
* @dev Returns a token ID owned by `owner` at a given `index` of its token list. | |
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens. | |
*/ | |
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); | |
/** | |
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract. | |
* Use along with {totalSupply} to enumerate all tokens. | |
*/ | |
function tokenByIndex(uint256 index) external view returns (uint256); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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`, 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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 `IERC721.onERC721Received.selector`. | |
*/ | |
function onERC721Received( | |
address operator, | |
address from, | |
uint256 tokenId, | |
bytes calldata data | |
) external returns (bytes4); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^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; | |
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"); | |
(bool success, ) = recipient.call{value: amount}(""); | |
require(success, "Address: unable to send value, recipient may have reverted"); | |
} | |
/** | |
* @dev Performs a Solidity function call using a low level `call`. A | |
* plain `call` is an unsafe replacement for a function call: use this | |
* function instead. | |
* | |
* If `target` reverts with a revert reason, it is bubbled up by this | |
* function (like regular Solidity function calls). | |
* | |
* Returns the raw returned data. To convert to the expected return value, | |
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. | |
* | |
* Requirements: | |
* | |
* - `target` must be a contract. | |
* - calling `target` with `data` must not revert. | |
* | |
* _Available since v3.1._ | |
*/ | |
function functionCall(address target, bytes memory data) internal returns (bytes memory) { | |
return functionCall(target, data, "Address: low-level call failed"); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with | |
* `errorMessage` as a fallback revert reason when `target` reverts. | |
* | |
* _Available since v3.1._ | |
*/ | |
function functionCall( | |
address target, | |
bytes memory data, | |
string memory errorMessage | |
) internal returns (bytes memory) { | |
return functionCallWithValue(target, data, 0, errorMessage); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | |
* but also transferring `value` wei to `target`. | |
* | |
* Requirements: | |
* | |
* - the calling contract must have an ETH balance of at least `value`. | |
* - the called Solidity function must be `payable`. | |
* | |
* _Available since v3.1._ | |
*/ | |
function functionCallWithValue( | |
address target, | |
bytes memory data, | |
uint256 value | |
) internal returns (bytes memory) { | |
return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but | |
* with `errorMessage` as a fallback revert reason when `target` reverts. | |
* | |
* _Available since v3.1._ | |
*/ | |
function functionCallWithValue( | |
address target, | |
bytes memory data, | |
uint256 value, | |
string memory errorMessage | |
) internal returns (bytes memory) { | |
require(address(this).balance >= value, "Address: insufficient balance for call"); | |
require(isContract(target), "Address: call to non-contract"); | |
(bool success, bytes memory returndata) = target.call{value: value}(data); | |
return _verifyCallResult(success, returndata, errorMessage); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | |
* but performing a static call. | |
* | |
* _Available since v3.3._ | |
*/ | |
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { | |
return functionStaticCall(target, data, "Address: low-level static call failed"); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], | |
* but performing a static call. | |
* | |
* _Available since v3.3._ | |
*/ | |
function functionStaticCall( | |
address target, | |
bytes memory data, | |
string memory errorMessage | |
) internal view returns (bytes memory) { | |
require(isContract(target), "Address: static call to non-contract"); | |
(bool success, bytes memory returndata) = target.staticcall(data); | |
return _verifyCallResult(success, returndata, errorMessage); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | |
* but performing a delegate call. | |
* | |
* _Available since v3.4._ | |
*/ | |
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { | |
return functionDelegateCall(target, data, "Address: low-level delegate call failed"); | |
} | |
/** | |
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], | |
* but performing a delegate call. | |
* | |
* _Available since v3.4._ | |
*/ | |
function functionDelegateCall( | |
address target, | |
bytes memory data, | |
string memory errorMessage | |
) internal returns (bytes memory) { | |
require(isContract(target), "Address: delegate call to non-contract"); | |
(bool success, bytes memory returndata) = target.delegatecall(data); | |
return _verifyCallResult(success, returndata, errorMessage); | |
} | |
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 | |
assembly { | |
let returndata_size := mload(returndata) | |
revert(add(32, returndata), returndata_size) | |
} | |
} else { | |
revert(errorMessage); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
/** | |
* @dev String operations. | |
*/ | |
library Strings { | |
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` decimal representation. | |
*/ | |
function toString(uint256 value) internal pure returns (string memory) { | |
// Inspired by OraclizeAPI's implementation - MIT licence | |
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol | |
if (value == 0) { | |
return "0"; | |
} | |
uint256 temp = value; | |
uint256 digits; | |
while (temp != 0) { | |
digits++; | |
temp /= 10; | |
} | |
bytes memory buffer = new bytes(digits); | |
while (value != 0) { | |
digits -= 1; | |
buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); | |
value /= 10; | |
} | |
return string(buffer); | |
} | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. | |
*/ | |
function toHexString(uint256 value) internal pure returns (string memory) { | |
if (value == 0) { | |
return "0x00"; | |
} | |
uint256 temp = value; | |
uint256 length = 0; | |
while (temp != 0) { | |
length++; | |
temp >>= 8; | |
} | |
return toHexString(value, length); | |
} | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. | |
*/ | |
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { | |
bytes memory buffer = new bytes(2 * length + 2); | |
buffer[0] = "0"; | |
buffer[1] = "x"; | |
for (uint256 i = 2 * length + 1; i > 1; --i) { | |
buffer[i] = _HEX_SYMBOLS[value & 0xf]; | |
value >>= 4; | |
} | |
require(value == 0, "Strings: hex length insufficient"); | |
return string(buffer); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REMIX EXAMPLE PROJECT | |
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer. | |
It contains 3 directories: | |
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name. | |
2. 'scripts': Holds two scripts to deploy a contract. It is explained below. | |
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity. | |
SCRIPTS | |
The 'scripts' folder contains example async/await scripts for deploying the 'Storage' contract. | |
For the deployment of any other contract, 'contractName' and 'constructorArgs' should be updated (along with other code if required). | |
Scripts have full access to the web3.js and ethers.js libraries. | |
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled. | |
Output from script will appear in remix terminal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this line is added to create a gist. Empty file is not allowed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compiler": { | |
"version": "0.8.6+commit.11564f7e" | |
}, | |
"language": "Solidity", | |
"output": { | |
"abi": [ | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "_noundersDAO", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "_minter", | |
"type": "address" | |
}, | |
{ | |
"internalType": "contract INounsDescriptor", | |
"name": "_descriptor", | |
"type": "address" | |
}, | |
{ | |
"internalType": "contract INounsSeeder", | |
"name": "_seeder", | |
"type": "address" | |
}, | |
{ | |
"internalType": "contract IProxyRegistry", | |
"name": "_proxyRegistry", | |
"type": "address" | |
} | |
], | |
"stateMutability": "nonpayable", | |
"type": "constructor" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "approved", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "Approval", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
}, | |
{ | |
"indexed": false, | |
"internalType": "bool", | |
"name": "approved", | |
"type": "bool" | |
} | |
], | |
"name": "ApprovalForAll", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "delegator", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "fromDelegate", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "toDelegate", | |
"type": "address" | |
} | |
], | |
"name": "DelegateChanged", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "delegate", | |
"type": "address" | |
}, | |
{ | |
"indexed": false, | |
"internalType": "uint256", | |
"name": "previousBalance", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"internalType": "uint256", | |
"name": "newBalance", | |
"type": "uint256" | |
} | |
], | |
"name": "DelegateVotesChanged", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [], | |
"name": "DescriptorLocked", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"internalType": "contract INounsDescriptor", | |
"name": "descriptor", | |
"type": "address" | |
} | |
], | |
"name": "DescriptorUpdated", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [], | |
"name": "MinterLocked", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"internalType": "address", | |
"name": "minter", | |
"type": "address" | |
} | |
], | |
"name": "MinterUpdated", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "NounBurned", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
}, | |
{ | |
"components": [ | |
{ | |
"internalType": "uint48", | |
"name": "background", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "body", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "accessory", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "head", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "glasses", | |
"type": "uint48" | |
} | |
], | |
"indexed": false, | |
"internalType": "struct INounsSeeder.Seed", | |
"name": "seed", | |
"type": "tuple" | |
} | |
], | |
"name": "NounCreated", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"internalType": "address", | |
"name": "noundersDAO", | |
"type": "address" | |
} | |
], | |
"name": "NoundersDAOUpdated", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "previousOwner", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "newOwner", | |
"type": "address" | |
} | |
], | |
"name": "OwnershipTransferred", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [], | |
"name": "SeederLocked", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"internalType": "contract INounsSeeder", | |
"name": "seeder", | |
"type": "address" | |
} | |
], | |
"name": "SeederUpdated", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "Transfer", | |
"type": "event" | |
}, | |
{ | |
"inputs": [], | |
"name": "DELEGATION_TYPEHASH", | |
"outputs": [ | |
{ | |
"internalType": "bytes32", | |
"name": "", | |
"type": "bytes32" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "DOMAIN_TYPEHASH", | |
"outputs": [ | |
{ | |
"internalType": "bytes32", | |
"name": "", | |
"type": "bytes32" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "approve", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
} | |
], | |
"name": "balanceOf", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "nounId", | |
"type": "uint256" | |
} | |
], | |
"name": "burn", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint32", | |
"name": "", | |
"type": "uint32" | |
} | |
], | |
"name": "checkpoints", | |
"outputs": [ | |
{ | |
"internalType": "uint32", | |
"name": "fromBlock", | |
"type": "uint32" | |
}, | |
{ | |
"internalType": "uint96", | |
"name": "votes", | |
"type": "uint96" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "contractURI", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "dataURI", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "decimals", | |
"outputs": [ | |
{ | |
"internalType": "uint8", | |
"name": "", | |
"type": "uint8" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "delegatee", | |
"type": "address" | |
} | |
], | |
"name": "delegate", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "delegatee", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "nonce", | |
"type": "uint256" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "expiry", | |
"type": "uint256" | |
}, | |
{ | |
"internalType": "uint8", | |
"name": "v", | |
"type": "uint8" | |
}, | |
{ | |
"internalType": "bytes32", | |
"name": "r", | |
"type": "bytes32" | |
}, | |
{ | |
"internalType": "bytes32", | |
"name": "s", | |
"type": "bytes32" | |
} | |
], | |
"name": "delegateBySig", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "delegator", | |
"type": "address" | |
} | |
], | |
"name": "delegates", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "descriptor", | |
"outputs": [ | |
{ | |
"internalType": "contract INounsDescriptor", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "getApproved", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "account", | |
"type": "address" | |
} | |
], | |
"name": "getCurrentVotes", | |
"outputs": [ | |
{ | |
"internalType": "uint96", | |
"name": "", | |
"type": "uint96" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "account", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "blockNumber", | |
"type": "uint256" | |
} | |
], | |
"name": "getPriorVotes", | |
"outputs": [ | |
{ | |
"internalType": "uint96", | |
"name": "", | |
"type": "uint96" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
} | |
], | |
"name": "isApprovedForAll", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "isDescriptorLocked", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "isMinterLocked", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "isSeederLocked", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "lockDescriptor", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "lockMinter", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "lockSeeder", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "mint", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "minter", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "name", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"name": "nonces", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "noundersDAO", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"name": "numCheckpoints", | |
"outputs": [ | |
{ | |
"internalType": "uint32", | |
"name": "", | |
"type": "uint32" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "owner", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "ownerOf", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "proxyRegistry", | |
"outputs": [ | |
{ | |
"internalType": "contract IProxyRegistry", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "renounceOwnership", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "safeTransferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
}, | |
{ | |
"internalType": "bytes", | |
"name": "_data", | |
"type": "bytes" | |
} | |
], | |
"name": "safeTransferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "seeder", | |
"outputs": [ | |
{ | |
"internalType": "contract INounsSeeder", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"name": "seeds", | |
"outputs": [ | |
{ | |
"internalType": "uint48", | |
"name": "background", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "body", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "accessory", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "head", | |
"type": "uint48" | |
}, | |
{ | |
"internalType": "uint48", | |
"name": "glasses", | |
"type": "uint48" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
}, | |
{ | |
"internalType": "bool", | |
"name": "approved", | |
"type": "bool" | |
} | |
], | |
"name": "setApprovalForAll", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "string", | |
"name": "newContractURIHash", | |
"type": "string" | |
} | |
], | |
"name": "setContractURIHash", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "contract INounsDescriptor", | |
"name": "_descriptor", | |
"type": "address" | |
} | |
], | |
"name": "setDescriptor", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "_minter", | |
"type": "address" | |
} | |
], | |
"name": "setMinter", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "_noundersDAO", | |
"type": "address" | |
} | |
], | |
"name": "setNoundersDAO", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "contract INounsSeeder", | |
"name": "_seeder", | |
"type": "address" | |
} | |
], | |
"name": "setSeeder", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "bytes4", | |
"name": "interfaceId", | |
"type": "bytes4" | |
} | |
], | |
"name": "supportsInterface", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "symbol", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "index", | |
"type": "uint256" | |
} | |
], | |
"name": "tokenByIndex", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "index", | |
"type": "uint256" | |
} | |
], | |
"name": "tokenOfOwnerByIndex", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "tokenURI", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "totalSupply", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "transferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "newOwner", | |
"type": "address" | |
} | |
], | |
"name": "transferOwnership", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "delegator", | |
"type": "address" | |
} | |
], | |
"name": "votesToDelegate", | |
"outputs": [ | |
{ | |
"internalType": "uint96", | |
"name": "", | |
"type": "uint96" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
} | |
], | |
"devdoc": { | |
"kind": "dev", | |
"methods": { | |
"approve(address,uint256)": { | |
"details": "See {IERC721-approve}." | |
}, | |
"balanceOf(address)": { | |
"details": "See {IERC721-balanceOf}." | |
}, | |
"delegate(address)": { | |
"params": { | |
"delegatee": "The address to delegate votes to" | |
} | |
}, | |
"delegateBySig(address,uint256,uint256,uint8,bytes32,bytes32)": { | |
"params": { | |
"delegatee": "The address to delegate votes to", | |
"expiry": "The time at which to expire the signature", | |
"nonce": "The contract state required to match the signature", | |
"r": "Half of the ECDSA signature pair", | |
"s": "Half of the ECDSA signature pair", | |
"v": "The recovery byte of the signature" | |
} | |
}, | |
"getApproved(uint256)": { | |
"details": "See {IERC721-getApproved}." | |
}, | |
"getCurrentVotes(address)": { | |
"params": { | |
"account": "The address to get votes balance" | |
}, | |
"returns": { | |
"_0": "The number of current votes for `account`" | |
} | |
}, | |
"getPriorVotes(address,uint256)": { | |
"details": "Block number must be a finalized block or else this function will revert to prevent misinformation.", | |
"params": { | |
"account": "The address of the account to check", | |
"blockNumber": "The block number to get the vote balance at" | |
}, | |
"returns": { | |
"_0": "The number of votes the account had as of the given block" | |
} | |
}, | |
"lockDescriptor()": { | |
"details": "This cannot be reversed and is only callable by the owner when not locked." | |
}, | |
"lockMinter()": { | |
"details": "This cannot be reversed and is only callable by the owner when not locked." | |
}, | |
"lockSeeder()": { | |
"details": "This cannot be reversed and is only callable by the owner when not locked." | |
}, | |
"mint()": { | |
"details": "Call _mintTo with the to address(es)." | |
}, | |
"name()": { | |
"details": "See {IERC721Metadata-name}." | |
}, | |
"owner()": { | |
"details": "Returns the address of the current owner." | |
}, | |
"ownerOf(uint256)": { | |
"details": "See {IERC721-ownerOf}." | |
}, | |
"renounceOwnership()": { | |
"details": "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." | |
}, | |
"safeTransferFrom(address,address,uint256)": { | |
"details": "See {IERC721-safeTransferFrom}." | |
}, | |
"safeTransferFrom(address,address,uint256,bytes)": { | |
"details": "See {IERC721-safeTransferFrom}." | |
}, | |
"setApprovalForAll(address,bool)": { | |
"details": "See {IERC721-setApprovalForAll}." | |
}, | |
"setContractURIHash(string)": { | |
"details": "Only callable by the owner." | |
}, | |
"setDescriptor(address)": { | |
"details": "Only callable by the owner when not locked." | |
}, | |
"setMinter(address)": { | |
"details": "Only callable by the owner when not locked." | |
}, | |
"setNoundersDAO(address)": { | |
"details": "Only callable by the nounders DAO when not locked." | |
}, | |
"setSeeder(address)": { | |
"details": "Only callable by the owner when not locked." | |
}, | |
"supportsInterface(bytes4)": { | |
"details": "See {IERC165-supportsInterface}." | |
}, | |
"symbol()": { | |
"details": "See {IERC721Metadata-symbol}." | |
}, | |
"tokenByIndex(uint256)": { | |
"details": "See {IERC721Enumerable-tokenByIndex}." | |
}, | |
"tokenOfOwnerByIndex(address,uint256)": { | |
"details": "See {IERC721Enumerable-tokenOfOwnerByIndex}." | |
}, | |
"tokenURI(uint256)": { | |
"details": "See {IERC721Metadata-tokenURI}." | |
}, | |
"totalSupply()": { | |
"details": "See {IERC721Enumerable-totalSupply}." | |
}, | |
"transferFrom(address,address,uint256)": { | |
"details": "See {IERC721-transferFrom}." | |
}, | |
"transferOwnership(address)": { | |
"details": "Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner." | |
}, | |
"votesToDelegate(address)": { | |
"details": "Used when calling `_delegate()`" | |
} | |
}, | |
"version": 1 | |
}, | |
"userdoc": { | |
"events": { | |
"DelegateChanged(address,address,address)": { | |
"notice": "An event thats emitted when an account changes its delegate" | |
}, | |
"DelegateVotesChanged(address,uint256,uint256)": { | |
"notice": "An event thats emitted when a delegate account's vote balance changes" | |
} | |
}, | |
"kind": "user", | |
"methods": { | |
"DELEGATION_TYPEHASH()": { | |
"notice": "The EIP-712 typehash for the delegation struct used by the contract" | |
}, | |
"DOMAIN_TYPEHASH()": { | |
"notice": "The EIP-712 typehash for the contract's domain" | |
}, | |
"burn(uint256)": { | |
"notice": "Burn a noun." | |
}, | |
"checkpoints(address,uint32)": { | |
"notice": "A record of votes checkpoints for each account, by index" | |
}, | |
"contractURI()": { | |
"notice": "The IPFS URI of contract-level metadata." | |
}, | |
"dataURI(uint256)": { | |
"notice": "Similar to `tokenURI`, but always serves a base64 encoded data URI with the JSON contents directly inlined." | |
}, | |
"decimals()": { | |
"notice": "Defines decimals as per ERC-20 convention to make integrations with 3rd party governance platforms easier" | |
}, | |
"delegate(address)": { | |
"notice": "Delegate votes from `msg.sender` to `delegatee`" | |
}, | |
"delegateBySig(address,uint256,uint256,uint8,bytes32,bytes32)": { | |
"notice": "Delegates votes from signatory to `delegatee`" | |
}, | |
"delegates(address)": { | |
"notice": "Overrides the standard `Comp.sol` delegates mapping to return the delegator's own address if they haven't delegated. This avoids having to delegate to oneself." | |
}, | |
"getCurrentVotes(address)": { | |
"notice": "Gets the current votes balance for `account`" | |
}, | |
"getPriorVotes(address,uint256)": { | |
"notice": "Determine the prior number of votes for an account as of a block number" | |
}, | |
"isApprovedForAll(address,address)": { | |
"notice": "Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings." | |
}, | |
"lockDescriptor()": { | |
"notice": "Lock the descriptor." | |
}, | |
"lockMinter()": { | |
"notice": "Lock the minter." | |
}, | |
"lockSeeder()": { | |
"notice": "Lock the seeder." | |
}, | |
"mint()": { | |
"notice": "Mint a Noun to the minter, along with a possible nounders reward Noun. Nounders reward Nouns are minted every 10 Nouns, starting at 0, until 183 nounder Nouns have been minted (5 years w/ 24 hour auctions)." | |
}, | |
"nonces(address)": { | |
"notice": "A record of states for signing / validating signatures" | |
}, | |
"numCheckpoints(address)": { | |
"notice": "The number of checkpoints for each account" | |
}, | |
"setContractURIHash(string)": { | |
"notice": "Set the _contractURIHash." | |
}, | |
"setDescriptor(address)": { | |
"notice": "Set the token URI descriptor." | |
}, | |
"setMinter(address)": { | |
"notice": "Set the token minter." | |
}, | |
"setNoundersDAO(address)": { | |
"notice": "Set the nounders DAO." | |
}, | |
"setSeeder(address)": { | |
"notice": "Set the token seeder." | |
}, | |
"tokenURI(uint256)": { | |
"notice": "A distinct Uniform Resource Identifier (URI) for a given asset." | |
}, | |
"votesToDelegate(address)": { | |
"notice": "The votes a delegator can delegate, which is the current balance of the delegator." | |
} | |
}, | |
"version": 1 | |
} | |
}, | |
"settings": { | |
"compilationTarget": { | |
"contracts/NounsToken.sol": "NounsToken" | |
}, | |
"evmVersion": "berlin", | |
"libraries": {}, | |
"metadata": { | |
"bytecodeHash": "ipfs" | |
}, | |
"optimizer": { | |
"enabled": true, | |
"runs": 200 | |
}, | |
"remappings": [] | |
}, | |
"sources": { | |
"@openzeppelin/contracts/access/Ownable.sol": { | |
"keccak256": "0x6bb804a310218875e89d12c053e94a13a4607cdf7cc2052f3e52bd32a0dc50a1", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://b2ebbbe6d0011175bd9e7268b83de3f9c2f9d8d4cbfbaef12aff977d7d727163", | |
"dweb:/ipfs/Qmd5c7Vxtis9wzkDNhxwc6A2QT5H9xn9kfjhx7qx44vpro" | |
] | |
}, | |
"@openzeppelin/contracts/token/ERC721/IERC721.sol": { | |
"keccak256": "0xf101e8720213560fab41104d53b3cc7ba0456ef3a98455aa7f022391783144a0", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://3e7820bcf567e6892d937c3cb10db263a4042e446799bca602535868d822384e", | |
"dweb:/ipfs/QmPG2oeDjKncqsEeyYGjAN7CwAJmMgHterXGGnpzhha4z7" | |
] | |
}, | |
"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": { | |
"keccak256": "0xd9517254724276e2e8de3769183c1f738f445f0095c26fd9b86d3c6687e887b9", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://0e604bcdcd5e5b2fb299ad09769cde6db19d5aa1929d1b5e939234a0f10d7eb8", | |
"dweb:/ipfs/Qmd8hXE3GZfBHuWx3RNiYgFW2ci7KvHtib8DiwzJ2dgo9V" | |
] | |
}, | |
"@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol": { | |
"keccak256": "0xa69205e5009601cf13be78b1e2f500e1e3b1d8012f22d966e63975273f602038", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://d919a0061e43f9878f6171b7f853cb92093805cd1160858c1884195a639b40a0", | |
"dweb:/ipfs/QmRZsS3EYuLp75nBym1QQ4y6aQXGew75wSbv1uwqkvouUK" | |
] | |
}, | |
"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": { | |
"keccak256": "0xd32fb7f530a914b1083d10a6bed3a586f2451952fec04fe542bcc670a82f7ba5", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://af63ab940a34687c45f0ad84960b048fc5f49330c92ccb422db7822a444733b9", | |
"dweb:/ipfs/QmUShaQEu8HS1GjDnsMJQ8jkZEBrecn6NuDZ3pfjY1gVck" | |
] | |
}, | |
"@openzeppelin/contracts/utils/Address.sol": { | |
"keccak256": "0x3b4820cac4f127869f6eb496c1d74fa6ac86ed24071e0f94742e6aef20e7252c", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://23e1c7303c30a2ef9c9b3f861cda15c78e4c9697b4a7988f2bf7b21c392a02fb", | |
"dweb:/ipfs/QmWQJh5MsXJZjSTzAs9n5gtrqWYgXwkBa6xfwD5KKGQgSC" | |
] | |
}, | |
"@openzeppelin/contracts/utils/Context.sol": { | |
"keccak256": "0x95098bd1d9c8dec4d80d3dedb88a0d949fa0d740ee99f2aa466bc308216ca6d5", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://7fec968dcd68e13961521fa3c7dd87baecad91a2653b19240e81f21cc4f3ba85", | |
"dweb:/ipfs/QmaXtsYt4Mphm8XHNUfk2me1cF3ssS2SqDBNFpYAzMjomC" | |
] | |
}, | |
"@openzeppelin/contracts/utils/Strings.sol": { | |
"keccak256": "0x391d3ba97ab6856a16b225d6ee29617ad15ff00db70f3b4df1ab5ea33aa47c9d", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://d636ba90bbbeed04a1ea7fe9ec2466757e30fd38ba2ca173636dbf69a518735e", | |
"dweb:/ipfs/QmQwCB2BHnEuYR22PYt9HkpbgeFDhq4rHmaYqAZbX3WRC7" | |
] | |
}, | |
"@openzeppelin/contracts/utils/introspection/ERC165.sol": { | |
"keccak256": "0x5718c5df9bd67ac68a796961df938821bb5dc0cd4c6118d77e9145afb187409b", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://d10e1d9b26042424789246603906ad06143bf9a928f4e99de8b5e3bdc662f549", | |
"dweb:/ipfs/Qmejonoaj5MLekPus229rJQHcC6E9dz2xorjHJR84fMfmn" | |
] | |
}, | |
"@openzeppelin/contracts/utils/introspection/IERC165.sol": { | |
"keccak256": "0xa28007762d9da9db878dd421960c8cb9a10471f47ab5c1b3309bfe48e9e79ff4", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://796ab6e88af7bf0e78def0f059310c903af6a312b565344e0ff524a0f26e81c6", | |
"dweb:/ipfs/QmcsVgLgzWdor3UnAztUkXKNGcysm1MPneWksF72AvnwBx" | |
] | |
}, | |
"contracts/ERC721.sol": { | |
"keccak256": "0xb1f95c731eb5f6b6a825ef231f1a41adc4f1c0d29fa7468359826f1517910252", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://3f996c0380182df786d39ae07a6ec9550fe28085b2380d60f783916d758e4cfe", | |
"dweb:/ipfs/QmPfPfHvupqXnGHmmJkZyqqMdRfmpCY8EaeoezVwh6N5Fq" | |
] | |
}, | |
"contracts/ERC721Checkpointable.sol": { | |
"keccak256": "0x4cf0f08a6e2fdc95aa52efc34954e49b50f03d3df3fca94ad235d6e35cd316b9", | |
"license": "BSD-3-Clause", | |
"urls": [ | |
"bzz-raw://de967443c67bc97b33dd2ccce98f374a6346f40da7a2c58285430457c6bab2f3", | |
"dweb:/ipfs/QmWKGt3YHcPkWMS6UzMFZapUBz3zwz814u7XSmhtF3cRvG" | |
] | |
}, | |
"contracts/ERC721Enumerable.sol": { | |
"keccak256": "0x732410e3e4cdd8007446b4c438f2997a49f63c3c99738111a0fd6194353d8377", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://2664eafa5da3378671cfa11ac91f75d1634b69592547457f88fa4cbeabd4ec4d", | |
"dweb:/ipfs/QmZZDpV6XWu15vb78fYgyktZBfU2xiZkSeEp2tgKf9F85t" | |
] | |
}, | |
"contracts/INounsDescriptor.sol": { | |
"keccak256": "0x4c4f18eefd703c692173b823fa91325a45daed023e8b4439e7f5eacf112a8914", | |
"license": "GPL-3.0", | |
"urls": [ | |
"bzz-raw://4c77b219c4eebe7c52217595e5a26c1dceb20af3e71776baf2665860a7147441", | |
"dweb:/ipfs/Qmcrg21PMuR7fiV15bn99dyJzHvSAWroUxy6PNDKoLueGy" | |
] | |
}, | |
"contracts/INounsSeeder.sol": { | |
"keccak256": "0x594e2edcdff74b9e9bbfdf49fd97b8032b40c60cdc06dc34716311807a5f94b4", | |
"license": "GPL-3.0", | |
"urls": [ | |
"bzz-raw://0506fcd6538ad4ce4f2a88c45e1a4bda53c3335873d2c3e0be7f10197b8ad964", | |
"dweb:/ipfs/QmSFDhiFRjUep1ByJdTggqrVscitChzkZAygYxdPf8BMrA" | |
] | |
}, | |
"contracts/INounsToken.sol": { | |
"keccak256": "0xfa606836d99e78db8cb390ce9090f024874f61e27d4fabc7e58d31a331f63389", | |
"license": "GPL-3.0", | |
"urls": [ | |
"bzz-raw://5f62bb434ddf557b0f40a70619214ccf08f8f418e466df6158c3e3ac279bbb03", | |
"dweb:/ipfs/QmcM8RpYrZLGKvRpYHWwQ2ZRhUGs23hYEekrBJDRVtXyyH" | |
] | |
}, | |
"contracts/IProxyRegistry.sol": { | |
"keccak256": "0x56580e041fe67cc7e15343e1efc5ed2641268abb49fb426d7d57365aa96fb37c", | |
"license": "MIT", | |
"urls": [ | |
"bzz-raw://0ea1f289baf6676b6ccf0ab86e4951b41aad4e19dadf182367671d42193ee3df", | |
"dweb:/ipfs/QmdngvewBMu4RzeKSV9HfFoPm4VtEJUNAG66pyLKd5SNTT" | |
] | |
}, | |
"contracts/NounsToken.sol": { | |
"keccak256": "0x43cc52ce2723d3aef6691625540e7e7c340028bbfbda15c68e3dbb5fddd388c2", | |
"license": "GPL-3.0", | |
"urls": [ | |
"bzz-raw://dbe37a46eeed54193b8afb4c89609d2e22c2886efd1beb6a47910ec1fd1cf92b", | |
"dweb:/ipfs/QmZx8r5W5qTCaSup7mS7R1eZVanrwkM3Nqi1BfJ8TA1JdV" | |
] | |
} | |
}, | |
"version": 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
/// @title ERC721 Token Implementation | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
// LICENSE | |
// ERC721.sol modifies OpenZeppelin's ERC721.sol: | |
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6618f9f18424ade44116d0221719f4c93be6a078/contracts/token/ERC721/ERC721.sol | |
// | |
// ERC721.sol source code copyright OpenZeppelin licensed under the MIT License. | |
// With modifications by Nounders DAO. | |
// | |
// | |
// MODIFICATIONS: | |
// `_safeMint` and `_mint` contain an additional `creator` argument and | |
// emit two `Transfer` logs, rather than one. The first log displays the | |
// transfer (mint) from `address(0)` to the `creator`. The second displays the | |
// transfer from the `creator` to the `to` address. This enables correct | |
// attribution on various NFT marketplaces. | |
pragma solidity ^0.8.6; | |
import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; | |
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; | |
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol'; | |
import '@openzeppelin/contracts/utils/Address.sol'; | |
import '@openzeppelin/contracts/utils/Context.sol'; | |
import '@openzeppelin/contracts/utils/Strings.sol'; | |
import '@openzeppelin/contracts/utils/introspection/ERC165.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}. | |
*/ | |
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { | |
using Address for address; | |
using Strings for uint256; | |
// Token name | |
string private _name; | |
// Token symbol | |
string private _symbol; | |
// Mapping from token ID to owner address | |
mapping(uint256 => address) private _owners; | |
// Mapping owner address to token count | |
mapping(address => uint256) private _balances; | |
// Mapping from token ID to approved address | |
mapping(uint256 => address) private _tokenApprovals; | |
// Mapping from owner to operator approvals | |
mapping(address => mapping(address => bool)) private _operatorApprovals; | |
/** | |
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. | |
*/ | |
constructor(string memory name_, string memory symbol_) { | |
_name = name_; | |
_symbol = symbol_; | |
} | |
/** | |
* @dev See {IERC165-supportsInterface}. | |
*/ | |
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { | |
return | |
interfaceId == type(IERC721).interfaceId || | |
interfaceId == type(IERC721Metadata).interfaceId || | |
super.supportsInterface(interfaceId); | |
} | |
/** | |
* @dev See {IERC721-balanceOf}. | |
*/ | |
function balanceOf(address owner) public view virtual override returns (uint256) { | |
require(owner != address(0), 'ERC721: balance query for the zero address'); | |
return _balances[owner]; | |
} | |
/** | |
* @dev See {IERC721-ownerOf}. | |
*/ | |
function ownerOf(uint256 tokenId) public view virtual override returns (address) { | |
address owner = _owners[tokenId]; | |
require(owner != address(0), 'ERC721: owner query for nonexistent token'); | |
return owner; | |
} | |
/** | |
* @dev See {IERC721Metadata-name}. | |
*/ | |
function name() public view virtual override returns (string memory) { | |
return _name; | |
} | |
/** | |
* @dev See {IERC721Metadata-symbol}. | |
*/ | |
function symbol() public view virtual override returns (string memory) { | |
return _symbol; | |
} | |
/** | |
* @dev See {IERC721Metadata-tokenURI}. | |
*/ | |
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { | |
require(_exists(tokenId), 'ERC721Metadata: URI query for nonexistent token'); | |
string memory baseURI = _baseURI(); | |
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; | |
} | |
/** | |
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each | |
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty | |
* by default, can be overriden in child contracts. | |
*/ | |
function _baseURI() internal view virtual returns (string memory) { | |
return ''; | |
} | |
/** | |
* @dev See {IERC721-approve}. | |
*/ | |
function approve(address to, uint256 tokenId) public virtual override { | |
address owner = ERC721.ownerOf(tokenId); | |
require(to != owner, 'ERC721: approval to current owner'); | |
require( | |
_msgSender() == owner || isApprovedForAll(owner, _msgSender()), | |
'ERC721: approve caller is not owner nor approved for all' | |
); | |
_approve(to, tokenId); | |
} | |
/** | |
* @dev See {IERC721-getApproved}. | |
*/ | |
function getApproved(uint256 tokenId) public view virtual override returns (address) { | |
require(_exists(tokenId), 'ERC721: approved query for nonexistent token'); | |
return _tokenApprovals[tokenId]; | |
} | |
/** | |
* @dev See {IERC721-setApprovalForAll}. | |
*/ | |
function setApprovalForAll(address operator, bool approved) public virtual override { | |
require(operator != _msgSender(), 'ERC721: approve to caller'); | |
_operatorApprovals[_msgSender()][operator] = approved; | |
emit ApprovalForAll(_msgSender(), operator, approved); | |
} | |
/** | |
* @dev See {IERC721-isApprovedForAll}. | |
*/ | |
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { | |
return _operatorApprovals[owner][operator]; | |
} | |
/** | |
* @dev See {IERC721-transferFrom}. | |
*/ | |
function transferFrom( | |
address from, | |
address to, | |
uint256 tokenId | |
) public virtual override { | |
//solhint-disable-next-line max-line-length | |
require(_isApprovedOrOwner(_msgSender(), tokenId), 'ERC721: transfer caller is not owner nor approved'); | |
_transfer(from, to, tokenId); | |
} | |
/** | |
* @dev See {IERC721-safeTransferFrom}. | |
*/ | |
function safeTransferFrom( | |
address from, | |
address to, | |
uint256 tokenId | |
) public virtual override { | |
safeTransferFrom(from, to, tokenId, ''); | |
} | |
/** | |
* @dev See {IERC721-safeTransferFrom}. | |
*/ | |
function safeTransferFrom( | |
address from, | |
address to, | |
uint256 tokenId, | |
bytes memory _data | |
) public virtual override { | |
require(_isApprovedOrOwner(_msgSender(), tokenId), 'ERC721: transfer caller is not owner nor approved'); | |
_safeTransfer(from, to, tokenId, _data); | |
} | |
/** | |
* @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. | |
* | |
* `_data` is additional data, it has no specified format and it is sent in call to `to`. | |
* | |
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. | |
* implement alternative mechanisms to perform token transfer, such as signature-based. | |
* | |
* Requirements: | |
* | |
* - `from` cannot be the zero address. | |
* - `to` cannot be the zero address. | |
* - `tokenId` token must exist and be owned by `from`. | |
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function _safeTransfer( | |
address from, | |
address to, | |
uint256 tokenId, | |
bytes memory _data | |
) internal virtual { | |
_transfer(from, to, tokenId); | |
require(_checkOnERC721Received(from, to, tokenId, _data), 'ERC721: transfer to non ERC721Receiver implementer'); | |
} | |
/** | |
* @dev Returns whether `tokenId` exists. | |
* | |
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. | |
* | |
* Tokens start existing when they are minted (`_mint`), | |
* and stop existing when they are burned (`_burn`). | |
*/ | |
function _exists(uint256 tokenId) internal view virtual returns (bool) { | |
return _owners[tokenId] != address(0); | |
} | |
/** | |
* @dev Returns whether `spender` is allowed to manage `tokenId`. | |
* | |
* Requirements: | |
* | |
* - `tokenId` must exist. | |
*/ | |
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { | |
require(_exists(tokenId), 'ERC721: operator query for nonexistent token'); | |
address owner = ERC721.ownerOf(tokenId); | |
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); | |
} | |
/** | |
* @dev Safely mints `tokenId`, transfers it to `to`, and emits two log events - | |
* 1. Credits the `minter` with the mint. | |
* 2. Shows transfer from the `minter` to `to`. | |
* | |
* Requirements: | |
* | |
* - `tokenId` must not exist. | |
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function _safeMint( | |
address creator, | |
address to, | |
uint256 tokenId | |
) internal virtual { | |
_safeMint(creator, to, tokenId, ''); | |
} | |
/** | |
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is | |
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients. | |
*/ | |
function _safeMint( | |
address creator, | |
address to, | |
uint256 tokenId, | |
bytes memory _data | |
) internal virtual { | |
_mint(creator, to, tokenId); | |
require( | |
_checkOnERC721Received(address(0), to, tokenId, _data), | |
'ERC721: transfer to non ERC721Receiver implementer' | |
); | |
} | |
/** | |
* @dev Mints `tokenId`, transfers it to `to`, and emits two log events - | |
* 1. Credits the `creator` with the mint. | |
* 2. Shows transfer from the `creator` to `to`. | |
* | |
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible | |
* | |
* Requirements: | |
* | |
* - `tokenId` must not exist. | |
* - `to` cannot be the zero address. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function _mint( | |
address creator, | |
address to, | |
uint256 tokenId | |
) internal virtual { | |
require(to != address(0), 'ERC721: mint to the zero address'); | |
require(!_exists(tokenId), 'ERC721: token already minted'); | |
_beforeTokenTransfer(address(0), to, tokenId); | |
_balances[to] += 1; | |
_owners[tokenId] = to; | |
emit Transfer(address(0), creator, tokenId); | |
emit Transfer(creator, to, tokenId); | |
} | |
/** | |
* @dev Destroys `tokenId`. | |
* The approval is cleared when the token is burned. | |
* | |
* Requirements: | |
* | |
* - `tokenId` must exist. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function _burn(uint256 tokenId) internal virtual { | |
address owner = ERC721.ownerOf(tokenId); | |
_beforeTokenTransfer(owner, address(0), tokenId); | |
// Clear approvals | |
_approve(address(0), tokenId); | |
_balances[owner] -= 1; | |
delete _owners[tokenId]; | |
emit Transfer(owner, address(0), tokenId); | |
} | |
/** | |
* @dev Transfers `tokenId` from `from` to `to`. | |
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender. | |
* | |
* Requirements: | |
* | |
* - `to` cannot be the zero address. | |
* - `tokenId` token must be owned by `from`. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function _transfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) internal virtual { | |
require(ERC721.ownerOf(tokenId) == from, 'ERC721: transfer of token that is not own'); | |
require(to != address(0), 'ERC721: transfer to the zero address'); | |
_beforeTokenTransfer(from, to, tokenId); | |
// Clear approvals from the previous owner | |
_approve(address(0), tokenId); | |
_balances[from] -= 1; | |
_balances[to] += 1; | |
_owners[tokenId] = to; | |
emit Transfer(from, to, tokenId); | |
} | |
/** | |
* @dev Approve `to` to operate on `tokenId` | |
* | |
* Emits a {Approval} event. | |
*/ | |
function _approve(address to, uint256 tokenId) internal virtual { | |
_tokenApprovals[tokenId] = to; | |
emit Approval(ERC721.ownerOf(tokenId), to, tokenId); | |
} | |
/** | |
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. | |
* The call is not executed if the target address is not a contract. | |
* | |
* @param from address representing the previous owner of the given token ID | |
* @param to target address that will receive the tokens | |
* @param tokenId uint256 ID of the token to be transferred | |
* @param _data bytes optional data to send along with the call | |
* @return bool whether the call correctly returned the expected magic value | |
*/ | |
function _checkOnERC721Received( | |
address from, | |
address to, | |
uint256 tokenId, | |
bytes memory _data | |
) private returns (bool) { | |
if (to.isContract()) { | |
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { | |
return retval == IERC721Receiver(to).onERC721Received.selector; | |
} catch (bytes memory reason) { | |
if (reason.length == 0) { | |
revert('ERC721: transfer to non ERC721Receiver implementer'); | |
} else { | |
assembly { | |
revert(add(32, reason), mload(reason)) | |
} | |
} | |
} | |
} else { | |
return true; | |
} | |
} | |
/** | |
* @dev Hook that is called before any token transfer. This includes minting | |
* and burning. | |
* | |
* Calling conditions: | |
* | |
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be | |
* transferred to `to`. | |
* - When `from` is zero, `tokenId` will be minted for `to`. | |
* - When `to` is zero, ``from``'s `tokenId` 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 tokenId | |
) internal virtual {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: BSD-3-Clause | |
/// @title Vote checkpointing for an ERC-721 token | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
// LICENSE | |
// ERC721Checkpointable.sol uses and modifies part of Compound Lab's Comp.sol: | |
// https://github.com/compound-finance/compound-protocol/blob/ae4388e780a8d596d97619d9704a931a2752c2bc/contracts/Governance/Comp.sol | |
// | |
// Comp.sol source code Copyright 2020 Compound Labs, Inc. licensed under the BSD-3-Clause license. | |
// With modifications by Nounders DAO. | |
// | |
// Additional conditions of BSD-3-Clause can be found here: https://opensource.org/licenses/BSD-3-Clause | |
// | |
// MODIFICATIONS | |
// Checkpointing logic from Comp.sol has been used with the following modifications: | |
// - `delegates` is renamed to `_delegates` and is set to private | |
// - `delegates` is a public function that uses the `_delegates` mapping look-up, but unlike | |
// Comp.sol, returns the delegator's own address if there is no delegate. | |
// This avoids the delegator needing to "delegate to self" with an additional transaction | |
// - `_transferTokens()` is renamed `_beforeTokenTransfer()` and adapted to hook into OpenZeppelin's ERC721 hooks. | |
pragma solidity ^0.8.6; | |
import './ERC721Enumerable.sol'; | |
abstract contract ERC721Checkpointable is ERC721Enumerable { | |
/// @notice Defines decimals as per ERC-20 convention to make integrations with 3rd party governance platforms easier | |
uint8 public constant decimals = 0; | |
/// @notice A record of each accounts delegate | |
mapping(address => address) private _delegates; | |
/// @notice A checkpoint for marking number of votes from a given block | |
struct Checkpoint { | |
uint32 fromBlock; | |
uint96 votes; | |
} | |
/// @notice A record of votes checkpoints for each account, by index | |
mapping(address => mapping(uint32 => Checkpoint)) public checkpoints; | |
/// @notice The number of checkpoints for each account | |
mapping(address => uint32) public numCheckpoints; | |
/// @notice The EIP-712 typehash for the contract's domain | |
bytes32 public constant DOMAIN_TYPEHASH = | |
keccak256('EIP712Domain(string name,uint256 chainId,address verifyingContract)'); | |
/// @notice The EIP-712 typehash for the delegation struct used by the contract | |
bytes32 public constant DELEGATION_TYPEHASH = | |
keccak256('Delegation(address delegatee,uint256 nonce,uint256 expiry)'); | |
/// @notice A record of states for signing / validating signatures | |
mapping(address => uint256) public nonces; | |
/// @notice An event thats emitted when an account changes its delegate | |
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); | |
/// @notice An event thats emitted when a delegate account's vote balance changes | |
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); | |
/** | |
* @notice The votes a delegator can delegate, which is the current balance of the delegator. | |
* @dev Used when calling `_delegate()` | |
*/ | |
function votesToDelegate(address delegator) public view returns (uint96) { | |
return safe96(balanceOf(delegator), 'ERC721Checkpointable::votesToDelegate: amount exceeds 96 bits'); | |
} | |
/** | |
* @notice Overrides the standard `Comp.sol` delegates mapping to return | |
* the delegator's own address if they haven't delegated. | |
* This avoids having to delegate to oneself. | |
*/ | |
function delegates(address delegator) public view returns (address) { | |
address current = _delegates[delegator]; | |
return current == address(0) ? delegator : current; | |
} | |
/** | |
* @notice Adapted from `_transferTokens()` in `Comp.sol` to update delegate votes. | |
* @dev hooks into OpenZeppelin's `ERC721._transfer` | |
*/ | |
function _beforeTokenTransfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) internal override { | |
super._beforeTokenTransfer(from, to, tokenId); | |
/// @notice Differs from `_transferTokens()` to use `delegates` override method to simulate auto-delegation | |
_moveDelegates(delegates(from), delegates(to), 1); | |
} | |
/** | |
* @notice Delegate votes from `msg.sender` to `delegatee` | |
* @param delegatee The address to delegate votes to | |
*/ | |
function delegate(address delegatee) public { | |
if (delegatee == address(0)) delegatee = msg.sender; | |
return _delegate(msg.sender, delegatee); | |
} | |
/** | |
* @notice Delegates votes from signatory to `delegatee` | |
* @param delegatee The address to delegate votes to | |
* @param nonce The contract state required to match the signature | |
* @param expiry The time at which to expire the signature | |
* @param v The recovery byte of the signature | |
* @param r Half of the ECDSA signature pair | |
* @param s Half of the ECDSA signature pair | |
*/ | |
function delegateBySig( | |
address delegatee, | |
uint256 nonce, | |
uint256 expiry, | |
uint8 v, | |
bytes32 r, | |
bytes32 s | |
) public { | |
bytes32 domainSeparator = keccak256( | |
abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this)) | |
); | |
bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry)); | |
bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash)); | |
address signatory = ecrecover(digest, v, r, s); | |
require(signatory != address(0), 'ERC721Checkpointable::delegateBySig: invalid signature'); | |
require(nonce == nonces[signatory]++, 'ERC721Checkpointable::delegateBySig: invalid nonce'); | |
require(block.timestamp <= expiry, 'ERC721Checkpointable::delegateBySig: signature expired'); | |
return _delegate(signatory, delegatee); | |
} | |
/** | |
* @notice Gets the current votes balance for `account` | |
* @param account The address to get votes balance | |
* @return The number of current votes for `account` | |
*/ | |
function getCurrentVotes(address account) external view returns (uint96) { | |
uint32 nCheckpoints = numCheckpoints[account]; | |
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; | |
} | |
/** | |
* @notice Determine the prior number of votes for an account as of a block number | |
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation. | |
* @param account The address of the account to check | |
* @param blockNumber The block number to get the vote balance at | |
* @return The number of votes the account had as of the given block | |
*/ | |
function getPriorVotes(address account, uint256 blockNumber) public view returns (uint96) { | |
require(blockNumber < block.number, 'ERC721Checkpointable::getPriorVotes: not yet determined'); | |
uint32 nCheckpoints = numCheckpoints[account]; | |
if (nCheckpoints == 0) { | |
return 0; | |
} | |
// First check most recent balance | |
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { | |
return checkpoints[account][nCheckpoints - 1].votes; | |
} | |
// Next check implicit zero balance | |
if (checkpoints[account][0].fromBlock > blockNumber) { | |
return 0; | |
} | |
uint32 lower = 0; | |
uint32 upper = nCheckpoints - 1; | |
while (upper > lower) { | |
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow | |
Checkpoint memory cp = checkpoints[account][center]; | |
if (cp.fromBlock == blockNumber) { | |
return cp.votes; | |
} else if (cp.fromBlock < blockNumber) { | |
lower = center; | |
} else { | |
upper = center - 1; | |
} | |
} | |
return checkpoints[account][lower].votes; | |
} | |
function _delegate(address delegator, address delegatee) internal { | |
/// @notice differs from `_delegate()` in `Comp.sol` to use `delegates` override method to simulate auto-delegation | |
address currentDelegate = delegates(delegator); | |
_delegates[delegator] = delegatee; | |
emit DelegateChanged(delegator, currentDelegate, delegatee); | |
uint96 amount = votesToDelegate(delegator); | |
_moveDelegates(currentDelegate, delegatee, amount); | |
} | |
function _moveDelegates( | |
address srcRep, | |
address dstRep, | |
uint96 amount | |
) internal { | |
if (srcRep != dstRep && amount > 0) { | |
if (srcRep != address(0)) { | |
uint32 srcRepNum = numCheckpoints[srcRep]; | |
uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; | |
uint96 srcRepNew = sub96(srcRepOld, amount, 'ERC721Checkpointable::_moveDelegates: amount underflows'); | |
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); | |
} | |
if (dstRep != address(0)) { | |
uint32 dstRepNum = numCheckpoints[dstRep]; | |
uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; | |
uint96 dstRepNew = add96(dstRepOld, amount, 'ERC721Checkpointable::_moveDelegates: amount overflows'); | |
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); | |
} | |
} | |
} | |
function _writeCheckpoint( | |
address delegatee, | |
uint32 nCheckpoints, | |
uint96 oldVotes, | |
uint96 newVotes | |
) internal { | |
uint32 blockNumber = safe32( | |
block.number, | |
'ERC721Checkpointable::_writeCheckpoint: block number exceeds 32 bits' | |
); | |
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { | |
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; | |
} else { | |
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); | |
numCheckpoints[delegatee] = nCheckpoints + 1; | |
} | |
emit DelegateVotesChanged(delegatee, oldVotes, newVotes); | |
} | |
function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { | |
require(n < 2**32, errorMessage); | |
return uint32(n); | |
} | |
function safe96(uint256 n, string memory errorMessage) internal pure returns (uint96) { | |
require(n < 2**96, errorMessage); | |
return uint96(n); | |
} | |
function add96( | |
uint96 a, | |
uint96 b, | |
string memory errorMessage | |
) internal pure returns (uint96) { | |
uint96 c = a + b; | |
require(c >= a, errorMessage); | |
return c; | |
} | |
function sub96( | |
uint96 a, | |
uint96 b, | |
string memory errorMessage | |
) internal pure returns (uint96) { | |
require(b <= a, errorMessage); | |
return a - b; | |
} | |
function getChainId() internal view returns (uint256) { | |
uint256 chainId; | |
assembly { | |
chainId := chainid() | |
} | |
return chainId; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
/// @title ERC721 Enumerable Extension | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
// LICENSE | |
// ERC721.sol modifies OpenZeppelin's ERC721Enumerable.sol: | |
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6618f9f18424ade44116d0221719f4c93be6a078/contracts/token/ERC721/extensions/ERC721Enumerable.sol | |
// | |
// ERC721Enumerable.sol source code copyright OpenZeppelin licensed under the MIT License. | |
// With modifications by Nounders DAO. | |
// | |
// MODIFICATIONS: | |
// Consumes modified `ERC721` contract. See notes in `ERC721.sol`. | |
pragma solidity ^0.8.0; | |
import './ERC721.sol'; | |
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol'; | |
/** | |
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds | |
* enumerability of all the token ids in the contract as well as all token ids owned by each | |
* account. | |
*/ | |
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { | |
// Mapping from owner to list of owned token IDs | |
mapping(address => mapping(uint256 => uint256)) private _ownedTokens; | |
// Mapping from token ID to index of the owner tokens list | |
mapping(uint256 => uint256) private _ownedTokensIndex; | |
// Array with all token ids, used for enumeration | |
uint256[] private _allTokens; | |
// Mapping from token id to position in the allTokens array | |
mapping(uint256 => uint256) private _allTokensIndex; | |
/** | |
* @dev See {IERC165-supportsInterface}. | |
*/ | |
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { | |
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); | |
} | |
/** | |
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. | |
*/ | |
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { | |
require(index < ERC721.balanceOf(owner), 'ERC721Enumerable: owner index out of bounds'); | |
return _ownedTokens[owner][index]; | |
} | |
/** | |
* @dev See {IERC721Enumerable-totalSupply}. | |
*/ | |
function totalSupply() public view virtual override returns (uint256) { | |
return _allTokens.length; | |
} | |
/** | |
* @dev See {IERC721Enumerable-tokenByIndex}. | |
*/ | |
function tokenByIndex(uint256 index) public view virtual override returns (uint256) { | |
require(index < ERC721Enumerable.totalSupply(), 'ERC721Enumerable: global index out of bounds'); | |
return _allTokens[index]; | |
} | |
/** | |
* @dev Hook that is called before any token transfer. This includes minting | |
* and burning. | |
* | |
* Calling conditions: | |
* | |
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be | |
* transferred to `to`. | |
* - When `from` is zero, `tokenId` will be minted for `to`. | |
* - When `to` is zero, ``from``'s `tokenId` will be burned. | |
* - `from` cannot be the zero address. | |
* - `to` cannot be the zero address. | |
* | |
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. | |
*/ | |
function _beforeTokenTransfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) internal virtual override { | |
super._beforeTokenTransfer(from, to, tokenId); | |
if (from == address(0)) { | |
_addTokenToAllTokensEnumeration(tokenId); | |
} else if (from != to) { | |
_removeTokenFromOwnerEnumeration(from, tokenId); | |
} | |
if (to == address(0)) { | |
_removeTokenFromAllTokensEnumeration(tokenId); | |
} else if (to != from) { | |
_addTokenToOwnerEnumeration(to, tokenId); | |
} | |
} | |
/** | |
* @dev Private function to add a token to this extension's ownership-tracking data structures. | |
* @param to address representing the new owner of the given token ID | |
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address | |
*/ | |
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { | |
uint256 length = ERC721.balanceOf(to); | |
_ownedTokens[to][length] = tokenId; | |
_ownedTokensIndex[tokenId] = length; | |
} | |
/** | |
* @dev Private function to add a token to this extension's token tracking data structures. | |
* @param tokenId uint256 ID of the token to be added to the tokens list | |
*/ | |
function _addTokenToAllTokensEnumeration(uint256 tokenId) private { | |
_allTokensIndex[tokenId] = _allTokens.length; | |
_allTokens.push(tokenId); | |
} | |
/** | |
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that | |
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for | |
* gas optimizations e.g. when performing a transfer operation (avoiding double writes). | |
* This has O(1) time complexity, but alters the order of the _ownedTokens array. | |
* @param from address representing the previous owner of the given token ID | |
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address | |
*/ | |
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { | |
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and | |
// then delete the last slot (swap and pop). | |
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; | |
uint256 tokenIndex = _ownedTokensIndex[tokenId]; | |
// When the token to delete is the last token, the swap operation is unnecessary | |
if (tokenIndex != lastTokenIndex) { | |
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; | |
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token | |
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index | |
} | |
// This also deletes the contents at the last position of the array | |
delete _ownedTokensIndex[tokenId]; | |
delete _ownedTokens[from][lastTokenIndex]; | |
} | |
/** | |
* @dev Private function to remove a token from this extension's token tracking data structures. | |
* This has O(1) time complexity, but alters the order of the _allTokens array. | |
* @param tokenId uint256 ID of the token to be removed from the tokens list | |
*/ | |
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { | |
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and | |
// then delete the last slot (swap and pop). | |
uint256 lastTokenIndex = _allTokens.length - 1; | |
uint256 tokenIndex = _allTokensIndex[tokenId]; | |
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so | |
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding | |
// an 'if' statement (like in _removeTokenFromOwnerEnumeration) | |
uint256 lastTokenId = _allTokens[lastTokenIndex]; | |
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token | |
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index | |
// This also deletes the contents at the last position of the array | |
delete _allTokensIndex[tokenId]; | |
_allTokens.pop(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
/// @title Interface for NounsDescriptor | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
pragma solidity ^0.8.6; | |
import { INounsSeeder } from './INounsSeeder.sol'; | |
interface INounsDescriptor { | |
event PartsLocked(); | |
event DataURIToggled(bool enabled); | |
event BaseURIUpdated(string baseURI); | |
function arePartsLocked() external returns (bool); | |
function isDataURIEnabled() external returns (bool); | |
function baseURI() external returns (string memory); | |
function palettes(uint8 paletteIndex, uint256 colorIndex) external view returns (string memory); | |
function backgrounds(uint256 index) external view returns (string memory); | |
function bodies(uint256 index) external view returns (bytes memory); | |
function accessories(uint256 index) external view returns (bytes memory); | |
function heads(uint256 index) external view returns (bytes memory); | |
function glasses(uint256 index) external view returns (bytes memory); | |
function backgroundCount() external view returns (uint256); | |
function bodyCount() external view returns (uint256); | |
function accessoryCount() external view returns (uint256); | |
function headCount() external view returns (uint256); | |
function glassesCount() external view returns (uint256); | |
function addManyColorsToPalette(uint8 paletteIndex, string[] calldata newColors) external; | |
function addManyBackgrounds(string[] calldata backgrounds) external; | |
function addManyBodies(bytes[] calldata bodies) external; | |
function addManyAccessories(bytes[] calldata accessories) external; | |
function addManyHeads(bytes[] calldata heads) external; | |
function addManyGlasses(bytes[] calldata glasses) external; | |
function addColorToPalette(uint8 paletteIndex, string calldata color) external; | |
function addBackground(string calldata background) external; | |
function addBody(bytes calldata body) external; | |
function addAccessory(bytes calldata accessory) external; | |
function addHead(bytes calldata head) external; | |
function addGlasses(bytes calldata glasses) external; | |
function lockParts() external; | |
function toggleDataURIEnabled() external; | |
function setBaseURI(string calldata baseURI) external; | |
function tokenURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory); | |
function dataURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory); | |
function genericDataURI( | |
string calldata name, | |
string calldata description, | |
INounsSeeder.Seed memory seed | |
) external view returns (string memory); | |
function generateSVGImage(INounsSeeder.Seed memory seed) external view returns (string memory); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
/// @title Interface for NounsSeeder | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
pragma solidity ^0.8.6; | |
import { INounsDescriptor } from './INounsDescriptor.sol'; | |
interface INounsSeeder { | |
struct Seed { | |
uint48 background; | |
uint48 body; | |
uint48 accessory; | |
uint48 head; | |
uint48 glasses; | |
} | |
function generateSeed(uint256 nounId, INounsDescriptor descriptor) external view returns (Seed memory); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
/// @title Interface for NounsToken | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
pragma solidity ^0.8.6; | |
import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; | |
import { INounsDescriptor } from './INounsDescriptor.sol'; | |
import { INounsSeeder } from './INounsSeeder.sol'; | |
interface INounsToken is IERC721 { | |
event NounCreated(uint256 indexed tokenId, INounsSeeder.Seed seed); | |
event NounBurned(uint256 indexed tokenId); | |
event NoundersDAOUpdated(address noundersDAO); | |
event MinterUpdated(address minter); | |
event MinterLocked(); | |
event DescriptorUpdated(INounsDescriptor descriptor); | |
event DescriptorLocked(); | |
event SeederUpdated(INounsSeeder seeder); | |
event SeederLocked(); | |
function mint() external returns (uint256); | |
function burn(uint256 tokenId) external; | |
function dataURI(uint256 tokenId) external returns (string memory); | |
function setNoundersDAO(address noundersDAO) external; | |
function setMinter(address minter) external; | |
function lockMinter() external; | |
function setDescriptor(INounsDescriptor descriptor) external; | |
function lockDescriptor() external; | |
function setSeeder(INounsSeeder seeder) external; | |
function lockSeeder() external; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.6; | |
interface IProxyRegistry { | |
function proxies(address) external view returns (address); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
/// @title The Nouns ERC-721 token | |
/********************************* | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░██░░░████░░██░░░████░░░ * | |
* ░░██████░░░████████░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░██░░██░░░████░░██░░░████░░░ * | |
* ░░░░░░█████████░░█████████░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * | |
*********************************/ | |
pragma solidity ^0.8.6; | |
import { Ownable } from '@openzeppelin/contracts/access/Ownable.sol'; | |
import { ERC721Checkpointable } from './ERC721Checkpointable.sol'; | |
import { INounsDescriptor } from './INounsDescriptor.sol'; | |
import { INounsSeeder } from './INounsSeeder.sol'; | |
import { INounsToken } from './INounsToken.sol'; | |
import { ERC721 } from './ERC721.sol'; | |
import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; | |
import { IProxyRegistry } from './IProxyRegistry.sol'; | |
contract NounsToken is INounsToken, Ownable, ERC721Checkpointable { | |
// The nounders DAO address (creators org) | |
address public noundersDAO; | |
// An address who has permissions to mint Nouns | |
address public minter; | |
// The Nouns token URI descriptor | |
INounsDescriptor public descriptor; | |
// The Nouns token seeder | |
INounsSeeder public seeder; | |
// Whether the minter can be updated | |
bool public isMinterLocked; | |
// Whether the descriptor can be updated | |
bool public isDescriptorLocked; | |
// Whether the seeder can be updated | |
bool public isSeederLocked; | |
// The noun seeds | |
mapping(uint256 => INounsSeeder.Seed) public seeds; | |
// The internal noun ID tracker | |
uint256 private _currentNounId; | |
// IPFS content hash of contract-level metadata | |
string private _contractURIHash = 'QmZi1n79FqWt2tTLwCqiy6nLM6xLGRsEPQ5JmReJQKNNzX'; | |
// OpenSea's Proxy Registry | |
IProxyRegistry public immutable proxyRegistry; | |
/** | |
* @notice Require that the minter has not been locked. | |
*/ | |
modifier whenMinterNotLocked() { | |
require(!isMinterLocked, 'Minter is locked'); | |
_; | |
} | |
/** | |
* @notice Require that the descriptor has not been locked. | |
*/ | |
modifier whenDescriptorNotLocked() { | |
require(!isDescriptorLocked, 'Descriptor is locked'); | |
_; | |
} | |
/** | |
* @notice Require that the seeder has not been locked. | |
*/ | |
modifier whenSeederNotLocked() { | |
require(!isSeederLocked, 'Seeder is locked'); | |
_; | |
} | |
/** | |
* @notice Require that the sender is the nounders DAO. | |
*/ | |
modifier onlyNoundersDAO() { | |
require(msg.sender == noundersDAO, 'Sender is not the nounders DAO'); | |
_; | |
} | |
/** | |
* @notice Require that the sender is the minter. | |
*/ | |
modifier onlyMinter() { | |
require(msg.sender == minter, 'Sender is not the minter'); | |
_; | |
} | |
constructor( | |
address _noundersDAO, | |
address _minter, | |
INounsDescriptor _descriptor, | |
INounsSeeder _seeder, | |
IProxyRegistry _proxyRegistry | |
) ERC721('Nouns', 'NOUN') { | |
noundersDAO = _noundersDAO; | |
minter = _minter; | |
descriptor = _descriptor; | |
seeder = _seeder; | |
proxyRegistry = _proxyRegistry; | |
} | |
/** | |
* @notice The IPFS URI of contract-level metadata. | |
*/ | |
function contractURI() public view returns (string memory) { | |
return string(abi.encodePacked('ipfs://', _contractURIHash)); | |
} | |
/** | |
* @notice Set the _contractURIHash. | |
* @dev Only callable by the owner. | |
*/ | |
function setContractURIHash(string memory newContractURIHash) external onlyOwner { | |
_contractURIHash = newContractURIHash; | |
} | |
/** | |
* @notice Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. | |
*/ | |
function isApprovedForAll(address owner, address operator) public view override(IERC721, ERC721) returns (bool) { | |
// Whitelist OpenSea proxy contract for easy trading. | |
if (proxyRegistry.proxies(owner) == operator) { | |
return true; | |
} | |
return super.isApprovedForAll(owner, operator); | |
} | |
/** | |
* @notice Mint a Noun to the minter, along with a possible nounders reward | |
* Noun. Nounders reward Nouns are minted every 10 Nouns, starting at 0, | |
* until 183 nounder Nouns have been minted (5 years w/ 24 hour auctions). | |
* @dev Call _mintTo with the to address(es). | |
*/ | |
function mint() public override onlyMinter returns (uint256) { | |
if (_currentNounId <= 1820 && _currentNounId % 10 == 0) { | |
_mintTo(noundersDAO, _currentNounId++); | |
} | |
return _mintTo(minter, _currentNounId++); | |
} | |
/** | |
* @notice Burn a noun. | |
*/ | |
function burn(uint256 nounId) public override onlyMinter { | |
_burn(nounId); | |
emit NounBurned(nounId); | |
} | |
/** | |
* @notice A distinct Uniform Resource Identifier (URI) for a given asset. | |
* @dev See {IERC721Metadata-tokenURI}. | |
*/ | |
function tokenURI(uint256 tokenId) public view override returns (string memory) { | |
require(_exists(tokenId), 'NounsToken: URI query for nonexistent token'); | |
return descriptor.tokenURI(tokenId, seeds[tokenId]); | |
} | |
/** | |
* @notice Similar to `tokenURI`, but always serves a base64 encoded data URI | |
* with the JSON contents directly inlined. | |
*/ | |
function dataURI(uint256 tokenId) public view override returns (string memory) { | |
require(_exists(tokenId), 'NounsToken: URI query for nonexistent token'); | |
return descriptor.dataURI(tokenId, seeds[tokenId]); | |
} | |
/** | |
* @notice Set the nounders DAO. | |
* @dev Only callable by the nounders DAO when not locked. | |
*/ | |
function setNoundersDAO(address _noundersDAO) external override onlyNoundersDAO { | |
noundersDAO = _noundersDAO; | |
emit NoundersDAOUpdated(_noundersDAO); | |
} | |
/** | |
* @notice Set the token minter. | |
* @dev Only callable by the owner when not locked. | |
*/ | |
function setMinter(address _minter) external override onlyOwner whenMinterNotLocked { | |
minter = _minter; | |
emit MinterUpdated(_minter); | |
} | |
/** | |
* @notice Lock the minter. | |
* @dev This cannot be reversed and is only callable by the owner when not locked. | |
*/ | |
function lockMinter() external override onlyOwner whenMinterNotLocked { | |
isMinterLocked = true; | |
emit MinterLocked(); | |
} | |
/** | |
* @notice Set the token URI descriptor. | |
* @dev Only callable by the owner when not locked. | |
*/ | |
function setDescriptor(INounsDescriptor _descriptor) external override onlyOwner whenDescriptorNotLocked { | |
descriptor = _descriptor; | |
emit DescriptorUpdated(_descriptor); | |
} | |
/** | |
* @notice Lock the descriptor. | |
* @dev This cannot be reversed and is only callable by the owner when not locked. | |
*/ | |
function lockDescriptor() external override onlyOwner whenDescriptorNotLocked { | |
isDescriptorLocked = true; | |
emit DescriptorLocked(); | |
} | |
/** | |
* @notice Set the token seeder. | |
* @dev Only callable by the owner when not locked. | |
*/ | |
function setSeeder(INounsSeeder _seeder) external override onlyOwner whenSeederNotLocked { | |
seeder = _seeder; | |
emit SeederUpdated(_seeder); | |
} | |
/** | |
* @notice Lock the seeder. | |
* @dev This cannot be reversed and is only callable by the owner when not locked. | |
*/ | |
function lockSeeder() external override onlyOwner whenSeederNotLocked { | |
isSeederLocked = true; | |
emit SeederLocked(); | |
} | |
/** | |
* @notice Mint a Noun with `nounId` to the provided `to` address. | |
*/ | |
function _mintTo(address to, uint256 nounId) internal returns (uint256) { | |
INounsSeeder.Seed memory seed = seeds[nounId] = seeder.generateSeed(nounId, descriptor); | |
_mint(owner(), to, nounId); | |
emit NounCreated(nounId, seed); | |
return nounId; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this line is added to create a gist. Empty file is not allowed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Right click on the script name and hit "Run" to execute | |
(async () => { | |
try { | |
console.log('Running deployWithEthers script...') | |
const contractName = 'Storage' // Change this for other contract | |
const constructorArgs = [] // Put constructor args (if any) here for your contract | |
// Note that the script needs the ABI which is generated from the compilation artifact. | |
// Make sure contract is compiled and artifacts are generated | |
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path | |
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) | |
// 'web3Provider' is a remix global variable object | |
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() | |
let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); | |
let contract = await factory.deploy(...constructorArgs); | |
console.log('Contract Address: ', contract.address); | |
// The contract is NOT deployed yet; we must wait until it is mined | |
await contract.deployed() | |
console.log('Deployment successful.') | |
} catch (e) { | |
console.log(e.message) | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Right click on the script name and hit "Run" to execute | |
(async () => { | |
try { | |
console.log('Running deployWithWeb3 script...') | |
const contractName = 'Storage' // Change this for other contract | |
const constructorArgs = [] // Put constructor args (if any) here for your contract | |
// Note that the script needs the ABI which is generated from the compilation artifact. | |
// Make sure contract is compiled and artifacts are generated | |
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path | |
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) | |
const accounts = await web3.eth.getAccounts() | |
let contract = new web3.eth.Contract(metadata.abi) | |
contract = contract.deploy({ | |
data: metadata.data.bytecode.object, | |
arguments: constructorArgs | |
}) | |
const newContractInstance = await contract.send({ | |
from: accounts[0], | |
gas: 1500000, | |
gasPrice: '30000000000' | |
}) | |
console.log('Contract deployed at address: ', newContractInstance.options.address) | |
} catch (e) { | |
console.log(e.message) | |
} | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "../contracts/3_Ballot.sol"; | |
contract BallotTest { | |
bytes32[] proposalNames; | |
Ballot ballotToTest; | |
function beforeAll () public { | |
proposalNames.push(bytes32("candidate1")); | |
ballotToTest = new Ballot(proposalNames); | |
} | |
function checkWinningProposal () public { | |
ballotToTest.vote(0); | |
Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal"); | |
Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name"); | |
} | |
function checkWinninProposalWithReturnValue () public view returns (bool) { | |
return ballotToTest.winningProposal() == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment