Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
QuestFactory
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; // Inherits import {Initializable} from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; import {LegacyStorage} from "./libraries/LegacyStorage.sol"; import {OwnableRoles} from "solady/auth/OwnableRoles.sol"; // Implements import {IQuestFactory} from "./interfaces/IQuestFactory.sol"; // Leverages import {ECDSA} from "solady/utils/ECDSA.sol"; import {LibClone} from "solady/utils/LibClone.sol"; import {LibString} from "solady/utils/LibString.sol"; import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; import {LibZip} from "solady/utils/LibZip.sol"; // References import {IERC1155} from "openzeppelin-contracts/token/ERC1155/IERC1155.sol"; import {IQuestOwnable} from "./interfaces/IQuestOwnable.sol"; import {IQuest1155Ownable} from "./interfaces/IQuest1155Ownable.sol"; /// @title QuestFactory /// @author RabbitHole.gg /// @dev This contract is used to create quests and handle claims // solhint-disable-next-line max-states-count /// @custom:oz-upgrades-from QuestFactoryV0 contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFactory { /*////////////////////////////////////////////////////////////// USING //////////////////////////////////////////////////////////////*/ using SafeTransferLib for address; using LibClone for address; using LibString for string; using LibString for uint256; using LibString for address; /*////////////////////////////////////////////////////////////// STORAGE //////////////////////////////////////////////////////////////*/ address public claimSignerAddress; address public protocolFeeRecipient; address public erc20QuestAddress; address public erc1155QuestAddress; mapping(string => Quest) public quests; address public rabbitHoleReceiptContract; // not used address public rabbitHoleTicketsContract; // not used mapping(address => bool) public rewardAllowlist; uint16 public questFee; uint256 public mintFee; /// @custom:oz-renamed-from mintFeeRecipient address public defaultMintFeeRecipient; uint256 private locked; /// @custom:oz-renamed-from questTerminalKeyContract address public defaultReferralFeeRecipient; uint256 public nftQuestFee; address public questNFTAddress; // not used mapping(address => address[]) public ownerCollections; mapping(address => NftQuestFees) public nftQuestFeeList; uint16 public referralFee; address public sablierV2LockupLinearAddress; mapping(address => address) public mintFeeRecipientList; // insert new vars here at the end to keep the storage layout the same /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ /// @custom:oz-upgrades-unsafe-allow constructor // solhint-disable-next-line func-visibility constructor() initializer {} function initialize( address claimSignerAddress_, address protocolFeeRecipient_, address erc20QuestAddress_, address payable erc1155QuestAddress_, address ownerAddress_, address defaultReferralFeeRecipientAddress_, address sablierV2LockupLinearAddress_, uint256 nftQuestFee_, uint16 referralFee_, uint256 mintFee_ ) external initializer { _initializeOwner(ownerAddress_); questFee = 2000; // in BIPS locked = 1; claimSignerAddress = claimSignerAddress_; protocolFeeRecipient = protocolFeeRecipient_; erc20QuestAddress = erc20QuestAddress_; erc1155QuestAddress = erc1155QuestAddress_; defaultReferralFeeRecipient = defaultReferralFeeRecipientAddress_; sablierV2LockupLinearAddress = sablierV2LockupLinearAddress_; nftQuestFee = nftQuestFee_; referralFee = referralFee_; mintFee = mintFee_; } /*////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////*/ modifier checkQuest(string memory questId_, address rewardTokenAddress_) { Quest storage currentQuest = quests[questId_]; if (currentQuest.questAddress != address(0)) revert QuestIdUsed(); if (!rewardAllowlist[rewardTokenAddress_]) revert RewardNotAllowed(); if (erc20QuestAddress == address(0)) revert Erc20QuestAddressNotSet(); _; } modifier claimChecks(ClaimData memory claimData_) { Quest storage currentQuest = quests[claimData_.questId]; if (currentQuest.numberMinted + 1 > currentQuest.totalParticipants) revert OverMaxAllowedToMint(); if (currentQuest.addressMinted[claimData_.claimer]) revert AddressAlreadyMinted(); if (recoverSigner(claimData_.hashBytes, claimData_.signature) != claimSignerAddress) revert AddressNotSigned(); _; } /// @dev ReentrancyGuard modifier from solmate, copied here because it was added after storage layout was finalized on first deploy /// @dev from https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol modifier nonReentrant() virtual { if (locked != 1) revert Reentrancy(); locked = 2; _; locked = 1; } modifier nonZeroAddress(address address_) { if (address_ == address(0)) revert ZeroAddressNotAllowed(); _; } modifier sufficientMintFee() { if (msg.value < mintFee) revert InvalidMintFee(); _; } /*////////////////////////////////////////////////////////////// EXTERNAL UPDATE //////////////////////////////////////////////////////////////*/ /*////////////////////////////////////////////////////////////// CREATE //////////////////////////////////////////////////////////////*/ /// @dev Create an erc1155 quest and start it at the same time. The function will transfer the reward amount to the quest contract /// @param rewardTokenAddress_ The contract address of the reward token /// @param endTime_ The end time of the quest /// @param startTime_ The start time of the quest /// @param totalParticipants_ The total amount of participants (accounts) the quest will have /// @param tokenId_ The reward token id of the erc1155 at rewardTokenAddress_ /// @param questId_ The id of the quest /// @param actionType_ The action type for the quest /// @param questName_ The name of the quest /// @return address the quest contract address function createERC1155Quest( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 tokenId_, string memory questId_, string memory actionType_, string memory questName_ ) external payable nonReentrant returns (address) { return createERC1155QuestInternal( ERC1155QuestData( rewardTokenAddress_, endTime_, startTime_, totalParticipants_, tokenId_, questId_, actionType_, questName_ ) ); } /// @notice Depricated /// @dev Create an erc1155 quest and start it at the same time. The function will transfer the reward amount to the quest contract /// @param rewardTokenAddress_ The contract address of the reward token /// @param endTime_ The end time of the quest /// @param startTime_ The start time of the quest /// @param totalParticipants_ The total amount of participants (accounts) the quest will have /// @param tokenId_ The reward token id of the erc1155 at rewardTokenAddress_ /// @param questId_ The id of the quest /// @return address the quest contract address function create1155QuestAndQueue( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 tokenId_, string memory questId_, string memory ) external payable nonReentrant returns (address) { return createERC1155QuestInternal( ERC1155QuestData( rewardTokenAddress_, endTime_, startTime_, totalParticipants_, tokenId_, questId_, "", "" ) ); } /// @dev Create an erc20 quest and start it at the same time. The function will transfer the reward amount to the quest contract /// @param rewardTokenAddress_ The contract address of the reward token /// @param endTime_ The end time of the quest /// @param startTime_ The start time of the quest /// @param totalParticipants_ The total amount of participants (accounts) the quest will have /// @param rewardAmount_ The reward amount for an erc20 quest /// @param questId_ The id of the quest /// @param actionType_ The action type for the quest /// @param questName_ The name of the quest /// @return address the quest contract address function createERC20Quest( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 rewardAmount_, string memory questId_, string memory actionType_, string memory questName_ ) external checkQuest(questId_, rewardTokenAddress_) returns (address) { return createERC20QuestInternal( ERC20QuestData( rewardTokenAddress_, endTime_, startTime_, totalParticipants_, rewardAmount_, questId_, actionType_, questName_, 0, "erc20" ) ); } /// @notice Depricated /// @dev Create an erc20 quest and start it at the same time. The function will transfer the reward amount to the quest contract /// @param rewardTokenAddress_ The contract address of the reward token /// @param endTime_ The end time of the quest /// @param startTime_ The start time of the quest /// @param totalParticipants_ The total amount of participants (accounts) the quest will have /// @param rewardAmount_ The reward amount for an erc20 quest /// @param questId_ The id of the quest /// @return address the quest contract address function createQuestAndQueue( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 rewardAmount_, string memory questId_, string memory, uint256 ) external checkQuest(questId_, rewardTokenAddress_) returns (address) { return createERC20QuestInternal( ERC20QuestData( rewardTokenAddress_, endTime_, startTime_, totalParticipants_, rewardAmount_, questId_, "", "", 0, "erc20" ) ); } /*////////////////////////////////////////////////////////////// CLAIM //////////////////////////////////////////////////////////////*/ /// @dev Claim rewards for a quest /// @param compressedData_ The claim data in abi encoded bytes, compressed with cdCompress from solady LibZip function claimCompressed(bytes calldata compressedData_) external payable { bytes memory data_ = LibZip.cdDecompress(compressedData_); ( bytes32 txHash_, bytes32 r_, bytes32 vs_, address ref_, bytes16 questid_, uint16 txHashChainId_ ) = abi.decode( data_, (bytes32, bytes32, bytes32, address, bytes16, uint16) ); string memory questIdString_ = bytes16ToUUID(questid_); Quest storage quest_ = quests[questIdString_]; string memory jsonData_ = buildJsonString(uint256(txHash_).toHexString(), uint256(txHashChainId_).toString(), quest_.actionType, quest_.questName); bytes memory claimData_ = abi.encode(msg.sender, ref_, questIdString_, jsonData_); this.claimOptimized{value: msg.value}(abi.encodePacked(r_,vs_), claimData_); } /// @notice External use is depricated /// @dev Claim rewards for a quest /// @param data_ The claim data in abi encoded bytes /// @param signature_ The signature of the claim data function claimOptimized(bytes calldata signature_, bytes calldata data_) external payable { ( address claimer_, address ref_, string memory questId_, string memory jsonData_ ) = abi.decode( data_, (address, address, string, string) ); Quest storage quest = quests[questId_]; uint256 numberMintedPlusOne_ = quest.numberMinted + 1; address rewardToken_ = IQuestOwnable(quest.questAddress).rewardToken(); uint256 rewardAmountOrTokenId; if (recoverSigner(keccak256(data_), signature_) != claimSignerAddress) revert AddressNotSigned(); if (msg.value < mintFee) revert InvalidMintFee(); if (quest.addressMinted[claimer_]) revert AddressAlreadyMinted(); if (numberMintedPlusOne_ > quest.totalParticipants) revert OverMaxAllowedToMint(); quest.addressMinted[claimer_] = true; quest.numberMinted = numberMintedPlusOne_; (bool success_, ) = quest.questAddress.call{value: msg.value}(abi.encodeWithSignature("claimFromFactory(address,address)", claimer_, ref_)); if (!success_) revert ClaimFailed(); emit QuestClaimedData(claimer_, quest.questAddress, jsonData_); if (quest.questType.eq("erc1155")) { rewardAmountOrTokenId = IQuest1155Ownable(quest.questAddress).tokenId(); emit Quest1155Claimed(claimer_, quest.questAddress, questId_, rewardToken_, rewardAmountOrTokenId); } else { rewardAmountOrTokenId = IQuestOwnable(quest.questAddress).rewardAmountInWei(); emit QuestClaimed(claimer_, quest.questAddress, questId_, rewardToken_, rewardAmountOrTokenId); } if(ref_ != address(0)){ emit QuestClaimedReferred(claimer_, quest.questAddress, questId_, rewardToken_, rewardAmountOrTokenId, ref_, 3333, mintFee); emit MintFeePaid(questId_, address(0), 0, address(0), 0, ref_, mintFee / 3); } } /*////////////////////////////////////////////////////////////// SET //////////////////////////////////////////////////////////////*/ /// @dev set the claim signer address /// @param claimSignerAddress_ The address of the claim signer function setClaimSignerAddress(address claimSignerAddress_) external onlyOwner { claimSignerAddress = claimSignerAddress_; } /// @dev set erc1155QuestAddress /// @param erc1155QuestAddress_ The address of the erc1155 quest function setErc1155QuestAddress(address erc1155QuestAddress_) external onlyOwner { erc1155QuestAddress = erc1155QuestAddress_; } /// @dev set erc20QuestAddress /// @param erc20QuestAddress_ The address of the erc20 quest function setErc20QuestAddress(address erc20QuestAddress_) external onlyOwner { erc20QuestAddress = erc20QuestAddress_; } /// @dev set the mint fee /// @notice the mint fee in ether /// @param mintFee_ The mint fee value function setMintFee(uint256 mintFee_) external onlyOwner { mintFee = mintFee_; emit MintFeeSet(mintFee_); } /// @dev set the nftQuestFee /// @param nftQuestFee_ The value of the nftQuestFee function setNftQuestFee(uint256 nftQuestFee_) external onlyOwner { nftQuestFee = nftQuestFee_; emit NftQuestFeeSet(nftQuestFee_); } /// @dev set the protocol fee recipient /// @param protocolFeeRecipient_ The address of the protocol fee recipient function setProtocolFeeRecipient(address protocolFeeRecipient_) external onlyOwner { if (protocolFeeRecipient_ == address(0)) revert AddressZeroNotAllowed(); protocolFeeRecipient = protocolFeeRecipient_; } /// @dev set the quest fee /// @notice the quest fee should be in Basis Point units /// @param questFee_ The quest fee value function setQuestFee(uint16 questFee_) external onlyOwner { if (questFee_ > 10_000) revert QuestFeeTooHigh(); questFee = questFee_; } /// @dev set the referral fee /// @param referralFee_ The value of the referralFee function setReferralFee(uint16 referralFee_) external onlyOwner { if (referralFee_ > 10_000) revert ReferralFeeTooHigh(); referralFee = referralFee_; emit ReferralFeeSet(referralFee_); } /// @dev set sablierV2LockupLinearAddress /// @param sablierV2LockupLinearAddress_ The address of the sablierV2LockupLinear contract function setSablierV2LockupLinearAddress(address sablierV2LockupLinearAddress_) external onlyOwner { sablierV2LockupLinearAddress = sablierV2LockupLinearAddress_; emit SablierV2LockupLinearAddressSet(sablierV2LockupLinearAddress_); } /// @dev set or remave a contract address to be used as a reward /// @param rewardAddress_ The contract address to set /// @param allowed_ Whether the contract address is allowed or not function setRewardAllowlistAddress(address rewardAddress_, bool allowed_) external onlyOwner { rewardAllowlist[rewardAddress_] = allowed_; } /// @dev set the mintFeeRecipient /// @param mintFeeRecipient_ The address of the mint fee recipient function setDefaultMintFeeRecipient(address mintFeeRecipient_) external onlyOwner { if (mintFeeRecipient_ == address(0)) revert AddressZeroNotAllowed(); defaultMintFeeRecipient = mintFeeRecipient_; } /// @dev set a mintFeeRecipient for a specific address /// @param address_ The address of the account /// @param mintFeeRecipient_ The address of the mint fee recipient function setMintFeeRecipientForAddress(address address_, address mintFeeRecipient_) external onlyOwner { mintFeeRecipientList[address_] = mintFeeRecipient_; } /// @dev set the nft quest fee for a list of addresses /// @param toAddAddresses_ The list of addresses to set the nft quest fee for /// @param fees_ The list of fees to set function setNftQuestFeeList(address[] calldata toAddAddresses_, uint256[] calldata fees_) external onlyOwner { for (uint256 i = 0; i < toAddAddresses_.length; i++) { nftQuestFeeList[toAddAddresses_[i]] = NftQuestFees(fees_[i], true); } emit NftQuestFeeListSet(toAddAddresses_, fees_); } /// @dev set the default referral fee recipient /// @param defaultReferralFeeRecipient_ The address of the default referral fee recipient function setDefaultReferralFeeRecipient(address defaultReferralFeeRecipient_) external onlyOwner { defaultReferralFeeRecipient = defaultReferralFeeRecipient_; } /*////////////////////////////////////////////////////////////// EXTERNAL VIEW //////////////////////////////////////////////////////////////*/ /// @notice This function name is a bit of a misnomer - gets whether an address has claimed a quest yet. /// @dev return status of whether an address has claimed a quest /// @param questId_ The id of the quest /// @param address_ The address to check /// @return claimed status function getAddressMinted(string memory questId_, address address_) external view returns (bool) { return quests[questId_].addressMinted[address_]; } /// @dev get the mintFeeRecipient return the protocol fee recipient if the mint fee recipient is not set /// @param questCreatorAddress_ The address of the quest creator, to get the mintFee /// @return address the mint fee recipient function getMintFeeRecipient(address questCreatorAddress_) public view returns (address) { address _mintFeeRecipient = mintFeeRecipientList[questCreatorAddress_]; return _mintFeeRecipient == address(0) ? defaultMintFeeRecipient : _mintFeeRecipient; } function getNftQuestFee(address address_) public view returns (uint256) { return nftQuestFeeList[address_].exists ? nftQuestFeeList[address_].fee : nftQuestFee; } /// @dev return the number of quest claims /// @param questId_ The id of the quest /// @return uint Total quests claimed function getNumberMinted(string memory questId_) external view returns (uint256) { return quests[questId_].numberMinted; } /// @dev return extended quest data for a questId /// @param questId_ The id of the quest function questData(string memory questId_) external view returns (QuestData memory) { Quest storage thisQuest = quests[questId_]; IQuestOwnable questContract = IQuestOwnable(thisQuest.questAddress); uint256 rewardAmountOrTokenId; uint16 erc20QuestFee; if (thisQuest.questType.eq("erc1155")) { rewardAmountOrTokenId = IQuest1155Ownable(thisQuest.questAddress).tokenId(); } else { rewardAmountOrTokenId = questContract.rewardAmountInWei(); erc20QuestFee = questContract.questFee(); } QuestData memory data = QuestData( thisQuest.questAddress, questContract.rewardToken(), questContract.queued(), erc20QuestFee, questContract.startTime(), questContract.endTime(), questContract.totalParticipants(), thisQuest.numberMinted, thisQuest.numberMinted, rewardAmountOrTokenId, questContract.hasWithdrawn() ); return data; } /// @dev return data in the quest struct for a questId /// @param questId_ The id of the quest function questInfo(string memory questId_) external view returns (address, uint256, uint256) { Quest storage currentQuest = quests[questId_]; return (currentQuest.questAddress, currentQuest.totalParticipants, currentQuest.numberMinted); } /// @dev recover the signer from a hash and signature /// @param hash_ The hash of the message /// @param signature_ The signature of the hash function recoverSigner(bytes32 hash_, bytes memory signature_) public view returns (address) { return ECDSA.recover(ECDSA.toEthSignedMessageHash(hash_), signature_); } function totalQuestNFTFee(uint256 totalParticipants_) public view returns (uint256) { return totalParticipants_ * getNftQuestFee(msg.sender); } function withdrawCallback(string calldata questId_, address protocolFeeRecipient_, uint protocolPayout_, address mintFeeRecipient_, uint mintPayout) external { Quest storage quest = quests[questId_]; if(msg.sender != quest.questAddress) revert QuestAddressMismatch(); emit MintFeePaid(questId_, protocolFeeRecipient_, protocolPayout_, mintFeeRecipient_, mintPayout, address(0), 0); } /*////////////////////////////////////////////////////////////// INTERNAL UPDATE //////////////////////////////////////////////////////////////*/ /// @dev claim rewards for a quest with a referral address /// @param claimData_ The claim data struct function claim1155RewardsRef(ClaimData memory claimData_) private nonReentrant sufficientMintFee claimChecks(claimData_) { Quest storage currentQuest = quests[claimData_.questId]; IQuest1155Ownable questContract_ = IQuest1155Ownable(currentQuest.questAddress); if (!questContract_.queued()) revert QuestNotQueued(); if (block.timestamp < questContract_.startTime()) revert QuestNotStarted(); if (block.timestamp > questContract_.endTime()) revert QuestEnded(); currentQuest.addressMinted[claimData_.claimer] = true; ++currentQuest.numberMinted; questContract_.singleClaim(claimData_.claimer); if (mintFee > 0) { string memory newJson = processMintFee(claimData_.ref, currentQuest.questCreator, claimData_.questId); if (bytes(claimData_.extraData).length > 0){ claimData_.extraData = claimData_.extraData.slice(0, bytes(claimData_.extraData).length -1).concat(newJson); } } emit QuestClaimedData( claimData_.claimer, currentQuest.questAddress, claimData_.extraData ); emit Quest1155Claimed( claimData_.claimer, currentQuest.questAddress, claimData_.questId, questContract_.rewardToken(), questContract_.tokenId() ); if (claimData_.ref != address(0)) { emit QuestClaimedReferred( claimData_.claimer, currentQuest.questAddress, claimData_.questId, questContract_.rewardToken(), questContract_.tokenId(), claimData_.ref, 3333, //referralFee, mintFee ); } } /// @dev claim rewards with a referral address /// @param claimData_ The claim data struct function claimRewardsRef(ClaimData memory claimData_) private nonReentrant sufficientMintFee claimChecks(claimData_) { Quest storage currentQuest = quests[claimData_.questId]; IQuestOwnable questContract_ = IQuestOwnable(currentQuest.questAddress); if (!questContract_.queued()) revert QuestNotQueued(); if (block.timestamp < questContract_.startTime()) revert QuestNotStarted(); if (block.timestamp > questContract_.endTime()) revert QuestEnded(); currentQuest.addressMinted[claimData_.claimer] = true; ++currentQuest.numberMinted; questContract_.singleClaim(claimData_.claimer); if (mintFee > 0) { string memory newJson = processMintFee(claimData_.ref, currentQuest.questCreator, claimData_.questId); if (bytes(claimData_.extraData).length > 0){ claimData_.extraData = claimData_.extraData.slice(0, bytes(claimData_.extraData).length -1).concat(newJson); } } emit QuestClaimedData( claimData_.claimer, currentQuest.questAddress, claimData_.extraData ); emit QuestClaimed( claimData_.claimer, currentQuest.questAddress, claimData_.questId, questContract_.rewardToken(), questContract_.rewardAmountInWei() ); if (claimData_.ref != address(0)) { emit QuestClaimedReferred( claimData_.claimer, currentQuest.questAddress, claimData_.questId, questContract_.rewardToken(), questContract_.rewardAmountInWei(), claimData_.ref, 3333, //referralFee, mintFee ); } } /// @dev Internal function to create an erc1155 quest /// @param data_ The erc20 quest data struct function createERC1155QuestInternal(ERC1155QuestData memory data_) internal returns (address) { Quest storage currentQuest = quests[data_.questId]; if (msg.value < totalQuestNFTFee(data_.totalParticipants)) revert MsgValueLessThanQuestNFTFee(); if (currentQuest.questAddress != address(0)) revert QuestIdUsed(); address payable newQuest = payable(erc1155QuestAddress.cloneDeterministic(keccak256(abi.encodePacked(msg.sender, block.chainid, block.timestamp)))); currentQuest.questAddress = address(newQuest); currentQuest.totalParticipants = data_.totalParticipants; currentQuest.questAddress.safeTransferETH(msg.value); currentQuest.questType = "erc1155"; currentQuest.questCreator = msg.sender; currentQuest.actionType = data_.actionType; currentQuest.questName = data_.questName; IQuest1155Ownable questContract = IQuest1155Ownable(newQuest); questContract.initialize( data_.rewardTokenAddress, data_.endTime, data_.startTime, data_.totalParticipants, data_.tokenId, protocolFeeRecipient, data_.questId ); IERC1155(data_.rewardTokenAddress).safeTransferFrom(msg.sender, newQuest, data_.tokenId, data_.totalParticipants, "0x00"); questContract.queue(); questContract.transferOwnership(msg.sender); emit QuestCreated( msg.sender, address(newQuest), data_.questId, "erc1155", data_.rewardTokenAddress, data_.endTime, data_.startTime, data_.totalParticipants, data_.tokenId ); return newQuest; } /// @dev Internal function to create an erc20 quest /// @param data_ The erc20 quest data struct function createERC20QuestInternal(ERC20QuestData memory data_) internal returns (address) { Quest storage currentQuest = quests[data_.questId]; address newQuest = erc20QuestAddress.cloneDeterministic(keccak256(abi.encodePacked(msg.sender, block.chainid, block.timestamp))); currentQuest.questAddress = address(newQuest); currentQuest.totalParticipants = data_.totalParticipants; currentQuest.questCreator = msg.sender; currentQuest.durationTotal = data_.durationTotal; currentQuest.questType = data_.questType; currentQuest.actionType = data_.actionType; currentQuest.questName = data_.questName; emit QuestCreated( msg.sender, address(newQuest), data_.questId, currentQuest.questType, data_.rewardTokenAddress, data_.endTime, data_.startTime, data_.totalParticipants, data_.rewardAmount ); IQuestOwnable(newQuest).initialize( data_.rewardTokenAddress, data_.endTime, data_.startTime, data_.totalParticipants, data_.rewardAmount, data_.questId, questFee, protocolFeeRecipient, data_.durationTotal, sablierV2LockupLinearAddress ); transferTokensAndOwnership(newQuest, data_.rewardTokenAddress); return newQuest; } function processMintFee(address ref_, address mintFeeRecipient_, string memory questId_) private returns (string memory) { returnChange(); uint256 cachedMintFee = mintFee; uint256 oneThirdMintfee = cachedMintFee / 3; uint256 protocolPayout; uint256 mintPayout; uint256 referrerPayout; if(ref_ == address(0)){ protocolPayout = oneThirdMintfee * 2; mintPayout = oneThirdMintfee; } else { protocolPayout = oneThirdMintfee; mintPayout = oneThirdMintfee; referrerPayout = oneThirdMintfee; } protocolFeeRecipient.safeTransferETH(protocolPayout); mintFeeRecipient_.safeTransferETH(mintPayout); if(referrerPayout != 0) ref_.safeTransferETH(referrerPayout); emit MintFeePaid(questId_, protocolFeeRecipient, protocolPayout, mintFeeRecipient_, mintPayout, ref_, referrerPayout); return string(abi.encodePacked( ', "claimFee": "', cachedMintFee.toString(), '", "claimFeePayouts": [{"name": "protocolPayout", "address": "', protocolFeeRecipient.toHexString(), '", "value": "', protocolPayout.toString(), '"}, {"name": "mintPayout", "address": "', mintFeeRecipient_.toHexString(), '", "value": "', mintPayout.toString(), '"}, {"name": "referrerPayout", "address": "', ref_.toHexString(), '", "value": "', referrerPayout.toString(), '"}]}' )); } // Refund any excess payment function returnChange() private { uint256 change = msg.value - mintFee; if (change > 0) { msg.sender.safeTransferETH(change); } } /// @dev Transfer the total transfer amount to the quest contract /// @dev Contract must be approved to transfer first /// @param newQuest_ The address of the new quest /// @param rewardTokenAddress_ The contract address of the reward token function transferTokensAndOwnership(address newQuest_, address rewardTokenAddress_) internal { address sender = msg.sender; IQuestOwnable questContract = IQuestOwnable(newQuest_); rewardTokenAddress_.safeTransferFrom(sender, newQuest_, questContract.totalTransferAmount()); questContract.transferOwnership(sender); } function buildJsonString( string memory txHash, string memory txHashChainId, string memory actionType, string memory questName ) internal pure returns (string memory) { // { // actionTxHashes: ["actionTxHash1"], // actionNetworkChainIds: ["chainId1"], // questName: "quest name", // actionType: "mint" // } return string(abi.encodePacked( '{"actionTxHashes":["', txHash, '"],"actionNetworkChainIds":[', txHashChainId, '],"questName":"', questName, '","actionType":"', actionType, '"}' )); } /// @dev Convert bytes16 to a UUID string e.g. 550e8400-e29b-41d4-a716-446655440000 /// @param data The bytes16 data e.g. 0x550e8400e29b41d4a716446655440000 function bytes16ToUUID(bytes16 data) internal pure returns (string memory) { bytes memory hexChars = "0123456789abcdef"; bytes memory uuid = new bytes(36); // UUID length with hyphens uint256 j = 0; // Position in uuid for (uint256 i = 0; i < 16; i++) { // Insert hyphens at the appropriate positions (after 4, 6, 8, 10 bytes) if (i == 4 || i == 6 || i == 8 || i == 10) { uuid[j++] = '-'; } uuid[j++] = hexChars[uint8(data[i] >> 4)]; uuid[j++] = hexChars[uint8(data[i] & 0x0F)]; } return string(uuid); } /*////////////////////////////////////////////////////////////// DEFAULTS //////////////////////////////////////////////////////////////*/ // Receive function to receive ETH receive() external payable {} // Fallback function to receive ETH when other functions are not available fallback() external payable {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.19; abstract contract LegacyStorage { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } uint256[50] private __gap; address private _owner; uint256[49] private __gap1; uint256[50] private __gap2; mapping(bytes32 => RoleData) private _roles; uint256[49] private __gap3; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {Ownable} from "./Ownable.sol"; /// @notice Simple single owner and multiroles authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// @dev While the ownable portion follows [EIP-173](https://eips.ethereum.org/EIPS/eip-173) /// for compatibility, the nomenclature for the 2-step ownership handover and roles /// may be unique to this codebase. abstract contract OwnableRoles is Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The `user`'s roles is updated to `roles`. /// Each bit of `roles` represents whether the role is set. event RolesUpdated(address indexed user, uint256 indexed roles); /// @dev `keccak256(bytes("RolesUpdated(address,uint256)"))`. uint256 private constant _ROLES_UPDATED_EVENT_SIGNATURE = 0x715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe26; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The role slot of `user` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _ROLE_SLOT_SEED)) /// let roleSlot := keccak256(0x00, 0x20) /// ``` /// This automatically ignores the upper bits of the `user` in case /// they are not clean, as well as keep the `keccak256` under 32-bytes. /// /// Note: This is equivalent to `uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))`. uint256 private constant _ROLE_SLOT_SEED = 0x8b78c6d8; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Overwrite the roles directly without authorization guard. function _setRoles(address user, uint256 roles) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) // Store the new value. sstore(keccak256(0x0c, 0x20), roles) // Emit the {RolesUpdated} event. log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), roles) } } /// @dev Updates the roles directly without authorization guard. /// If `on` is true, each set bit of `roles` will be turned on, /// otherwise, each set bit of `roles` will be turned off. function _updateRoles(address user, uint256 roles, bool on) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) let roleSlot := keccak256(0x0c, 0x20) // Load the current value. let current := sload(roleSlot) // Compute the updated roles if `on` is true. let updated := or(current, roles) // Compute the updated roles if `on` is false. // Use `and` to compute the intersection of `current` and `roles`, // `xor` it with `current` to flip the bits in the intersection. if iszero(on) { updated := xor(current, and(current, roles)) } // Then, store the new value. sstore(roleSlot, updated) // Emit the {RolesUpdated} event. log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), updated) } } /// @dev Grants the roles directly without authorization guard. /// Each bit of `roles` represents the role to turn on. function _grantRoles(address user, uint256 roles) internal virtual { _updateRoles(user, roles, true); } /// @dev Removes the roles directly without authorization guard. /// Each bit of `roles` represents the role to turn off. function _removeRoles(address user, uint256 roles) internal virtual { _updateRoles(user, roles, false); } /// @dev Throws if the sender does not have any of the `roles`. function _checkRoles(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Throws if the sender is not the owner, /// and does not have any of the `roles`. /// Checks for ownership first, then lazily checks for roles. function _checkOwnerOrRoles(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner. // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`. if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } } /// @dev Throws if the sender does not have any of the `roles`, /// and is not the owner. /// Checks for roles first, then lazily checks for ownership. function _checkRolesOrOwner(uint256 roles) internal view virtual { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, caller()) // Load the stored value, and if the `and` intersection // of the value and `roles` is zero, revert. if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) { // If the caller is not the stored owner. // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`. if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } } /// @dev Convenience function to return a `roles` bitmap from an array of `ordinals`. /// This is meant for frontends like Etherscan, and is therefore not fully optimized. /// Not recommended to be called on-chain. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _rolesFromOrdinals(uint8[] memory ordinals) internal pure returns (uint256 roles) { /// @solidity memory-safe-assembly assembly { for { let i := shl(5, mload(ordinals)) } i { i := sub(i, 0x20) } { // We don't need to mask the values of `ordinals`, as Solidity // cleans dirty upper bits when storing variables into memory. roles := or(shl(mload(add(ordinals, i)), 1), roles) } } } /// @dev Convenience function to return an array of `ordinals` from the `roles` bitmap. /// This is meant for frontends like Etherscan, and is therefore not fully optimized. /// Not recommended to be called on-chain. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ordinalsFromRoles(uint256 roles) internal pure returns (uint8[] memory ordinals) { /// @solidity memory-safe-assembly assembly { // Grab the pointer to the free memory. ordinals := mload(0x40) let ptr := add(ordinals, 0x20) let o := 0 // The absence of lookup tables, De Bruijn, etc., here is intentional for // smaller bytecode, as this function is not meant to be called on-chain. for { let t := roles } 1 {} { mstore(ptr, o) // `shr` 5 is equivalent to multiplying by 0x20. // Push back into the ordinals array if the bit is set. ptr := add(ptr, shl(5, and(t, 1))) o := add(o, 1) t := shr(o, roles) if iszero(t) { break } } // Store the length of `ordinals`. mstore(ordinals, shr(5, sub(ptr, add(ordinals, 0x20)))) // Allocate the memory. mstore(0x40, ptr) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to grant `user` `roles`. /// If the `user` already has a role, then it will be an no-op for the role. function grantRoles(address user, uint256 roles) public payable virtual onlyOwner { _grantRoles(user, roles); } /// @dev Allows the owner to remove `user` `roles`. /// If the `user` does not have a role, then it will be an no-op for the role. function revokeRoles(address user, uint256 roles) public payable virtual onlyOwner { _removeRoles(user, roles); } /// @dev Allow the caller to remove their own roles. /// If the caller does not have a role, then it will be an no-op for the role. function renounceRoles(uint256 roles) public payable virtual { _removeRoles(msg.sender, roles); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the roles of `user`. function rolesOf(address user) public view virtual returns (uint256 roles) { /// @solidity memory-safe-assembly assembly { // Compute the role slot. mstore(0x0c, _ROLE_SLOT_SEED) mstore(0x00, user) // Load the stored value. roles := sload(keccak256(0x0c, 0x20)) } } /// @dev Returns whether `user` has any of `roles`. function hasAnyRole(address user, uint256 roles) public view virtual returns (bool) { return rolesOf(user) & roles != 0; } /// @dev Returns whether `user` has all of `roles`. function hasAllRoles(address user, uint256 roles) public view virtual returns (bool) { return rolesOf(user) & roles == roles; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by an account with `roles`. modifier onlyRoles(uint256 roles) virtual { _checkRoles(roles); _; } /// @dev Marks a function as only callable by the owner or by an account /// with `roles`. Checks for ownership first, then lazily checks for roles. modifier onlyOwnerOrRoles(uint256 roles) virtual { _checkOwnerOrRoles(roles); _; } /// @dev Marks a function as only callable by an account with `roles` /// or the owner. Checks for roles first, then lazily checks for ownership. modifier onlyRolesOrOwner(uint256 roles) virtual { _checkRolesOrOwner(roles); _; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ROLE CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // IYKYK uint256 internal constant _ROLE_0 = 1 << 0; uint256 internal constant _ROLE_1 = 1 << 1; uint256 internal constant _ROLE_2 = 1 << 2; uint256 internal constant _ROLE_3 = 1 << 3; uint256 internal constant _ROLE_4 = 1 << 4; uint256 internal constant _ROLE_5 = 1 << 5; uint256 internal constant _ROLE_6 = 1 << 6; uint256 internal constant _ROLE_7 = 1 << 7; uint256 internal constant _ROLE_8 = 1 << 8; uint256 internal constant _ROLE_9 = 1 << 9; uint256 internal constant _ROLE_10 = 1 << 10; uint256 internal constant _ROLE_11 = 1 << 11; uint256 internal constant _ROLE_12 = 1 << 12; uint256 internal constant _ROLE_13 = 1 << 13; uint256 internal constant _ROLE_14 = 1 << 14; uint256 internal constant _ROLE_15 = 1 << 15; uint256 internal constant _ROLE_16 = 1 << 16; uint256 internal constant _ROLE_17 = 1 << 17; uint256 internal constant _ROLE_18 = 1 << 18; uint256 internal constant _ROLE_19 = 1 << 19; uint256 internal constant _ROLE_20 = 1 << 20; uint256 internal constant _ROLE_21 = 1 << 21; uint256 internal constant _ROLE_22 = 1 << 22; uint256 internal constant _ROLE_23 = 1 << 23; uint256 internal constant _ROLE_24 = 1 << 24; uint256 internal constant _ROLE_25 = 1 << 25; uint256 internal constant _ROLE_26 = 1 << 26; uint256 internal constant _ROLE_27 = 1 << 27; uint256 internal constant _ROLE_28 = 1 << 28; uint256 internal constant _ROLE_29 = 1 << 29; uint256 internal constant _ROLE_30 = 1 << 30; uint256 internal constant _ROLE_31 = 1 << 31; uint256 internal constant _ROLE_32 = 1 << 32; uint256 internal constant _ROLE_33 = 1 << 33; uint256 internal constant _ROLE_34 = 1 << 34; uint256 internal constant _ROLE_35 = 1 << 35; uint256 internal constant _ROLE_36 = 1 << 36; uint256 internal constant _ROLE_37 = 1 << 37; uint256 internal constant _ROLE_38 = 1 << 38; uint256 internal constant _ROLE_39 = 1 << 39; uint256 internal constant _ROLE_40 = 1 << 40; uint256 internal constant _ROLE_41 = 1 << 41; uint256 internal constant _ROLE_42 = 1 << 42; uint256 internal constant _ROLE_43 = 1 << 43; uint256 internal constant _ROLE_44 = 1 << 44; uint256 internal constant _ROLE_45 = 1 << 45; uint256 internal constant _ROLE_46 = 1 << 46; uint256 internal constant _ROLE_47 = 1 << 47; uint256 internal constant _ROLE_48 = 1 << 48; uint256 internal constant _ROLE_49 = 1 << 49; uint256 internal constant _ROLE_50 = 1 << 50; uint256 internal constant _ROLE_51 = 1 << 51; uint256 internal constant _ROLE_52 = 1 << 52; uint256 internal constant _ROLE_53 = 1 << 53; uint256 internal constant _ROLE_54 = 1 << 54; uint256 internal constant _ROLE_55 = 1 << 55; uint256 internal constant _ROLE_56 = 1 << 56; uint256 internal constant _ROLE_57 = 1 << 57; uint256 internal constant _ROLE_58 = 1 << 58; uint256 internal constant _ROLE_59 = 1 << 59; uint256 internal constant _ROLE_60 = 1 << 60; uint256 internal constant _ROLE_61 = 1 << 61; uint256 internal constant _ROLE_62 = 1 << 62; uint256 internal constant _ROLE_63 = 1 << 63; uint256 internal constant _ROLE_64 = 1 << 64; uint256 internal constant _ROLE_65 = 1 << 65; uint256 internal constant _ROLE_66 = 1 << 66; uint256 internal constant _ROLE_67 = 1 << 67; uint256 internal constant _ROLE_68 = 1 << 68; uint256 internal constant _ROLE_69 = 1 << 69; uint256 internal constant _ROLE_70 = 1 << 70; uint256 internal constant _ROLE_71 = 1 << 71; uint256 internal constant _ROLE_72 = 1 << 72; uint256 internal constant _ROLE_73 = 1 << 73; uint256 internal constant _ROLE_74 = 1 << 74; uint256 internal constant _ROLE_75 = 1 << 75; uint256 internal constant _ROLE_76 = 1 << 76; uint256 internal constant _ROLE_77 = 1 << 77; uint256 internal constant _ROLE_78 = 1 << 78; uint256 internal constant _ROLE_79 = 1 << 79; uint256 internal constant _ROLE_80 = 1 << 80; uint256 internal constant _ROLE_81 = 1 << 81; uint256 internal constant _ROLE_82 = 1 << 82; uint256 internal constant _ROLE_83 = 1 << 83; uint256 internal constant _ROLE_84 = 1 << 84; uint256 internal constant _ROLE_85 = 1 << 85; uint256 internal constant _ROLE_86 = 1 << 86; uint256 internal constant _ROLE_87 = 1 << 87; uint256 internal constant _ROLE_88 = 1 << 88; uint256 internal constant _ROLE_89 = 1 << 89; uint256 internal constant _ROLE_90 = 1 << 90; uint256 internal constant _ROLE_91 = 1 << 91; uint256 internal constant _ROLE_92 = 1 << 92; uint256 internal constant _ROLE_93 = 1 << 93; uint256 internal constant _ROLE_94 = 1 << 94; uint256 internal constant _ROLE_95 = 1 << 95; uint256 internal constant _ROLE_96 = 1 << 96; uint256 internal constant _ROLE_97 = 1 << 97; uint256 internal constant _ROLE_98 = 1 << 98; uint256 internal constant _ROLE_99 = 1 << 99; uint256 internal constant _ROLE_100 = 1 << 100; uint256 internal constant _ROLE_101 = 1 << 101; uint256 internal constant _ROLE_102 = 1 << 102; uint256 internal constant _ROLE_103 = 1 << 103; uint256 internal constant _ROLE_104 = 1 << 104; uint256 internal constant _ROLE_105 = 1 << 105; uint256 internal constant _ROLE_106 = 1 << 106; uint256 internal constant _ROLE_107 = 1 << 107; uint256 internal constant _ROLE_108 = 1 << 108; uint256 internal constant _ROLE_109 = 1 << 109; uint256 internal constant _ROLE_110 = 1 << 110; uint256 internal constant _ROLE_111 = 1 << 111; uint256 internal constant _ROLE_112 = 1 << 112; uint256 internal constant _ROLE_113 = 1 << 113; uint256 internal constant _ROLE_114 = 1 << 114; uint256 internal constant _ROLE_115 = 1 << 115; uint256 internal constant _ROLE_116 = 1 << 116; uint256 internal constant _ROLE_117 = 1 << 117; uint256 internal constant _ROLE_118 = 1 << 118; uint256 internal constant _ROLE_119 = 1 << 119; uint256 internal constant _ROLE_120 = 1 << 120; uint256 internal constant _ROLE_121 = 1 << 121; uint256 internal constant _ROLE_122 = 1 << 122; uint256 internal constant _ROLE_123 = 1 << 123; uint256 internal constant _ROLE_124 = 1 << 124; uint256 internal constant _ROLE_125 = 1 << 125; uint256 internal constant _ROLE_126 = 1 << 126; uint256 internal constant _ROLE_127 = 1 << 127; uint256 internal constant _ROLE_128 = 1 << 128; uint256 internal constant _ROLE_129 = 1 << 129; uint256 internal constant _ROLE_130 = 1 << 130; uint256 internal constant _ROLE_131 = 1 << 131; uint256 internal constant _ROLE_132 = 1 << 132; uint256 internal constant _ROLE_133 = 1 << 133; uint256 internal constant _ROLE_134 = 1 << 134; uint256 internal constant _ROLE_135 = 1 << 135; uint256 internal constant _ROLE_136 = 1 << 136; uint256 internal constant _ROLE_137 = 1 << 137; uint256 internal constant _ROLE_138 = 1 << 138; uint256 internal constant _ROLE_139 = 1 << 139; uint256 internal constant _ROLE_140 = 1 << 140; uint256 internal constant _ROLE_141 = 1 << 141; uint256 internal constant _ROLE_142 = 1 << 142; uint256 internal constant _ROLE_143 = 1 << 143; uint256 internal constant _ROLE_144 = 1 << 144; uint256 internal constant _ROLE_145 = 1 << 145; uint256 internal constant _ROLE_146 = 1 << 146; uint256 internal constant _ROLE_147 = 1 << 147; uint256 internal constant _ROLE_148 = 1 << 148; uint256 internal constant _ROLE_149 = 1 << 149; uint256 internal constant _ROLE_150 = 1 << 150; uint256 internal constant _ROLE_151 = 1 << 151; uint256 internal constant _ROLE_152 = 1 << 152; uint256 internal constant _ROLE_153 = 1 << 153; uint256 internal constant _ROLE_154 = 1 << 154; uint256 internal constant _ROLE_155 = 1 << 155; uint256 internal constant _ROLE_156 = 1 << 156; uint256 internal constant _ROLE_157 = 1 << 157; uint256 internal constant _ROLE_158 = 1 << 158; uint256 internal constant _ROLE_159 = 1 << 159; uint256 internal constant _ROLE_160 = 1 << 160; uint256 internal constant _ROLE_161 = 1 << 161; uint256 internal constant _ROLE_162 = 1 << 162; uint256 internal constant _ROLE_163 = 1 << 163; uint256 internal constant _ROLE_164 = 1 << 164; uint256 internal constant _ROLE_165 = 1 << 165; uint256 internal constant _ROLE_166 = 1 << 166; uint256 internal constant _ROLE_167 = 1 << 167; uint256 internal constant _ROLE_168 = 1 << 168; uint256 internal constant _ROLE_169 = 1 << 169; uint256 internal constant _ROLE_170 = 1 << 170; uint256 internal constant _ROLE_171 = 1 << 171; uint256 internal constant _ROLE_172 = 1 << 172; uint256 internal constant _ROLE_173 = 1 << 173; uint256 internal constant _ROLE_174 = 1 << 174; uint256 internal constant _ROLE_175 = 1 << 175; uint256 internal constant _ROLE_176 = 1 << 176; uint256 internal constant _ROLE_177 = 1 << 177; uint256 internal constant _ROLE_178 = 1 << 178; uint256 internal constant _ROLE_179 = 1 << 179; uint256 internal constant _ROLE_180 = 1 << 180; uint256 internal constant _ROLE_181 = 1 << 181; uint256 internal constant _ROLE_182 = 1 << 182; uint256 internal constant _ROLE_183 = 1 << 183; uint256 internal constant _ROLE_184 = 1 << 184; uint256 internal constant _ROLE_185 = 1 << 185; uint256 internal constant _ROLE_186 = 1 << 186; uint256 internal constant _ROLE_187 = 1 << 187; uint256 internal constant _ROLE_188 = 1 << 188; uint256 internal constant _ROLE_189 = 1 << 189; uint256 internal constant _ROLE_190 = 1 << 190; uint256 internal constant _ROLE_191 = 1 << 191; uint256 internal constant _ROLE_192 = 1 << 192; uint256 internal constant _ROLE_193 = 1 << 193; uint256 internal constant _ROLE_194 = 1 << 194; uint256 internal constant _ROLE_195 = 1 << 195; uint256 internal constant _ROLE_196 = 1 << 196; uint256 internal constant _ROLE_197 = 1 << 197; uint256 internal constant _ROLE_198 = 1 << 198; uint256 internal constant _ROLE_199 = 1 << 199; uint256 internal constant _ROLE_200 = 1 << 200; uint256 internal constant _ROLE_201 = 1 << 201; uint256 internal constant _ROLE_202 = 1 << 202; uint256 internal constant _ROLE_203 = 1 << 203; uint256 internal constant _ROLE_204 = 1 << 204; uint256 internal constant _ROLE_205 = 1 << 205; uint256 internal constant _ROLE_206 = 1 << 206; uint256 internal constant _ROLE_207 = 1 << 207; uint256 internal constant _ROLE_208 = 1 << 208; uint256 internal constant _ROLE_209 = 1 << 209; uint256 internal constant _ROLE_210 = 1 << 210; uint256 internal constant _ROLE_211 = 1 << 211; uint256 internal constant _ROLE_212 = 1 << 212; uint256 internal constant _ROLE_213 = 1 << 213; uint256 internal constant _ROLE_214 = 1 << 214; uint256 internal constant _ROLE_215 = 1 << 215; uint256 internal constant _ROLE_216 = 1 << 216; uint256 internal constant _ROLE_217 = 1 << 217; uint256 internal constant _ROLE_218 = 1 << 218; uint256 internal constant _ROLE_219 = 1 << 219; uint256 internal constant _ROLE_220 = 1 << 220; uint256 internal constant _ROLE_221 = 1 << 221; uint256 internal constant _ROLE_222 = 1 << 222; uint256 internal constant _ROLE_223 = 1 << 223; uint256 internal constant _ROLE_224 = 1 << 224; uint256 internal constant _ROLE_225 = 1 << 225; uint256 internal constant _ROLE_226 = 1 << 226; uint256 internal constant _ROLE_227 = 1 << 227; uint256 internal constant _ROLE_228 = 1 << 228; uint256 internal constant _ROLE_229 = 1 << 229; uint256 internal constant _ROLE_230 = 1 << 230; uint256 internal constant _ROLE_231 = 1 << 231; uint256 internal constant _ROLE_232 = 1 << 232; uint256 internal constant _ROLE_233 = 1 << 233; uint256 internal constant _ROLE_234 = 1 << 234; uint256 internal constant _ROLE_235 = 1 << 235; uint256 internal constant _ROLE_236 = 1 << 236; uint256 internal constant _ROLE_237 = 1 << 237; uint256 internal constant _ROLE_238 = 1 << 238; uint256 internal constant _ROLE_239 = 1 << 239; uint256 internal constant _ROLE_240 = 1 << 240; uint256 internal constant _ROLE_241 = 1 << 241; uint256 internal constant _ROLE_242 = 1 << 242; uint256 internal constant _ROLE_243 = 1 << 243; uint256 internal constant _ROLE_244 = 1 << 244; uint256 internal constant _ROLE_245 = 1 << 245; uint256 internal constant _ROLE_246 = 1 << 246; uint256 internal constant _ROLE_247 = 1 << 247; uint256 internal constant _ROLE_248 = 1 << 248; uint256 internal constant _ROLE_249 = 1 << 249; uint256 internal constant _ROLE_250 = 1 << 250; uint256 internal constant _ROLE_251 = 1 << 251; uint256 internal constant _ROLE_252 = 1 << 252; uint256 internal constant _ROLE_253 = 1 << 253; uint256 internal constant _ROLE_254 = 1 << 254; uint256 internal constant _ROLE_255 = 1 << 255; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; interface IQuestFactory { // Errors error AddressAlreadyMinted(); error AddressNotSigned(); error AddressZeroNotAllowed(); error AuthOwnerDiscountToken(); error Deprecated(); error Erc20QuestAddressNotSet(); error InvalidMintFee(); error MsgValueLessThanQuestNFTFee(); error OverMaxAllowedToMint(); error QuestFeeTooHigh(); error QuestIdUsed(); error QuestNotQueued(); error QuestNotStarted(); error QuestEnded(); error QuestTypeNotSupported(); error Reentrancy(); error ReferralFeeTooHigh(); error RewardNotAllowed(); error ZeroAddressNotAllowed(); error QuestAddressMismatch(); error ClaimFailed(); // Structs // This struct is used in a mapping - only add new fields to the end struct NftQuestFees { uint256 fee; bool exists; } // This struct is used in a mapping - only add new fields to the end struct Quest { mapping(address => bool) addressMinted; address questAddress; uint256 totalParticipants; uint256 numberMinted; string questType; uint40 durationTotal; address questCreator; address mintFeeRecipient; string actionType; string questName; } struct QuestData { address questAddress; address rewardToken; bool queued; uint16 questFee; uint256 startTime; uint256 endTime; uint256 totalParticipants; uint256 numberMinted; uint256 redeemedTokens; uint256 rewardAmountOrTokenId; bool hasWithdrawn; } struct ClaimData { string questId; bytes32 hashBytes; bytes signature; address ref; address claimer; string extraData; } struct ERC20QuestData { address rewardTokenAddress; uint256 endTime; uint256 startTime; uint256 totalParticipants; uint256 rewardAmount; string questId; string actionType; string questName; uint40 durationTotal; string questType; } struct ERC1155QuestData { address rewardTokenAddress; uint256 endTime; uint256 startTime; uint256 totalParticipants; uint256 tokenId; string questId; string actionType; string questName; } // Events event ExtraMintFeeReturned(address indexed recipient, uint256 amount); event MintFeeSet(uint256 mintFee); event NftQuestFeeListSet(address[] addresses, uint256[] fees); event NftQuestFeeSet(uint256 nftQuestFee); event QuestClaimedData( address indexed recipient, address indexed questAddress, string extraData ); event Quest1155Claimed( address indexed recipient, address indexed questAddress, string questId, address rewardToken, uint256 tokenId ); event QuestClaimed( address indexed recipient, address indexed questAddress, string questId, address rewardToken, uint256 rewardAmountInWei ); event QuestClaimedReferred( address indexed recipient, address indexed questAddress, string questId, address rewardToken, uint256 rewardAmountInWeiOrTokenId, address referrer, uint16 referralFee, uint256 mintFeeEthWei ); event MintFeePaid( string questId, address rabbitHoleAddress, uint256 rabbitHoleAmountWei, address questCreatorAddress, uint256 questCreatorAmountWei, address referrerAddress, uint256 referrerAmountWei ); event QuestCreated( address indexed creator, address indexed contractAddress, string questId, string questType, address rewardToken, uint256 endTime, uint256 startTime, uint256 totalParticipants, uint256 rewardAmountOrTokenId ); event ReferralFeeSet(uint16 percent); event SablierV2LockupLinearAddressSet(address sablierV2LockupLinearAddress); // Read Functions function getAddressMinted(string memory questId_, address address_) external view returns (bool); function getMintFeeRecipient(address address_) external view returns (address); function getNftQuestFee(address address_) external view returns (uint256); function getNumberMinted(string memory questId_) external view returns (uint256); function questData(string memory questId_) external view returns (QuestData memory); function questInfo(string memory questId_) external view returns (address, uint256, uint256); function recoverSigner(bytes32 hash_, bytes memory signature_) external view returns (address); function totalQuestNFTFee(uint256 totalParticipants_) external view returns (uint256); function mintFee() external view returns (uint256); // Create function create1155QuestAndQueue( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 tokenId_, string memory questId_, string memory ) external payable returns (address); // Set function setClaimSignerAddress(address claimSignerAddress_) external; function setErc1155QuestAddress(address erc1155QuestAddress_) external; function setErc20QuestAddress(address erc20QuestAddress_) external; function setMintFee(uint256 mintFee_) external; function setDefaultMintFeeRecipient(address mintFeeRecipient_) external; function setNftQuestFee(uint256 nftQuestFee_) external; function setNftQuestFeeList(address[] calldata toAddAddresses_, uint256[] calldata fees_) external; function setProtocolFeeRecipient(address protocolFeeRecipient_) external; function setQuestFee(uint16 questFee_) external; function setRewardAllowlistAddress(address rewardAddress_, bool allowed_) external; function setSablierV2LockupLinearAddress(address sablierV2LockupLinearAddress_) external; // Callbacks function withdrawCallback(string calldata questId_, address protocolFeeRecipient_, uint protocolPayout_, address mintFeeRecipient_, uint mintPayout) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Gas optimized ECDSA wrapper. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol) /// /// @dev Note: /// - The recovery functions use the ecrecover precompile (0x1). /// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure. /// This is for more safety by default. /// Use the `tryRecover` variants if you need to get the zero address back /// upon recovery failure instead. /// - As of Solady version 0.0.134, all `bytes signature` variants accept both /// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures. /// See: https://eips.ethereum.org/EIPS/eip-2098 /// This is for calldata efficiency on smart accounts prevalent on L2s. /// /// WARNING! Do NOT use signatures as unique identifiers: /// - Use a nonce in the digest to prevent replay attacks on the same contract. /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts. /// EIP-712 also enables readable signing of typed data for better user safety. /// This implementation does NOT check if a signature is non-malleable. library ECDSA { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The signature is invalid. error InvalidSignature(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RECOVERY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { result := 1 let m := mload(0x40) // Cache the free memory pointer. for {} 1 {} { mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. if eq(mload(signature), 64) { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. break } if eq(mload(signature), 65) { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. break } result := 0 break } result := mload( staticcall( gas(), // Amount of gas left for the transaction. result, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x01, // Start of output. 0x20 // Size of output. ) ) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { result := 1 let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) for {} 1 {} { if eq(signature.length, 64) { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. break } if eq(signature.length, 65) { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. break } result := 0 break } result := mload( staticcall( gas(), // Amount of gas left for the transaction. result, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x01, // Start of output. 0x20 // Size of output. ) ) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. result := mload( staticcall( gas(), // Amount of gas left for the transaction. 1, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x01, // Start of output. 0x20 // Size of output. ) ) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) result := mload( staticcall( gas(), // Amount of gas left for the transaction. 1, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x01, // Start of output. 0x20 // Size of output. ) ) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* TRY-RECOVER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // WARNING! // These functions will NOT revert upon recovery failure. // Instead, they will return the zero address upon recovery failure. // It is critical that the returned address is NEVER compared against // a zero address (e.g. an uninitialized address variable). /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { result := 1 let m := mload(0x40) // Cache the free memory pointer. for {} 1 {} { mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. if eq(mload(signature), 64) { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. break } if eq(mload(signature), 65) { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. break } result := 0 break } pop( staticcall( gas(), // Amount of gas left for the transaction. result, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x40, // Start of output. 0x20 // Size of output. ) ) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { result := 1 let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) for {} 1 {} { if eq(signature.length, 64) { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. break } if eq(signature.length, 65) { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. break } result := 0 break } pop( staticcall( gas(), // Amount of gas left for the transaction. result, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x40, // Start of output. 0x20 // Size of output. ) ) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. pop( staticcall( gas(), // Amount of gas left for the transaction. 1, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x40, // Start of output. 0x20 // Size of output. ) ) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) pop( staticcall( gas(), // Amount of gas left for the transaction. 1, // Address of `ecrecover`. 0x00, // Start of input. 0x80, // Size of input. 0x40, // Start of output. 0x20 // Size of output. ) ) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HASHING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an Ethereum Signed Message, created from a `hash`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign) /// JSON-RPC method as part of EIP-191. function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { mstore(0x20, hash) // Store into scratch space for keccak256. mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes. result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`. } } /// @dev Returns an Ethereum Signed Message, created from `s`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign) /// JSON-RPC method as part of EIP-191. /// Note: Supports lengths of `s` up to 999999 bytes. function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let sLength := mload(s) let o := 0x20 mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded. mstore(0x00, 0x00) // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`. for { let temp := sLength } 1 {} { o := sub(o, 1) mstore8(o, add(48, mod(temp, 10))) temp := div(temp, 10) if iszero(temp) { break } } let n := sub(0x3a, o) // Header length: `26 + 32 - o`. // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes. returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20)) mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header. result := keccak256(add(s, sub(0x20, n)), add(n, sLength)) mstore(s, sLength) // Restore the length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EMPTY CALLDATA HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an empty calldata bytes. function emptySignature() internal pure returns (bytes calldata signature) { /// @solidity memory-safe-assembly assembly { signature.length := 0 } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Minimal proxy library. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibClone.sol) /// @author Minimal proxy by 0age (https://github.com/0age) /// @author Clones with immutable args by wighawag, zefram.eth, Saw-mon & Natalie /// (https://github.com/Saw-mon-and-Natalie/clones-with-immutable-args) /// @author Minimal ERC1967 proxy by jtriley-eth (https://github.com/jtriley-eth/minimum-viable-proxy) /// /// @dev Minimal proxy: /// Although the sw0nt pattern saves 5 gas over the erc-1167 pattern during runtime, /// it is not supported out-of-the-box on Etherscan. Hence, we choose to use the 0age pattern, /// which saves 4 gas over the erc-1167 pattern during runtime, and has the smallest bytecode. /// /// @dev Minimal proxy (PUSH0 variant): /// This is a new minimal proxy that uses the PUSH0 opcode introduced during Shanghai. /// It is optimized first for minimal runtime gas, then for minimal bytecode. /// The PUSH0 clone functions are intentionally postfixed with a jarring "_PUSH0" as /// many EVM chains may not support the PUSH0 opcode in the early months after Shanghai. /// Please use with caution. /// /// @dev Clones with immutable args (CWIA): /// The implementation of CWIA here implements a `receive()` method that emits the /// `ReceiveETH(uint256)` event. This skips the `DELEGATECALL` when there is no calldata, /// enabling us to accept hard gas-capped `sends` & `transfers` for maximum backwards /// composability. The minimal proxy implementation does not offer this feature. /// /// @dev Minimal ERC1967 proxy: /// An minimal ERC1967 proxy, intended to be upgraded with UUPS. /// This is NOT the same as ERC1967Factory's transparent proxy, which includes admin logic. library LibClone { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Unable to deploy the clone. error DeploymentFailed(); /// @dev The salt must start with either the zero address or `by`. error SaltDoesNotStartWith(); /// @dev The ETH transfer has failed. error ETHTransferFailed(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MINIMAL PROXY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Deploys a clone of `implementation`. function clone(address implementation) internal returns (address instance) { instance = clone(0, implementation); } /// @dev Deploys a clone of `implementation`. function clone(uint256 value, address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { /** * --------------------------------------------------------------------------+ * CREATION (9 bytes) | * --------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * --------------------------------------------------------------------------| * 60 runSize | PUSH1 runSize | r | | * 3d | RETURNDATASIZE | 0 r | | * 81 | DUP2 | r 0 r | | * 60 offset | PUSH1 offset | o r 0 r | | * 3d | RETURNDATASIZE | 0 o r 0 r | | * 39 | CODECOPY | 0 r | [0..runSize): runtime code | * f3 | RETURN | | [0..runSize): runtime code | * --------------------------------------------------------------------------| * RUNTIME (44 bytes) | * --------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * --------------------------------------------------------------------------| * | * ::: keep some values in stack ::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | 0 | | * 3d | RETURNDATASIZE | 0 0 | | * 3d | RETURNDATASIZE | 0 0 0 | | * 3d | RETURNDATASIZE | 0 0 0 0 | | * | * ::: copy calldata to memory ::::::::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds 0 0 0 0 | | * 3d | RETURNDATASIZE | 0 cds 0 0 0 0 | | * 3d | RETURNDATASIZE | 0 0 cds 0 0 0 0 | | * 37 | CALLDATACOPY | 0 0 0 0 | [0..cds): calldata | * | * ::: delegate call to the implementation contract :::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds 0 0 0 0 | [0..cds): calldata | * 3d | RETURNDATASIZE | 0 cds 0 0 0 0 | [0..cds): calldata | * 73 addr | PUSH20 addr | addr 0 cds 0 0 0 0 | [0..cds): calldata | * 5a | GAS | gas addr 0 cds 0 0 0 0 | [0..cds): calldata | * f4 | DELEGATECALL | success 0 0 | [0..cds): calldata | * | * ::: copy return data to memory :::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds success 0 0 | [0..cds): calldata | * 3d | RETURNDATASIZE | rds rds success 0 0 | [0..cds): calldata | * 93 | SWAP4 | 0 rds success 0 rds | [0..cds): calldata | * 80 | DUP1 | 0 0 rds success 0 rds | [0..cds): calldata | * 3e | RETURNDATACOPY | success 0 rds | [0..rds): returndata | * | * 60 0x2a | PUSH1 0x2a | 0x2a success 0 rds | [0..rds): returndata | * 57 | JUMPI | 0 rds | [0..rds): returndata | * | * ::: revert :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * fd | REVERT | | [0..rds): returndata | * | * ::: return :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 5b | JUMPDEST | 0 rds | [0..rds): returndata | * f3 | RETURN | | [0..rds): returndata | * --------------------------------------------------------------------------+ */ mstore(0x21, 0x5af43d3d93803e602a57fd5bf3) mstore(0x14, implementation) mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73) instance := create(value, 0x0c, 0x35) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Deploys a deterministic clone of `implementation` with `salt`. function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { instance = cloneDeterministic(0, implementation, salt); } /// @dev Deploys a deterministic clone of `implementation` with `salt`. function cloneDeterministic(uint256 value, address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { mstore(0x21, 0x5af43d3d93803e602a57fd5bf3) mstore(0x14, implementation) mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73) instance := create2(value, 0x0c, 0x35, salt) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the initialization code hash of the clone of `implementation`. /// Used for mining vanity addresses with create2crunch. function initCodeHash(address implementation) internal pure returns (bytes32 hash) { /// @solidity memory-safe-assembly assembly { mstore(0x21, 0x5af43d3d93803e602a57fd5bf3) mstore(0x14, implementation) mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73) hash := keccak256(0x0c, 0x35) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the address of the deterministic clone of `implementation`, /// with `salt` by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddress(address implementation, bytes32 salt, address deployer) internal pure returns (address predicted) { bytes32 hash = initCodeHash(implementation); predicted = predictDeterministicAddress(hash, salt, deployer); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MINIMAL PROXY OPERATIONS (PUSH0 VARIANT) */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Deploys a PUSH0 clone of `implementation`. function clone_PUSH0(address implementation) internal returns (address instance) { instance = clone_PUSH0(0, implementation); } /// @dev Deploys a PUSH0 clone of `implementation`. function clone_PUSH0(uint256 value, address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { /** * --------------------------------------------------------------------------+ * CREATION (9 bytes) | * --------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * --------------------------------------------------------------------------| * 60 runSize | PUSH1 runSize | r | | * 5f | PUSH0 | 0 r | | * 81 | DUP2 | r 0 r | | * 60 offset | PUSH1 offset | o r 0 r | | * 5f | PUSH0 | 0 o r 0 r | | * 39 | CODECOPY | 0 r | [0..runSize): runtime code | * f3 | RETURN | | [0..runSize): runtime code | * --------------------------------------------------------------------------| * RUNTIME (45 bytes) | * --------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * --------------------------------------------------------------------------| * | * ::: keep some values in stack ::::::::::::::::::::::::::::::::::::::::::: | * 5f | PUSH0 | 0 | | * 5f | PUSH0 | 0 0 | | * | * ::: copy calldata to memory ::::::::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds 0 0 | | * 5f | PUSH0 | 0 cds 0 0 | | * 5f | PUSH0 | 0 0 cds 0 0 | | * 37 | CALLDATACOPY | 0 0 | [0..cds): calldata | * | * ::: delegate call to the implementation contract :::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds 0 0 | [0..cds): calldata | * 5f | PUSH0 | 0 cds 0 0 | [0..cds): calldata | * 73 addr | PUSH20 addr | addr 0 cds 0 0 | [0..cds): calldata | * 5a | GAS | gas addr 0 cds 0 0 | [0..cds): calldata | * f4 | DELEGATECALL | success | [0..cds): calldata | * | * ::: copy return data to memory :::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds success | [0..cds): calldata | * 5f | PUSH0 | 0 rds success | [0..cds): calldata | * 5f | PUSH0 | 0 0 rds success | [0..cds): calldata | * 3e | RETURNDATACOPY | success | [0..rds): returndata | * | * 60 0x29 | PUSH1 0x29 | 0x29 success | [0..rds): returndata | * 57 | JUMPI | | [0..rds): returndata | * | * ::: revert :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds | [0..rds): returndata | * 5f | PUSH0 | 0 rds | [0..rds): returndata | * fd | REVERT | | [0..rds): returndata | * | * ::: return :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 5b | JUMPDEST | | [0..rds): returndata | * 3d | RETURNDATASIZE | rds | [0..rds): returndata | * 5f | PUSH0 | 0 rds | [0..rds): returndata | * f3 | RETURN | | [0..rds): returndata | * --------------------------------------------------------------------------+ */ mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16 mstore(0x14, implementation) // 20 mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9 instance := create(value, 0x0e, 0x36) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x24, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Deploys a deterministic PUSH0 clone of `implementation` with `salt`. function cloneDeterministic_PUSH0(address implementation, bytes32 salt) internal returns (address instance) { instance = cloneDeterministic_PUSH0(0, implementation, salt); } /// @dev Deploys a deterministic PUSH0 clone of `implementation` with `salt`. function cloneDeterministic_PUSH0(uint256 value, address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16 mstore(0x14, implementation) // 20 mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9 instance := create2(value, 0x0e, 0x36, salt) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x24, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the initialization code hash of the PUSH0 clone of `implementation`. /// Used for mining vanity addresses with create2crunch. function initCodeHash_PUSH0(address implementation) internal pure returns (bytes32 hash) { /// @solidity memory-safe-assembly assembly { mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16 mstore(0x14, implementation) // 20 mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9 hash := keccak256(0x0e, 0x36) mstore(0x24, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the address of the deterministic PUSH0 clone of `implementation`, /// with `salt` by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddress_PUSH0( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { bytes32 hash = initCodeHash_PUSH0(implementation); predicted = predictDeterministicAddress(hash, salt, deployer); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CLONES WITH IMMUTABLE ARGS OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Note: This implementation of CWIA differs from the original implementation. // If the calldata is empty, it will emit a `ReceiveETH(uint256)` event and skip the `DELEGATECALL`. /// @dev Deploys a clone of `implementation` with immutable arguments encoded in `data`. function clone(address implementation, bytes memory data) internal returns (address instance) { instance = clone(0, implementation, data); } /// @dev Deploys a clone of `implementation` with immutable arguments encoded in `data`. function clone(uint256 value, address implementation, bytes memory data) internal returns (address instance) { assembly { // Compute the boundaries of the data and cache the memory slots around it. let mBefore3 := mload(sub(data, 0x60)) let mBefore2 := mload(sub(data, 0x40)) let mBefore1 := mload(sub(data, 0x20)) let dataLength := mload(data) let dataEnd := add(add(data, 0x20), dataLength) let mAfter1 := mload(dataEnd) // +2 bytes for telling how much data there is appended to the call. let extraLength := add(dataLength, 2) // The `creationSize` is `extraLength + 108` // The `runSize` is `creationSize - 10`. /** * ---------------------------------------------------------------------------------------------------+ * CREATION (10 bytes) | * ---------------------------------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * ---------------------------------------------------------------------------------------------------| * 61 runSize | PUSH2 runSize | r | | * 3d | RETURNDATASIZE | 0 r | | * 81 | DUP2 | r 0 r | | * 60 offset | PUSH1 offset | o r 0 r | | * 3d | RETURNDATASIZE | 0 o r 0 r | | * 39 | CODECOPY | 0 r | [0..runSize): runtime code | * f3 | RETURN | | [0..runSize): runtime code | * ---------------------------------------------------------------------------------------------------| * RUNTIME (98 bytes + extraLength) | * ---------------------------------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * ---------------------------------------------------------------------------------------------------| * | * ::: if no calldata, emit event & return w/o `DELEGATECALL` ::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds | | * 60 0x2c | PUSH1 0x2c | 0x2c cds | | * 57 | JUMPI | | | * 34 | CALLVALUE | cv | | * 3d | RETURNDATASIZE | 0 cv | | * 52 | MSTORE | | [0..0x20): callvalue | * 7f sig | PUSH32 0x9e.. | sig | [0..0x20): callvalue | * 59 | MSIZE | 0x20 sig | [0..0x20): callvalue | * 3d | RETURNDATASIZE | 0 0x20 sig | [0..0x20): callvalue | * a1 | LOG1 | | [0..0x20): callvalue | * 00 | STOP | | [0..0x20): callvalue | * 5b | JUMPDEST | | | * | * ::: copy calldata to memory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds | | * 3d | RETURNDATASIZE | 0 cds | | * 3d | RETURNDATASIZE | 0 0 cds | | * 37 | CALLDATACOPY | | [0..cds): calldata | * | * ::: keep some values in stack :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | 0 | [0..cds): calldata | * 3d | RETURNDATASIZE | 0 0 | [0..cds): calldata | * 3d | RETURNDATASIZE | 0 0 0 | [0..cds): calldata | * 3d | RETURNDATASIZE | 0 0 0 0 | [0..cds): calldata | * 61 extra | PUSH2 extra | e 0 0 0 0 | [0..cds): calldata | * | * ::: copy extra data to memory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 80 | DUP1 | e e 0 0 0 0 | [0..cds): calldata | * 60 0x62 | PUSH1 0x62 | 0x62 e e 0 0 0 0 | [0..cds): calldata | * 36 | CALLDATASIZE | cds 0x62 e e 0 0 0 0 | [0..cds): calldata | * 39 | CODECOPY | e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * | * ::: delegate call to the implementation contract ::::::::::::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 01 | ADD | cds+e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 3d | RETURNDATASIZE | 0 cds+e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 73 addr | PUSH20 addr | addr 0 cds+e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 5a | GAS | gas addr 0 cds+e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * f4 | DELEGATECALL | success 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * | * ::: copy return data to memory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds success 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 3d | RETURNDATASIZE | rds rds success 0 0 | [0..cds): calldata, [cds..cds+e): extraData | * 93 | SWAP4 | 0 rds success 0 rds | [0..cds): calldata, [cds..cds+e): extraData | * 80 | DUP1 | 0 0 rds success 0 rds | [0..cds): calldata, [cds..cds+e): extraData | * 3e | RETURNDATACOPY | success 0 rds | [0..rds): returndata | * | * 60 0x60 | PUSH1 0x60 | 0x60 success 0 rds | [0..rds): returndata | * 57 | JUMPI | 0 rds | [0..rds): returndata | * | * ::: revert ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * fd | REVERT | | [0..rds): returndata | * | * ::: return ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | * 5b | JUMPDEST | 0 rds | [0..rds): returndata | * f3 | RETURN | | [0..rds): returndata | * ---------------------------------------------------------------------------------------------------+ */ mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data. mstore(sub(data, 0x0d), implementation) // Write the address of the implementation. // Write the rest of the bytecode. mstore( sub(data, 0x21), or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73) ) // `keccak256("ReceiveETH(uint256)")` mstore( sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff ) mstore( // Do a out-of-gas revert if `extraLength` is too big. 0xffff - 0x62 + 0x01 = 0xff9e. // The actual EVM limit may be smaller and may change over time. sub(data, add(0x59, lt(extraLength, 0xff9e))), or(shl(0x78, add(extraLength, 0x62)), 0xfd6100003d81600a3d39f336602c57343d527f) ) mstore(dataEnd, shl(0xf0, extraLength)) instance := create(value, sub(data, 0x4c), add(extraLength, 0x6c)) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } // Restore the overwritten memory surrounding `data`. mstore(dataEnd, mAfter1) mstore(data, dataLength) mstore(sub(data, 0x20), mBefore1) mstore(sub(data, 0x40), mBefore2) mstore(sub(data, 0x60), mBefore3) } } /// @dev Deploys a deterministic clone of `implementation` /// with immutable arguments encoded in `data` and `salt`. function cloneDeterministic(address implementation, bytes memory data, bytes32 salt) internal returns (address instance) { instance = cloneDeterministic(0, implementation, data, salt); } /// @dev Deploys a deterministic clone of `implementation` /// with immutable arguments encoded in `data` and `salt`. function cloneDeterministic( uint256 value, address implementation, bytes memory data, bytes32 salt ) internal returns (address instance) { assembly { // Compute the boundaries of the data and cache the memory slots around it. let mBefore3 := mload(sub(data, 0x60)) let mBefore2 := mload(sub(data, 0x40)) let mBefore1 := mload(sub(data, 0x20)) let dataLength := mload(data) let dataEnd := add(add(data, 0x20), dataLength) let mAfter1 := mload(dataEnd) // +2 bytes for telling how much data there is appended to the call. let extraLength := add(dataLength, 2) mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data. mstore(sub(data, 0x0d), implementation) // Write the address of the implementation. // Write the rest of the bytecode. mstore( sub(data, 0x21), or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73) ) // `keccak256("ReceiveETH(uint256)")` mstore( sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff ) mstore( // Do a out-of-gas revert if `extraLength` is too big. 0xffff - 0x62 + 0x01 = 0xff9e. // The actual EVM limit may be smaller and may change over time. sub(data, add(0x59, lt(extraLength, 0xff9e))), or(shl(0x78, add(extraLength, 0x62)), 0xfd6100003d81600a3d39f336602c57343d527f) ) mstore(dataEnd, shl(0xf0, extraLength)) instance := create2(value, sub(data, 0x4c), add(extraLength, 0x6c), salt) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } // Restore the overwritten memory surrounding `data`. mstore(dataEnd, mAfter1) mstore(data, dataLength) mstore(sub(data, 0x20), mBefore1) mstore(sub(data, 0x40), mBefore2) mstore(sub(data, 0x60), mBefore3) } } /// @dev Returns the initialization code hash of the clone of `implementation` /// using immutable arguments encoded in `data`. /// Used for mining vanity addresses with create2crunch. function initCodeHash(address implementation, bytes memory data) internal pure returns (bytes32 hash) { assembly { // Compute the boundaries of the data and cache the memory slots around it. let mBefore3 := mload(sub(data, 0x60)) let mBefore2 := mload(sub(data, 0x40)) let mBefore1 := mload(sub(data, 0x20)) let dataLength := mload(data) let dataEnd := add(add(data, 0x20), dataLength) let mAfter1 := mload(dataEnd) // Do a out-of-gas revert if `dataLength` is too big. 0xffff - 0x02 - 0x62 = 0xff9b. // The actual EVM limit may be smaller and may change over time. returndatacopy(returndatasize(), returndatasize(), gt(dataLength, 0xff9b)) // +2 bytes for telling how much data there is appended to the call. let extraLength := add(dataLength, 2) mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data. mstore(sub(data, 0x0d), implementation) // Write the address of the implementation. // Write the rest of the bytecode. mstore( sub(data, 0x21), or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73) ) // `keccak256("ReceiveETH(uint256)")` mstore( sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff ) mstore( sub(data, 0x5a), or(shl(0x78, add(extraLength, 0x62)), 0x6100003d81600a3d39f336602c57343d527f) ) mstore(dataEnd, shl(0xf0, extraLength)) hash := keccak256(sub(data, 0x4c), add(extraLength, 0x6c)) // Restore the overwritten memory surrounding `data`. mstore(dataEnd, mAfter1) mstore(data, dataLength) mstore(sub(data, 0x20), mBefore1) mstore(sub(data, 0x40), mBefore2) mstore(sub(data, 0x60), mBefore3) } } /// @dev Returns the address of the deterministic clone of /// `implementation` using immutable arguments encoded in `data`, with `salt`, by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddress( address implementation, bytes memory data, bytes32 salt, address deployer ) internal pure returns (address predicted) { bytes32 hash = initCodeHash(implementation, data); predicted = predictDeterministicAddress(hash, salt, deployer); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MINIMAL ERC1967 PROXY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Note: The ERC1967 proxy here is intended to be upgraded with UUPS. // This is NOT the same as ERC1967Factory's transparent proxy, which includes admin logic. /// @dev Deploys a minimal ERC1967 proxy with `implementation`. function deployERC1967(address implementation) internal returns (address instance) { instance = deployERC1967(0, implementation); } /// @dev Deploys a minimal ERC1967 proxy with `implementation`. function deployERC1967(uint256 value, address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { /** * ---------------------------------------------------------------------------------+ * CREATION (34 bytes) | * ---------------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * ---------------------------------------------------------------------------------| * 60 runSize | PUSH1 runSize | r | | * 3d | RETURNDATASIZE | 0 r | | * 81 | DUP2 | r 0 r | | * 60 offset | PUSH1 offset | o r 0 r | | * 3d | RETURNDATASIZE | 0 o r 0 r | | * 39 | CODECOPY | 0 r | [0..runSize): runtime code | * 73 impl | PUSH20 impl | impl 0 r | [0..runSize): runtime code | * 60 slotPos | PUSH1 slotPos | slotPos impl 0 r | [0..runSize): runtime code | * 51 | MLOAD | slot impl 0 r | [0..runSize): runtime code | * 55 | SSTORE | 0 r | [0..runSize): runtime code | * f3 | RETURN | | [0..runSize): runtime code | * ---------------------------------------------------------------------------------| * RUNTIME (62 bytes) | * ---------------------------------------------------------------------------------| * Opcode | Mnemonic | Stack | Memory | * ---------------------------------------------------------------------------------| * | * ::: copy calldata to memory :::::::::::::::::::::::::::::::::::::::::::::::::::: | * 36 | CALLDATASIZE | cds | | * 3d | RETURNDATASIZE | 0 cds | | * 3d | RETURNDATASIZE | 0 0 cds | | * 37 | CALLDATACOPY | | [0..calldatasize): calldata | * | * ::: delegatecall to implementation ::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | 0 | | * 3d | RETURNDATASIZE | 0 0 | | * 36 | CALLDATASIZE | cds 0 0 | [0..calldatasize): calldata | * 3d | RETURNDATASIZE | 0 cds 0 0 | [0..calldatasize): calldata | * 7f slot | PUSH32 slot | s 0 cds 0 0 | [0..calldatasize): calldata | * 54 | SLOAD | i 0 cds 0 0 | [0..calldatasize): calldata | * 5a | GAS | g i 0 cds 0 0 | [0..calldatasize): calldata | * f4 | DELEGATECALL | succ | [0..calldatasize): calldata | * | * ::: copy returndata to memory :::::::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds succ | [0..calldatasize): calldata | * 60 0x00 | PUSH1 0x00 | 0 rds succ | [0..calldatasize): calldata | * 80 | DUP1 | 0 0 rds succ | [0..calldatasize): calldata | * 3e | RETURNDATACOPY | succ | [0..returndatasize): returndata | * | * ::: branch on delegatecall status :::::::::::::::::::::::::::::::::::::::::::::: | * 60 0x38 | PUSH1 0x38 | dest succ | [0..returndatasize): returndata | * 57 | JUMPI | | [0..returndatasize): returndata | * | * ::: delegatecall failed, revert :::::::::::::::::::::::::::::::::::::::::::::::: | * 3d | RETURNDATASIZE | rds | [0..returndatasize): returndata | * 60 0x00 | PUSH1 0x00 | 0 rds | [0..returndatasize): returndata | * fd | REVERT | | [0..returndatasize): returndata | * | * ::: delegatecall succeeded, return ::::::::::::::::::::::::::::::::::::::::::::: | * 5b | JUMPDEST | | [0..returndatasize): returndata | * 3d | RETURNDATASIZE | rds | [0..returndatasize): returndata | * 60 0x00 | PUSH1 0x00 | 0 rds | [0..returndatasize): returndata | * f3 | RETURN | | [0..returndatasize): returndata | * ---------------------------------------------------------------------------------+ */ let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3) mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076) mstore(0x20, 0x6009) mstore(0x1e, implementation) mstore(0x0a, 0x603d3d8160223d3973) instance := create(value, 0x21, 0x5f) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero slot. } } /// @dev Deploys a deterministic minimal ERC1967 proxy with `implementation` and `salt`. function deployDeterministicERC1967(address implementation, bytes32 salt) internal returns (address instance) { instance = deployDeterministicERC1967(0, implementation, salt); } /// @dev Deploys a deterministic minimal ERC1967 proxy with `implementation` and `salt`. function deployDeterministicERC1967(uint256 value, address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3) mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076) mstore(0x20, 0x6009) mstore(0x1e, implementation) mstore(0x0a, 0x603d3d8160223d3973) instance := create2(value, 0x21, 0x5f, salt) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero slot. } } /// @dev Creates a deterministic minimal ERC1967 proxy with `implementation` and `salt`. /// Note: This method is intended for use in ERC4337 factories, /// which are expected to NOT revert if the proxy is already deployed. function createDeterministicERC1967(address implementation, bytes32 salt) internal returns (bool alreadyDeployed, address instance) { return createDeterministicERC1967(0, implementation, salt); } /// @dev Creates a deterministic minimal ERC1967 proxy with `implementation` and `salt`. /// Note: This method is intended for use in ERC4337 factories, /// which are expected to NOT revert if the proxy is already deployed. function createDeterministicERC1967(uint256 value, address implementation, bytes32 salt) internal returns (bool alreadyDeployed, address instance) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3) mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076) mstore(0x20, 0x6009) mstore(0x1e, implementation) mstore(0x0a, 0x603d3d8160223d3973) // Compute and store the bytecode hash. mstore(add(m, 0x35), keccak256(0x21, 0x5f)) mstore(m, shl(88, address())) mstore8(m, 0xff) // Write the prefix. mstore(add(m, 0x15), salt) instance := keccak256(m, 0x55) for {} 1 {} { if iszero(extcodesize(instance)) { instance := create2(value, 0x21, 0x5f, salt) if iszero(instance) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } break } alreadyDeployed := 1 if iszero(value) { break } if iszero(call(gas(), instance, value, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } break } mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero slot. } } /// @dev Returns the initialization code hash of the clone of `implementation` /// using immutable arguments encoded in `data`. /// Used for mining vanity addresses with create2crunch. function initCodeHashERC1967(address implementation) internal pure returns (bytes32 hash) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3) mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076) mstore(0x20, 0x6009) mstore(0x1e, implementation) mstore(0x0a, 0x603d3d8160223d3973) hash := keccak256(0x21, 0x5f) mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero slot. } } /// @dev Returns the address of the deterministic clone of /// `implementation` using immutable arguments encoded in `data`, with `salt`, by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddressERC1967( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { bytes32 hash = initCodeHashERC1967(implementation); predicted = predictDeterministicAddress(hash, salt, deployer); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* OTHER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the address when a contract with initialization code hash, /// `hash`, is deployed with `salt`, by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddress(bytes32 hash, bytes32 salt, address deployer) internal pure returns (address predicted) { /// @solidity memory-safe-assembly assembly { // Compute and store the bytecode hash. mstore8(0x00, 0xff) // Write the prefix. mstore(0x35, hash) mstore(0x01, shl(96, deployer)) mstore(0x15, salt) predicted := keccak256(0x00, 0x55) mstore(0x35, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Requires that `salt` starts with either the zero address or `by`. function checkStartsWith(bytes32 salt, address by) internal pure { /// @solidity memory-safe-assembly assembly { // If the salt does not start with the zero address or `by`. if iszero(or(iszero(shr(96, salt)), eq(shr(96, shl(96, by)), shr(96, salt)))) { mstore(0x00, 0x0c4549ef) // `SaltDoesNotStartWith()`. revert(0x1c, 0x04) } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for converting numbers into strings and other string operations. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol) library LibString { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The `length` of the output is too small to contain all the hex digits. error HexLengthInsufficient(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the `search` is not found in the string. uint256 internal constant NOT_FOUND = type(uint256).max; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the base 10 decimal representation of `value`. function toString(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned. // We will need 1 word for the trailing zeros padding, 1 word for the length, // and 3 words for a maximum of 78 digits. str := add(mload(0x40), 0x80) // Update the free memory pointer to allocate. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end of the memory to calculate the length later. let end := str let w := not(0) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 1)`. // Write the character to the pointer. // The ASCII index of the '0' character is 48. mstore8(str, add(48, mod(temp, 10))) // Keep dividing `temp` until zero. temp := div(temp, 10) if iszero(temp) { break } } let length := sub(end, str) // Move the pointer 32 bytes leftwards to make room for the length. str := sub(str, 0x20) // Store the length. mstore(str, length) } } /// @dev Returns the base 10 decimal representation of `value`. function toString(int256 value) internal pure returns (string memory str) { if (value >= 0) { return toString(uint256(value)); } unchecked { str = toString(uint256(-value)); } /// @solidity memory-safe-assembly assembly { // We still have some spare memory space on the left, // as we have allocated 3 words (96 bytes) for up to 78 digits. let length := mload(str) // Load the string length. mstore(str, 0x2d) // Store the '-' character. str := sub(str, 1) // Move back the string pointer by a byte. mstore(str, add(length, 1)) // Update the string length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HEXADECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2 + 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) { str = toHexStringNoPrefix(value, length); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length. // We add 0x20 to the total and round down to a multiple of 0x20. // (0x20 + 0x20 + 0x02 + 0x20) = 0x62. str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f))) // Allocate the memory. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end to calculate the length later. let end := str // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let start := sub(str, add(length, length)) let w := not(1) // Tsk. let temp := value // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for {} 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(xor(str, start)) { break } } if temp { // Store the function selector of `HexLengthInsufficient()`. mstore(0x00, 0x2194895a) // Revert with (offset, size). revert(0x1c, 0x04) } // Compute the string's length. let strLength := sub(end, str) // Move the pointer and write the length. str := sub(str, 0x20) mstore(str, strLength) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2 + 2` bytes. function toHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x". /// The output excludes leading "0" from the `toHexString` output. /// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`. function toMinimalHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := add(mload(str), 2) // Compute the length. mstore(add(str, o), 0x3078) // Write the "0x" prefix, accounting for leading zero. str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output excludes leading "0" from the `toHexStringNoPrefix` output. /// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`. function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := mload(str) // Get the length. str := add(str, o) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2` bytes. function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x40 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0. str := add(mload(0x40), 0x80) // Allocate the memory. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end to calculate the length later. let end := str // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let w := not(1) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(temp) { break } } // Compute the string's length. let strLength := sub(end, str) // Move the pointer and write the length. str := sub(str, 0x20) mstore(str, strLength) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte, /// and the alphabets are capitalized conditionally according to /// https://eips.ethereum.org/EIPS/eip-55 function toHexStringChecksummed(address value) internal pure returns (string memory str) { str = toHexString(value); /// @solidity memory-safe-assembly assembly { let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...` let o := add(str, 0x22) let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... ` let t := shl(240, 136) // `0b10001000 << 240` for { let i := 0 } 1 {} { mstore(add(i, i), mul(t, byte(i, hashed))) i := add(i, 1) if eq(i, 20) { break } } mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask))))) o := add(o, 0x20) mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask))))) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. function toHexString(address value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(address value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { str := mload(0x40) // Allocate the memory. // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x28 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80. mstore(0x40, add(str, 0x80)) // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) str := add(str, 2) mstore(str, 40) let o := add(str, 0x20) mstore(add(o, 40), 0) value := shl(96, value) // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let i := 0 } 1 {} { let p := add(o, add(i, i)) let temp := byte(i, value) mstore8(add(p, 1), mload(and(temp, 15))) mstore8(p, mload(shr(4, temp))) i := add(i, 1) if eq(i, 20) { break } } } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexString(bytes memory raw) internal pure returns (string memory str) { str = toHexStringNoPrefix(raw); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { let length := mload(raw) str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix. mstore(str, add(length, length)) // Store the length of the output. // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let o := add(str, 0x20) let end := add(raw, length) for {} iszero(eq(raw, end)) {} { raw := add(raw, 1) mstore8(add(o, 1), mload(and(mload(raw), 15))) mstore8(o, mload(and(shr(4, mload(raw)), 15))) o := add(o, 2) } mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RUNE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the number of UTF characters in the string. function runeCount(string memory s) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { if mload(s) { mstore(0x00, div(not(0), 255)) mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506) let o := add(s, 0x20) let end := add(o, mload(s)) for { result := 1 } 1 { result := add(result, 1) } { o := add(o, byte(0, mload(shr(250, mload(o))))) if iszero(lt(o, end)) { break } } } } } /// @dev Returns if this string is a 7-bit ASCII string. /// (i.e. all characters codes are in [0..127]) function is7BitASCII(string memory s) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let mask := shl(7, div(not(0), 255)) result := 1 let n := mload(s) if n { let o := add(s, 0x20) let end := add(o, n) let last := mload(end) mstore(end, 0) for {} 1 {} { if and(mask, mload(o)) { result := 0 break } o := add(o, 0x20) if iszero(lt(o, end)) { break } } mstore(end, last) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // For performance and bytecode compactness, all indices of the following operations // are byte (ASCII) offsets, not UTF character offsets. /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`. function replace(string memory subject, string memory search, string memory replacement) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) let replacementLength := mload(replacement) subject := add(subject, 0x20) search := add(search, 0x20) replacement := add(replacement, 0x20) result := add(mload(0x40), 0x20) let subjectEnd := add(subject, subjectLength) if iszero(gt(searchLength, subjectLength)) { let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Copy the `replacement` one word at a time. for { let o := 0 } 1 {} { mstore(add(result, o), mload(add(replacement, o))) o := add(o, 0x20) if iszero(lt(o, replacementLength)) { break } } result := add(result, replacementLength) subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } } let resultRemainder := result result := add(mload(0x40), 0x20) let k := add(sub(resultRemainder, result), sub(subjectEnd, subject)) // Copy the rest of the string one word at a time. for {} lt(subject, subjectEnd) {} { mstore(resultRemainder, mload(subject)) resultRemainder := add(resultRemainder, 0x20) subject := add(subject, 0x20) } result := sub(result, 0x20) let last := add(add(result, 0x20), k) // Zeroize the slot after the string. mstore(last, 0) mstore(0x40, add(last, 0x20)) // Allocate the memory. mstore(result, k) // Store the length. } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for { let subjectLength := mload(subject) } 1 {} { if iszero(mload(search)) { if iszero(gt(from, subjectLength)) { result := from break } result := subjectLength break } let searchLength := mload(search) let subjectStart := add(subject, 0x20) result := not(0) // Initialize to `NOT_FOUND`. subject := add(subjectStart, from) let end := add(sub(add(subjectStart, subjectLength), searchLength), 1) let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(add(search, 0x20)) if iszero(and(lt(subject, end), lt(from, subjectLength))) { break } if iszero(lt(searchLength, 0x20)) { for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if iszero(shr(m, xor(mload(subject), s))) { if eq(keccak256(subject, searchLength), h) { result := sub(subject, subjectStart) break } } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } for {} 1 {} { if iszero(shr(m, xor(mload(subject), s))) { result := sub(subject, subjectStart) break } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = indexOf(subject, search, 0); } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for {} 1 {} { result := not(0) // Initialize to `NOT_FOUND`. let searchLength := mload(search) if gt(searchLength, mload(subject)) { break } let w := result let fromMax := sub(mload(subject), searchLength) if iszero(gt(fromMax, from)) { from := fromMax } let end := add(add(subject, 0x20), w) subject := add(add(subject, 0x20), from) if iszero(gt(subject, end)) { break } // As this function is not too often used, // we shall simply use keccak256 for smaller bytecode size. for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if eq(keccak256(subject, searchLength), h) { result := sub(subject, add(end, 1)) break } subject := add(subject, w) // `sub(subject, 1)`. if iszero(gt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = lastIndexOf(subject, search, uint256(int256(-1))); } /// @dev Returns true if `search` is found in `subject`, false otherwise. function contains(string memory subject, string memory search) internal pure returns (bool) { return indexOf(subject, search) != NOT_FOUND; } /// @dev Returns whether `subject` starts with `search`. function startsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( iszero(gt(searchLength, mload(subject))), eq( keccak256(add(subject, 0x20), searchLength), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns whether `subject` ends with `search`. function endsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) let subjectLength := mload(subject) // Whether `search` is not longer than `subject`. let withinRange := iszero(gt(searchLength, subjectLength)) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( withinRange, eq( keccak256( // `subject + 0x20 + max(subjectLength - searchLength, 0)`. add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))), searchLength ), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns `subject` repeated `times`. function repeat(string memory subject, uint256 times) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(or(iszero(times), iszero(subjectLength))) { subject := add(subject, 0x20) result := mload(0x40) let output := add(result, 0x20) for {} 1 {} { // Copy the `subject` one word at a time. for { let o := 0 } 1 {} { mstore(add(output, o), mload(add(subject, o))) o := add(o, 0x20) if iszero(lt(o, subjectLength)) { break } } output := add(output, subjectLength) times := sub(times, 1) if iszero(times) { break } } mstore(output, 0) // Zeroize the slot after the string. let resultLength := sub(output, add(result, 0x20)) mstore(result, resultLength) // Store the length. // Allocate the memory. mstore(0x40, add(result, add(resultLength, 0x20))) } } } /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive). /// `start` and `end` are byte offsets. function slice(string memory subject, uint256 start, uint256 end) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(gt(subjectLength, end)) { end := subjectLength } if iszero(gt(subjectLength, start)) { start := subjectLength } if lt(start, end) { result := mload(0x40) let resultLength := sub(end, start) mstore(result, resultLength) subject := add(subject, start) let w := not(0x1f) // Copy the `subject` one word at a time, backwards. for { let o := and(add(resultLength, 0x1f), w) } 1 {} { mstore(add(result, o), mload(add(subject, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(result, 0x20), resultLength), 0) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, add(result, and(add(resultLength, 0x3f), w))) } } } /// @dev Returns a copy of `subject` sliced from `start` to the end of the string. /// `start` is a byte offset. function slice(string memory subject, uint256 start) internal pure returns (string memory result) { result = slice(subject, start, uint256(int256(-1))); } /// @dev Returns all the indices of `search` in `subject`. /// The indices are byte offsets. function indicesOf(string memory subject, string memory search) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) if iszero(gt(searchLength, subjectLength)) { subject := add(subject, 0x20) search := add(search, 0x20) result := add(mload(0x40), 0x20) let subjectStart := subject let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Append to `result`. mstore(result, sub(subject, subjectStart)) result := add(result, 0x20) // Advance `subject` by `searchLength`. subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } let resultEnd := result // Assign `result` to the free memory pointer. result := mload(0x40) // Store the length of `result`. mstore(result, shr(5, sub(resultEnd, add(result, 0x20)))) // Allocate memory for result. // We allocate one more word, so this array can be recycled for {split}. mstore(0x40, add(resultEnd, 0x20)) } } } /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string. function split(string memory subject, string memory delimiter) internal pure returns (string[] memory result) { uint256[] memory indices = indicesOf(subject, delimiter); /// @solidity memory-safe-assembly assembly { let w := not(0x1f) let indexPtr := add(indices, 0x20) let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1))) mstore(add(indicesEnd, w), mload(subject)) mstore(indices, add(mload(indices), 1)) let prevIndex := 0 for {} 1 {} { let index := mload(indexPtr) mstore(indexPtr, 0x60) if iszero(eq(index, prevIndex)) { let element := mload(0x40) let elementLength := sub(index, prevIndex) mstore(element, elementLength) // Copy the `subject` one word at a time, backwards. for { let o := and(add(elementLength, 0x1f), w) } 1 {} { mstore(add(element, o), mload(add(add(subject, prevIndex), o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(element, 0x20), elementLength), 0) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, add(element, and(add(elementLength, 0x3f), w))) // Store the `element` into the array. mstore(indexPtr, element) } prevIndex := add(index, mload(delimiter)) indexPtr := add(indexPtr, 0x20) if iszero(lt(indexPtr, indicesEnd)) { break } } result := indices if iszero(mload(delimiter)) { result := add(indices, 0x20) mstore(result, sub(mload(indices), 2)) } } } /// @dev Returns a concatenated string of `a` and `b`. /// Cheaper than `string.concat()` and does not de-align the free memory pointer. function concat(string memory a, string memory b) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let w := not(0x1f) result := mload(0x40) let aLength := mload(a) // Copy `a` one word at a time, backwards. for { let o := and(add(aLength, 0x20), w) } 1 {} { mstore(add(result, o), mload(add(a, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let bLength := mload(b) let output := add(result, aLength) // Copy `b` one word at a time, backwards. for { let o := and(add(bLength, 0x20), w) } 1 {} { mstore(add(output, o), mload(add(b, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let totalLength := add(aLength, bLength) let last := add(add(result, 0x20), totalLength) // Zeroize the slot after the string. mstore(last, 0) // Stores the length. mstore(result, totalLength) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, and(add(last, 0x1f), w)) } } /// @dev Returns a copy of the string in either lowercase or UPPERCASE. /// WARNING! This function is only compatible with 7-bit ASCII strings. function toCase(string memory subject, bool toUpper) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let length := mload(subject) if length { result := add(mload(0x40), 0x20) subject := add(subject, 1) let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff) let w := not(0) for { let o := length } 1 {} { o := add(o, w) let b := and(0xff, mload(add(subject, o))) mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20))) if iszero(o) { break } } result := mload(0x40) mstore(result, length) // Store the length. let last := add(add(result, 0x20), length) mstore(last, 0) // Zeroize the slot after the string. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } } /// @dev Returns a string from a small bytes32 string. /// `smallString` must be null terminated, or behavior will be undefined. function fromSmallString(bytes32 smallString) internal pure returns (string memory result) { if (smallString == bytes32(0)) return result; /// @solidity memory-safe-assembly assembly { result := mload(0x40) let n := 0 for {} 1 {} { n := add(n, 1) if iszero(byte(n, smallString)) { break } // Scan for '\0'. } mstore(result, n) let o := add(result, 0x20) mstore(o, smallString) mstore(add(o, n), 0) mstore(0x40, add(result, 0x40)) } } /// @dev Returns a lowercased copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function lower(string memory subject) internal pure returns (string memory result) { result = toCase(subject, false); } /// @dev Returns an UPPERCASED copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function upper(string memory subject) internal pure returns (string memory result) { result = toCase(subject, true); } /// @dev Escapes the string to be used within HTML tags. function escapeHTML(string memory s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) // Store the bytes of the packed offsets and strides into the scratch space. // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6. mstore(0x1f, 0x900094) mstore(0x08, 0xc0000000a6ab) // Store ""&'<>" into the scratch space. mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) // Not in `["\"","'","&","<",">"]`. if iszero(and(shl(c, 1), 0x500000c400000000)) { mstore8(result, c) result := add(result, 1) continue } let t := shr(248, mload(c)) mstore(result, mload(and(t, 0x1f))) result := add(result, shr(5, t)) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes. function escapeJSON(string memory s, bool addDoubleQuotes) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } // Store "\\u0000" in scratch space. // Store "0123456789abcdef" in scratch space. // Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`. // into the scratch space. mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672) // Bitmask for detecting `["\"","\\"]`. let e := or(shl(0x22, 1), shl(0x5c, 1)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) if iszero(lt(c, 0x20)) { if iszero(and(shl(c, 1), e)) { // Not in `["\"","\\"]`. mstore8(result, c) result := add(result, 1) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), c) result := add(result, 2) continue } if iszero(and(shl(c, 1), 0x3700)) { // Not in `["\b","\t","\n","\f","\d"]`. mstore8(0x1d, mload(shr(4, c))) // Hex value. mstore8(0x1e, mload(and(c, 15))) // Hex value. mstore(result, mload(0x19)) // "\\u00XX". result := add(result, 6) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), mload(add(c, 8))) result := add(result, 2) } if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. function escapeJSON(string memory s) internal pure returns (string memory result) { result = escapeJSON(s, false); } /// @dev Returns whether `a` equals `b`. function eq(string memory a, string memory b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b))) } } /// @dev Returns whether `a` equals `b`. For small strings up to 32 bytes. /// `b` must be null terminated, or behavior will be undefined. function eqs(string memory a, bytes32 b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { // These should be evaluated on compile time, as far as possible. let x := and(b, add(not(b), 1)) let r := or(shl(8, iszero(b)), shl(7, iszero(iszero(shr(128, x))))) r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x)))))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) result := gt(eq(mload(a), sub(32, shr(3, r))), shr(r, xor(b, mload(add(a, 0x20))))) } } /// @dev Packs a single string with its length into a single word. /// Returns `bytes32(0)` if the length is zero or greater than 31. function packOne(string memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { // We don't need to zero right pad the string, // since this is our own custom non-standard packing scheme. result := mul( // Load the length and the bytes. mload(add(a, 0x1f)), // `length != 0 && length < 32`. Abuses underflow. // Assumes that the length is valid and within the block gas limit. lt(sub(mload(a), 1), 0x1f) ) } } /// @dev Unpacks a string packed using {packOne}. /// Returns the empty string if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packOne}, the output behavior is undefined. function unpackOne(bytes32 packed) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { // Grab the free memory pointer. result := mload(0x40) // Allocate 2 words (1 for the length, 1 for the bytes). mstore(0x40, add(result, 0x40)) // Zeroize the length slot. mstore(result, 0) // Store the length and bytes. mstore(add(result, 0x1f), packed) // Right pad with zeroes. mstore(add(add(result, 0x20), mload(result)), 0) } } /// @dev Packs two strings with their lengths into a single word. /// Returns `bytes32(0)` if combined length is zero or greater than 30. function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let aLength := mload(a) // We don't need to zero right pad the strings, // since this is our own custom non-standard packing scheme. result := mul( // Load the length and the bytes of `a` and `b`. or( shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))), mload(sub(add(b, 0x1e), aLength)) ), // `totalLength != 0 && totalLength < 31`. Abuses underflow. // Assumes that the lengths are valid and within the block gas limit. lt(sub(add(aLength, mload(b)), 1), 0x1e) ) } } /// @dev Unpacks strings packed using {packTwo}. /// Returns the empty strings if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packTwo}, the output behavior is undefined. function unpackTwo(bytes32 packed) internal pure returns (string memory resultA, string memory resultB) { /// @solidity memory-safe-assembly assembly { // Grab the free memory pointer. resultA := mload(0x40) resultB := add(resultA, 0x40) // Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words. mstore(0x40, add(resultB, 0x40)) // Zeroize the length slots. mstore(resultA, 0) mstore(resultB, 0) // Store the lengths and bytes. mstore(add(resultA, 0x1f), packed) mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA)))) // Right pad with zeroes. mstore(add(add(resultA, 0x20), mload(resultA)), 0) mstore(add(add(resultB, 0x20), mload(resultB)), 0) } } /// @dev Directly returns `a` without copying. function directReturn(string memory a) internal pure { assembly { // Assumes that the string does not start from the scratch space. let retStart := sub(a, 0x20) let retSize := add(mload(a), 0x40) // Right pad with zeroes. Just in case the string is produced // by a method that doesn't zero right pad. mstore(add(retStart, retSize), 0) // Store the return offset. mstore(retStart, 0x20) // End the transaction, returning the string. return(retStart, retSize) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// /// @dev Note: /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection. /// - For ERC20s, this implementation won't check that a token has code, /// responsibility is delegated to the caller. library SafeTransferLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev The ERC20 `transferFrom` has failed. error TransferFromFailed(); /// @dev The ERC20 `transfer` has failed. error TransferFailed(); /// @dev The ERC20 `approve` has failed. error ApproveFailed(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes. uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300; /// @dev Suggested gas stipend for contract receiving ETH to perform a few /// storage reads and writes, but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ETH OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants. // // The regular variants: // - Forwards all remaining gas to the target. // - Reverts if the target reverts. // - Reverts if the current contract has insufficient balance. // // The force variants: // - Forwards with an optional gas stipend // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases). // - If the target reverts, or if the gas stipend is exhausted, // creates a temporary contract to force send the ETH via `SELFDESTRUCT`. // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758. // - Reverts if the current contract has insufficient balance. // // The try variants: // - Forwards with a mandatory gas stipend. // - Instead of reverting, returns whether the transfer succeeded. /// @dev Sends `amount` (in wei) ETH to `to`. function safeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Sends all the ETH in the current contract to `to`. function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`. function forceSafeTransferAllETH(address to, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // forgefmt: disable-next-item if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00) } } /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`. function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for /// the current contract to manage. function safeTransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends all of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have their entire balance approved for /// the current contract to manage. function safeTransferAllFrom(address token, address from, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`. amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransfer(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sends all of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransferAll(address token, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`. mstore(0x20, address()) // Store the address of the current contract. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x14, to) // Store the `to` argument. amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// Reverts upon failure. function safeApprove(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// If the initial attempt to approve fails, attempts to reset the approved amount to zero, /// then retries the approval again (some tokens, e.g. USDT, requires this). /// Reverts upon failure. function safeApproveWithRetry(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, retrying upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x34, 0) // Store 0 for the `amount`. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval. mstore(0x34, amount) // Store back the original `amount`. // Retry the approval, reverting upon failure. if iszero( and( or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Returns the amount of ERC20 `token` owned by `account`. /// Returns zero if the `token` does not exist. function balanceOf(address token, address account) internal view returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x14, account) // Store the `account` argument. mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. amount := mul( mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20) ) ) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for compressing and decompressing bytes. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibZip.sol) /// @author Calldata compression by clabby (https://github.com/clabby/op-kompressor) /// @author FastLZ by ariya (https://github.com/ariya/FastLZ) /// /// @dev Note: /// The accompanying solady.js library includes implementations of /// FastLZ and calldata operations for convenience. library LibZip { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* FAST LZ OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // LZ77 implementation based on FastLZ. // Equivalent to level 1 compression and decompression at the following commit: // https://github.com/ariya/FastLZ/commit/344eb4025f9ae866ebf7a2ec48850f7113a97a42 // Decompression is backwards compatible. /// @dev Returns the compressed `data`. function flzCompress(bytes memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { function ms8(d_, v_) -> _d { mstore8(d_, v_) _d := add(d_, 1) } function u24(p_) -> _u { let w := mload(p_) _u := or(shl(16, byte(2, w)), or(shl(8, byte(1, w)), byte(0, w))) } function cmp(p_, q_, e_) -> _l { for { e_ := sub(e_, q_) } lt(_l, e_) { _l := add(_l, 1) } { e_ := mul(iszero(byte(0, xor(mload(add(p_, _l)), mload(add(q_, _l))))), e_) } } function literals(runs_, src_, dest_) -> _o { for { _o := dest_ } iszero(lt(runs_, 0x20)) { runs_ := sub(runs_, 0x20) } { mstore(ms8(_o, 31), mload(src_)) _o := add(_o, 0x21) src_ := add(src_, 0x20) } if iszero(runs_) { leave } mstore(ms8(_o, sub(runs_, 1)), mload(src_)) _o := add(1, add(_o, runs_)) } function match(l_, d_, o_) -> _o { for { d_ := sub(d_, 1) } iszero(lt(l_, 263)) { l_ := sub(l_, 262) } { o_ := ms8(ms8(ms8(o_, add(224, shr(8, d_))), 253), and(0xff, d_)) } if iszero(lt(l_, 7)) { _o := ms8(ms8(ms8(o_, add(224, shr(8, d_))), sub(l_, 7)), and(0xff, d_)) leave } _o := ms8(ms8(o_, add(shl(5, l_), shr(8, d_))), and(0xff, d_)) } function setHash(i_, v_) { let p := add(mload(0x40), shl(2, i_)) mstore(p, xor(mload(p), shl(224, xor(shr(224, mload(p)), v_)))) } function getHash(i_) -> _h { _h := shr(224, mload(add(mload(0x40), shl(2, i_)))) } function hash(v_) -> _r { _r := and(shr(19, mul(2654435769, v_)), 0x1fff) } function setNextHash(ip_, ipStart_) -> _ip { setHash(hash(u24(ip_)), sub(ip_, ipStart_)) _ip := add(ip_, 1) } codecopy(mload(0x40), codesize(), 0x8000) // Zeroize the hashmap. let op := add(mload(0x40), 0x8000) let a := add(data, 0x20) let ipStart := a let ipLimit := sub(add(ipStart, mload(data)), 13) for { let ip := add(2, a) } lt(ip, ipLimit) {} { let r := 0 let d := 0 for {} 1 {} { let s := u24(ip) let h := hash(s) r := add(ipStart, getHash(h)) setHash(h, sub(ip, ipStart)) d := sub(ip, r) if iszero(lt(ip, ipLimit)) { break } ip := add(ip, 1) if iszero(gt(d, 0x1fff)) { if eq(s, u24(r)) { break } } } if iszero(lt(ip, ipLimit)) { break } ip := sub(ip, 1) if gt(ip, a) { op := literals(sub(ip, a), a, op) } let l := cmp(add(r, 3), add(ip, 3), add(ipLimit, 9)) op := match(l, d, op) ip := setNextHash(setNextHash(add(ip, l), ipStart), ipStart) a := ip } op := literals(sub(add(ipStart, mload(data)), a), a, op) result := mload(0x40) let t := add(result, 0x8000) let n := sub(op, t) mstore(result, n) // Store the length. // Copy the result to compact the memory, overwriting the hashmap. let o := add(result, 0x20) for { let i } lt(i, n) { i := add(i, 0x20) } { mstore(add(o, i), mload(add(t, i))) } mstore(add(o, n), 0) // Zeroize the slot after the string. mstore(0x40, add(add(o, n), 0x20)) // Allocate the memory. } } /// @dev Returns the decompressed `data`. function flzDecompress(bytes memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { let n := 0 let end := add(add(data, 0x20), mload(data)) result := mload(0x40) let op := add(result, 0x20) for { data := add(data, 0x20) } lt(data, end) {} { let w := mload(data) let c := byte(0, w) let t := shr(5, c) if iszero(t) { mstore(add(op, n), mload(add(data, 1))) data := add(data, add(2, c)) n := add(n, add(1, c)) continue } let g := eq(t, 7) let l := add(2, xor(t, mul(g, xor(t, add(7, byte(1, w)))))) for { let s := add(add(shl(8, and(0x1f, c)), byte(add(1, g), w)), 1) let r := add(op, sub(n, s)) let o := add(op, n) let f := xor(s, mul(gt(s, 0x20), xor(s, 0x20))) let j := 0 } 1 {} { mstore(add(o, j), mload(add(r, j))) j := add(j, f) if iszero(lt(j, l)) { break } } data := add(data, add(2, g)) n := add(n, l) } mstore(result, n) // Store the length. let o := add(add(result, 0x20), n) mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CALLDATA OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Calldata compression and decompression using selective run length encoding: // - Sequences of 0x00 (up to 128 consecutive). // - Sequences of 0xff (up to 32 consecutive). // // A run length encoded block consists of two bytes: // (0) 0x00 // (1) A control byte with the following bit layout: // - [7] `0: 0x00, 1: 0xff`. // - [0..6] `runLength - 1`. // // The first 4 bytes are bitwise negated so that the compressed calldata // can be dispatched into the `fallback` and `receive` functions. /// @dev Returns the compressed `data`. function cdCompress(bytes memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { function rle(v_, o_, d_) -> _o, _d { mstore(o_, shl(240, or(and(0xff, add(d_, 0xff)), and(0x80, v_)))) _o := add(o_, 2) } result := mload(0x40) let o := add(result, 0x20) let z := 0 // Number of consecutive 0x00. let y := 0 // Number of consecutive 0xff. for { let end := add(data, mload(data)) } iszero(eq(data, end)) {} { data := add(data, 1) let c := byte(31, mload(data)) if iszero(c) { if y { o, y := rle(0xff, o, y) } z := add(z, 1) if eq(z, 0x80) { o, z := rle(0x00, o, 0x80) } continue } if eq(c, 0xff) { if z { o, z := rle(0x00, o, z) } y := add(y, 1) if eq(y, 0x20) { o, y := rle(0xff, o, 0x20) } continue } if y { o, y := rle(0xff, o, y) } if z { o, z := rle(0x00, o, z) } mstore8(o, c) o := add(o, 1) } if y { o, y := rle(0xff, o, y) } if z { o, z := rle(0x00, o, z) } // Bitwise negate the first 4 bytes. mstore(add(result, 4), not(mload(add(result, 4)))) mstore(result, sub(o, add(result, 0x20))) // Store the length. mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } /// @dev Returns the decompressed `data`. function cdDecompress(bytes memory data) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { if mload(data) { result := mload(0x40) let o := add(result, 0x20) let s := add(data, 4) let v := mload(s) let end := add(data, mload(data)) mstore(s, not(v)) // Bitwise negate the first 4 bytes. for {} lt(data, end) {} { data := add(data, 1) let c := byte(31, mload(data)) if iszero(c) { data := add(data, 1) let d := byte(31, mload(data)) // Fill with either 0xff or 0x00. mstore(o, not(0)) if iszero(gt(d, 0x7f)) { codecopy(o, codesize(), add(d, 1)) } o := add(o, add(and(d, 0x7f), 1)) continue } mstore8(o, c) o := add(o, 1) } mstore(s, v) // Restore the first 4 bytes. mstore(result, sub(o, add(result, 0x20))) // Store the length. mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } } /// @dev To be called in the `receive` and `fallback` functions. /// ``` /// receive() external payable { LibZip.cdFallback(); } /// fallback() external payable { LibZip.cdFallback(); } /// ``` /// For efficiency, this function will directly return the results, terminating the context. /// If called internally, it must be called at the end of the function. function cdFallback() internal { assembly { if iszero(calldatasize()) { return(calldatasize(), calldatasize()) } let o := 0 let f := not(3) // For negating the first 4 bytes. for { let i := 0 } lt(i, calldatasize()) {} { let c := byte(0, xor(add(i, f), calldataload(i))) i := add(i, 1) if iszero(c) { let d := byte(0, xor(add(i, f), calldataload(i))) i := add(i, 1) // Fill with either 0xff or 0x00. mstore(o, not(0)) if iszero(gt(d, 0x7f)) { codecopy(o, codesize(), add(d, 1)) } o := add(o, add(and(d, 0x7f), 1)) continue } mstore8(o, c) o := add(o, 1) } let success := delegatecall(gas(), address(), 0x00, o, codesize(), 0x00) returndatacopy(0x00, 0x00, returndatasize()) if iszero(success) { revert(0x00, returndatasize()) } return(0x00, returndatasize()) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] calldata accounts, uint256[] calldata ids ) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; import {IOwnable} from "./IOwnable.sol"; import {IQuest} from "./IQuest.sol"; // solhint-disable-next-line no-empty-blocks interface IQuestOwnable is IQuest, IOwnable {}
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; import {IOwnable} from "./IOwnable.sol"; import {IQuest1155} from "./IQuest1155.sol"; // solhint-disable-next-line no-empty-blocks interface IQuest1155Ownable is IQuest1155, IOwnable {}
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [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://consensys.net/diligence/blog/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.8.0/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 pragma solidity ^0.8.4; /// @notice Simple single owner authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The caller is not authorized to call the function. error Unauthorized(); /// @dev The `newOwner` cannot be the zero address. error NewOwnerIsZeroAddress(); /// @dev The `pendingOwner` does not have a valid handover request. error NoHandoverRequest(); /// @dev Cannot double-initialize. error AlreadyInitialized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This event is intentionally kept the same as OpenZeppelin's Ownable to be /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173), /// despite it not being as lightweight as a single argument event. event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); /// @dev An ownership handover to `pendingOwner` has been requested. event OwnershipHandoverRequested(address indexed pendingOwner); /// @dev The ownership handover to `pendingOwner` has been canceled. event OwnershipHandoverCanceled(address indexed pendingOwner); /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`. uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE = 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0; /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE = 0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d; /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE = 0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The owner slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`. /// It is intentionally chosen to be a high value /// to avoid collision with lower slots. /// The choice of manual storage layout is to enable compatibility /// with both regular and upgradeable contracts. bytes32 internal constant _OWNER_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927; /// The ownership handover slot of `newOwner` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED)) /// let handoverSlot := keccak256(0x00, 0x20) /// ``` /// It stores the expiry timestamp of the two-step ownership handover. uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return true to make `_initializeOwner` prevent double-initialization. function _guardInitializeOwner() internal pure virtual returns (bool guard) {} /// @dev Initializes the owner directly without authorization guard. /// This function must be called upon initialization, /// regardless of whether the contract is upgradeable or not. /// This is to enable generalization to both regular and upgradeable contracts, /// and to save gas in case the initial owner is not the caller. /// For performance reasons, this function will not check if there /// is an existing owner. function _initializeOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT if sload(ownerSlot) { mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`. revert(0x1c, 0x04) } // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } else { /// @solidity memory-safe-assembly assembly { // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(_OWNER_SLOT, newOwner) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } } /// @dev Sets the owner directly without authorization guard. function _setOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) } } else { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, newOwner) } } } /// @dev Throws if the sender is not the owner. function _checkOwner() internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner, revert. if iszero(eq(caller(), sload(_OWNER_SLOT))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Returns how long a two-step ownership handover is valid for in seconds. /// Override to return a different value if needed. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ownershipHandoverValidFor() internal view virtual returns (uint64) { return 48 * 3600; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to transfer the ownership to `newOwner`. function transferOwnership(address newOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { if iszero(shl(96, newOwner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _setOwner(newOwner); } /// @dev Allows the owner to renounce their ownership. function renounceOwnership() public payable virtual onlyOwner { _setOwner(address(0)); } /// @dev Request a two-step ownership handover to the caller. /// The request will automatically expire in 48 hours (172800 seconds) by default. function requestOwnershipHandover() public payable virtual { unchecked { uint256 expires = block.timestamp + _ownershipHandoverValidFor(); /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to `expires`. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), expires) // Emit the {OwnershipHandoverRequested} event. log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller()) } } } /// @dev Cancels the two-step ownership handover to the caller, if any. function cancelOwnershipHandover() public payable virtual { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), 0) // Emit the {OwnershipHandoverCanceled} event. log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller()) } } /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. /// Reverts if there is no existing ownership handover requested by `pendingOwner`. function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) let handoverSlot := keccak256(0x0c, 0x20) // If the handover does not exist, or has expired. if gt(timestamp(), sload(handoverSlot)) { mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`. revert(0x1c, 0x04) } // Set the handover slot to 0. sstore(handoverSlot, 0) } _setOwner(pendingOwner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the owner of the contract. function owner() public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { result := sload(_OWNER_SLOT) } } /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. function ownershipHandoverExpiresAt(address pendingOwner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the handover slot. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) // Load the handover slot. result := sload(keccak256(0x0c, 0x20)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by the owner. modifier onlyOwner() virtual { _checkOwner(); _; } }
// 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 pragma solidity 0.8.19; interface IOwnable { // Events event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); event OwnershipHandoverRequested(address indexed pendingOwner); event OwnershipHandoverCanceled(address indexed pendingOwner); // Update functions function transferOwnership(address newOwner) external payable; function renounceOwnership() external payable; function requestOwnershipHandover() external payable; function cancelOwnershipHandover() external payable; function completeOwnershipHandover(address pendingOwner) external payable; // Read functions function owner() external view returns (address); function ownershipHandoverExpiresAt(address pendingOwner) external view returns (uint256); }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; interface IQuest { event Queued(uint256 timestamp); event JsonSpecCIDSet(string cid); event ProtocolFeeDistributed(string questId, address rewardToken, address protocolOwner, uint256 feeAmountToProtocolOwner, address questOwner, uint256 feeAmountToQuestOwner); error AlreadyClaimed(); error AlreadyWithdrawn(); error AmountExceedsBalance(); error ClaimWindowNotStarted(); error EndTimeInPast(); error EndTimeLessThanOrEqualToStartTime(); error InvalidRefundToken(); error MustImplementInChild(); error NotQuestFactory(); error NoWithdrawDuringClaim(); error NotStarted(); error TotalAmountExceedsBalance(); error AuthOwnerRecipient(); error AddressNotSigned(); error InvalidClaimFee(); error OverMaxAllowedToMint(); error AddressAlreadyMinted(); error QuestEnded(); function initialize( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 rewardAmountInWei_, string memory questId_, uint16 questFee_, address protocolFeeRecipient_, uint40 durationTotal_, address sablierV2LockupLinearAddress_ ) external; function getRewardAmount() external view returns (uint256); function getRewardToken() external view returns (address); function queued() external view returns (bool); function startTime() external view returns (uint256); function endTime() external view returns (uint256); function singleClaim(address account) external; function rewardToken() external view returns (address); function rewardAmountInWei() external view returns (uint256); function totalTransferAmount() external view returns (uint256); function questFee() external view returns (uint16); function totalParticipants() external view returns (uint256); function hasWithdrawn() external view returns (bool); function questId() external view returns (string memory); }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; interface IQuest1155 { // Structs struct FactoryQuest { mapping(address => bool) addressMinted; address questAddress; uint256 totalParticipants; uint256 numberMinted; string questType; uint40 durationTotal; address questCreator; address mintFeeRecipient; } // Events event Queued(uint256 timestamp); event QuestClaimedData( address indexed recipient, address indexed referrer, string extraData ); // Errors error EndTimeInPast(); error EndTimeLessThanOrEqualToStartTime(); error InsufficientTokenBalance(); error InsufficientETHBalance(); error NotStarted(); error NotEnded(); error NotQueued(); error NotQuestFactory(); error QuestEnded(); error AlreadyWithdrawn(); error AddressNotSigned(); error InvalidClaimFee(); error AddressAlreadyMinted(); error OverMaxAllowedToMint(); // Initializer/Contstructor Function function initialize( address rewardTokenAddress_, uint256 endTime_, uint256 startTime_, uint256 totalParticipants_, uint256 tokenId_, address protocolFeeRecipient_, string memory questId_ ) external; // Read Functions function endTime() external view returns (uint256); function hasWithdrawn() external view returns (bool); function maxProtocolReward() external view returns (uint256); function questFee() external view returns (uint256); function queued() external view returns (bool); function startTime() external view returns (uint256); function tokenId() external view returns (uint256); function rewardToken() external view returns (address); // Update Functions function pause() external; function queue() external; function singleClaim(address account_) external; function unPause() external; function withdrawRemainingTokens() external; }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "solady/=lib/solady/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "sablier/=lib/v2-core/src/", "@openzeppelin/contracts/=lib/v2-core/lib/openzeppelin-contracts/contracts/", "@prb/math/=lib/v2-core/lib/prb-math/", "@prb/test/=lib/v2-core/lib/prb-test/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/", "openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/", "prb-math/=lib/v2-core/lib/prb-math/src/", "prb-test/=lib/v2-core/lib/prb-test/src/", "solarray/=lib/v2-core/lib/solarray/src/", "v2-core/=lib/v2-core/" ], "optimizer": { "enabled": true, "runs": 1000 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AddressAlreadyMinted","type":"error"},{"inputs":[],"name":"AddressNotSigned","type":"error"},{"inputs":[],"name":"AddressZeroNotAllowed","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"AuthOwnerDiscountToken","type":"error"},{"inputs":[],"name":"ClaimFailed","type":"error"},{"inputs":[],"name":"Deprecated","type":"error"},{"inputs":[],"name":"Erc20QuestAddressNotSet","type":"error"},{"inputs":[],"name":"InvalidMintFee","type":"error"},{"inputs":[],"name":"MsgValueLessThanQuestNFTFee","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"OverMaxAllowedToMint","type":"error"},{"inputs":[],"name":"QuestAddressMismatch","type":"error"},{"inputs":[],"name":"QuestEnded","type":"error"},{"inputs":[],"name":"QuestFeeTooHigh","type":"error"},{"inputs":[],"name":"QuestIdUsed","type":"error"},{"inputs":[],"name":"QuestNotQueued","type":"error"},{"inputs":[],"name":"QuestNotStarted","type":"error"},{"inputs":[],"name":"QuestTypeNotSupported","type":"error"},{"inputs":[],"name":"Reentrancy","type":"error"},{"inputs":[],"name":"ReferralFeeTooHigh","type":"error"},{"inputs":[],"name":"RewardNotAllowed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"ZeroAddressNotAllowed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ExtraMintFeeReturned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"questId","type":"string"},{"indexed":false,"internalType":"address","name":"rabbitHoleAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"rabbitHoleAmountWei","type":"uint256"},{"indexed":false,"internalType":"address","name":"questCreatorAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"questCreatorAmountWei","type":"uint256"},{"indexed":false,"internalType":"address","name":"referrerAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"referrerAmountWei","type":"uint256"}],"name":"MintFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"mintFee","type":"uint256"}],"name":"MintFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"addresses","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"fees","type":"uint256[]"}],"name":"NftQuestFeeListSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftQuestFee","type":"uint256"}],"name":"NftQuestFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"address","name":"questAddress","type":"address"},{"indexed":false,"internalType":"string","name":"questId","type":"string"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Quest1155Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"address","name":"questAddress","type":"address"},{"indexed":false,"internalType":"string","name":"questId","type":"string"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardAmountInWei","type":"uint256"}],"name":"QuestClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"address","name":"questAddress","type":"address"},{"indexed":false,"internalType":"string","name":"extraData","type":"string"}],"name":"QuestClaimedData","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"address","name":"questAddress","type":"address"},{"indexed":false,"internalType":"string","name":"questId","type":"string"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardAmountInWeiOrTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"uint16","name":"referralFee","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"mintFeeEthWei","type":"uint256"}],"name":"QuestClaimedReferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":false,"internalType":"string","name":"questId","type":"string"},{"indexed":false,"internalType":"string","name":"questType","type":"string"},{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalParticipants","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardAmountOrTokenId","type":"uint256"}],"name":"QuestCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"percent","type":"uint16"}],"name":"ReferralFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"roles","type":"uint256"}],"name":"RolesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sablierV2LockupLinearAddress","type":"address"}],"name":"SablierV2LockupLinearAddressSet","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"compressedData_","type":"bytes"}],"name":"claimCompressed","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"signature_","type":"bytes"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"claimOptimized","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"claimSignerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardTokenAddress_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"uint256","name":"totalParticipants_","type":"uint256"},{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"string","name":"questId_","type":"string"},{"internalType":"string","name":"","type":"string"}],"name":"create1155QuestAndQueue","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardTokenAddress_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"uint256","name":"totalParticipants_","type":"uint256"},{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"string","name":"questId_","type":"string"},{"internalType":"string","name":"actionType_","type":"string"},{"internalType":"string","name":"questName_","type":"string"}],"name":"createERC1155Quest","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardTokenAddress_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"uint256","name":"totalParticipants_","type":"uint256"},{"internalType":"uint256","name":"rewardAmount_","type":"uint256"},{"internalType":"string","name":"questId_","type":"string"},{"internalType":"string","name":"actionType_","type":"string"},{"internalType":"string","name":"questName_","type":"string"}],"name":"createERC20Quest","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardTokenAddress_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"uint256","name":"totalParticipants_","type":"uint256"},{"internalType":"uint256","name":"rewardAmount_","type":"uint256"},{"internalType":"string","name":"questId_","type":"string"},{"internalType":"string","name":"","type":"string"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"createQuestAndQueue","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultMintFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultReferralFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"erc1155QuestAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"erc20QuestAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"questId_","type":"string"},{"internalType":"address","name":"address_","type":"address"}],"name":"getAddressMinted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"questCreatorAddress_","type":"address"}],"name":"getMintFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"address_","type":"address"}],"name":"getNftQuestFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"questId_","type":"string"}],"name":"getNumberMinted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"grantRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"hasAllRoles","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"hasAnyRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"claimSignerAddress_","type":"address"},{"internalType":"address","name":"protocolFeeRecipient_","type":"address"},{"internalType":"address","name":"erc20QuestAddress_","type":"address"},{"internalType":"address payable","name":"erc1155QuestAddress_","type":"address"},{"internalType":"address","name":"ownerAddress_","type":"address"},{"internalType":"address","name":"defaultReferralFeeRecipientAddress_","type":"address"},{"internalType":"address","name":"sablierV2LockupLinearAddress_","type":"address"},{"internalType":"uint256","name":"nftQuestFee_","type":"uint256"},{"internalType":"uint16","name":"referralFee_","type":"uint16"},{"internalType":"uint256","name":"mintFee_","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintFeeRecipientList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftQuestFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nftQuestFeeList","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bool","name":"exists","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"ownerCollections","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"questId_","type":"string"}],"name":"questData","outputs":[{"components":[{"internalType":"address","name":"questAddress","type":"address"},{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"bool","name":"queued","type":"bool"},{"internalType":"uint16","name":"questFee","type":"uint16"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"uint256","name":"totalParticipants","type":"uint256"},{"internalType":"uint256","name":"numberMinted","type":"uint256"},{"internalType":"uint256","name":"redeemedTokens","type":"uint256"},{"internalType":"uint256","name":"rewardAmountOrTokenId","type":"uint256"},{"internalType":"bool","name":"hasWithdrawn","type":"bool"}],"internalType":"struct IQuestFactory.QuestData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"questFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"questId_","type":"string"}],"name":"questInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"questNFTAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"quests","outputs":[{"internalType":"address","name":"questAddress","type":"address"},{"internalType":"uint256","name":"totalParticipants","type":"uint256"},{"internalType":"uint256","name":"numberMinted","type":"uint256"},{"internalType":"string","name":"questType","type":"string"},{"internalType":"uint40","name":"durationTotal","type":"uint40"},{"internalType":"address","name":"questCreator","type":"address"},{"internalType":"address","name":"mintFeeRecipient","type":"address"},{"internalType":"string","name":"actionType","type":"string"},{"internalType":"string","name":"questName","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rabbitHoleReceiptContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rabbitHoleTicketsContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"hash_","type":"bytes32"},{"internalType":"bytes","name":"signature_","type":"bytes"}],"name":"recoverSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referralFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"renounceRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"roles","type":"uint256"}],"name":"revokeRoles","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardAllowlist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"rolesOf","outputs":[{"internalType":"uint256","name":"roles","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sablierV2LockupLinearAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"claimSignerAddress_","type":"address"}],"name":"setClaimSignerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"mintFeeRecipient_","type":"address"}],"name":"setDefaultMintFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"defaultReferralFeeRecipient_","type":"address"}],"name":"setDefaultReferralFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"erc1155QuestAddress_","type":"address"}],"name":"setErc1155QuestAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"erc20QuestAddress_","type":"address"}],"name":"setErc20QuestAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"mintFee_","type":"uint256"}],"name":"setMintFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"address_","type":"address"},{"internalType":"address","name":"mintFeeRecipient_","type":"address"}],"name":"setMintFeeRecipientForAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftQuestFee_","type":"uint256"}],"name":"setNftQuestFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"toAddAddresses_","type":"address[]"},{"internalType":"uint256[]","name":"fees_","type":"uint256[]"}],"name":"setNftQuestFeeList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"protocolFeeRecipient_","type":"address"}],"name":"setProtocolFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"questFee_","type":"uint16"}],"name":"setQuestFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"referralFee_","type":"uint16"}],"name":"setReferralFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardAddress_","type":"address"},{"internalType":"bool","name":"allowed_","type":"bool"}],"name":"setRewardAllowlistAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sablierV2LockupLinearAddress_","type":"address"}],"name":"setSablierV2LockupLinearAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalParticipants_","type":"uint256"}],"name":"totalQuestNFTFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"questId_","type":"string"},{"internalType":"address","name":"protocolFeeRecipient_","type":"address"},{"internalType":"uint256","name":"protocolPayout_","type":"uint256"},{"internalType":"address","name":"mintFeeRecipient_","type":"address"},{"internalType":"uint256","name":"mintPayout","type":"uint256"}],"name":"withdrawCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60806040523480156200001157600080fd5b50600054610100900460ff1615808015620000335750600054600160ff909116105b806200004f5750303b1580156200004f575060005460ff166001145b620000b75760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b6000805460ff191660011790558015620000db576000805461ff0019166101001790555b801562000122576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50614ab080620001336000396000f3fe6080604052600436106103815760003560e01c806384ae2bc6116101cf578063c6eba76611610101578063e521cb921161009a578063f18cb7841161006c578063f18cb78414610b0c578063f2fde38b14610b2c578063f8565efd14610b3f578063fee81cf414610b5f57005b8063e521cb9214610a74578063ec461ac414610a94578063eddd0d9c14610ad9578063f04e283e14610af957005b8063d4faaa17116100d3578063d4faaa17146109de578063d693e8d3146109fe578063deac34c814610a1e578063e1bc3aba14610a5457005b8063c6eba76614610978578063cc923e0c14610998578063ce53b152146109b8578063d27cae76146109cb57005b8063a1db1ba411610173578063be979d3711610145578063be979d37146108f8578063c03bf91f14610918578063c42fe71814610938578063c476dbcc1461095857005b8063a1db1ba414610885578063a2e44593146108a5578063abab135a146108b8578063b4cbdd8b146108d857005b806393600093116101ac578063936000931461080957806397aba7f91461082f578063994f3bd21461084f5780639b86630d1461086f57005b806384ae2bc6146107b557806387c4d47d146107d05780638da5cb5b146107f057005b80634a4ee7b1116102b3578063715018a61161024c5780637e4176e31161021e5780637e4176e3146107135780637f7c0ef7146107485780637fceecd61461077557806381589b1f1461079557005b8063715018a61461067f57806378077f8d146106875780637afc4469146106a75780637c93f9ee146106f357005b806364df049e1161028557806364df049e146105ee57806367dfa3e71461060e578063695ef19f1461063c57806370dfd40a1461066c57005b80634a4ee7b11461057c578063514e62fc1461058f57806354d1f13d146105c65780635ccb62fc146105ce57005b806327b0655f1161032557806339b5f830116102f757806339b5f830146104fc5780633ef17b171461051c5780633f7c9a881461053c57806343ff27d11461055c57005b806327b0655f1461046957806328d3164d146104895780632de94807146104a957806332f58eb5146104dc57005b80631c10893f1161035e5780631c10893f146103fe5780631cd64df4146104115780631ddc4f3014610441578063256929621461046157005b80630b6fc1631461038a57806313966db5146103c7578063183a4f6e146103eb57005b3661038857005b005b34801561039657600080fd5b5060c9546103aa906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156103d357600080fd5b506103dd60d25481565b6040519081526020016103be565b6103886103f9366004613877565b610b92565b61038861040c3660046138b0565b610b9f565b34801561041d57600080fd5b5061043161042c3660046138b0565b610bb5565b60405190151581526020016103be565b34801561044d57600080fd5b5061038861045c3660046138ec565b610bd4565b610388610dce565b34801561047557600080fd5b50610431610484366004613a56565b610e1e565b34801561049557600080fd5b506103886104a4366004613aa8565b610e62565b3480156104b557600080fd5b506103dd6104c4366004613ad6565b638b78c6d8600c908152600091909152602090205490565b3480156104e857600080fd5b506103886104f7366004613ad6565b610e98565b34801561050857600080fd5b506103aa6105173660046138b0565b610ee9565b34801561052857600080fd5b5060ce546103aa906001600160a01b031681565b34801561054857600080fd5b50610388610557366004613ad6565b610f21565b34801561056857600080fd5b506103dd610577366004613af3565b610f4b565b61038861058a3660046138b0565b610f76565b34801561059b57600080fd5b506104316105aa3660046138b0565b638b78c6d8600c90815260009290925260209091205416151590565b610388610f88565b3480156105da57600080fd5b506103aa6105e9366004613ad6565b610fc4565b3480156105fa57600080fd5b5060ca546103aa906001600160a01b031681565b34801561061a57600080fd5b5060d1546106299061ffff1681565b60405161ffff90911681526020016103be565b34801561064857600080fd5b50610431610657366004613ad6565b60d06020526000908152604090205460ff1681565b6103aa61067a366004613b30565b611001565b6103886110a8565b34801561069357600080fd5b5060cf546103aa906001600160a01b031681565b3480156106b357600080fd5b506106de6106c2366004613ad6565b60d9602052600090815260409020805460019091015460ff1682565b604080519283529015156020830152016103be565b3480156106ff57600080fd5b5061038861070e366004613ad6565b6110bc565b34801561071f57600080fd5b5061073361072e366004613af3565b6110e6565b6040516103be99989796959493929190613c1d565b34801561075457600080fd5b50610768610763366004613af3565b6112fb565b6040516103be9190613c93565b34801561078157600080fd5b506103dd610790366004613ad6565b61189b565b3480156107a157600080fd5b506103aa6107b0366004613d46565b6118e2565b3480156107c157600080fd5b5060da546106299061ffff1681565b3480156107dc57600080fd5b506103886107eb366004613e39565b611a42565b3480156107fc57600080fd5b50638b78c6d819546103aa565b34801561081557600080fd5b5060da546103aa906201000090046001600160a01b031681565b34801561083b57600080fd5b506103aa61084a366004613ea5565b611b3b565b34801561085b57600080fd5b5060d7546103aa906001600160a01b031681565b34801561087b57600080fd5b506103dd60d65481565b34801561089157600080fd5b5060cb546103aa906001600160a01b031681565b6103886108b3366004613f42565b611b75565b3480156108c457600080fd5b506103aa6108d3366004613f84565b611e14565b3480156108e457600080fd5b506103886108f3366004613ad6565b611f46565b34801561090457600080fd5b5060d5546103aa906001600160a01b031681565b34801561092457600080fd5b50610388610933366004613ad6565b611f70565b34801561094457600080fd5b50610388610953366004614044565b611fed565b34801561096457600080fd5b506103dd610973366004613877565b612079565b34801561098457600080fd5b50610388610993366004614061565b61208e565b3480156109a457600080fd5b5060d3546103aa906001600160a01b031681565b6103886109c63660046140dd565b61214b565b6103aa6109d9366004613f84565b6127c2565b3480156109ea57600080fd5b5060cc546103aa906001600160a01b031681565b348015610a0a57600080fd5b50610388610a1936600461414b565b61284c565b348015610a2a57600080fd5b506103aa610a39366004613ad6565b60db602052600090815260409020546001600160a01b031681565b348015610a6057600080fd5b50610388610a6f366004614044565b61287f565b348015610a8057600080fd5b50610388610a8f366004613ad6565b6128df565b348015610aa057600080fd5b50610ab4610aaf366004613af3565b612930565b604080516001600160a01b0390941684526020840192909252908201526060016103be565b348015610ae557600080fd5b50610388610af4366004613877565b61297f565b610388610b07366004613ad6565b6129bc565b348015610b1857600080fd5b50610388610b27366004613877565b6129f9565b610388610b3a366004613ad6565b612a36565b348015610b4b57600080fd5b50610388610b5a366004613ad6565b612a5d565b348015610b6b57600080fd5b506103dd610b7a366004613ad6565b63389a75e1600c908152600091909152602090205490565b610b9c3382612a87565b50565b610ba7612a93565b610bb18282612aae565b5050565b638b78c6d8600c90815260008390526020902054811681145b92915050565b600054610100900460ff1615808015610bf45750600054600160ff909116105b80610c0e5750303b158015610c0e575060005460ff166001145b610c9e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840160405180910390fd5b6000805460ff191660011790558015610cc1576000805461ff0019166101001790555b610cca87612aba565b60d180546107d061ffff1991821617909155600160d45560c980546001600160a01b03199081166001600160a01b038f81169190911790925560ca805482168e841617905560cb805482168d841617905560cc805482168c841617905560d5805490911689831617905560da805460d68890557fffffffffffffffffffff000000000000000000000000000000000000000000001662010000928916929092029092161761ffff851617905560d28290558015610dc1576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050505050505050565b60006202a30067ffffffffffffffff164201905063389a75e1600c5233600052806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a250565b600060cd83604051610e309190614179565b908152604080519182900360209081019092206001600160a01b0385166000908152925290205460ff16905092915050565b610e6a612a93565b6001600160a01b03918216600090815260db6020526040902080546001600160a01b03191691909216179055565b610ea0612a93565b6001600160a01b038116610ec7576040516302154e0360e21b815260040160405180910390fd5b60d380546001600160a01b0319166001600160a01b0392909216919091179055565b60d86020528160005260406000208181548110610f0557600080fd5b6000918252602090912001546001600160a01b03169150829050565b610f29612a93565b60d580546001600160a01b0319166001600160a01b0392909216919091179055565b600060cd82604051610f5d9190614179565b9081526020016040518091039020600301549050919050565b610f7e612a93565b610bb18282612a87565b63389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2565b6001600160a01b03808216600090815260db60205260408120549091168015610fed5780610ffa565b60d3546001600160a01b03165b9392505050565b600060d4546001146110265760405163558a1e0360e11b815260040160405180910390fd5b600260d4819055506110976040518061010001604052808a6001600160a01b0316815260200189815260200188815260200187815260200186815260200185815260200160405180602001604052806000815250815260200160405180602001604052806000815250815250612af6565b600160d45598975050505050505050565b6110b0612a93565b6110ba6000612f40565b565b6110c4612a93565b60cb80546001600160a01b0319166001600160a01b0392909216919091179055565b805160208183018101805160cd8252928201919093012091526001810154600282015460038301546004840180546001600160a01b0390941694929391929161112e90614195565b80601f016020809104026020016040519081016040528092919081815260200182805461115a90614195565b80156111a75780601f1061117c576101008083540402835291602001916111a7565b820191906000526020600020905b81548152906001019060200180831161118a57829003601f168201915b5050505060058301546006840154600785018054949564ffffffffff841695650100000000009094046001600160a01b039081169550909216926111ea90614195565b80601f016020809104026020016040519081016040528092919081815260200182805461121690614195565b80156112635780601f1061123857610100808354040283529160200191611263565b820191906000526020600020905b81548152906001019060200180831161124657829003601f168201915b50505050509080600801805461127890614195565b80601f01602080910402602001604051908101604052809291908181526020018280546112a490614195565b80156112f15780601f106112c6576101008083540402835291602001916112f1565b820191906000526020600020905b8154815290600101906020018083116112d457829003601f168201915b5050505050905089565b61137260405180610160016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600015158152602001600061ffff1681526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b600060cd836040516113849190614179565b9081526020016040518091039020905060008160010160009054906101000a90046001600160a01b03169050600080611471604051806040016040528060078152602001666572633131353560c81b8152508560040180546113e590614195565b80601f016020809104026020016040519081016040528092919081815260200182805461141190614195565b801561145e5780601f106114335761010080835404028352916020019161145e565b820191906000526020600020905b81548152906001019060200180831161144157829003601f168201915b5050505050612f7e90919063ffffffff16565b156114f6578360010160009054906101000a90046001600160a01b03166001600160a01b03166317d70f7c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ef91906141cf565b91506115bf565b826001600160a01b03166369d2dc056040518163ffffffff1660e01b8152600401602060405180830381865afa158015611534573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155891906141cf565b9150826001600160a01b03166367dfa3e76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115bc91906141e8565b90505b604080516101608101825260018601546001600160a01b03908116825282517ff7c618c1000000000000000000000000000000000000000000000000000000008152925160009360208085019389169263f7c618c19260048082019392918290030181865afa158015611636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165a9190614205565b6001600160a01b03168152602001856001600160a01b03166316049ddf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ca9190614222565b151581526020018361ffff168152602001856001600160a01b03166378e979256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173d91906141cf565b8152602001856001600160a01b0316633197cbb66040518163ffffffff1660e01b8152600401602060405180830381865afa158015611780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a491906141cf565b8152602001856001600160a01b031663a26dbf266040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180b91906141cf565b81526020018660030154815260200186600301548152602001848152602001856001600160a01b0316636cb4e6116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611868573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188c9190614222565b15159052979650505050505050565b6001600160a01b038116600090815260d9602052604081206001015460ff166118c65760d654610bce565b506001600160a01b0316600090815260d9602052604090205490565b60008389600060cd836040516118f89190614179565b90815260405190819003602001902060018101549091506001600160a01b0316156119365760405163b2431b6160e01b815260040160405180910390fd5b6001600160a01b038216600090815260d0602052604090205460ff1661196f57604051639f7fdf3160e01b815260040160405180910390fd5b60cb546001600160a01b031661199857604051636d9282ef60e11b815260040160405180910390fd5b611a326040518061014001604052808e6001600160a01b031681526020018d81526020018c81526020018b81526020018a8152602001898152602001604051806020016040528060008152508152602001604051806020016040528060008152508152602001600064ffffffffff16815260200160405180604001604052806005815260200164065726332360dc1b815250815250612f94565b9c9b505050505050505050505050565b611a4a612a93565b60005b83811015611af7576040518060400160405280848484818110611a7257611a7261423f565b9050602002013581526020016001151581525060d96000878785818110611a9b57611a9b61423f565b9050602002016020810190611ab09190613ad6565b6001600160a01b03168152602080820192909252604001600020825181559101516001909101805460ff191691151591909117905580611aef8161426b565b915050611a4d565b507f7412a73f7b9b8b4a2fa22f3cb493a2e3008eb96b92abf7f5b06a18ca796eaa3184848484604051611b2d9493929190614284565b60405180910390a150505050565b6000610ffa611b6f846020527b19457468657265756d205369676e6564204d6573736167653a0a3332600052603c60042090565b83613214565b6000611bb683838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506132be92505050565b905060008060008060008086806020019051810190611bd5919061431b565b9550955095509550955095506000611bec83613353565b9050600060cd82604051611c009190614179565b90815260405190819003602001902090506000611d4b611c1f8a61356c565b611c2c8661ffff16613590565b846007018054611c3b90614195565b80601f0160208091040260200160405190810160405280929190818152602001828054611c6790614195565b8015611cb45780601f10611c8957610100808354040283529160200191611cb4565b820191906000526020600020905b815481529060010190602001808311611c9757829003601f168201915b5050505050856008018054611cc890614195565b80601f0160208091040260200160405190810160405280929190818152602001828054611cf490614195565b8015611d415780601f10611d1657610100808354040283529160200191611d41565b820191906000526020600020905b815481529060010190602001808311611d2457829003601f168201915b50505050506135d5565b9050600033878584604051602001611d6694939291906143a9565b60408051808303601f19018152828252602083018c90528282018b905281518084038301815260608401928390527fce53b152000000000000000000000000000000000000000000000000000000009092529250309163ce53b152913491611dd3919086906064016143f2565b6000604051808303818588803b158015611dec57600080fd5b505af1158015611e00573d6000803e3d6000fd5b505050505050505050505050505050505050565b60008389600060cd83604051611e2a9190614179565b90815260405190819003602001902060018101549091506001600160a01b031615611e685760405163b2431b6160e01b815260040160405180910390fd5b6001600160a01b038216600090815260d0602052604090205460ff16611ea157604051639f7fdf3160e01b815260040160405180910390fd5b60cb546001600160a01b0316611eca57604051636d9282ef60e11b815260040160405180910390fd5b611a326040518061014001604052808e6001600160a01b031681526020018d81526020018c81526020018b81526020018a8152602001898152602001888152602001878152602001600064ffffffffff16815260200160405180604001604052806005815260200164065726332360dc1b815250815250612f94565b611f4e612a93565b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b611f78612a93565b60da80547fffffffffffffffffffff0000000000000000000000000000000000000000ffff16620100006001600160a01b038416908102919091179091556040519081527fca0f60d8c8bcfc3249661e03a4dcd6a0342cd857e0b00968738f82e573722a9b906020015b60405180910390a150565b611ff5612a93565b6127108161ffff161115612035576040517faa6e211200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60da805461ffff191661ffff83169081179091556040519081527fa7bf2cb2b95a425df48655de4071d888fbb2d429d265bb008a4cea1dc8a8954890602001611fe2565b60006120843361189b565b610bce9083614420565b600060cd87876040516120a2929190614437565b9081526040519081900360200190206001810154909150336001600160a01b03909116146120fc576040517f7fa7559100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f8e47afab301dea587ea57f7c95a3fe844a798013dd5c177c2e5575c35b1c73bf87878787878760008060405161213a989796959493929190614447565b60405180910390a150505050505050565b600080808061215c858701876144ad565b9350935093509350600060cd836040516121769190614179565b908152602001604051809103902090506000816003015460016121999190614536565b905060008260010160009054906101000a90046001600160a01b03166001600160a01b031663f7c618c16040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122169190614205565b60c9546040519192506000916001600160a01b03909116906122839061223f908d908d90614437565b60405180910390208e8e8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611b3b92505050565b6001600160a01b0316146122c3576040517f05d0fdda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60d2543410156122ff576040517fc288bf8f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03881660009081526020859052604090205460ff1615612352576040517ff5f915f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8360020154831115612390576040517f571e5b1800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03888116600081815260208790526040808220805460ff1916600190811790915560038901889055880154905160248101939093528a8416604484015290921690349060640160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f842acd6800000000000000000000000000000000000000000000000000000000179052516124409190614179565b60006040518083038185875af1925050503d806000811461247d576040519150601f19603f3d011682016040523d82523d6000602084013e612482565b606091505b50509050806124bd576040517f360e42e100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018501546040516001600160a01b03918216918b16907f776d31c62981a6d4b846ed3aeace92ca390dcf303bac6d12439917d147c34ae190612501908a90614549565b60405180910390a361253b604051806040016040528060078152602001666572633131353560c81b8152508660040180546113e590614195565b15612612578460010160009054906101000a90046001600160a01b03166001600160a01b03166317d70f7c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612595573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b991906141cf565b60018601546040519193506001600160a01b0390811691908b16907f10301d5d7c155e8a5269fc62b7841a3fd101266acc5768d5df29b6e8d823433190612605908b908890889061455c565b60405180910390a36126e0565b8460010160009054906101000a90046001600160a01b03166001600160a01b03166369d2dc056040518163ffffffff1660e01b8152600401602060405180830381865afa158015612667573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061268b91906141cf565b60018601546040519193506001600160a01b0390811691908b16907fd35f2250d08242f6e4e2bfe3dac8b5887040ea7223991b25a628b415c3265be9906126d7908b908890889061455c565b60405180910390a35b6001600160a01b038816156127b3578460010160009054906101000a90046001600160a01b03166001600160a01b0316896001600160a01b03167f9c503975322622df0e05ce3ba5b99b1eace4b358cc8c0af4ddf1610f9ce58bbc8986868d610d0560d2546040516127579695949392919061458a565b60405180910390a37f8e47afab301dea587ea57f7c95a3fe844a798013dd5c177c2e5575c35b1c73bf876000806000808d600360d25461279791906145d4565b6040516127aa97969594939291906145f6565b60405180910390a15b50505050505050505050505050565b600060d4546001146127e75760405163558a1e0360e11b815260040160405180910390fd5b600260d48190555061283a6040518061010001604052808b6001600160a01b031681526020018a815260200189815260200188815260200187815260200186815260200185815260200184815250612af6565b600160d4559998505050505050505050565b612854612a93565b6001600160a01b0391909116600090815260d060205260409020805460ff1916911515919091179055565b612887612a93565b6127108161ffff1611156128c7576040517f4ae19ab600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60d1805461ffff191661ffff92909216919091179055565b6128e7612a93565b6001600160a01b03811661290e576040516302154e0360e21b815260040160405180910390fd5b60ca80546001600160a01b0319166001600160a01b0392909216919091179055565b60008060008060cd856040516129469190614179565b908152604051908190036020019020600181015460028201546003909201546001600160a01b0390911695509093509150509193909250565b612987612a93565b60d28190556040518181527f97aee230ba41961438e908e115df76fa8113f85a0586d85b19ba5be50e6a227490602001611fe2565b6129c4612a93565b63389a75e1600c52806000526020600c2080544211156129ec57636f5e88186000526004601cfd5b60009055610b9c81612f40565b612a01612a93565b60d68190556040518181527facfc857f5247cf27fd46d9d8774f59e409be9b50fe1412825bec5c648863f03690602001611fe2565b612a3e612a93565b8060601b612a5457637448fbae6000526004601cfd5b610b9c81612f40565b612a65612a93565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b610bb182826000613607565b638b78c6d8195433146110ba576382b429006000526004601cfd5b610bb182826001613607565b6001600160a01b0316638b78c6d8198190558060007f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a350565b60008060cd8360a00151604051612b0d9190614179565b90815260200160405180910390209050612b2a8360600151612079565b341015612b63576040517f97e2b23c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018101546001600160a01b031615612b8f5760405163b2431b6160e01b815260040160405180910390fd5b6040516bffffffffffffffffffffffff193360601b166020820152466034820152426054820152600090612bea9060740160408051601f19818403018152919052805160209091012060cc546001600160a01b031690613660565b6001830180546001600160a01b0319166001600160a01b03831690811790915560608601516002850155909150612c21903461366e565b6040805180820190915260078152666572633131353560c81b60208201526004830190612c4e9082614695565b506005820180547fffffffffffffff0000000000000000000000000000000000000000ffffffffff1633650100000000000217905560c08401516007830190612c979082614695565b5060e08401516008830190612cac9082614695565b50835160208501516040808701516060880151608089015160ca5460a08b015194517feff5c5bd00000000000000000000000000000000000000000000000000000000815288976001600160a01b03808a169863eff5c5bd98612d1e9893979196939591949290911691600401614755565b600060405180830381600087803b158015612d3857600080fd5b505af1158015612d4c573d6000803e3d6000fd5b50508651608088015160608901516040517ff242432a000000000000000000000000000000000000000000000000000000008152336004808301919091526001600160a01b0389811660248401526044830194909452606482019290925260a0608482015260a48101919091527f307830300000000000000000000000000000000000000000000000000000000060c48201529116925063f242432a915060e401600060405180830381600087803b158015612e0757600080fd5b505af1158015612e1b573d6000803e3d6000fd5b50505050806001600160a01b031663e10d29ee6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612e5a57600080fd5b505af1158015612e6e573d6000803e3d6000fd5b505060405163f2fde38b60e01b81523360048201526001600160a01b038416925063f2fde38b9150602401600060405180830381600087803b158015612eb357600080fd5b505af1158015612ec7573d6000803e3d6000fd5b50505050816001600160a01b0316336001600160a01b03167f7ffd904b9426b92270b251e237818b61230a9c7dc857d7e6130dddc21b7619378760a00151886000015189602001518a604001518b606001518c60800151604051612f30969594939291906147a6565b60405180910390a3509392505050565b638b78c6d81980546001600160a01b039092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355565b8051602091820120825192909101919091201490565b60008060cd8360a00151604051612fab9190614179565b90815260405190819003602090810182206bffffffffffffffffffffffff193360601b169183019190915246603483015242605483015291506000906130189060740160408051601f19818403018152919052805160209091012060cb546001600160a01b031690613660565b6001830180546001600160a01b0319166001600160a01b038316179055606085015160028401556005830180546101008701517fffffffffffffff0000000000000000000000000000000000000000000000000090911633650100000000000264ffffffffff19161764ffffffffff90911617905561012085015190915060048301906130a59082614695565b5060c084015160078301906130ba9082614695565b5060e084015160088301906130cf9082614695565b50806001600160a01b0316336001600160a01b03167f7ffd904b9426b92270b251e237818b61230a9c7dc857d7e6130dddc21b7619378660a0015185600401886000015189602001518a604001518b606001518c6080015160405161313a979695949392919061480e565b60405180910390a3835160208501516040808701516060880151608089015160a08a015160d15460ca546101008d015160da5497517fbb7516550000000000000000000000000000000000000000000000000000000081526001600160a01b03808d169b63bb7516559b6131d49b919a9099909890979096909561ffff9091169490831693909262010000909204909116906004016148db565b600060405180830381600087803b1580156131ee57600080fd5b505af1158015613202573d6000803e3d6000fd5b50505050610ffa81856000015161368a565b604051600190836000526020830151604052604083510361326957604083015160ff81901c601b016020527f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660605261328f565b604183510361328a57606083015160001a602052604083015160605261328f565b600091505b6020600160806000855afa5191503d6132b057638baa579f6000526004601cfd5b600060605260405292915050565b606081511561334e5760405190506020810160048301805184518501811983525b80861015613337576001860195508551601f1a80613328576001870196508651601f1a6000198652607f811161331757600181013887395b607f169490940160010193506132df565b808553506001840193506132df565b509052601f19828203018252600081526020016040525b919050565b604080518082018252601081527f30313233343536373839616263646566000000000000000000000000000000006020820152815160248082526060828101909452600091906020820181803683370190505090506000805b60108110156135625780600414806133c45750806006145b806133cf5750806008145b806133da575080600a145b15613435577f2d00000000000000000000000000000000000000000000000000000000000000838361340b8161426b565b94508151811061341d5761341d61423f565b60200101906001600160f81b031916908160001a9053505b83600487836010811061344a5761344a61423f565b1a60f81b6001600160f81b031916901c60f81c60ff16815181106134705761347061423f565b01602001517fff000000000000000000000000000000000000000000000000000000000000001683836134a28161426b565b9450815181106134b4576134b461423f565b60200101906001600160f81b031916908160001a905350838682601081106134de576134de61423f565b825191901a600f169081106134f5576134f561423f565b01602001517fff000000000000000000000000000000000000000000000000000000000000001683836135278161426b565b9450815181106135395761353961423f565b60200101906001600160f81b031916908160001a9053508061355a8161426b565b9150506133ac565b5090949350505050565b60606135778261376e565b8051613078825260020160011990910190815292915050565b60606080604051019050602081016040526000815280600019835b928101926030600a8206018453600a9004806135ab575b5050819003601f19909101908152919050565b6060848483856040516020016135ee9493929190614951565b6040516020818303038152906040529050949350505050565b638b78c6d8600c52826000526020600c20805483811783613629575080841681185b80835580600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe26600080a3505050505050565b6000610ffa600084846137c3565b60003860003884865af1610bb15763b12d13eb6000526004601cfd5b6000339050600083905061370d8285836001600160a01b0316633dd4d94f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156136d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136fb91906141cf565b6001600160a01b03871692919061381a565b60405163f2fde38b60e01b81526001600160a01b03838116600483015282169063f2fde38b90602401600060405180830381600087803b15801561375057600080fd5b505af1158015613764573d6000803e3d6000fd5b5050505050505050565b606060806040510190506020810160405260008152806f30313233343536373839616263646566600f52600119835b600f811651938201936001850153600f8160041c1651845360081c80156135c25761379d565b60006c5af43d3d93803e602a57fd5bf36021528260145273602c3d8160093d39f33d3d3d3d363d3d37363d73600052816035600c86f590508061380e5763301164256000526004601cfd5b60006021529392505050565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d15600160005114171661386957637939f4246000526004601cfd5b600060605260405250505050565b60006020828403121561388957600080fd5b5035919050565b6001600160a01b0381168114610b9c57600080fd5b803561334e81613890565b600080604083850312156138c357600080fd5b82356138ce81613890565b946020939093013593505050565b61ffff81168114610b9c57600080fd5b6000806000806000806000806000806101408b8d03121561390c57600080fd5b8a3561391781613890565b995060208b013561392781613890565b985060408b013561393781613890565b975060608b013561394781613890565b965060808b013561395781613890565b955060a08b013561396781613890565b945060c08b013561397781613890565b935060e08b013592506101008b013561398f816138dc565b809250506101208b013590509295989b9194979a5092959850565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff808411156139db576139db6139aa565b604051601f8501601f19908116603f01168101908282118183101715613a0357613a036139aa565b81604052809350858152868686011115613a1c57600080fd5b858560208301376000602087830101525050509392505050565b600082601f830112613a4757600080fd5b610ffa838335602085016139c0565b60008060408385031215613a6957600080fd5b823567ffffffffffffffff811115613a8057600080fd5b613a8c85828601613a36565b9250506020830135613a9d81613890565b809150509250929050565b60008060408385031215613abb57600080fd5b8235613ac681613890565b91506020830135613a9d81613890565b600060208284031215613ae857600080fd5b8135610ffa81613890565b600060208284031215613b0557600080fd5b813567ffffffffffffffff811115613b1c57600080fd5b613b2884828501613a36565b949350505050565b600080600080600080600060e0888a031215613b4b57600080fd5b8735613b5681613890565b96506020880135955060408801359450606088013593506080880135925060a088013567ffffffffffffffff80821115613b8f57600080fd5b613b9b8b838c01613a36565b935060c08a0135915080821115613bb157600080fd5b50613bbe8a828b01613a36565b91505092959891949750929550565b60005b83811015613be8578181015183820152602001613bd0565b50506000910152565b60008151808452613c09816020860160208601613bcd565b601f01601f19169290920160200192915050565b60006101206001600160a01b03808d1684528b60208501528a6040850152816060850152613c4d8285018b613bf1565b64ffffffffff8a16608086015288821660a086015290871660c085015283810360e08501529050613c7e8186613bf1565b9050828103610100840152611a328185613bf1565b81516001600160a01b0316815261016081016020830151613cbf60208401826001600160a01b03169052565b506040830151613cd3604084018215159052565b506060830151613ce9606084018261ffff169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525061014080840151613d3e8285018215159052565b505092915050565b600080600080600080600080610100898b031215613d6357600080fd5b8835613d6e81613890565b97506020890135965060408901359550606089013594506080890135935060a089013567ffffffffffffffff80821115613da757600080fd5b613db38c838d01613a36565b945060c08b0135915080821115613dc957600080fd5b50613dd68b828c01613a36565b92505060e089013590509295985092959890939650565b60008083601f840112613dff57600080fd5b50813567ffffffffffffffff811115613e1757600080fd5b6020830191508360208260051b8501011115613e3257600080fd5b9250929050565b60008060008060408587031215613e4f57600080fd5b843567ffffffffffffffff80821115613e6757600080fd5b613e7388838901613ded565b90965094506020870135915080821115613e8c57600080fd5b50613e9987828801613ded565b95989497509550505050565b60008060408385031215613eb857600080fd5b82359150602083013567ffffffffffffffff811115613ed657600080fd5b8301601f81018513613ee757600080fd5b613ef6858235602084016139c0565b9150509250929050565b60008083601f840112613f1257600080fd5b50813567ffffffffffffffff811115613f2a57600080fd5b602083019150836020828501011115613e3257600080fd5b60008060208385031215613f5557600080fd5b823567ffffffffffffffff811115613f6c57600080fd5b613f7885828601613f00565b90969095509350505050565b600080600080600080600080610100898b031215613fa157600080fd5b613faa896138a5565b97506020890135965060408901359550606089013594506080890135935060a089013567ffffffffffffffff80821115613fe357600080fd5b613fef8c838d01613a36565b945060c08b013591508082111561400557600080fd5b6140118c838d01613a36565b935060e08b013591508082111561402757600080fd5b506140348b828c01613a36565b9150509295985092959890939650565b60006020828403121561405657600080fd5b8135610ffa816138dc565b60008060008060008060a0878903121561407a57600080fd5b863567ffffffffffffffff81111561409157600080fd5b61409d89828a01613f00565b90975095505060208701356140b181613890565b93506040870135925060608701356140c881613890565b80925050608087013590509295509295509295565b600080600080604085870312156140f357600080fd5b843567ffffffffffffffff8082111561410b57600080fd5b61411788838901613f00565b9096509450602087013591508082111561413057600080fd5b50613e9987828801613f00565b8015158114610b9c57600080fd5b6000806040838503121561415e57600080fd5b823561416981613890565b91506020830135613a9d8161413d565b6000825161418b818460208701613bcd565b9190910192915050565b600181811c908216806141a957607f821691505b6020821081036141c957634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156141e157600080fd5b5051919050565b6000602082840312156141fa57600080fd5b8151610ffa816138dc565b60006020828403121561421757600080fd5b8151610ffa81613890565b60006020828403121561423457600080fd5b8151610ffa8161413d565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161427d5761427d614255565b5060010190565b6040808252810184905260008560608301825b878110156142c75782356142aa81613890565b6001600160a01b0316825260209283019290910190600101614297565b5083810360208501528481527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85111561430057600080fd5b8460051b915081866020830137016020019695505050505050565b60008060008060008060c0878903121561433457600080fd5b865195506020870151945060408701519350606087015161435481613890565b60808801519093507fffffffffffffffffffffffffffffffff000000000000000000000000000000008116811461438a57600080fd5b60a088015190925061439b816138dc565b809150509295509295509295565b60006001600160a01b038087168352808616602084015250608060408301526143d56080830185613bf1565b82810360608401526143e78185613bf1565b979650505050505050565b6040815260006144056040830185613bf1565b82810360208401526144178185613bf1565b95945050505050565b8082028115828204841417610bce57610bce614255565b8183823760009101908152919050565b60e081528760e08201526000610100898b828501376000838b018201526001600160a01b0398891660208401526040830197909752509386166060850152608084019290925290931660a082015260c0810192909252601f909201601f19160101919050565b600080600080608085870312156144c357600080fd5b84356144ce81613890565b935060208501356144de81613890565b9250604085013567ffffffffffffffff808211156144fb57600080fd5b61450788838901613a36565b9350606087013591508082111561451d57600080fd5b5061452a87828801613a36565b91505092959194509250565b80820180821115610bce57610bce614255565b602081526000610ffa6020830184613bf1565b60608152600061456f6060830186613bf1565b6001600160a01b039490941660208301525060400152919050565b60c08152600061459d60c0830189613bf1565b6001600160a01b03978816602084015260408301969096525092909416606083015261ffff16608082015260a00191909152919050565b6000826145f157634e487b7160e01b600052601260045260246000fd5b500490565b60e08152600061460960e083018a613bf1565b6001600160a01b0398891660208401526040830197909752509386166060850152608084019290925290931660a082015260c00191909152919050565b601f82111561469057600081815260208120601f850160051c8101602086101561466d5750805b601f850160051c820191505b8181101561468c57828155600101614679565b5050505b505050565b815167ffffffffffffffff8111156146af576146af6139aa565b6146c3816146bd8454614195565b84614646565b602080601f8311600181146146f857600084156146e05750858301515b600019600386901b1c1916600185901b17855561468c565b600085815260208120601f198616915b8281101561472757888601518255948401946001909101908401614708565b50858210156147455787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60006001600160a01b03808a16835288602084015287604084015286606084015285608084015280851660a08401525060e060c083015261479960e0830184613bf1565b9998505050505050505050565b60e0815260006147b960e0830189613bf1565b828103602084015260078152666572633131353560c81b6020820152604081019150506001600160a01b03871660408301528560608301528460808301528360a08301528260c0830152979650505050505050565b60e08152600061482160e083018a613bf1565b60208382038185015260008a5461483781614195565b80855260018281168015614852576001811461486c5761489a565b60ff1984168787015282151560051b87018601945061489a565b8e6000528560002060005b84811015614892578154898201890152908301908701614877565b880187019550505b5050506001600160a01b038b1660408701525092506148b7915050565b8560608301528460808301528360a08301528260c083015298975050505050505050565b60006101406001600160a01b03808e1684528c60208501528b60408501528a60608501528960808501528160a08501526149178285018a613bf1565b61ffff9890981660c085015295861660e0840152505064ffffffffff92909216610100830152909116610120909101529695505050505050565b7f7b22616374696f6e5478486173686573223a5b22000000000000000000000000815260008551614989816014850160208a01613bcd565b7f225d2c22616374696f6e4e6574776f726b436861696e496473223a5b0000000060149184019182015285516149c6816030840160208a01613bcd565b7f5d2c2271756573744e616d65223a220000000000000000000000000000000000603092909101918201528451614a0481603f840160208901613bcd565b7f222c22616374696f6e54797065223a2200000000000000000000000000000000603f92909101918201528351614a4281604f840160208801613bcd565b7f227d000000000000000000000000000000000000000000000000000000000000604f9290910191820152605101969550505050505056fea26469706673582212203ce84486c04e97259962ea5b8a52cb298bf3bdce0cfee042228bf817f3ac714764736f6c63430008130033
Deployed Bytecode
0x6080604052600436106103815760003560e01c806384ae2bc6116101cf578063c6eba76611610101578063e521cb921161009a578063f18cb7841161006c578063f18cb78414610b0c578063f2fde38b14610b2c578063f8565efd14610b3f578063fee81cf414610b5f57005b8063e521cb9214610a74578063ec461ac414610a94578063eddd0d9c14610ad9578063f04e283e14610af957005b8063d4faaa17116100d3578063d4faaa17146109de578063d693e8d3146109fe578063deac34c814610a1e578063e1bc3aba14610a5457005b8063c6eba76614610978578063cc923e0c14610998578063ce53b152146109b8578063d27cae76146109cb57005b8063a1db1ba411610173578063be979d3711610145578063be979d37146108f8578063c03bf91f14610918578063c42fe71814610938578063c476dbcc1461095857005b8063a1db1ba414610885578063a2e44593146108a5578063abab135a146108b8578063b4cbdd8b146108d857005b806393600093116101ac578063936000931461080957806397aba7f91461082f578063994f3bd21461084f5780639b86630d1461086f57005b806384ae2bc6146107b557806387c4d47d146107d05780638da5cb5b146107f057005b80634a4ee7b1116102b3578063715018a61161024c5780637e4176e31161021e5780637e4176e3146107135780637f7c0ef7146107485780637fceecd61461077557806381589b1f1461079557005b8063715018a61461067f57806378077f8d146106875780637afc4469146106a75780637c93f9ee146106f357005b806364df049e1161028557806364df049e146105ee57806367dfa3e71461060e578063695ef19f1461063c57806370dfd40a1461066c57005b80634a4ee7b11461057c578063514e62fc1461058f57806354d1f13d146105c65780635ccb62fc146105ce57005b806327b0655f1161032557806339b5f830116102f757806339b5f830146104fc5780633ef17b171461051c5780633f7c9a881461053c57806343ff27d11461055c57005b806327b0655f1461046957806328d3164d146104895780632de94807146104a957806332f58eb5146104dc57005b80631c10893f1161035e5780631c10893f146103fe5780631cd64df4146104115780631ddc4f3014610441578063256929621461046157005b80630b6fc1631461038a57806313966db5146103c7578063183a4f6e146103eb57005b3661038857005b005b34801561039657600080fd5b5060c9546103aa906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156103d357600080fd5b506103dd60d25481565b6040519081526020016103be565b6103886103f9366004613877565b610b92565b61038861040c3660046138b0565b610b9f565b34801561041d57600080fd5b5061043161042c3660046138b0565b610bb5565b60405190151581526020016103be565b34801561044d57600080fd5b5061038861045c3660046138ec565b610bd4565b610388610dce565b34801561047557600080fd5b50610431610484366004613a56565b610e1e565b34801561049557600080fd5b506103886104a4366004613aa8565b610e62565b3480156104b557600080fd5b506103dd6104c4366004613ad6565b638b78c6d8600c908152600091909152602090205490565b3480156104e857600080fd5b506103886104f7366004613ad6565b610e98565b34801561050857600080fd5b506103aa6105173660046138b0565b610ee9565b34801561052857600080fd5b5060ce546103aa906001600160a01b031681565b34801561054857600080fd5b50610388610557366004613ad6565b610f21565b34801561056857600080fd5b506103dd610577366004613af3565b610f4b565b61038861058a3660046138b0565b610f76565b34801561059b57600080fd5b506104316105aa3660046138b0565b638b78c6d8600c90815260009290925260209091205416151590565b610388610f88565b3480156105da57600080fd5b506103aa6105e9366004613ad6565b610fc4565b3480156105fa57600080fd5b5060ca546103aa906001600160a01b031681565b34801561061a57600080fd5b5060d1546106299061ffff1681565b60405161ffff90911681526020016103be565b34801561064857600080fd5b50610431610657366004613ad6565b60d06020526000908152604090205460ff1681565b6103aa61067a366004613b30565b611001565b6103886110a8565b34801561069357600080fd5b5060cf546103aa906001600160a01b031681565b3480156106b357600080fd5b506106de6106c2366004613ad6565b60d9602052600090815260409020805460019091015460ff1682565b604080519283529015156020830152016103be565b3480156106ff57600080fd5b5061038861070e366004613ad6565b6110bc565b34801561071f57600080fd5b5061073361072e366004613af3565b6110e6565b6040516103be99989796959493929190613c1d565b34801561075457600080fd5b50610768610763366004613af3565b6112fb565b6040516103be9190613c93565b34801561078157600080fd5b506103dd610790366004613ad6565b61189b565b3480156107a157600080fd5b506103aa6107b0366004613d46565b6118e2565b3480156107c157600080fd5b5060da546106299061ffff1681565b3480156107dc57600080fd5b506103886107eb366004613e39565b611a42565b3480156107fc57600080fd5b50638b78c6d819546103aa565b34801561081557600080fd5b5060da546103aa906201000090046001600160a01b031681565b34801561083b57600080fd5b506103aa61084a366004613ea5565b611b3b565b34801561085b57600080fd5b5060d7546103aa906001600160a01b031681565b34801561087b57600080fd5b506103dd60d65481565b34801561089157600080fd5b5060cb546103aa906001600160a01b031681565b6103886108b3366004613f42565b611b75565b3480156108c457600080fd5b506103aa6108d3366004613f84565b611e14565b3480156108e457600080fd5b506103886108f3366004613ad6565b611f46565b34801561090457600080fd5b5060d5546103aa906001600160a01b031681565b34801561092457600080fd5b50610388610933366004613ad6565b611f70565b34801561094457600080fd5b50610388610953366004614044565b611fed565b34801561096457600080fd5b506103dd610973366004613877565b612079565b34801561098457600080fd5b50610388610993366004614061565b61208e565b3480156109a457600080fd5b5060d3546103aa906001600160a01b031681565b6103886109c63660046140dd565b61214b565b6103aa6109d9366004613f84565b6127c2565b3480156109ea57600080fd5b5060cc546103aa906001600160a01b031681565b348015610a0a57600080fd5b50610388610a1936600461414b565b61284c565b348015610a2a57600080fd5b506103aa610a39366004613ad6565b60db602052600090815260409020546001600160a01b031681565b348015610a6057600080fd5b50610388610a6f366004614044565b61287f565b348015610a8057600080fd5b50610388610a8f366004613ad6565b6128df565b348015610aa057600080fd5b50610ab4610aaf366004613af3565b612930565b604080516001600160a01b0390941684526020840192909252908201526060016103be565b348015610ae557600080fd5b50610388610af4366004613877565b61297f565b610388610b07366004613ad6565b6129bc565b348015610b1857600080fd5b50610388610b27366004613877565b6129f9565b610388610b3a366004613ad6565b612a36565b348015610b4b57600080fd5b50610388610b5a366004613ad6565b612a5d565b348015610b6b57600080fd5b506103dd610b7a366004613ad6565b63389a75e1600c908152600091909152602090205490565b610b9c3382612a87565b50565b610ba7612a93565b610bb18282612aae565b5050565b638b78c6d8600c90815260008390526020902054811681145b92915050565b600054610100900460ff1615808015610bf45750600054600160ff909116105b80610c0e5750303b158015610c0e575060005460ff166001145b610c9e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840160405180910390fd5b6000805460ff191660011790558015610cc1576000805461ff0019166101001790555b610cca87612aba565b60d180546107d061ffff1991821617909155600160d45560c980546001600160a01b03199081166001600160a01b038f81169190911790925560ca805482168e841617905560cb805482168d841617905560cc805482168c841617905560d5805490911689831617905560da805460d68890557fffffffffffffffffffff000000000000000000000000000000000000000000001662010000928916929092029092161761ffff851617905560d28290558015610dc1576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050505050505050565b60006202a30067ffffffffffffffff164201905063389a75e1600c5233600052806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a250565b600060cd83604051610e309190614179565b908152604080519182900360209081019092206001600160a01b0385166000908152925290205460ff16905092915050565b610e6a612a93565b6001600160a01b03918216600090815260db6020526040902080546001600160a01b03191691909216179055565b610ea0612a93565b6001600160a01b038116610ec7576040516302154e0360e21b815260040160405180910390fd5b60d380546001600160a01b0319166001600160a01b0392909216919091179055565b60d86020528160005260406000208181548110610f0557600080fd5b6000918252602090912001546001600160a01b03169150829050565b610f29612a93565b60d580546001600160a01b0319166001600160a01b0392909216919091179055565b600060cd82604051610f5d9190614179565b9081526020016040518091039020600301549050919050565b610f7e612a93565b610bb18282612a87565b63389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2565b6001600160a01b03808216600090815260db60205260408120549091168015610fed5780610ffa565b60d3546001600160a01b03165b9392505050565b600060d4546001146110265760405163558a1e0360e11b815260040160405180910390fd5b600260d4819055506110976040518061010001604052808a6001600160a01b0316815260200189815260200188815260200187815260200186815260200185815260200160405180602001604052806000815250815260200160405180602001604052806000815250815250612af6565b600160d45598975050505050505050565b6110b0612a93565b6110ba6000612f40565b565b6110c4612a93565b60cb80546001600160a01b0319166001600160a01b0392909216919091179055565b805160208183018101805160cd8252928201919093012091526001810154600282015460038301546004840180546001600160a01b0390941694929391929161112e90614195565b80601f016020809104026020016040519081016040528092919081815260200182805461115a90614195565b80156111a75780601f1061117c576101008083540402835291602001916111a7565b820191906000526020600020905b81548152906001019060200180831161118a57829003601f168201915b5050505060058301546006840154600785018054949564ffffffffff841695650100000000009094046001600160a01b039081169550909216926111ea90614195565b80601f016020809104026020016040519081016040528092919081815260200182805461121690614195565b80156112635780601f1061123857610100808354040283529160200191611263565b820191906000526020600020905b81548152906001019060200180831161124657829003601f168201915b50505050509080600801805461127890614195565b80601f01602080910402602001604051908101604052809291908181526020018280546112a490614195565b80156112f15780601f106112c6576101008083540402835291602001916112f1565b820191906000526020600020905b8154815290600101906020018083116112d457829003601f168201915b5050505050905089565b61137260405180610160016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600015158152602001600061ffff1681526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b600060cd836040516113849190614179565b9081526020016040518091039020905060008160010160009054906101000a90046001600160a01b03169050600080611471604051806040016040528060078152602001666572633131353560c81b8152508560040180546113e590614195565b80601f016020809104026020016040519081016040528092919081815260200182805461141190614195565b801561145e5780601f106114335761010080835404028352916020019161145e565b820191906000526020600020905b81548152906001019060200180831161144157829003601f168201915b5050505050612f7e90919063ffffffff16565b156114f6578360010160009054906101000a90046001600160a01b03166001600160a01b03166317d70f7c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ef91906141cf565b91506115bf565b826001600160a01b03166369d2dc056040518163ffffffff1660e01b8152600401602060405180830381865afa158015611534573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155891906141cf565b9150826001600160a01b03166367dfa3e76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115bc91906141e8565b90505b604080516101608101825260018601546001600160a01b03908116825282517ff7c618c1000000000000000000000000000000000000000000000000000000008152925160009360208085019389169263f7c618c19260048082019392918290030181865afa158015611636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165a9190614205565b6001600160a01b03168152602001856001600160a01b03166316049ddf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ca9190614222565b151581526020018361ffff168152602001856001600160a01b03166378e979256040518163ffffffff1660e01b8152600401602060405180830381865afa158015611719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173d91906141cf565b8152602001856001600160a01b0316633197cbb66040518163ffffffff1660e01b8152600401602060405180830381865afa158015611780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a491906141cf565b8152602001856001600160a01b031663a26dbf266040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180b91906141cf565b81526020018660030154815260200186600301548152602001848152602001856001600160a01b0316636cb4e6116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611868573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188c9190614222565b15159052979650505050505050565b6001600160a01b038116600090815260d9602052604081206001015460ff166118c65760d654610bce565b506001600160a01b0316600090815260d9602052604090205490565b60008389600060cd836040516118f89190614179565b90815260405190819003602001902060018101549091506001600160a01b0316156119365760405163b2431b6160e01b815260040160405180910390fd5b6001600160a01b038216600090815260d0602052604090205460ff1661196f57604051639f7fdf3160e01b815260040160405180910390fd5b60cb546001600160a01b031661199857604051636d9282ef60e11b815260040160405180910390fd5b611a326040518061014001604052808e6001600160a01b031681526020018d81526020018c81526020018b81526020018a8152602001898152602001604051806020016040528060008152508152602001604051806020016040528060008152508152602001600064ffffffffff16815260200160405180604001604052806005815260200164065726332360dc1b815250815250612f94565b9c9b505050505050505050505050565b611a4a612a93565b60005b83811015611af7576040518060400160405280848484818110611a7257611a7261423f565b9050602002013581526020016001151581525060d96000878785818110611a9b57611a9b61423f565b9050602002016020810190611ab09190613ad6565b6001600160a01b03168152602080820192909252604001600020825181559101516001909101805460ff191691151591909117905580611aef8161426b565b915050611a4d565b507f7412a73f7b9b8b4a2fa22f3cb493a2e3008eb96b92abf7f5b06a18ca796eaa3184848484604051611b2d9493929190614284565b60405180910390a150505050565b6000610ffa611b6f846020527b19457468657265756d205369676e6564204d6573736167653a0a3332600052603c60042090565b83613214565b6000611bb683838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506132be92505050565b905060008060008060008086806020019051810190611bd5919061431b565b9550955095509550955095506000611bec83613353565b9050600060cd82604051611c009190614179565b90815260405190819003602001902090506000611d4b611c1f8a61356c565b611c2c8661ffff16613590565b846007018054611c3b90614195565b80601f0160208091040260200160405190810160405280929190818152602001828054611c6790614195565b8015611cb45780601f10611c8957610100808354040283529160200191611cb4565b820191906000526020600020905b815481529060010190602001808311611c9757829003601f168201915b5050505050856008018054611cc890614195565b80601f0160208091040260200160405190810160405280929190818152602001828054611cf490614195565b8015611d415780601f10611d1657610100808354040283529160200191611d41565b820191906000526020600020905b815481529060010190602001808311611d2457829003601f168201915b50505050506135d5565b9050600033878584604051602001611d6694939291906143a9565b60408051808303601f19018152828252602083018c90528282018b905281518084038301815260608401928390527fce53b152000000000000000000000000000000000000000000000000000000009092529250309163ce53b152913491611dd3919086906064016143f2565b6000604051808303818588803b158015611dec57600080fd5b505af1158015611e00573d6000803e3d6000fd5b505050505050505050505050505050505050565b60008389600060cd83604051611e2a9190614179565b90815260405190819003602001902060018101549091506001600160a01b031615611e685760405163b2431b6160e01b815260040160405180910390fd5b6001600160a01b038216600090815260d0602052604090205460ff16611ea157604051639f7fdf3160e01b815260040160405180910390fd5b60cb546001600160a01b0316611eca57604051636d9282ef60e11b815260040160405180910390fd5b611a326040518061014001604052808e6001600160a01b031681526020018d81526020018c81526020018b81526020018a8152602001898152602001888152602001878152602001600064ffffffffff16815260200160405180604001604052806005815260200164065726332360dc1b815250815250612f94565b611f4e612a93565b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b611f78612a93565b60da80547fffffffffffffffffffff0000000000000000000000000000000000000000ffff16620100006001600160a01b038416908102919091179091556040519081527fca0f60d8c8bcfc3249661e03a4dcd6a0342cd857e0b00968738f82e573722a9b906020015b60405180910390a150565b611ff5612a93565b6127108161ffff161115612035576040517faa6e211200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60da805461ffff191661ffff83169081179091556040519081527fa7bf2cb2b95a425df48655de4071d888fbb2d429d265bb008a4cea1dc8a8954890602001611fe2565b60006120843361189b565b610bce9083614420565b600060cd87876040516120a2929190614437565b9081526040519081900360200190206001810154909150336001600160a01b03909116146120fc576040517f7fa7559100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f8e47afab301dea587ea57f7c95a3fe844a798013dd5c177c2e5575c35b1c73bf87878787878760008060405161213a989796959493929190614447565b60405180910390a150505050505050565b600080808061215c858701876144ad565b9350935093509350600060cd836040516121769190614179565b908152602001604051809103902090506000816003015460016121999190614536565b905060008260010160009054906101000a90046001600160a01b03166001600160a01b031663f7c618c16040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122169190614205565b60c9546040519192506000916001600160a01b03909116906122839061223f908d908d90614437565b60405180910390208e8e8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611b3b92505050565b6001600160a01b0316146122c3576040517f05d0fdda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60d2543410156122ff576040517fc288bf8f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03881660009081526020859052604090205460ff1615612352576040517ff5f915f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8360020154831115612390576040517f571e5b1800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03888116600081815260208790526040808220805460ff1916600190811790915560038901889055880154905160248101939093528a8416604484015290921690349060640160408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f842acd6800000000000000000000000000000000000000000000000000000000179052516124409190614179565b60006040518083038185875af1925050503d806000811461247d576040519150601f19603f3d011682016040523d82523d6000602084013e612482565b606091505b50509050806124bd576040517f360e42e100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018501546040516001600160a01b03918216918b16907f776d31c62981a6d4b846ed3aeace92ca390dcf303bac6d12439917d147c34ae190612501908a90614549565b60405180910390a361253b604051806040016040528060078152602001666572633131353560c81b8152508660040180546113e590614195565b15612612578460010160009054906101000a90046001600160a01b03166001600160a01b03166317d70f7c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612595573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b991906141cf565b60018601546040519193506001600160a01b0390811691908b16907f10301d5d7c155e8a5269fc62b7841a3fd101266acc5768d5df29b6e8d823433190612605908b908890889061455c565b60405180910390a36126e0565b8460010160009054906101000a90046001600160a01b03166001600160a01b03166369d2dc056040518163ffffffff1660e01b8152600401602060405180830381865afa158015612667573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061268b91906141cf565b60018601546040519193506001600160a01b0390811691908b16907fd35f2250d08242f6e4e2bfe3dac8b5887040ea7223991b25a628b415c3265be9906126d7908b908890889061455c565b60405180910390a35b6001600160a01b038816156127b3578460010160009054906101000a90046001600160a01b03166001600160a01b0316896001600160a01b03167f9c503975322622df0e05ce3ba5b99b1eace4b358cc8c0af4ddf1610f9ce58bbc8986868d610d0560d2546040516127579695949392919061458a565b60405180910390a37f8e47afab301dea587ea57f7c95a3fe844a798013dd5c177c2e5575c35b1c73bf876000806000808d600360d25461279791906145d4565b6040516127aa97969594939291906145f6565b60405180910390a15b50505050505050505050505050565b600060d4546001146127e75760405163558a1e0360e11b815260040160405180910390fd5b600260d48190555061283a6040518061010001604052808b6001600160a01b031681526020018a815260200189815260200188815260200187815260200186815260200185815260200184815250612af6565b600160d4559998505050505050505050565b612854612a93565b6001600160a01b0391909116600090815260d060205260409020805460ff1916911515919091179055565b612887612a93565b6127108161ffff1611156128c7576040517f4ae19ab600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60d1805461ffff191661ffff92909216919091179055565b6128e7612a93565b6001600160a01b03811661290e576040516302154e0360e21b815260040160405180910390fd5b60ca80546001600160a01b0319166001600160a01b0392909216919091179055565b60008060008060cd856040516129469190614179565b908152604051908190036020019020600181015460028201546003909201546001600160a01b0390911695509093509150509193909250565b612987612a93565b60d28190556040518181527f97aee230ba41961438e908e115df76fa8113f85a0586d85b19ba5be50e6a227490602001611fe2565b6129c4612a93565b63389a75e1600c52806000526020600c2080544211156129ec57636f5e88186000526004601cfd5b60009055610b9c81612f40565b612a01612a93565b60d68190556040518181527facfc857f5247cf27fd46d9d8774f59e409be9b50fe1412825bec5c648863f03690602001611fe2565b612a3e612a93565b8060601b612a5457637448fbae6000526004601cfd5b610b9c81612f40565b612a65612a93565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b610bb182826000613607565b638b78c6d8195433146110ba576382b429006000526004601cfd5b610bb182826001613607565b6001600160a01b0316638b78c6d8198190558060007f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a350565b60008060cd8360a00151604051612b0d9190614179565b90815260200160405180910390209050612b2a8360600151612079565b341015612b63576040517f97e2b23c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018101546001600160a01b031615612b8f5760405163b2431b6160e01b815260040160405180910390fd5b6040516bffffffffffffffffffffffff193360601b166020820152466034820152426054820152600090612bea9060740160408051601f19818403018152919052805160209091012060cc546001600160a01b031690613660565b6001830180546001600160a01b0319166001600160a01b03831690811790915560608601516002850155909150612c21903461366e565b6040805180820190915260078152666572633131353560c81b60208201526004830190612c4e9082614695565b506005820180547fffffffffffffff0000000000000000000000000000000000000000ffffffffff1633650100000000000217905560c08401516007830190612c979082614695565b5060e08401516008830190612cac9082614695565b50835160208501516040808701516060880151608089015160ca5460a08b015194517feff5c5bd00000000000000000000000000000000000000000000000000000000815288976001600160a01b03808a169863eff5c5bd98612d1e9893979196939591949290911691600401614755565b600060405180830381600087803b158015612d3857600080fd5b505af1158015612d4c573d6000803e3d6000fd5b50508651608088015160608901516040517ff242432a000000000000000000000000000000000000000000000000000000008152336004808301919091526001600160a01b0389811660248401526044830194909452606482019290925260a0608482015260a48101919091527f307830300000000000000000000000000000000000000000000000000000000060c48201529116925063f242432a915060e401600060405180830381600087803b158015612e0757600080fd5b505af1158015612e1b573d6000803e3d6000fd5b50505050806001600160a01b031663e10d29ee6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612e5a57600080fd5b505af1158015612e6e573d6000803e3d6000fd5b505060405163f2fde38b60e01b81523360048201526001600160a01b038416925063f2fde38b9150602401600060405180830381600087803b158015612eb357600080fd5b505af1158015612ec7573d6000803e3d6000fd5b50505050816001600160a01b0316336001600160a01b03167f7ffd904b9426b92270b251e237818b61230a9c7dc857d7e6130dddc21b7619378760a00151886000015189602001518a604001518b606001518c60800151604051612f30969594939291906147a6565b60405180910390a3509392505050565b638b78c6d81980546001600160a01b039092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355565b8051602091820120825192909101919091201490565b60008060cd8360a00151604051612fab9190614179565b90815260405190819003602090810182206bffffffffffffffffffffffff193360601b169183019190915246603483015242605483015291506000906130189060740160408051601f19818403018152919052805160209091012060cb546001600160a01b031690613660565b6001830180546001600160a01b0319166001600160a01b038316179055606085015160028401556005830180546101008701517fffffffffffffff0000000000000000000000000000000000000000000000000090911633650100000000000264ffffffffff19161764ffffffffff90911617905561012085015190915060048301906130a59082614695565b5060c084015160078301906130ba9082614695565b5060e084015160088301906130cf9082614695565b50806001600160a01b0316336001600160a01b03167f7ffd904b9426b92270b251e237818b61230a9c7dc857d7e6130dddc21b7619378660a0015185600401886000015189602001518a604001518b606001518c6080015160405161313a979695949392919061480e565b60405180910390a3835160208501516040808701516060880151608089015160a08a015160d15460ca546101008d015160da5497517fbb7516550000000000000000000000000000000000000000000000000000000081526001600160a01b03808d169b63bb7516559b6131d49b919a9099909890979096909561ffff9091169490831693909262010000909204909116906004016148db565b600060405180830381600087803b1580156131ee57600080fd5b505af1158015613202573d6000803e3d6000fd5b50505050610ffa81856000015161368a565b604051600190836000526020830151604052604083510361326957604083015160ff81901c601b016020527f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660605261328f565b604183510361328a57606083015160001a602052604083015160605261328f565b600091505b6020600160806000855afa5191503d6132b057638baa579f6000526004601cfd5b600060605260405292915050565b606081511561334e5760405190506020810160048301805184518501811983525b80861015613337576001860195508551601f1a80613328576001870196508651601f1a6000198652607f811161331757600181013887395b607f169490940160010193506132df565b808553506001840193506132df565b509052601f19828203018252600081526020016040525b919050565b604080518082018252601081527f30313233343536373839616263646566000000000000000000000000000000006020820152815160248082526060828101909452600091906020820181803683370190505090506000805b60108110156135625780600414806133c45750806006145b806133cf5750806008145b806133da575080600a145b15613435577f2d00000000000000000000000000000000000000000000000000000000000000838361340b8161426b565b94508151811061341d5761341d61423f565b60200101906001600160f81b031916908160001a9053505b83600487836010811061344a5761344a61423f565b1a60f81b6001600160f81b031916901c60f81c60ff16815181106134705761347061423f565b01602001517fff000000000000000000000000000000000000000000000000000000000000001683836134a28161426b565b9450815181106134b4576134b461423f565b60200101906001600160f81b031916908160001a905350838682601081106134de576134de61423f565b825191901a600f169081106134f5576134f561423f565b01602001517fff000000000000000000000000000000000000000000000000000000000000001683836135278161426b565b9450815181106135395761353961423f565b60200101906001600160f81b031916908160001a9053508061355a8161426b565b9150506133ac565b5090949350505050565b60606135778261376e565b8051613078825260020160011990910190815292915050565b60606080604051019050602081016040526000815280600019835b928101926030600a8206018453600a9004806135ab575b5050819003601f19909101908152919050565b6060848483856040516020016135ee9493929190614951565b6040516020818303038152906040529050949350505050565b638b78c6d8600c52826000526020600c20805483811783613629575080841681185b80835580600c5160601c7f715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe26600080a3505050505050565b6000610ffa600084846137c3565b60003860003884865af1610bb15763b12d13eb6000526004601cfd5b6000339050600083905061370d8285836001600160a01b0316633dd4d94f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156136d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136fb91906141cf565b6001600160a01b03871692919061381a565b60405163f2fde38b60e01b81526001600160a01b03838116600483015282169063f2fde38b90602401600060405180830381600087803b15801561375057600080fd5b505af1158015613764573d6000803e3d6000fd5b5050505050505050565b606060806040510190506020810160405260008152806f30313233343536373839616263646566600f52600119835b600f811651938201936001850153600f8160041c1651845360081c80156135c25761379d565b60006c5af43d3d93803e602a57fd5bf36021528260145273602c3d8160093d39f33d3d3d3d363d3d37363d73600052816035600c86f590508061380e5763301164256000526004601cfd5b60006021529392505050565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d15600160005114171661386957637939f4246000526004601cfd5b600060605260405250505050565b60006020828403121561388957600080fd5b5035919050565b6001600160a01b0381168114610b9c57600080fd5b803561334e81613890565b600080604083850312156138c357600080fd5b82356138ce81613890565b946020939093013593505050565b61ffff81168114610b9c57600080fd5b6000806000806000806000806000806101408b8d03121561390c57600080fd5b8a3561391781613890565b995060208b013561392781613890565b985060408b013561393781613890565b975060608b013561394781613890565b965060808b013561395781613890565b955060a08b013561396781613890565b945060c08b013561397781613890565b935060e08b013592506101008b013561398f816138dc565b809250506101208b013590509295989b9194979a5092959850565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff808411156139db576139db6139aa565b604051601f8501601f19908116603f01168101908282118183101715613a0357613a036139aa565b81604052809350858152868686011115613a1c57600080fd5b858560208301376000602087830101525050509392505050565b600082601f830112613a4757600080fd5b610ffa838335602085016139c0565b60008060408385031215613a6957600080fd5b823567ffffffffffffffff811115613a8057600080fd5b613a8c85828601613a36565b9250506020830135613a9d81613890565b809150509250929050565b60008060408385031215613abb57600080fd5b8235613ac681613890565b91506020830135613a9d81613890565b600060208284031215613ae857600080fd5b8135610ffa81613890565b600060208284031215613b0557600080fd5b813567ffffffffffffffff811115613b1c57600080fd5b613b2884828501613a36565b949350505050565b600080600080600080600060e0888a031215613b4b57600080fd5b8735613b5681613890565b96506020880135955060408801359450606088013593506080880135925060a088013567ffffffffffffffff80821115613b8f57600080fd5b613b9b8b838c01613a36565b935060c08a0135915080821115613bb157600080fd5b50613bbe8a828b01613a36565b91505092959891949750929550565b60005b83811015613be8578181015183820152602001613bd0565b50506000910152565b60008151808452613c09816020860160208601613bcd565b601f01601f19169290920160200192915050565b60006101206001600160a01b03808d1684528b60208501528a6040850152816060850152613c4d8285018b613bf1565b64ffffffffff8a16608086015288821660a086015290871660c085015283810360e08501529050613c7e8186613bf1565b9050828103610100840152611a328185613bf1565b81516001600160a01b0316815261016081016020830151613cbf60208401826001600160a01b03169052565b506040830151613cd3604084018215159052565b506060830151613ce9606084018261ffff169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525061014080840151613d3e8285018215159052565b505092915050565b600080600080600080600080610100898b031215613d6357600080fd5b8835613d6e81613890565b97506020890135965060408901359550606089013594506080890135935060a089013567ffffffffffffffff80821115613da757600080fd5b613db38c838d01613a36565b945060c08b0135915080821115613dc957600080fd5b50613dd68b828c01613a36565b92505060e089013590509295985092959890939650565b60008083601f840112613dff57600080fd5b50813567ffffffffffffffff811115613e1757600080fd5b6020830191508360208260051b8501011115613e3257600080fd5b9250929050565b60008060008060408587031215613e4f57600080fd5b843567ffffffffffffffff80821115613e6757600080fd5b613e7388838901613ded565b90965094506020870135915080821115613e8c57600080fd5b50613e9987828801613ded565b95989497509550505050565b60008060408385031215613eb857600080fd5b82359150602083013567ffffffffffffffff811115613ed657600080fd5b8301601f81018513613ee757600080fd5b613ef6858235602084016139c0565b9150509250929050565b60008083601f840112613f1257600080fd5b50813567ffffffffffffffff811115613f2a57600080fd5b602083019150836020828501011115613e3257600080fd5b60008060208385031215613f5557600080fd5b823567ffffffffffffffff811115613f6c57600080fd5b613f7885828601613f00565b90969095509350505050565b600080600080600080600080610100898b031215613fa157600080fd5b613faa896138a5565b97506020890135965060408901359550606089013594506080890135935060a089013567ffffffffffffffff80821115613fe357600080fd5b613fef8c838d01613a36565b945060c08b013591508082111561400557600080fd5b6140118c838d01613a36565b935060e08b013591508082111561402757600080fd5b506140348b828c01613a36565b9150509295985092959890939650565b60006020828403121561405657600080fd5b8135610ffa816138dc565b60008060008060008060a0878903121561407a57600080fd5b863567ffffffffffffffff81111561409157600080fd5b61409d89828a01613f00565b90975095505060208701356140b181613890565b93506040870135925060608701356140c881613890565b80925050608087013590509295509295509295565b600080600080604085870312156140f357600080fd5b843567ffffffffffffffff8082111561410b57600080fd5b61411788838901613f00565b9096509450602087013591508082111561413057600080fd5b50613e9987828801613f00565b8015158114610b9c57600080fd5b6000806040838503121561415e57600080fd5b823561416981613890565b91506020830135613a9d8161413d565b6000825161418b818460208701613bcd565b9190910192915050565b600181811c908216806141a957607f821691505b6020821081036141c957634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156141e157600080fd5b5051919050565b6000602082840312156141fa57600080fd5b8151610ffa816138dc565b60006020828403121561421757600080fd5b8151610ffa81613890565b60006020828403121561423457600080fd5b8151610ffa8161413d565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161427d5761427d614255565b5060010190565b6040808252810184905260008560608301825b878110156142c75782356142aa81613890565b6001600160a01b0316825260209283019290910190600101614297565b5083810360208501528481527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85111561430057600080fd5b8460051b915081866020830137016020019695505050505050565b60008060008060008060c0878903121561433457600080fd5b865195506020870151945060408701519350606087015161435481613890565b60808801519093507fffffffffffffffffffffffffffffffff000000000000000000000000000000008116811461438a57600080fd5b60a088015190925061439b816138dc565b809150509295509295509295565b60006001600160a01b038087168352808616602084015250608060408301526143d56080830185613bf1565b82810360608401526143e78185613bf1565b979650505050505050565b6040815260006144056040830185613bf1565b82810360208401526144178185613bf1565b95945050505050565b8082028115828204841417610bce57610bce614255565b8183823760009101908152919050565b60e081528760e08201526000610100898b828501376000838b018201526001600160a01b0398891660208401526040830197909752509386166060850152608084019290925290931660a082015260c0810192909252601f909201601f19160101919050565b600080600080608085870312156144c357600080fd5b84356144ce81613890565b935060208501356144de81613890565b9250604085013567ffffffffffffffff808211156144fb57600080fd5b61450788838901613a36565b9350606087013591508082111561451d57600080fd5b5061452a87828801613a36565b91505092959194509250565b80820180821115610bce57610bce614255565b602081526000610ffa6020830184613bf1565b60608152600061456f6060830186613bf1565b6001600160a01b039490941660208301525060400152919050565b60c08152600061459d60c0830189613bf1565b6001600160a01b03978816602084015260408301969096525092909416606083015261ffff16608082015260a00191909152919050565b6000826145f157634e487b7160e01b600052601260045260246000fd5b500490565b60e08152600061460960e083018a613bf1565b6001600160a01b0398891660208401526040830197909752509386166060850152608084019290925290931660a082015260c00191909152919050565b601f82111561469057600081815260208120601f850160051c8101602086101561466d5750805b601f850160051c820191505b8181101561468c57828155600101614679565b5050505b505050565b815167ffffffffffffffff8111156146af576146af6139aa565b6146c3816146bd8454614195565b84614646565b602080601f8311600181146146f857600084156146e05750858301515b600019600386901b1c1916600185901b17855561468c565b600085815260208120601f198616915b8281101561472757888601518255948401946001909101908401614708565b50858210156147455787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60006001600160a01b03808a16835288602084015287604084015286606084015285608084015280851660a08401525060e060c083015261479960e0830184613bf1565b9998505050505050505050565b60e0815260006147b960e0830189613bf1565b828103602084015260078152666572633131353560c81b6020820152604081019150506001600160a01b03871660408301528560608301528460808301528360a08301528260c0830152979650505050505050565b60e08152600061482160e083018a613bf1565b60208382038185015260008a5461483781614195565b80855260018281168015614852576001811461486c5761489a565b60ff1984168787015282151560051b87018601945061489a565b8e6000528560002060005b84811015614892578154898201890152908301908701614877565b880187019550505b5050506001600160a01b038b1660408701525092506148b7915050565b8560608301528460808301528360a08301528260c083015298975050505050505050565b60006101406001600160a01b03808e1684528c60208501528b60408501528a60608501528960808501528160a08501526149178285018a613bf1565b61ffff9890981660c085015295861660e0840152505064ffffffffff92909216610100830152909116610120909101529695505050505050565b7f7b22616374696f6e5478486173686573223a5b22000000000000000000000000815260008551614989816014850160208a01613bcd565b7f225d2c22616374696f6e4e6574776f726b436861696e496473223a5b0000000060149184019182015285516149c6816030840160208a01613bcd565b7f5d2c2271756573744e616d65223a220000000000000000000000000000000000603092909101918201528451614a0481603f840160208901613bcd565b7f222c22616374696f6e54797065223a2200000000000000000000000000000000603f92909101918201528351614a4281604f840160208801613bcd565b7f227d000000000000000000000000000000000000000000000000000000000000604f9290910191820152605101969550505050505056fea26469706673582212203ce84486c04e97259962ea5b8a52cb298bf3bdce0cfee042228bf817f3ac714764736f6c63430008130033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
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.