More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 107 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Open Gift | 16412241 | 677 days ago | IN | 0 ETH | 0.00057455 | ||||
Open Gift | 16412239 | 677 days ago | IN | 0 ETH | 0.00271284 | ||||
Open Gift | 16353997 | 686 days ago | IN | 0 ETH | 0.00203608 | ||||
Open Gift | 16292829 | 694 days ago | IN | 0 ETH | 0.00329391 | ||||
Open Gift | 16292825 | 694 days ago | IN | 0 ETH | 0.00268779 | ||||
Open Gift | 16274826 | 697 days ago | IN | 0 ETH | 0.00200622 | ||||
Open Gift | 16274821 | 697 days ago | IN | 0 ETH | 0.00211794 | ||||
Open Gift | 16273137 | 697 days ago | IN | 0 ETH | 0.0025414 | ||||
Open Gift | 16271475 | 697 days ago | IN | 0 ETH | 0.00218212 | ||||
Open Gift | 16266620 | 698 days ago | IN | 0 ETH | 0.00204541 | ||||
Open Gift | 16265847 | 698 days ago | IN | 0 ETH | 0.0018542 | ||||
Open Gift | 16265845 | 698 days ago | IN | 0 ETH | 0.00189602 | ||||
Open Gift | 16265603 | 698 days ago | IN | 0 ETH | 0.00225485 | ||||
Open Gift | 16265443 | 698 days ago | IN | 0 ETH | 0.00187921 | ||||
Open Gift | 16265101 | 698 days ago | IN | 0 ETH | 0.00176536 | ||||
Open Gift | 16264868 | 698 days ago | IN | 0 ETH | 0.0019225 | ||||
Open Gift | 16264605 | 698 days ago | IN | 0 ETH | 0.00177732 | ||||
Open Gift | 16264349 | 698 days ago | IN | 0 ETH | 0.00177996 | ||||
Open Gift | 16264135 | 698 days ago | IN | 0 ETH | 0.00195912 | ||||
Open Gift | 16264115 | 698 days ago | IN | 0 ETH | 0.00253144 | ||||
Open Gift | 16263971 | 698 days ago | IN | 0 ETH | 0.00238542 | ||||
Open Gift | 16263889 | 698 days ago | IN | 0 ETH | 0.0024686 | ||||
Open Gift | 16263809 | 698 days ago | IN | 0 ETH | 0.00196718 | ||||
Open Gift | 16263805 | 698 days ago | IN | 0 ETH | 0.00215715 | ||||
Open Gift | 16263641 | 698 days ago | IN | 0 ETH | 0.00280911 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
SantaProtocol
Compiler Version
v0.8.7+commit.e28d00a7
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.7; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./utils/RandomNumberConsumerV2.sol"; import "./WrappedPresent.sol"; /** * @title The SantaProtocol contract * @notice A contract that lets people deposit an NFT into a pool and then later lets them randomly redeem another one using Chainlink VRF2 */ contract SantaProtocol is Ownable, IERC721Receiver, RandomNumberConsumerV2 { using ECDSA for bytes32; using SafeMath for uint256; // Struct to store gifts in the pool struct Gift { address gifter; address nft; uint256 tokenId; } // Address that signs verification messages when adding gifts address s_signer; // Blocktime that adding gifts to the pool ends uint256 public s_registrationEnd; // Blocktime that redemptions start uint256 public s_redemptionStart; // State that pauses the contract's functionality bool public PAUSED = false; // The random word returned by VRF used as a seed for the randomness uint256 public SEED; // The request ID for the SEED uint256 public SEED_REQUEST_ID; // The state that says that the gift pool has been shuffled bool public SHUFFLED = false; // Maximum allowed gifts in the pool uint32 public MAX_GIFTS = 50000; // The Gift Pool Gift[] public s_giftPool; // The array to map Present Token IDs to gifts in the Gift Pool uint32[] public s_giftPoolIndices; // The Present NFT that's minted to users when they add to the pool WrappedPresent PRESENT_NFT; // Mapping of gifts chosen by each user mapping(address => Gift[]) s_chosenGifts; // Revert reasons error GiftMustSupportERC721Interface(); error InvalidSenderMustNotBeContract(); error RedemptionHasNotStarted(); error PoolSizeExceedsAmount(); error MustApproveContract(); error HasNotBeenShuffled(); error DoesNotOwnPresent(); error RegistrationEnded(); error CannotGiftPresent(); error InvalidSignature(); error MaxGiftsReached(); error MustOwnTokenId(); error AllGiftsGiven(); // Events event NewSigner(address newSigner); event NewOwner(address newOwner); event AddGift(address gifter, address nft, uint256 tokenId); event GiftUnwrapped(address receiver, address nft, uint256 tokenId); event ERC721Received( address operator, address from, uint256 tokenId, bytes data ); event GiftAdded(address gifter, address nft, uint256 tokenId); event GiftChosen( address account, uint256 presentTokenId, address nft, uint256 tokenId ); /** * @notice Constructor inherits RandomNumberConsumerV2 * * @param subscriptionId - the subscription ID that this contract uses for funding Chainlink VFR requests * @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations * @param keyHash - the Chainlink gas lane to use, which specifies the maximum gas price to bump to * @param registrationEnd - the time that registration/adding gifts ends * @param redemptionStart - the time that participants can begin redeeming their gifts */ constructor( uint64 subscriptionId, address vrfCoordinator, bytes32 keyHash, uint256 registrationEnd, uint256 redemptionStart, address signer, address presentNft ) RandomNumberConsumerV2(subscriptionId, vrfCoordinator, keyHash) { s_registrationEnd = registrationEnd; s_redemptionStart = redemptionStart; s_signer = signer; PRESENT_NFT = WrappedPresent(presentNft); } /* * Functions used to interact with the gift exchange */ /** * @notice Function used to add an NFT to the pool. * * @param nft - the address of the NFT being added * @param tokenId - the token id of the NFT being added * @param sig - a message signed by the signer address verifying the NFT is eligible */ function addGift( address nft, uint256 tokenId, bytes memory sig ) public isNotPaused { // If the registration/adding gift end time has passed if (block.timestamp > s_registrationEnd) revert RegistrationEnded(); // If the pool size has already reached its limit if (s_giftPool.length >= MAX_GIFTS) revert MaxGiftsReached(); // If the gift is already a present, ya do-do! if (nft == address(PRESENT_NFT)) revert CannotGiftPresent(); // If the gift doesn't support the ERC721 interface if (!giftSupports721(nft)) revert GiftMustSupportERC721Interface(); // IF the user doesn't own the nft they're adding if (IERC721(nft).ownerOf(tokenId) != msg.sender) revert MustOwnTokenId(); // If the user hasn't individually approved this contract if (IERC721(nft).getApproved(tokenId) != address(this)) revert MustApproveContract(); // If the signature isn't valid if (!validateGiftHashSignature(msg.sender, nft, tokenId, sig)) revert InvalidSignature(); // Transfer the NFT from the caller to this contract IERC721(nft).safeTransferFrom(msg.sender, address(this), tokenId); // Mint a present NFT to the caller PRESENT_NFT.simpleMint(msg.sender); // Add the gift to the pool s_giftPool.push(Gift(msg.sender, nft, tokenId)); s_giftPoolIndices.push(uint32(s_giftPool.length - 1)); emit GiftAdded(msg.sender, nft, tokenId); } /** * @notice Function used to burn a Present NFT and redeem the gift in the pool it's been tied to */ function openGift(uint256 tokenId) public isNotPaused { // If redemptions haven't started yet if (block.timestamp < s_redemptionStart) revert RedemptionHasNotStarted(); // If the pool has not been shuffled if (!SHUFFLED) revert HasNotBeenShuffled(); // If there are no gifts left in the pool if (s_giftPool.length == 0) revert AllGiftsGiven(); // Make sure the caller owns the tokenId if (PRESENT_NFT.ownerOf(tokenId) != msg.sender) revert DoesNotOwnPresent(); // Select the randomized gift associated with the tokenId uint32 index = s_giftPoolIndices[tokenId - 1]; Gift memory chosenGift = s_giftPool[index]; // Trade the present for a random number PRESENT_NFT.burn(tokenId, msg.sender); IERC721(chosenGift.nft).safeTransferFrom( address(this), msg.sender, chosenGift.tokenId ); emit GiftChosen( msg.sender, tokenId, chosenGift.nft, chosenGift.tokenId ); } /** * @notice Get the number of NFTs in the gift pool */ function getGiftPoolSize() public view returns (uint256) { return s_giftPool.length; } /** * @notice Get the whole gift pool * * @dev intended for offchain use only */ function getGiftPool() public view returns (Gift[] memory) { return s_giftPool; } /** * @notice Get the indices mapping presents to gifts * * @dev intended for offchain use only */ function getGiftPoolIndices() public view returns (uint32[] memory) { return s_giftPoolIndices; } /** * @notice Get the number of gifts that a user has randomly chosen * @param account - the wallet address of the user */ function getNumberOfChosenGifts( address account ) public view returns (uint256) { return s_chosenGifts[account].length; } /** * @notice Get the array of gifts that a user has randomly chosen * @param account - the wallet address of the user * * @dev intended for offchain use only */ function getChosenGifts( address account ) public view returns (Gift[] memory gifts) { return s_chosenGifts[account]; } /* * Admin Functions */ /** * @notice Set signer to new account * * @param newSigner - the addres of the new owner */ function setSigner(address newSigner) public onlyOwner { s_signer = newSigner; } /** * @notice Set the time that adding gifts ends * * @param newRegistrationEnd - the new s_registerationEnd time */ function setRegistrationEnd(uint256 newRegistrationEnd) public onlyOwner { s_registrationEnd = newRegistrationEnd; } /** * @notice Set the time that claiming a random gift starts * * @param newRedemptionStart - the new s_redemptionStart time */ function setRedemptionStart(uint256 newRedemptionStart) public onlyOwner { s_redemptionStart = newRedemptionStart; } /** * @notice Function used to update the subscription ID * * @param subscriptionId - the chainlink vrf subscription id */ function setSubscriptionId(uint64 subscriptionId) public onlyOwner { s_subscriptionId = subscriptionId; } /** * @notice Function used to update the gas lane used by VRF * * @param keyHash - the keyhash of the gaslane that VRF uses */ function setKeyHash(bytes32 keyHash) public onlyOwner { s_keyHash = keyHash; } /** * @notice Function used to update the callback gas limit * * @param callbackGasLimit - the gas limit of the fulfillRandomWords callback */ function setCallbackGasLimit(uint32 callbackGasLimit) public onlyOwner { CALLBACK_GAS_LIMIT = callbackGasLimit; } /** * @notice Function that pauses the contract * * @param _isPaused - now what're we turning the pause to!? */ function setPaused(bool _isPaused) public onlyOwner { PAUSED = _isPaused; } /** * @notice Function that allows the owner to update the max size of the pool * * @param _maxGifts - new max number of gifts in the pool */ function setMaxGifts(uint32 _maxGifts) public onlyOwner { if (s_giftPool.length > _maxGifts) revert PoolSizeExceedsAmount(); MAX_GIFTS = _maxGifts; } /** * @notice Function that requests a random seed from VRF */ function requestSeed() public onlyOwner { require( block.timestamp > s_registrationEnd, "Registration has not ended yet" ); SEED_REQUEST_ID = requestRandomWords(1); SHUFFLED = false; } /** * @notice Callback function used by VRF Coordinator * * @param requestId - id of the request * @param randomWords - array of random results from VRF Coordinator */ function fulfillRandomWords( uint256 requestId, uint256[] memory randomWords ) internal override { if (SEED_REQUEST_ID == requestId) { SEED = randomWords[0]; } } /** * @notice Function that uses the SEED to shuffle the index array. * Just in case this ends up being a large array (Ho Ho Ho!), we will make it possible * to break this operation up into multiple calls * * @param startPosition - the starting index we're shuffling * @param endPosition - the ending index we're shuffling */ function shuffleRandomGiftIndices( uint32 startPosition, uint32 endPosition ) public onlyOwner { require(SEED != 0, "SEED does not exist"); require( endPosition >= startPosition, "End position must be after start position" ); // Make sure that we're not going to go out of bounds uint32 lastPosition = endPosition > s_giftPool.length - 1 ? uint32(s_giftPool.length - 1) : endPosition; // Shuffle the indices in the array for (uint32 i = startPosition; i <= lastPosition; ) { uint32 j = uint32( (uint256(keccak256(abi.encode(SEED, i))) % (s_giftPool.length)) ); (s_giftPoolIndices[i], s_giftPoolIndices[j]) = ( s_giftPoolIndices[j], s_giftPoolIndices[i] ); unchecked { i++; } } // Once we've shuffled the entire array, set the state to shuffled if (lastPosition == s_giftPool.length - 1) { SHUFFLED = true; } } /* * Functions used for signing gifts as they get added */ /** * @notice returns an identifying contract hash to verify this contract */ function getContractHash() public view returns (bytes32) { return keccak256(abi.encode(block.chainid, address(this))); } /** * @notice Function used to hash a gift * * @param gifter - address of the gifter * @param nft - the address of the NFT being gifted * @param tokenId - the id of the NFT being gifted */ function hashGift( address gifter, address nft, uint256 tokenId ) public view returns (bytes32) { bytes32 giftHash = keccak256(abi.encode(Gift(gifter, nft, tokenId))); return keccak256(abi.encode(getContractHash(), giftHash)); } /** * @notice Function that valifates that the gift hash signature was signed by the designated signer authority * * @param gifter - address of the gifter * @param nft - the address of the NFT being gifted * @param tokenId - the id of the NFT being gifted * @param sig - the signature of the gift hash */ function validateGiftHashSignature( address gifter, address nft, uint256 tokenId, bytes memory sig ) public view returns (bool) { bytes32 giftHash = hashGift(gifter, nft, tokenId); bytes32 ethSignedMessageHash = giftHash.toEthSignedMessageHash(); address signer = ethSignedMessageHash.recover(sig); return signer == s_signer; } /* * Misc */ /** * @notice OpenZeppelin requires ERC721Received implementation. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) public override returns (bytes4) { emit ERC721Received(operator, from, tokenId, data); return this.onERC721Received.selector; } /** * @notice Function used to determine if a caller is a contract * * @param account - the address of an account * * @dev note, this isn't foolproof so use with caution */ function isContract(address account) internal view returns (bool) { uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @notice Function used to determine if a contract supports 721 interface * * @param nft - the address of an NFT */ function giftSupports721(address nft) public view returns (bool) { try IERC165(nft).supportsInterface(type(IERC721).interfaceId) returns ( bool result ) { return result; } catch { return false; } } /* * Modifiers */ modifier isNotPaused() { require(!PAUSED, "The NFT Exchange is currently paused."); _; } }
// 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 // 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 // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: address zero is not a valid owner"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _ownerOf(tokenId); require(owner != address(0), "ERC721: invalid token ID"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not token owner or approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { _requireMinted(tokenId); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved"); _safeTransfer(from, to, tokenId, data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist */ function _ownerOf(uint256 tokenId) internal view virtual returns (address) { return _owners[tokenId]; } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _ownerOf(tokenId) != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { address owner = ERC721.ownerOf(tokenId); return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId, 1); // Check that tokenId was not minted by `_beforeTokenTransfer` hook require(!_exists(tokenId), "ERC721: token already minted"); unchecked { // Will not overflow unless all 2**256 token ids are minted to the same owner. // Given that tokens are minted one by one, it is impossible in practice that // this ever happens. Might change if we allow batch minting. // The ERC fails to describe this case. _balances[to] += 1; } _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId, 1); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * This is an internal function that does not check if the sender is authorized to operate on the token. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId, 1); // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook owner = ERC721.ownerOf(tokenId); // Clear approvals delete _tokenApprovals[tokenId]; unchecked { // Cannot overflow, as that would require more tokens to be burned/transferred // out than the owner initially received through minting and transferring in. _balances[owner] -= 1; } delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId, 1); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId, 1); // Check that tokenId was not transferred by `_beforeTokenTransfer` hook require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); // Clear approvals from the previous owner delete _tokenApprovals[tokenId]; unchecked { // `_balances[from]` cannot overflow for the same reason as described in `_burn`: // `from`'s balance is the number of token held, which is at least one before the current // transfer. // `_balances[to]` could overflow in the conditions described in `_mint`. That would require // all 2**256 token ids to be minted, which in practice is impossible. _balances[from] -= 1; _balances[to] += 1; } _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId, 1); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits an {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Reverts if the `tokenId` has not been minted yet. */ function _requireMinted(uint256 tokenId) internal view virtual { require(_exists(tokenId), "ERC721: invalid token ID"); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`. * - When `from` is zero, the tokens will be minted for `to`. * - When `to` is zero, ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * - `batchSize` is non-zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256, /* firstTokenId */ uint256 batchSize ) internal virtual { if (batchSize > 1) { if (from != address(0)) { _balances[from] -= batchSize; } if (to != address(0)) { _balances[to] += batchSize; } } } /** * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`. * - When `from` is zero, the tokens were minted for `to`. * - When `to` is zero, ``from``'s tokens were burned. * - `from` and `to` are never both zero. * - `batchSize` is non-zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @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 have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// 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 // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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 // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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.7; import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; /** * @title The RandomNumberConsumerV2 contract * @notice A contract that gets random values from Chainlink VRF V2 */ contract RandomNumberConsumerV2 is VRFConsumerBaseV2 { VRFCoordinatorV2Interface immutable COORDINATOR; // VRF subscription ID. uint64 internal s_subscriptionId; // The gas lane to use, which specifies the maximum gas price to bump to. // For a list of available gas lanes on each network, // see https://docs.chain.link/docs/vrf-contracts/#configurations bytes32 internal s_keyHash; // Depends on the number of requested values that you want sent to the // fulfillRandomWords() function. Storing each word costs about 20,000 gas. uint32 internal CALLBACK_GAS_LIMIT = 100000; // The default is 3, but you can set this higher. uint16 constant REQUEST_CONFIRMATIONS = 3; // For this example, retrieve 2 random values in one request. // Cannot exceed VRFCoordinatorV2.MAX_NUM_WORDS. uint32 constant NUM_WORDS = 1; uint256[] public s_randomWords; uint256 public s_requestId; mapping(uint256 => address) public s_requestIdMapping; mapping(address => uint256[]) s_randomWordMapping; event ReturnedRandomness(uint256 requestId, uint256[] randomWords); event NewRandomNumberConsumerOwner(address newOwner); /** * @notice Constructor inherits VRFConsumerBaseV2 * * @param subscriptionId - the subscription ID that this contract uses for funding requests * @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations * @param keyHash - the gas lane to use, which specifies the maximum gas price to bump to */ constructor( uint64 subscriptionId, address vrfCoordinator, bytes32 keyHash ) VRFConsumerBaseV2(vrfCoordinator) { COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator); s_keyHash = keyHash; s_subscriptionId = subscriptionId; } /** * @notice Requests randomness * Assumes the subscription is funded sufficiently; "Words" refers to unit of data in Computer Science */ function requestRandomWords( uint32 numberOfWords ) internal returns (uint256 requestId) { // Will revert if subscription is not set and funded. requestId = COORDINATOR.requestRandomWords( s_keyHash, s_subscriptionId, REQUEST_CONFIRMATIONS, CALLBACK_GAS_LIMIT, numberOfWords ); s_requestIdMapping[requestId] = msg.sender; } /** * @notice Callback function used by VRF Coordinator * * @param requestId - id of the request * @param randomWords - array of random results from VRF Coordinator */ function fulfillRandomWords( uint256 requestId, uint256[] memory randomWords ) internal virtual override { s_randomWordMapping[s_requestIdMapping[requestId]] = randomWords; emit ReturnedRandomness(requestId, randomWords); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** * @title The WrappedPresent contract * @notice A contract that represents a random gift in the Santa.fm Gift Exchange */ contract WrappedPresent is Ownable, ERC721 { using Strings for string; // Table used for encoding the metadata in base64 string internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; // Designated Minter Role address minter; // URL for the image returned in the token's metadata string internal tokenImage; // Counter for tokens minted uint256 public totalTokensMinted; // Counter for tokens burned uint256 public totalTokensBurned; // Mapping of burned tokens by address mapping(address => uint256[]) public burnedBy; // Mapping of of whether or not a token has been burned mapping(uint256 => bool) public burned; // Error for when an account doesn't own a token when burning error OnlyOwnerCanBurnThroughMinter(); // Event for burning tokens event Burn(uint256 tokenId, address account); constructor( string memory _name, string memory _symbol, string memory _tokenImage ) Ownable() ERC721(_name, _symbol) { tokenImage = _tokenImage; } /* * Owner Functions */ /** * @notice Function that sets the image to be returned in Token URI * @param _tokenImage - The tokenId we're checking */ function setTokenImage(string memory _tokenImage) public onlyOwner { tokenImage = _tokenImage; } /** * @notice Function that updates the designated minter * @param _minter - The address of the new minter */ function setMinter(address _minter) public onlyOwner { minter = _minter; } /** * @notice Function that transfers a tokenId * @param from - The sender of the transfer * @param to - The receiver of the transfer * @param tokenId - TokenID of the token being transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public override { safeTransferFrom(from, to, tokenId, ""); } /* * Minter Functions */ /** * @notice Function that mints an NFT. Can only be called by `minter` * @param to - The address that receives the minted NFT */ function simpleMint(address to) public onlyMinter { // increment number of tokens minted totalTokensMinted += 1; // mint the token to the address _mint(to, totalTokensMinted); } /** * @notice Function that burns a present * @param tokenId - The tokenId to burn * @param account - The account that owns the token * * @dev [WARNING!] Be sure that when using this function, the `account` actually owns `tokenId` */ function burn(uint256 tokenId, address account) public onlyMinter { // Since _burn does not check approval for burning, we have to make sure that the // designated Minter only passes the correct owner of the token as `account` if (ownerOf(tokenId) != account) revert OnlyOwnerCanBurnThroughMinter(); // burn the token. _burn(tokenId); // keep track of burnings totalTokensBurned += 1; burnedBy[account].push(tokenId); burned[tokenId] = true; // emit our event emit Burn(tokenId, account); } /* * URI Functions */ /** * @notice Function that returns the Contract URI */ function contractURI() public pure returns (string memory) { return string( abi.encodePacked( "data:application/json;base64,", encodeByte64( bytes( string( abi.encodePacked( '{"name": "Santa.FM x PoolTogether NFT Gift Exchange", ', '"description": "Santa.FM x PoolTogether Presents are NFTs from the NFT Gift Exchange pool. Add a NFT gift to the pool and receive a NFT Present in return that you open on Christmas morning.", ', '"external_link": "https://pooltogether.santa.fm",' ) ) ) ) ) ); } /** * @notice Function that returns the URI for a token * @param id - Token ID we're referencing */ function tokenURI(uint256 id) public view override returns (string memory) { // Fail if token hasn't been minted require(id <= totalTokensMinted); // Fail if token has been burned require(!burned[id]); return string( abi.encodePacked( "data:application/json;base64,", encodeByte64( bytes( string( abi.encodePacked( '{"name": "Wrapped Present #', toString(id), '", ', '"description": "Wrapped Presents are given to you when you add an NFT to the Gift Dexchange. Use this present to redeem a random gift on Christmas Day!", ', '"image": "', tokenImage, '", "attributes": [{"trait_type": "Gift", "value": "Wrapped Present"}, {"trait_type": "Year", "value": "2022" }]}' ) ) ) ) ) ); } /** * @notice Function that encodes byte64 * @param data - data to be encoded */ function encodeByte64( bytes memory data ) internal pure returns (string memory) { if (data.length == 0) return ""; // load the table into memory string memory table = TABLE; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((data.length + 2) / 3); // add some extra buffer at the end required for the writing string memory result = new string(encodedLen + 32); assembly { // set the actual output length mstore(result, encodedLen) // prepare the lookup table let tablePtr := add(table, 1) // input ptr let dataPtr := data let endPtr := add(dataPtr, mload(data)) // result ptr, jump over length let resultPtr := add(result, 32) // run over the input, 3 bytes at a time for { } lt(dataPtr, endPtr) { } { dataPtr := add(dataPtr, 3) // read 3 bytes let input := mload(dataPtr) // write 4 characters mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(6, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(input, 0x3F)))) ) resultPtr := add(resultPtr, 1) } // padding with '=' switch mod(mload(data), 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } } return result; } /** * @notice Function that converts numbers to strings * @param value - number to be converted */ function toString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /* * Modifiers */ modifier onlyMinter() { require(msg.sender == minter); _; } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"uint64","name":"subscriptionId","type":"uint64"},{"internalType":"address","name":"vrfCoordinator","type":"address"},{"internalType":"bytes32","name":"keyHash","type":"bytes32"},{"internalType":"uint256","name":"registrationEnd","type":"uint256"},{"internalType":"uint256","name":"redemptionStart","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"presentNft","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AllGiftsGiven","type":"error"},{"inputs":[],"name":"CannotGiftPresent","type":"error"},{"inputs":[],"name":"DoesNotOwnPresent","type":"error"},{"inputs":[],"name":"GiftMustSupportERC721Interface","type":"error"},{"inputs":[],"name":"HasNotBeenShuffled","type":"error"},{"inputs":[],"name":"InvalidSenderMustNotBeContract","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"MaxGiftsReached","type":"error"},{"inputs":[],"name":"MustApproveContract","type":"error"},{"inputs":[],"name":"MustOwnTokenId","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","type":"error"},{"inputs":[],"name":"PoolSizeExceedsAmount","type":"error"},{"inputs":[],"name":"RedemptionHasNotStarted","type":"error"},{"inputs":[],"name":"RegistrationEnded","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gifter","type":"address"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"AddGift","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gifter","type":"address"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"GiftAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"presentTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"GiftChosen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"GiftUnwrapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"NewRandomNumberConsumerOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newSigner","type":"address"}],"name":"NewSigner","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":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"ReturnedRandomness","type":"event"},{"inputs":[],"name":"MAX_GIFTS","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEED","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEED_REQUEST_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHUFFLED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"addGift","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getChosenGifts","outputs":[{"components":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct SantaProtocol.Gift[]","name":"gifts","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getContractHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftPool","outputs":[{"components":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct SantaProtocol.Gift[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftPoolIndices","outputs":[{"internalType":"uint32[]","name":"","type":"uint32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftPoolSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNumberOfChosenGifts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"}],"name":"giftSupports721","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"hashGift","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"openGift","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":"requestSeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_giftPool","outputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_giftPoolIndices","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_randomWords","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_redemptionStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_registrationEnd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_requestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_requestIdMapping","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"callbackGasLimit","type":"uint32"}],"name":"setCallbackGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"keyHash","type":"bytes32"}],"name":"setKeyHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_maxGifts","type":"uint32"}],"name":"setMaxGifts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_isPaused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRedemptionStart","type":"uint256"}],"name":"setRedemptionStart","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRegistrationEnd","type":"uint256"}],"name":"setRegistrationEnd","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSigner","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"subscriptionId","type":"uint64"}],"name":"setSubscriptionId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"startPosition","type":"uint32"},{"internalType":"uint32","name":"endPosition","type":"uint32"}],"name":"shuffleRandomGiftIndices","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"validateGiftHashSignature","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60c06040526002805463ffffffff1916620186a0179055600a805460ff19169055600d805462c3500064ffffffffff199091161790553480156200004257600080fd5b50604051620023883803806200238883398101604081905262000065916200016f565b86868681620000743362000102565b6001600160601b0319606091821b811660805292901b90911660a052600155600080546001600160401b03909216600160a01b02600160a01b600160e01b0319909216919091179055600893909355600991909155600780546001600160a01b039283166001600160a01b0319918216179091556010805493909216921691909117905550620001f6915050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146200016a57600080fd5b919050565b600080600080600080600060e0888a0312156200018b57600080fd5b87516001600160401b0381168114620001a357600080fd5b9650620001b36020890162000152565b9550604088015194506060880151935060808801519250620001d860a0890162000152565b9150620001e860c0890162000152565b905092959891949750929550565b60805160601c60a05160601c61215f6200022960003960006117080152600081816106ae01526106f0015261215f6000f3fe608060405234801561001057600080fd5b50600436106102325760003560e01c80638da5cb5b11610130578063c60f3ac9116100b8578063ea7b4f771161007c578063ea7b4f771461050c578063f27010e91461051f578063f2fde38b14610532578063f3fecc0b14610545578063f6eaffc81461055857600080fd5b8063c60f3ac9146104c1578063cb111cf8146104d4578063e067510c146104e7578063e5bc1759146104fa578063e89e106a1461050357600080fd5b8063998dc690116100ff578063998dc6901461045c578063a0c70d6914610464578063a4eb718c1461048e578063a9aad58c146104a1578063c48de91f146104ae57600080fd5b80638da5cb5b14610408578063964da0db1461041957806397e8db301461043c578063985447101461044957600080fd5b806347c76ef1116101be5780637af9f010116101825780637af9f010146103a55780637f712e41146103b857806385dfc7e4146103cd578063889dae13146103e25780638d17e3ac146103f557600080fd5b806347c76ef114610317578063521a179e146103205780636c19e78314610361578063715018a6146103745780637a33d5ae1461037c57600080fd5b8063150b7a0211610205578063150b7a021461029a57806316c38b3c146102c65780631fe543e3146102d95780633dff11f1146102ec5780633e6c8376146102f557600080fd5b80630770e2381461023757806309b98ce8146102745780630edc473714610289578063114bf2e314610292575b600080fd5b60408051466020808301919091523082840152825180830384018152606090920190925280519101205b6040519081526020015b60405180910390f35b610287610282366004611e3a565b61056b565b005b610261600b5481565b6102876105be565b6102ad6102a8366004611bb1565b610635565b6040516001600160e01b0319909116815260200161026b565b6102876102d4366004611d15565b610688565b6102876102e7366004611d81565b6106a3565b61026160085481565b610308610303366004611d4f565b61072b565b60405161026b93929190611eb2565b610261600c5481565b61034961032e366004611d4f565b6005602052600090815260409020546001600160a01b031681565b6040516001600160a01b03909116815260200161026b565b61028761036f366004611b2f565b61076b565b610287610795565b61026161038a366004611b2f565b6001600160a01b031660009081526011602052604090205490565b6102876103b3366004611d4f565b6107a9565b6103c06107b6565b60405161026b9190611f9a565b6103d561083a565b60405161026b9190611f2a565b6102616103f0366004611b70565b6108c1565b610287610403366004611d4f565b610966565b6000546001600160a01b0316610349565b61042c610427366004611b2f565b610973565b604051901515815260200161026b565b600d5461042c9060ff1681565b610287610457366004611d4f565b610a03565b600e54610261565b600d5461047990610100900463ffffffff1681565b60405163ffffffff909116815260200161026b565b61028761049c366004611e3a565b610a10565b600a5461042c9060ff1681565b61042c6104bc366004611c50565b610a34565b6104796104cf366004611d4f565b610ac8565b6103d56104e2366004611b2f565b610b02565b6102876104f5366004611cbc565b610b9f565b61026160095481565b61026160045481565b61028761051a366004611e88565b610fec565b61028761052d366004611e55565b611022565b610287610540366004611b2f565b6112d2565b610287610553366004611d4f565b61134b565b610261610566366004611d4f565b611639565b61057361165a565b600e5463ffffffff8216101561059c5760405163059f769f60e31b815260040160405180910390fd5b600d805463ffffffff9092166101000264ffffffff0019909216919091179055565b6105c661165a565b600854421161061c5760405162461bcd60e51b815260206004820152601e60248201527f526567697374726174696f6e20686173206e6f7420656e64656420796574000060448201526064015b60405180910390fd5b61062660016116b4565b600c55600d805460ff19169055565b60007fa05d90f300156ad1b545bc5d8197024456f21d22a708f5af04dd293e3d605251868686868660405161066e959493929190611ed6565b60405180910390a150630a85bd0160e11b95945050505050565b61069061165a565b600a805460ff1916911515919091179055565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461071d5760405163073e64fd60e21b81523360048201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166024820152604401610613565b61072782826117b0565b5050565b600e818154811061073b57600080fd5b60009182526020909120600390910201805460018201546002909201546001600160a01b03918216935091169083565b61077361165a565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b61079d61165a565b6107a760006117df565b565b6107b161165a565b600955565b6060600f80548060200260200160405190810160405280929190818152602001828054801561083057602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116107f35790505b5050505050905090565b6060600e805480602002602001604051908101604052809291908181526020016000905b828210156108b8576000848152602090819020604080516060810182526003860290920180546001600160a01b0390811684526001808301549091168486015260029091015491830191909152908352909201910161085e565b50505050905090565b6000806040518060600160405280866001600160a01b03168152602001856001600160a01b0316815260200184815250604051602001610901919061201d565b60408051808303601f19018152828252805160209182012046828501523084840152825180850384018152606085018452805190830120608085015260a0808501919091528251808503909101815260c0909301909152815191012095945050505050565b61096e61165a565b600855565b6040516301ffc9a760e01b81526380ac58cd60e01b60048201526000906001600160a01b038316906301ffc9a79060240160206040518083038186803b1580156109bc57600080fd5b505afa9250505080156109ec575060408051601f3d908101601f191682019092526109e991810190611d32565b60015b6109f857506000919050565b92915050565b919050565b610a0b61165a565b600155565b610a1861165a565b6002805463ffffffff191663ffffffff92909216919091179055565b600080610a428686866108c1565b90506000610a9d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000610aab828661182f565b6007546001600160a01b0390811691161498975050505050505050565b600f8181548110610ad857600080fd5b9060005260206000209060089182820401919006600402915054906101000a900463ffffffff1681565b6001600160a01b0381166000908152601160209081526040808320805482518185028101850190935280835260609492939192909184015b82821015610b94576000848152602090819020604080516060810182526003860290920180546001600160a01b03908116845260018083015490911684860152600290910154918301919091529083529092019101610b3a565b505050509050919050565b600a5460ff1615610bc25760405162461bcd60e51b815260040161061390611fd8565b600854421115610be5576040516302ee88f560e41b815260040160405180910390fd5b600d54600e5461010090910463ffffffff1611610c1557604051631213ef8960e31b815260040160405180910390fd5b6010546001600160a01b0384811691161415610c445760405163f52aae4360e01b815260040160405180910390fd5b610c4d83610973565b610c6a57604051630620437160e11b815260040160405180910390fd5b6040516331a9108f60e11b81526004810183905233906001600160a01b03851690636352211e9060240160206040518083038186803b158015610cac57600080fd5b505afa158015610cc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce49190611b53565b6001600160a01b031614610d0b57604051633bf00d8d60e21b815260040160405180910390fd5b60405163020604bf60e21b81526004810183905230906001600160a01b0385169063081812fc9060240160206040518083038186803b158015610d4d57600080fd5b505afa158015610d61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d859190611b53565b6001600160a01b031614610dac57604051636b73ff7960e11b815260040160405180910390fd5b610db833848484610a34565b610dd557604051638baa579f60e01b815260040160405180910390fd5b604051632142170760e11b81526001600160a01b038416906342842e0e90610e0590339030908790600401611eb2565b600060405180830381600087803b158015610e1f57600080fd5b505af1158015610e33573d6000803e3d6000fd5b5050601054604051630b1ba4e360e31b81523360048201526001600160a01b0390911692506358dd27189150602401600060405180830381600087803b158015610e7c57600080fd5b505af1158015610e90573d6000803e3d6000fd5b5050604080516060810182523381526001600160a01b0387811660208301908152928201878152600e8054600181810183556000839052945160039091027fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd810180549286166001600160a01b031993841617905595517fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fe8701805491909516911617909255517fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3ff909301929092559054600f9350610f6f925061207d565b8154600181018355600092835260209092206008830401805460079093166004026101000a63ffffffff8181021990941692909316929092021790556040517faf5427fde32e98c3ccd610fa453b4b72f665627361c9edd4325e96916cbbbb8790610fdf90339086908690611eb2565b60405180910390a1505050565b610ff461165a565b6000805467ffffffffffffffff909216600160a01b0267ffffffffffffffff60a01b19909216919091179055565b61102a61165a565b600b5461106f5760405162461bcd60e51b815260206004820152601360248201527214d1515108191bd95cc81b9bdd08195e1a5cdd606a1b6044820152606401610613565b8163ffffffff168163ffffffff1610156110dd5760405162461bcd60e51b815260206004820152602960248201527f456e6420706f736974696f6e206d757374206265206166746572207374617274604482015268103837b9b4ba34b7b760b91b6064820152608401610613565b600e546000906110ef9060019061207d565b8263ffffffff16116111015781611110565b600e546111109060019061207d565b9050825b8163ffffffff168163ffffffff16116112a257600e54600b546040516000929161115191859060200191825263ffffffff16602082015260400190565b6040516020818303038152906040528051906020012060001c61117491906120a2565b9050600f8163ffffffff168154811061118f5761118f6120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16600f8363ffffffff16815481106111ce576111ce6120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16600f8463ffffffff168154811061120d5761120d6120da565b9060005260206000209060089182820401919006600402600f8563ffffffff168154811061123d5761123d6120da565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff1602179055505050818060010192505050611114565b50600e546112b29060019061207d565b8163ffffffff1614156112cd57600d805460ff191660011790555b505050565b6112da61165a565b6001600160a01b03811661133f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610613565b611348816117df565b50565b600a5460ff161561136e5760405162461bcd60e51b815260040161061390611fd8565b600954421015611391576040516319fed63960e21b815260040160405180910390fd5b600d5460ff166113b45760405163f34818c560e01b815260040160405180910390fd5b600e546113d45760405163022a0b9b60e61b815260040160405180910390fd5b6010546040516331a9108f60e11b81526004810183905233916001600160a01b031690636352211e9060240160206040518083038186803b15801561141857600080fd5b505afa15801561142c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114509190611b53565b6001600160a01b031614611477576040516331a4290b60e01b815260040160405180910390fd5b6000600f61148660018461207d565b81548110611496576114966120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506000600e8263ffffffff16815481106114d9576114d96120da565b60009182526020918290206040805160608101825260039390930290910180546001600160a01b039081168452600182015481169484019490945260020154828201526010549051633f34d4cf60e21b8152600481018790523360248201529193509091169063fcd3533c90604401600060405180830381600087803b15801561156257600080fd5b505af1158015611576573d6000803e3d6000fd5b5050505080602001516001600160a01b03166342842e0e303384604001516040518463ffffffff1660e01b81526004016115b293929190611eb2565b600060405180830381600087803b1580156115cc57600080fd5b505af11580156115e0573d6000803e3d6000fd5b50505060208083015160408085015181513381529384018890526001600160a01b039092169083015260608201527f0e660191854ca48492f5d6d0ae52c3c534561146f368eff1c3324cef2d1837b59150608001610fdf565b6003818154811061164957600080fd5b600091825260209091200154905081565b6000546001600160a01b031633146107a75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610613565b600154600080546002546040516305d3b1d360e41b81526004810194909452600160a01b90910467ffffffffffffffff1660248401526003604484015263ffffffff908116606484015283166084830152907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690635d3b1d309060a401602060405180830381600087803b15801561175457600080fd5b505af1158015611768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061178c9190611d68565b600081815260056020526040902080546001600160a01b0319163317905592915050565b81600c54141561072757806000815181106117cd576117cd6120da565b6020026020010151600b819055505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600061183e8585611853565b9150915061184b81611899565b509392505050565b60008082516041141561188a5760208301516040840151606085015160001a61187e878285856119e7565b94509450505050611892565b506000905060025b9250929050565b60008160048111156118ad576118ad6120c4565b14156118b65750565b60018160048111156118ca576118ca6120c4565b14156119185760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610613565b600281600481111561192c5761192c6120c4565b141561197a5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610613565b600381600481111561198e5761198e6120c4565b14156113485760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610613565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611a1e5750600090506003611aa2565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611a72573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611a9b57600060019250925050611aa2565b9150600090505b94509492505050565b600082601f830112611abc57600080fd5b813567ffffffffffffffff811115611ad657611ad66120f0565b611ae9601f8201601f191660200161204c565b818152846020838601011115611afe57600080fd5b816020850160208301376000918101602001919091529392505050565b803563ffffffff811681146109fe57600080fd5b600060208284031215611b4157600080fd5b8135611b4c81612106565b9392505050565b600060208284031215611b6557600080fd5b8151611b4c81612106565b600080600060608486031215611b8557600080fd5b8335611b9081612106565b92506020840135611ba081612106565b929592945050506040919091013590565b600080600080600060808688031215611bc957600080fd5b8535611bd481612106565b94506020860135611be481612106565b935060408601359250606086013567ffffffffffffffff80821115611c0857600080fd5b818801915088601f830112611c1c57600080fd5b813581811115611c2b57600080fd5b896020828501011115611c3d57600080fd5b9699959850939650602001949392505050565b60008060008060808587031215611c6657600080fd5b8435611c7181612106565b93506020850135611c8181612106565b925060408501359150606085013567ffffffffffffffff811115611ca457600080fd5b611cb087828801611aab565b91505092959194509250565b600080600060608486031215611cd157600080fd5b8335611cdc81612106565b925060208401359150604084013567ffffffffffffffff811115611cff57600080fd5b611d0b86828701611aab565b9150509250925092565b600060208284031215611d2757600080fd5b8135611b4c8161211b565b600060208284031215611d4457600080fd5b8151611b4c8161211b565b600060208284031215611d6157600080fd5b5035919050565b600060208284031215611d7a57600080fd5b5051919050565b60008060408385031215611d9457600080fd5b8235915060208084013567ffffffffffffffff80821115611db457600080fd5b818601915086601f830112611dc857600080fd5b813581811115611dda57611dda6120f0565b8060051b9150611deb84830161204c565b8181528481019084860184860187018b1015611e0657600080fd5b600095505b83861015611e29578035835260019590950194918601918601611e0b565b508096505050505050509250929050565b600060208284031215611e4c57600080fd5b611b4c82611b1b565b60008060408385031215611e6857600080fd5b611e7183611b1b565b9150611e7f60208401611b1b565b90509250929050565b600060208284031215611e9a57600080fd5b813567ffffffffffffffff81168114611b4c57600080fd5b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b038681168252851660208201526040810184905260806060820181905281018290526000828460a0840137600060a0848401015260a0601f19601f85011683010190509695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611f8e57611f7b83855180516001600160a01b03908116835260208083015190911690830152604090810151910152565b9284019260609290920191600101611f46565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611f8e57835163ffffffff1683529284019291840191600101611fb6565b60208082526025908201527f546865204e46542045786368616e67652069732063757272656e746c792070616040820152643ab9b2b21760d91b606082015260800190565b81516001600160a01b0390811682526020808401519091169082015260408083015190820152606081016109f8565b604051601f8201601f1916810167ffffffffffffffff81118282101715612075576120756120f0565b604052919050565b60008282101561209d57634e487b7160e01b600052601160045260246000fd5b500390565b6000826120bf57634e487b7160e01b600052601260045260246000fd5b500690565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461134857600080fd5b801515811461134857600080fdfea2646970667358221220a51dc067727245edd79a287d0555eba1c9d256a91e7f508c4bbe0b61de3c2b2364736f6c63430008070033000000000000000000000000000000000000000000000000000000000000024e000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699098af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef0000000000000000000000000000000000000000000000000000000063a7e6e00000000000000000000000000000000000000000000000000000000063a85760000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e0000000000000000000000002cf5f3c007164adcac33adcc942e85606f9a6022
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102325760003560e01c80638da5cb5b11610130578063c60f3ac9116100b8578063ea7b4f771161007c578063ea7b4f771461050c578063f27010e91461051f578063f2fde38b14610532578063f3fecc0b14610545578063f6eaffc81461055857600080fd5b8063c60f3ac9146104c1578063cb111cf8146104d4578063e067510c146104e7578063e5bc1759146104fa578063e89e106a1461050357600080fd5b8063998dc690116100ff578063998dc6901461045c578063a0c70d6914610464578063a4eb718c1461048e578063a9aad58c146104a1578063c48de91f146104ae57600080fd5b80638da5cb5b14610408578063964da0db1461041957806397e8db301461043c578063985447101461044957600080fd5b806347c76ef1116101be5780637af9f010116101825780637af9f010146103a55780637f712e41146103b857806385dfc7e4146103cd578063889dae13146103e25780638d17e3ac146103f557600080fd5b806347c76ef114610317578063521a179e146103205780636c19e78314610361578063715018a6146103745780637a33d5ae1461037c57600080fd5b8063150b7a0211610205578063150b7a021461029a57806316c38b3c146102c65780631fe543e3146102d95780633dff11f1146102ec5780633e6c8376146102f557600080fd5b80630770e2381461023757806309b98ce8146102745780630edc473714610289578063114bf2e314610292575b600080fd5b60408051466020808301919091523082840152825180830384018152606090920190925280519101205b6040519081526020015b60405180910390f35b610287610282366004611e3a565b61056b565b005b610261600b5481565b6102876105be565b6102ad6102a8366004611bb1565b610635565b6040516001600160e01b0319909116815260200161026b565b6102876102d4366004611d15565b610688565b6102876102e7366004611d81565b6106a3565b61026160085481565b610308610303366004611d4f565b61072b565b60405161026b93929190611eb2565b610261600c5481565b61034961032e366004611d4f565b6005602052600090815260409020546001600160a01b031681565b6040516001600160a01b03909116815260200161026b565b61028761036f366004611b2f565b61076b565b610287610795565b61026161038a366004611b2f565b6001600160a01b031660009081526011602052604090205490565b6102876103b3366004611d4f565b6107a9565b6103c06107b6565b60405161026b9190611f9a565b6103d561083a565b60405161026b9190611f2a565b6102616103f0366004611b70565b6108c1565b610287610403366004611d4f565b610966565b6000546001600160a01b0316610349565b61042c610427366004611b2f565b610973565b604051901515815260200161026b565b600d5461042c9060ff1681565b610287610457366004611d4f565b610a03565b600e54610261565b600d5461047990610100900463ffffffff1681565b60405163ffffffff909116815260200161026b565b61028761049c366004611e3a565b610a10565b600a5461042c9060ff1681565b61042c6104bc366004611c50565b610a34565b6104796104cf366004611d4f565b610ac8565b6103d56104e2366004611b2f565b610b02565b6102876104f5366004611cbc565b610b9f565b61026160095481565b61026160045481565b61028761051a366004611e88565b610fec565b61028761052d366004611e55565b611022565b610287610540366004611b2f565b6112d2565b610287610553366004611d4f565b61134b565b610261610566366004611d4f565b611639565b61057361165a565b600e5463ffffffff8216101561059c5760405163059f769f60e31b815260040160405180910390fd5b600d805463ffffffff9092166101000264ffffffff0019909216919091179055565b6105c661165a565b600854421161061c5760405162461bcd60e51b815260206004820152601e60248201527f526567697374726174696f6e20686173206e6f7420656e64656420796574000060448201526064015b60405180910390fd5b61062660016116b4565b600c55600d805460ff19169055565b60007fa05d90f300156ad1b545bc5d8197024456f21d22a708f5af04dd293e3d605251868686868660405161066e959493929190611ed6565b60405180910390a150630a85bd0160e11b95945050505050565b61069061165a565b600a805460ff1916911515919091179055565b336001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909161461071d5760405163073e64fd60e21b81523360048201526001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909166024820152604401610613565b61072782826117b0565b5050565b600e818154811061073b57600080fd5b60009182526020909120600390910201805460018201546002909201546001600160a01b03918216935091169083565b61077361165a565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b61079d61165a565b6107a760006117df565b565b6107b161165a565b600955565b6060600f80548060200260200160405190810160405280929190818152602001828054801561083057602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116107f35790505b5050505050905090565b6060600e805480602002602001604051908101604052809291908181526020016000905b828210156108b8576000848152602090819020604080516060810182526003860290920180546001600160a01b0390811684526001808301549091168486015260029091015491830191909152908352909201910161085e565b50505050905090565b6000806040518060600160405280866001600160a01b03168152602001856001600160a01b0316815260200184815250604051602001610901919061201d565b60408051808303601f19018152828252805160209182012046828501523084840152825180850384018152606085018452805190830120608085015260a0808501919091528251808503909101815260c0909301909152815191012095945050505050565b61096e61165a565b600855565b6040516301ffc9a760e01b81526380ac58cd60e01b60048201526000906001600160a01b038316906301ffc9a79060240160206040518083038186803b1580156109bc57600080fd5b505afa9250505080156109ec575060408051601f3d908101601f191682019092526109e991810190611d32565b60015b6109f857506000919050565b92915050565b919050565b610a0b61165a565b600155565b610a1861165a565b6002805463ffffffff191663ffffffff92909216919091179055565b600080610a428686866108c1565b90506000610a9d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000610aab828661182f565b6007546001600160a01b0390811691161498975050505050505050565b600f8181548110610ad857600080fd5b9060005260206000209060089182820401919006600402915054906101000a900463ffffffff1681565b6001600160a01b0381166000908152601160209081526040808320805482518185028101850190935280835260609492939192909184015b82821015610b94576000848152602090819020604080516060810182526003860290920180546001600160a01b03908116845260018083015490911684860152600290910154918301919091529083529092019101610b3a565b505050509050919050565b600a5460ff1615610bc25760405162461bcd60e51b815260040161061390611fd8565b600854421115610be5576040516302ee88f560e41b815260040160405180910390fd5b600d54600e5461010090910463ffffffff1611610c1557604051631213ef8960e31b815260040160405180910390fd5b6010546001600160a01b0384811691161415610c445760405163f52aae4360e01b815260040160405180910390fd5b610c4d83610973565b610c6a57604051630620437160e11b815260040160405180910390fd5b6040516331a9108f60e11b81526004810183905233906001600160a01b03851690636352211e9060240160206040518083038186803b158015610cac57600080fd5b505afa158015610cc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce49190611b53565b6001600160a01b031614610d0b57604051633bf00d8d60e21b815260040160405180910390fd5b60405163020604bf60e21b81526004810183905230906001600160a01b0385169063081812fc9060240160206040518083038186803b158015610d4d57600080fd5b505afa158015610d61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d859190611b53565b6001600160a01b031614610dac57604051636b73ff7960e11b815260040160405180910390fd5b610db833848484610a34565b610dd557604051638baa579f60e01b815260040160405180910390fd5b604051632142170760e11b81526001600160a01b038416906342842e0e90610e0590339030908790600401611eb2565b600060405180830381600087803b158015610e1f57600080fd5b505af1158015610e33573d6000803e3d6000fd5b5050601054604051630b1ba4e360e31b81523360048201526001600160a01b0390911692506358dd27189150602401600060405180830381600087803b158015610e7c57600080fd5b505af1158015610e90573d6000803e3d6000fd5b5050604080516060810182523381526001600160a01b0387811660208301908152928201878152600e8054600181810183556000839052945160039091027fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd810180549286166001600160a01b031993841617905595517fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fe8701805491909516911617909255517fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3ff909301929092559054600f9350610f6f925061207d565b8154600181018355600092835260209092206008830401805460079093166004026101000a63ffffffff8181021990941692909316929092021790556040517faf5427fde32e98c3ccd610fa453b4b72f665627361c9edd4325e96916cbbbb8790610fdf90339086908690611eb2565b60405180910390a1505050565b610ff461165a565b6000805467ffffffffffffffff909216600160a01b0267ffffffffffffffff60a01b19909216919091179055565b61102a61165a565b600b5461106f5760405162461bcd60e51b815260206004820152601360248201527214d1515108191bd95cc81b9bdd08195e1a5cdd606a1b6044820152606401610613565b8163ffffffff168163ffffffff1610156110dd5760405162461bcd60e51b815260206004820152602960248201527f456e6420706f736974696f6e206d757374206265206166746572207374617274604482015268103837b9b4ba34b7b760b91b6064820152608401610613565b600e546000906110ef9060019061207d565b8263ffffffff16116111015781611110565b600e546111109060019061207d565b9050825b8163ffffffff168163ffffffff16116112a257600e54600b546040516000929161115191859060200191825263ffffffff16602082015260400190565b6040516020818303038152906040528051906020012060001c61117491906120a2565b9050600f8163ffffffff168154811061118f5761118f6120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16600f8363ffffffff16815481106111ce576111ce6120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16600f8463ffffffff168154811061120d5761120d6120da565b9060005260206000209060089182820401919006600402600f8563ffffffff168154811061123d5761123d6120da565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff1602179055505050818060010192505050611114565b50600e546112b29060019061207d565b8163ffffffff1614156112cd57600d805460ff191660011790555b505050565b6112da61165a565b6001600160a01b03811661133f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610613565b611348816117df565b50565b600a5460ff161561136e5760405162461bcd60e51b815260040161061390611fd8565b600954421015611391576040516319fed63960e21b815260040160405180910390fd5b600d5460ff166113b45760405163f34818c560e01b815260040160405180910390fd5b600e546113d45760405163022a0b9b60e61b815260040160405180910390fd5b6010546040516331a9108f60e11b81526004810183905233916001600160a01b031690636352211e9060240160206040518083038186803b15801561141857600080fd5b505afa15801561142c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114509190611b53565b6001600160a01b031614611477576040516331a4290b60e01b815260040160405180910390fd5b6000600f61148660018461207d565b81548110611496576114966120da565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506000600e8263ffffffff16815481106114d9576114d96120da565b60009182526020918290206040805160608101825260039390930290910180546001600160a01b039081168452600182015481169484019490945260020154828201526010549051633f34d4cf60e21b8152600481018790523360248201529193509091169063fcd3533c90604401600060405180830381600087803b15801561156257600080fd5b505af1158015611576573d6000803e3d6000fd5b5050505080602001516001600160a01b03166342842e0e303384604001516040518463ffffffff1660e01b81526004016115b293929190611eb2565b600060405180830381600087803b1580156115cc57600080fd5b505af11580156115e0573d6000803e3d6000fd5b50505060208083015160408085015181513381529384018890526001600160a01b039092169083015260608201527f0e660191854ca48492f5d6d0ae52c3c534561146f368eff1c3324cef2d1837b59150608001610fdf565b6003818154811061164957600080fd5b600091825260209091200154905081565b6000546001600160a01b031633146107a75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610613565b600154600080546002546040516305d3b1d360e41b81526004810194909452600160a01b90910467ffffffffffffffff1660248401526003604484015263ffffffff908116606484015283166084830152907f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699096001600160a01b031690635d3b1d309060a401602060405180830381600087803b15801561175457600080fd5b505af1158015611768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061178c9190611d68565b600081815260056020526040902080546001600160a01b0319163317905592915050565b81600c54141561072757806000815181106117cd576117cd6120da565b6020026020010151600b819055505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600061183e8585611853565b9150915061184b81611899565b509392505050565b60008082516041141561188a5760208301516040840151606085015160001a61187e878285856119e7565b94509450505050611892565b506000905060025b9250929050565b60008160048111156118ad576118ad6120c4565b14156118b65750565b60018160048111156118ca576118ca6120c4565b14156119185760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610613565b600281600481111561192c5761192c6120c4565b141561197a5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610613565b600381600481111561198e5761198e6120c4565b14156113485760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610613565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611a1e5750600090506003611aa2565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611a72573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611a9b57600060019250925050611aa2565b9150600090505b94509492505050565b600082601f830112611abc57600080fd5b813567ffffffffffffffff811115611ad657611ad66120f0565b611ae9601f8201601f191660200161204c565b818152846020838601011115611afe57600080fd5b816020850160208301376000918101602001919091529392505050565b803563ffffffff811681146109fe57600080fd5b600060208284031215611b4157600080fd5b8135611b4c81612106565b9392505050565b600060208284031215611b6557600080fd5b8151611b4c81612106565b600080600060608486031215611b8557600080fd5b8335611b9081612106565b92506020840135611ba081612106565b929592945050506040919091013590565b600080600080600060808688031215611bc957600080fd5b8535611bd481612106565b94506020860135611be481612106565b935060408601359250606086013567ffffffffffffffff80821115611c0857600080fd5b818801915088601f830112611c1c57600080fd5b813581811115611c2b57600080fd5b896020828501011115611c3d57600080fd5b9699959850939650602001949392505050565b60008060008060808587031215611c6657600080fd5b8435611c7181612106565b93506020850135611c8181612106565b925060408501359150606085013567ffffffffffffffff811115611ca457600080fd5b611cb087828801611aab565b91505092959194509250565b600080600060608486031215611cd157600080fd5b8335611cdc81612106565b925060208401359150604084013567ffffffffffffffff811115611cff57600080fd5b611d0b86828701611aab565b9150509250925092565b600060208284031215611d2757600080fd5b8135611b4c8161211b565b600060208284031215611d4457600080fd5b8151611b4c8161211b565b600060208284031215611d6157600080fd5b5035919050565b600060208284031215611d7a57600080fd5b5051919050565b60008060408385031215611d9457600080fd5b8235915060208084013567ffffffffffffffff80821115611db457600080fd5b818601915086601f830112611dc857600080fd5b813581811115611dda57611dda6120f0565b8060051b9150611deb84830161204c565b8181528481019084860184860187018b1015611e0657600080fd5b600095505b83861015611e29578035835260019590950194918601918601611e0b565b508096505050505050509250929050565b600060208284031215611e4c57600080fd5b611b4c82611b1b565b60008060408385031215611e6857600080fd5b611e7183611b1b565b9150611e7f60208401611b1b565b90509250929050565b600060208284031215611e9a57600080fd5b813567ffffffffffffffff81168114611b4c57600080fd5b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b038681168252851660208201526040810184905260806060820181905281018290526000828460a0840137600060a0848401015260a0601f19601f85011683010190509695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611f8e57611f7b83855180516001600160a01b03908116835260208083015190911690830152604090810151910152565b9284019260609290920191600101611f46565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611f8e57835163ffffffff1683529284019291840191600101611fb6565b60208082526025908201527f546865204e46542045786368616e67652069732063757272656e746c792070616040820152643ab9b2b21760d91b606082015260800190565b81516001600160a01b0390811682526020808401519091169082015260408083015190820152606081016109f8565b604051601f8201601f1916810167ffffffffffffffff81118282101715612075576120756120f0565b604052919050565b60008282101561209d57634e487b7160e01b600052601160045260246000fd5b500390565b6000826120bf57634e487b7160e01b600052601260045260246000fd5b500690565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461134857600080fd5b801515811461134857600080fdfea2646970667358221220a51dc067727245edd79a287d0555eba1c9d256a91e7f508c4bbe0b61de3c2b2364736f6c63430008070033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000024e000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699098af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef0000000000000000000000000000000000000000000000000000000063a7e6e00000000000000000000000000000000000000000000000000000000063a85760000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e0000000000000000000000002cf5f3c007164adcac33adcc942e85606f9a6022
-----Decoded View---------------
Arg [0] : subscriptionId (uint64): 590
Arg [1] : vrfCoordinator (address): 0x271682DEB8C4E0901D1a1550aD2e64D568E69909
Arg [2] : keyHash (bytes32): 0x8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef
Arg [3] : registrationEnd (uint256): 1671948000
Arg [4] : redemptionStart (uint256): 1671976800
Arg [5] : signer (address): 0xBf6B2273bBb4489e2EFF99AE43fF148F04849b6E
Arg [6] : presentNft (address): 0x2Cf5F3c007164ADCaC33aDcC942e85606F9a6022
-----Encoded View---------------
7 Constructor Arguments found :
Arg [0] : 000000000000000000000000000000000000000000000000000000000000024e
Arg [1] : 000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909
Arg [2] : 8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef
Arg [3] : 0000000000000000000000000000000000000000000000000000000063a7e6e0
Arg [4] : 0000000000000000000000000000000000000000000000000000000063a85760
Arg [5] : 000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e
Arg [6] : 0000000000000000000000002cf5f3c007164adcac33adcc942e85606f9a6022
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.