Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- BRC404
- Optimization enabled
- true
- Compiler version
- v0.8.19+commit.7dd6d404
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-02-26T10:35:23.377378Z
Constructor Arguments
0x00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000088e16a09fa0554000000000000000000000000000000000000000000000014e2e53e25b67021400000000000000000000000000000047ee841ae2bd1b1d2d3f5bef15aa0bd7af30b8ee000000000000000000000000000000000000000000000000000000000000000e50414745204e4f5420464f554e4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033430340000000000000000000000000000000000000000000000000000000000
Arg [0] (string) : PAGE NOT FOUND
Arg [1] (string) : 404
Arg [2] (uint256) : 40400000000000000000000
Arg [3] (uint96) : 404000000000000000000000000
Arg [4] (address) : <a href=/address/0x47ee841ae2bd1b1d2d3f5bef15aa0bd7af30b8ee>0x47ee841ae2bd1b1d2d3f5bef15aa0bd7af30b8ee</a>
contracts/brc404/BRC404.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "./DN404.sol"; import "./DN404Mirror.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {SafeTransferLib} from "./utils/SafeTransferLib.sol"; /** * @title BRC404 * @notice BRC404 contract that demonstrates the owner selling fungible tokens. * When a user has at least one base unit (10^18) amount of tokens, they will automatically receive an NFT. * NFTs are minted as an address accumulates each base unit amount of tokens. */ contract BRC404 is DN404, Ownable { string private _name; string private _symbol; string private _baseURI; uint256 private _unitX18; constructor( string memory name_, string memory symbol_, uint256 unitX18, uint96 initialTokenSupplyX18, address initialSupplyOwner ) Ownable() { require(initialTokenSupplyX18 % unitX18 == 0, "invalid params"); _name = name_; _symbol = symbol_; _unitX18 = unitX18; address mirror = address(new DN404Mirror(msg.sender)); _initializeDN404(initialTokenSupplyX18, initialSupplyOwner, mirror); } function name() public view override returns (string memory) { return _name; } function symbol() public view override returns (string memory) { return _symbol; } function _unit() internal view virtual override returns (uint256) { return _unitX18; } function tokenURI( uint256 tokenId ) public view override returns (string memory result) { if (bytes(_baseURI).length != 0) { result = string( abi.encodePacked(_baseURI, Strings.toString(tokenId)) ); } } function setBaseURI(string calldata baseURI_) public onlyOwner { _baseURI = baseURI_; } function withdraw() public onlyOwner { SafeTransferLib.safeTransferAllETH(msg.sender); } }
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // ā `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // ā `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
@openzeppelin/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
contracts/brc404/DN404.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @title DN404 /// @notice DN404 is a hybrid ERC20 and ERC721 implementation that mints /// and burns NFTs based on an account's ERC20 token balance. /// /// @dev Note: /// - The ERC721 data is stored in this base DN404 contract, however a /// DN404Mirror contract ***MUST*** be deployed and linked during /// initialization. abstract contract DN404 { /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* EVENTS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Emitted when `amount` tokens is transferred from `from` to `to`. event Transfer(address indexed from, address indexed to, uint256 amount); /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`. event Approval( address indexed owner, address indexed spender, uint256 amount ); /// @dev Emitted when `target` sets their skipNFT flag to `status`. event SkipNFTSet(address indexed target, bool status); /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`. uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`. uint256 private constant _APPROVAL_EVENT_SIGNATURE = 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925; /// @dev `keccak256(bytes("SkipNFTSet(address,bool)"))`. uint256 private constant _SKIP_NFT_SET_EVENT_SIGNATURE = 0xb5a1de456fff688115a4f75380060c23c8532d14ff85f687cc871456d6420393; /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* CUSTOM ERRORS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Thrown when attempting to double-initialize the contract. error DNAlreadyInitialized(); /// @dev Thrown when attempting to transfer or burn more tokens than sender's balance. error InsufficientBalance(); /// @dev Thrown when a spender attempts to transfer tokens with an insufficient allowance. error InsufficientAllowance(); /// @dev Thrown when minting an amount of tokens that would overflow the max tokens. error TotalSupplyOverflow(); /// @dev The unit cannot be zero. error UnitIsZero(); /// @dev Thrown when the caller for a fallback NFT function is not the mirror contract. error SenderNotMirror(); /// @dev Thrown when attempting to transfer tokens to the zero address. error TransferToZeroAddress(); /// @dev Thrown when the mirror address provided for initialization is the zero address. error MirrorAddressIsZero(); /// @dev Thrown when the link call to the mirror contract reverts. error LinkMirrorContractFailed(); /// @dev Thrown when setting an NFT token approval /// and the caller is not the owner or an approved operator. error ApprovalCallerNotOwnerNorApproved(); /// @dev Thrown when transferring an NFT /// and the caller is not the owner or an approved operator. error TransferCallerNotOwnerNorApproved(); /// @dev Thrown when transferring an NFT and the from address is not the current owner. error TransferFromIncorrectOwner(); /// @dev Thrown when checking the owner or approved address for a non-existent NFT. error TokenDoesNotExist(); /// @dev The function selector is not recognized. error FnSelectorNotRecognized(); /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* CONSTANTS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev The flag to denote that the address data is initialized. uint8 internal constant _ADDRESS_DATA_INITIALIZED_FLAG = 1 << 0; /// @dev The flag to denote that the address should skip NFTs. uint8 internal constant _ADDRESS_DATA_SKIP_NFT_FLAG = 1 << 1; /// @dev The flag to denote that the address has overridden the default Permit2 allowance. uint8 internal constant _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG = 1 << 2; /// @dev The canonical Permit2 address. /// For signature-based allowance granting for single transaction ERC20 `transferFrom`. /// To enable, override `_givePermit2DefaultInfiniteAllowance()`. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* STORAGE */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Struct containing an address's token data and settings. struct AddressData { // Auxiliary data. uint88 aux; // Flags for `initialized` and `skipNFT`. uint8 flags; // The alias for the address. Zero means absence of an alias. uint32 addressAlias; // The number of NFT tokens. uint32 ownedLength; // The token balance in wei. uint96 balance; } /// @dev A uint32 map in storage. struct Uint32Map { uint256 spacer; } /// @dev A bitmap in storage. struct Bitmap { uint256 spacer; } /// @dev A struct to wrap a uint256 in storage. struct Uint256Ref { uint256 value; } /// @dev A mapping of an address pair to a Uint256Ref. struct AddressPairToUint256RefMap { uint256 spacer; } /// @dev Struct containing the base token contract storage. struct DN404Storage { // Current number of address aliases assigned. uint32 numAliases; // Next NFT ID to assign for a mint. uint32 nextTokenId; // The head of the burned pool. uint32 burnedPoolHead; // The tail of the burned pool. uint32 burnedPoolTail; // Total number of NFTs in existence. uint32 totalNFTSupply; // Total supply of tokens. uint96 totalSupply; // Address of the NFT mirror contract. address mirrorERC721; // Mapping of a user alias number to their address. mapping(uint32 => address) aliasToAddress; // Mapping of user operator approvals for NFTs. AddressPairToUint256RefMap operatorApprovals; // Mapping of NFT approvals to approved operators. mapping(uint256 => address) nftApprovals; // Bitmap of whether an non-zero NFT approval may exist. Bitmap mayHaveNFTApproval; // Bitmap of whether a NFT ID exists. Ignored if `_useExistsLookup()` returns false. Bitmap exists; // Mapping of user allowances for ERC20 spenders. AddressPairToUint256RefMap allowance; // Mapping of NFT IDs owned by an address. mapping(address => Uint32Map) owned; // The pool of burned NFT IDs. Uint32Map burnedPool; // Even indices: owner aliases. Odd indices: owned indices. Uint32Map oo; // Mapping of user account AddressData. mapping(address => AddressData) addressData; } /// @dev Returns a storage pointer for DN404Storage. function _getDN404Storage() internal pure virtual returns (DN404Storage storage $) { /// @solidity memory-safe-assembly assembly { // `uint72(bytes9(keccak256("DN404_STORAGE")))`. $.slot := 0xa20d6e21d0e5255308 // Truncate to 9 bytes to reduce bytecode size. } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INITIALIZER */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Initializes the DN404 contract with an /// `initialTokenSupply`, `initialTokenOwner` and `mirror` NFT contract address. function _initializeDN404( uint256 initialTokenSupply, address initialSupplyOwner, address mirror ) internal virtual { DN404Storage storage $ = _getDN404Storage(); if (_unit() == 0) revert UnitIsZero(); if ($.mirrorERC721 != address(0)) revert DNAlreadyInitialized(); if (mirror == address(0)) revert MirrorAddressIsZero(); /// @solidity memory-safe-assembly assembly { // Make the call to link the mirror contract. mstore(0x00, 0x0f4599e5) // `linkMirrorContract(address)`. mstore(0x20, caller()) if iszero( and( eq(mload(0x00), 1), call(gas(), mirror, 0, 0x1c, 0x24, 0x00, 0x20) ) ) { mstore(0x00, 0xd125259c) // `LinkMirrorContractFailed()`. revert(0x1c, 0x04) } } $.nextTokenId = 1; $.mirrorERC721 = mirror; if (initialTokenSupply != 0) { if (initialSupplyOwner == address(0)) revert TransferToZeroAddress(); if (_totalSupplyOverflows(initialTokenSupply)) revert TotalSupplyOverflow(); $.totalSupply = uint96(initialTokenSupply); AddressData storage initialOwnerAddressData = _addressData( initialSupplyOwner ); initialOwnerAddressData.balance = uint96(initialTokenSupply); /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, initialTokenSupply) log3( 0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, shl(96, initialSupplyOwner)) ) } _setSkipNFT(initialSupplyOwner, true); } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* BASE UNIT FUNCTION TO OVERRIDE */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Amount of token balance that is equal to one NFT. function _unit() internal view virtual returns (uint256) { return 10 ** 18; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* METADATA FUNCTIONS TO OVERRIDE */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the name of the token. function name() public view virtual returns (string memory); /// @dev Returns the symbol of the token. function symbol() public view virtual returns (string memory); /// @dev Returns the Uniform Resource Identifier (URI) for token `id`. function tokenURI(uint256 id) public view virtual returns (string memory); /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* CONFIGURABLES */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns if direct NFT transfers should be used during ERC20 transfers /// whenever possible, instead of burning and re-minting. function _useDirectTransfersIfPossible() internal view virtual returns (bool) { return true; } /// @dev Returns if burns should be added to the burn pool. /// This returns false by default, which means the NFT IDs are re-minted in a cycle. function _addToBurnedPool( uint256 totalNFTSupplyAfterBurn, uint256 totalSupplyAfterBurn ) internal view virtual returns (bool) { // Silence unused variable compiler warning. totalSupplyAfterBurn = totalNFTSupplyAfterBurn; return false; } /// @dev Returns whether to use the exists bitmap for more efficient /// scanning of an empty token ID slot. /// Recommended for collections that do not use the burn pool, /// and are expected to have nearly all possible NFTs materialized. /// /// Note: The returned value must be constant after initialization. function _useExistsLookup() internal view virtual returns (bool) { return true; } /// @dev Hook that is called after any NFT token transfers, including minting and burning. function _afterNFTTransfer( address from, address to, uint256 id ) internal virtual {} /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* ERC20 OPERATIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the decimals places of the token. Always 18. function decimals() public pure returns (uint8) { return 18; } /// @dev Returns the amount of tokens in existence. function totalSupply() public view virtual returns (uint256) { return uint256(_getDN404Storage().totalSupply); } /// @dev Returns the amount of tokens owned by `owner`. function balanceOf(address owner) public view virtual returns (uint256) { return _getDN404Storage().addressData[owner].balance; } /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`. function allowance( address owner, address spender ) public view returns (uint256) { if (_givePermit2DefaultInfiniteAllowance() && spender == _PERMIT2) { uint8 flags = _getDN404Storage().addressData[owner].flags; if (flags & _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG == 0) return type(uint256).max; } return _ref(_getDN404Storage().allowance, owner, spender).value; } /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens. /// /// Emits a {Approval} event. function approve( address spender, uint256 amount ) public virtual returns (bool) { _approve(msg.sender, spender, amount); return true; } /// @dev Transfer `amount` tokens from the caller to `to`. /// /// Will burn sender NFTs if balance after transfer is less than /// the amount required to support the current NFT balance. /// /// Will mint NFTs to `to` if the recipient's new balance supports /// additional NFTs ***AND*** the `to` address's skipNFT flag is /// set to false. /// /// Requirements: /// - `from` must at least have `amount`. /// /// Emits a {Transfer} event. function transfer( address to, uint256 amount ) public virtual returns (bool) { _transfer(msg.sender, to, amount); return true; } /// @dev Transfers `amount` tokens from `from` to `to`. /// /// Note: Does not update the allowance if it is the maximum uint256 value. /// /// Will burn sender NFTs if balance after transfer is less than /// the amount required to support the current NFT balance. /// /// Will mint NFTs to `to` if the recipient's new balance supports /// additional NFTs ***AND*** the `to` address's skipNFT flag is /// set to false. /// /// Requirements: /// - `from` must at least have `amount`. /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`. /// /// Emits a {Transfer} event. function transferFrom( address from, address to, uint256 amount ) public virtual returns (bool) { Uint256Ref storage a = _ref( _getDN404Storage().allowance, from, msg.sender ); uint256 allowed = _givePermit2DefaultInfiniteAllowance() && msg.sender == _PERMIT2 && (_getDN404Storage().addressData[from].flags & _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG) == 0 ? type(uint256).max : a.value; if (allowed != type(uint256).max) { if (amount > allowed) revert InsufficientAllowance(); unchecked { a.value = allowed - amount; } } _transfer(from, to, amount); return true; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* PERMIT2 */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Whether Permit2 has infinite allowances by default for all owners. /// For signature-based allowance granting for single transaction ERC20 `transferFrom`. /// To enable, override this function to return true. function _givePermit2DefaultInfiniteAllowance() internal view virtual returns (bool) { return false; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INTERNAL MINT FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Mints `amount` tokens to `to`, increasing the total supply. /// /// Will mint NFTs to `to` if the recipient's new balance supports /// additional NFTs ***AND*** the `to` address's skipNFT flag is set to false. /// /// Emits a {Transfer} event. function _mint(address to, uint256 amount) internal virtual { if (to == address(0)) revert TransferToZeroAddress(); AddressData storage toAddressData = _addressData(to); DN404Storage storage $ = _getDN404Storage(); if ($.mirrorERC721 == address(0)) revert(); _DNMintTemps memory t; unchecked { uint256 toBalance = uint256(toAddressData.balance) + amount; toAddressData.balance = uint96(toBalance); t.toEnd = toBalance / _unit(); } uint256 maxId; unchecked { uint256 totalSupply_ = uint256($.totalSupply) + amount; $.totalSupply = uint96(totalSupply_); uint256 overflows = _toUint(_totalSupplyOverflows(totalSupply_)); if (overflows | _toUint(totalSupply_ < amount) != 0) revert TotalSupplyOverflow(); maxId = totalSupply_ / _unit(); } unchecked { if (toAddressData.flags & _ADDRESS_DATA_SKIP_NFT_FLAG == 0) { Uint32Map storage toOwned = $.owned[to]; Uint32Map storage oo = $.oo; uint256 toIndex = toAddressData.ownedLength; _DNPackedLogs memory packedLogs = _packedLogsMalloc( _zeroFloorSub(t.toEnd, toIndex) ); if (packedLogs.logs.length != 0) { _packedLogsSet(packedLogs, to, 0); $.totalNFTSupply += uint32(packedLogs.logs.length); toAddressData.ownedLength = uint32(t.toEnd); t.toAlias = _registerAndResolveAlias(toAddressData, to); uint32 burnedPoolHead = $.burnedPoolHead; t.burnedPoolTail = $.burnedPoolTail; t.nextTokenId = _wrapNFTId($.nextTokenId, maxId); // Mint loop. do { uint256 id; if (burnedPoolHead != t.burnedPoolTail) { id = _get($.burnedPool, burnedPoolHead++); } else { id = t.nextTokenId; while (_get(oo, _ownershipIndex(id)) != 0) { id = _useExistsLookup() ? _wrapNFTId( _findFirstUnset( $.exists, id + 1, maxId + 1 ), maxId ) : _wrapNFTId(id + 1, maxId); } t.nextTokenId = _wrapNFTId(id + 1, maxId); } if (_useExistsLookup()) _set($.exists, id, true); _set(toOwned, toIndex, uint32(id)); _setOwnerAliasAndOwnedIndex( oo, id, t.toAlias, uint32(toIndex++) ); _packedLogsAppend(packedLogs, id); _afterNFTTransfer(address(0), to, id); } while (toIndex != t.toEnd); $.nextTokenId = uint32(t.nextTokenId); $.burnedPoolHead = burnedPoolHead; _packedLogsSend(packedLogs, $.mirrorERC721); } } } /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, amount) log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, shl(96, to))) } } /// @dev Mints `amount` tokens to `to`, increasing the total supply. /// This variant mints NFT tokens starting from ID `preTotalSupply / _unit() + 1`. /// This variant will not touch the `burnedPool` and `nextTokenId`. /// /// Will mint NFTs to `to` if the recipient's new balance supports /// additional NFTs ***AND*** the `to` address's skipNFT flag is set to false. /// /// Emits a {Transfer} event. function _mintNext(address to, uint256 amount) internal virtual { if (to == address(0)) revert TransferToZeroAddress(); AddressData storage toAddressData = _addressData(to); DN404Storage storage $ = _getDN404Storage(); if ($.mirrorERC721 == address(0)) revert(); _DNMintTemps memory t; unchecked { uint256 toBalance = uint256(toAddressData.balance) + amount; toAddressData.balance = uint96(toBalance); t.toEnd = toBalance / _unit(); } uint256 startId; uint256 maxId; unchecked { uint256 preTotalSupply = uint256($.totalSupply); startId = preTotalSupply / _unit() + 1; uint256 totalSupply_ = uint256(preTotalSupply) + amount; $.totalSupply = uint96(totalSupply_); uint256 overflows = _toUint(_totalSupplyOverflows(totalSupply_)); if (overflows | _toUint(totalSupply_ < amount) != 0) revert TotalSupplyOverflow(); maxId = totalSupply_ / _unit(); } unchecked { if (toAddressData.flags & _ADDRESS_DATA_SKIP_NFT_FLAG == 0) { Uint32Map storage toOwned = $.owned[to]; Uint32Map storage oo = $.oo; uint256 toIndex = toAddressData.ownedLength; _DNPackedLogs memory packedLogs = _packedLogsMalloc( _zeroFloorSub(t.toEnd, toIndex) ); if (packedLogs.logs.length != 0) { _packedLogsSet(packedLogs, to, 0); $.totalNFTSupply += uint32(packedLogs.logs.length); toAddressData.ownedLength = uint32(t.toEnd); t.toAlias = _registerAndResolveAlias(toAddressData, to); // Mint loop. do { uint256 id = startId; while (_get(oo, _ownershipIndex(id)) != 0) { id = _useExistsLookup() ? _wrapNFTId( _findFirstUnset( $.exists, id + 1, maxId + 1 ), maxId ) : _wrapNFTId(id + 1, maxId); } startId = _wrapNFTId(id + 1, maxId); if (_useExistsLookup()) _set($.exists, id, true); _set(toOwned, toIndex, uint32(id)); _setOwnerAliasAndOwnedIndex( oo, id, t.toAlias, uint32(toIndex++) ); _packedLogsAppend(packedLogs, id); _afterNFTTransfer(address(0), to, id); } while (toIndex != t.toEnd); _packedLogsSend(packedLogs, $.mirrorERC721); } } } /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, amount) log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, shl(96, to))) } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INTERNAL BURN FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Burns `amount` tokens from `from`, reducing the total supply. /// /// Will burn sender NFTs if balance after transfer is less than /// the amount required to support the current NFT balance. /// /// Emits a {Transfer} event. function _burn(address from, uint256 amount) internal virtual { AddressData storage fromAddressData = _addressData(from); DN404Storage storage $ = _getDN404Storage(); if ($.mirrorERC721 == address(0)) revert(); uint256 fromBalance = fromAddressData.balance; if (amount > fromBalance) revert InsufficientBalance(); unchecked { fromAddressData.balance = uint96(fromBalance -= amount); uint256 totalSupply_ = uint256($.totalSupply) - amount; $.totalSupply = uint96(totalSupply_); Uint32Map storage fromOwned = $.owned[from]; uint256 fromIndex = fromAddressData.ownedLength; uint256 numNFTBurns = _zeroFloorSub( fromIndex, fromBalance / _unit() ); if (numNFTBurns != 0) { _DNPackedLogs memory packedLogs = _packedLogsMalloc( numNFTBurns ); _packedLogsSet(packedLogs, from, 1); bool addToBurnedPool; { uint256 totalNFTSupply = uint256($.totalNFTSupply) - numNFTBurns; $.totalNFTSupply = uint32(totalNFTSupply); addToBurnedPool = _addToBurnedPool( totalNFTSupply, totalSupply_ ); } Uint32Map storage oo = $.oo; uint256 fromEnd = fromIndex - numNFTBurns; fromAddressData.ownedLength = uint32(fromEnd); uint32 burnedPoolTail = $.burnedPoolTail; // Burn loop. do { uint256 id = _get(fromOwned, --fromIndex); _setOwnerAliasAndOwnedIndex(oo, id, 0, 0); _packedLogsAppend(packedLogs, id); if (_useExistsLookup()) _set($.exists, id, false); if (addToBurnedPool) _set($.burnedPool, burnedPoolTail++, uint32(id)); if (_get($.mayHaveNFTApproval, id)) { _set($.mayHaveNFTApproval, id, false); delete $.nftApprovals[id]; } _afterNFTTransfer(from, address(0), id); } while (fromIndex != fromEnd); if (addToBurnedPool) $.burnedPoolTail = burnedPoolTail; _packedLogsSend(packedLogs, $.mirrorERC721); } } /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, amount) log3( 0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0 ) } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INTERNAL TRANSFER FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Moves `amount` of tokens from `from` to `to`. /// /// Will burn sender NFTs if balance after transfer is less than /// the amount required to support the current NFT balance. /// /// Will mint NFTs to `to` if the recipient's new balance supports /// additional NFTs ***AND*** the `to` address's skipNFT flag is /// set to false. /// /// Emits a {Transfer} event. function _transfer( address from, address to, uint256 amount ) internal virtual { if (to == address(0)) revert TransferToZeroAddress(); AddressData storage fromAddressData = _addressData(from); AddressData storage toAddressData = _addressData(to); DN404Storage storage $ = _getDN404Storage(); if ($.mirrorERC721 == address(0)) revert(); _DNTransferTemps memory t; t.fromOwnedLength = fromAddressData.ownedLength; t.toOwnedLength = toAddressData.ownedLength; t.totalSupply = $.totalSupply; if (amount > (t.fromBalance = fromAddressData.balance)) revert InsufficientBalance(); unchecked { fromAddressData.balance = uint96(t.fromBalance -= amount); toAddressData.balance = uint96( t.toBalance = uint256(toAddressData.balance) + amount ); t.numNFTBurns = _zeroFloorSub( t.fromOwnedLength, t.fromBalance / _unit() ); if (toAddressData.flags & _ADDRESS_DATA_SKIP_NFT_FLAG == 0) { if (from == to) t.toOwnedLength = t.fromOwnedLength - t.numNFTBurns; t.numNFTMints = _zeroFloorSub( t.toBalance / _unit(), t.toOwnedLength ); } while (_useDirectTransfersIfPossible()) { uint256 n = _min( t.fromOwnedLength, _min(t.numNFTBurns, t.numNFTMints) ); if (n == 0) break; t.numNFTBurns -= n; t.numNFTMints -= n; if (from == to) { t.toOwnedLength += n; break; } _DNDirectLogs memory directLogs = _directLogsMalloc( n, from, to ); Uint32Map storage fromOwned = $.owned[from]; Uint32Map storage toOwned = $.owned[to]; t.toAlias = _registerAndResolveAlias(toAddressData, to); uint256 toIndex = t.toOwnedLength; // Direct transfer loop. do { uint256 id = _get(fromOwned, --t.fromOwnedLength); _set(toOwned, toIndex, uint32(id)); _setOwnerAliasAndOwnedIndex( $.oo, id, t.toAlias, uint32(toIndex++) ); _directLogsAppend(directLogs, id); if (_get($.mayHaveNFTApproval, id)) { _set($.mayHaveNFTApproval, id, false); delete $.nftApprovals[id]; } _afterNFTTransfer(from, to, id); } while (--n != 0); toAddressData.ownedLength = uint32(t.toOwnedLength = toIndex); fromAddressData.ownedLength = uint32(t.fromOwnedLength); _directLogsSend(directLogs, $.mirrorERC721); break; } t.totalNFTSupply = uint256($.totalNFTSupply) + t.numNFTMints - t.numNFTBurns; $.totalNFTSupply = uint32(t.totalNFTSupply); Uint32Map storage oo = $.oo; _DNPackedLogs memory packedLogs = _packedLogsMalloc( t.numNFTBurns + t.numNFTMints ); t.burnedPoolTail = $.burnedPoolTail; if (t.numNFTBurns != 0) { _packedLogsSet(packedLogs, from, 1); bool addToBurnedPool = _addToBurnedPool( t.totalNFTSupply, t.totalSupply ); Uint32Map storage fromOwned = $.owned[from]; uint256 fromIndex = t.fromOwnedLength; fromAddressData.ownedLength = uint32( t.fromEnd = fromIndex - t.numNFTBurns ); uint32 burnedPoolTail = t.burnedPoolTail; // Burn loop. do { uint256 id = _get(fromOwned, --fromIndex); _setOwnerAliasAndOwnedIndex(oo, id, 0, 0); _packedLogsAppend(packedLogs, id); if (_useExistsLookup()) _set($.exists, id, false); if (addToBurnedPool) _set($.burnedPool, burnedPoolTail++, uint32(id)); if (_get($.mayHaveNFTApproval, id)) { _set($.mayHaveNFTApproval, id, false); delete $.nftApprovals[id]; } _afterNFTTransfer(from, address(0), id); } while (fromIndex != t.fromEnd); if (addToBurnedPool) $.burnedPoolTail = (t.burnedPoolTail = burnedPoolTail); } if (t.numNFTMints != 0) { _packedLogsSet(packedLogs, to, 0); Uint32Map storage toOwned = $.owned[to]; t.toAlias = _registerAndResolveAlias(toAddressData, to); uint256 maxId = t.totalSupply / _unit(); t.nextTokenId = _wrapNFTId($.nextTokenId, maxId); uint256 toIndex = t.toOwnedLength; toAddressData.ownedLength = uint32( t.toEnd = toIndex + t.numNFTMints ); uint32 burnedPoolHead = $.burnedPoolHead; // Mint loop. do { uint256 id; if (burnedPoolHead != t.burnedPoolTail) { id = _get($.burnedPool, burnedPoolHead++); } else { id = t.nextTokenId; while (_get(oo, _ownershipIndex(id)) != 0) { id = _useExistsLookup() ? _wrapNFTId( _findFirstUnset( $.exists, id + 1, maxId + 1 ), maxId ) : _wrapNFTId(id + 1, maxId); } t.nextTokenId = _wrapNFTId(id + 1, maxId); } if (_useExistsLookup()) _set($.exists, id, true); _set(toOwned, toIndex, uint32(id)); _setOwnerAliasAndOwnedIndex( oo, id, t.toAlias, uint32(toIndex++) ); _packedLogsAppend(packedLogs, id); _afterNFTTransfer(address(0), to, id); } while (toIndex != t.toEnd); $.burnedPoolHead = burnedPoolHead; $.nextTokenId = uint32(t.nextTokenId); } if (packedLogs.logs.length != 0) _packedLogsSend(packedLogs, $.mirrorERC721); } /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, amount) // forgefmt: disable-next-item log3( 0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), shr(96, shl(96, to)) ) } } /// @dev Transfers token `id` from `from` to `to`. /// /// Requirements: /// /// - Call must originate from the mirror contract. /// - Token `id` must exist. /// - `from` must be the owner of the token. /// - `to` cannot be the zero address. /// `msgSender` must be the owner of the token, or be approved to manage the token. /// /// Emits a {Transfer} event. function _transferFromNFT( address from, address to, uint256 id, address msgSender ) internal virtual { if (to == address(0)) revert TransferToZeroAddress(); DN404Storage storage $ = _getDN404Storage(); if ($.mirrorERC721 == address(0)) revert(); Uint32Map storage oo = $.oo; if ( from != $.aliasToAddress[_get(oo, _ownershipIndex(_restrictNFTId(id)))] ) { revert TransferFromIncorrectOwner(); } if (msgSender != from) { if (_ref($.operatorApprovals, from, msgSender).value == 0) { if (msgSender != $.nftApprovals[id]) { revert TransferCallerNotOwnerNorApproved(); } } } AddressData storage fromAddressData = _addressData(from); AddressData storage toAddressData = _addressData(to); uint256 unit = _unit(); mapping(address => Uint32Map) storage owned = $.owned; Uint32Map storage fromOwned = owned[from]; unchecked { uint256 fromBalance = fromAddressData.balance; if (unit > fromBalance) revert InsufficientBalance(); fromAddressData.balance = uint96(fromBalance - unit); toAddressData.balance += uint96(unit); } if (_get($.mayHaveNFTApproval, id)) { _set($.mayHaveNFTApproval, id, false); delete $.nftApprovals[id]; } unchecked { uint32 updatedId = _get(fromOwned, --fromAddressData.ownedLength); uint32 i = _get(oo, _ownedIndex(id)); _set(fromOwned, i, updatedId); _set(oo, _ownedIndex(updatedId), i); } unchecked { uint32 n = toAddressData.ownedLength++; _set(owned[to], n, uint32(id)); _setOwnerAliasAndOwnedIndex( oo, id, _registerAndResolveAlias(toAddressData, to), n ); } _afterNFTTransfer(from, to, id); /// @solidity memory-safe-assembly assembly { // Emit the {Transfer} event. mstore(0x00, unit) // forgefmt: disable-next-item log3( 0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), shr(96, shl(96, to)) ) } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INTERNAL APPROVE FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`. /// /// Emits a {Approval} event. function _approve( address owner, address spender, uint256 amount ) internal virtual { if (_givePermit2DefaultInfiniteAllowance() && spender == _PERMIT2) { _getDN404Storage() .addressData[owner] .flags |= _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG; } _ref(_getDN404Storage().allowance, owner, spender).value = amount; /// @solidity memory-safe-assembly assembly { // Emit the {Approval} event. mstore(0x00, amount) // forgefmt: disable-next-item log3( 0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, shl(96, owner)), shr(96, shl(96, spender)) ) } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* DATA HITCHHIKING FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the auxiliary data for `owner`. /// Minting, transferring, burning the tokens of `owner` will not change the auxiliary data. /// Auxiliary data can be set for any address, even if it does not have any tokens. function _getAux(address owner) internal view virtual returns (uint88) { return _getDN404Storage().addressData[owner].aux; } /// @dev Set the auxiliary data for `owner` to `value`. /// Minting, transferring, burning the tokens of `owner` will not change the auxiliary data. /// Auxiliary data can be set for any address, even if it does not have any tokens. function _setAux(address owner, uint88 value) internal virtual { _getDN404Storage().addressData[owner].aux = value; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* SKIP NFT FUNCTIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns true if minting and transferring ERC20s to `owner` will skip minting NFTs. /// Returns false otherwise. function getSkipNFT(address owner) public view virtual returns (bool) { AddressData storage d = _getDN404Storage().addressData[owner]; if (d.flags & _ADDRESS_DATA_INITIALIZED_FLAG == 0) return _hasCode(owner); return d.flags & _ADDRESS_DATA_SKIP_NFT_FLAG != 0; } /// @dev Sets the caller's skipNFT flag to `skipNFT`. Returns true. /// /// Emits a {SkipNFTSet} event. function setSkipNFT(bool skipNFT) public virtual returns (bool) { _setSkipNFT(msg.sender, skipNFT); return true; } /// @dev Internal function to set account `owner` skipNFT flag to `state` /// /// Initializes account `owner` AddressData if it is not currently initialized. /// /// Emits a {SkipNFTSet} event. function _setSkipNFT(address owner, bool state) internal virtual { AddressData storage d = _addressData(owner); if ((d.flags & _ADDRESS_DATA_SKIP_NFT_FLAG != 0) != state) { d.flags ^= _ADDRESS_DATA_SKIP_NFT_FLAG; } /// @solidity memory-safe-assembly assembly { mstore(0x00, iszero(iszero(state))) log2( 0x00, 0x20, _SKIP_NFT_SET_EVENT_SIGNATURE, shr(96, shl(96, owner)) ) } } /// @dev Returns a storage data pointer for account `owner` AddressData /// /// Initializes account `owner` AddressData if it is not currently initialized. function _addressData( address owner ) internal virtual returns (AddressData storage d) { d = _getDN404Storage().addressData[owner]; unchecked { if (d.flags & _ADDRESS_DATA_INITIALIZED_FLAG == 0) { uint256 skipNFT = _toUint(_hasCode(owner)) * _ADDRESS_DATA_SKIP_NFT_FLAG; d.flags = uint8(skipNFT | _ADDRESS_DATA_INITIALIZED_FLAG); } } } /// @dev Returns the `addressAlias` of account `to`. /// /// Assigns and registers the next alias if `to` alias was not previously registered. function _registerAndResolveAlias( AddressData storage toAddressData, address to ) internal virtual returns (uint32 addressAlias) { DN404Storage storage $ = _getDN404Storage(); addressAlias = toAddressData.addressAlias; if (addressAlias == 0) { unchecked { addressAlias = ++$.numAliases; } toAddressData.addressAlias = addressAlias; $.aliasToAddress[addressAlias] = to; if (addressAlias == 0) revert(); // Overflow. } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* MIRROR OPERATIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the address of the mirror NFT contract. function mirrorERC721() public view virtual returns (address) { return _getDN404Storage().mirrorERC721; } /// @dev Returns the total NFT supply. function _totalNFTSupply() internal view virtual returns (uint256) { return _getDN404Storage().totalNFTSupply; } /// @dev Returns `owner` NFT balance. function _balanceOfNFT( address owner ) internal view virtual returns (uint256) { return _getDN404Storage().addressData[owner].ownedLength; } /// @dev Returns the owner of token `id`. /// Returns the zero address instead of reverting if the token does not exist. function _ownerAt(uint256 id) internal view virtual returns (address) { DN404Storage storage $ = _getDN404Storage(); return $.aliasToAddress[_get($.oo, _ownershipIndex(_restrictNFTId(id)))]; } /// @dev Returns the owner of token `id`. /// /// Requirements: /// - Token `id` must exist. function _ownerOf(uint256 id) internal view virtual returns (address) { if (!_exists(id)) revert TokenDoesNotExist(); return _ownerAt(id); } /// @dev Returns if token `id` exists. function _exists(uint256 id) internal view virtual returns (bool) { return _ownerAt(id) != address(0); } /// @dev Returns the account approved to manage token `id`. /// /// Requirements: /// - Token `id` must exist. function _getApproved(uint256 id) internal view virtual returns (address) { if (!_exists(id)) revert TokenDoesNotExist(); return _getDN404Storage().nftApprovals[id]; } /// @dev Sets `spender` as the approved account to manage token `id`, using `msgSender`. /// /// Requirements: /// - `msgSender` must be the owner or an approved operator for the token owner. function _approveNFT( address spender, uint256 id, address msgSender ) internal virtual returns (address owner) { DN404Storage storage $ = _getDN404Storage(); owner = $.aliasToAddress[ _get($.oo, _ownershipIndex(_restrictNFTId(id))) ]; if (msgSender != owner) { if (_ref($.operatorApprovals, owner, msgSender).value == 0) { revert ApprovalCallerNotOwnerNorApproved(); } } $.nftApprovals[id] = spender; _set($.mayHaveNFTApproval, id, spender != address(0)); } /// @dev Approve or remove the `operator` as an operator for `msgSender`, /// without authorization checks. function _setApprovalForAll( address operator, bool approved, address msgSender ) internal virtual { _ref(_getDN404Storage().operatorApprovals, msgSender, operator) .value = _toUint(approved); } /// @dev Returns the NFT IDs of `owner` in range `[begin, end)`. /// Optimized for smaller bytecode size, as this function is intended for off-chain calling. function _ownedIds( address owner, uint256 begin, uint256 end ) internal view virtual returns (uint256[] memory ids) { DN404Storage storage $ = _getDN404Storage(); Uint32Map storage owned = $.owned[owner]; uint256 n = _min($.addressData[owner].ownedLength, end); /// @solidity memory-safe-assembly assembly { ids := mload(0x40) let i := begin for { } lt(i, n) { i := add(i, 1) } { let s := add(shl(96, owned.slot), shr(3, i)) // Storage slot. let id := and(0xffffffff, shr(shl(5, and(i, 7)), sload(s))) mstore(add(add(ids, 0x20), shl(5, sub(i, begin))), id) // Append to. } mstore(ids, sub(i, begin)) // Store the length. mstore(0x40, add(add(ids, 0x20), shl(5, sub(i, begin)))) // Allocate memory. } } /// @dev Fallback modifier to dispatch calls from the mirror NFT contract /// to internal functions in this contract. modifier dn404Fallback() virtual { DN404Storage storage $ = _getDN404Storage(); uint256 fnSelector = _calldataload(0x00) >> 224; address mirror = $.mirrorERC721; // `transferFromNFT(address,address,uint256,address)`. if (fnSelector == 0xe5eb36c8) { if (msg.sender != mirror) revert SenderNotMirror(); _transferFromNFT( address(uint160(_calldataload(0x04))), // `from`. address(uint160(_calldataload(0x24))), // `to`. _calldataload(0x44), // `id`. address(uint160(_calldataload(0x64))) // `msgSender`. ); _return(1); } // `setApprovalForAll(address,bool,address)`. if (fnSelector == 0x813500fc) { if (msg.sender != mirror) revert SenderNotMirror(); _setApprovalForAll( address(uint160(_calldataload(0x04))), // `spender`. _calldataload(0x24) != 0, // `status`. address(uint160(_calldataload(0x44))) // `msgSender`. ); _return(1); } // `isApprovedForAll(address,address)`. if (fnSelector == 0xe985e9c5) { if (msg.sender != mirror) revert SenderNotMirror(); Uint256Ref storage ref = _ref( $.operatorApprovals, address(uint160(_calldataload(0x04))), // `owner`. address(uint160(_calldataload(0x24))) // `operator`. ); _return(ref.value); } // `ownerOf(uint256)`. if (fnSelector == 0x6352211e) { if (msg.sender != mirror) revert SenderNotMirror(); _return(uint160(_ownerOf(_calldataload(0x04)))); } // `ownerAt(uint256)`. if (fnSelector == 0x24359879) { if (msg.sender != mirror) revert SenderNotMirror(); _return(uint160(_ownerAt(_calldataload(0x04)))); } // `approveNFT(address,uint256,address)`. if (fnSelector == 0xd10b6e0c) { if (msg.sender != mirror) revert SenderNotMirror(); address owner = _approveNFT( address(uint160(_calldataload(0x04))), // `spender`. _calldataload(0x24), // `id`. address(uint160(_calldataload(0x44))) // `msgSender`. ); _return(uint160(owner)); } // `getApproved(uint256)`. if (fnSelector == 0x081812fc) { if (msg.sender != mirror) revert SenderNotMirror(); _return(uint160(_getApproved(_calldataload(0x04)))); } // `balanceOfNFT(address)`. if (fnSelector == 0xf5b100ea) { if (msg.sender != mirror) revert SenderNotMirror(); _return(_balanceOfNFT(address(uint160(_calldataload(0x04))))); } // `totalNFTSupply()`. if (fnSelector == 0xe2c79281) { if (msg.sender != mirror) revert SenderNotMirror(); _return(_totalNFTSupply()); } // `implementsDN404()`. if (fnSelector == 0xb7a94eb8) { _return(1); } _; } /// @dev Fallback function for calls from mirror NFT contract. /// Override this if you need to implement your custom /// fallback with utilities like Solady's `LibZip.cdFallback()`. /// And always remember to always wrap the fallback with `dn404Fallback`. fallback() external payable virtual dn404Fallback { revert FnSelectorNotRecognized(); // Not mandatory. Just for quality of life. } /// @dev This is to silence the compiler warning. /// Override and remove the revert if you want your contract to receive ETH via receive. receive() external payable virtual { if (msg.value != 0) revert(); } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* INTERNAL / PRIVATE HELPERS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns `(i - 1) << 1`. function _ownershipIndex(uint256 i) internal pure returns (uint256) { unchecked { return (i - 1) << 1; // Minus 1 as token IDs start from 1. } } /// @dev Returns `((i - 1) << 1) + 1`. function _ownedIndex(uint256 i) internal pure returns (uint256) { unchecked { return ((i - 1) << 1) + 1; // Minus 1 as token IDs start from 1. } } /// @dev Returns the uint32 value at `index` in `map`. function _get( Uint32Map storage map, uint256 index ) internal view returns (uint32 result) { /// @solidity memory-safe-assembly assembly { let s := add(shl(96, map.slot), shr(3, index)) // Storage slot. result := and(0xffffffff, shr(shl(5, and(index, 7)), sload(s))) } } /// @dev Updates the uint32 value at `index` in `map`. function _set(Uint32Map storage map, uint256 index, uint32 value) internal { /// @solidity memory-safe-assembly assembly { let s := add(shl(96, map.slot), shr(3, index)) // Storage slot. let o := shl(5, and(index, 7)) // Storage slot offset (bits). let v := sload(s) // Storage slot value. sstore(s, xor(v, shl(o, and(0xffffffff, xor(value, shr(o, v)))))) } } /// @dev Sets the owner alias and the owned index together. function _setOwnerAliasAndOwnedIndex( Uint32Map storage map, uint256 id, uint32 ownership, uint32 ownedIndex ) internal { /// @solidity memory-safe-assembly assembly { let i := sub(id, 1) // Index of the uint64 combined value. let s := add(shl(96, map.slot), shr(2, i)) // Storage slot. let v := sload(s) // Storage slot value. let o := shl(6, and(i, 3)) // Storage slot offset (bits). let combined := or(shl(32, ownedIndex), and(0xffffffff, ownership)) sstore( s, xor( v, shl(o, and(0xffffffffffffffff, xor(shr(o, v), combined))) ) ) } } /// @dev Returns the boolean value of the bit at `index` in `bitmap`. function _get( Bitmap storage bitmap, uint256 index ) internal view returns (bool result) { /// @solidity memory-safe-assembly assembly { let s := add(shl(96, bitmap.slot), shr(8, index)) // Storage slot. result := and(1, shr(and(0xff, index), sload(s))) } } /// @dev Updates the bit at `index` in `bitmap` to `value`. function _set(Bitmap storage bitmap, uint256 index, bool value) internal { /// @solidity memory-safe-assembly assembly { let s := add(shl(96, bitmap.slot), shr(8, index)) // Storage slot. let o := and(0xff, index) // Storage slot offset (bits). sstore( s, or(and(sload(s), not(shl(o, 1))), shl(o, iszero(iszero(value)))) ) } } /// @dev Returns the index of the least significant unset bit in `[begin, end)`. /// If no unset bit is found, returns `type(uint256).max`. function _findFirstUnset( Bitmap storage bitmap, uint256 begin, uint256 end ) internal view returns (uint256 unsetBitIndex) { /// @solidity memory-safe-assembly assembly { unsetBitIndex := not(0) // Initialize to `type(uint256).max`. let s := shl(96, bitmap.slot) // Storage offset of the bitmap. let bucket := add(s, shr(8, begin)) let negBits := shl( and(0xff, begin), shr(and(0xff, begin), not(sload(bucket))) ) if iszero(negBits) { let lastBucket := add(s, shr(8, end)) for { } 1 { } { bucket := add(bucket, 1) negBits := not(sload(bucket)) if or(negBits, gt(bucket, lastBucket)) { break } } if gt(bucket, lastBucket) { negBits := shr( and(0xff, not(end)), shl(and(0xff, not(end)), negBits) ) } } if negBits { // Find-first-set routine. let b := and(negBits, add(not(negBits), 1)) // Isolate the least significant bit. let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, b)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, b)))) r := or(r, shl(5, lt(0xffffffff, shr(r, b)))) // For the remaining 32 bits, use a De Bruijn lookup. // forgefmt: disable-next-item r := or( r, byte( and(div(0xd76453e0, shr(r, b)), 0x1f), 0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405 ) ) r := or(shl(8, sub(bucket, s)), r) unsetBitIndex := or( r, sub(0, or(iszero(lt(r, end)), lt(r, begin))) ) } } } /// @dev Returns a storage reference to the value at (`a0`, `a1`) in `map`. function _ref( AddressPairToUint256RefMap storage map, address a0, address a1 ) internal pure returns (Uint256Ref storage ref) { /// @solidity memory-safe-assembly assembly { mstore(0x28, a1) mstore(0x14, a0) mstore(0x00, map.slot) ref.slot := keccak256(0x00, 0x48) // Clear the part of the free memory pointer that was overwritten. mstore(0x28, 0x00) } } /// @dev Wraps the NFT ID. function _wrapNFTId( uint256 id, uint256 maxId ) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := or(mul(iszero(gt(id, maxId)), id), gt(id, maxId)) } } /// @dev Returns `id > type(uint32).max ? 0 : id`. function _restrictNFTId(uint256 id) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mul(id, lt(id, 0x100000000)) } } /// @dev Returns whether `amount` is a valid `totalSupply`. function _totalSupplyOverflows( uint256 amount ) internal view returns (bool result) { uint256 unit = _unit(); /// @solidity memory-safe-assembly assembly { result := iszero( iszero(or(shr(96, amount), lt(0xfffffffe, div(amount, unit)))) ) } } /// @dev Returns `max(0, x - y)`. function _zeroFloorSub( uint256 x, uint256 y ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(gt(x, y), sub(x, y)) } } /// @dev Returns `x < y ? x : y`. function _min(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Returns `b ? 1 : 0`. function _toUint(bool b) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := iszero(iszero(b)) } } /// @dev Struct containing direct transfer log data for {Transfer} events to be /// emitted by the mirror NFT contract. struct _DNDirectLogs { uint256 offset; address from; address to; uint256[] logs; } /// @dev Initiates memory allocation for direct logs with `n` log items. function _directLogsMalloc( uint256 n, address from, address to ) private pure returns (_DNDirectLogs memory p) { /// @solidity memory-safe-assembly assembly { // Note that `p` implicitly allocates and advances the free memory pointer by // 4 words, which we can safely mutate in `_directLogsSend`. let logs := mload(0x40) mstore(logs, n) // Store the length. let offset := add(0x20, logs) // Skip the word for `p.logs.length`. mstore(0x40, add(offset, shl(5, n))) // Allocate memory. mstore(add(0x60, p), logs) // Set `p.logs`. mstore(add(0x40, p), to) // Set `p.to`. mstore(add(0x20, p), from) // Set `p.from`. mstore(p, offset) // Set `p.offset`. } } /// @dev Adds a direct log item to `p` with token `id`. function _directLogsAppend( _DNDirectLogs memory p, uint256 id ) private pure { /// @solidity memory-safe-assembly assembly { let offset := mload(p) mstore(offset, id) mstore(p, add(offset, 0x20)) } } /// @dev Calls the `mirror` NFT contract to emit {Transfer} events for packed logs `p`. function _directLogsSend(_DNDirectLogs memory p, address mirror) private { /// @solidity memory-safe-assembly assembly { let logs := mload(add(p, 0x60)) let n := add(0x84, shl(5, mload(logs))) // Length of calldata to send. let o := sub(logs, 0x80) // Start of calldata to send. mstore(o, 0x144027d3) // `logDirectTransfer(address,address,uint256[])`. let from := mload(add(0x20, p)) let to := mload(add(0x40, p)) mstore(add(o, 0x20), from) mstore(add(o, 0x40), to) mstore(add(o, 0x60), 0x60) // Offset of `logs` in the calldata to send. if iszero( and( eq(mload(o), 1), call(gas(), mirror, 0, add(o, 0x1c), n, o, 0x20) ) ) { revert(o, 0x00) } } } /// @dev Struct containing packed log data for {Transfer} events to be /// emitted by the mirror NFT contract. struct _DNPackedLogs { uint256 offset; uint256 addressAndBit; uint256[] logs; } /// @dev Initiates memory allocation for packed logs with `n` log items. function _packedLogsMalloc( uint256 n ) private pure returns (_DNPackedLogs memory p) { /// @solidity memory-safe-assembly assembly { // Note that `p` implicitly allocates and advances the free memory pointer by // 3 words, which we can safely mutate in `_packedLogsSend`. let logs := mload(0x40) mstore(logs, n) // Store the length. let offset := add(0x20, logs) // Skip the word for `p.logs.length`. mstore(0x40, add(offset, shl(5, n))) // Allocate memory. mstore(add(0x40, p), logs) // Set `p.logs`. mstore(p, offset) // Set `p.offset`. } } /// @dev Set the current address and the burn bit. function _packedLogsSet( _DNPackedLogs memory p, address a, uint256 burnBit ) private pure { /// @solidity memory-safe-assembly assembly { mstore(add(p, 0x20), or(shl(96, a), burnBit)) // Set `p.addressAndBit`. } } /// @dev Adds a packed log item to `p` with token `id`. function _packedLogsAppend( _DNPackedLogs memory p, uint256 id ) private pure { /// @solidity memory-safe-assembly assembly { let offset := mload(p) mstore(offset, or(mload(add(p, 0x20)), shl(8, id))) // `p.addressAndBit | (id << 8)`. mstore(p, add(offset, 0x20)) } } /// @dev Calls the `mirror` NFT contract to emit {Transfer} events for packed logs `p`. function _packedLogsSend(_DNPackedLogs memory p, address mirror) private { /// @solidity memory-safe-assembly assembly { let logs := mload(add(p, 0x40)) let o := sub(logs, 0x40) // Start of calldata to send. mstore(o, 0x263c69d6) // `logTransfer(uint256[])`. mstore(add(o, 0x20), 0x20) // Offset of `logs` in the calldata to send. let n := add(0x44, shl(5, mload(logs))) // Length of calldata to send. if iszero( and( eq(mload(o), 1), call(gas(), mirror, 0, add(o, 0x1c), n, o, 0x20) ) ) { revert(o, 0x00) } } } /// @dev Struct of temporary variables for transfers. struct _DNTransferTemps { uint256 numNFTBurns; uint256 numNFTMints; uint256 fromBalance; uint256 toBalance; uint256 fromOwnedLength; uint256 toOwnedLength; uint256 totalSupply; uint256 totalNFTSupply; uint256 fromEnd; uint256 toEnd; uint32 toAlias; uint256 nextTokenId; uint32 burnedPoolTail; } /// @dev Struct of temporary variables for mints. struct _DNMintTemps { uint256 nextTokenId; uint32 burnedPoolTail; uint256 toEnd; uint32 toAlias; } /// @dev Returns if `a` has bytecode of non-zero length. function _hasCode(address a) private view returns (bool result) { /// @solidity memory-safe-assembly assembly { result := extcodesize(a) // Can handle dirty upper bits. } } /// @dev Returns the calldata value at `offset`. function _calldataload( uint256 offset ) private pure returns (uint256 value) { /// @solidity memory-safe-assembly assembly { value := calldataload(offset) } } /// @dev Executes a return opcode to return `x` and end the current call frame. function _return(uint256 x) private pure { /// @solidity memory-safe-assembly assembly { mstore(0x00, x) return(0x00, 0x20) } } }
contracts/brc404/DN404Mirror.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @title DN404Mirror /// @notice DN404Mirror provides an interface for interacting with the /// NFT tokens in a DN404 implementation. /// /// @dev Note: /// - The ERC721 data is stored in the base DN404 contract. contract DN404Mirror { /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* EVENTS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Emitted when token `id` is transferred from `from` to `to`. event Transfer( address indexed from, address indexed to, uint256 indexed id ); /// @dev Emitted when `owner` enables `account` to manage the `id` token. event Approval( address indexed owner, address indexed account, uint256 indexed id ); /// @dev Emitted when `owner` enables or disables `operator` to manage all of their tokens. event ApprovalForAll( address indexed owner, address indexed operator, bool isApproved ); /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This is for marketplace signaling purposes. This contract has a `pullOwner()` /// function that will sync the owner from the base contract. event OwnershipTransferred( address indexed oldOwner, address indexed newOwner ); /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`. uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`. uint256 private constant _APPROVAL_EVENT_SIGNATURE = 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925; /// @dev `keccak256(bytes("ApprovalForAll(address,address,bool)"))`. uint256 private constant _APPROVAL_FOR_ALL_EVENT_SIGNATURE = 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31; /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* CUSTOM ERRORS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Thrown when a call for an NFT function did not originate /// from the base DN404 contract. error SenderNotBase(); /// @dev Thrown when a call for an NFT function did not originate from the deployer. error SenderNotDeployer(); /// @dev Thrown when transferring an NFT to a contract address that /// does not implement ERC721Receiver. error TransferToNonERC721ReceiverImplementer(); /// @dev Thrown when linking to the DN404 base contract and the /// DN404 supportsInterface check fails or the call reverts. error CannotLink(); /// @dev Thrown when a linkMirrorContract call is received and the /// NFT mirror contract has already been linked to a DN404 base contract. error AlreadyLinked(); /// @dev Thrown when retrieving the base DN404 address when a link has not /// been established. error NotLinked(); /// @dev The function selector is not recognized. error FnSelectorNotRecognized(); /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* STORAGE */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Struct contain the NFT mirror contract storage. struct DN404NFTStorage { // Address of the ERC20 base contract. address baseERC20; // The deployer, if provided. If non-zero, the initialization of the // ERC20 <-> ERC721 link can only be done be the deployer via the ERC20 base contract. address deployer; // The owner of the ERC20 base contract. For marketplace signaling. address owner; } /// @dev Returns a storage pointer for DN404NFTStorage. function _getDN404NFTStorage() internal pure virtual returns (DN404NFTStorage storage $) { /// @solidity memory-safe-assembly assembly { // `uint72(bytes9(keccak256("DN404_MIRROR_STORAGE")))`. $.slot := 0x3602298b8c10b01230 // Truncate to 9 bytes to reduce bytecode size. } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* CONSTRUCTOR */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ constructor(address deployer) { // For non-proxies, we will store the deployer so that only the deployer can // link the base contract. _getDN404NFTStorage().deployer = deployer; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* ERC721 OPERATIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the token collection name from the base DN404 contract. function name() public view virtual returns (string memory) { return _readString(0x06fdde03, 0); // `name()`. } /// @dev Returns the token collection symbol from the base DN404 contract. function symbol() public view virtual returns (string memory) { return _readString(0x95d89b41, 0); // `symbol()`. } /// @dev Returns the Uniform Resource Identifier (URI) for token `id` from /// the base DN404 contract. function tokenURI(uint256 id) public view virtual returns (string memory) { return _readString(0xc87b56dd, id); // `tokenURI()`. } /// @dev Returns the total NFT supply from the base DN404 contract. function totalSupply() public view virtual returns (uint256) { return _readWord(0xe2c79281, 0, 0); // `totalNFTSupply()`. } /// @dev Returns the number of NFT tokens owned by `nftOwner` from the base DN404 contract. /// /// Requirements: /// - `nftOwner` must not be the zero address. function balanceOf(address nftOwner) public view virtual returns (uint256) { return _readWord(0xf5b100ea, uint160(nftOwner), 0); // `balanceOfNFT(address)`. } /// @dev Returns the owner of token `id` from the base DN404 contract. /// /// Requirements: /// - Token `id` must exist. function ownerOf(uint256 id) public view virtual returns (address) { return address(uint160(_readWord(0x6352211e, id, 0))); // `ownerOf(uint256)`. } /// @dev Returns the owner of token `id` from the base DN404 contract. /// Returns `address(0)` instead of reverting if the token does not exist. function ownerAt(uint256 id) public view virtual returns (address) { return address(uint160(_readWord(0x24359879, id, 0))); // `ownerAt(uint256)`. } /// @dev Sets `spender` as the approved account to manage token `id` in /// the base DN404 contract. /// /// Requirements: /// - Token `id` must exist. /// - The caller must be the owner of the token, /// or an approved operator for the token owner. /// /// Emits an {Approval} event. function approve(address spender, uint256 id) public payable virtual { address base = baseERC20(); /// @solidity memory-safe-assembly assembly { spender := shr(96, shl(96, spender)) let m := mload(0x40) mstore(0x00, 0xd10b6e0c) // `approveNFT(address,uint256,address)`. mstore(0x20, spender) mstore(0x40, id) mstore(0x60, caller()) if iszero( and( // Arguments of `and` are evaluated last to first. gt(returndatasize(), 0x1f), // The call must return at least 32 bytes. call(gas(), base, callvalue(), 0x1c, 0x64, 0x00, 0x20) ) ) { returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero pointer. // Emit the {Approval} event. log4( codesize(), 0x00, _APPROVAL_EVENT_SIGNATURE, shr(96, mload(0x0c)), spender, id ) } } /// @dev Returns the account approved to manage token `id` from /// the base DN404 contract. /// /// Requirements: /// - Token `id` must exist. function getApproved(uint256 id) public view virtual returns (address) { return address(uint160(_readWord(0x081812fc, id, 0))); // `getApproved(uint256)`. } /// @dev Sets whether `operator` is approved to manage the tokens of the caller in /// the base DN404 contract. /// /// Emits an {ApprovalForAll} event. function setApprovalForAll(address operator, bool approved) public virtual { address base = baseERC20(); /// @solidity memory-safe-assembly assembly { operator := shr(96, shl(96, operator)) let m := mload(0x40) mstore(0x00, 0x813500fc) // `setApprovalForAll(address,bool,address)`. mstore(0x20, operator) mstore(0x40, iszero(iszero(approved))) mstore(0x60, caller()) if iszero( and( // Arguments of `and` are evaluated last to first. eq(mload(0x00), 1), // The call must return 1. call(gas(), base, callvalue(), 0x1c, 0x64, 0x00, 0x20) ) ) { returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } // Emit the {ApprovalForAll} event. // The `approved` value is already at 0x40. log3( 0x40, 0x20, _APPROVAL_FOR_ALL_EVENT_SIGNATURE, caller(), operator ) mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero pointer. } } /// @dev Returns whether `operator` is approved to manage the tokens of `nftOwner` from /// the base DN404 contract. function isApprovedForAll( address nftOwner, address operator ) public view virtual returns (bool) { // `isApprovedForAll(address,address)`. return _readWord(0xe985e9c5, uint160(nftOwner), uint160(operator)) != 0; } /// @dev Transfers token `id` from `from` to `to`. /// /// Requirements: /// /// - Token `id` must exist. /// - `from` must be the owner of the token. /// - `to` cannot be the zero address. /// - The caller must be the owner of the token, or be approved to manage the token. /// /// Emits a {Transfer} event. function transferFrom( address from, address to, uint256 id ) public payable virtual { address base = baseERC20(); /// @solidity memory-safe-assembly assembly { from := shr(96, shl(96, from)) to := shr(96, shl(96, to)) let m := mload(0x40) mstore(m, 0xe5eb36c8) // `transferFromNFT(address,address,uint256,address)`. mstore(add(m, 0x20), from) mstore(add(m, 0x40), to) mstore(add(m, 0x60), id) mstore(add(m, 0x80), caller()) if iszero( and( // Arguments of `and` are evaluated last to first. eq(mload(m), 1), // The call must return 1. call(gas(), base, callvalue(), add(m, 0x1c), 0x84, m, 0x20) ) ) { returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } // Emit the {Transfer} event. log4(codesize(), 0x00, _TRANSFER_EVENT_SIGNATURE, from, to, id) } } /// @dev Equivalent to `safeTransferFrom(from, to, id, "")`. function safeTransferFrom( address from, address to, uint256 id ) public payable virtual { transferFrom(from, to, id); if (_hasCode(to)) _checkOnERC721Received(from, to, id, ""); } /// @dev Transfers token `id` from `from` to `to`. /// /// Requirements: /// /// - Token `id` must exist. /// - `from` must be the owner of the token. /// - `to` cannot be the zero address. /// - The caller must be the owner of the token, or be approved to manage the token. /// - 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 id, bytes calldata data ) public payable virtual { transferFrom(from, to, id); if (_hasCode(to)) _checkOnERC721Received(from, to, id, data); } /// @dev Returns true if this contract implements the interface defined by `interfaceId`. /// See: https://eips.ethereum.org/EIPS/eip-165 /// This function call must use less than 30000 gas. function supportsInterface( bytes4 interfaceId ) public view virtual returns (bool result) { /// @solidity memory-safe-assembly assembly { let s := shr(224, interfaceId) // ERC165: 0x01ffc9a7, ERC721: 0x80ac58cd, ERC721Metadata: 0x5b5e139f. result := or( or(eq(s, 0x01ffc9a7), eq(s, 0x80ac58cd)), eq(s, 0x5b5e139f) ) } } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* OWNER SYNCING OPERATIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the `owner` of the contract, for marketplace signaling purposes. function owner() public view virtual returns (address) { return _getDN404NFTStorage().owner; } /// @dev Permissionless function to pull the owner from the base DN404 contract /// if it implements ownable, for marketplace signaling purposes. function pullOwner() public virtual returns (bool) { address newOwner; address base = baseERC20(); /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x8da5cb5b) // `owner()`. let success := staticcall(gas(), base, 0x1c, 0x04, 0x00, 0x20) newOwner := mul( shr(96, mload(0x0c)), and(gt(returndatasize(), 0x1f), success) ) } DN404NFTStorage storage $ = _getDN404NFTStorage(); address oldOwner = $.owner; if (oldOwner != newOwner) { $.owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } return true; } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* MIRROR OPERATIONS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Returns the address of the base DN404 contract. function baseERC20() public view virtual returns (address base) { base = _getDN404NFTStorage().baseERC20; if (base == address(0)) revert NotLinked(); } /// @dev Fallback modifier to execute calls from the base DN404 contract. modifier dn404NFTFallback() virtual { DN404NFTStorage storage $ = _getDN404NFTStorage(); uint256 fnSelector = _calldataload(0x00) >> 224; // `logTransfer(uint256[])`. if (fnSelector == 0x263c69d6) { if (msg.sender != $.baseERC20) revert SenderNotBase(); /// @solidity memory-safe-assembly assembly { let o := add(0x24, calldataload(0x04)) // Packed logs offset. let end := add(o, shl(5, calldataload(sub(o, 0x20)))) for { } iszero(eq(o, end)) { o := add(0x20, o) } { let d := calldataload(o) // Entry in the packed logs. let a := shr(96, d) // The address. let b := and(1, d) // Whether it is a burn. log4( codesize(), 0x00, _TRANSFER_EVENT_SIGNATURE, mul(a, b), // `from`. mul(a, iszero(b)), // `to`. shr(168, shl(160, d)) // `id`. ) } mstore(0x00, 0x01) return(0x00, 0x20) } } // `logDirectTransfer(address,address,uint256[])`. if (fnSelector == 0x144027d3) { if (msg.sender != $.baseERC20) revert SenderNotBase(); /// @solidity memory-safe-assembly assembly { let from := calldataload(0x04) let to := calldataload(0x24) let o := add(0x24, calldataload(0x44)) // Direct logs offset. let end := add(o, shl(5, calldataload(sub(o, 0x20)))) for { } iszero(eq(o, end)) { o := add(0x20, o) } { log4( codesize(), 0x00, _TRANSFER_EVENT_SIGNATURE, from, to, calldataload(o) ) } mstore(0x00, 0x01) return(0x00, 0x20) } } // `linkMirrorContract(address)`. if (fnSelector == 0x0f4599e5) { if ($.deployer != address(0)) { if (address(uint160(_calldataload(0x04))) != $.deployer) { revert SenderNotDeployer(); } } if ($.baseERC20 != address(0)) revert AlreadyLinked(); $.baseERC20 = msg.sender; /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x01) return(0x00, 0x20) } } _; } /// @dev Fallback function for calls from base DN404 contract. /// Override this if you need to implement your custom /// fallback with utilities like Solady's `LibZip.cdFallback()`. /// And always remember to always wrap the fallback with `dn404NFTFallback`. fallback() external payable virtual dn404NFTFallback { revert FnSelectorNotRecognized(); // Not mandatory. Just for quality of life. } /// @dev This is to silence the compiler warning. /// Override and remove the revert if you want your contract to receive ETH via receive. receive() external payable virtual { if (msg.value != 0) revert(); } /*Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-Ā«-*/ /* PRIVATE HELPERS */ /*-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»-Ā»*/ /// @dev Helper to read a string from the base DN404 contract. function _readString( uint256 fnSelector, uint256 arg0 ) private view returns (string memory result) { address base = baseERC20(); /// @solidity memory-safe-assembly assembly { result := mload(0x40) mstore(0x00, fnSelector) mstore(0x20, arg0) if iszero(staticcall(gas(), base, 0x1c, 0x24, 0x00, 0x00)) { returndatacopy(result, 0x00, returndatasize()) revert(result, returndatasize()) } returndatacopy(0x00, 0x00, 0x20) // Copy the offset of the string in returndata. returndatacopy(result, mload(0x00), 0x20) // Copy the length of the string. returndatacopy( add(result, 0x20), add(mload(0x00), 0x20), mload(result) ) // Copy the string. let end := add(add(result, 0x20), mload(result)) mstore(end, 0) // Zeroize the word after the string. mstore(0x40, add(end, 0x20)) // Allocate memory. } } /// @dev Helper to read a word from the base DN404 contract. function _readWord( uint256 fnSelector, uint256 arg0, uint256 arg1 ) private view returns (uint256 result) { address base = baseERC20(); /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(0x00, fnSelector) mstore(0x20, arg0) mstore(0x40, arg1) if iszero( and( // Arguments of `and` are evaluated last to first. gt(returndatasize(), 0x1f), // The call must return at least 32 bytes. staticcall(gas(), base, 0x1c, 0x44, 0x00, 0x20) ) ) { returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } mstore(0x40, m) // Restore the free memory pointer. result := mload(0x00) } } /// @dev Returns the calldata value at `offset`. function _calldataload( uint256 offset ) private pure returns (uint256 value) { /// @solidity memory-safe-assembly assembly { value := calldataload(offset) } } /// @dev Returns if `a` has bytecode of non-zero length. function _hasCode(address a) private view returns (bool result) { /// @solidity memory-safe-assembly assembly { result := extcodesize(a) // Can handle dirty upper bits. } } /// @dev Perform a call to invoke {IERC721Receiver-onERC721Received} on `to`. /// Reverts if the target does not support the function correctly. function _checkOnERC721Received( address from, address to, uint256 id, bytes memory data ) private { /// @solidity memory-safe-assembly assembly { // Prepare the calldata. let m := mload(0x40) let onERC721ReceivedSelector := 0x150b7a02 mstore(m, onERC721ReceivedSelector) mstore(add(m, 0x20), caller()) // The `operator`, which is always `msg.sender`. mstore(add(m, 0x40), shr(96, shl(96, from))) mstore(add(m, 0x60), id) mstore(add(m, 0x80), 0x80) let n := mload(data) mstore(add(m, 0xa0), n) if n { pop(staticcall(gas(), 4, add(data, 0x20), n, add(m, 0xc0), n)) } // Revert if the call reverts. if iszero(call(gas(), to, 0, add(m, 0x1c), add(n, 0xa4), m, 0x20)) { if returndatasize() { // Bubble up the revert if the call reverts. returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } } // Load the returndata and compare it. if iszero(eq(mload(m), shl(224, onERC721ReceivedSelector))) { mstore(0x00, 0xd1a57ed6) // `TransferToNonERC721ReceiverImplementer()`. revert(0x1c, 0x04) } } } }
contracts/brc404/utils/SafeTransferLib.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; library SafeTransferLib { function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero( call( gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00 ) ) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } }
Compiler Settings
{"viaIR":true,"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"string","name":"name_","internalType":"string"},{"type":"string","name":"symbol_","internalType":"string"},{"type":"uint256","name":"unitX18","internalType":"uint256"},{"type":"uint96","name":"initialTokenSupplyX18","internalType":"uint96"},{"type":"address","name":"initialSupplyOwner","internalType":"address"}]},{"type":"error","name":"ApprovalCallerNotOwnerNorApproved","inputs":[]},{"type":"error","name":"DNAlreadyInitialized","inputs":[]},{"type":"error","name":"FnSelectorNotRecognized","inputs":[]},{"type":"error","name":"InsufficientAllowance","inputs":[]},{"type":"error","name":"InsufficientBalance","inputs":[]},{"type":"error","name":"LinkMirrorContractFailed","inputs":[]},{"type":"error","name":"MirrorAddressIsZero","inputs":[]},{"type":"error","name":"SenderNotMirror","inputs":[]},{"type":"error","name":"TokenDoesNotExist","inputs":[]},{"type":"error","name":"TotalSupplyOverflow","inputs":[]},{"type":"error","name":"TransferCallerNotOwnerNorApproved","inputs":[]},{"type":"error","name":"TransferFromIncorrectOwner","inputs":[]},{"type":"error","name":"TransferToZeroAddress","inputs":[]},{"type":"error","name":"UnitIsZero","inputs":[]},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"spender","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"SkipNFTSet","inputs":[{"type":"address","name":"target","internalType":"address","indexed":true},{"type":"bool","name":"status","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"fallback","stateMutability":"payable"},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"allowance","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"spender","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"approve","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"decimals","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"getSkipNFT","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"mirrorERC721","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBaseURI","inputs":[{"type":"string","name":"baseURI_","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"setSkipNFT","inputs":[{"type":"bool","name":"skipNFT","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"result","internalType":"string"}],"name":"tokenURI","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transfer","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x60406080815234620006d0576200367490813803806200001f81620006d5565b938439820160a083820312620006d05782516001600160401b038111620006d057816200004e918501620006fb565b602084015190916001600160401b038211620006d05762000071918501620006fb565b83830151606085015190946001600160601b0382168203620006d057608001516001600160a01b03811693909290848403620006d05760008054336001600160a01b031982168117835588519290916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a38715620006ba576001600160601b0384168890066200068757508051906001600160401b038211620005785760015490600182811c921680156200067c575b6020831014620005575781601f84931162000618575b50602090601f83116001146200059a576000926200058e575b50508160011b916000199060031b1c1916176001555b8051906001600160401b038211620005785760025490600182811c921680156200056d575b6020831014620005575781601f849311620004f3575b50602090601f831160011462000479576000926200046d575b50508160011b916000199060031b1c1916176002555b60049485558351610c84808201906001600160401b0382118383101762000458576020918391620029b083393381520301906000f080156200044d5760018060a01b03168554156200043d5768a20d6e21d0e525530980549091906001600160a01b03166200042d5780156200041d57630f4599e560005233602052602060006024601c82855af16001600051141615620004105768a20d6e21d0e5255308805463ffffffff60201b198116640100000000908117835584546001600160a01b031916909317909355906001600160601b038416620002c5575b86516121e89081620007c88239f35b8515620004005787546001600160601b0385160463fffffffe10620003f057620003659596975060018060a01b03198460a01b16809367ffffffff00000001600160a01b0316171790556200031a836200076d565b80546001600160a01b031690911790556001600160601b0316600090815283907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602082a36200076d565b805460581c90600160028316151503620003b4575b505060016000527fb5a1de456fff688115a4f75380060c23c8532d14ff85f687cc871456d642039360206000a280388080808080620002b6565b600260ff620003e89316186bff000000000000000000000082549160581b16906bff00000000000000000000001916179055565b38806200037a565b865163e5cfe95760e01b81528890fd5b8651633a954ecd60e21b81528890fd5b8663d125259c600052601cfd5b85516339a84a7b60e01b81528790fd5b8551633ab534b960e21b81528790fd5b8451630af2b2b160e01b81528690fd5b84513d6000823e3d90fd5b604188634e487b7160e01b6000525260246000fd5b015190503880620001c6565b60026000908152600080516020620036348339815191529350601f198516905b818110620004da5750908460019594939210620004c0575b505050811b01600255620001dc565b015160001960f88460031b161c19169055388080620004b1565b9293602060018192878601518155019501930162000499565b600260005290915060008051602062003634833981519152601f840160051c810191602085106200054c575b90601f859493920160051c01905b8181106200053c5750620001ad565b600081558493506001016200052d565b90915081906200051f565b634e487b7160e01b600052602260045260246000fd5b91607f169162000197565b634e487b7160e01b600052604160045260246000fd5b0151905038806200015c565b6001600090815293506000805160206200365483398151915291905b601f1984168510620005fc576001945083601f19811610620005e2575b505050811b0160015562000172565b015160001960f88460031b161c19169055388080620005d3565b81810151835560209485019460019093019290910190620005b6565b600160005290915060008051602062003654833981519152601f840160051c8101916020851062000671575b90601f859493920160051c01905b81811062000661575062000143565b6000815584935060010162000652565b909150819062000644565b91607f16916200012d565b62461bcd60e51b815260206004820152600e60248201526d696e76616c696420706172616d7360901b6044820152606490fd5b634e487b7160e01b600052601260045260246000fd5b600080fd5b6040519190601f01601f191682016001600160401b038111838210176200057857604052565b919080601f84011215620006d05782516001600160401b038111620005785760209062000731601f8201601f19168301620006d5565b92818452828287010111620006d05760005b8181106200075957508260009394955001015290565b858101830151848201840152820162000743565b9060018060a01b03821660005268a20d6e21d0e52553136020526040600020916001835460581c16156200079e5750565b825460ff60581b1916903b1515600190811b1760581b6bff00000000000000000000001617825556fe608060408181526004918236101561080f575b5036156108035768a20d6e21d0e5255309546001600160a01b039081169190600090813560e01c9063e5eb36c8821461045b5763813500fc82146104125763e985e9c582146103d157636352211e821461032257632435987982146102d15763d10b6e0c82146101df5763081812fc82146101475763f5b100ea82146100f5575063e2c7928181146100c35763b7a94eb891929350146100ba575051631e085ca760e11b8152fd5b80600160209252f35b509133036100e65760208263ffffffff68a20d6e21d0e52553085460801c168152f35b5163ce5a776b60e01b81529050fd5b92919390503303610138575061012f63ffffffff91602094351660018060a01b031660005268a20d6e21d0e5255313602052604060002090565b5460801c168152f35b5163ce5a776b60e01b81528390fd5b92919390503303610138578335826101ae610190600019640100000000851085020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b63ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5416156101cf5760209450835268a20d6e21d0e525530c8452822054168152f35b815163677510db60e11b81528590fd5b92919390503303610138578184351660243591836044351693610233610190600019640100000000871087020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b541693848103610290575b506020955082855268a20d6e21d0e525530c86528420816001600160601b0360a01b82541617905560018260081c68a20d6e21d0e525530d60601b019260ff16911515821b911b198254161790558152f35b6102b690859060285260145268a20d6e21d0e525530b6000526048600020906000602852565b54156102c2578561023e565b516367d9dca160e11b81528590fd5b92919390503303610138575061031c61019060209435600019906401000000008110020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b54168152f35b9050848433036103c3578035600019906401000000008110020160e060018060fd1b038260021c16685106b710e87292a98960611b01549160061b161c63ffffffff1693826103898663ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5416156103b657505061031c60209363ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5163677510db60e11b8152fd5b835163ce5a776b60e01b8152fd5b9291939050330361013857506020928161040d92602435169135169060285260145268a20d6e21d0e525530b6000526048600020906000602852565b548152f35b9291939050330361013857509161045483602094602435151593351690604435169060285260145268a20d6e21d0e525530b6000526048600020906000602852565b5560018152f35b91928591508433036107f65782823516908360243516926044359685606435169085156107e657156107e25760001990600196806104c7610190858d640100000000811002018b1b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b541686036107d357858203610778575b50506104e284612074565b916104ec86612074565b918154946105148760018060a01b031660005268a20d6e21d0e5255310602052604060002090565b92855460a01c9081881161076a575085546001600160a01b03199188900360a090811b83166001600160a01b0392831617885586546001600160601b038a1681831c0190911b909216911617845560209a6106fa959490936106f4938a938c91908e68a20d6e21d0e525530d60601b60088a901c015460ff8a161c8416610724575b5050875463ffffffff60801b198116608091821c63ffffffff90811684019283901b63ffffffff60801b169190911790995560e0631fffffff8260031c168560601b01549160051b161c88166106418161061485858c01811b0160e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b958b87169060e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b01811b019060e08260031c685106b710e87292a98960611b019260051b1682549182821c188816901b1890556106ef85825460801c16956106a2818d890116849081549063ffffffff60801b9060801b169063ffffffff60801b1916179055565b6001600160a01b038416600090815268a20d6e21d0e52553106020526040902060601b600388901c01805463ffffffff60058a901b60e01682811c948a16949094181690921b9091189055565b6120c9565b90612170565b84527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8585a38152f35b68a20d6e21d0e525530d60601b60088a901c018054600160ff8c161b1916905588815268a20d6e21d0e525530c6020522080546001600160a01b03191690558f8e610596565b8251631e9acf1760e31b8152fd5b61079e82879060285260145268a20d6e21d0e525530b6000526048600020906000602852565b546104d75789895268a20d6e21d0e525530c6020528489205416036107c45788806104d7565b509051632ce44b5f60e11b8152fd5b845162a1148160e81b81528490fd5b8680fd5b8351633a954ecd60e21b81528390fd5b5163ce5a776b60e01b8152fd5b3461080a57005b600080fd5b600090813560e01c90816306fdde031461125b57508063095ea7b3146111d957806318160ddd146111af57806323b872dd14611120578063274e430b146110f15780632a6a935d1461105b578063313ce5671461103f5780633ccfd60b146110095780634ef41efc14610fd857806355f804b314610e4c57806370a0823114610dfe578063715018a614610da45780638da5cb5b14610d7c57806395d89b4114610c9f578063a9059cbb14610c6e578063c87b56dd146109f8578063dd62ed3e146109a45763f2fde38b036100125791346109a05760203660031901126109a0576108f8611350565b9061090161137c565b6001600160a01b0391821692831561094e57505082546001600160a01b0319811683178455167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b5090346109f457806003193601126109f4576020906109ec6109c4611350565b6109cc611366565b60285260145268a20d6e21d0e525530f6000526048600020906000602852565b549051908152f35b5080fd5b5090346109f45760209182600319360112610c6b5783359260609360035495610a20876113d4565b610a36575b845180610a328882611324565b0390f35b9394509192839183917a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008381811015610c5e575b50506d04ee2d6d415b85acef810000000080841015610c50575b50662386f26fc1000080841015610c41575b506305f5e10080841015610c32575b5061271080841015610c24575b50506064821015610c14575b600a80921015610c0a575b60019687840192610aec610ad785611446565b94610ae48a51968761140e565b808652611446565b9589602185870197601f19809a01368a37870101905b610bdb575b5050508651958098610b18836113d4565b92818116908115610bba5750600114610b5f575b5050505085610a3296610b48610b559594879451938491611301565b010390810183528261140e565b9038808080610a25565b9091929850600382527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b838310610ba7575050508401909501948181610b48610a32610b2c565b80548884018b0152918901918101610b8a565b60ff1916898601525050508015150285010195508181610b48610a32610b2c565b600019019082906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a835304908a82610b025750610b07565b9160010191610ac4565b9190606460029104910191610ab9565b930192909104903880610aad565b60089194930492019238610aa0565b60109194930492019238610a91565b829194930492019238610a7f565b8895500492503880610a65565b80fd5b5090346109f457806003193601126109f457602090610c98610c8e611350565b6024359033611482565b5160018152f35b5090346109f457816003193601126109f45780519082600254610cc1816113d4565b80855291600191808316908115610d545750600114610cf7575b505050610ced82610a3294038361140e565b5191829182611324565b9450600285527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b828610610d3c57505050610ced826020610a329582010194610cdb565b80546020878701810191909152909501948101610d1f565b610a32975086935060209250610ced94915060ff191682840152151560051b82010194610cdb565b5090346109f457816003193601126109f457905490516001600160a01b039091168152602090f35b5034610c6b5780600319360112610c6b57610dbd61137c565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5090346109f45760203660031901126109f457602090610e41610e1f611350565b6001600160a01b0316600090815268a20d6e21d0e52553136020526040902090565b5460a01c9051908152f35b838234610c6b57602091826003193601126109f457803567ffffffffffffffff91828211610fd45736602383011215610fd4578101359182116109a05760249036828483010111610fd457610e9f61137c565b610eaa6003546113d4565b601f8111610f76575b508394601f8411600114610ef35750938394839493610ee6575b5050508160011b916000199060031b1c19161760035580f35b0101359050838080610ecd565b601f198416957fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b939186905b888210610f5c575050846001969710610f40575b50505050811b0160035580f35b60001960f88660031b161c199201013516905583808080610f33565b806001849786839596890101358155019601920190610f1f565b7fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b601f850160051c810191878610610fca575b601f0160051c01905b818110610fbf5750610eb3565b858155600101610fb2565b9091508190610fa9565b8380fd5b5090346109f457816003193601126109f45768a20d6e21d0e52553095490516001600160a01b039091168152602090f35b5082346109f457816003193601126109f45761102361137c565b8138818047335af115611034575080f35b63b12d13eb8252601cfd5b5090346109f457816003193601126109f4576020905160128152f35b5091346109a05760203660031901126109a057358015158091036109a0579160209261108633612074565b805460581c9082600283161515036110c9575b505081527fb5a1de456fff688115a4f75380060c23c8532d14ff85f687cc871456d6420393833392a25160018152f35b805460ff60581b191660ff9290921660021860581b60ff60581b169190911790553880611099565b5090346109f45760203660031901126109f457602090611117611112611350565b612038565b90519015158152f35b5034610c6b576060366003190112610c6b575061113b611350565b611143611366565b906044359361116e33839060285260145268a20d6e21d0e525530f6000526048600020906000602852565b8054909160018201611189575b602086610c98898888611482565b8187116111a157508590039055816020610c9861117b565b85516313be252b60e01b8152fd5b5090346109f457816003193601126109f45760209068a20d6e21d0e52553085460a01c9051908152f35b5090346109f457806003193601126109f4576020916111f6611350565b6024358061122083339060285260145268a20d6e21d0e525530f6000526048600020906000602852565b5582526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925908590a35160018152f35b905082346109a057826003193601126109a05782600180549161127d836113d4565b80865292828116908115610d5457506001146112a557505050610ced82610a3294038361140e565b94508085527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8286106112e957505050610ced826020610a329582010194610cdb565b805460208787018101919091529095019481016112cc565b60005b8381106113145750506000910152565b8181015183820152602001611304565b604091602082526113448151809281602086015260208686019101611301565b601f01601f1916010190565b600435906001600160a01b038216820361080a57565b602435906001600160a01b038216820361080a57565b6000546001600160a01b0316330361139057565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b90600182811c92168015611404575b60208310146113ee57565b634e487b7160e01b600052602260045260246000fd5b91607f16916113e3565b90601f8019910116810190811067ffffffffffffffff82111761143057604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161143057601f01601f191660200190565b811561146c570490565b634e487b7160e01b600052601260045260246000fd5b6001600160a01b038216156120265761149a81612074565b6114a383612074565b68a20d6e21d0e5255309549095906001600160a01b03161561080a57604051926101a0840184811067ffffffffffffffff82111761143057604052600084526000602085015260006060850152600060e085015260006101008501526000610120850152600061014085015260006101608501526000610180850152825463ffffffff8160801c16608086015263ffffffff885460801c1660a086015268a20d6e21d0e52553085460a01c60c086015260a01c8060408601528611612014576040840180518790039081905283546001600160a01b031960a083811b82166001600160a01b039384161787558a5480821c8b0160608a0181905290911b909116911617885560808501516115ba6004548093611462565b808203911102908186526002895460581c1615611fc9575b505060808401518451602086015180821882821002821880841890841102808418989391929114611fbb57879003865286900360208601526001600160a01b0382811690821614611fa4576040519687608081011067ffffffffffffffff60808a011117611430576080880160409081526000808a526020808b01828152838c018381526060808e0190815285518d815260058e901b81018501875290819052908790529087905281018b526001600160a01b03808716835268a20d6e21d0e525531090915282822090851682529190209990959063ffffffff6116b685836120c9565b1661014089015260a088015198878c8a8c60015b156117e0575b63ffffffff60018161014061174a9561173560009960e0600019608085015101918260808601528260031c9060601b01549160051b161c98878a86169160e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b015116929f019e16908363ffffffff16612170565b60208d518263ffffffff168152018d5262ffffff8160081c1668a20d6e21d0e525530d60601b015460ff82161c60011661178a575b508c8a8c8b936116ca565b68a20d6e21d0e525530d60601b62ffffff600883901c16018054600160ff84161b1916905563ffffffff1660005268a20d6e21d0e525530c60205260406000206001600160601b0360a01b81541690553861177f565b505050506000190180156117f757878c8a8c6116d0565b5060a08801899052805463ffffffff60801b191660809990991b63ffffffff60801b16989098178855939850919690959194929350909190608082810151855463ffffffff60801b1916911b63ffffffff60801b1617845560016020818060a01b0368a20d6e21d0e5255309541692606081015193845160051b608401906000607f19870196879463144027d3865280870151906040015190605f19830152603f198201526060601f1982015260631901915af1915114161561080a575b68a20d6e21d0e525530854926020820151825194858263ffffffff8360801c1601038060e086015263ffffffff60801b8160801b1663ffffffff60801b1983161768a20d6e21d0e5255308556040519687606081011067ffffffffffffffff60608a01111761143057602063ffffffff9460608a0160405260008a526000828b0152606060408b01526040519281810184520160051b82010160405280886040015260200187528260801b9060801b16908260801b19161760601c166101808301528151611e16575b506020810151611a24575b5050604001518051806119d6575b505060009081526001600160a01b0391821692909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602090a3565b6020600191600093838060a01b0368a20d6e21d0e52553095416603f19820195869363263c69d6855285601f1985015260051b6044019260231901915af1915114161561080a573880611997565b91939092958160601b6020860152611a568260018060a01b031660005268a20d6e21d0e5255310602052604060002090565b9563ffffffff611a6684876120c9565b16610140850152611a7e60c085015160045490611462565b68a20d6e21d0e525530854602090811c63ffffffff1682811180159091021761016087015260a08601519086015181016101208701819052875463ffffffff60801b191660809190911b63ffffffff60801b16179096559263ffffffff68a20d6e21d0e52553085460401c169860015b15611dac575b61018086015160009063ffffffff8c8116911614611bd557611bd063ffffffff60018d01169b60e0631fffffff8260031c1668a20d6e21d0e525531160601b01549160051b161c63ffffffff165b8060081c685106b710e87292a98760611b0160018260ff161b8019825416179055611b988c8b63ffffffff84169160e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b611bb963ffffffff6101408b01511663ffffffff60018d019c169083612170565b8a9060209082519060081b82840151178152019052565b611aee565b949899939291906101608701515b63ffffffff611c17600019830160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b1615611d8857600019906001810160081c685106b710e87292a98760611b018054196001830160ff1690811c901b8015611d03575b80611c62575b5050508a81119081150217611be3565b600180939450811901167e1f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405601f826fffffffffffffffffffffffffffffffff1060071b83811c67ffffffffffffffff1060061b1783811c63ffffffff1060051b1792831c63d76453e004161a179074a20d6e21d0e525530dffffffffffffffffffffffff190160081b179101811060018c018210151760000317388080611c52565b506001909d999a9794919b9895929d9693965b01805419685106b710e87292a98760611b60018f0160081c0182118117611d405750600190611d16565b809a9e9396999c9295989b9a8e9895986001810160081c685106b710e87292a98760611b018411611d73575b5050611c4c565b60019150011960ff1690811b901c808e611d6c565b611bd0909b9a9691929394959b6001810188811190811502176101608a0152611b42565b6101208601518703611af45795509592509550956040926bffffffff000000000000000067ffffffff0000000061016068a20d6e21d0e52553085493015160201b1692851b16906bffffffffffffffff000000001916171768a20d6e21d0e5255308559038611989565b949160018760609996939895991b176020890152611e4e8460018060a01b031660005268a20d6e21d0e5255310602052604060002090565b608080890151895181036101008b01819052895463ffffffff60801b1916921b63ffffffff60801b16919091179097559660015b15611f89575b60009660001901968760031c8960601b015460e08960051b161c8063ffffffff169060001982018060021c685106b710e87292a98960611b019060c082549160061b1681811c67ffffffffffffffff16901b189055611ef8828d9060209082519060081b82840151178152019052565b62ffffff8160081c1660ff81685106b710e87292a98760611b019216916001831b19815416905568a20d6e21d0e525530d60601b0154901c600116611f3e575b50611e82565b68a20d6e21d0e525530d60601b600882901c018054600160ff84161b1916905560005268a20d6e21d0e525530c60205260406000206001600160601b0360a01b815416905538611f38565b6101008101518703611e88579194979396509194503861197e565b9460a08592979598939801510160a08201526118b5565b5050945094929590956118b5565b611fec916001600160a01b0384811690891614612003575b506060860151611462565b60a0850151808203911102602085015238806115d2565b60808701510360a087015238611fe1565b604051631e9acf1760e31b8152600490fd5b604051633a954ecd60e21b8152600490fd5b6001600160a01b038116600090815268a20d6e21d0e5255313602052604090205460581c600181161561206f576002915016151590565b503b90565b6001600160a01b038116600090815268a20d6e21d0e525531360205260409020909190916001835460581c16156120a85750565b825460ff60581b1916903b1515600190811b1760581b60ff60581b16178255565b91909163ffffffff9081815460601c169384156120e557505050565b68a20d6e21d0e5255308805463ffffffff198116908516600101948516908117909155825463ffffffff60601b191660609490941b63ffffffff60601b169390931790915563ffffffff8216600090815268a20d6e21d0e525530a60205260409020919350839180546001600160a01b0319166001600160a01b039092169190911790551561080a57565b60001901908160021c685106b710e87292a98960611b019260c084549360061b169163ffffffff169060201b1782821c1867ffffffffffffffff16901b18905556fea26469706673582212200863fc3b72979f2c50b42a603f17d1505f071fa61346362c80a07a5df8ef689864736f6c6343000813003360803461007b57601f610c8438819003918201601f19168301916001600160401b038311848410176100805780849260209460405283398101031261007b57516001600160a01b0381169081900361007b57683602298b8c10b0123180546001600160a01b0319169091179055604051610bed90816100978239f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040818152600491823610156101eb575b5036156101df576000803560e01c63263c69d681146101505763144027d381146100c957630f4599e51461004e575051631e085ca760e11b8152fd5b683602298b8c10b01231549091906001600160a01b03908116806100aa575b50683602298b8c10b0123091825491821661009b57506001600160a01b031916331790556001815260209150f35b51635fb2b52360e11b81528490fd5b81853516036100b9573861006d565b81516362cf623d60e11b81528490fd5b50683602298b8c10b01230549091906001600160a01b03163303610141575081356024359060246044358082019581013560051b0101935b8481036101115760208460018152f35b803583837fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8780a4602001610101565b51631b1e598960e11b81529050fd5b50683602298b8c10b01230549091906001600160a01b031633036101415750602482358082019381013560051b0101915b8281036101915760208260018152f35b80358060601c6affffffffffffffffffffff826001169260081c16918015820291027fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8580a4602001610181565b346101e657005b600080fd5b600090813560e01c90816301ffc9a71461097a5750806306fdde0314610916578063081812fc146108c4578063095ea7b31461084357806318160ddd146107fb57806323b872dd146107e5578063243598791461079357806342842e0e1461072c5780636352211e146106da5780636cef16e61461063057806370a08231146105d75780638da5cb5b146105a657806395d89b411461054257806397e5311c14610514578063a22cb46514610478578063b88d4fde146103a0578063c87b56dd1461032c5763e985e9c50361001257346103295781600319360112610329576102d2610a0e565b916020826044601c6102e2610a24565b966102eb610af3565b865163e985e9c586526001600160a01b0392831687529890911686525afa601f3d111615610320578290525115158152602090f35b503d90823e3d90fd5b80fd5b5082903461032957602090816003193601126103295780806024601c610350610af3565b88519763c87b56dd85523587525afa15610397578181803e818151843e8251828251018385013e8251830191820152828101809352610392603f1992846109c5565b030190f35b3d9150823e3d90fd5b50906080366003190112610474576103b6610a0e565b6103be610a24565b6044359167ffffffffffffffff606435818111610470573660238201121561047057808801359180831161046c57366024848401011161046c57610403868686610a6f565b843b61040d578780f35b865196601f8401601f19908116603f011688019182118883101761045957889950926024602093829361044d9b9652828a52018389013786010152610b22565b80388080808080808780f35b634e487b7160e01b895260418a52602489fd5b8780fd5b8680fd5b5080fd5b509034610474578060031936011261047457610492610a0e565b90602435801515809103610510576020846064601c826104b0610af3565b875163813500fc83526001600160a01b03909916808752968852336060529597955af16001855114161561050857507f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b3d84823e3d90fd5b8380fd5b509034610474578160031936011261047457602090610531610af3565b90516001600160a01b039091168152f35b503461032957806003193601126103295761055b610af3565b8251916395d89b41815280806024601c6020958387525afa15610397578181803e818151843e8251828251018385013e8251830191820152828101809352610392603f1992846109c5565b509034610474578160031936011261047457683602298b8c10b012325490516001600160a01b039091168152602090f35b5034610329576020366003190112610329576001600160a01b036105f9610a0e565b16916020826044601c61060a610af3565b85519763f5b100ea855285528386525afa601f3d11161561032057829052518152602090f35b5091346106d657826003193601126106d657916020818194601c610652610af3565b638da5cb5b84525afa601f3d1116600c5160601c02683602298b8c10b012329182549060018060a01b03808316931693848403610693575b86865160018152f35b847f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0936bffffffffffffffffffffffff60a01b1617905580a3388080808061068a565b8280fd5b509034610474576020366003190112610474576020826044601c6106fc610af3565b855197636352211e85523585528386525afa601f3d11161561032057829052516001600160a01b03168152602090f35b509061073736610a3a565b91610743838383610a6f565b813b61074d578480f35b835193602085019085821067ffffffffffffffff8311176107805761077796975052858452610b22565b80388080808480f35b634e487b7160e01b875260418852602487fd5b509034610474576020366003190112610474576020826044601c6107b5610af3565b855197632435987985523585528386525afa601f3d11161561032057829052516001600160a01b03168152602090f35b506107f86107f236610a3a565b91610a6f565b80f35b5034610329578060031936011261032957610814610af3565b916020826044601c84519663e2c7928184528385528386525afa601f3d11161561032057829052518152602090f35b50908060031936011261047457610858610a0e565b602435916020846064601c61086b610af3565b9560018060a01b0316958786519663d10b6e0c8652888752523360605234905af1601f3d1116156105085750600c5160601c7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258480a480f35b509034610474576020366003190112610474576020826044601c6108e6610af3565b85519763081812fc85523585528386525afa601f3d11161561032057829052516001600160a01b03168152602090f35b503461032957806003193601126103295761092f610af3565b8251916306fdde03815280806024601c6020958387525afa15610397578181803e818151843e8251828251018385013e8251830191820152828101809352610392603f1992846109c5565b905083346106d65760203660031901126106d657356001600160e01b0319811681036106d6576020925060e01c635b5e139f8114906301ffc9a76380ac58cd82149114171715158152f35b6020808252825181830181905290939260005b8281106109fa57505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016109d8565b600435906001600160a01b03821682036101e657565b602435906001600160a01b03821682036101e657565b60609060031901126101e6576001600160a01b039060043582811681036101e6579160243590811681036101e6579060443590565b9060846020610a7c610af3565b9360018060a01b0380911693169360405192839163e5eb36c883528584840152866040840152876060840152336080840152601c83019034905af160018251141615610aea57507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a4565b3d6000823e3d90fd5b683602298b8c10b01230546001600160a01b0316908115610b1057565b604051632d9523d760e11b8152600490fd5b9060a46020939460405195869463150b7a028652338787015260018060a01b03166040860152606085015260808085015280518091818060a0880152610ba3575b505001906000601c8401915af115610b94575b5163757a42ff60e11b01610b8657565b63d1a57ed66000526004601cfd5b3d15610b76573d6000823e3d90fd5b818760c08801920160045afa508038610b6356fea264697066735822122024040581c6989aa449b6f61b1ecb0a179df3ea10d2cc4950abe6774fbc9bb18264736f6c63430008130033405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5aceb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf600000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000088e16a09fa0554000000000000000000000000000000000000000000000014e2e53e25b67021400000000000000000000000000000047ee841ae2bd1b1d2d3f5bef15aa0bd7af30b8ee000000000000000000000000000000000000000000000000000000000000000e50414745204e4f5420464f554e4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033430340000000000000000000000000000000000000000000000000000000000
Deployed ByteCode
0x608060408181526004918236101561080f575b5036156108035768a20d6e21d0e5255309546001600160a01b039081169190600090813560e01c9063e5eb36c8821461045b5763813500fc82146104125763e985e9c582146103d157636352211e821461032257632435987982146102d15763d10b6e0c82146101df5763081812fc82146101475763f5b100ea82146100f5575063e2c7928181146100c35763b7a94eb891929350146100ba575051631e085ca760e11b8152fd5b80600160209252f35b509133036100e65760208263ffffffff68a20d6e21d0e52553085460801c168152f35b5163ce5a776b60e01b81529050fd5b92919390503303610138575061012f63ffffffff91602094351660018060a01b031660005268a20d6e21d0e5255313602052604060002090565b5460801c168152f35b5163ce5a776b60e01b81528390fd5b92919390503303610138578335826101ae610190600019640100000000851085020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b63ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5416156101cf5760209450835268a20d6e21d0e525530c8452822054168152f35b815163677510db60e11b81528590fd5b92919390503303610138578184351660243591836044351693610233610190600019640100000000871087020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b541693848103610290575b506020955082855268a20d6e21d0e525530c86528420816001600160601b0360a01b82541617905560018260081c68a20d6e21d0e525530d60601b019260ff16911515821b911b198254161790558152f35b6102b690859060285260145268a20d6e21d0e525530b6000526048600020906000602852565b54156102c2578561023e565b516367d9dca160e11b81528590fd5b92919390503303610138575061031c61019060209435600019906401000000008110020160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b54168152f35b9050848433036103c3578035600019906401000000008110020160e060018060fd1b038260021c16685106b710e87292a98960611b01549160061b161c63ffffffff1693826103898663ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5416156103b657505061031c60209363ffffffff1660005268a20d6e21d0e525530a602052604060002090565b5163677510db60e11b8152fd5b835163ce5a776b60e01b8152fd5b9291939050330361013857506020928161040d92602435169135169060285260145268a20d6e21d0e525530b6000526048600020906000602852565b548152f35b9291939050330361013857509161045483602094602435151593351690604435169060285260145268a20d6e21d0e525530b6000526048600020906000602852565b5560018152f35b91928591508433036107f65782823516908360243516926044359685606435169085156107e657156107e25760001990600196806104c7610190858d640100000000811002018b1b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b541686036107d357858203610778575b50506104e284612074565b916104ec86612074565b918154946105148760018060a01b031660005268a20d6e21d0e5255310602052604060002090565b92855460a01c9081881161076a575085546001600160a01b03199188900360a090811b83166001600160a01b0392831617885586546001600160601b038a1681831c0190911b909216911617845560209a6106fa959490936106f4938a938c91908e68a20d6e21d0e525530d60601b60088a901c015460ff8a161c8416610724575b5050875463ffffffff60801b198116608091821c63ffffffff90811684019283901b63ffffffff60801b169190911790995560e0631fffffff8260031c168560601b01549160051b161c88166106418161061485858c01811b0160e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b958b87169060e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b01811b019060e08260031c685106b710e87292a98960611b019260051b1682549182821c188816901b1890556106ef85825460801c16956106a2818d890116849081549063ffffffff60801b9060801b169063ffffffff60801b1916179055565b6001600160a01b038416600090815268a20d6e21d0e52553106020526040902060601b600388901c01805463ffffffff60058a901b60e01682811c948a16949094181690921b9091189055565b6120c9565b90612170565b84527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8585a38152f35b68a20d6e21d0e525530d60601b60088a901c018054600160ff8c161b1916905588815268a20d6e21d0e525530c6020522080546001600160a01b03191690558f8e610596565b8251631e9acf1760e31b8152fd5b61079e82879060285260145268a20d6e21d0e525530b6000526048600020906000602852565b546104d75789895268a20d6e21d0e525530c6020528489205416036107c45788806104d7565b509051632ce44b5f60e11b8152fd5b845162a1148160e81b81528490fd5b8680fd5b8351633a954ecd60e21b81528390fd5b5163ce5a776b60e01b8152fd5b3461080a57005b600080fd5b600090813560e01c90816306fdde031461125b57508063095ea7b3146111d957806318160ddd146111af57806323b872dd14611120578063274e430b146110f15780632a6a935d1461105b578063313ce5671461103f5780633ccfd60b146110095780634ef41efc14610fd857806355f804b314610e4c57806370a0823114610dfe578063715018a614610da45780638da5cb5b14610d7c57806395d89b4114610c9f578063a9059cbb14610c6e578063c87b56dd146109f8578063dd62ed3e146109a45763f2fde38b036100125791346109a05760203660031901126109a0576108f8611350565b9061090161137c565b6001600160a01b0391821692831561094e57505082546001600160a01b0319811683178455167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b5090346109f457806003193601126109f4576020906109ec6109c4611350565b6109cc611366565b60285260145268a20d6e21d0e525530f6000526048600020906000602852565b549051908152f35b5080fd5b5090346109f45760209182600319360112610c6b5783359260609360035495610a20876113d4565b610a36575b845180610a328882611324565b0390f35b9394509192839183917a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008381811015610c5e575b50506d04ee2d6d415b85acef810000000080841015610c50575b50662386f26fc1000080841015610c41575b506305f5e10080841015610c32575b5061271080841015610c24575b50506064821015610c14575b600a80921015610c0a575b60019687840192610aec610ad785611446565b94610ae48a51968761140e565b808652611446565b9589602185870197601f19809a01368a37870101905b610bdb575b5050508651958098610b18836113d4565b92818116908115610bba5750600114610b5f575b5050505085610a3296610b48610b559594879451938491611301565b010390810183528261140e565b9038808080610a25565b9091929850600382527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b838310610ba7575050508401909501948181610b48610a32610b2c565b80548884018b0152918901918101610b8a565b60ff1916898601525050508015150285010195508181610b48610a32610b2c565b600019019082906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a835304908a82610b025750610b07565b9160010191610ac4565b9190606460029104910191610ab9565b930192909104903880610aad565b60089194930492019238610aa0565b60109194930492019238610a91565b829194930492019238610a7f565b8895500492503880610a65565b80fd5b5090346109f457806003193601126109f457602090610c98610c8e611350565b6024359033611482565b5160018152f35b5090346109f457816003193601126109f45780519082600254610cc1816113d4565b80855291600191808316908115610d545750600114610cf7575b505050610ced82610a3294038361140e565b5191829182611324565b9450600285527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b828610610d3c57505050610ced826020610a329582010194610cdb565b80546020878701810191909152909501948101610d1f565b610a32975086935060209250610ced94915060ff191682840152151560051b82010194610cdb565b5090346109f457816003193601126109f457905490516001600160a01b039091168152602090f35b5034610c6b5780600319360112610c6b57610dbd61137c565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5090346109f45760203660031901126109f457602090610e41610e1f611350565b6001600160a01b0316600090815268a20d6e21d0e52553136020526040902090565b5460a01c9051908152f35b838234610c6b57602091826003193601126109f457803567ffffffffffffffff91828211610fd45736602383011215610fd4578101359182116109a05760249036828483010111610fd457610e9f61137c565b610eaa6003546113d4565b601f8111610f76575b508394601f8411600114610ef35750938394839493610ee6575b5050508160011b916000199060031b1c19161760035580f35b0101359050838080610ecd565b601f198416957fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b939186905b888210610f5c575050846001969710610f40575b50505050811b0160035580f35b60001960f88660031b161c199201013516905583808080610f33565b806001849786839596890101358155019601920190610f1f565b7fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b601f850160051c810191878610610fca575b601f0160051c01905b818110610fbf5750610eb3565b858155600101610fb2565b9091508190610fa9565b8380fd5b5090346109f457816003193601126109f45768a20d6e21d0e52553095490516001600160a01b039091168152602090f35b5082346109f457816003193601126109f45761102361137c565b8138818047335af115611034575080f35b63b12d13eb8252601cfd5b5090346109f457816003193601126109f4576020905160128152f35b5091346109a05760203660031901126109a057358015158091036109a0579160209261108633612074565b805460581c9082600283161515036110c9575b505081527fb5a1de456fff688115a4f75380060c23c8532d14ff85f687cc871456d6420393833392a25160018152f35b805460ff60581b191660ff9290921660021860581b60ff60581b169190911790553880611099565b5090346109f45760203660031901126109f457602090611117611112611350565b612038565b90519015158152f35b5034610c6b576060366003190112610c6b575061113b611350565b611143611366565b906044359361116e33839060285260145268a20d6e21d0e525530f6000526048600020906000602852565b8054909160018201611189575b602086610c98898888611482565b8187116111a157508590039055816020610c9861117b565b85516313be252b60e01b8152fd5b5090346109f457816003193601126109f45760209068a20d6e21d0e52553085460a01c9051908152f35b5090346109f457806003193601126109f4576020916111f6611350565b6024358061122083339060285260145268a20d6e21d0e525530f6000526048600020906000602852565b5582526001600160a01b03169033907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925908590a35160018152f35b905082346109a057826003193601126109a05782600180549161127d836113d4565b80865292828116908115610d5457506001146112a557505050610ced82610a3294038361140e565b94508085527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8286106112e957505050610ced826020610a329582010194610cdb565b805460208787018101919091529095019481016112cc565b60005b8381106113145750506000910152565b8181015183820152602001611304565b604091602082526113448151809281602086015260208686019101611301565b601f01601f1916010190565b600435906001600160a01b038216820361080a57565b602435906001600160a01b038216820361080a57565b6000546001600160a01b0316330361139057565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b90600182811c92168015611404575b60208310146113ee57565b634e487b7160e01b600052602260045260246000fd5b91607f16916113e3565b90601f8019910116810190811067ffffffffffffffff82111761143057604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161143057601f01601f191660200190565b811561146c570490565b634e487b7160e01b600052601260045260246000fd5b6001600160a01b038216156120265761149a81612074565b6114a383612074565b68a20d6e21d0e5255309549095906001600160a01b03161561080a57604051926101a0840184811067ffffffffffffffff82111761143057604052600084526000602085015260006060850152600060e085015260006101008501526000610120850152600061014085015260006101608501526000610180850152825463ffffffff8160801c16608086015263ffffffff885460801c1660a086015268a20d6e21d0e52553085460a01c60c086015260a01c8060408601528611612014576040840180518790039081905283546001600160a01b031960a083811b82166001600160a01b039384161787558a5480821c8b0160608a0181905290911b909116911617885560808501516115ba6004548093611462565b808203911102908186526002895460581c1615611fc9575b505060808401518451602086015180821882821002821880841890841102808418989391929114611fbb57879003865286900360208601526001600160a01b0382811690821614611fa4576040519687608081011067ffffffffffffffff60808a011117611430576080880160409081526000808a526020808b01828152838c018381526060808e0190815285518d815260058e901b81018501875290819052908790529087905281018b526001600160a01b03808716835268a20d6e21d0e525531090915282822090851682529190209990959063ffffffff6116b685836120c9565b1661014089015260a088015198878c8a8c60015b156117e0575b63ffffffff60018161014061174a9561173560009960e0600019608085015101918260808601528260031c9060601b01549160051b161c98878a86169160e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b015116929f019e16908363ffffffff16612170565b60208d518263ffffffff168152018d5262ffffff8160081c1668a20d6e21d0e525530d60601b015460ff82161c60011661178a575b508c8a8c8b936116ca565b68a20d6e21d0e525530d60601b62ffffff600883901c16018054600160ff84161b1916905563ffffffff1660005268a20d6e21d0e525530c60205260406000206001600160601b0360a01b81541690553861177f565b505050506000190180156117f757878c8a8c6116d0565b5060a08801899052805463ffffffff60801b191660809990991b63ffffffff60801b16989098178855939850919690959194929350909190608082810151855463ffffffff60801b1916911b63ffffffff60801b1617845560016020818060a01b0368a20d6e21d0e5255309541692606081015193845160051b608401906000607f19870196879463144027d3865280870151906040015190605f19830152603f198201526060601f1982015260631901915af1915114161561080a575b68a20d6e21d0e525530854926020820151825194858263ffffffff8360801c1601038060e086015263ffffffff60801b8160801b1663ffffffff60801b1983161768a20d6e21d0e5255308556040519687606081011067ffffffffffffffff60608a01111761143057602063ffffffff9460608a0160405260008a526000828b0152606060408b01526040519281810184520160051b82010160405280886040015260200187528260801b9060801b16908260801b19161760601c166101808301528151611e16575b506020810151611a24575b5050604001518051806119d6575b505060009081526001600160a01b0391821692909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602090a3565b6020600191600093838060a01b0368a20d6e21d0e52553095416603f19820195869363263c69d6855285601f1985015260051b6044019260231901915af1915114161561080a573880611997565b91939092958160601b6020860152611a568260018060a01b031660005268a20d6e21d0e5255310602052604060002090565b9563ffffffff611a6684876120c9565b16610140850152611a7e60c085015160045490611462565b68a20d6e21d0e525530854602090811c63ffffffff1682811180159091021761016087015260a08601519086015181016101208701819052875463ffffffff60801b191660809190911b63ffffffff60801b16179096559263ffffffff68a20d6e21d0e52553085460401c169860015b15611dac575b61018086015160009063ffffffff8c8116911614611bd557611bd063ffffffff60018d01169b60e0631fffffff8260031c1668a20d6e21d0e525531160601b01549160051b161c63ffffffff165b8060081c685106b710e87292a98760611b0160018260ff161b8019825416179055611b988c8b63ffffffff84169160e0909291928360031c9060601b019260051b1682549182821c1863ffffffff16901b189055565b611bb963ffffffff6101408b01511663ffffffff60018d019c169083612170565b8a9060209082519060081b82840151178152019052565b611aee565b949899939291906101608701515b63ffffffff611c17600019830160011b60e08160031c685106b710e87292a98960611b01549160051b161c63ffffffff1690565b1615611d8857600019906001810160081c685106b710e87292a98760611b018054196001830160ff1690811c901b8015611d03575b80611c62575b5050508a81119081150217611be3565b600180939450811901167e1f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405601f826fffffffffffffffffffffffffffffffff1060071b83811c67ffffffffffffffff1060061b1783811c63ffffffff1060051b1792831c63d76453e004161a179074a20d6e21d0e525530dffffffffffffffffffffffff190160081b179101811060018c018210151760000317388080611c52565b506001909d999a9794919b9895929d9693965b01805419685106b710e87292a98760611b60018f0160081c0182118117611d405750600190611d16565b809a9e9396999c9295989b9a8e9895986001810160081c685106b710e87292a98760611b018411611d73575b5050611c4c565b60019150011960ff1690811b901c808e611d6c565b611bd0909b9a9691929394959b6001810188811190811502176101608a0152611b42565b6101208601518703611af45795509592509550956040926bffffffff000000000000000067ffffffff0000000061016068a20d6e21d0e52553085493015160201b1692851b16906bffffffffffffffff000000001916171768a20d6e21d0e5255308559038611989565b949160018760609996939895991b176020890152611e4e8460018060a01b031660005268a20d6e21d0e5255310602052604060002090565b608080890151895181036101008b01819052895463ffffffff60801b1916921b63ffffffff60801b16919091179097559660015b15611f89575b60009660001901968760031c8960601b015460e08960051b161c8063ffffffff169060001982018060021c685106b710e87292a98960611b019060c082549160061b1681811c67ffffffffffffffff16901b189055611ef8828d9060209082519060081b82840151178152019052565b62ffffff8160081c1660ff81685106b710e87292a98760611b019216916001831b19815416905568a20d6e21d0e525530d60601b0154901c600116611f3e575b50611e82565b68a20d6e21d0e525530d60601b600882901c018054600160ff84161b1916905560005268a20d6e21d0e525530c60205260406000206001600160601b0360a01b815416905538611f38565b6101008101518703611e88579194979396509194503861197e565b9460a08592979598939801510160a08201526118b5565b5050945094929590956118b5565b611fec916001600160a01b0384811690891614612003575b506060860151611462565b60a0850151808203911102602085015238806115d2565b60808701510360a087015238611fe1565b604051631e9acf1760e31b8152600490fd5b604051633a954ecd60e21b8152600490fd5b6001600160a01b038116600090815268a20d6e21d0e5255313602052604090205460581c600181161561206f576002915016151590565b503b90565b6001600160a01b038116600090815268a20d6e21d0e525531360205260409020909190916001835460581c16156120a85750565b825460ff60581b1916903b1515600190811b1760581b60ff60581b16178255565b91909163ffffffff9081815460601c169384156120e557505050565b68a20d6e21d0e5255308805463ffffffff198116908516600101948516908117909155825463ffffffff60601b191660609490941b63ffffffff60601b169390931790915563ffffffff8216600090815268a20d6e21d0e525530a60205260409020919350839180546001600160a01b0319166001600160a01b039092169190911790551561080a57565b60001901908160021c685106b710e87292a98960611b019260c084549360061b169163ffffffff169060201b1782821c1867ffffffffffffffff16901b18905556fea26469706673582212200863fc3b72979f2c50b42a603f17d1505f071fa61346362c80a07a5df8ef689864736f6c63430008130033