ERC-721
Overview
Max Total Supply
6,000 AMFD
Holders
383
Market
Volume (24H)
N/A
Min Price (24H)
N/A
Max Price (24H)
N/A
Other Info
Token Contract
Balance
15 AMFDLoading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Name:
Clifford
Compiler Version
v0.8.16+commit.07a7930e
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "@openzeppelin/contracts/access/Ownable.sol"; import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol"; import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; import "ERC721A/ERC721A.sol"; import "./Metadata.sol"; import "solady/utils/LibBitmap.sol"; interface ICypher { function ownerOf(uint) external view returns (address); } /// @notice Main Contract for the Machine For Dying NFT collection. /// @author Zac Williams (https://twitter.com/ZacW369) /// @author Anomalous Materials (https://twitter.com/AnomalousMatter) contract Clifford is ERC721A, Ownable, VRFConsumerBaseV2 { address private constant vrfCoordinator = 0x271682DEB8C4E0901D1a1550aD2e64D568E69909; VRFCoordinatorV2Interface constant COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator); LinkTokenInterface constant LINKTOKEN = LinkTokenInterface(0x514910771AF9Ca656af840dff83E8264EcF986CA); // CUSTOM ERRORS error InvalidTokenId(uint tokenId); error SeedNotSet(uint genId); error TransferFailed(); error NotOwnerOfCypher(uint tokenId); error CypherAlreadyClaimed(uint tokenId); error CypherClaimNotActive(); error CannotBidZero(); error IncorrectBidIncrement(uint amount); error AuctionNotActive(); error BidTooSmall(uint amount); error AuctionAlreadyStarted(); error CypherClaimNotStarted(); error CypherClaimNotEnded(); error AuctionNotOver(); error NftsNotAllMinted(); error TransferNotSuccessful(address to); error NoBidToClaim(address to); error TooManyRequested(); // EVENTS // emit genId and seed when random number is generated event RandomNumberGenerated(uint256 genId, uint256 seed); // emit genId when reveal is called event RandomnessRequested(uint256 genId); // emit bidder's address and amount bid event UserPlacesBid(address user, uint amount); // MAPPINGS // requestId => genId mapping(uint256 => uint256) private requestIdToGenId; // genId => seed mapping(uint256 => uint256) private genSeed; // genId => tokenId mapping(uint256 => uint256) private genIdToTokenId; // bidder => total amount bidded mapping(address => uint) private allBids; // CONSTANTS uint256 public constant MAX_SUPPLY = 6_000; // The gas lane to use, which specifies the maximum gas price to bump to. bytes32 private constant keyHash = 0xff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92; uint32 private constant callbackGasLimit = 100_000; uint16 private constant requestConfirmations = 3; // Number of random values to request uint32 private constant numWords = 1; // Subscription Id set during deployment uint64 public constant s_subscriptionId = 747; // Auction Settings uint private constant BID_INCREMENT = 0.01 ether; uint private constant AUCTION_LENGTH = 1 weeks; // Time after auction ends that users can claim their nfts and refunds // Also the time cypher holders have to claim their NFT uint private constant CLAIM_PERIOD = 1 weeks; uint private constant BID_EXTENSION_LENGTH = 15 minutes; uint private constant BID_INCREASE_PERCENT = 10; ICypher internal constant CYPHER_CONTRACT = ICypher(0xdDA32aabBBB6c44eFC567baC5F7C35f185338456); // current genId for minting uint private currentGen; uint private numOfCyphersClaimed; // Cypher claims equivalent to mapping(uint => bool) private cypherClaims; LibBitmap.Bitmap private cypherClaims; // Auction Info uint private startedAt; uint private endAt; uint private sumOfAllBids; address[] private allBidders; Metadata private immutable _metadata; constructor(Metadata metadata) ERC721A("AMachineForDying", "AMFD") VRFConsumerBaseV2(vrfCoordinator) { _metadata = metadata; } /** * @dev Reveals all minted tokens that have not been revealed yet. */ function reveal() external onlyOwner { // Assumes the subscription is funded sufficiently. uint gen = currentGen; genIdToTokenId[gen] = totalSupply(); currentGen++; // Will revert if subscription is not set and funded. uint256 s_requestId = COORDINATOR.requestRandomWords( keyHash, s_subscriptionId, requestConfirmations, callbackGasLimit, numWords ); requestIdToGenId[s_requestId] = gen; emit RandomnessRequested(gen); } /** * @dev Callback function used by VRF Coordinator. * @param requestId The request Id used to get the random number. * @param randomWords The random words generated by the VRF Coordinator. */ function fulfillRandomWords( uint256 requestId, /* requestId */ uint256[] memory randomWords ) internal override { uint256 randomness = randomWords[0]; uint256 genId = requestIdToGenId[requestId]; delete requestIdToGenId[genId]; genSeed[genId] = randomness; emit RandomNumberGenerated(genId, randomness); } // Step 1 - Cypher Claim /** * @dev Start the cypher claim period. */ function startCypherClaimPeriod() external onlyOwner { // Auction settings startedAt = block.timestamp + CLAIM_PERIOD; endAt = block.timestamp + CLAIM_PERIOD + AUCTION_LENGTH; } /** * @dev Validate that the cypher can be claimed and that the sender owns the cypher. * @param tokenId The tokenId to validate. */ function _validateCypherClaim(uint tokenId) internal { // Check sender owns the cypher they are claiming for if (msg.sender != CYPHER_CONTRACT.ownerOf(tokenId)) revert NotOwnerOfCypher(tokenId); // check the cypher has not already been claimed if (LibBitmap.get(cypherClaims, tokenId)) revert CypherAlreadyClaimed(tokenId); // set claimed for this cypher to be true LibBitmap.set(cypherClaims, tokenId); } /** * @dev Claim a free NFT for each cypher you own. * @param tokenIds The tokenIds to claim for. */ function claimCyphers(uint[] memory tokenIds) external { // will revert if the claim period hasn't started or if the auction has started if (block.timestamp >= startedAt) revert CypherClaimNotActive(); uint numOfCyphers = tokenIds.length; numOfCyphersClaimed += numOfCyphers; for (uint i = 0; i < numOfCyphers;) { _validateCypherClaim(tokenIds[i]); unchecked { ++i; } } _mint(msg.sender, numOfCyphers); } // Step 2 - Auction /** * @dev User places a bid in the auction in the form of ETH. */ function placeBid() external payable { // Check the auction has started and hasn't ended if (block.timestamp >= endAt || block.timestamp < startedAt) revert AuctionNotActive(); uint bidAmount = msg.value; // msg.value cannot be zero if (bidAmount == 0) revert CannotBidZero(); // Check the bid increment is correct if (bidAmount % BID_INCREMENT != 0) revert IncorrectBidIncrement(bidAmount); uint totalBidsFromBidder = bidAmount + allBids[msg.sender]; // Check the bid is large enough to recieve at least 1 NFT at the current price if (totalBidsFromBidder < getMinimumBid()) revert BidTooSmall(bidAmount); // reset the timer to 15mins if less than 15mins is remaining if (block.timestamp + BID_EXTENSION_LENGTH > endAt) { endAt = block.timestamp + BID_EXTENSION_LENGTH; } // keeptrack of all bidders for distributing NFT's and refunds // if the 2 values are equal then their original bid must be zero if (bidAmount == totalBidsFromBidder) { allBidders.push(msg.sender); } sumOfAllBids += bidAmount; allBids[msg.sender] = totalBidsFromBidder; emit UserPlacesBid(msg.sender, totalBidsFromBidder); } /** * @dev When the auction ends, bidders can claim their NFT's and any remaining ETH. */ function claimAfterAuction() external { // Check the auction has ended and it is within the claim period (1 week) if (block.timestamp < endAt + BID_EXTENSION_LENGTH || block.timestamp > endAt + CLAIM_PERIOD) revert AuctionNotOver(); // Check the sender has placed a bid and has not already claimed if (allBids[msg.sender] == 0) revert NoBidToClaim(msg.sender); uint pricePerUnit = getCurrentPricePerUnit(); uint amount = allBids[msg.sender]; uint quantityToMint = amount / pricePerUnit; allBids[msg.sender] = 0; if (quantityToMint > 0) { _mint(msg.sender, quantityToMint); } uint remainder = amount % pricePerUnit; (bool success, ) = (msg.sender).call{value: remainder}(""); if (!success) revert TransferNotSuccessful(msg.sender); } // Step 3 - Withdraw Remaining NFTs function withdrawRemainingNFTs(uint amount) external onlyOwner { // Check the auction has started, ended and the claim period has passed if (startedAt == 0 || block.timestamp < endAt + CLAIM_PERIOD) revert AuctionNotOver(); if (totalSupply() + amount > MAX_SUPPLY) revert TooManyRequested(); // After all nfts have been minted, this will revert // In the rare case that there are no NFTs left after the auction, this will revert _mint(owner(), amount); } // Step 4 - Withdraw /** * @dev Withdraw the ETH from the contract, but only after all other steps have been completed. */ function withdraw() external onlyOwner { if (totalSupply() != MAX_SUPPLY) revert NftsNotAllMinted(); (bool success, ) = msg.sender.call{value: address(this).balance}(""); if (!success) revert TransferFailed(); } // Getters/ View Functions /** * @dev Get the seed for a given tokenId. * @param tokenId The tokenId to get the seed for. * @return The seed(random number) for the given tokenId. */ function getSeed(uint256 tokenId) public view returns (uint256) { if (tokenId >= totalSupply()) revert InvalidTokenId(tokenId); for (uint i = 0; i < currentGen;) { if (tokenId < genIdToTokenId[i]) { uint seed = genSeed[i]; return uint256(keccak256(abi.encodePacked(seed, tokenId))); } unchecked { ++i; } } return 0; } /** * @dev Get the metadata for a given tokenId. * @param tokenId The tokenId to get the metadata for. * @return The metadata for the given tokenId. */ function tokenURI(uint256 tokenId) public view override returns (string memory) { uint seed = getSeed(tokenId); if (seed == 0) { return "ipfs://QmTJf1jnE2E8iMtVdVvdcCUwC1D8kJ4Qktise1XM1CfvyS"; } return _metadata.buildMetadata(tokenId, seed); } /** * @dev Get the current price per unit. * @return The current price per unit. */ function getCurrentPricePerUnit() public view returns (uint) { return sumOfAllBids / (MAX_SUPPLY - numOfCyphersClaimed); } /** * @dev Get the minimum bid. * @return The minimum bid. */ function getMinimumBid() public view returns (uint) { uint minimum = getCurrentPricePerUnit() + getCurrentPricePerUnit() / BID_INCREASE_PERCENT; if (minimum <= BID_INCREMENT) { return BID_INCREMENT; } else { return minimum - minimum % BID_INCREMENT + BID_INCREMENT; } } /** * @dev Get all bidders. * @return An array of all bidders. */ function getAllBidders() external view returns (address[] memory) { return allBidders; } /** * @dev Get the total amount of bids for a given bidder, assuming they have not claimed. * @param bidder The bidder to get the total amount of bids for. * @return The total amount of bids for the given bidder. */ function getUserBid(address bidder) external view returns (uint) { return allBids[bidder]; } /** * @dev Get when the auction started * @return The timestamp when the auction started. */ function getStartTimestamp() external view returns(uint) { return startedAt; } /** * @dev Get when the auction is currently scheduled to end. This may be extended if a bid is placed in the last 15mins. * @return The timestamp when the auction ends. */ function getEndTimestamp() external view returns(uint) { return endAt; } /** * @dev check if an individual cypher claim has been claimed * @param tokenId The tokenId to check if it has been claimed. * @return true if the given tokenId has been claimed. */ function getIfCypherClaimed(uint tokenId) external view returns(bool) { return LibBitmap.get(cypherClaims, tokenId); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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 anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _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); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall( address to, uint256 value, bytes calldata data ) external returns (bool success); function transferFrom( address from, address to, uint256 value ) external returns (bool success); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface VRFCoordinatorV2Interface { /** * @notice Get configuration relevant for making requests * @return minimumRequestConfirmations global min for request confirmations * @return maxGasLimit global max for request gas limit * @return s_provingKeyHashes list of registered key hashes */ function getRequestConfig() external view returns ( uint16, uint32, bytes32[] memory ); /** * @notice Request a set of random words. * @param keyHash - Corresponds to a particular oracle job which uses * that key for generating the VRF proof. Different keyHash's have different gas price * ceilings, so you can select a specific one to bound your maximum per request cost. * @param subId - The ID of the VRF subscription. Must be funded * with the minimum subscription balance required for the selected keyHash. * @param minimumRequestConfirmations - How many blocks you'd like the * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS * for why you may want to request more. The acceptable range is * [minimumRequestBlockConfirmations, 200]. * @param callbackGasLimit - How much gas you'd like to receive in your * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords * may be slightly less than this amount because of gas used calling the function * (argument decoding etc.), so you may need to request slightly more than you expect * to have inside fulfillRandomWords. The acceptable range is * [0, maxGasLimit] * @param numWords - The number of uint256 random values you'd like to receive * in your fulfillRandomWords callback. Note these numbers are expanded in a * secure way by the VRFCoordinator from a single random value supplied by the oracle. * @return requestId - A unique identifier of the request. Can be used to match * a request to a response in fulfillRandomWords. */ function requestRandomWords( bytes32 keyHash, uint64 subId, uint16 minimumRequestConfirmations, uint32 callbackGasLimit, uint32 numWords ) external returns (uint256 requestId); /** * @notice Create a VRF subscription. * @return subId - A unique subscription id. * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer. * @dev Note to fund the subscription, use transferAndCall. For example * @dev LINKTOKEN.transferAndCall( * @dev address(COORDINATOR), * @dev amount, * @dev abi.encode(subId)); */ function createSubscription() external returns (uint64 subId); /** * @notice Get a VRF subscription. * @param subId - ID of the subscription * @return balance - LINK balance of the subscription in juels. * @return reqCount - number of requests for this subscription, determines fee tier. * @return owner - owner of the subscription. * @return consumers - list of consumer address which are able to use this subscription. */ function getSubscription(uint64 subId) external view returns ( uint96 balance, uint64 reqCount, address owner, address[] memory consumers ); /** * @notice Request subscription owner transfer. * @param subId - ID of the subscription * @param newOwner - proposed new owner of the subscription */ function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external; /** * @notice Request subscription owner transfer. * @param subId - ID of the subscription * @dev will revert if original owner of subId has * not requested that msg.sender become the new owner. */ function acceptSubscriptionOwnerTransfer(uint64 subId) external; /** * @notice Add a consumer to a VRF subscription. * @param subId - ID of the subscription * @param consumer - New consumer which can use the subscription */ function addConsumer(uint64 subId, address consumer) external; /** * @notice Remove a consumer from a VRF subscription. * @param subId - ID of the subscription * @param consumer - Consumer to remove from the subscription */ function removeConsumer(uint64 subId, address consumer) external; /** * @notice Cancel a subscription * @param subId - ID of the subscription * @param to - Where to send the remaining LINK to */ function cancelSubscription(uint64 subId, address to) external; /* * @notice Check to see if there exists a request commitment consumers * for all consumers and keyhashes for a given sub. * @param subId - ID of the subscription * @return true if there exists at least one unfulfilled request for the subscription, false * otherwise. */ function pendingRequestExists(uint64 subId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** **************************************************************************** * @notice Interface for contracts using VRF randomness * ***************************************************************************** * @dev PURPOSE * * @dev Reggie the Random Oracle (not his real job) wants to provide randomness * @dev to Vera the verifier in such a way that Vera can be sure he's not * @dev making his output up to suit himself. Reggie provides Vera a public key * @dev to which he knows the secret key. Each time Vera provides a seed to * @dev Reggie, he gives back a value which is computed completely * @dev deterministically from the seed and the secret key. * * @dev Reggie provides a proof by which Vera can verify that the output was * @dev correctly computed once Reggie tells it to her, but without that proof, * @dev the output is indistinguishable to her from a uniform random sample * @dev from the output space. * * @dev The purpose of this contract is to make it easy for unrelated contracts * @dev to talk to Vera the verifier about the work Reggie is doing, to provide * @dev simple access to a verifiable source of randomness. It ensures 2 things: * @dev 1. The fulfillment came from the VRFCoordinator * @dev 2. The consumer contract implements fulfillRandomWords. * ***************************************************************************** * @dev USAGE * * @dev Calling contracts must inherit from VRFConsumerBase, and can * @dev initialize VRFConsumerBase's attributes in their constructor as * @dev shown: * * @dev contract VRFConsumer { * @dev constructor(<other arguments>, address _vrfCoordinator, address _link) * @dev VRFConsumerBase(_vrfCoordinator) public { * @dev <initialization with other arguments goes here> * @dev } * @dev } * * @dev The oracle will have given you an ID for the VRF keypair they have * @dev committed to (let's call it keyHash). Create subscription, fund it * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface * @dev subscription management functions). * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations, * @dev callbackGasLimit, numWords), * @dev see (VRFCoordinatorInterface for a description of the arguments). * * @dev Once the VRFCoordinator has received and validated the oracle's response * @dev to your request, it will call your contract's fulfillRandomWords method. * * @dev The randomness argument to fulfillRandomWords is a set of random words * @dev generated from your requestId and the blockHash of the request. * * @dev If your contract could have concurrent requests open, you can use the * @dev requestId returned from requestRandomWords to track which response is associated * @dev with which randomness request. * @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind, * @dev if your contract could have multiple requests in flight simultaneously. * * @dev Colliding `requestId`s are cryptographically impossible as long as seeds * @dev differ. * * ***************************************************************************** * @dev SECURITY CONSIDERATIONS * * @dev A method with the ability to call your fulfillRandomness method directly * @dev could spoof a VRF response with any random value, so it's critical that * @dev it cannot be directly called by anything other than this base contract * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method). * * @dev For your users to trust that your contract's random behavior is free * @dev from malicious interference, it's best if you can write it so that all * @dev behaviors implied by a VRF response are executed *during* your * @dev fulfillRandomness method. If your contract must store the response (or * @dev anything derived from it) and use it later, you must ensure that any * @dev user-significant behavior which depends on that stored value cannot be * @dev manipulated by a subsequent VRF request. * * @dev Similarly, both miners and the VRF oracle itself have some influence * @dev over the order in which VRF responses appear on the blockchain, so if * @dev your contract could have multiple VRF requests in flight simultaneously, * @dev you must ensure that the order in which the VRF responses arrive cannot * @dev be used to manipulate your contract's user-significant behavior. * * @dev Since the block hash of the block which contains the requestRandomness * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful * @dev miner could, in principle, fork the blockchain to evict the block * @dev containing the request, forcing the request to be included in a * @dev different block with a different hash, and therefore a different input * @dev to the VRF. However, such an attack would incur a substantial economic * @dev cost. This cost scales with the number of blocks the VRF oracle waits * @dev until it calls responds to a request. It is for this reason that * @dev that you can signal to an oracle you'd like them to wait longer before * @dev responding to the request (however this is not enforced in the contract * @dev and so remains effective only in the case of unmodified oracle software). */ abstract contract VRFConsumerBaseV2 { error OnlyCoordinatorCanFulfill(address have, address want); address private immutable vrfCoordinator; /** * @param _vrfCoordinator address of VRFCoordinator contract */ constructor(address _vrfCoordinator) { vrfCoordinator = _vrfCoordinator; } /** * @notice fulfillRandomness handles the VRF response. Your contract must * @notice implement it. See "SECURITY CONSIDERATIONS" above for important * @notice principles to keep in mind when implementing your fulfillRandomness * @notice method. * * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this * @dev signature, and will call it once it has verified the proof * @dev associated with the randomness. (It is triggered via a call to * @dev rawFulfillRandomness, below.) * * @param requestId The Id initially returned by requestRandomness * @param randomWords the VRF output expanded to the requested number of words */ function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual; // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF // proof. rawFulfillRandomness then calls fulfillRandomness, after validating // the origin of the call function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external { if (msg.sender != vrfCoordinator) { revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator); } fulfillRandomWords(requestId, randomWords); } }
// SPDX-License-Identifier: MIT // ERC721A Contracts v4.2.3 // Creator: Chiru Labs pragma solidity ^0.8.4; import './IERC721A.sol'; /** * @dev Interface of ERC721 token receiver. */ interface ERC721A__IERC721Receiver { function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } /** * @title ERC721A * * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721) * Non-Fungible Token Standard, including the Metadata extension. * Optimized for lower gas during batch mints. * * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...) * starting from `_startTokenId()`. * * Assumptions: * * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply. * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256). */ contract ERC721A is IERC721A { // Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364). struct TokenApprovalRef { address value; } // ============================================================= // CONSTANTS // ============================================================= // Mask of an entry in packed address data. uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1; // The bit position of `numberMinted` in packed address data. uint256 private constant _BITPOS_NUMBER_MINTED = 64; // The bit position of `numberBurned` in packed address data. uint256 private constant _BITPOS_NUMBER_BURNED = 128; // The bit position of `aux` in packed address data. uint256 private constant _BITPOS_AUX = 192; // Mask of all 256 bits in packed address data except the 64 bits for `aux`. uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1; // The bit position of `startTimestamp` in packed ownership. uint256 private constant _BITPOS_START_TIMESTAMP = 160; // The bit mask of the `burned` bit in packed ownership. uint256 private constant _BITMASK_BURNED = 1 << 224; // The bit position of the `nextInitialized` bit in packed ownership. uint256 private constant _BITPOS_NEXT_INITIALIZED = 225; // The bit mask of the `nextInitialized` bit in packed ownership. uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225; // The bit position of `extraData` in packed ownership. uint256 private constant _BITPOS_EXTRA_DATA = 232; // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`. uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1; // The mask of the lower 160 bits for addresses. uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1; // The maximum `quantity` that can be minted with {_mintERC2309}. // This limit is to prevent overflows on the address data entries. // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309} // is required to cause an overflow, which is unrealistic. uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000; // The `Transfer` event signature is given by: // `keccak256(bytes("Transfer(address,address,uint256)"))`. bytes32 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; // ============================================================= // STORAGE // ============================================================= // The next token ID to be minted. uint256 private _currentIndex; // The number of tokens burned. uint256 private _burnCounter; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. // See {_packedOwnershipOf} implementation for details. // // Bits Layout: // - [0..159] `addr` // - [160..223] `startTimestamp` // - [224] `burned` // - [225] `nextInitialized` // - [232..255] `extraData` mapping(uint256 => uint256) private _packedOwnerships; // Mapping owner address to address data. // // Bits Layout: // - [0..63] `balance` // - [64..127] `numberMinted` // - [128..191] `numberBurned` // - [192..255] `aux` mapping(address => uint256) private _packedAddressData; // Mapping from token ID to approved address. mapping(uint256 => TokenApprovalRef) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; // ============================================================= // CONSTRUCTOR // ============================================================= constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; _currentIndex = _startTokenId(); } // ============================================================= // TOKEN COUNTING OPERATIONS // ============================================================= /** * @dev Returns the starting token ID. * To change the starting token ID, please override this function. */ function _startTokenId() internal view virtual returns (uint256) { return 0; } /** * @dev Returns the next token ID to be minted. */ function _nextTokenId() internal view virtual returns (uint256) { return _currentIndex; } /** * @dev Returns the total number of tokens in existence. * Burned tokens will reduce the count. * To get the total number of tokens minted, please see {_totalMinted}. */ function totalSupply() public view virtual override returns (uint256) { // Counter underflow is impossible as _burnCounter cannot be incremented // more than `_currentIndex - _startTokenId()` times. unchecked { return _currentIndex - _burnCounter - _startTokenId(); } } /** * @dev Returns the total amount of tokens minted in the contract. */ function _totalMinted() internal view virtual returns (uint256) { // Counter underflow is impossible as `_currentIndex` does not decrement, // and it is initialized to `_startTokenId()`. unchecked { return _currentIndex - _startTokenId(); } } /** * @dev Returns the total number of tokens burned. */ function _totalBurned() internal view virtual returns (uint256) { return _burnCounter; } // ============================================================= // ADDRESS DATA OPERATIONS // ============================================================= /** * @dev Returns the number of tokens in `owner`'s account. */ function balanceOf(address owner) public view virtual override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY; } /** * Returns the number of tokens minted by `owner`. */ function _numberMinted(address owner) internal view returns (uint256) { return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY; } /** * Returns the number of tokens burned by or on behalf of `owner`. */ function _numberBurned(address owner) internal view returns (uint256) { return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY; } /** * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used). */ function _getAux(address owner) internal view returns (uint64) { return uint64(_packedAddressData[owner] >> _BITPOS_AUX); } /** * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used). * If there are multiple variables, please pack them into a uint64. */ function _setAux(address owner, uint64 aux) internal virtual { uint256 packed = _packedAddressData[owner]; uint256 auxCasted; // Cast `aux` with assembly to avoid redundant masking. assembly { auxCasted := aux } packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX); _packedAddressData[owner] = packed; } // ============================================================= // IERC165 // ============================================================= /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified) * to learn more about how these ids are created. * * This function call must use less than 30000 gas. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { // The interface IDs are constants representing the first 4 bytes // of the XOR of all function selectors in the interface. // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165) // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`) return interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165. interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721. interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata. } // ============================================================= // IERC721Metadata // ============================================================= /** * @dev Returns the token collection name. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the token collection symbol. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : ''; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, it can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ''; } // ============================================================= // OWNERSHIPS OPERATIONS // ============================================================= /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return address(uint160(_packedOwnershipOf(tokenId))); } /** * @dev Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around over time. */ function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) { return _unpackedOwnership(_packedOwnershipOf(tokenId)); } /** * @dev Returns the unpacked `TokenOwnership` struct at `index`. */ function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) { return _unpackedOwnership(_packedOwnerships[index]); } /** * @dev Initializes the ownership slot minted at `index` for efficiency purposes. */ function _initializeOwnershipAt(uint256 index) internal virtual { if (_packedOwnerships[index] == 0) { _packedOwnerships[index] = _packedOwnershipOf(index); } } /** * Returns the packed ownership data of `tokenId`. */ function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) { if (_startTokenId() <= tokenId) { packed = _packedOwnerships[tokenId]; // If not burned. if (packed & _BITMASK_BURNED == 0) { // If the data at the starting slot does not exist, start the scan. if (packed == 0) { if (tokenId >= _currentIndex) revert OwnerQueryForNonexistentToken(); // Invariant: // There will always be an initialized ownership slot // (i.e. `ownership.addr != address(0) && ownership.burned == false`) // before an unintialized ownership slot // (i.e. `ownership.addr == address(0) && ownership.burned == false`) // Hence, `tokenId` will not underflow. // // We can directly compare the packed value. // If the address is zero, packed will be zero. for (;;) { unchecked { packed = _packedOwnerships[--tokenId]; } if (packed == 0) continue; return packed; } } // Otherwise, the data exists and is not burned. We can skip the scan. // This is possible because we have already achieved the target condition. // This saves 2143 gas on transfers of initialized tokens. return packed; } } revert OwnerQueryForNonexistentToken(); } /** * @dev Returns the unpacked `TokenOwnership` struct from `packed`. */ function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) { ownership.addr = address(uint160(packed)); ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP); ownership.burned = packed & _BITMASK_BURNED != 0; ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA); } /** * @dev Packs ownership data into a single uint256. */ function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) { assembly { // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean. owner := and(owner, _BITMASK_ADDRESS) // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`. result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags)) } } /** * @dev Returns the `nextInitialized` flag set if `quantity` equals 1. */ function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) { // For branchless setting of the `nextInitialized` flag. assembly { // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`. result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1)) } } // ============================================================= // APPROVAL OPERATIONS // ============================================================= /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. See {ERC721A-_approve}. * * Requirements: * * - The caller must own the token or be an approved operator. */ function approve(address to, uint256 tokenId) public payable virtual override { _approve(to, tokenId, true); } /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId].value; } /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} * for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) public virtual override { _operatorApprovals[_msgSenderERC721A()][operator] = approved; emit ApprovalForAll(_msgSenderERC721A(), operator, approved); } /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted. See {_mint}. */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _startTokenId() <= tokenId && tokenId < _currentIndex && // If within bounds, _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned. } /** * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`. */ function _isSenderApprovedOrOwner( address approvedAddress, address owner, address msgSender ) private pure returns (bool result) { assembly { // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean. owner := and(owner, _BITMASK_ADDRESS) // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean. msgSender := and(msgSender, _BITMASK_ADDRESS) // `msgSender == owner || msgSender == approvedAddress`. result := or(eq(msgSender, owner), eq(msgSender, approvedAddress)) } } /** * @dev Returns the storage slot and value for the approved address of `tokenId`. */ function _getApprovedSlotAndAddress(uint256 tokenId) private view returns (uint256 approvedAddressSlot, address approvedAddress) { TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId]; // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`. assembly { approvedAddressSlot := tokenApproval.slot approvedAddress := sload(approvedAddressSlot) } } // ============================================================= // TRANSFER OPERATIONS // ============================================================= /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token * by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) public payable virtual override { uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId); if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner(); (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId); // The nested ifs save around 20+ gas over a compound boolean condition. if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A())) if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved(); if (to == address(0)) revert TransferToZeroAddress(); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner. assembly { if approvedAddress { // This is equivalent to `delete _tokenApprovals[tokenId]`. sstore(approvedAddressSlot, 0) } } // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256. unchecked { // We can directly increment and decrement the balances. --_packedAddressData[from]; // Updates: `balance -= 1`. ++_packedAddressData[to]; // Updates: `balance += 1`. // Updates: // - `address` to the next owner. // - `startTimestamp` to the timestamp of transfering. // - `burned` to `false`. // - `nextInitialized` to `true`. _packedOwnerships[tokenId] = _packOwnershipData( to, _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked) ); // If the next slot may not have been initialized (i.e. `nextInitialized == false`) . if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) { uint256 nextTokenId = tokenId + 1; // If the next slot's address is zero and not burned (i.e. packed value is zero). if (_packedOwnerships[nextTokenId] == 0) { // If the next slot is within bounds. if (nextTokenId != _currentIndex) { // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`. _packedOwnerships[nextTokenId] = prevOwnershipPacked; } } } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public payable virtual override { safeTransferFrom(from, to, tokenId, ''); } /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token * by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public payable virtual override { transferFrom(from, to, tokenId); if (to.code.length != 0) if (!_checkContractOnERC721Received(from, to, tokenId, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } /** * @dev Hook that is called before a set of serially-ordered token IDs * are about to be transferred. This includes minting. * And also called before burning one token. * * `startTokenId` - the first token ID to be transferred. * `quantity` - the amount to be transferred. * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token IDs * have been transferred. This includes minting. * And also called after one token has been burned. * * `startTokenId` - the first token ID to be transferred. * `quantity` - the amount to be transferred. * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract. * * `from` - Previous owner of the given token ID. * `to` - Target address that will receive the token. * `tokenId` - Token ID to be transferred. * `_data` - Optional data to send along with the call. * * Returns whether the call correctly returned the expected magic value. */ function _checkContractOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns ( bytes4 retval ) { return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } // ============================================================= // MINT OPERATIONS // ============================================================= /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {Transfer} event for each mint. */ function _mint(address to, uint256 quantity) internal virtual { uint256 startTokenId = _currentIndex; if (quantity == 0) revert MintZeroQuantity(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are incredibly unrealistic. // `balance` and `numberMinted` have a maximum limit of 2**64. // `tokenId` has a maximum limit of 2**256. unchecked { // Updates: // - `balance += quantity`. // - `numberMinted += quantity`. // // We can directly add to the `balance` and `numberMinted`. _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1); // Updates: // - `address` to the owner. // - `startTimestamp` to the timestamp of minting. // - `burned` to `false`. // - `nextInitialized` to `quantity == 1`. _packedOwnerships[startTokenId] = _packOwnershipData( to, _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0) ); uint256 toMasked; uint256 end = startTokenId + quantity; // Use assembly to loop and emit the `Transfer` event for gas savings. // The duplicated `log4` removes an extra check and reduces stack juggling. // The assembly, together with the surrounding Solidity code, have been // delicately arranged to nudge the compiler into producing optimized opcodes. assembly { // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean. toMasked := and(to, _BITMASK_ADDRESS) // Emit the `Transfer` event. log4( 0, // Start of data (0, since no data). 0, // End of data (0, since no data). _TRANSFER_EVENT_SIGNATURE, // Signature. 0, // `address(0)`. toMasked, // `to`. startTokenId // `tokenId`. ) // The `iszero(eq(,))` check ensures that large values of `quantity` // that overflows uint256 will make the loop run out of gas. // The compiler will optimize the `iszero` away for performance. for { let tokenId := add(startTokenId, 1) } iszero(eq(tokenId, end)) { tokenId := add(tokenId, 1) } { // Emit the `Transfer` event. Similar to above. log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId) } } if (toMasked == 0) revert MintToZeroAddress(); _currentIndex = end; } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * This function is intended for efficient minting only during contract creation. * * It emits only one {ConsecutiveTransfer} as defined in * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309), * instead of a sequence of {Transfer} event(s). * * Calling this function outside of contract creation WILL make your contract * non-compliant with the ERC721 standard. * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309 * {ConsecutiveTransfer} event is only permissible during contract creation. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {ConsecutiveTransfer} event. */ function _mintERC2309(address to, uint256 quantity) internal virtual { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are unrealistic due to the above check for `quantity` to be below the limit. unchecked { // Updates: // - `balance += quantity`. // - `numberMinted += quantity`. // // We can directly add to the `balance` and `numberMinted`. _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1); // Updates: // - `address` to the owner. // - `startTimestamp` to the timestamp of minting. // - `burned` to `false`. // - `nextInitialized` to `quantity == 1`. _packedOwnerships[startTokenId] = _packOwnershipData( to, _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0) ); emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to); _currentIndex = startTokenId + quantity; } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Safely mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - If `to` refers to a smart contract, it must implement * {IERC721Receiver-onERC721Received}, which is called for each safe transfer. * - `quantity` must be greater than 0. * * See {_mint}. * * Emits a {Transfer} event for each mint. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal virtual { _mint(to, quantity); unchecked { if (to.code.length != 0) { uint256 end = _currentIndex; uint256 index = end - quantity; do { if (!_checkContractOnERC721Received(address(0), to, index++, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } while (index < end); // Reentrancy protection. if (_currentIndex != end) revert(); } } } /** * @dev Equivalent to `_safeMint(to, quantity, '')`. */ function _safeMint(address to, uint256 quantity) internal virtual { _safeMint(to, quantity, ''); } // ============================================================= // APPROVAL OPERATIONS // ============================================================= /** * @dev Equivalent to `_approve(to, tokenId, false)`. */ function _approve(address to, uint256 tokenId) internal virtual { _approve(to, tokenId, false); } /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the * zero address clears previous approvals. * * Requirements: * * - `tokenId` must exist. * * Emits an {Approval} event. */ function _approve( address to, uint256 tokenId, bool approvalCheck ) internal virtual { address owner = ownerOf(tokenId); if (approvalCheck) if (_msgSenderERC721A() != owner) if (!isApprovedForAll(owner, _msgSenderERC721A())) { revert ApprovalCallerNotOwnerNorApproved(); } _tokenApprovals[tokenId].value = to; emit Approval(owner, to, tokenId); } // ============================================================= // BURN OPERATIONS // ============================================================= /** * @dev Equivalent to `_burn(tokenId, false)`. */ function _burn(uint256 tokenId) internal virtual { _burn(tokenId, false); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId, bool approvalCheck) internal virtual { uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId); address from = address(uint160(prevOwnershipPacked)); (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId); if (approvalCheck) { // The nested ifs save around 20+ gas over a compound boolean condition. if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A())) if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved(); } _beforeTokenTransfers(from, address(0), tokenId, 1); // Clear approvals from the previous owner. assembly { if approvedAddress { // This is equivalent to `delete _tokenApprovals[tokenId]`. sstore(approvedAddressSlot, 0) } } // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256. unchecked { // Updates: // - `balance -= 1`. // - `numberBurned += 1`. // // We can directly decrement the balance, and increment the number burned. // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`. _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1; // Updates: // - `address` to the last owner. // - `startTimestamp` to the timestamp of burning. // - `burned` to `true`. // - `nextInitialized` to `true`. _packedOwnerships[tokenId] = _packOwnershipData( from, (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked) ); // If the next slot may not have been initialized (i.e. `nextInitialized == false`) . if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) { uint256 nextTokenId = tokenId + 1; // If the next slot's address is zero and not burned (i.e. packed value is zero). if (_packedOwnerships[nextTokenId] == 0) { // If the next slot is within bounds. if (nextTokenId != _currentIndex) { // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`. _packedOwnerships[nextTokenId] = prevOwnershipPacked; } } } } emit Transfer(from, address(0), tokenId); _afterTokenTransfers(from, address(0), tokenId, 1); // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times. unchecked { _burnCounter++; } } // ============================================================= // EXTRA DATA OPERATIONS // ============================================================= /** * @dev Directly sets the extra data for the ownership data `index`. */ function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual { uint256 packed = _packedOwnerships[index]; if (packed == 0) revert OwnershipNotInitializedForExtraData(); uint256 extraDataCasted; // Cast `extraData` with assembly to avoid redundant masking. assembly { extraDataCasted := extraData } packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA); _packedOwnerships[index] = packed; } /** * @dev Called during each token transfer to set the 24bit `extraData` field. * Intended to be overridden by the cosumer contract. * * `previousExtraData` - the value of `extraData` before transfer. * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _extraData( address from, address to, uint24 previousExtraData ) internal view virtual returns (uint24) {} /** * @dev Returns the next extra data for the packed ownership data. * The returned result is shifted into position. */ function _nextExtraData( address from, address to, uint256 prevOwnershipPacked ) private view returns (uint256) { uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA); return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA; } // ============================================================= // OTHER OPERATIONS // ============================================================= /** * @dev Returns the message sender (defaults to `msg.sender`). * * If you are writing GSN compatible contracts, you need to override this function. */ function _msgSenderERC721A() internal view virtual returns (address) { return msg.sender; } /** * @dev Converts a uint256 to its ASCII string decimal representation. */ function _toString(uint256 value) internal pure virtual returns (string memory str) { assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned. // We will need 1 word for the trailing zeros padding, 1 word for the length, // and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0. let m := add(mload(0x40), 0xa0) // Update the free memory pointer to allocate. mstore(0x40, m) // Assign the `str` to the end. str := sub(m, 0x20) // Zeroize the slot after the string. mstore(str, 0) // Cache the end of the memory to calculate the length later. let end := str // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. // prettier-ignore for { let temp := value } 1 {} { str := sub(str, 1) // Write the character to the pointer. // The ASCII index of the '0' character is 48. mstore8(str, add(48, mod(temp, 10))) // Keep dividing `temp` until zero. temp := div(temp, 10) // prettier-ignore if iszero(temp) { break } } let length := sub(end, str) // Move the pointer 32 bytes leftwards to make room for the length. str := sub(str, 0x20) // Store the length. mstore(str, length) } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "solady/utils/Base64.sol"; import "./Machine.sol"; import "./GridHelper.sol"; import "./GlobalSVG.sol"; import "./Noise.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; contract Metadata { Machine private immutable _machine; // Clifford private _clifford; GlobalSVG private immutable _globalSVG; string[3] allStates = ["Degraded", "Basic", "Embellished"]; constructor(Machine machine, GlobalSVG globalSVG) { _machine = machine; _globalSVG = globalSVG; } /** * @dev Returns the machine based on the random number * @param rand The digits to use * @return The machine */ function getMachine(uint rand) public view returns (string memory) { return _machine.selectMachine(rand); } /** * @dev build entire metadata for a given token * @param tokenId The token to build metadata for * @param rand The digits to use * @return The metadata */ function buildMetadata(uint256 tokenId, uint rand) public view returns (string memory) { int baseline = getBaselineRarity(rand); uint state = getState(baseline); string memory jsonInitial = string.concat( '{"name": "A Machine For Dying # ', Strings.toString(tokenId), '", "description": "A Machine For Dying is centred around the concept of the Worker in a Box, a trapped individual, doomed to toil forever. The collection presents the stark contrast between autonomy and individuality versus the destruction and apathy that can come from being trapped and exploited by the corporate machine.", "attributes": [{"trait_type": "Machine", "value":"', getMachine(rand), '"}, {"trait_type": "State", "value":"', allStates[state], '"}, {"trait_type": "Small Asset:", "value":"', _machine.getSmallAssetName(rand, baseline) ); jsonInitial = string.concat( jsonInitial, '"}, {"trait_type": "Large Asset:", "value":"', _machine.getLargeAssetName(rand, baseline), '"}, {"trait_type": "Wall Out:", "value":"', _machine.getWallOutName(rand, baseline), '"}, {"trait_type": "Wall Flat:", "value":"', _machine.getWallFlatName(rand, baseline) ); jsonInitial = string.concat( jsonInitial, '"}, {"trait_type": "Colour:", "value":"', getColourIndexTier(rand, baseline), '"}, {"trait_type": "Pattern:", "value":"', Patterns.getPatternName(rand, baseline), '"}, {"trait_type": "Character:", "value":"', _machine.getCharacterName(rand, baseline), '"}],', '"image": "data:image/svg+xml;base64,' ); string memory jsonFinal = Base64.encode( bytes(string.concat( jsonInitial, composeSVG(rand, baseline), '", ', '"animation_url": "data:image/svg+xml;base64,', composeSVG(rand, baseline), '"}' )) ); string memory output = string.concat("data:application/json;base64,", jsonFinal); return output; } /** * @dev Inject data into the SVG for the sound script * @param rand The digits to use * @return The data info object string */ function createDataInfo(uint rand) internal view returns (string memory) { int baseline = getBaselineRarity(rand); uint state = getState(baseline); string memory json = string.concat( 'data-info=\'{"RandomNumber":"', Strings.toString(rand), '","State":"', allStates[state], '","Machine":"', getMachine(rand), '","SmallAsset":"', _machine.getSmallAssetName(rand, baseline) ); json = string.concat( json, '","LargeAsset":"', _machine.getLargeAssetName(rand, baseline), '","WallOut":"', _machine.getWallOutName(rand, baseline), '","WallFlat":"', _machine.getWallFlatName(rand, baseline) ); json = string.concat( json, '","Colour":"', getColourIndexTier(rand, baseline), '","Pattern":"', Patterns.getPatternName(rand, baseline), '","Character":"', _machine.getCharacterName(rand, baseline), '"}\' >' ); return json; } /** * @dev Get the colour index based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The colour index as a string */ function getBaseColourValue(uint rand, int baseline) internal pure returns (uint) { return GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 3)] + baseline); } /** * @dev Get the colour index tier based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The colour index tier as a string */ function getColourIndexTier(uint rand, int baseline) public pure returns(string memory) { uint value = Environment.getColourIndex(getBaseColourValue(rand, baseline)); if (value < 12) { return string.concat("DEG", Strings.toString(11-value)); } else { return string.concat("EMB", Strings.toString(value-12)); } } /** * @dev Get the state based on the baseline rarity * @param baseline The baseline rarity * @return The state as an integer */ function getState(int baseline) public pure returns (uint) { // 0 = degraded, 1 = basic, 2 = embellished if (baseline < 85) { return 0; } else if (baseline < 171) { return 1; } else { return 2; } } /** * @dev Get the baseline rarity based on the random number * @param rand The digits to use * @return The baseline rarity as an integer */ function getBaselineRarity(uint rand) public pure returns (int) { int baselineDigits = int(GridHelper.constrainToHex(Noise.getNoiseArrayZero()[GridHelper.getRandByte(rand, 2)])); return baselineDigits; } /** * @dev Get the SVG for a given token base64 encoded * @param rand The digits to use * @param baseline The baseline rarity * @return The SVG as a string */ function composeSVG(uint rand, int baseline) public view returns (string memory) { // return all svg's concatenated together and base64 encoded return Base64.encode(bytes(composeOnlyImage(rand, baseline))); } /** * @dev Get the SVG for a given token not base64 encoded * @param rand The digits to use * @param baseline The baseline rarity * @return The SVG as a string */ function composeOnlyImage(uint rand, int baseline) public view returns (string memory) { // determine if flipped // 0 if not flipped, 1 if flipped uint isFlipped = rand % 2; string memory flip = ""; if (isFlipped == 0) { flip = "1"; } else { flip = "-1"; } string memory machine = getMachine(rand); uint colourValue = getBaseColourValue(rand, baseline); string memory dataInfo = createDataInfo(rand); string memory opening = _globalSVG.getOpeningSVG(machine, colourValue, rand, baseline); string memory objects = _machine.machineToGetter(machine, rand, baseline); string memory closing = _globalSVG.getClosingSVG(); // return all svg's concatenated together and base64 encoded return string.concat(opening, _globalSVG.getShell(flip, rand, baseline, dataInfo), objects, closing); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "./LibBit.sol"; /// @notice Library for storage of packed unsigned booleans. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBitmap.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibBitmap.sol) /// @author Modified from Solidity-Bits (https://github.com/estarriolvetch/solidity-bits/blob/main/contracts/BitMaps.sol) library LibBitmap { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when a bitmap scan does not find a result. uint256 internal constant NOT_FOUND = type(uint256).max; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRUCTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev A bitmap in storage. struct Bitmap { mapping(uint256 => uint256) map; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the boolean value of the bit at `index` in `bitmap`. function get(Bitmap storage bitmap, uint256 index) internal view returns (bool isSet) { // It is better to set `isSet` to either 0 or 1, than zero vs non-zero. // Both cost the same amount of gas, but the former allows the returned value // to be reused without cleaning the upper bits. uint256 b = (bitmap.map[index >> 8] >> (index & 0xff)) & 1; /// @solidity memory-safe-assembly assembly { isSet := b } } /// @dev Updates the bit at `index` in `bitmap` to true. function set(Bitmap storage bitmap, uint256 index) internal { bitmap.map[index >> 8] |= (1 << (index & 0xff)); } /// @dev Updates the bit at `index` in `bitmap` to false. function unset(Bitmap storage bitmap, uint256 index) internal { bitmap.map[index >> 8] &= ~(1 << (index & 0xff)); } /// @dev Flips the bit at `index` in `bitmap`. /// Returns the boolean result of the flipped bit. function toggle(Bitmap storage bitmap, uint256 index) internal returns (bool newIsSet) { /// @solidity memory-safe-assembly assembly { mstore(0x00, shr(8, index)) mstore(0x20, bitmap.slot) let storageSlot := keccak256(0x00, 0x40) let shift := and(index, 0xff) let storageValue := sload(storageSlot) let mask := shl(shift, 1) storageValue := xor(storageValue, mask) // It makes sense to return the `newIsSet`, // as it allow us to skip an additional warm `sload`, // and it costs minimal gas (about 15), // which may be optimized away if the returned value is unused. newIsSet := iszero(iszero(and(storageValue, mask))) sstore(storageSlot, storageValue) } } /// @dev Updates the bit at `index` in `bitmap` to `shouldSet`. function setTo(Bitmap storage bitmap, uint256 index, bool shouldSet) internal { /// @solidity memory-safe-assembly assembly { mstore(0x20, bitmap.slot) mstore(0x00, shr(8, index)) let storageSlot := keccak256(0x00, 0x40) let storageValue := sload(storageSlot) let shift := and(index, 0xff) sstore( storageSlot, // Unsets the bit at `shift` via `and`, then sets its new value via `or`. or(and(storageValue, not(shl(shift, 1))), shl(shift, iszero(iszero(shouldSet)))) ) } } /// @dev Consecutively sets `amount` of bits starting from the bit at `start`. function setBatch(Bitmap storage bitmap, uint256 start, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let max := not(0) let shift := and(start, 0xff) mstore(0x20, bitmap.slot) mstore(0x00, shr(8, start)) if iszero(lt(add(shift, amount), 257)) { let storageSlot := keccak256(0x00, 0x40) sstore(storageSlot, or(sload(storageSlot), shl(shift, max))) let bucket := add(mload(0x00), 1) let bucketEnd := add(mload(0x00), shr(8, add(amount, shift))) amount := and(add(amount, shift), 0xff) shift := 0 for {} iszero(eq(bucket, bucketEnd)) { bucket := add(bucket, 1) } { mstore(0x00, bucket) sstore(keccak256(0x00, 0x40), max) } mstore(0x00, bucket) } let storageSlot := keccak256(0x00, 0x40) sstore(storageSlot, or(sload(storageSlot), shl(shift, shr(sub(256, amount), max)))) } } /// @dev Consecutively unsets `amount` of bits starting from the bit at `start`. function unsetBatch(Bitmap storage bitmap, uint256 start, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let shift := and(start, 0xff) mstore(0x20, bitmap.slot) mstore(0x00, shr(8, start)) if iszero(lt(add(shift, amount), 257)) { let storageSlot := keccak256(0x00, 0x40) sstore(storageSlot, and(sload(storageSlot), not(shl(shift, not(0))))) let bucket := add(mload(0x00), 1) let bucketEnd := add(mload(0x00), shr(8, add(amount, shift))) amount := and(add(amount, shift), 0xff) shift := 0 for {} iszero(eq(bucket, bucketEnd)) { bucket := add(bucket, 1) } { mstore(0x00, bucket) sstore(keccak256(0x00, 0x40), 0) } mstore(0x00, bucket) } let storageSlot := keccak256(0x00, 0x40) sstore( storageSlot, and(sload(storageSlot), not(shl(shift, shr(sub(256, amount), not(0))))) ) } } /// @dev Returns number of set bits within a range by /// scanning `amount` of bits starting from the bit at `start`. function popCount(Bitmap storage bitmap, uint256 start, uint256 amount) internal view returns (uint256 count) { unchecked { uint256 bucket = start >> 8; uint256 shift = start & 0xff; if (!(amount + shift < 257)) { count = LibBit.popCount(bitmap.map[bucket] >> shift); uint256 bucketEnd = bucket + ((amount + shift) >> 8); amount = (amount + shift) & 0xff; shift = 0; for (++bucket; bucket != bucketEnd; ++bucket) { count += LibBit.popCount(bitmap.map[bucket]); } } count += LibBit.popCount((bitmap.map[bucket] >> shift) << (256 - amount)); } } /// @dev Returns the index of the most significant set bit before the bit at `before`. /// If no set bit is found, returns `NOT_FOUND`. function findLastSet(Bitmap storage bitmap, uint256 before) internal view returns (uint256 setBitIndex) { uint256 bucket; uint256 bucketBits; /// @solidity memory-safe-assembly assembly { setBitIndex := not(0) bucket := shr(8, before) mstore(0x00, bucket) mstore(0x20, bitmap.slot) let offset := and(0xff, not(before)) // `256 - (255 & before) - 1`. bucketBits := shr(offset, shl(offset, sload(keccak256(0x00, 0x40)))) if iszero(bucketBits) { for {} bucket {} { bucket := add(bucket, setBitIndex) // `sub(bucket, 1)`. mstore(0x00, bucket) bucketBits := sload(keccak256(0x00, 0x40)) if bucketBits { break } } } } if (bucketBits != 0) { setBitIndex = (bucket << 8) | LibBit.fls(bucketBits); /// @solidity memory-safe-assembly assembly { setBitIndex := or(setBitIndex, sub(0, gt(setBitIndex, before))) } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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; } }
// SPDX-License-Identifier: MIT // ERC721A Contracts v4.2.3 // Creator: Chiru Labs pragma solidity ^0.8.4; /** * @dev Interface of ERC721A. */ interface IERC721A { /** * The caller must own the token or be an approved operator. */ error ApprovalCallerNotOwnerNorApproved(); /** * The token does not exist. */ error ApprovalQueryForNonexistentToken(); /** * Cannot query the balance for the zero address. */ error BalanceQueryForZeroAddress(); /** * Cannot mint to the zero address. */ error MintToZeroAddress(); /** * The quantity of tokens minted must be more than zero. */ error MintZeroQuantity(); /** * The token does not exist. */ error OwnerQueryForNonexistentToken(); /** * The caller must own the token or be an approved operator. */ error TransferCallerNotOwnerNorApproved(); /** * The token must be owned by `from`. */ error TransferFromIncorrectOwner(); /** * Cannot safely transfer to a contract that does not implement the * ERC721Receiver interface. */ error TransferToNonERC721ReceiverImplementer(); /** * Cannot transfer to the zero address. */ error TransferToZeroAddress(); /** * The token does not exist. */ error URIQueryForNonexistentToken(); /** * The `quantity` minted with ERC2309 exceeds the safety limit. */ error MintERC2309QuantityExceedsLimit(); /** * The `extraData` cannot be set on an unintialized ownership slot. */ error OwnershipNotInitializedForExtraData(); // ============================================================= // STRUCTS // ============================================================= struct TokenOwnership { // The address of the owner. address addr; // Stores the start time of ownership with minimal overhead for tokenomics. uint64 startTimestamp; // Whether the token has been burned. bool burned; // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}. uint24 extraData; } // ============================================================= // TOKEN COUNTERS // ============================================================= /** * @dev Returns the total number of tokens in existence. * Burned tokens will reduce the count. * To get the total number of tokens minted, please see {_totalMinted}. */ function totalSupply() external view returns (uint256); // ============================================================= // IERC165 // ============================================================= /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified) * to learn more about how these ids are created. * * This function call must use less than 30000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); // ============================================================= // IERC721 // ============================================================= /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables * (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in `owner`'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, * checking first that contract recipients are aware of the ERC721 protocol * to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move * this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external payable; /** * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external payable; /** * @dev Transfers `tokenId` from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} * whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token * by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external payable; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the * zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external payable; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} * for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll}. */ function isApprovedForAll(address owner, address operator) external view returns (bool); // ============================================================= // IERC721Metadata // ============================================================= /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); // ============================================================= // IERC2309 // ============================================================= /** * @dev Emitted when tokens in `fromTokenId` to `toTokenId` * (inclusive) is transferred from `from` to `to`, as defined in the * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard. * * See {_mintERC2309} for more details. */ event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library to encode strings in Base64. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Base64.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Base64.sol) /// @author Modified from (https://github.com/Brechtpd/base64/blob/main/base64.sol) by Brecht Devos - <[email protected]>. library Base64 { /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// See: https://datatracker.ietf.org/doc/html/rfc4648 /// @param fileSafe Whether to replace '+' with '-' and '/' with '_'. /// @param noPadding Whether to strip away the padding. function encode(bytes memory data, bool fileSafe, bool noPadding) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let dataLength := mload(data) if dataLength { // Multiply by 4/3 rounded up. // The `shl(2, ...)` is equivalent to multiplying by 4. let encodedLength := shl(2, div(add(dataLength, 2), 3)) // Set `result` to point to the start of the free memory. result := mload(0x40) // Store the table into the scratch space. // Offsetted by -1 byte so that the `mload` will load the character. // We will rewrite the free memory pointer at `0x40` later with // the allocated size. // The magic constant 0x0230 will translate "-_" + "+/". mstore(0x1f, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef") mstore(0x3f, sub("ghijklmnopqrstuvwxyz0123456789-_", mul(iszero(fileSafe), 0x0230))) // Skip the first slot, which stores the length. let ptr := add(result, 0x20) let end := add(ptr, encodedLength) // Run over the input, 3 bytes at a time. for {} 1 {} { data := add(data, 3) // Advance 3 bytes. let input := mload(data) // Write 4 bytes. Optimized for fewer stack operations. mstore8(0, mload(and(shr(18, input), 0x3F))) mstore8(1, mload(and(shr(12, input), 0x3F))) mstore8(2, mload(and(shr(6, input), 0x3F))) mstore8(3, mload(and(input, 0x3F))) mstore(ptr, mload(0x00)) ptr := add(ptr, 4) // Advance 4 bytes. if iszero(lt(ptr, end)) { break } } // Allocate the memory for the string. // Add 31 and mask with `not(31)` to round the // free memory pointer up the next multiple of 32. mstore(0x40, and(add(end, 31), not(31))) // Equivalent to `o = [0, 2, 1][dataLength % 3]`. let o := div(2, mod(dataLength, 3)) // Offset `ptr` and pad with '='. We can simply write over the end. mstore(sub(ptr, o), shl(240, 0x3d3d)) // Set `o` to zero if there is padding. o := mul(iszero(iszero(noPadding)), o) // Zeroize the slot after the string. mstore(sub(ptr, o), 0) // Write the length of the string. mstore(result, sub(encodedLength, o)) } } } /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// Equivalent to `encode(data, false, false)`. function encode(bytes memory data) internal pure returns (string memory result) { result = encode(data, false, false); } /// @dev Encodes `data` using the base64 encoding described in RFC 4648. /// Equivalent to `encode(data, fileSafe, false)`. function encode(bytes memory data, bool fileSafe) internal pure returns (string memory result) { result = encode(data, fileSafe, false); } /// @dev Decodes base64 encoded `data`. /// /// Supports: /// - RFC 4648 (both standard and file-safe mode). /// - RFC 3501 (63: ','). /// /// Does not support: /// - Line breaks. /// /// Note: For performance reasons, /// this function will NOT revert on invalid `data` inputs. /// Outputs for invalid inputs will simply be undefined behaviour. /// It is the user's responsibility to ensure that the `data` /// is a valid base64 encoded string. function decode(string memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { let dataLength := mload(data) if dataLength { let decodedLength := mul(shr(2, dataLength), 3) for {} 1 {} { // If padded. if iszero(and(dataLength, 3)) { let t := xor(mload(add(data, dataLength)), 0x3d3d) // forgefmt: disable-next-item decodedLength := sub( decodedLength, add(iszero(byte(30, t)), iszero(byte(31, t))) ) break } // If non-padded. decodedLength := add(decodedLength, sub(and(dataLength, 3), 1)) break } result := mload(0x40) // Write the length of the bytes. mstore(result, decodedLength) // Skip the first slot, which stores the length. let ptr := add(result, 0x20) let end := add(ptr, decodedLength) // Load the table into the scratch space. // Constants are optimized for smaller bytecode with zero gas overhead. // `m` also doubles as the mask of the upper 6 bits. let m := 0xfc000000fc00686c7074787c8084888c9094989ca0a4a8acb0b4b8bcc0c4c8cc mstore(0x5b, m) mstore(0x3b, 0x04080c1014181c2024282c3034383c4044484c5054585c6064) mstore(0x1a, 0xf8fcf800fcd0d4d8dce0e4e8ecf0f4) for {} 1 {} { // Read 4 bytes. data := add(data, 4) let input := mload(data) // Write 3 bytes. // forgefmt: disable-next-item mstore(ptr, or( and(m, mload(byte(28, input))), shr(6, or( and(m, mload(byte(29, input))), shr(6, or( and(m, mload(byte(30, input))), shr(6, mload(byte(31, input))) )) )) )) ptr := add(ptr, 3) if iszero(lt(ptr, end)) { break } } // Allocate the memory for the string. // Add 31 and mask with `not(31)` to round the // free memory pointer up the next multiple of 32. mstore(0x40, and(add(end, 31), not(31))) // Zeroize the slot after the bytes. mstore(end, 0) // Restore the zero slot. mstore(0x60, 0) } } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "@openzeppelin/contracts/utils/Strings.sol"; import "./GridHelper.sol"; import "./GlobalNumbers.sol"; import "./AssetRetriever.sol"; interface IMachine { function getMachine(uint rand, int baseline) external view returns (string memory); function getAllNumbersUsed(uint rand, int baseline) external pure returns (uint[] memory, string[] memory); function getGlobalAssetNumber(uint rand, uint version, int baseline) external pure returns (uint); } contract Machine { AssetRetriever internal immutable _assetRetriever; string[] public allMachines = ["Altar", "Apparatus", "Cells", "Tubes", "Beast", "Conveyor"]; mapping(string => address) public machineToWorkstation; constructor(address[6] memory workstations, AssetRetriever assetRetriever) { _assetRetriever = assetRetriever; for (uint i = 0; i < allMachines.length; ++i) { machineToWorkstation[allMachines[i]] = workstations[i]; } } /** * @dev Returns the machine based on the random number * @param rand The digits to use * @return The machine */ function selectMachine(uint rand) external view returns (string memory) { return allMachines[rand % allMachines.length]; // return allMachines[5]; } /** * @dev Get a machine based on the random number * @param machine The machine to get * @param rand The digits to use * @param baseline The baseline rarity */ function machineToGetter(string memory machine, uint rand, int baseline) external view returns (string memory) { return IMachine(machineToWorkstation[machine]).getMachine(rand, baseline); } /** * @dev Get the global asset name based on the random number * @param rand The digits to use * @param baseline The baseline rarity * @return The global asset name */ function getSmallAssetName(uint rand, int baseline) external pure returns (string memory) { uint assetNumber = GlobalNumbers.getSmallAssetNumber(rand, baseline); if (assetNumber == 6000) { return "Lava Lamp"; } else if (assetNumber == 6004) { return "Martini"; } else if (assetNumber == 6006) { return "Bong"; } else if (assetNumber == 6011) { return "Books"; } else if (assetNumber == 6014) { return "Dog Bowl"; } else if (assetNumber == 6020) { return "Lizard"; } else if (assetNumber == 6021) { return "Skull"; } else if (assetNumber == 6022) { return "Dead Rat"; } else if (assetNumber == 6025) { return "Pineapple"; } else if (assetNumber == 6026) { return "Can"; } else if (assetNumber == 6027) { return "Cracked Bottle"; } else if (assetNumber == 6028) { return "Dead Plant"; } else if (assetNumber == 6029) { return "Watermelon"; } else { return "None"; } } /** * @dev Get the expansion prop name based on the random number * @param rand The digits to use * @param baseline The baseline rarity * @return The expansion prop name */ function getLargeAssetName(uint rand, int baseline) external pure returns (string memory) { uint propNumber = GlobalNumbers.getLargeAssetNumber(rand, baseline); if (propNumber == 2001) { return "Grate"; } else if (propNumber == 2002) { return "Pit"; } else if (propNumber == 2003) { return "Stairs"; } else if (propNumber == 2004) { return "Ladder"; } else if (propNumber == 2008) { return "Spikes A"; } else if (propNumber == 2009) { return "Spikes B"; } else if (propNumber == 6008) { return "Fridge"; } else if (propNumber == 6009) { return "Rug Circle"; } else if (propNumber == 6013) { return "Toilet"; } else if (propNumber == 6017) { return "Harp"; } else if (propNumber == 6018) { return "Cello"; } else if (propNumber == 6019) { return "Stool"; } else if (propNumber == 6023) { return "Deck Chair"; } else if (propNumber == 6024) { return "Cactus Chunk"; } else if (propNumber == 6030) { return "Gramophone"; } else { return "None"; } } /** * @dev Get the wall prop name based on the random number * @param rand The digits to use * @param baseline The baseline rarity * @return The wall out name */ function getWallOutName(uint rand, int baseline) external pure returns (string memory) { uint wallOutNumber = GlobalNumbers.getOutWallNumber(rand, baseline); if (wallOutNumber == 6005) { return "Peephole A"; } else if (wallOutNumber == 6007) { return "Peephole B"; } else if (wallOutNumber == 6010) { return "CCTV"; } else if (wallOutNumber == 6016) { return "Megaphone"; } else { return "None"; } } /** * @dev Get the wall flat name based on the random number * @param rand The digits to use * @param baseline The baseline rarity * @return The wall flat name */ function getWallFlatName(uint rand, int baseline) external pure returns (string memory) { uint wallFlatNumber = GlobalNumbers.getFlatWallNumber(rand, baseline); if (wallFlatNumber == 2000) { return "Crack"; } else if (wallFlatNumber == 2005) { return "Recess A"; } else if (wallFlatNumber == 2006) { return "Recess B"; } else if (wallFlatNumber == 2007) { return "Recess C"; } else if (wallFlatNumber == 2010) { return "Wall Rug"; } else if (wallFlatNumber == 2011) { return "Numbers"; } else { return "None"; } } /** * @dev Get the character name based on the random number * @param rand The digits to use * @param baseline The baseline rarity * @return The character name */ function getCharacterName(uint rand, int baseline) external pure returns (string memory) { uint characterNumber = GlobalNumbers.getCharacterNumber(rand, baseline); if (characterNumber == 14000) { return "Sitting"; } else if (characterNumber == 14001) { return "Standing"; } else if (characterNumber == 14002) { return "Collapsed"; } else if (characterNumber == 14003) { return "Slouched"; } else if (characterNumber == 14004) { return "Meditating"; } else if (characterNumber == 14005) { return "Hunched"; } else { return "None"; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "@openzeppelin/contracts/utils/Strings.sol"; library GridHelper { uint256 public constant MAX_GRID_INDEX = 8; /** * @dev slice array of bytes * @param data The array of bytes to slice * @param start The start index * @param len The length of the slice * @return The sliced array of bytes */ function slice(bytes memory data, uint256 start, uint256 len) internal pure returns (bytes memory) { bytes memory b = new bytes(len); for (uint256 i = 0; i < len; i++) { b[i] = data[i + start]; } return b; } /** * @dev combine two arrays of strings * @param a The first array * @param b The second array * @return The combined array */ function combineStringArrays(string[] memory a, string[] memory b) public pure returns (string[] memory) { string[] memory c = new string[](a.length + b.length); for (uint256 i = 0; i < a.length; i++) { c[i] = a[i]; } for (uint256 i = 0; i < b.length; i++) { c[i + a.length] = b[i]; } return c; } /** * @dev combine two arrays of uints * @param a The first array * @param b The second array * @return The combined array */ function combineUintArrays(uint256[] memory a, uint256[] memory b) public pure returns (uint256[] memory) { uint256[] memory c = new uint256[](a.length + b.length); for (uint256 i = 0; i < a.length; i++) { c[i] = a[i]; } for (uint256 i = 0; i < b.length; i++) { c[i + a.length] = b[i]; } return c; } /** * @dev wrap a string in a transform group * @param x The x position * @param y The y position * @param data The data to wrap * @return The wrapped string */ function groupTransform(string memory x, string memory y, string memory data) internal pure returns (string memory) { return string.concat("<g transform='translate(", x, ",", y, ")'>", data, "</g>"); } /** * @dev convert a uint to bytes * @param x The uint to convert * @return b The bytes */ function uintToBytes(uint256 x) internal pure returns (bytes memory b) { b = new bytes(32); assembly { mstore(add(b, 32), x) } // first 32 bytes = length of the bytes value } /** * @dev convert bytes with length equal to bytes32 to uint * @param value The bytes to convert * @return The uint */ function bytesToUint(bytes memory value) internal pure returns(uint) { uint256 num = uint256(bytes32(value)); return num; } /** * @dev convert bytes with length less than bytes32 to uint * @param a The bytes to convert * @return The uint */ function byteSliceToUint (bytes memory a) internal pure returns(uint) { bytes32 padding = bytes32(0); bytes memory formattedSlice = slice(bytes.concat(padding, a), 1, 32); return bytesToUint(formattedSlice); } /** * @dev get a byte from a random number at a given position * @param rand The random number * @param slicePosition The position of the byte to slice * @return The random byte */ function getRandByte(uint rand, uint slicePosition) internal pure returns(uint) { bytes memory bytesRand = uintToBytes(rand); bytes memory part = slice(bytesRand, slicePosition, 1); return byteSliceToUint(part); } /** * @dev convert a string to a uint * @param s The string to convert * @return The uint */ function stringToUint(string memory s) internal pure returns (uint) { bytes memory b = bytes(s); uint result = 0; for (uint256 i = 0; i < b.length; i++) { uint256 c = uint256(uint8(b[i])); if (c >= 48 && c <= 57) { result = result * 10 + (c - 48); } } return result; } /** * @dev repeat an object a given number of times with given offsets * @param object The object to repeat * @param times The number of times to repeat * @param offsetBytes The offsets to use * @return The repeated object */ function repeatGivenObject(string memory object, uint times, bytes memory offsetBytes) internal pure returns (string memory) { // uint sliceSize = offsetBytes.length / (times * 2); // /2 for x and y require(offsetBytes.length % (times * 2) == 0, "offsetBytes length must be divisible by times * 2"); string memory output = ""; for (uint256 i = 0; i < times; i++) { string memory xOffset = string(slice(offsetBytes, 2*i * offsetBytes.length / (times * 2), offsetBytes.length / (times * 2))); string memory yOffset = string(slice(offsetBytes, (2*i + 1) * offsetBytes.length / (times * 2), offsetBytes.length / (times * 2))); output = string.concat( output, groupTransform(xOffset, yOffset, object) ); } return output; } /** * @dev convert a single string to an array of uints * @param values The string to convert * @param numOfValues The number of values in the string * @param lengthOfValue The length of each value in the string * @return The array of uints */ function setUintArrayFromString(string memory values, uint numOfValues, uint lengthOfValue) internal pure returns (uint[] memory) { uint[] memory output = new uint[](numOfValues); for (uint256 i = 0; i < numOfValues; i++) { output[i] = stringToUint(string(slice(bytes(values), i*lengthOfValue, lengthOfValue))); } return output; } /** * @dev get the sum of an array of uints * @param arr The array to sum * @return The sum */ function getSumOfUintArray(uint[] memory arr) internal pure returns (uint) { uint sum = 0; for (uint i = 0; i < arr.length; i++) { sum += arr[i]; } return sum; } /** * @dev constrain a value to the range 0-255, must be between -255 and 510 * @param value The value to constrain * @return The constrained value */ function constrainToHex(int value) internal pure returns (uint) { require(value >= -255 && value <= 510, "Value out of bounds."); if (value < 0) { // if negative, make positive return uint(0 - value); } else if (value > 255) { // if greater than 255, count back from 255 return uint(255 - (value - 255)); } else { return uint(value); } } /** * @dev create an array of equal probabilities for a given number of values * @param numOfValues The number of values * @return The array of probabilities */ function createEqualProbabilityArray(uint numOfValues) internal pure returns (uint[] memory) { uint oneLess = numOfValues - 1; uint[] memory probabilities = new uint[](oneLess); for (uint256 i = 0; i < oneLess; ++i) { probabilities[i] = 256 * (i + 1) / numOfValues; } return probabilities; } /** * @dev get a single object from a string of object numbers * @param objectNumbers The string of objects * @param channelValue The hex value of the channel * @param numOfValues The number of values in the string * @param valueLength The length of each value in the string * @return The object */ function getSingleObject(string memory objectNumbers, uint channelValue, uint numOfValues, uint valueLength) internal pure returns (uint) { // create probability array assuming all objects have equal probability uint[] memory probabilities = createEqualProbabilityArray(numOfValues); uint[] memory objectNumbersArray = setUintArrayFromString(objectNumbers, numOfValues, valueLength); uint oneLess = numOfValues - 1; for (uint256 i = 0; i < oneLess; ++i) { if (channelValue < probabilities[i]) { return objectNumbersArray[i]; } } return objectNumbersArray[oneLess]; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./CommonSVG.sol"; interface ILibrary { function getPart() external view returns (string memory); } contract GlobalSVG { constructor(address[13] memory allLibraries) { libraryDeployments = allLibraries; } address[13] public libraryDeployments; string internal constant TEXTURE_CSS_OPEN = ":root { --grey: hsl(0, 0%, 10%); --anim-speed: "; string internal constant TEXTURE_CSS_MID = "s; --rdm-seed: 0."; string internal constant TEXTURE_CSS_CLOSE = "; --anim-scale-0: 1; --anim-scale-50: 5; --anim-scale-100: 1; --end-rotation: calc(var(--rdm-seed) * 360); --num-rectangles: 7; } .pulsateInOutOld { animation: pulsateInOutOld var(--anim-speed) infinite linear; } @keyframes infinityWellRect { 0% { opacity: 0; transform: scale(1.1) rotate(0deg); transform-origin: 78px 90px; } 10% { opacity: 1; } 100% { opacity: 1; transform: scale(0) rotate(calc(var(--end-rotation) * 1deg)); transform-origin: 78px 90px; } } .infinityWell { animation: infinityWell var(--anim-speed) infinite linear forwards; } .infinityWellRect { animation: infinityWell var(--anim-speed) infinite linear forwards; } .rt-0 { animation: infinityWellRect var(--anim-speed) infinite linear; } .rt-1 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 1); } .rt-2 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 2); } .rt-3 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 3); } .rt-4 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 4); } .rt-5 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 5); } .rt-6 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 6); } .rt-7 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 7); } }"; string internal constant PATTERN_CSS_OPEN = ":root { --anim-speed: "; string internal constant PATTERN_CSS_CLOSE = "s; --anim-scale-0: 1; --anim-scale-50: 2; --anim-scale-100: 1; } @keyframes pulsateInOutOld { 0% { transform: scale(var(--anim-scale-0)); transform-origin: 78px 90px; } 50% { transform: scale(var(--anim-scale-50)); transform-origin: 78px 90px; } 100% { transform: scale(var(--anim-scale-100)); transform-origin: 78px 90px; } } .pulsateInOutOld { animation: pulsateInOutOld var(--anim-speed) infinite linear; }"; function getAnimationSpeed(int baseline) internal pure returns (string memory) { uint patternSpeed = 0; uint textureSpeed = uint(baseline) % 30; if (baseline > 185 || baseline < 70) { patternSpeed = 10 + uint(baseline) % 11; } if (baseline < 70) { return string.concat( TEXTURE_CSS_OPEN, Strings.toString(patternSpeed), TEXTURE_CSS_MID, Strings.toString(textureSpeed), TEXTURE_CSS_CLOSE ); } else { return string.concat( PATTERN_CSS_OPEN, Strings.toString(patternSpeed), PATTERN_CSS_CLOSE ); } } function getClosingSVG() external pure returns (string memory) { return string.concat( "<g id='shell-vignette' style='mix-blend-mode:normal'><rect fill='url(#vig1-u-vig1-fill)' width='1080' height='1080'/></g>", "</g>", "</svg>" ); } function getShell(string memory flip, uint rand, int baseline, string memory dataInfo) external pure returns (string memory) { return string.concat( CommonSVG.SHELL_OPEN, flip, CommonSVG.SHELL_CLOSE, dataInfo, CommonSVG.createShellOpacity(rand, baseline) ); } function getOpeningSVG(string memory machine, uint colourValue, uint rand, int baseline) external view returns (string memory) { string memory output = string.concat( CommonSVG.SVG_START, CommonSVG.getshellColours(machine, colourValue), CommonSVG.createShellPattern(rand, baseline), ILibrary(libraryDeployments[0]).getPart(), ILibrary(libraryDeployments[1]).getPart() ); output = string.concat( output, ILibrary(libraryDeployments[2]).getPart(), ILibrary(libraryDeployments[3]).getPart(), ILibrary(libraryDeployments[4]).getPart(), ILibrary(libraryDeployments[5]).getPart(), ILibrary(libraryDeployments[6]).getPart() ); output = string.concat( output, ILibrary(libraryDeployments[7]).getPart(), ILibrary(libraryDeployments[8]).getPart(), CommonSVG.TEMP_STYLE, CommonSVG.STYLE, getAnimationSpeed(baseline) ); return string.concat( output, ILibrary(libraryDeployments[9]).getPart(), ILibrary(libraryDeployments[10]).getPart(), ILibrary(libraryDeployments[11]).getPart(), ILibrary(libraryDeployments[12]).getPart(), CommonSVG.STYLE_CLOSE ); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; library Noise { // Normal distribution function getNoiseArrayZero() external pure returns (int256[256] memory) { int[256] memory noiseArray = [int(8), 16, 24, 32, 40, 40, 48, 48, 48, 56, 56, 64, 64, 64, 64, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 80, 80, 80, 80, 80, 80, 80, 80, 88, 88, 88, 88, 88, 88, 88, 88, 88, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 176, 176, 176, 176, 176, 176, 176, 176, 176, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 192, 192, 192, 192, 200, 200, 200, 200, 200, 200, 200, 208, 208, 216, 224, 232, 240, 248]; return noiseArray; } // Linear -64 -> 63 function getNoiseArrayOne() external pure returns (int256[] memory) { return createLinearNoiseArray(128); } // Linear -16 -> 15 function getNoiseArrayTwo() external pure returns (int256[] memory) { return createLinearNoiseArray(32); } // Linear -32 -> 31 function getNoiseArrayThree() external pure returns (int256[] memory) { return createLinearNoiseArray(64); } // Create a linear noise array function createLinearNoiseArray(uint range) internal pure returns (int256[] memory) { int[] memory output = new int[](256); require(256 % range == 0, "range must be a factor of 256"); require(range % 2 == 0, "range must be even"); uint numOfCycles = 256 / range; int halfRange = int(range / 2); for (uint i = 0; i < numOfCycles; i++) { for (uint j = 0; j < range; ++j) { output[i * range + j] = int(j) - halfRange; } } return output; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.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 `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); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for bit twiddling and boolean operations. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBit.sol) /// @author Inspired by (https://graphics.stanford.edu/~seander/bithacks.html) library LibBit { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BIT TWIDDLING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Find last set. /// Returns the index of the most significant bit of `x`, /// counting from the least significant bit position. /// If `x` is zero, returns 256. /// Equivalent to `log2(x)`, but without reverting for the zero case. function fls(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(8, iszero(x)) r := or(r, shl(7, lt(0xffffffffffffffffffffffffffffffff, x))) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) // For the remaining 32 bits, use a De Bruijn lookup. x := shr(r, x) x := or(x, shr(1, x)) x := or(x, shr(2, x)) x := or(x, shr(4, x)) x := or(x, shr(8, x)) x := or(x, shr(16, x)) // forgefmt: disable-next-item r := or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))), 0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f)) } } /// @dev Count leading zeros. /// Returns the number of zeros preceding the most significant one bit. /// If `x` is zero, returns 256. function clz(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { let t := add(iszero(x), 255) r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) // For the remaining 32 bits, use a De Bruijn lookup. x := shr(r, x) x := or(x, shr(1, x)) x := or(x, shr(2, x)) x := or(x, shr(4, x)) x := or(x, shr(8, x)) x := or(x, shr(16, x)) // forgefmt: disable-next-item r := sub(t, or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))), 0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f))) } } /// @dev Find first set. /// Returns the index of the least significant bit of `x`, /// counting from the least significant bit position. /// If `x` is zero, returns 256. /// Equivalent to `ctz` (count trailing zeros), which gives /// the number of zeros following the least significant one bit. function ffs(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(8, iszero(x)) // Isolate the least significant bit. x := and(x, add(not(x), 1)) r := or(r, shl(7, lt(0xffffffffffffffffffffffffffffffff, x))) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) // For the remaining 32 bits, use a De Bruijn lookup. // forgefmt: disable-next-item r := or(r, byte(shr(251, mul(shr(r, x), shl(224, 0x077cb531))), 0x00011c021d0e18031e16140f191104081f1b0d17151310071a0c12060b050a09)) } } /// @dev Returns the number of set bits in `x`. function popCount(uint256 x) internal pure returns (uint256 c) { /// @solidity memory-safe-assembly assembly { let max := not(0) let isMax := eq(x, max) x := sub(x, and(shr(1, x), div(max, 3))) x := add(and(x, div(max, 5)), and(shr(2, x), div(max, 5))) x := and(add(x, shr(4, x)), div(max, 17)) c := or(shl(8, isMax), shr(248, mul(x, div(max, 255)))) } } /// @dev Returns whether `x` is a power of 2. function isPo2(uint256 x) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { // Equivalent to `x && !(x & (x - 1))`. result := iszero(add(and(x, sub(x, 1)), iszero(x))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BOOLEAN OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `x & y`. function and(bool x, bool y) internal pure returns (bool z) { /// @solidity memory-safe-assembly assembly { z := and(x, y) } } /// @dev Returns `x | y`. function or(bool x, bool y) internal pure returns (bool z) { /// @solidity memory-safe-assembly assembly { z := or(x, y) } } /// @dev Returns a non-zero number if `b` is true, else 0. /// If `b` is from plain Solidity, the non-zero number will be 1. function toUint(bool b) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := b } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./GridHelper.sol"; import "./Noise.sol"; library GlobalNumbers { uint internal constant FLIPPER_WRAPPER_NUMBER = 13010; uint internal constant CHAR_MASK_GROUP_NUMBER = 14006; uint internal constant GROUP_CLOSE_NUMBER = 13000; // Small Asset numbers // 00000 - None // 06022 - Rat // 06021 - Skull // 06028 - Dead Plant // 06014 - Dog Bowl // 06027 - Bottle // 06026 - Can // 06006 - Bong // 06004 - Martini // 06011 - Books // 06000 - Lavalamp // 06025 - Pineapple // 06029 - Watermelon // 06020 - Lizard string internal constant SMALL_ASSET_NUMBERS = "0000006022060210602806014060270602606006060040601106000060250602906020"; // Large Asset numbers // 00000 - None // 02002 - Pit // 06013 - Toilet // 02001 - Pit with Grate // 02009 - Spikes B // 02008 - Spikes A // 02004 - Ladder // 02003 - Stairs // 06008 - Fridge // 06019 - Stool // 06009 - Circular Rug // 06023 - Desk Chair // 06024 - Cactus (Large) // 06030 - Gramaphone // 06018 - Cello // 06017 - Harp string internal constant LARGE_ASSET_NUMBERS = "00000020020601302001020090200802004020030600806019060090602306024060300601806017"; // Out Wall numbers // 06005 - Peephole A // 06007 - Peephole B // 06016 - Megaphone // 06010 - CCTV string internal constant OUT_WALL_NUMBERS = "0000006005060070601606010"; // Flat Wall numbers // 02000 - Crack // 02011 - Numbers // 02007 - Recess C // 02006 - Recess B // 02005 - Recess A // 02010 - Wall Rug string internal constant FLAT_WALL_NUMBERS = "00000020000201102007020060200502010"; // Expansion Props - 9 values // None // Crack // Recess A // Recess B // Recess C // Pit // Grate // Stairs // Ladder string internal constant EXPANSION_PROPS_NUMBERS = "000000200002005020060200702002020010200302004"; // Character Lever - 8 values // LEVER D // LEVER C // LEVER B // LEVER A // DETAILED LEVER D // DETAILED LEVER C // DETAILED LEVER B // DETAILED LEVER A string internal constant CHARACTER_LEVER_NUMBERS = "0300003001030020300303016030170301803019"; // Character - 7 values // 00000 - None // 14002 - COLLAPSED // 14005 - HUNCHED // 14003 - SLOUCHED // 14001 - STANDING // 14000 - SITTING // 14004 - MEDITATING string internal constant CHARACTER_NUMBERS = "00000140021400514003140011400014004"; /** * @dev Returns the small asset number based on the digits * @param rand The digits to use * @return The small asset number */ function getSmallAssetNumber(uint rand, int baseline) external pure returns (uint) { uint smallAssetDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 20)] + baseline); return GridHelper.getSingleObject(SMALL_ASSET_NUMBERS, smallAssetDigits, 14, 5); } /** * @dev Returns the large asset number based on the digits * @param rand The digits to use * @return The large asset number */ function getLargeAssetNumber(uint rand, int baseline) external pure returns (uint) { uint largeAssetDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 21)] + baseline); return GridHelper.getSingleObject(LARGE_ASSET_NUMBERS, largeAssetDigits, 16, 5); } /** * @dev Returns the out wall number based on the digits * @param rand The digits to use * @return The out wall number */ function getOutWallNumber(uint rand, int baseline) external pure returns (uint) { uint outWallDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 22)] + baseline); return GridHelper.getSingleObject(OUT_WALL_NUMBERS, outWallDigits, 5, 5); } /** * @dev Returns the flat wall number based on the digits * @param rand The digits to use * @return The flat wall number */ function getFlatWallNumber(uint rand, int baseline) external pure returns (uint) { uint flatWallDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 23)] + baseline); return GridHelper.getSingleObject(FLAT_WALL_NUMBERS, flatWallDigits, 7, 5); } /** * @dev Returns the character lever number based on the digits and state * @param rand The digits to use * @return The character lever number */ function getCharacterLeverNumber(uint rand, int baseline) internal pure returns (uint) { uint characterLeverDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 30)] + baseline); return GridHelper.getSingleObject(CHARACTER_LEVER_NUMBERS, characterLeverDigits, 8, 5); } /** * @dev Returns the character number based on the digits and state * @param rand The digits to use * @return The character number */ function getCharacterNumber(uint rand, int baseline) internal pure returns (uint) { uint characterDigits = GridHelper.constrainToHex(Noise.getNoiseArrayTwo()[GridHelper.getRandByte(rand, 31)] + baseline); return GridHelper.getSingleObject(CHARACTER_NUMBERS, characterDigits, 7, 5); } /** * @dev Returns the character number and lever number based on the digits and state * @param rand The digits to use * @param flip Whether to flip the character * @return The character number and lever numbers */ function getCharacterNumberAndLeverNumber(uint rand, bool flip, int baseline) external pure returns (uint[5] memory) { uint characterNumber = getCharacterNumber(rand, baseline); uint characterLeverNumber = getCharacterLeverNumber(rand, baseline); uint armMask = 0; if (characterNumber == 14001 || characterNumber == 14003 || characterNumber == 14005) { armMask = CHAR_MASK_GROUP_NUMBER; } uint flipOpen = 0; uint flipClose = 0; if (flip) { flipOpen = FLIPPER_WRAPPER_NUMBER; flipClose = GROUP_CLOSE_NUMBER; } return [flipOpen, characterLeverNumber, armMask, characterNumber, flipClose]; } /** * @dev Returns the expansion prop number based on the digits * @param rand The digits to use * @param baseline The baseline to use * @param offsetNumbers The offset numbers to use * @param numOptions The number of options * @return The expansion prop number */ function getSingleOffset(uint rand, int baseline, string memory offsetNumbers, uint numOptions) external pure returns (string memory) { uint offsetDigits1 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 20)] + baseline); uint offsetDigits2 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 21)] + baseline); uint offsetDigits3 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 22)] + baseline); uint finalOffsetDigits = (offsetDigits1 + offsetDigits2 + offsetDigits3) / 3; return string(GridHelper.slice(bytes(offsetNumbers), (finalOffsetDigits % numOptions)*8, 8)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./TraitBase.sol"; contract AssetRetriever { TraitBase[] internal traitBases; constructor(TraitBase[] memory _traitBases) { traitBases = _traitBases; } function getAsset(uint assetID) public view returns (string memory) { if (assetID == 0) { return ""; } return traitBases[assetID / 1000 - 1].getAssetFromTrait(assetID); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./Environment.sol"; import "./Patterns.sol"; import "./GridHelper.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; library CommonSVG { // opening svg start tag string internal constant SVG_START = "<svg xmlns='http://www.w3.org/2000/svg' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' width='936' height='1080' xmlns:xlink='http://www.w3.org/1999/xlink'>"; string internal constant DUOTONE_DEFS = "<linearGradient id='lDT' gradientTransform='rotate(45)'><stop offset='0.2' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient><linearGradient id='rDT' gradientTransform='rotate(0)'><stop offset='0.2' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient><linearGradient id='fDT' gradientTransform='rotate(90)'><stop offset='0' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient>"; string internal constant SCRIPT = "<script type='text/javascript' href='https://demowebdevukssa2.z33.web.core.windows.net/html-svg/pocs/0311/anma.js' xlink:actuate='onLoad' xlink:show='other' xlink:type='simple' />"; // string internal constant SCRIPT = ""; string internal constant STYLE = "<style>"; string internal constant TEMP_STYLE = "<style> .no-animation * { animation: none !important; transition: none !important; } </style>"; string internal constant STYLE_CLOSE = "</style>"; string internal constant G_START = "<g>"; string internal constant FLIPPED = "<g style='transform:scaleX(-1);transform-origin:50% 50%;'>"; string internal constant NOT_FLIPPED = "<g style='transform:scaleX(1);transform-origin:50% 50%;'>"; string internal constant SHELL_OPEN = "<g style='transform:scaleX("; string internal constant SHELL_CLOSE = ");transform-origin:50% 50%;' id='shell' clip-path='url(#clipPathShell)' "; string internal constant ROTATIONS = "-40-45-45"; // 18 colours: light, base and dark for each of the 6 gradients string internal constant OBJECT_GRADIENTS_IDS = "c0lc0bc0dc1lc1bc1dc2lc2bc2dc3lc3bc3dc4lc4bc4dc5lc5bc5d"; string internal constant LIGHTEN_PERCENTAGES = "025000025"; // 25% lighter, 0% base, 25% darker string internal constant GRADIENT_STYLE_OPEN = "<style id='gradient-colors'> :root { "; string internal constant GRADIENT_STYLE_CLOSE = " } </style>"; string internal constant GLOBAL_COLOURS = "051093072042080068328072085327073074027087076025054060000000069000000050085092060082067051051093072060088081002087076000054060000000069000000050322092060322092056322092060322092056047084056046068047000000069000000050"; string internal constant GLOBAL_COLOURS_IDS = "g0g1g2g3g4g5g6g7"; string internal constant SHELL_COLOUR_IDS = "s2s1s0"; string internal constant CHARACTER_COLOUR_IDS = "r0"; // string internal constant x = "<g id='shell-vignette' style='mix-blend-mode:normal'><rect fill='url(#vig1-u-vig1-fill)' width='1080' height='1080'/></g>"; string internal constant VIGNETTE_GRADIENT = "<clipPath id='clipPathShell'><polygon points='0,270 468,0 936,270 936,810 468,1080 0,810'/></clipPath><radialGradient id='vig1-u-vig1-fill' cx='0' cy='0' r='0.5' spreadMethod='pad' gradientUnits='objectBoundingBox' gradientTransform='translate(0.43 0.5)'><stop id='vig1-u-vig1-fill-0' offset='50%' stop-color='#000' stop-opacity='0'/><stop id='vig1-u-vig1-fill-1' offset='100%' stop-color='#000' stop-opacity='0.3'/></radialGradient>"; // PATTERNS string internal constant PATTERNS_START = "<pattern id='shell-pattern' patternUnits='objectBoundingBox' x='0' y='0' width='"; string internal constant PATTERNS_HEIGHT = "' height='"; string internal constant PATTERNS_SCALE_OPEN = "' patternTransform=' scale("; string internal constant PATTERNS_SCALE_CLOSE = ")'><use xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#mp2-u-group-"; string internal constant PATTERNS_END = "' id='shell-pattern-use' class='pulsateInOutOld'/></pattern>"; string internal constant OPACITY_START = "<g id='leftWall'><polygon points='0,270 468,0 468,540 0,810' fill='url(#s0)' stroke='black'/><g id='leftWallPat' transform='skewY(-30)'><rect x='0' y='270' width='468' height='540' opacity='"; string internal constant OPACITY_MID_ONE = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g><polygon points='0,270 468,0 468,540 0,810' fill='url(#lDT)' stroke='black'/></g><g id='rightWall'><polygon points='468,540 468,0 936,270 936,810' fill='url(#s1)' stroke='black'/><g id='rightWallPat' transform='skewY(30)'><rect x='468' y='-270' width='468' height='540' opacity='"; string internal constant OPACITY_MID_TWO = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g><polygon points='468,540 468,0 936,270 936,810' fill='url(#rDT)' stroke='black'/></g><g id='floor'><polygon id='polygon-floor-border' points='0,810 468,1080 936,810 468,540' fill='url(#s2)' stroke='black'/><g id='floorPat' transform='translate(234 135) rotate(60)' transform-origin='0 540'><g transform='skewY(-30)' transform-origin='0 0'><rect id='floorPatRect' x='0' y='270' width='468' height='540' opacity='"; string internal constant OPACITY_END = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g></g><polygon id='polygon-floor-border-DT' points='0,810 468,1080 936,810 468,540' fill='url(#fDT)' stroke='black'/></g>"; function createObjectGradient(uint[6] memory colours, string memory id) internal pure returns (string memory) { string memory output = string.concat( "<linearGradient id='", id, "' x1='0%' y1='0%' x2='100%' y2='0%'><stop offset='0%' stop-color='hsl(", Strings.toString(colours[0]), ",", Strings.toString(colours[1]), "%," ); output = string.concat( output, Strings.toString(colours[2]), "%)'/><stop offset='100%' stop-color='hsl(", Strings.toString(colours[3]), ",", Strings.toString(colours[4]), "%,", Strings.toString(colours[5]), "%)'/></linearGradient>" ); return output; } function appendToGradientStyle(string memory gradientStyle, string memory id, uint h, uint s, uint l) internal pure returns (string memory) { return string.concat( gradientStyle, "--", id, ": hsl(", Strings.toString(h), ",", Strings.toString(s), "%,", Strings.toString(l), "%); " ); } function getshellColours(string memory machine, uint colourValue) external pure returns(string memory) { uint[] memory baseColours = Environment.getColours(machine, colourValue); // 12 colours, 3 values for each string memory gradientStyle = GRADIENT_STYLE_OPEN; // uint[] memory lightenBy = GridHelper.setUintArrayFromString(LIGHTEN_PERCENTAGES, 3, 3); string[] memory objectGradients = new string[](18); for (uint i = 0; i < 6; ++i) { for (uint j = 0; j < 3; ++j) { objectGradients[i*3+j] = createObjectGradient([baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2], baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]], string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3))); if (j == 1) { gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3)), baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2]); } else { gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3)), baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]); } } } // SHELL COLOURS string[] memory shellColours = new string[](3); for (uint i = 0; i < 3; ++i) { shellColours[i] = createObjectGradient([baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2], baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]], string(GridHelper.slice(bytes(SHELL_COLOUR_IDS), i*2, 2))); } // GLOBAL COLOURS uint[] memory globalColours = GridHelper.setUintArrayFromString(GLOBAL_COLOURS, 72, 3); uint globalOffset = 0; if (colourValue > 170) { globalOffset = 48; } else if (colourValue > 84) { globalOffset = 24; } for (uint i = 0; i < 8; ++i) { gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(GLOBAL_COLOURS_IDS), i*2, 2)), globalColours[i*3+globalOffset], globalColours[i*3+1+globalOffset], globalColours[i*3+2+globalOffset]); } // CHARACTER COLOURs gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(CHARACTER_COLOUR_IDS), 0, 2)), baseColours[0], baseColours[1], 90); gradientStyle = string.concat(gradientStyle, GRADIENT_STYLE_CLOSE); string memory returnDefs = string.concat( gradientStyle, "<defs>", VIGNETTE_GRADIENT, DUOTONE_DEFS ); for (uint i = 0; i < 18; ++i) { returnDefs = string.concat(returnDefs, objectGradients[i]); } for (uint i = 0; i < 3; ++i) { returnDefs = string.concat(returnDefs, shellColours[i]); } returnDefs = string.concat(returnDefs, "</defs>"); return returnDefs; } function createShellPattern(uint rand, int baseline) external pure returns(string memory) { return string.concat( PATTERNS_START, "0.330", // width PATTERNS_HEIGHT, "0.330", // height PATTERNS_SCALE_OPEN, Patterns.getScale(rand, baseline), PATTERNS_SCALE_CLOSE, Patterns.getPatternName(rand, baseline), PATTERNS_END ); } function createShellOpacity(uint rand, int baseline) external pure returns(string memory) { return string.concat( OPACITY_START, Patterns.getOpacity(rand, baseline, 0), OPACITY_MID_ONE, Patterns.getOpacity(rand, baseline, 1), OPACITY_MID_TWO, Patterns.getOpacity(rand, baseline, 2), OPACITY_END ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 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 10, 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 * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; interface IAssetFromID { function getAssetFromID(uint assetID) external view returns (string memory); } contract TraitBase { address[] internal implementationAddresses; constructor(address[] memory addresses) { implementationAddresses = addresses; } function getAssetFromTrait(uint assetID) external view returns (string memory) { string memory asset = ""; for (uint i = 0; i < implementationAddresses.length;) { asset = IAssetFromID(implementationAddresses[i]).getAssetFromID(assetID); if (bytes(asset).length > 0) { return asset; } unchecked { ++i; } } return ""; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./GridHelper.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; library Environment { uint internal constant TOTAL_BASIC_COLOURS = 5; uint internal constant TOTAL_EMBELLISHED_COLOURS = 6; uint internal constant TOTAL_DEGRADED_COLOURS = 8; // includes grey // LW, RW, FLOOR string internal constant EXECUTIVE_COLOUR_PERCENTAGES = "040020025000070000"; string internal constant LAB_COLOUR_PERCENTAGES = "040020025000070000"; string internal constant FACTORY_COLOUR_PERCENTAGES = "040020025000070000"; // Darker Gray, Orange, Dark Gray, Red, Light Gray, Orange, Lightest Gray, Red string internal constant EXECUTIVE_DEGRADED_HSL = "120001015120001035120001061120002088019068078019032045019058048002047049"; string internal constant LAB_DEGRADED_HSL = "120001015120001035120001061120002088156015049050047054276021058155037049"; string internal constant FACTORY_DEGRADED_HSL = "120001015120001035120001061120002088021042074203032059319029046243031039"; // EXECUTIVE // Combined without shades string internal constant EXECUTIVE_COLOURS_BASIC = "000000069240003029000000069240003029000000069000000069240003013000000069354100060240003013000000069240003013240003029047100050240003013240003029240003013240003029121082050240003013240003029240003013240003029221082050240003013354100060000100004000100004022100050041100050047100050021081004021081004030100013022100045221081088194090077200075078195086089200084076"; string internal constant EXECUTIVE_COLOURS_EMBELLISHED = "121082050093090004099074009095085054099075072093090004221082050194089004199074009195085054199075080194089004339082050314089004317074009313085054318075084314089004357061040040091044040091062040091044040091062040091044137093049197100052287100053347100053047100052287100053259100052184100052083100052050100050000100050083100052093063053082084048066100048053100050036100050066100048060087053061100042070100040101055042165100025070100040"; // Combined with shades string internal constant EXECUTIVE_COLOURS_BASIC_SHADE = "000000050240003029000000050240003029000000050000000050240003029000000050000086027240003029000000050240003029240003013047100032240003029240003013240003029240003013104079046240003029240003013240003029240003013204079046240003029000086027000061010000100007013091043041100045047100032022080008022081012030100015022100040204079087196071077180054080195093089195095092"; string internal constant EXECUTIVE_COLOURS_EMBELLISHED_SHADE = "104079046096071004080054015095093054095096068096071004204079046196071004180054015195093054195096068196071004322079046316071004299054015313093054313096068316071004357078056040091062040091044040091062040091044040091062168100054257100053317100053017100052047100056317100053284100052212092052155100052068100052032100050155100052093063057093068048075100048058100050047100050075100048060100062061100044065100041081077041137055037065100041"; // LAB // Combined without shades string internal constant LAB_COLOURS_BASIC = "185053039180055056185053039180095040181066049231095074252070052231095074210049067030100050168056095228081062168056095051093072182081087240060097253081078240060097224062081245080083352033081165032066027028078027033080037031079143014078000000100143014078237045053183099034207099060207099060040090096239066051176077048221081088194090077200075078195086089200084076"; string internal constant LAB_COLOURS_EMBELLISHED = "158100077228081062168056095051093072182081087168056095238100086253081078240060097224062081245080083253081078190054036252070052231095074210049067030100050252070052144090033040091044040091062040091044040091062040091044287100053047100052137093049347100053197100052287100053000100050050100050083100052184100052259100052083100052036100050053100050066100048082084048093063053082084048165100025101055042070100040061100042060087053070100040"; // Combined with shades string internal constant LAB_COLOURS_BASIC_SHADE = "181085042184045075181085042180059062181062052251085079251073027251085079211053076030100050182081087229047032182081087051090084180064063242083093252047060242083093224058089244079072004029080164031070021030079022034081023028075143014068183100080143014068237045048183099028239066051207099060041090092238072019176077048204079087196071077180054080195093089195095092"; string internal constant LAB_COLOURS_EMBELLISHED_SHADE = "169048056229047032182081087051090084180064063182081087241047074252047060242083093224058089244079072252047060184021040251073027251085079211053076030100050251073027147089054040091062040091044040091062040091044040091062317100053047100056168100054017100052257100053317100053032100050068100052155100052212092052284100052155100052047100050058100050075100048093068048093063057093068048137055037081077041065100041061100044060100062065100041"; // FACTORY // Combined without shades string internal constant FACTORY_COLOURS_BASIC = "232053033232052058232054032232051037232058059196085079193083063193048054193064047193089055231032035196085079231032035300085082000000085249069060196085079231032035300085082000000085266083081162085079197031035266083081000000085033098060196085068231032035196085068000000085300085082196085079231032035033100052000000085221081088194090077200075078195086089200084076"; string internal constant FACTORY_COLOURS_EMBELLISHED = "160073059280078043280077074340097062160071039280078043280094041340086057280084075340084055340087027340086057162085079266083081266083081197031035000000085266083081220067026040091044040091072040091044040091072040091044197100052287100053137093049347100053047100052287100053083100052050100050000100050259100052184100052050100050082084048066100048036100050053100050093063053082084048101055042070100040165100025060087053061100042070100040"; // Combined with shades string internal constant FACTORY_COLOURS_BASIC_SHADE = "232066056233054034232066067232071029232091066196084068193045040193073053193067051193070044229034024193083063229034024033098060000000052243039046193083063229034024033098060000000052359097059159084063195034025266086072000000052033098044193083052229034024193083052000000052321076067193083063229034024033098060000000052204079087196071077180054080195093089195095092"; string internal constant FACTORY_COLOURS_EMBELLISHED_SHADE = "243039046300085082193083063229034024000000052300085082249069060033098060196085079231032035000000085033098060159084063359097059266086072195034025000000052359097059220096052040091072040091044040091072040091044220087032257100053317100053168100054017100052047100056317100053155100052068100052032100050284100052212092052068100052093068048075100048047100050058100050093063057093068048081077041065100041137055037060100062061100044065100041"; string internal constant DEGRADED_COLOUR_PERCENTAGES = "064115153191217237251256"; string internal constant BASIC_COLOUR_PERCENTAGES = "064115153191217237251256"; string internal constant EMBELLISHED_COLOUR_PERCENTAGES = "064115153191217237251256"; function increaseValueByPercentage(uint baseLightness, uint percentage) internal pure returns(uint) { uint value = baseLightness + (baseLightness * percentage / 100); if (value > 100) { value = 100; } return value; } function decreaseValueByPercentage(uint baseLightness, uint percentage) internal pure returns (uint) { return baseLightness - (baseLightness * percentage / 100); } function getColours(string memory machine, uint baseValue) external pure returns (uint[] memory) { uint[] memory colourArray = new uint[](36); // 6 colours, 3*2 values each uint colourIndex = getColourIndex(baseValue); if (colourIndex < 8) { // degraded colourArray = getDegradedShell(colourArray, machine, baseValue); } else { // basic or embellished colourArray = getBasicEmbelishedShell(colourArray, machine, baseValue); } return colourArray; } function getColourIndex(uint baseValue) internal pure returns(uint) { uint[] memory colourProbabilitiesArray = GridHelper.createEqualProbabilityArray(24); uint index = 100; for (uint i = 0; i < colourProbabilitiesArray.length; ++i) { if (baseValue < colourProbabilitiesArray[i]) { index = i; break; } } if (index == 100) { index = 23; } return index; } function selectBasicEmbellishedPalette(string memory machine, uint baseValue) internal pure returns (string[] memory) { string[] memory basicPalette = new string[](2); uint index = getColourIndex(baseValue); uint state = 2; if (index < 16) { state = 1; } index = index % 8; uint size; if (state == 1) { size = TOTAL_BASIC_COLOURS * 9; } else { size = TOTAL_EMBELLISHED_COLOURS * 9; } // could be simplified by storing every colour in a single string but this is more readable and easier to change if (keccak256(bytes(machine)) == keccak256(bytes("Altar"))) { // executive if (state == 1) { basicPalette[0] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_BASIC), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_BASIC_SHADE), index * size, size)); } else { basicPalette[0] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_EMBELLISHED), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_EMBELLISHED_SHADE), index * size, size)); } } else if (keccak256(bytes(machine)) == keccak256(bytes("Apparatus")) || keccak256(bytes(machine)) == keccak256(bytes("Cells"))) { // lab if (state == 1) { basicPalette[0] = string(GridHelper.slice(bytes(LAB_COLOURS_BASIC), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(LAB_COLOURS_BASIC_SHADE), index * size, size)); } else { basicPalette[0] = string(GridHelper.slice(bytes(LAB_COLOURS_EMBELLISHED), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(LAB_COLOURS_EMBELLISHED_SHADE), index * size, size)); } } else { // factory if (state == 1) { basicPalette[0] = string(GridHelper.slice(bytes(FACTORY_COLOURS_BASIC), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(FACTORY_COLOURS_BASIC_SHADE), index * size, size)); } else { basicPalette[0] = string(GridHelper.slice(bytes(FACTORY_COLOURS_EMBELLISHED), index * size, size)); basicPalette[1] = string(GridHelper.slice(bytes(FACTORY_COLOURS_EMBELLISHED_SHADE), index * size, size)); } } return basicPalette; } function getDegradedShell(uint[] memory colourArray, string memory machine, uint baseValue) internal pure returns (uint[] memory) { string memory degradedHsl; string memory degradedPercentages; if (keccak256(bytes(machine)) == keccak256(bytes("Altar"))) { // executive degradedHsl = EXECUTIVE_DEGRADED_HSL; degradedPercentages = EXECUTIVE_COLOUR_PERCENTAGES; } else if (keccak256(bytes(machine)) == keccak256(bytes("Apparatus")) || keccak256(bytes(machine)) == keccak256(bytes("Cells"))) { // lab degradedHsl = LAB_DEGRADED_HSL; degradedPercentages = LAB_COLOUR_PERCENTAGES; } else { // factory degradedHsl = FACTORY_DEGRADED_HSL; degradedPercentages = FACTORY_COLOUR_PERCENTAGES; } uint index = getColourIndex(baseValue); uint[] memory singleColour = new uint[](3); // h, s, l for (uint i = 0; i < 3; ++i) { singleColour[i] = GridHelper.stringToUint(string(GridHelper.slice(bytes(degradedHsl), (index)*9 + 3*i, 3))); // 9 = h,s,l to 3 significant digits } uint[] memory colourPercentages = GridHelper.setUintArrayFromString(degradedPercentages, 6, 3); for (uint i = 0; i < 12; ++i) { // 12 = 6 colours, 2 values each colourArray[i*3] = singleColour[0]; colourArray[i*3+1] = singleColour[1]; colourArray[i*3+2] = increaseValueByPercentage(singleColour[2], colourPercentages[i%6]); } return colourArray; } function getBasicEmbelishedShell(uint[] memory colourArray, string memory machine, uint baseValue) internal pure returns (uint[] memory) { uint index = getColourIndex(baseValue); uint state = 2; if (index < 16) { state = 1; } uint numColours; if (state == 1) { numColours = TOTAL_BASIC_COLOURS; } else { numColours = TOTAL_EMBELLISHED_COLOURS; } string[] memory colourAvailableStrings = selectBasicEmbellishedPalette(machine, baseValue); uint[] memory coloursAvailable = GridHelper.setUintArrayFromString(colourAvailableStrings[0], numColours*3, 3); uint[] memory coloursAvailableShade = GridHelper.setUintArrayFromString(colourAvailableStrings[1], numColours*3, 3); for (uint i = 0; i < 6; ++i) { for (uint j = 0; j < 3; ++j) { // j = h, s, l // Duplicate colours for linear gradient colourArray[2*i*3+j] = coloursAvailable[3*(i % numColours) + j]; colourArray[(2*i+1)*3+j] = coloursAvailableShade[3*(i % numColours) + j]; } } return colourArray; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import "./GridHelper.sol"; import "./Noise.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; library Patterns { // 20 to 2 inclusive in 0.5 decrements string internal constant ANIMATED_TEXTURE_NUMBERS = "20.019.018.017.016.015.014.013.012.011.010.09.008.007.006.005.004.003.002.00"; // 4 to 1 inclusive in 0.1 decriments string internal constant TEXTURE_SCALE_NUMBERS = "4.03.93.83.73.63.53.43.33.23.13.02.92.82.72.62.52.42.32.22.12.01.91.81.71.61.51.41.31.21.11.0"; // 15 to 0.3 inclusive in 0.3 decriments string internal constant PATTERNS_SCALE_NUMBERS = "15.014.714.414.113.813.513.212.912.612.312.011.711.411.110.810.510.209.909.609.309.008.708.408.107.807.507.206.906.606.306.005.705.405.104.804.504.203.903.603.303.002.702.402.101.801.501.200.900.600.3"; string internal constant ANIMATED_TEXTURE_NAMES = "TEXT12TEXT14TEXT09TEXT10TEXT13TEXT11"; string internal constant TEXTURE_NAMES = "TEXT04TEXT01TEXT07TEXT05TEXT08TEXT02TEXT03TEXT06"; string internal constant PATTERNS_NAMES = "GEOM03GEOM04PIXE02AZTC10GEOM02GEOM01LOGI01GEOM05PIXE02AZTC01AZTC05AZTC03AZTC09AZTC02AZTC08AZTC04AZTC06AZTC07"; /** * @dev Get if the pattern is a texture or not based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return If the pattern is a texture or not */ function getIsTexture(uint rand, int baseline) public pure returns (bool) { uint textureDigits = GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 5)] + baseline); return textureDigits < 128; } /** * @dev Get the pattern name based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The pattern name */ function getPatternName(uint rand, int baseline) public pure returns (string memory) { uint patternDigits = GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 5)] + baseline); bool isTexture = getIsTexture(rand, baseline); if (!isTexture) { patternDigits -= 128; } patternDigits *= 2; bool isAnimatedTexture = baseline < 70; uint nameLength; uint nameCount; string memory names; if (isAnimatedTexture) { nameLength = 6; nameCount = 6; names = ANIMATED_TEXTURE_NAMES; } else if (isTexture && !isAnimatedTexture) { nameLength = 6; nameCount = 8; names = TEXTURE_NAMES; } else { nameLength = 6; nameCount = 18; names = PATTERNS_NAMES; } uint[] memory nameProbabilitiesArray = GridHelper.createEqualProbabilityArray(nameCount); uint oneLess = nameCount - 1; for (uint i = 0; i < oneLess; ++i) { if (patternDigits < nameProbabilitiesArray[i]) { return string(GridHelper.slice(bytes(names), i * nameLength, nameLength)); } } return string(GridHelper.slice(bytes(names), oneLess * nameLength, nameLength)); } /** * @dev Get the surface quantity based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The surface quantity */ function getSurfaceQuantity(uint rand, int baseline) public pure returns (bool[3] memory) { uint surfaceDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 6)] + baseline); if (baseline < 70) { surfaceDigits += 128; // animated textures should appear on 2+ surfaces } // LW, RW, FLOOR uint[] memory surfaceProbabilitiesArray = GridHelper.createEqualProbabilityArray(4); if (surfaceDigits < surfaceProbabilitiesArray[0]) { return [true, false, false]; } else if (surfaceDigits < surfaceProbabilitiesArray[1]) { return [false, true, false]; } else if (surfaceDigits < surfaceProbabilitiesArray[2]) { return [true, true, false]; } else { return [true, true, true]; } } /** * @dev Get the pattern scale based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The pattern scale */ function getScale(uint rand, int baseline) public pure returns (string memory) { uint scaleDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 7)] + baseline); bool isTexture = getIsTexture(rand, baseline); bool isAnimatedTexture = baseline < 70; uint scaleLength; uint scaleCount; string memory scales; if (isAnimatedTexture) { scaleLength = 4; scaleCount = 19; scales = ANIMATED_TEXTURE_NUMBERS; } else if (isTexture && !isAnimatedTexture) { scaleLength = 3; scaleCount = 31; scales = TEXTURE_SCALE_NUMBERS; } else { scaleLength = 4; scaleCount = 50; scales = PATTERNS_SCALE_NUMBERS; } uint[] memory scaleProbabilitiesArray = GridHelper.createEqualProbabilityArray(scaleCount); uint oneLess = scaleCount - 1; if (baseline > 185) { uint scaleValue = oneLess - (scaleDigits % 5); return string(GridHelper.slice(bytes(scales), scaleValue * scaleLength, scaleLength)); } for (uint i = 0; i < oneLess; ++i) { if (scaleDigits < scaleProbabilitiesArray[i]) { return string(GridHelper.slice(bytes(scales), i * scaleLength, scaleLength)); } } return string(GridHelper.slice(bytes(scales), oneLess * scaleLength, scaleLength)); } /** * @dev Get the pattern opacity based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @param surfaceNumber The surface number 0 is left wall, 1 is right wall, 2 is floor * @return The pattern opacity as a string */ function getOpacity(uint rand, int baseline, uint surfaceNumber) public pure returns (string memory) { uint opacityDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 8)] + baseline); bool[3] memory surfaceQuantity = getSurfaceQuantity(rand, baseline); if (!surfaceQuantity[surfaceNumber]) { return Strings.toString(0); } bool isTexture = getIsTexture(rand, baseline); if (isTexture) { // 100 -> 20 return Strings.toString(100 - (opacityDigits * 80 / 255 + 20)); } else { if (baseline > 185) { return Strings.toString(100); } else { // 25 -> 100 return Strings.toString(opacityDigits * 75 / 255 + 25); } } } /** * @dev Get the pattern rotation based on the baseline rarity and random number * @param rand The digits to use * @param baseline The baseline rarity * @return The pattern rotation in degrees from 0 to 45 */ // Only used for textures function getRotate(uint rand, int baseline) public pure returns (uint) { uint rotateDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 9)] + baseline); // 0 -> 45 return rotateDigits * 45 / 255; } }
{ "remappings": [ "@chainlink/=lib/chainlink/", "@openzeppelin/=lib/openzeppelin-contracts/", "ERC721A/=lib/ERC721A/contracts/", "base64-sol/=lib/base64/", "base64/=lib/base64/", "chainlink/=lib/chainlink/contracts/src/v0.8/dev/vendor/@arbitrum/nitro-contracts/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solady/=lib/solady/src/", "solmate/=lib/solady/lib/solmate/src/" ], "optimizer": { "enabled": true, "runs": 200, "details": { "constantOptimizer": true, "yul": true, "yulDetails": { "stackAllocation": true, "optimizerSteps": "" } } }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract Metadata","name":"metadata","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ApprovalCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"ApprovalQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"AuctionAlreadyStarted","type":"error"},{"inputs":[],"name":"AuctionNotActive","type":"error"},{"inputs":[],"name":"AuctionNotOver","type":"error"},{"inputs":[],"name":"BalanceQueryForZeroAddress","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BidTooSmall","type":"error"},{"inputs":[],"name":"CannotBidZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"CypherAlreadyClaimed","type":"error"},{"inputs":[],"name":"CypherClaimNotActive","type":"error"},{"inputs":[],"name":"CypherClaimNotEnded","type":"error"},{"inputs":[],"name":"CypherClaimNotStarted","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"IncorrectBidIncrement","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"MintERC2309QuantityExceedsLimit","type":"error"},{"inputs":[],"name":"MintToZeroAddress","type":"error"},{"inputs":[],"name":"MintZeroQuantity","type":"error"},{"inputs":[],"name":"NftsNotAllMinted","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"NoBidToClaim","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NotOwnerOfCypher","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","type":"error"},{"inputs":[],"name":"OwnerQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"OwnershipNotInitializedForExtraData","type":"error"},{"inputs":[{"internalType":"uint256","name":"genId","type":"uint256"}],"name":"SeedNotSet","type":"error"},{"inputs":[],"name":"TooManyRequested","type":"error"},{"inputs":[],"name":"TransferCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"TransferFromIncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"TransferNotSuccessful","type":"error"},{"inputs":[],"name":"TransferToNonERC721ReceiverImplementer","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"inputs":[],"name":"URIQueryForNonexistentToken","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"fromTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toTokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"ConsecutiveTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"genId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"seed","type":"uint256"}],"name":"RandomNumberGenerated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"genId","type":"uint256"}],"name":"RandomnessRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UserPlacesBid","type":"event"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAfterAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"claimCyphers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAllBidders","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentPricePerUnit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEndTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getIfCypherClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumBid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSeed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStartTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"bidder","type":"address"}],"name":"getUserBid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"placeBid","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"rawFulfillRandomWords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"s_subscriptionId","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startCypherClaimPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawRemainingNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60c06040523480156200001157600080fd5b50604051620025f4380380620025f4833981016040819052620000349162000172565b73271682deb8c4e0901d1a1550ad2e64d568e699096040518060400160405280601081526020016f414d616368696e65466f724479696e6760801b815250604051806040016040528060048152602001631053519160e21b8152508160029081620000a09190620002b2565b506003620000af8282620002b2565b50506000805550620000c133620000d9565b6001600160a01b039081166080521660a0526200037e565b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006001600160a01b0382165b92915050565b600062000138826200012b565b62000156816200013e565b81146200016257600080fd5b50565b805162000138816200014b565b600060208284031215620001895762000189600080fd5b600062000197848462000165565b949350505050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052602260045260246000fd5b600281046001821680620001e057607f821691505b602082108103620001f557620001f5620001b5565b50919050565b600062000138620002098381565b90565b6200021783620001fb565b81546008840282811b60001990911b908116901990911617825550505050565b6000620002468184846200020c565b505050565b818110156200026a576200026160008262000237565b6001016200024b565b5050565b601f82111562000246576000818152602090206020601f85010481016020851015620002975750805b620002ab6020601f8601048301826200024b565b5050505050565b81516001600160401b03811115620002ce57620002ce6200019f565b620002da8254620001cb565b620002e78282856200026e565b506020601f8211600181146200031f5760008315620003065750848201515b600019600885021c1981166002850217855550620002ab565b600084815260208120601f198516915b828110156200035157878501518255602094850194600190920191016200032f565b50848210156200036f5783870151600019601f87166008021c191681555b50505050600202600101905550565b60805160a051612249620003ab6000396000610fc301526000818161075f015261078701526122496000f3fe6080604052600436106102045760003560e01c8063715018a611610118578063a475b5dd116100a0578063e0d4ea371161006f578063e0d4ea371461055f578063e985e9c51461057f578063ecfc7ecc1461059f578063f2fde38b146105a7578063fc41b699146105c757600080fd5b8063a475b5dd14610502578063b88d4fde14610517578063c5b636001461052a578063c87b56dd1461053f57600080fd5b80637a2ffe31116100e75780637a2ffe311461046c5780638ac000211461048c5780638da5cb5b146104af57806395d89b41146104cd578063a22cb465146104e257600080fd5b8063715018a614610418578063738e901e1461042d57806374e94deb146104425780637817399e1461045757600080fd5b806323b872dd1161019b5780633ccfd60b1161016a5780633ccfd60b1461039057806342842e0e146103a55780634a27721c146103b85780636352211e146103d857806370a08231146103f857600080fd5b806323b872dd1461030f57806332cb6b0c1461032257806339c8ac89146103385780633a79d2e51461036e57600080fd5b8063095ea7b3116101d7578063095ea7b3146102a557806318160ddd146102b85780631f89f25e146102da5780631fe543e3146102ef57600080fd5b8063012c69961461020957806301ffc9a71461022057806306fdde0314610256578063081812fc14610278575b600080fd5b34801561021557600080fd5b5061021e6105e7565b005b34801561022c57600080fd5b5061024061023b3660046118e3565b61061c565b60405161024d919061190e565b60405180910390f35b34801561026257600080fd5b5061026b61066e565b60405161024d9190611972565b34801561028457600080fd5b50610298610293366004611994565b610700565b60405161024d91906119cf565b61021e6102b33660046119f1565b610744565b3480156102c457600080fd5b50600154600054035b60405161024d9190611a34565b3480156102e657600080fd5b506010546102cd565b3480156102fb57600080fd5b5061021e61030a366004611b42565b610754565b61021e61031d366004611b90565b6107d4565b34801561032e57600080fd5b506102cd61177081565b34801561034457600080fd5b506102cd610353366004611be0565b6001600160a01b03166000908152600c602052604090205490565b34801561037a57600080fd5b5061038361096c565b60405161024d9190611c5f565b34801561039c57600080fd5b5061021e6109cd565b61021e6103b3366004611b90565b610a6f565b3480156103c457600080fd5b506102406103d3366004611994565b610a8f565b3480156103e457600080fd5b506102986103f3366004611994565b610ab0565b34801561040457600080fd5b506102cd610413366004611be0565b610abb565b34801561042457600080fd5b5061021e610b0a565b34801561043957600080fd5b506102cd610b1e565b34801561044e57600080fd5b506011546102cd565b34801561046357600080fd5b5061021e610b42565b34801561047857600080fd5b5061021e610487366004611c70565b610c87565b34801561049857600080fd5b506104a26102eb81565b60405161024d9190611cbb565b3480156104bb57600080fd5b506008546001600160a01b0316610298565b3480156104d957600080fd5b5061026b610d07565b3480156104ee57600080fd5b5061021e6104fd366004611cdc565b610d16565b34801561050e57600080fd5b5061021e610d85565b61021e610525366004611da7565b610eb8565b34801561053657600080fd5b506102cd610f02565b34801561054b57600080fd5b5061026b61055a366004611994565b610f75565b34801561056b57600080fd5b506102cd61057a366004611994565b611046565b34801561058b57600080fd5b5061024061059a366004611e26565b6110ed565b61021e61111b565b3480156105b357600080fd5b5061021e6105c2366004611be0565b6112ad565b3480156105d357600080fd5b5061021e6105e2366004611994565b6112e4565b6105ef61137d565b6105fc62093a8042611e6f565b60105562093a8061060d8142611e6f565b6106179190611e6f565b601155565b60006301ffc9a760e01b6001600160e01b03198316148061064d57506380ac58cd60e01b6001600160e01b03198316145b806106685750635b5e139f60e01b6001600160e01b03198316145b92915050565b60606002805461067d90611e98565b80601f01602080910402602001604051908101604052809291908181526020018280546106a990611e98565b80156106f65780601f106106cb576101008083540402835291602001916106f6565b820191906000526020600020905b8154815290600101906020018083116106d957829003601f168201915b5050505050905090565b600061070b826113a7565b610728576040516333d1c03960e21b815260040160405180910390fd5b506000908152600660205260409020546001600160a01b031690565b610750828260016113ce565b5050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146107ca57337f000000000000000000000000000000000000000000000000000000000000000060405163073e64fd60e21b81526004016107c1929190611ec4565b60405180910390fd5b6107508282611475565b60006107df826114fb565b9050836001600160a01b0316816001600160a01b0316146108125760405162a1148160e81b815260040160405180910390fd5b60008281526006602052604090208054338082146001600160a01b0388169091141761085f5761084286336110ed565b61085f57604051632ce44b5f60e11b815260040160405180910390fd5b6001600160a01b03851661088657604051633a954ecd60e21b815260040160405180910390fd5b801561089157600082555b6001600160a01b038681166000908152600560205260408082208054600019019055918716808252919020805460010190554260a01b17600160e11b17600085815260046020526040812091909155600160e11b84169003610923576001840160008181526004602052604081205490036109215760005481146109215760008181526004602052604090208490555b505b83856001600160a01b0316876001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050505050565b606060138054806020026020016040519081016040528092919081815260200182805480156106f657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116109a6575050505050905090565b6109d561137d565b6117706109e56001546000540390565b14610a035760405163e1f59d7360e01b815260040160405180910390fd5b604051600090339047908381818185875af1925050503d8060008114610a45576040519150601f19603f3d011682016040523d82523d6000602084013e610a4a565b606091505b5050905080610a6c576040516312171d8360e31b815260040160405180910390fd5b50565b610a8a83838360405180602001604052806000815250610eb8565b505050565b600881901c6000908152600f602052604081205460ff83161c600116610668565b6000610668826114fb565b60006001600160a01b038216610ae4576040516323d3ad8160e21b815260040160405180910390fd5b506001600160a01b031660009081526005602052604090205467ffffffffffffffff1690565b610b1261137d565b610b1c600061157c565b565b6000600e54611770610b309190611edf565b601254610b3d9190611f08565b905090565b610384601154610b529190611e6f565b421080610b6e575062093a80601154610b6b9190611e6f565b42115b15610b8c5760405163058ebc1760e11b815260040160405180910390fd5b336000908152600c60205260408120549003610bbd573360405163b1b93d5f60e01b81526004016107c191906119cf565b6000610bc7610b1e565b336000908152600c6020526040812054919250610be48383611f08565b336000908152600c602052604081205590508015610c0657610c0633826115ce565b6000610c128484611f1c565b604051909150600090339083908381818185875af1925050503d8060008114610c57576040519150601f19603f3d011682016040523d82523d6000602084013e610c5c565b606091505b5050905080610c80573360405163159459a160e31b81526004016107c191906119cf565b5050505050565b6010544210610ca957604051630c51a79160e41b815260040160405180910390fd5b60008151905080600e6000828254610cc19190611e6f565b90915550600090505b81811015610cfc57610cf4838281518110610ce757610ce7611f30565b60200260200101516116cc565b600101610cca565b5061075033826115ce565b60606003805461067d90611e98565b3360008181526007602090815260408083206001600160a01b038716808552925291829020805460ff191685151517905590519091907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3190610d7990859061190e565b60405180910390a35050565b610d8d61137d565b600d54600154600054036000828152600b6020526040812091909155600d805491610db783611f46565b90915550506040516305d3b1d360e41b815260009073271682deb8c4e0901d1a1550ad2e64d568e6990990635d3b1d3090610e25907fff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92906102eb90600390620186a090600190600401611f75565b6020604051808303816000875af1158015610e44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e689190611fcc565b60008181526009602052604090819020849055519091507f9ac10fb18c93d33ad7b0a941897aef048d0f8d30756684e82b4552ba12764d4590610eac908490611a34565b60405180910390a15050565b610ec38484846107d4565b6001600160a01b0383163b15610efc57610edf848484846117d5565b610efc576040516368d2bf6b60e11b815260040160405180910390fd5b50505050565b600080600a610f0f610b1e565b610f199190611f08565b610f21610b1e565b610f2b9190611e6f565b9050662386f26fc100008111610f4957662386f26fc1000091505090565b662386f26fc10000610f5b8183611f1c565b610f659083611edf565b610f6f9190611e6f565b91505090565b60606000610f8283611046565b905080600003610fac576040518060600160405280603581526020016121df603591399392505050565b6040516309419a8160e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906325066a0490610ffa9086908590600401611fed565b600060405180830381865afa158015611017573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261103f9190810190612060565b9392505050565b60006110556001546000540390565b8210611076578160405163ed15e6cf60e01b81526004016107c19190611a34565b60005b600d548110156110e4576000818152600b60205260409020548310156110dc576000818152600a60209081526040918290205491516110bc91839187910161209b565b60408051601f198184030181529190528051602090910120949350505050565b600101611079565b50600092915050565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b6011544210158061112d575060105442105b1561114b576040516334dc687f60e11b815260040160405180910390fd5b34600081900361116e5760405163600af40560e01b815260040160405180910390fd5b61117f662386f26fc1000082611f1c565b1561119f5780604051633974ac6360e01b81526004016107c19190611a34565b336000908152600c60205260408120546111b99083611e6f565b90506111c3610f02565b8110156111e557816040516322afe53560e21b81526004016107c19190611a34565b6011546111f461038442611e6f565b111561120a5761120661038442611e6f565b6011555b80820361125457601380546001810182556000919091527f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0900180546001600160a01b031916331790555b81601260008282546112669190611e6f565b9091555050336000818152600c602052604090819020839055517f0abe00b0e1d3ed939902c6a41c86c34ea31064f2084d386bc04349e3106aea4791610eac9184906120b4565b6112b561137d565b6001600160a01b0381166112db5760405162461bcd60e51b81526004016107c1906120c2565b610a6c8161157c565b6112ec61137d565b601054158061130a575062093a806011546113079190611e6f565b42105b156113285760405163058ebc1760e11b815260040160405180910390fd5b611770816113396001546000540390565b6113439190611e6f565b111561136257604051638d83cdd760e01b815260040160405180910390fd5b610a6c6113776008546001600160a01b031690565b826115ce565b6008546001600160a01b03163314610b1c5760405162461bcd60e51b81526004016107c19061213c565b6000805482108015610668575050600090815260046020526040902054600160e01b161590565b60006113d983610ab0565b9050811561141857336001600160a01b03821614611418576113fb81336110ed565b611418576040516367d9dca160e11b815260040160405180910390fd5b60008381526006602052604080822080546001600160a01b0319166001600160a01b0388811691821790925591518693918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a450505050565b60008160008151811061148a5761148a611f30565b602090810291909101810151600085815260098352604080822054808352818320839055600a90945290819020829055519092507f252851c72bba973a3eff4c55d976631b74c5e463b736ab3ba7ea37cbe40bbc19906114ed9083908590611fed565b60405180910390a150505050565b60008181526004602052604081205490600160e01b82169003611563578060000361155e57600054821061154257604051636f96cda160e11b815260040160405180910390fd5b5b50600019016000818152600460205260409020548015611543575b919050565b604051636f96cda160e11b815260040160405180910390fd5b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008054908290036115f35760405163b562e8dd60e01b815260040160405180910390fd5b6001600160a01b03831660008181526005602090815260408083208054680100000000000000018802019055848352600490915281206001851460e11b4260a01b178317905582840190839083907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4600183015b8181146116a257808360007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a460010161166a565b50816000036116c357604051622e076360e81b815260040160405180910390fd5b60005550505050565b6040516331a9108f60e11b815273dda32aabbbb6c44efc567bac5f7c35f18533845690636352211e90611703908490600401611a34565b602060405180830381865afa158015611720573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117449190612157565b6001600160a01b0316336001600160a01b031614611777578060405163a73d740960e01b81526004016107c19190611a34565b600881901c6000908152600f602052604090205460ff82161c600116156117b357806040516316a8344960e31b81526004016107c19190611a34565b600881901c6000908152600f602052604090208054600160ff84161b17905550565b604051630a85bd0160e11b81526000906001600160a01b0385169063150b7a029061180a903390899088908890600401612178565b6020604051808303816000875af1925050508015611845575060408051601f3d908101601f19168201909252611842918101906121bd565b60015b6118a3573d808015611873576040519150601f19603f3d011682016040523d82523d6000602084013e611878565b606091505b50805160000361189b576040516368d2bf6b60e11b815260040160405180910390fd5b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490505b949350505050565b6001600160e01b031981165b8114610a6c57600080fd5b8035610668816118c1565b6000602082840312156118f8576118f8600080fd5b60006118b984846118d8565b8015155b82525050565b602081016106688284611904565b60005b8381101561193757818101518382015260200161191f565b50506000910152565b600061194a825190565b80845260208401935061196181856020860161191c565b601f01601f19169290920192915050565b6020808252810161103f8184611940565b806118cd565b803561066881611983565b6000602082840312156119a9576119a9600080fd5b60006118b98484611989565b60006001600160a01b038216610668565b611908816119b5565b6020810161066882846119c6565b6118cd816119b5565b8035610668816119dd565b60008060408385031215611a0757611a07600080fd5b6000611a1385856119e6565b9250506020611a2485828601611989565b9150509250929050565b80611908565b602081016106688284611a2e565b634e487b7160e01b600052604160045260246000fd5b601f19601f830116810181811067ffffffffffffffff82111715611a7e57611a7e611a42565b6040525050565b6000611a9060405190565b905061155e8282611a58565b600067ffffffffffffffff821115611ab657611ab6611a42565b5060209081020190565b6000611ad3611ace84611a9c565b611a85565b83815290506020808201908402830185811115611af257611af2600080fd5b835b81811015611b1457611b068782611989565b835260209283019201611af4565b5050509392505050565b600082601f830112611b3257611b32600080fd5b81356118b9848260208601611ac0565b60008060408385031215611b5857611b58600080fd5b6000611b648585611989565b925050602083013567ffffffffffffffff811115611b8457611b84600080fd5b611a2485828601611b1e565b600080600060608486031215611ba857611ba8600080fd5b6000611bb486866119e6565b9350506020611bc5868287016119e6565b9250506040611bd686828701611989565b9150509250925092565b600060208284031215611bf557611bf5600080fd5b60006118b984846119e6565b611c0b82826119c6565b5060200190565b60200190565b6000611c22825190565b808452602093840193830160005b82811015611c55578151611c448782611c01565b965050602082019150600101611c30565b5093949350505050565b6020808252810161103f8184611c18565b600060208284031215611c8557611c85600080fd5b813567ffffffffffffffff811115611c9f57611c9f600080fd5b6118b984828501611b1e565b67ffffffffffffffff8116611908565b602081016106688284611cab565b8015156118cd565b803561066881611cc9565b60008060408385031215611cf257611cf2600080fd5b6000611cfe85856119e6565b9250506020611a2485828601611cd1565b600067ffffffffffffffff821115611d2957611d29611a42565b601f19601f8301165b60200192915050565b82818337506000910152565b6000611d55611ace84611d0f565b905082815260208101848484011115611d7057611d70600080fd5b611d7b848285611d3b565b509392505050565b600082601f830112611d9757611d97600080fd5b81356118b9848260208601611d47565b60008060008060808587031215611dc057611dc0600080fd5b6000611dcc87876119e6565b9450506020611ddd878288016119e6565b9350506040611dee87828801611989565b925050606085013567ffffffffffffffff811115611e0e57611e0e600080fd5b611e1a87828801611d83565b91505092959194509250565b60008060408385031215611e3c57611e3c600080fd5b6000611e4885856119e6565b9250506020611a24858286016119e6565b634e487b7160e01b600052601160045260246000fd5b8082018082111561066857610668611e59565b634e487b7160e01b600052602260045260246000fd5b600281046001821680611eac57607f821691505b602082108103611ebe57611ebe611e82565b50919050565b60408101611ed282856119c6565b61103f60208301846119c6565b8181038181111561066857610668611e59565b634e487b7160e01b600052601260045260246000fd5b600082611f1757611f17611ef2565b500490565b600082611f2b57611f2b611ef2565b500690565b634e487b7160e01b600052603260045260246000fd5b600060018201611f5857611f58611e59565b5060010190565b61ffff8116611908565b63ffffffff8116611908565b60a08101611f838288611a2e565b611f906020830187611cab565b611f9d6040830186611f5f565b611faa6060830185611f69565b611fb76080830184611f69565b9695505050505050565b805161066881611983565b600060208284031215611fe157611fe1600080fd5b60006118b98484611fc1565b60408101611ffb8285611a2e565b61103f6020830184611a2e565b6000612016611ace84611d0f565b90508281526020810184848401111561203157612031600080fd5b611d7b84828561191c565b600082601f83011261205057612050600080fd5b81516118b9848260208601612008565b60006020828403121561207557612075600080fd5b815167ffffffffffffffff81111561208f5761208f600080fd5b6118b98482850161203c565b6120a6818480611908565b602001611d32818380611908565b60408101611ffb82856119c6565b6020808252810161066881602681527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160208201526564647265737360d01b604082015260600190565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65729101908152611c12565b602080825281016106688161210c565b8051610668816119dd565b60006020828403121561216c5761216c600080fd5b60006118b9848461214c565b6080810161218682876119c6565b61219360208301866119c6565b6121a06040830185611a2e565b8181036060830152611fb78184611940565b8051610668816118c1565b6000602082840312156121d2576121d2600080fd5b60006118b984846121b256fe697066733a2f2f516d544a66316a6e45324538694d74566456766463435577433144386b4a34516b7469736531584d314366767953a26469706673582212202bed1327f9946a98c2a476f8c890d43e427424dfd477172b540a0764459b529864736f6c63430008100033000000000000000000000000248b1149203933c1b08e985ad67138af0ddd1b94
Deployed Bytecode
0x6080604052600436106102045760003560e01c8063715018a611610118578063a475b5dd116100a0578063e0d4ea371161006f578063e0d4ea371461055f578063e985e9c51461057f578063ecfc7ecc1461059f578063f2fde38b146105a7578063fc41b699146105c757600080fd5b8063a475b5dd14610502578063b88d4fde14610517578063c5b636001461052a578063c87b56dd1461053f57600080fd5b80637a2ffe31116100e75780637a2ffe311461046c5780638ac000211461048c5780638da5cb5b146104af57806395d89b41146104cd578063a22cb465146104e257600080fd5b8063715018a614610418578063738e901e1461042d57806374e94deb146104425780637817399e1461045757600080fd5b806323b872dd1161019b5780633ccfd60b1161016a5780633ccfd60b1461039057806342842e0e146103a55780634a27721c146103b85780636352211e146103d857806370a08231146103f857600080fd5b806323b872dd1461030f57806332cb6b0c1461032257806339c8ac89146103385780633a79d2e51461036e57600080fd5b8063095ea7b3116101d7578063095ea7b3146102a557806318160ddd146102b85780631f89f25e146102da5780631fe543e3146102ef57600080fd5b8063012c69961461020957806301ffc9a71461022057806306fdde0314610256578063081812fc14610278575b600080fd5b34801561021557600080fd5b5061021e6105e7565b005b34801561022c57600080fd5b5061024061023b3660046118e3565b61061c565b60405161024d919061190e565b60405180910390f35b34801561026257600080fd5b5061026b61066e565b60405161024d9190611972565b34801561028457600080fd5b50610298610293366004611994565b610700565b60405161024d91906119cf565b61021e6102b33660046119f1565b610744565b3480156102c457600080fd5b50600154600054035b60405161024d9190611a34565b3480156102e657600080fd5b506010546102cd565b3480156102fb57600080fd5b5061021e61030a366004611b42565b610754565b61021e61031d366004611b90565b6107d4565b34801561032e57600080fd5b506102cd61177081565b34801561034457600080fd5b506102cd610353366004611be0565b6001600160a01b03166000908152600c602052604090205490565b34801561037a57600080fd5b5061038361096c565b60405161024d9190611c5f565b34801561039c57600080fd5b5061021e6109cd565b61021e6103b3366004611b90565b610a6f565b3480156103c457600080fd5b506102406103d3366004611994565b610a8f565b3480156103e457600080fd5b506102986103f3366004611994565b610ab0565b34801561040457600080fd5b506102cd610413366004611be0565b610abb565b34801561042457600080fd5b5061021e610b0a565b34801561043957600080fd5b506102cd610b1e565b34801561044e57600080fd5b506011546102cd565b34801561046357600080fd5b5061021e610b42565b34801561047857600080fd5b5061021e610487366004611c70565b610c87565b34801561049857600080fd5b506104a26102eb81565b60405161024d9190611cbb565b3480156104bb57600080fd5b506008546001600160a01b0316610298565b3480156104d957600080fd5b5061026b610d07565b3480156104ee57600080fd5b5061021e6104fd366004611cdc565b610d16565b34801561050e57600080fd5b5061021e610d85565b61021e610525366004611da7565b610eb8565b34801561053657600080fd5b506102cd610f02565b34801561054b57600080fd5b5061026b61055a366004611994565b610f75565b34801561056b57600080fd5b506102cd61057a366004611994565b611046565b34801561058b57600080fd5b5061024061059a366004611e26565b6110ed565b61021e61111b565b3480156105b357600080fd5b5061021e6105c2366004611be0565b6112ad565b3480156105d357600080fd5b5061021e6105e2366004611994565b6112e4565b6105ef61137d565b6105fc62093a8042611e6f565b60105562093a8061060d8142611e6f565b6106179190611e6f565b601155565b60006301ffc9a760e01b6001600160e01b03198316148061064d57506380ac58cd60e01b6001600160e01b03198316145b806106685750635b5e139f60e01b6001600160e01b03198316145b92915050565b60606002805461067d90611e98565b80601f01602080910402602001604051908101604052809291908181526020018280546106a990611e98565b80156106f65780601f106106cb576101008083540402835291602001916106f6565b820191906000526020600020905b8154815290600101906020018083116106d957829003601f168201915b5050505050905090565b600061070b826113a7565b610728576040516333d1c03960e21b815260040160405180910390fd5b506000908152600660205260409020546001600160a01b031690565b610750828260016113ce565b5050565b336001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990916146107ca57337f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990960405163073e64fd60e21b81526004016107c1929190611ec4565b60405180910390fd5b6107508282611475565b60006107df826114fb565b9050836001600160a01b0316816001600160a01b0316146108125760405162a1148160e81b815260040160405180910390fd5b60008281526006602052604090208054338082146001600160a01b0388169091141761085f5761084286336110ed565b61085f57604051632ce44b5f60e11b815260040160405180910390fd5b6001600160a01b03851661088657604051633a954ecd60e21b815260040160405180910390fd5b801561089157600082555b6001600160a01b038681166000908152600560205260408082208054600019019055918716808252919020805460010190554260a01b17600160e11b17600085815260046020526040812091909155600160e11b84169003610923576001840160008181526004602052604081205490036109215760005481146109215760008181526004602052604090208490555b505b83856001600160a01b0316876001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050505050565b606060138054806020026020016040519081016040528092919081815260200182805480156106f657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116109a6575050505050905090565b6109d561137d565b6117706109e56001546000540390565b14610a035760405163e1f59d7360e01b815260040160405180910390fd5b604051600090339047908381818185875af1925050503d8060008114610a45576040519150601f19603f3d011682016040523d82523d6000602084013e610a4a565b606091505b5050905080610a6c576040516312171d8360e31b815260040160405180910390fd5b50565b610a8a83838360405180602001604052806000815250610eb8565b505050565b600881901c6000908152600f602052604081205460ff83161c600116610668565b6000610668826114fb565b60006001600160a01b038216610ae4576040516323d3ad8160e21b815260040160405180910390fd5b506001600160a01b031660009081526005602052604090205467ffffffffffffffff1690565b610b1261137d565b610b1c600061157c565b565b6000600e54611770610b309190611edf565b601254610b3d9190611f08565b905090565b610384601154610b529190611e6f565b421080610b6e575062093a80601154610b6b9190611e6f565b42115b15610b8c5760405163058ebc1760e11b815260040160405180910390fd5b336000908152600c60205260408120549003610bbd573360405163b1b93d5f60e01b81526004016107c191906119cf565b6000610bc7610b1e565b336000908152600c6020526040812054919250610be48383611f08565b336000908152600c602052604081205590508015610c0657610c0633826115ce565b6000610c128484611f1c565b604051909150600090339083908381818185875af1925050503d8060008114610c57576040519150601f19603f3d011682016040523d82523d6000602084013e610c5c565b606091505b5050905080610c80573360405163159459a160e31b81526004016107c191906119cf565b5050505050565b6010544210610ca957604051630c51a79160e41b815260040160405180910390fd5b60008151905080600e6000828254610cc19190611e6f565b90915550600090505b81811015610cfc57610cf4838281518110610ce757610ce7611f30565b60200260200101516116cc565b600101610cca565b5061075033826115ce565b60606003805461067d90611e98565b3360008181526007602090815260408083206001600160a01b038716808552925291829020805460ff191685151517905590519091907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3190610d7990859061190e565b60405180910390a35050565b610d8d61137d565b600d54600154600054036000828152600b6020526040812091909155600d805491610db783611f46565b90915550506040516305d3b1d360e41b815260009073271682deb8c4e0901d1a1550ad2e64d568e6990990635d3b1d3090610e25907fff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92906102eb90600390620186a090600190600401611f75565b6020604051808303816000875af1158015610e44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e689190611fcc565b60008181526009602052604090819020849055519091507f9ac10fb18c93d33ad7b0a941897aef048d0f8d30756684e82b4552ba12764d4590610eac908490611a34565b60405180910390a15050565b610ec38484846107d4565b6001600160a01b0383163b15610efc57610edf848484846117d5565b610efc576040516368d2bf6b60e11b815260040160405180910390fd5b50505050565b600080600a610f0f610b1e565b610f199190611f08565b610f21610b1e565b610f2b9190611e6f565b9050662386f26fc100008111610f4957662386f26fc1000091505090565b662386f26fc10000610f5b8183611f1c565b610f659083611edf565b610f6f9190611e6f565b91505090565b60606000610f8283611046565b905080600003610fac576040518060600160405280603581526020016121df603591399392505050565b6040516309419a8160e21b81526001600160a01b037f000000000000000000000000248b1149203933c1b08e985ad67138af0ddd1b9416906325066a0490610ffa9086908590600401611fed565b600060405180830381865afa158015611017573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261103f9190810190612060565b9392505050565b60006110556001546000540390565b8210611076578160405163ed15e6cf60e01b81526004016107c19190611a34565b60005b600d548110156110e4576000818152600b60205260409020548310156110dc576000818152600a60209081526040918290205491516110bc91839187910161209b565b60408051601f198184030181529190528051602090910120949350505050565b600101611079565b50600092915050565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b6011544210158061112d575060105442105b1561114b576040516334dc687f60e11b815260040160405180910390fd5b34600081900361116e5760405163600af40560e01b815260040160405180910390fd5b61117f662386f26fc1000082611f1c565b1561119f5780604051633974ac6360e01b81526004016107c19190611a34565b336000908152600c60205260408120546111b99083611e6f565b90506111c3610f02565b8110156111e557816040516322afe53560e21b81526004016107c19190611a34565b6011546111f461038442611e6f565b111561120a5761120661038442611e6f565b6011555b80820361125457601380546001810182556000919091527f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0900180546001600160a01b031916331790555b81601260008282546112669190611e6f565b9091555050336000818152600c602052604090819020839055517f0abe00b0e1d3ed939902c6a41c86c34ea31064f2084d386bc04349e3106aea4791610eac9184906120b4565b6112b561137d565b6001600160a01b0381166112db5760405162461bcd60e51b81526004016107c1906120c2565b610a6c8161157c565b6112ec61137d565b601054158061130a575062093a806011546113079190611e6f565b42105b156113285760405163058ebc1760e11b815260040160405180910390fd5b611770816113396001546000540390565b6113439190611e6f565b111561136257604051638d83cdd760e01b815260040160405180910390fd5b610a6c6113776008546001600160a01b031690565b826115ce565b6008546001600160a01b03163314610b1c5760405162461bcd60e51b81526004016107c19061213c565b6000805482108015610668575050600090815260046020526040902054600160e01b161590565b60006113d983610ab0565b9050811561141857336001600160a01b03821614611418576113fb81336110ed565b611418576040516367d9dca160e11b815260040160405180910390fd5b60008381526006602052604080822080546001600160a01b0319166001600160a01b0388811691821790925591518693918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a450505050565b60008160008151811061148a5761148a611f30565b602090810291909101810151600085815260098352604080822054808352818320839055600a90945290819020829055519092507f252851c72bba973a3eff4c55d976631b74c5e463b736ab3ba7ea37cbe40bbc19906114ed9083908590611fed565b60405180910390a150505050565b60008181526004602052604081205490600160e01b82169003611563578060000361155e57600054821061154257604051636f96cda160e11b815260040160405180910390fd5b5b50600019016000818152600460205260409020548015611543575b919050565b604051636f96cda160e11b815260040160405180910390fd5b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008054908290036115f35760405163b562e8dd60e01b815260040160405180910390fd5b6001600160a01b03831660008181526005602090815260408083208054680100000000000000018802019055848352600490915281206001851460e11b4260a01b178317905582840190839083907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4600183015b8181146116a257808360007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a460010161166a565b50816000036116c357604051622e076360e81b815260040160405180910390fd5b60005550505050565b6040516331a9108f60e11b815273dda32aabbbb6c44efc567bac5f7c35f18533845690636352211e90611703908490600401611a34565b602060405180830381865afa158015611720573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117449190612157565b6001600160a01b0316336001600160a01b031614611777578060405163a73d740960e01b81526004016107c19190611a34565b600881901c6000908152600f602052604090205460ff82161c600116156117b357806040516316a8344960e31b81526004016107c19190611a34565b600881901c6000908152600f602052604090208054600160ff84161b17905550565b604051630a85bd0160e11b81526000906001600160a01b0385169063150b7a029061180a903390899088908890600401612178565b6020604051808303816000875af1925050508015611845575060408051601f3d908101601f19168201909252611842918101906121bd565b60015b6118a3573d808015611873576040519150601f19603f3d011682016040523d82523d6000602084013e611878565b606091505b50805160000361189b576040516368d2bf6b60e11b815260040160405180910390fd5b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490505b949350505050565b6001600160e01b031981165b8114610a6c57600080fd5b8035610668816118c1565b6000602082840312156118f8576118f8600080fd5b60006118b984846118d8565b8015155b82525050565b602081016106688284611904565b60005b8381101561193757818101518382015260200161191f565b50506000910152565b600061194a825190565b80845260208401935061196181856020860161191c565b601f01601f19169290920192915050565b6020808252810161103f8184611940565b806118cd565b803561066881611983565b6000602082840312156119a9576119a9600080fd5b60006118b98484611989565b60006001600160a01b038216610668565b611908816119b5565b6020810161066882846119c6565b6118cd816119b5565b8035610668816119dd565b60008060408385031215611a0757611a07600080fd5b6000611a1385856119e6565b9250506020611a2485828601611989565b9150509250929050565b80611908565b602081016106688284611a2e565b634e487b7160e01b600052604160045260246000fd5b601f19601f830116810181811067ffffffffffffffff82111715611a7e57611a7e611a42565b6040525050565b6000611a9060405190565b905061155e8282611a58565b600067ffffffffffffffff821115611ab657611ab6611a42565b5060209081020190565b6000611ad3611ace84611a9c565b611a85565b83815290506020808201908402830185811115611af257611af2600080fd5b835b81811015611b1457611b068782611989565b835260209283019201611af4565b5050509392505050565b600082601f830112611b3257611b32600080fd5b81356118b9848260208601611ac0565b60008060408385031215611b5857611b58600080fd5b6000611b648585611989565b925050602083013567ffffffffffffffff811115611b8457611b84600080fd5b611a2485828601611b1e565b600080600060608486031215611ba857611ba8600080fd5b6000611bb486866119e6565b9350506020611bc5868287016119e6565b9250506040611bd686828701611989565b9150509250925092565b600060208284031215611bf557611bf5600080fd5b60006118b984846119e6565b611c0b82826119c6565b5060200190565b60200190565b6000611c22825190565b808452602093840193830160005b82811015611c55578151611c448782611c01565b965050602082019150600101611c30565b5093949350505050565b6020808252810161103f8184611c18565b600060208284031215611c8557611c85600080fd5b813567ffffffffffffffff811115611c9f57611c9f600080fd5b6118b984828501611b1e565b67ffffffffffffffff8116611908565b602081016106688284611cab565b8015156118cd565b803561066881611cc9565b60008060408385031215611cf257611cf2600080fd5b6000611cfe85856119e6565b9250506020611a2485828601611cd1565b600067ffffffffffffffff821115611d2957611d29611a42565b601f19601f8301165b60200192915050565b82818337506000910152565b6000611d55611ace84611d0f565b905082815260208101848484011115611d7057611d70600080fd5b611d7b848285611d3b565b509392505050565b600082601f830112611d9757611d97600080fd5b81356118b9848260208601611d47565b60008060008060808587031215611dc057611dc0600080fd5b6000611dcc87876119e6565b9450506020611ddd878288016119e6565b9350506040611dee87828801611989565b925050606085013567ffffffffffffffff811115611e0e57611e0e600080fd5b611e1a87828801611d83565b91505092959194509250565b60008060408385031215611e3c57611e3c600080fd5b6000611e4885856119e6565b9250506020611a24858286016119e6565b634e487b7160e01b600052601160045260246000fd5b8082018082111561066857610668611e59565b634e487b7160e01b600052602260045260246000fd5b600281046001821680611eac57607f821691505b602082108103611ebe57611ebe611e82565b50919050565b60408101611ed282856119c6565b61103f60208301846119c6565b8181038181111561066857610668611e59565b634e487b7160e01b600052601260045260246000fd5b600082611f1757611f17611ef2565b500490565b600082611f2b57611f2b611ef2565b500690565b634e487b7160e01b600052603260045260246000fd5b600060018201611f5857611f58611e59565b5060010190565b61ffff8116611908565b63ffffffff8116611908565b60a08101611f838288611a2e565b611f906020830187611cab565b611f9d6040830186611f5f565b611faa6060830185611f69565b611fb76080830184611f69565b9695505050505050565b805161066881611983565b600060208284031215611fe157611fe1600080fd5b60006118b98484611fc1565b60408101611ffb8285611a2e565b61103f6020830184611a2e565b6000612016611ace84611d0f565b90508281526020810184848401111561203157612031600080fd5b611d7b84828561191c565b600082601f83011261205057612050600080fd5b81516118b9848260208601612008565b60006020828403121561207557612075600080fd5b815167ffffffffffffffff81111561208f5761208f600080fd5b6118b98482850161203c565b6120a6818480611908565b602001611d32818380611908565b60408101611ffb82856119c6565b6020808252810161066881602681527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160208201526564647265737360d01b604082015260600190565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65729101908152611c12565b602080825281016106688161210c565b8051610668816119dd565b60006020828403121561216c5761216c600080fd5b60006118b9848461214c565b6080810161218682876119c6565b61219360208301866119c6565b6121a06040830185611a2e565b8181036060830152611fb78184611940565b8051610668816118c1565b6000602082840312156121d2576121d2600080fd5b60006118b984846121b256fe697066733a2f2f516d544a66316a6e45324538694d74566456766463435577433144386b4a34516b7469736531584d314366767953a26469706673582212202bed1327f9946a98c2a476f8c890d43e427424dfd477172b540a0764459b529864736f6c63430008100033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000248b1149203933c1b08e985ad67138af0ddd1b94
-----Decoded View---------------
Arg [0] : metadata (address): 0x248B1149203933c1B08E985aD67138AF0dDd1b94
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000248b1149203933c1b08e985ad67138af0ddd1b94
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.