Source Code
Overview
ETH Balance
0 ETH
Token Holdings
More Info
ContractCreator
Multichain Info
N/A
Latest 25 from a total of 345,212 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Cancel Upkeep | 7155428 | 16 days ago | IN | 0 ETH | 0.00105561 | ||||
Migrate Upkeeps | 6600835 | 104 days ago | IN | 0 ETH | 0.01398717 | ||||
Migrate Upkeeps | 6429014 | 131 days ago | IN | 0 ETH | 0.00641101 | ||||
Cancel Upkeep | 6415271 | 133 days ago | IN | 0 ETH | 0.00125457 | ||||
Cancel Upkeep | 6415269 | 133 days ago | IN | 0 ETH | 0.00133372 | ||||
Cancel Upkeep | 6415262 | 133 days ago | IN | 0 ETH | 0.00185635 | ||||
Migrate Upkeeps | 6360387 | 142 days ago | IN | 0 ETH | 0.00069576 | ||||
Migrate Upkeeps | 6334139 | 147 days ago | IN | 0 ETH | 0.01792367 | ||||
Cancel Upkeep | 6138248 | 176 days ago | IN | 0 ETH | 0.0000904 | ||||
Migrate Upkeeps | 6043536 | 190 days ago | IN | 0 ETH | 0.09713625 | ||||
Cancel Upkeep | 6013616 | 195 days ago | IN | 0 ETH | 0.00057509 | ||||
Pause | 5995126 | 198 days ago | IN | 0 ETH | 0.0003838 | ||||
Cancel Upkeep | 5976846 | 201 days ago | IN | 0 ETH | 0.0000905 | ||||
Migrate Upkeeps | 5946719 | 205 days ago | IN | 0 ETH | 0.05951218 | ||||
Migrate Upkeeps | 5907104 | 211 days ago | IN | 0 ETH | 0.0287247 | ||||
Withdraw Funds | 5835908 | 222 days ago | IN | 0 ETH | 0.00094811 | ||||
Withdraw Funds | 5835906 | 222 days ago | IN | 0 ETH | 0.00098954 | ||||
Withdraw Funds | 5835238 | 222 days ago | IN | 0 ETH | 0.00068307 | ||||
Cancel Upkeep | 5835186 | 222 days ago | IN | 0 ETH | 0.00080335 | ||||
Withdraw Funds | 5835181 | 222 days ago | IN | 0 ETH | 0.00083222 | ||||
Cancel Upkeep | 5815101 | 225 days ago | IN | 0 ETH | 0.00021744 | ||||
Transmit | 5809149 | 226 days ago | IN | 0 ETH | 0.00062979 | ||||
Transmit | 5808844 | 226 days ago | IN | 0 ETH | 0.00126233 | ||||
Transmit | 5805504 | 226 days ago | IN | 0 ETH | 0.00020234 | ||||
Transmit | 5805482 | 226 days ago | IN | 0 ETH | 0.00022686 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
KeeperRegistry2_0
Compiler Version
v0.8.6+commit.11564f7e
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/proxy/Proxy.sol"; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol"; import "./KeeperRegistryBase2_0.sol"; import {KeeperRegistryExecutableInterface, UpkeepInfo} from "../interfaces/KeeperRegistryInterface2_0.sol"; import "../interfaces/MigratableKeeperRegistryInterface.sol"; import "../interfaces/ERC677ReceiverInterface.sol"; import "../OCR2Abstract.sol"; /** _. _|_ _ ._ _ _._|_o _ ._ o _ _ ._ _| _ __|_o._ (_||_||_(_)| | |(_| |_|(_)| | |_> (_)|_|| (_|(/__> |_|| |\/ / */ /** * @notice Registry for adding work for Chainlink Keepers to perform on client * contracts. Clients must support the Upkeep interface. */ contract KeeperRegistry2_0 is KeeperRegistryBase2_0, Proxy, OCR2Abstract, KeeperRegistryExecutableInterface, MigratableKeeperRegistryInterface, ERC677ReceiverInterface { using Address for address; using EnumerableSet for EnumerableSet.UintSet; // Immutable address of logic contract where some functionality is delegated to address private immutable i_keeperRegistryLogic; /** * @notice versions: * - KeeperRegistry 2.0.0: implement OCR interface * - KeeperRegistry 1.3.0: split contract into Proxy and Logic * : account for Arbitrum and Optimism L1 gas fee * : allow users to configure upkeeps * - KeeperRegistry 1.2.0: allow funding within performUpkeep * : allow configurable registry maxPerformGas * : add function to let admin change upkeep gas limit * : add minUpkeepSpend requirement * : upgrade to solidity v0.8 * - KeeperRegistry 1.1.0: added flatFeeMicroLink * - KeeperRegistry 1.0.0: initial release */ string public constant override typeAndVersion = "KeeperRegistry 2.0.0"; /** * @inheritdoc MigratableKeeperRegistryInterface */ UpkeepFormat public constant override upkeepTranscoderVersion = UPKEEP_TRANSCODER_VERSION_BASE; /** * @param keeperRegistryLogic address of the logic contract */ constructor(KeeperRegistryBase2_0 keeperRegistryLogic) KeeperRegistryBase2_0( keeperRegistryLogic.getPaymentModel(), keeperRegistryLogic.getLinkAddress(), keeperRegistryLogic.getLinkNativeFeedAddress(), keeperRegistryLogic.getFastGasFeedAddress() ) { i_keeperRegistryLogic = address(keeperRegistryLogic); } //////// // ACTIONS //////// /** * @dev This struct is used to maintain run time information about an upkeep in transmit function * @member upkeep the upkeep struct * @member earlyChecksPassed whether the upkeep passed early checks before perform * @member paymentParams the paymentParams for this upkeep * @member performSuccess whether the perform was successful * @member gasUsed gasUsed by this upkeep in perform */ struct UpkeepTransmitInfo { Upkeep upkeep; bool earlyChecksPassed; uint96 maxLinkPayment; bool performSuccess; uint256 gasUsed; uint256 gasOverhead; } /** * @inheritdoc OCR2Abstract */ function transmit( bytes32[3] calldata reportContext, bytes calldata rawReport, bytes32[] calldata rs, bytes32[] calldata ss, bytes32 rawVs ) external override { uint256 gasOverhead = gasleft(); HotVars memory hotVars = s_hotVars; if (hotVars.paused) revert RegistryPaused(); if (!s_transmitters[msg.sender].active) revert OnlyActiveTransmitters(); Report memory report = _decodeReport(rawReport); UpkeepTransmitInfo[] memory upkeepTransmitInfo = new UpkeepTransmitInfo[](report.upkeepIds.length); uint16 numUpkeepsPassedChecks; for (uint256 i = 0; i < report.upkeepIds.length; i++) { upkeepTransmitInfo[i].upkeep = s_upkeep[report.upkeepIds[i]]; upkeepTransmitInfo[i].maxLinkPayment = _getMaxLinkPayment( hotVars, upkeepTransmitInfo[i].upkeep.executeGas, uint32(report.wrappedPerformDatas[i].performData.length), report.fastGasWei, report.linkNative, true ); upkeepTransmitInfo[i].earlyChecksPassed = _prePerformChecks( report.upkeepIds[i], report.wrappedPerformDatas[i], upkeepTransmitInfo[i].upkeep, upkeepTransmitInfo[i].maxLinkPayment ); if (upkeepTransmitInfo[i].earlyChecksPassed) { numUpkeepsPassedChecks += 1; } } // No upkeeps to be performed in this report if (numUpkeepsPassedChecks == 0) revert StaleReport(); // Verify signatures if (s_latestConfigDigest != reportContext[0]) revert ConfigDigestMismatch(); if (rs.length != hotVars.f + 1 || rs.length != ss.length) revert IncorrectNumberOfSignatures(); _verifyReportSignature(reportContext, rawReport, rs, ss, rawVs); // Actually perform upkeeps for (uint256 i = 0; i < report.upkeepIds.length; i++) { if (upkeepTransmitInfo[i].earlyChecksPassed) { // Check if this upkeep was already performed in this report if (s_upkeep[report.upkeepIds[i]].lastPerformBlockNumber == uint32(block.number)) { revert InvalidReport(); } // Actually perform the target upkeep (upkeepTransmitInfo[i].performSuccess, upkeepTransmitInfo[i].gasUsed) = _performUpkeep( upkeepTransmitInfo[i].upkeep, report.wrappedPerformDatas[i].performData ); // Deduct that gasUsed by upkeep from our running counter gasOverhead -= upkeepTransmitInfo[i].gasUsed; // Store last perform block number for upkeep s_upkeep[report.upkeepIds[i]].lastPerformBlockNumber = uint32(block.number); } } // This is the overall gas overhead that will be split across performed upkeeps // Take upper bound of 16 gas per callData bytes, which is approximated to be reportLength // Rest of msg.data is accounted for in accounting overheads gasOverhead = (gasOverhead - gasleft() + 16 * rawReport.length) + ACCOUNTING_FIXED_GAS_OVERHEAD + (ACCOUNTING_PER_SIGNER_GAS_OVERHEAD * (hotVars.f + 1)); gasOverhead = gasOverhead / numUpkeepsPassedChecks + ACCOUNTING_PER_UPKEEP_GAS_OVERHEAD; uint96 totalReimbursement; uint96 totalPremium; { uint96 reimbursement; uint96 premium; for (uint256 i = 0; i < report.upkeepIds.length; i++) { if (upkeepTransmitInfo[i].earlyChecksPassed) { upkeepTransmitInfo[i].gasOverhead = _getCappedGasOverhead( gasOverhead, uint32(report.wrappedPerformDatas[i].performData.length), hotVars.f ); (reimbursement, premium) = _postPerformPayment( hotVars, report.upkeepIds[i], upkeepTransmitInfo[i], report.fastGasWei, report.linkNative, numUpkeepsPassedChecks ); totalPremium += premium; totalReimbursement += reimbursement; emit UpkeepPerformed( report.upkeepIds[i], upkeepTransmitInfo[i].performSuccess, report.wrappedPerformDatas[i].checkBlockNumber, upkeepTransmitInfo[i].gasUsed, upkeepTransmitInfo[i].gasOverhead, reimbursement + premium ); } } } // record payments s_transmitters[msg.sender].balance += totalReimbursement; s_hotVars.totalPremium += totalPremium; uint40 epochAndRound = uint40(uint256(reportContext[1])); uint32 epoch = uint32(epochAndRound >> 8); if (epoch > hotVars.latestEpoch) { s_hotVars.latestEpoch = epoch; } } /** * @notice simulates the upkeep with the perform data returned from * checkUpkeep * @param id identifier of the upkeep to execute the data with. * @param performData calldata parameter to be passed to the target upkeep. */ function simulatePerformUpkeep(uint256 id, bytes calldata performData) external cannotExecute returns (bool success, uint256 gasUsed) { if (s_hotVars.paused) revert RegistryPaused(); Upkeep memory upkeep = s_upkeep[id]; return _performUpkeep(upkeep, performData); } /** * @notice uses LINK's transferAndCall to LINK and add funding to an upkeep * @dev safe to cast uint256 to uint96 as total LINK supply is under UINT96MAX * @param sender the account which transferred the funds * @param amount number of LINK transfer */ function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external override { if (msg.sender != address(i_link)) revert OnlyCallableByLINKToken(); if (data.length != 32) revert InvalidDataLength(); uint256 id = abi.decode(data, (uint256)); if (s_upkeep[id].maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); s_upkeep[id].balance = s_upkeep[id].balance + uint96(amount); s_expectedLinkBalance = s_expectedLinkBalance + amount; emit FundsAdded(id, sender, uint96(amount)); } //////// // SETTERS //////// /** * @inheritdoc OCR2Abstract */ function setConfig( address[] memory signers, address[] memory transmitters, uint8 f, bytes memory onchainConfig, uint64 offchainConfigVersion, bytes memory offchainConfig ) external override onlyOwner { if (signers.length > maxNumOracles) revert TooManyOracles(); if (f == 0) revert IncorrectNumberOfFaultyOracles(); if (signers.length != transmitters.length || signers.length <= 3 * f) revert IncorrectNumberOfSigners(); // move all pooled payments out of the pool to each transmitter's balance uint96 totalPremium = s_hotVars.totalPremium; uint96 oldLength = uint96(s_transmittersList.length); for (uint256 i = 0; i < oldLength; i++) { _updateTransmitterBalanceFromPool(s_transmittersList[i], totalPremium, oldLength); } // remove any old signer/transmitter addresses address signerAddress; address transmitterAddress; for (uint256 i = 0; i < oldLength; i++) { signerAddress = s_signersList[i]; transmitterAddress = s_transmittersList[i]; delete s_signers[signerAddress]; // Do not delete the whole transmitter struct as it has balance information stored s_transmitters[transmitterAddress].active = false; } delete s_signersList; delete s_transmittersList; // add new signer/transmitter addresses { Transmitter memory transmitter; address temp; for (uint256 i = 0; i < signers.length; i++) { if (s_signers[signers[i]].active) revert RepeatedSigner(); s_signers[signers[i]] = Signer({active: true, index: uint8(i)}); temp = transmitters[i]; transmitter = s_transmitters[temp]; if (transmitter.active) revert RepeatedTransmitter(); transmitter.active = true; transmitter.index = uint8(i); transmitter.lastCollected = totalPremium; s_transmitters[temp] = transmitter; } } s_signersList = signers; s_transmittersList = transmitters; // Set the onchain config OnchainConfig memory onchainConfigStruct = abi.decode(onchainConfig, (OnchainConfig)); if (onchainConfigStruct.maxPerformGas < s_storage.maxPerformGas) revert GasLimitCanOnlyIncrease(); if (onchainConfigStruct.maxCheckDataSize < s_storage.maxCheckDataSize) revert MaxCheckDataSizeCanOnlyIncrease(); if (onchainConfigStruct.maxPerformDataSize < s_storage.maxPerformDataSize) revert MaxPerformDataSizeCanOnlyIncrease(); s_hotVars = HotVars({ f: f, paymentPremiumPPB: onchainConfigStruct.paymentPremiumPPB, flatFeeMicroLink: onchainConfigStruct.flatFeeMicroLink, stalenessSeconds: onchainConfigStruct.stalenessSeconds, gasCeilingMultiplier: onchainConfigStruct.gasCeilingMultiplier, paused: false, reentrancyGuard: false, totalPremium: totalPremium, latestEpoch: 0 }); s_storage = Storage({ checkGasLimit: onchainConfigStruct.checkGasLimit, minUpkeepSpend: onchainConfigStruct.minUpkeepSpend, maxPerformGas: onchainConfigStruct.maxPerformGas, transcoder: onchainConfigStruct.transcoder, registrar: onchainConfigStruct.registrar, maxCheckDataSize: onchainConfigStruct.maxCheckDataSize, maxPerformDataSize: onchainConfigStruct.maxPerformDataSize, nonce: s_storage.nonce, configCount: s_storage.configCount, latestConfigBlockNumber: s_storage.latestConfigBlockNumber, ownerLinkBalance: s_storage.ownerLinkBalance }); s_fallbackGasPrice = onchainConfigStruct.fallbackGasPrice; s_fallbackLinkPrice = onchainConfigStruct.fallbackLinkPrice; uint32 previousConfigBlockNumber = s_storage.latestConfigBlockNumber; s_storage.latestConfigBlockNumber = uint32(block.number); s_storage.configCount += 1; s_latestConfigDigest = _configDigestFromConfigData( block.chainid, address(this), s_storage.configCount, signers, transmitters, f, onchainConfig, offchainConfigVersion, offchainConfig ); emit ConfigSet( previousConfigBlockNumber, s_latestConfigDigest, s_storage.configCount, signers, transmitters, f, onchainConfig, offchainConfigVersion, offchainConfig ); } //////// // GETTERS //////// /** * @notice read all of the details about an upkeep */ function getUpkeep(uint256 id) external view override returns (UpkeepInfo memory upkeepInfo) { Upkeep memory reg = s_upkeep[id]; upkeepInfo = UpkeepInfo({ target: reg.target, executeGas: reg.executeGas, checkData: s_checkData[id], balance: reg.balance, admin: s_upkeepAdmin[id], maxValidBlocknumber: reg.maxValidBlocknumber, lastPerformBlockNumber: reg.lastPerformBlockNumber, amountSpent: reg.amountSpent, paused: reg.paused, offchainConfig: s_upkeepOffchainConfig[id] }); return upkeepInfo; } /** * @notice retrieve active upkeep IDs. Active upkeep is defined as an upkeep which is not paused and not canceled. * @param startIndex starting index in list * @param maxCount max count to retrieve (0 = unlimited) * @dev the order of IDs in the list is **not guaranteed**, therefore, if making successive calls, one * should consider keeping the blockheight constant to ensure a holistic picture of the contract state */ function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view override returns (uint256[] memory) { uint256 maxIdx = s_upkeepIDs.length(); if (startIndex >= maxIdx) revert IndexOutOfRange(); if (maxCount == 0) { maxCount = maxIdx - startIndex; } uint256[] memory ids = new uint256[](maxCount); for (uint256 idx = 0; idx < maxCount; idx++) { ids[idx] = s_upkeepIDs.at(startIndex + idx); } return ids; } /** * @notice read the current info about any transmitter address */ function getTransmitterInfo(address query) external view override returns ( bool active, uint8 index, uint96 balance, uint96 lastCollected, address payee ) { Transmitter memory transmitter = s_transmitters[query]; uint96 totalDifference = s_hotVars.totalPremium - transmitter.lastCollected; uint96 pooledShare = totalDifference / uint96(s_transmittersList.length); return ( transmitter.active, transmitter.index, (transmitter.balance + pooledShare), transmitter.lastCollected, s_transmitterPayees[query] ); } /** * @notice read the current info about any signer address */ function getSignerInfo(address query) external view returns (bool active, uint8 index) { Signer memory signer = s_signers[query]; return (signer.active, signer.index); } /** * @notice read the current state of the registry */ function getState() external view override returns ( State memory state, OnchainConfig memory config, address[] memory signers, address[] memory transmitters, uint8 f ) { state = State({ nonce: s_storage.nonce, ownerLinkBalance: s_storage.ownerLinkBalance, expectedLinkBalance: s_expectedLinkBalance, totalPremium: s_hotVars.totalPremium, numUpkeeps: s_upkeepIDs.length(), configCount: s_storage.configCount, latestConfigBlockNumber: s_storage.latestConfigBlockNumber, latestConfigDigest: s_latestConfigDigest, latestEpoch: s_hotVars.latestEpoch, paused: s_hotVars.paused }); config = OnchainConfig({ paymentPremiumPPB: s_hotVars.paymentPremiumPPB, flatFeeMicroLink: s_hotVars.flatFeeMicroLink, checkGasLimit: s_storage.checkGasLimit, stalenessSeconds: s_hotVars.stalenessSeconds, gasCeilingMultiplier: s_hotVars.gasCeilingMultiplier, minUpkeepSpend: s_storage.minUpkeepSpend, maxPerformGas: s_storage.maxPerformGas, maxCheckDataSize: s_storage.maxCheckDataSize, maxPerformDataSize: s_storage.maxPerformDataSize, fallbackGasPrice: s_fallbackGasPrice, fallbackLinkPrice: s_fallbackLinkPrice, transcoder: s_storage.transcoder, registrar: s_storage.registrar }); return (state, config, s_signersList, s_transmittersList, s_hotVars.f); } /** * @notice calculates the minimum balance required for an upkeep to remain eligible * @param id the upkeep id to calculate minimum balance for */ function getMinBalanceForUpkeep(uint256 id) external view returns (uint96 minBalance) { return getMaxPaymentForGas(s_upkeep[id].executeGas); } /** * @notice calculates the maximum payment for a given gas limit * @param gasLimit the gas to calculate payment for */ function getMaxPaymentForGas(uint32 gasLimit) public view returns (uint96 maxPayment) { HotVars memory hotVars = s_hotVars; (uint256 fastGasWei, uint256 linkNative) = _getFeedData(hotVars); return _getMaxLinkPayment(hotVars, gasLimit, s_storage.maxPerformDataSize, fastGasWei, linkNative, false); } /** * @notice retrieves the migration permission for a peer registry */ function getPeerRegistryMigrationPermission(address peer) external view returns (MigrationPermission) { return s_peerRegistryMigrationPermission[peer]; } /** * @notice retrieves the address of the logic address */ function getKeeperRegistryLogicAddress() external view returns (address) { return i_keeperRegistryLogic; } /** * @inheritdoc OCR2Abstract */ function latestConfigDetails() external view override returns ( uint32 configCount, uint32 blockNumber, bytes32 configDigest ) { return (s_storage.configCount, s_storage.latestConfigBlockNumber, s_latestConfigDigest); } /** * @inheritdoc OCR2Abstract */ function latestConfigDigestAndEpoch() external view override returns ( bool scanLogs, bytes32 configDigest, uint32 epoch ) { return (false, s_latestConfigDigest, s_hotVars.latestEpoch); } //////// // INTERNAL FUNCTIONS //////// /** * @dev This is the address to which proxy functions are delegated to */ function _implementation() internal view override returns (address) { return i_keeperRegistryLogic; } /** * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available */ function _callWithExactGas( uint256 gasAmount, address target, bytes memory data ) private returns (bool success) { assembly { let g := gas() // Compute g -= PERFORM_GAS_CUSHION and check for underflow if lt(g, PERFORM_GAS_CUSHION) { revert(0, 0) } g := sub(g, PERFORM_GAS_CUSHION) // if g - g//64 <= gasAmount, revert // (we subtract g//64 because of EIP-150) if iszero(gt(sub(g, div(g, 64)), gasAmount)) { revert(0, 0) } // solidity calls check that a contract actually exists at the destination, so we do the same if iszero(extcodesize(target)) { revert(0, 0) } // call and return whether we succeeded. ignore return data success := call(gasAmount, target, 0, add(data, 0x20), mload(data), 0, 0) } return success; } /** * @dev _decodeReport decodes a serialized report into a Report struct */ function _decodeReport(bytes memory rawReport) internal pure returns (Report memory) { ( uint256 fastGasWei, uint256 linkNative, uint256[] memory upkeepIds, PerformDataWrapper[] memory wrappedPerformDatas ) = abi.decode(rawReport, (uint256, uint256, uint256[], PerformDataWrapper[])); if (upkeepIds.length != wrappedPerformDatas.length) revert InvalidReport(); return Report({ fastGasWei: fastGasWei, linkNative: linkNative, upkeepIds: upkeepIds, wrappedPerformDatas: wrappedPerformDatas }); } /** * @dev Does some early sanity checks before actually performing an upkeep */ function _prePerformChecks( uint256 upkeepId, PerformDataWrapper memory wrappedPerformData, Upkeep memory upkeep, uint96 maxLinkPayment ) internal returns (bool) { if (wrappedPerformData.checkBlockNumber < upkeep.lastPerformBlockNumber) { // Can happen when another report performed this upkeep after this report was generated emit StaleUpkeepReport(upkeepId); return false; } if (blockhash(wrappedPerformData.checkBlockNumber) != wrappedPerformData.checkBlockhash) { // Can happen when the block on which report was generated got reorged // We will also revert if checkBlockNumber is older than 256 blocks. In this case we rely on a new transmission // with the latest checkBlockNumber emit ReorgedUpkeepReport(upkeepId); return false; } if (upkeep.maxValidBlocknumber <= block.number) { // Can happen when an upkeep got cancelled after report was generated. // However we have a CANCELLATION_DELAY of 50 blocks so shouldn't happen in practice emit CancelledUpkeepReport(upkeepId); return false; } if (upkeep.balance < maxLinkPayment) { // Can happen due to flucutations in gas / link prices emit InsufficientFundsUpkeepReport(upkeepId); return false; } return true; } /** * @dev Verify signatures attached to report */ function _verifyReportSignature( bytes32[3] calldata reportContext, bytes calldata report, bytes32[] calldata rs, bytes32[] calldata ss, bytes32 rawVs ) internal view { bytes32 h = keccak256(abi.encode(keccak256(report), reportContext)); // i-th byte counts number of sigs made by i-th signer uint256 signedCount = 0; Signer memory signer; address signerAddress; for (uint256 i = 0; i < rs.length; i++) { signerAddress = ecrecover(h, uint8(rawVs[i]) + 27, rs[i], ss[i]); signer = s_signers[signerAddress]; if (!signer.active) revert OnlyActiveSigners(); unchecked { signedCount += 1 << (8 * signer.index); } } if (signedCount & ORACLE_MASK != signedCount) revert DuplicateSigners(); } /** * @dev calls the Upkeep target with the performData param passed in by the * transmitter and the exact gas required by the Upkeep */ function _performUpkeep(Upkeep memory upkeep, bytes memory performData) private nonReentrant returns (bool success, uint256 gasUsed) { gasUsed = gasleft(); bytes memory callData = abi.encodeWithSelector(PERFORM_SELECTOR, performData); success = _callWithExactGas(upkeep.executeGas, upkeep.target, callData); gasUsed = gasUsed - gasleft(); return (success, gasUsed); } /** * @dev does postPerform payment processing for an upkeep. Deducts upkeep's balance and increases * amount spent. */ function _postPerformPayment( HotVars memory hotVars, uint256 upkeepId, UpkeepTransmitInfo memory upkeepTransmitInfo, uint256 fastGasWei, uint256 linkNative, uint16 numBatchedUpkeeps ) internal returns (uint96 gasReimbursement, uint96 premium) { (gasReimbursement, premium) = _calculatePaymentAmount( hotVars, upkeepTransmitInfo.gasUsed, upkeepTransmitInfo.gasOverhead, fastGasWei, linkNative, numBatchedUpkeeps, true ); uint96 payment = gasReimbursement + premium; s_upkeep[upkeepId].balance -= payment; s_upkeep[upkeepId].amountSpent += payment; return (gasReimbursement, premium); } /** * @dev Caps the gas overhead by the constant overhead used within initial payment checks in order to * prevent a revert in payment processing. */ function _getCappedGasOverhead( uint256 calculatedGasOverhead, uint32 performDataLength, uint8 f ) private pure returns (uint256 cappedGasOverhead) { cappedGasOverhead = _getMaxGasOverhead(performDataLength, f); if (calculatedGasOverhead < cappedGasOverhead) { return calculatedGasOverhead; } return cappedGasOverhead; } //////// // PROXY FUNCTIONS - EXECUTED THROUGH FALLBACK //////// /** * @notice adds a new upkeep * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep */ function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData, bytes calldata offchainConfig ) external override returns (uint256 id) { // Executed through logic contract _fallback(); } /** * @notice simulated by keepers via eth_call to see if the upkeep needs to be * performed. It returns the success status / failure reason along with the perform data payload. * @param id identifier of the upkeep to check */ function checkUpkeep(uint256 id) external override cannotExecute returns ( bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed, uint256 fastGasWei, uint256 linkNative ) { // Executed through logic contract _fallback(); } /** * @notice prevent an upkeep from being performed in the future * @param id upkeep to be canceled */ function cancelUpkeep(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @notice pause an upkeep * @param id upkeep to be paused */ function pauseUpkeep(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @notice unpause an upkeep * @param id upkeep to be resumed */ function unpauseUpkeep(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @notice update the check data of an upkeep * @param id the id of the upkeep whose check data needs to be updated * @param newCheckData the new check data */ function updateCheckData(uint256 id, bytes calldata newCheckData) external override { // Executed through logic contract _fallback(); } /** * @notice adds LINK funding for an upkeep by transferring from the sender's * LINK balance * @param id upkeep to fund * @param amount number of LINK to transfer */ function addFunds(uint256 id, uint96 amount) external override { // Executed through logic contract _fallback(); } /** * @notice removes funding from a canceled upkeep * @param id upkeep to withdraw funds from * @param to destination address for sending remaining funds */ function withdrawFunds(uint256 id, address to) external { // Executed through logic contract // Restricted to nonRentrant in logic contract as this is not callable from a user's performUpkeep _fallback(); } /** * @notice allows the admin of an upkeep to modify gas limit * @param id upkeep to be change the gas limit for * @param gasLimit new gas limit for the upkeep */ function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external override { // Executed through logic contract _fallback(); } /** * @notice allows the admin of an upkeep to modify the offchain config * @param id upkeep to be change the gas limit for * @param config instructs oracles of offchain config preferences */ function setUpkeepOffchainConfig(uint256 id, bytes calldata config) external override { // Executed through logic contract _fallback(); } /** * @notice withdraws a transmitter's payment, callable only by the transmitter's payee * @param from transmitter address * @param to address to send the payment to */ function withdrawPayment(address from, address to) external { // Executed through logic contract _fallback(); } /** * @notice proposes the safe transfer of a transmitter's payee to another address * @param transmitter address of the transmitter to transfer payee role * @param proposed address to nominate for next payeeship */ function transferPayeeship(address transmitter, address proposed) external { // Executed through logic contract _fallback(); } /** * @notice accepts the safe transfer of payee role for a transmitter * @param transmitter address to accept the payee role for */ function acceptPayeeship(address transmitter) external { // Executed through logic contract _fallback(); } /** * @notice proposes the safe transfer of an upkeep's admin role to another address * @param id the upkeep id to transfer admin * @param proposed address to nominate for the new upkeep admin */ function transferUpkeepAdmin(uint256 id, address proposed) external override { // Executed through logic contract _fallback(); } /** * @notice accepts the safe transfer of admin role for an upkeep * @param id the upkeep id */ function acceptUpkeepAdmin(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @inheritdoc MigratableKeeperRegistryInterface */ function migrateUpkeeps(uint256[] calldata ids, address destination) external override { // Executed through logic contract _fallback(); } /** * @inheritdoc MigratableKeeperRegistryInterface */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external override { // Executed through logic contract _fallback(); } //////// // OWNER RESTRICTED FUNCTIONS //////// /** * @notice recovers LINK funds improperly transferred to the registry * @dev In principle this function’s execution cost could exceed block * gas limit. However, in our anticipated deployment, the number of upkeeps and * transmitters will be low enough to avoid this problem. */ function recoverFunds() external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } /** * @notice withdraws LINK funds collected through cancellation fees */ function withdrawOwnerFunds() external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } /** * @notice update the list of payees corresponding to the transmitters * @param payees addresses corresponding to transmitters who are allowed to * move payments which have been accrued */ function setPayees(address[] calldata payees) external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } /** * @notice signals to transmitters that they should not perform upkeeps until the * contract has been unpaused */ function pause() external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } /** * @notice signals to transmitters that they can perform upkeeps once again after * having been paused */ function unpause() external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } /** * @notice sets the peer registry migration permission */ function setPeerRegistryMigrationPermission(address peer, MigrationPermission permission) external { // Executed through logic contract // Restricted to onlyOwner in logic contract _fallback(); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "./KeeperRegistryBase1_3.sol"; import "./interfaces/MigratableKeeperRegistryInterface.sol"; import "./interfaces/UpkeepTranscoderInterface.sol"; /** * @notice Logic contract, works in tandem with KeeperRegistry as a proxy */ contract KeeperRegistryLogic1_3 is KeeperRegistryBase1_3 { using Address for address; using EnumerableSet for EnumerableSet.UintSet; /** * @param paymentModel one of Default, Arbitrum, Optimism * @param registryGasOverhead the gas overhead used by registry in performUpkeep * @param link address of the LINK Token * @param linkEthFeed address of the LINK/ETH price feed * @param fastGasFeed address of the Fast Gas price feed */ constructor( PaymentModel paymentModel, uint256 registryGasOverhead, address link, address linkEthFeed, address fastGasFeed ) KeeperRegistryBase1_3(paymentModel, registryGasOverhead, link, linkEthFeed, fastGasFeed) {} function checkUpkeep(uint256 id, address from) external cannotExecute returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ) { Upkeep memory upkeep = s_upkeep[id]; bytes memory callData = abi.encodeWithSelector(CHECK_SELECTOR, s_checkData[id]); (bool success, bytes memory result) = upkeep.target.call{gas: s_storage.checkGasLimit}(callData); if (!success) revert TargetCheckReverted(result); (success, performData) = abi.decode(result, (bool, bytes)); if (!success) revert UpkeepNotNeeded(); PerformParams memory params = _generatePerformParams(from, id, performData, false); _prePerformUpkeep(upkeep, params.from, params.maxLinkPayment); return ( performData, params.maxLinkPayment, params.gasLimit, // adjustedGasWei equals fastGasWei multiplies gasCeilingMultiplier in non-execution cases params.fastGasWei * s_storage.gasCeilingMultiplier, params.linkEth ); } /** * @dev Called through KeeperRegistry main contract */ function withdrawOwnerFunds() external onlyOwner { uint96 amount = s_ownerLinkBalance; s_expectedLinkBalance = s_expectedLinkBalance - amount; s_ownerLinkBalance = 0; emit OwnerFundsWithdrawn(amount); LINK.transfer(msg.sender, amount); } /** * @dev Called through KeeperRegistry main contract */ function recoverFunds() external onlyOwner { uint256 total = LINK.balanceOf(address(this)); LINK.transfer(msg.sender, total - s_expectedLinkBalance); } /** * @dev Called through KeeperRegistry main contract */ function setKeepers(address[] calldata keepers, address[] calldata payees) external onlyOwner { if (keepers.length != payees.length || keepers.length < 2) revert ParameterLengthError(); for (uint256 i = 0; i < s_keeperList.length; i++) { address keeper = s_keeperList[i]; s_keeperInfo[keeper].active = false; } for (uint256 i = 0; i < keepers.length; i++) { address keeper = keepers[i]; KeeperInfo storage s_keeper = s_keeperInfo[keeper]; address oldPayee = s_keeper.payee; address newPayee = payees[i]; if ( (newPayee == ZERO_ADDRESS) || (oldPayee != ZERO_ADDRESS && oldPayee != newPayee && newPayee != IGNORE_ADDRESS) ) revert InvalidPayee(); if (s_keeper.active) revert DuplicateEntry(); s_keeper.active = true; if (newPayee != IGNORE_ADDRESS) { s_keeper.payee = newPayee; } } s_keeperList = keepers; emit KeepersUpdated(keepers, payees); } /** * @dev Called through KeeperRegistry main contract */ function pause() external onlyOwner { _pause(); } /** * @dev Called through KeeperRegistry main contract */ function unpause() external onlyOwner { _unpause(); } /** * @dev Called through KeeperRegistry main contract */ function setPeerRegistryMigrationPermission(address peer, MigrationPermission permission) external onlyOwner { s_peerRegistryMigrationPermission[peer] = permission; } /** * @dev Called through KeeperRegistry main contract */ function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData ) external returns (uint256 id) { if (msg.sender != owner() && msg.sender != s_registrar) revert OnlyCallableByOwnerOrRegistrar(); id = uint256(keccak256(abi.encodePacked(blockhash(block.number - 1), address(this), s_storage.nonce))); _createUpkeep(id, target, gasLimit, admin, 0, checkData, false); s_storage.nonce++; emit UpkeepRegistered(id, gasLimit, admin); return id; } /** * @dev Called through KeeperRegistry main contract */ function cancelUpkeep(uint256 id) external { Upkeep memory upkeep = s_upkeep[id]; bool canceled = upkeep.maxValidBlocknumber != UINT32_MAX; bool isOwner = msg.sender == owner(); if (canceled && !(isOwner && upkeep.maxValidBlocknumber > block.number)) revert CannotCancel(); if (!isOwner && msg.sender != upkeep.admin) revert OnlyCallableByOwnerOrAdmin(); uint256 height = block.number; if (!isOwner) { height = height + CANCELLATION_DELAY; } s_upkeep[id].maxValidBlocknumber = uint32(height); s_upkeepIDs.remove(id); // charge the cancellation fee if the minUpkeepSpend is not met uint96 minUpkeepSpend = s_storage.minUpkeepSpend; uint96 cancellationFee = 0; // cancellationFee is supposed to be min(max(minUpkeepSpend - amountSpent,0), amountLeft) if (upkeep.amountSpent < minUpkeepSpend) { cancellationFee = minUpkeepSpend - upkeep.amountSpent; if (cancellationFee > upkeep.balance) { cancellationFee = upkeep.balance; } } s_upkeep[id].balance = upkeep.balance - cancellationFee; s_ownerLinkBalance = s_ownerLinkBalance + cancellationFee; emit UpkeepCanceled(id, uint64(height)); } /** * @dev Called through KeeperRegistry main contract */ function addFunds(uint256 id, uint96 amount) external { Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); s_upkeep[id].balance = upkeep.balance + amount; s_expectedLinkBalance = s_expectedLinkBalance + amount; LINK.transferFrom(msg.sender, address(this), amount); emit FundsAdded(id, msg.sender, amount); } /** * @dev Called through KeeperRegistry main contract */ function withdrawFunds(uint256 id, address to) external { if (to == ZERO_ADDRESS) revert InvalidRecipient(); Upkeep memory upkeep = s_upkeep[id]; if (upkeep.admin != msg.sender) revert OnlyCallableByAdmin(); if (upkeep.maxValidBlocknumber > block.number) revert UpkeepNotCanceled(); uint96 amountToWithdraw = s_upkeep[id].balance; s_expectedLinkBalance = s_expectedLinkBalance - amountToWithdraw; s_upkeep[id].balance = 0; emit FundsWithdrawn(id, amountToWithdraw, to); LINK.transfer(to, amountToWithdraw); } /** * @dev Called through KeeperRegistry main contract */ function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external { if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); if (upkeep.admin != msg.sender) revert OnlyCallableByAdmin(); s_upkeep[id].executeGas = gasLimit; emit UpkeepGasLimitSet(id, gasLimit); } /** * @dev Called through KeeperRegistry main contract */ function withdrawPayment(address from, address to) external { if (to == ZERO_ADDRESS) revert InvalidRecipient(); KeeperInfo memory keeper = s_keeperInfo[from]; if (keeper.payee != msg.sender) revert OnlyCallableByPayee(); s_keeperInfo[from].balance = 0; s_expectedLinkBalance = s_expectedLinkBalance - keeper.balance; emit PaymentWithdrawn(from, keeper.balance, to, msg.sender); LINK.transfer(to, keeper.balance); } /** * @dev Called through KeeperRegistry main contract */ function transferPayeeship(address keeper, address proposed) external { if (s_keeperInfo[keeper].payee != msg.sender) revert OnlyCallableByPayee(); if (proposed == msg.sender) revert ValueNotChanged(); if (s_proposedPayee[keeper] != proposed) { s_proposedPayee[keeper] = proposed; emit PayeeshipTransferRequested(keeper, msg.sender, proposed); } } /** * @dev Called through KeeperRegistry main contract */ function acceptPayeeship(address keeper) external { if (s_proposedPayee[keeper] != msg.sender) revert OnlyCallableByProposedPayee(); address past = s_keeperInfo[keeper].payee; s_keeperInfo[keeper].payee = msg.sender; s_proposedPayee[keeper] = ZERO_ADDRESS; emit PayeeshipTransferred(keeper, past, msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function transferUpkeepAdmin(uint256 id, address proposed) external { Upkeep memory upkeep = s_upkeep[id]; requireAdminAndNotCancelled(upkeep); if (proposed == msg.sender) revert ValueNotChanged(); if (proposed == ZERO_ADDRESS) revert InvalidRecipient(); if (s_proposedAdmin[id] != proposed) { s_proposedAdmin[id] = proposed; emit UpkeepAdminTransferRequested(id, msg.sender, proposed); } } /** * @dev Called through KeeperRegistry main contract */ function acceptUpkeepAdmin(uint256 id) external { Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); if (s_proposedAdmin[id] != msg.sender) revert OnlyCallableByProposedAdmin(); address past = upkeep.admin; s_upkeep[id].admin = msg.sender; s_proposedAdmin[id] = ZERO_ADDRESS; emit UpkeepAdminTransferred(id, past, msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function migrateUpkeeps(uint256[] calldata ids, address destination) external { if ( s_peerRegistryMigrationPermission[destination] != MigrationPermission.OUTGOING && s_peerRegistryMigrationPermission[destination] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); if (s_transcoder == ZERO_ADDRESS) revert TranscoderNotSet(); if (ids.length == 0) revert ArrayHasNoEntries(); uint256 id; Upkeep memory upkeep; uint256 totalBalanceRemaining; bytes[] memory checkDatas = new bytes[](ids.length); Upkeep[] memory upkeeps = new Upkeep[](ids.length); for (uint256 idx = 0; idx < ids.length; idx++) { id = ids[idx]; upkeep = s_upkeep[id]; requireAdminAndNotCancelled(upkeep); upkeeps[idx] = upkeep; checkDatas[idx] = s_checkData[id]; totalBalanceRemaining = totalBalanceRemaining + upkeep.balance; delete s_upkeep[id]; delete s_checkData[id]; // nullify existing proposed admin change if an upkeep is being migrated delete s_proposedAdmin[id]; s_upkeepIDs.remove(id); emit UpkeepMigrated(id, upkeep.balance, destination); } s_expectedLinkBalance = s_expectedLinkBalance - totalBalanceRemaining; bytes memory encodedUpkeeps = abi.encode(ids, upkeeps, checkDatas); MigratableKeeperRegistryInterface(destination).receiveUpkeeps( UpkeepTranscoderInterface(s_transcoder).transcodeUpkeeps( UPKEEP_TRANSCODER_VERSION_BASE, MigratableKeeperRegistryInterface(destination).upkeepTranscoderVersion(), encodedUpkeeps ) ); LINK.transfer(destination, totalBalanceRemaining); } /** * @dev Called through KeeperRegistry main contract */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external { if ( s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.INCOMING && s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); (uint256[] memory ids, Upkeep[] memory upkeeps, bytes[] memory checkDatas) = abi.decode( encodedUpkeeps, (uint256[], Upkeep[], bytes[]) ); for (uint256 idx = 0; idx < ids.length; idx++) { _createUpkeep( ids[idx], upkeeps[idx].target, upkeeps[idx].executeGas, upkeeps[idx].admin, upkeeps[idx].balance, checkDatas[idx], upkeeps[idx].paused ); emit UpkeepReceived(ids[idx], upkeeps[idx].balance, msg.sender); } } /** * @notice creates a new upkeep with the given fields * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep * @param paused if this upkeep is paused */ function _createUpkeep( uint256 id, address target, uint32 gasLimit, address admin, uint96 balance, bytes memory checkData, bool paused ) internal whenNotPaused { if (!target.isContract()) revert NotAContract(); if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); s_upkeep[id] = Upkeep({ target: target, executeGas: gasLimit, balance: balance, admin: admin, maxValidBlocknumber: UINT32_MAX, lastKeeper: ZERO_ADDRESS, amountSpent: 0, paused: paused }); s_expectedLinkBalance = s_expectedLinkBalance + balance; s_checkData[id] = checkData; s_upkeepIDs.add(id); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { return _values(set._inner); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
pragma solidity 0.8.6; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "./vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol"; import "./vendor/@eth-optimism/contracts/0.8.6/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; import "./ExecutionPrevention.sol"; import {Config, State, Upkeep} from "./interfaces/KeeperRegistryInterface1_3.sol"; import "./ConfirmedOwner.sol"; import "./interfaces/AggregatorV3Interface.sol"; import "./interfaces/LinkTokenInterface.sol"; import "./interfaces/KeeperCompatibleInterface.sol"; import "./interfaces/UpkeepTranscoderInterface.sol"; /** * @notice Base Keeper Registry contract, contains shared logic between * KeeperRegistry and KeeperRegistryLogic */ abstract contract KeeperRegistryBase1_3 is ConfirmedOwner, ExecutionPrevention, ReentrancyGuard, Pausable { address internal constant ZERO_ADDRESS = address(0); address internal constant IGNORE_ADDRESS = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF; bytes4 internal constant CHECK_SELECTOR = KeeperCompatibleInterface.checkUpkeep.selector; bytes4 internal constant PERFORM_SELECTOR = KeeperCompatibleInterface.performUpkeep.selector; uint256 internal constant PERFORM_GAS_MIN = 2_300; uint256 internal constant CANCELLATION_DELAY = 50; uint256 internal constant PERFORM_GAS_CUSHION = 5_000; uint256 internal constant PPB_BASE = 1_000_000_000; uint32 internal constant UINT32_MAX = type(uint32).max; uint96 internal constant LINK_TOTAL_SUPPLY = 1e27; UpkeepFormat internal constant UPKEEP_TRANSCODER_VERSION_BASE = UpkeepFormat.V2; // L1_FEE_DATA_PADDING includes 35 bytes for L1 data padding for Optimism bytes internal constant L1_FEE_DATA_PADDING = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; // MAX_INPUT_DATA represents the estimated max size of the sum of L1 data padding and msg.data in performUpkeep // function, which includes 4 bytes for function selector, 32 bytes for upkeep id, 35 bytes for data padding, and // 64 bytes for estimated perform data bytes internal constant MAX_INPUT_DATA = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; address[] internal s_keeperList; EnumerableSet.UintSet internal s_upkeepIDs; mapping(uint256 => Upkeep) internal s_upkeep; mapping(address => KeeperInfo) internal s_keeperInfo; mapping(address => address) internal s_proposedPayee; mapping(uint256 => address) internal s_proposedAdmin; mapping(uint256 => bytes) internal s_checkData; mapping(address => MigrationPermission) internal s_peerRegistryMigrationPermission; Storage internal s_storage; uint256 internal s_fallbackGasPrice; // not in config object for gas savings uint256 internal s_fallbackLinkPrice; // not in config object for gas savings uint96 internal s_ownerLinkBalance; uint256 internal s_expectedLinkBalance; address internal s_transcoder; address internal s_registrar; LinkTokenInterface public immutable LINK; AggregatorV3Interface public immutable LINK_ETH_FEED; AggregatorV3Interface public immutable FAST_GAS_FEED; OVM_GasPriceOracle public immutable OPTIMISM_ORACLE = OVM_GasPriceOracle(0x420000000000000000000000000000000000000F); ArbGasInfo public immutable ARB_NITRO_ORACLE = ArbGasInfo(0x000000000000000000000000000000000000006C); PaymentModel public immutable PAYMENT_MODEL; uint256 public immutable REGISTRY_GAS_OVERHEAD; error ArrayHasNoEntries(); error CannotCancel(); error DuplicateEntry(); error EmptyAddress(); error GasLimitCanOnlyIncrease(); error GasLimitOutsideRange(); error IndexOutOfRange(); error InsufficientFunds(); error InvalidDataLength(); error InvalidPayee(); error InvalidRecipient(); error KeepersMustTakeTurns(); error MigrationNotPermitted(); error NotAContract(); error OnlyActiveKeepers(); error OnlyCallableByAdmin(); error OnlyCallableByLINKToken(); error OnlyCallableByOwnerOrAdmin(); error OnlyCallableByOwnerOrRegistrar(); error OnlyCallableByPayee(); error OnlyCallableByProposedAdmin(); error OnlyCallableByProposedPayee(); error OnlyPausedUpkeep(); error OnlyUnpausedUpkeep(); error ParameterLengthError(); error PaymentGreaterThanAllLINK(); error TargetCheckReverted(bytes reason); error TranscoderNotSet(); error UpkeepCancelled(); error UpkeepNotCanceled(); error UpkeepNotNeeded(); error ValueNotChanged(); enum MigrationPermission { NONE, OUTGOING, INCOMING, BIDIRECTIONAL } enum PaymentModel { DEFAULT, ARBITRUM, OPTIMISM } /** * @notice storage of the registry, contains a mix of config and state data */ struct Storage { uint32 paymentPremiumPPB; uint32 flatFeeMicroLink; uint24 blockCountPerTurn; uint32 checkGasLimit; uint24 stalenessSeconds; uint16 gasCeilingMultiplier; uint96 minUpkeepSpend; // 1 full evm word uint32 maxPerformGas; uint32 nonce; } struct KeeperInfo { address payee; uint96 balance; bool active; } struct PerformParams { address from; uint256 id; bytes performData; uint256 maxLinkPayment; uint256 gasLimit; uint256 fastGasWei; uint256 linkEth; } event ConfigSet(Config config); event FundsAdded(uint256 indexed id, address indexed from, uint96 amount); event FundsWithdrawn(uint256 indexed id, uint256 amount, address to); event KeepersUpdated(address[] keepers, address[] payees); event OwnerFundsWithdrawn(uint96 amount); event PayeeshipTransferRequested(address indexed keeper, address indexed from, address indexed to); event PayeeshipTransferred(address indexed keeper, address indexed from, address indexed to); event PaymentWithdrawn(address indexed keeper, uint256 indexed amount, address indexed to, address payee); event UpkeepAdminTransferRequested(uint256 indexed id, address indexed from, address indexed to); event UpkeepAdminTransferred(uint256 indexed id, address indexed from, address indexed to); event UpkeepCanceled(uint256 indexed id, uint64 indexed atBlockHeight); event UpkeepCheckDataUpdated(uint256 indexed id, bytes newCheckData); event UpkeepGasLimitSet(uint256 indexed id, uint96 gasLimit); event UpkeepMigrated(uint256 indexed id, uint256 remainingBalance, address destination); event UpkeepPaused(uint256 indexed id); event UpkeepPerformed( uint256 indexed id, bool indexed success, address indexed from, uint96 payment, bytes performData ); event UpkeepReceived(uint256 indexed id, uint256 startingBalance, address importedFrom); event UpkeepUnpaused(uint256 indexed id); event UpkeepRegistered(uint256 indexed id, uint32 executeGas, address admin); /** * @param paymentModel the payment model of default, Arbitrum, or Optimism * @param registryGasOverhead the gas overhead used by registry in performUpkeep * @param link address of the LINK Token * @param linkEthFeed address of the LINK/ETH price feed * @param fastGasFeed address of the Fast Gas price feed */ constructor( PaymentModel paymentModel, uint256 registryGasOverhead, address link, address linkEthFeed, address fastGasFeed ) ConfirmedOwner(msg.sender) { PAYMENT_MODEL = paymentModel; REGISTRY_GAS_OVERHEAD = registryGasOverhead; if (ZERO_ADDRESS == link || ZERO_ADDRESS == linkEthFeed || ZERO_ADDRESS == fastGasFeed) { revert EmptyAddress(); } LINK = LinkTokenInterface(link); LINK_ETH_FEED = AggregatorV3Interface(linkEthFeed); FAST_GAS_FEED = AggregatorV3Interface(fastGasFeed); } /** * @dev retrieves feed data for fast gas/eth and link/eth prices. if the feed * data is stale it uses the configured fallback price. Once a price is picked * for gas it takes the min of gas price in the transaction or the fast gas * price in order to reduce costs for the upkeep clients. */ function _getFeedData() internal view returns (uint256 gasWei, uint256 linkEth) { uint32 stalenessSeconds = s_storage.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; uint256 timestamp; int256 feedValue; (, feedValue, , timestamp, ) = FAST_GAS_FEED.latestRoundData(); if ((staleFallback && stalenessSeconds < block.timestamp - timestamp) || feedValue <= 0) { gasWei = s_fallbackGasPrice; } else { gasWei = uint256(feedValue); } (, feedValue, , timestamp, ) = LINK_ETH_FEED.latestRoundData(); if ((staleFallback && stalenessSeconds < block.timestamp - timestamp) || feedValue <= 0) { linkEth = s_fallbackLinkPrice; } else { linkEth = uint256(feedValue); } return (gasWei, linkEth); } /** * @dev calculates LINK paid for gas spent plus a configure premium percentage * @param gasLimit the amount of gas used * @param fastGasWei the fast gas price * @param linkEth the exchange ratio between LINK and ETH * @param isExecution if this is triggered by a perform upkeep function */ function _calculatePaymentAmount( uint256 gasLimit, uint256 fastGasWei, uint256 linkEth, bool isExecution ) internal view returns (uint96 payment) { Storage memory store = s_storage; uint256 gasWei = fastGasWei * store.gasCeilingMultiplier; // in case it's actual execution use actual gas price, capped by fastGasWei * gasCeilingMultiplier if (isExecution && tx.gasprice < gasWei) { gasWei = tx.gasprice; } uint256 weiForGas = gasWei * (gasLimit + REGISTRY_GAS_OVERHEAD); uint256 premium = PPB_BASE + store.paymentPremiumPPB; uint256 l1CostWei = 0; if (PAYMENT_MODEL == PaymentModel.OPTIMISM) { bytes memory txCallData = new bytes(0); if (isExecution) { txCallData = bytes.concat(msg.data, L1_FEE_DATA_PADDING); } else { txCallData = MAX_INPUT_DATA; } l1CostWei = OPTIMISM_ORACLE.getL1Fee(txCallData); } else if (PAYMENT_MODEL == PaymentModel.ARBITRUM) { l1CostWei = ARB_NITRO_ORACLE.getCurrentTxL1GasFees(); } // if it's not performing upkeeps, use gas ceiling multiplier to estimate the upper bound if (!isExecution) { l1CostWei = store.gasCeilingMultiplier * l1CostWei; } uint256 total = ((weiForGas + l1CostWei) * 1e9 * premium) / linkEth + uint256(store.flatFeeMicroLink) * 1e12; if (total > LINK_TOTAL_SUPPLY) revert PaymentGreaterThanAllLINK(); return uint96(total); // LINK_TOTAL_SUPPLY < UINT96_MAX } /** * @dev ensures all required checks are passed before an upkeep is performed */ function _prePerformUpkeep( Upkeep memory upkeep, address from, uint256 maxLinkPayment ) internal view { if (upkeep.paused) revert OnlyUnpausedUpkeep(); if (!s_keeperInfo[from].active) revert OnlyActiveKeepers(); if (upkeep.balance < maxLinkPayment) revert InsufficientFunds(); if (upkeep.lastKeeper == from) revert KeepersMustTakeTurns(); } /** * @dev ensures the upkeep is not cancelled and the caller is the upkeep admin */ function requireAdminAndNotCancelled(Upkeep memory upkeep) internal view { if (msg.sender != upkeep.admin) revert OnlyCallableByAdmin(); if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); } /** * @dev generates a PerformParams struct for use in _performUpkeepWithParams() */ function _generatePerformParams( address from, uint256 id, bytes memory performData, bool isExecution ) internal view returns (PerformParams memory) { uint256 gasLimit = s_upkeep[id].executeGas; (uint256 fastGasWei, uint256 linkEth) = _getFeedData(); uint96 maxLinkPayment = _calculatePaymentAmount(gasLimit, fastGasWei, linkEth, isExecution); return PerformParams({ from: from, id: id, performData: performData, maxLinkPayment: maxLinkPayment, gasLimit: gasLimit, fastGasWei: fastGasWei, linkEth: linkEth }); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../UpkeepFormat.sol"; interface MigratableKeeperRegistryInterface { /** * @notice Migrates upkeeps from one registry to another, including LINK and upkeep params. * Only callable by the upkeep admin. All upkeeps must have the same admin. Can only migrate active upkeeps. * @param upkeepIDs ids of upkeeps to migrate * @param destination the address of the registry to migrate to */ function migrateUpkeeps(uint256[] calldata upkeepIDs, address destination) external; /** * @notice Called by other registries when migrating upkeeps. Only callable by other registries. * @param encodedUpkeeps abi encoding of upkeeps to import - decoded by the transcoder */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external; /** * @notice Specifies the version of upkeep data that this registry requires in order to import */ function upkeepTranscoderVersion() external returns (UpkeepFormat version); }
// SPDX-License-Identifier: MIT import "../UpkeepFormat.sol"; pragma solidity ^0.8.0; interface UpkeepTranscoderInterface { function transcodeUpkeeps( UpkeepFormat fromVersion, UpkeepFormat toVersion, bytes calldata encodedUpkeeps ) external view returns (bytes memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
pragma solidity >=0.4.21 <0.9.0; interface ArbGasInfo { // return gas prices in wei, assuming the specified aggregator is used // ( // per L2 tx, // per L1 calldata unit, (zero byte = 4 units, nonzero byte = 16 units) // per storage allocation, // per ArbGas base, // per ArbGas congestion, // per ArbGas total // ) function getPricesInWeiWithAggregator(address aggregator) external view returns (uint, uint, uint, uint, uint, uint); // return gas prices in wei, as described above, assuming the caller's preferred aggregator is used // if the caller hasn't specified a preferred aggregator, the default aggregator is assumed function getPricesInWei() external view returns (uint, uint, uint, uint, uint, uint); // return prices in ArbGas (per L2 tx, per L1 calldata unit, per storage allocation), // assuming the specified aggregator is used function getPricesInArbGasWithAggregator(address aggregator) external view returns (uint, uint, uint); // return gas prices in ArbGas, as described above, assuming the caller's preferred aggregator is used // if the caller hasn't specified a preferred aggregator, the default aggregator is assumed function getPricesInArbGas() external view returns (uint, uint, uint); // return gas accounting parameters (speedLimitPerSecond, gasPoolMax, maxTxGasLimit) function getGasAccountingParams() external view returns (uint, uint, uint); // get ArbOS's estimate of the L1 gas price in wei function getL1GasPriceEstimate() external view returns(uint); // set ArbOS's estimate of the L1 gas price in wei // reverts unless called by chain owner or designated gas oracle (if any) function setL1GasPriceEstimate(uint priceInWei) external; // get L1 gas fees paid by the current transaction (txBaseFeeWei, calldataFeeWei) function getCurrentTxL1GasFees() external view returns(uint); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; /* External Imports */ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title OVM_GasPriceOracle * @dev This contract exposes the current l2 gas price, a measure of how congested the network * currently is. This measure is used by the Sequencer to determine what fee to charge for * transactions. When the system is more congested, the l2 gas price will increase and fees * will also increase as a result. * * All public variables are set while generating the initial L2 state. The * constructor doesn't run in practice as the L2 state generation script uses * the deployed bytecode instead of running the initcode. */ contract OVM_GasPriceOracle is Ownable { /************* * Variables * *************/ // Current L2 gas price uint256 public gasPrice; // Current L1 base fee uint256 public l1BaseFee; // Amortized cost of batch submission per transaction uint256 public overhead; // Value to scale the fee up by uint256 public scalar; // Number of decimals of the scalar uint256 public decimals; /*************** * Constructor * ***************/ /** * @param _owner Address that will initially own this contract. */ constructor(address _owner) Ownable() { transferOwnership(_owner); } /********** * Events * **********/ event GasPriceUpdated(uint256); event L1BaseFeeUpdated(uint256); event OverheadUpdated(uint256); event ScalarUpdated(uint256); event DecimalsUpdated(uint256); /******************** * Public Functions * ********************/ /** * Allows the owner to modify the l2 gas price. * @param _gasPrice New l2 gas price. */ // slither-disable-next-line external-function function setGasPrice(uint256 _gasPrice) public onlyOwner { gasPrice = _gasPrice; emit GasPriceUpdated(_gasPrice); } /** * Allows the owner to modify the l1 base fee. * @param _baseFee New l1 base fee */ // slither-disable-next-line external-function function setL1BaseFee(uint256 _baseFee) public onlyOwner { l1BaseFee = _baseFee; emit L1BaseFeeUpdated(_baseFee); } /** * Allows the owner to modify the overhead. * @param _overhead New overhead */ // slither-disable-next-line external-function function setOverhead(uint256 _overhead) public onlyOwner { overhead = _overhead; emit OverheadUpdated(_overhead); } /** * Allows the owner to modify the scalar. * @param _scalar New scalar */ // slither-disable-next-line external-function function setScalar(uint256 _scalar) public onlyOwner { scalar = _scalar; emit ScalarUpdated(_scalar); } /** * Allows the owner to modify the decimals. * @param _decimals New decimals */ // slither-disable-next-line external-function function setDecimals(uint256 _decimals) public onlyOwner { decimals = _decimals; emit DecimalsUpdated(_decimals); } /** * Computes the L1 portion of the fee * based on the size of the RLP encoded tx * and the current l1BaseFee * @param _data Unsigned RLP encoded tx, 6 elements * @return L1 fee that should be paid for the tx */ // slither-disable-next-line external-function function getL1Fee(bytes memory _data) public view returns (uint256) { uint256 l1GasUsed = getL1GasUsed(_data); uint256 l1Fee = l1GasUsed * l1BaseFee; uint256 divisor = 10**decimals; uint256 unscaled = l1Fee * scalar; uint256 scaled = unscaled / divisor; return scaled; } // solhint-disable max-line-length /** * Computes the amount of L1 gas used for a transaction * The overhead represents the per batch gas overhead of * posting both transaction and state roots to L1 given larger * batch sizes. * 4 gas for 0 byte * https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L33 * 16 gas for non zero byte * https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L87 * This will need to be updated if calldata gas prices change * Account for the transaction being unsigned * Padding is added to account for lack of signature on transaction * 1 byte for RLP V prefix * 1 byte for V * 1 byte for RLP R prefix * 32 bytes for R * 1 byte for RLP S prefix * 32 bytes for S * Total: 68 bytes of padding * @param _data Unsigned RLP encoded tx, 6 elements * @return Amount of L1 gas used for a transaction */ // solhint-enable max-line-length function getL1GasUsed(bytes memory _data) public view returns (uint256) { uint256 total = 0; for (uint256 i = 0; i < _data.length; i++) { if (_data[i] == 0) { total += 4; } else { total += 16; } } uint256 unsigned = total + overhead; return unsigned + (68 * 16); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; abstract contract ExecutionPrevention { error OnlySimulatedBackend(); /** * @notice method that allows it to be simulated via eth_call by checking that * the sender is the zero address. */ function preventExecution() internal view { if (tx.origin != address(0)) { revert OnlySimulatedBackend(); } } /** * @notice modifier that allows it to be simulated via eth_call by checking * that the sender is the zero address. */ modifier cannotExecute() { preventExecution(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice config of the registry * @dev only used in params and return values * @member paymentPremiumPPB payment premium rate oracles receive on top of * being reimbursed for gas, measured in parts per billion * @member flatFeeMicroLink flat fee paid to oracles for performing upkeeps, * priced in MicroLink; can be used in conjunction with or independently of * paymentPremiumPPB * @member blockCountPerTurn number of blocks each oracle has during their turn to * perform upkeep before it will be the next keeper's turn to submit * @member checkGasLimit gas limit when checking for upkeep * @member stalenessSeconds number of seconds that is allowed for feed data to * be stale before switching to the fallback pricing * @member gasCeilingMultiplier multiplier to apply to the fast gas feed price * when calculating the payment ceiling for keepers * @member minUpkeepSpend minimum LINK that an upkeep must spend before cancelling * @member maxPerformGas max executeGas allowed for an upkeep on this registry * @member fallbackGasPrice gas price used if the gas price feed is stale * @member fallbackLinkPrice LINK price used if the LINK price feed is stale * @member transcoder address of the transcoder contract * @member registrar address of the registrar contract */ struct Config { uint32 paymentPremiumPPB; uint32 flatFeeMicroLink; // min 0.000001 LINK, max 4294 LINK uint24 blockCountPerTurn; uint32 checkGasLimit; uint24 stalenessSeconds; uint16 gasCeilingMultiplier; uint96 minUpkeepSpend; uint32 maxPerformGas; uint256 fallbackGasPrice; uint256 fallbackLinkPrice; address transcoder; address registrar; } /** * @notice state of the registry * @dev only used in params and return values * @member nonce used for ID generation * @member ownerLinkBalance withdrawable balance of LINK by contract owner * @member expectedLinkBalance the expected balance of LINK of the registry * @member numUpkeeps total number of upkeeps on the registry */ struct State { uint32 nonce; uint96 ownerLinkBalance; uint256 expectedLinkBalance; uint256 numUpkeeps; } /** * @notice relevant state of an upkeep * @member balance the balance of this upkeep * @member lastKeeper the keeper which last performs the upkeep * @member executeGas the gas limit of upkeep execution * @member maxValidBlocknumber until which block this upkeep is valid * @member target the contract which needs to be serviced * @member amountSpent the amount this upkeep has spent * @member admin the upkeep admin * @member paused if this upkeep has been paused */ struct Upkeep { uint96 balance; address lastKeeper; // 1 full evm word uint96 amountSpent; address admin; // 2 full evm words uint32 executeGas; uint32 maxValidBlocknumber; address target; bool paused; // 24 bits to 3 full evm words } interface KeeperRegistryBaseInterface { function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData ) external returns (uint256 id); function performUpkeep(uint256 id, bytes calldata performData) external returns (bool success); function cancelUpkeep(uint256 id) external; function pauseUpkeep(uint256 id) external; function unpauseUpkeep(uint256 id) external; function transferUpkeepAdmin(uint256 id, address proposed) external; function acceptUpkeepAdmin(uint256 id) external; function updateCheckData(uint256 id, bytes calldata newCheckData) external; function addFunds(uint256 id, uint96 amount) external; function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external; function getUpkeep(uint256 id) external view returns ( address target, uint32 executeGas, bytes memory checkData, uint96 balance, address lastKeeper, address admin, uint64 maxValidBlocknumber, uint96 amountSpent, bool paused ); function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view returns (uint256[] memory); function getKeeperInfo(address query) external view returns ( address payee, bool active, uint96 balance ); function getState() external view returns ( State memory, Config memory, address[] memory ); } /** * @dev The view methods are not actually marked as view in the implementation * but we want them to be easily queried off-chain. Solidity will not compile * if we actually inherit from this interface, so we document it here. */ interface KeeperRegistryInterface is KeeperRegistryBaseInterface { function checkUpkeep(uint256 upkeepId, address from) external view returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, int256 gasWei, int256 linkEth ); } interface KeeperRegistryExecutableInterface is KeeperRegistryBaseInterface { function checkUpkeep(uint256 upkeepId, address from) external returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ConfirmedOwnerWithProposal.sol"; /** * @title The ConfirmedOwner contract * @notice A contract with helpers for basic contract ownership. */ contract ConfirmedOwner is ConfirmedOwnerWithProposal { constructor(address newOwner) ConfirmedOwnerWithProposal(newOwner, address(0)) {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall( address to, uint256 value, bytes calldata data ) external returns (bool success); function transferFrom( address from, address to, uint256 value ) external returns (bool success); }
// SPDX-License-Identifier: MIT /** * @notice This is a deprecated interface. Please use AutomationCompatibleInterface directly. */ pragma solidity ^0.8.0; import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "./AutomationCompatibleInterface.sol";
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./interfaces/OwnableInterface.sol"; /** * @title The ConfirmedOwner contract * @notice A contract with helpers for basic contract ownership. */ contract ConfirmedOwnerWithProposal is OwnableInterface { address private s_owner; address private s_pendingOwner; event OwnershipTransferRequested(address indexed from, address indexed to); event OwnershipTransferred(address indexed from, address indexed to); constructor(address newOwner, address pendingOwner) { require(newOwner != address(0), "Cannot set owner to zero"); s_owner = newOwner; if (pendingOwner != address(0)) { _transferOwnership(pendingOwner); } } /** * @notice Allows an owner to begin transferring ownership to a new address, * pending. */ function transferOwnership(address to) public override onlyOwner { _transferOwnership(to); } /** * @notice Allows an ownership transfer to be completed by the recipient. */ function acceptOwnership() external override { require(msg.sender == s_pendingOwner, "Must be proposed owner"); address oldOwner = s_owner; s_owner = msg.sender; s_pendingOwner = address(0); emit OwnershipTransferred(oldOwner, msg.sender); } /** * @notice Get the current owner */ function owner() public view override returns (address) { return s_owner; } /** * @notice validate, transfer ownership, and emit relevant events */ function _transferOwnership(address to) private { require(to != msg.sender, "Cannot transfer to self"); s_pendingOwner = to; emit OwnershipTransferRequested(s_owner, to); } /** * @notice validate access */ function _validateOwnership() internal view { require(msg.sender == s_owner, "Only callable by owner"); } /** * @notice Reverts if called by anyone other than the contract owner. */ modifier onlyOwner() { _validateOwnership(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface OwnableInterface { function owner() external returns (address); function transferOwnership(address recipient) external; function acceptOwnership() external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AutomationCompatibleInterface { /** * @notice method that is simulated by the keepers to see if any work actually * needs to be performed. This method does does not actually need to be * executable, and since it is only ever simulated it can consume lots of gas. * @dev To ensure that it is never called, you may want to add the * cannotExecute modifier from KeeperBase to your implementation of this * method. * @param checkData specified in the upkeep registration so it is always the * same for a registered upkeep. This can easily be broken down into specific * arguments using `abi.decode`, so multiple upkeeps can be registered on the * same contract and easily differentiated by the contract. * @return upkeepNeeded boolean to indicate whether the keeper should call * performUpkeep or not. * @return performData bytes that the keeper should call performUpkeep with, if * upkeep is needed. If you would like to encode data to decode later, try * `abi.encode`. */ function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData); /** * @notice method that is actually executed by the keepers, via the registry. * The data returned by the checkUpkeep simulation will be passed into * this method to actually be executed. * @dev The input to this method should not be trusted, and the caller of the * method should not even be restricted to any single registry. Anyone should * be able call it, and the input should be validated, there is no guarantee * that the data passed in is the performData returned from checkUpkeep. This * could happen due to malicious keepers, racing keepers, or simply a state * change while the performUpkeep transaction is waiting for confirmation. * Always validate the data passed in. * @param performData is the data which was passed back from the checkData * simulation. If it is encoded, it can easily be decoded into other types by * calling `abi.decode`. This data should not be trusted, and should be * validated against the contract's current state. */ function performUpkeep(bytes calldata performData) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; enum UpkeepFormat { V1, V2, V3 }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "./KeeperRegistryBase1_3.sol"; import "./KeeperRegistryLogic1_3.sol"; import {KeeperRegistryExecutableInterface} from "./interfaces/KeeperRegistryInterface1_3.sol"; import "./interfaces/MigratableKeeperRegistryInterface.sol"; import "./interfaces/TypeAndVersionInterface.sol"; import "./interfaces/ERC677ReceiverInterface.sol"; /** * @notice Registry for adding work for Chainlink Keepers to perform on client * contracts. Clients must support the Upkeep interface. */ contract KeeperRegistry1_3 is KeeperRegistryBase1_3, Proxy, TypeAndVersionInterface, KeeperRegistryExecutableInterface, MigratableKeeperRegistryInterface, ERC677ReceiverInterface { using Address for address; using EnumerableSet for EnumerableSet.UintSet; address public immutable KEEPER_REGISTRY_LOGIC; /** * @notice versions: * - KeeperRegistry 1.3.0: split contract into Proxy and Logic * : account for Arbitrum and Optimism L1 gas fee * : allow users to configure upkeeps * - KeeperRegistry 1.2.0: allow funding within performUpkeep * : allow configurable registry maxPerformGas * : add function to let admin change upkeep gas limit * : add minUpkeepSpend requirement : upgrade to solidity v0.8 * - KeeperRegistry 1.1.0: added flatFeeMicroLink * - KeeperRegistry 1.0.0: initial release */ string public constant override typeAndVersion = "KeeperRegistry 1.3.0"; /** * @param keeperRegistryLogic the address of keeper registry logic * @param config registry config settings */ constructor(KeeperRegistryLogic1_3 keeperRegistryLogic, Config memory config) KeeperRegistryBase1_3( keeperRegistryLogic.PAYMENT_MODEL(), keeperRegistryLogic.REGISTRY_GAS_OVERHEAD(), address(keeperRegistryLogic.LINK()), address(keeperRegistryLogic.LINK_ETH_FEED()), address(keeperRegistryLogic.FAST_GAS_FEED()) ) { KEEPER_REGISTRY_LOGIC = address(keeperRegistryLogic); setConfig(config); } // ACTIONS /** * @notice adds a new upkeep * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep */ function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData ) external override returns (uint256 id) { // Executed through logic contract _fallback(); } /** * @notice simulated by keepers via eth_call to see if the upkeep needs to be * performed. If upkeep is needed, the call then simulates performUpkeep * to make sure it succeeds. Finally, it returns the success status along with * payment information and the perform data payload. * @param id identifier of the upkeep to check * @param from the address to simulate performing the upkeep from */ function checkUpkeep(uint256 id, address from) external override cannotExecute returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ) { // Executed through logic contract _fallback(); } /** * @notice executes the upkeep with the perform data returned from * checkUpkeep, validates the keeper's permissions, and pays the keeper. * @param id identifier of the upkeep to execute the data with. * @param performData calldata parameter to be passed to the target upkeep. */ function performUpkeep(uint256 id, bytes calldata performData) external override whenNotPaused returns (bool success) { return _performUpkeepWithParams(_generatePerformParams(msg.sender, id, performData, true)); } /** * @notice prevent an upkeep from being performed in the future * @param id upkeep to be canceled */ function cancelUpkeep(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @notice pause an upkeep * @param id upkeep to be paused */ function pauseUpkeep(uint256 id) external override { Upkeep memory upkeep = s_upkeep[id]; requireAdminAndNotCancelled(upkeep); if (upkeep.paused) revert OnlyUnpausedUpkeep(); s_upkeep[id].paused = true; s_upkeepIDs.remove(id); emit UpkeepPaused(id); } /** * @notice unpause an upkeep * @param id upkeep to be resumed */ function unpauseUpkeep(uint256 id) external override { Upkeep memory upkeep = s_upkeep[id]; requireAdminAndNotCancelled(upkeep); if (!upkeep.paused) revert OnlyPausedUpkeep(); s_upkeep[id].paused = false; s_upkeepIDs.add(id); emit UpkeepUnpaused(id); } /** * @notice update the check data of an upkeep * @param id the id of the upkeep whose check data needs to be updated * @param newCheckData the new check data */ function updateCheckData(uint256 id, bytes calldata newCheckData) external override { Upkeep memory upkeep = s_upkeep[id]; requireAdminAndNotCancelled(upkeep); s_checkData[id] = newCheckData; emit UpkeepCheckDataUpdated(id, newCheckData); } /** * @notice adds LINK funding for an upkeep by transferring from the sender's * LINK balance * @param id upkeep to fund * @param amount number of LINK to transfer */ function addFunds(uint256 id, uint96 amount) external override { // Executed through logic contract _fallback(); } /** * @notice uses LINK's transferAndCall to LINK and add funding to an upkeep * @dev safe to cast uint256 to uint96 as total LINK supply is under UINT96MAX * @param sender the account which transferred the funds * @param amount number of LINK transfer */ function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external override { if (msg.sender != address(LINK)) revert OnlyCallableByLINKToken(); if (data.length != 32) revert InvalidDataLength(); uint256 id = abi.decode(data, (uint256)); if (s_upkeep[id].maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); s_upkeep[id].balance = s_upkeep[id].balance + uint96(amount); s_expectedLinkBalance = s_expectedLinkBalance + amount; emit FundsAdded(id, sender, uint96(amount)); } /** * @notice removes funding from a canceled upkeep * @param id upkeep to withdraw funds from * @param to destination address for sending remaining funds */ function withdrawFunds(uint256 id, address to) external { // Executed through logic contract _fallback(); } /** * @notice withdraws LINK funds collected through cancellation fees */ function withdrawOwnerFunds() external { // Executed through logic contract _fallback(); } /** * @notice allows the admin of an upkeep to modify gas limit * @param id upkeep to be change the gas limit for * @param gasLimit new gas limit for the upkeep */ function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external override { // Executed through logic contract _fallback(); } /** * @notice recovers LINK funds improperly transferred to the registry * @dev In principle this function’s execution cost could exceed block * gas limit. However, in our anticipated deployment, the number of upkeeps and * keepers will be low enough to avoid this problem. */ function recoverFunds() external { // Executed through logic contract _fallback(); } /** * @notice withdraws a keeper's payment, callable only by the keeper's payee * @param from keeper address * @param to address to send the payment to */ function withdrawPayment(address from, address to) external { // Executed through logic contract _fallback(); } /** * @notice proposes the safe transfer of a keeper's payee to another address * @param keeper address of the keeper to transfer payee role * @param proposed address to nominate for next payeeship */ function transferPayeeship(address keeper, address proposed) external { // Executed through logic contract _fallback(); } /** * @notice accepts the safe transfer of payee role for a keeper * @param keeper address to accept the payee role for */ function acceptPayeeship(address keeper) external { // Executed through logic contract _fallback(); } /** * @notice proposes the safe transfer of an upkeep's admin role to another address * @param id the upkeep id to transfer admin * @param proposed address to nominate for the new upkeep admin */ function transferUpkeepAdmin(uint256 id, address proposed) external override { // Executed through logic contract _fallback(); } /** * @notice accepts the safe transfer of admin role for an upkeep * @param id the upkeep id */ function acceptUpkeepAdmin(uint256 id) external override { // Executed through logic contract _fallback(); } /** * @notice signals to keepers that they should not perform upkeeps until the * contract has been unpaused */ function pause() external { // Executed through logic contract _fallback(); } /** * @notice signals to keepers that they can perform upkeeps once again after * having been paused */ function unpause() external { // Executed through logic contract _fallback(); } // SETTERS /** * @notice updates the configuration of the registry * @param config registry config fields */ function setConfig(Config memory config) public onlyOwner { if (config.maxPerformGas < s_storage.maxPerformGas) revert GasLimitCanOnlyIncrease(); s_storage = Storage({ paymentPremiumPPB: config.paymentPremiumPPB, flatFeeMicroLink: config.flatFeeMicroLink, blockCountPerTurn: config.blockCountPerTurn, checkGasLimit: config.checkGasLimit, stalenessSeconds: config.stalenessSeconds, gasCeilingMultiplier: config.gasCeilingMultiplier, minUpkeepSpend: config.minUpkeepSpend, maxPerformGas: config.maxPerformGas, nonce: s_storage.nonce }); s_fallbackGasPrice = config.fallbackGasPrice; s_fallbackLinkPrice = config.fallbackLinkPrice; s_transcoder = config.transcoder; s_registrar = config.registrar; emit ConfigSet(config); } /** * @notice update the list of keepers allowed to perform upkeep * @param keepers list of addresses allowed to perform upkeep * @param payees addresses corresponding to keepers who are allowed to * move payments which have been accrued */ function setKeepers(address[] calldata keepers, address[] calldata payees) external { // Executed through logic contract _fallback(); } // GETTERS /** * @notice read all of the details about an upkeep */ function getUpkeep(uint256 id) external view override returns ( address target, uint32 executeGas, bytes memory checkData, uint96 balance, address lastKeeper, address admin, uint64 maxValidBlocknumber, uint96 amountSpent, bool paused ) { Upkeep memory reg = s_upkeep[id]; return ( reg.target, reg.executeGas, s_checkData[id], reg.balance, reg.lastKeeper, reg.admin, reg.maxValidBlocknumber, reg.amountSpent, reg.paused ); } /** * @notice retrieve active upkeep IDs. Active upkeep is defined as an upkeep which is not paused and not canceled. * @param startIndex starting index in list * @param maxCount max count to retrieve (0 = unlimited) * @dev the order of IDs in the list is **not guaranteed**, therefore, if making successive calls, one * should consider keeping the blockheight constant to ensure a holistic picture of the contract state */ function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view override returns (uint256[] memory) { uint256 maxIdx = s_upkeepIDs.length(); if (startIndex >= maxIdx) revert IndexOutOfRange(); if (maxCount == 0) { maxCount = maxIdx - startIndex; } uint256[] memory ids = new uint256[](maxCount); for (uint256 idx = 0; idx < maxCount; idx++) { ids[idx] = s_upkeepIDs.at(startIndex + idx); } return ids; } /** * @notice read the current info about any keeper address */ function getKeeperInfo(address query) external view override returns ( address payee, bool active, uint96 balance ) { KeeperInfo memory keeper = s_keeperInfo[query]; return (keeper.payee, keeper.active, keeper.balance); } /** * @notice read the current state of the registry */ function getState() external view override returns ( State memory state, Config memory config, address[] memory keepers ) { Storage memory store = s_storage; state.nonce = store.nonce; state.ownerLinkBalance = s_ownerLinkBalance; state.expectedLinkBalance = s_expectedLinkBalance; state.numUpkeeps = s_upkeepIDs.length(); config.paymentPremiumPPB = store.paymentPremiumPPB; config.flatFeeMicroLink = store.flatFeeMicroLink; config.blockCountPerTurn = store.blockCountPerTurn; config.checkGasLimit = store.checkGasLimit; config.stalenessSeconds = store.stalenessSeconds; config.gasCeilingMultiplier = store.gasCeilingMultiplier; config.minUpkeepSpend = store.minUpkeepSpend; config.maxPerformGas = store.maxPerformGas; config.fallbackGasPrice = s_fallbackGasPrice; config.fallbackLinkPrice = s_fallbackLinkPrice; config.transcoder = s_transcoder; config.registrar = s_registrar; return (state, config, s_keeperList); } /** * @notice calculates the minimum balance required for an upkeep to remain eligible * @param id the upkeep id to calculate minimum balance for */ function getMinBalanceForUpkeep(uint256 id) external view returns (uint96 minBalance) { return getMaxPaymentForGas(s_upkeep[id].executeGas); } /** * @notice calculates the maximum payment for a given gas limit * @param gasLimit the gas to calculate payment for */ function getMaxPaymentForGas(uint256 gasLimit) public view returns (uint96 maxPayment) { (uint256 fastGasWei, uint256 linkEth) = _getFeedData(); return _calculatePaymentAmount(gasLimit, fastGasWei, linkEth, false); } /** * @notice retrieves the migration permission for a peer registry */ function getPeerRegistryMigrationPermission(address peer) external view returns (MigrationPermission) { return s_peerRegistryMigrationPermission[peer]; } /** * @notice sets the peer registry migration permission */ function setPeerRegistryMigrationPermission(address peer, MigrationPermission permission) external { // Executed through logic contract _fallback(); } /** * @inheritdoc MigratableKeeperRegistryInterface */ function migrateUpkeeps(uint256[] calldata ids, address destination) external override { // Executed through logic contract _fallback(); } /** * @inheritdoc MigratableKeeperRegistryInterface */ UpkeepFormat public constant override upkeepTranscoderVersion = UPKEEP_TRANSCODER_VERSION_BASE; /** * @inheritdoc MigratableKeeperRegistryInterface */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external override { // Executed through logic contract _fallback(); } /** * @dev This is the address to which proxy functions are delegated to */ function _implementation() internal view override returns (address) { return KEEPER_REGISTRY_LOGIC; } /** * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available */ function _callWithExactGas( uint256 gasAmount, address target, bytes memory data ) private returns (bool success) { assembly { let g := gas() // Compute g -= PERFORM_GAS_CUSHION and check for underflow if lt(g, PERFORM_GAS_CUSHION) { revert(0, 0) } g := sub(g, PERFORM_GAS_CUSHION) // if g - g//64 <= gasAmount, revert // (we subtract g//64 because of EIP-150) if iszero(gt(sub(g, div(g, 64)), gasAmount)) { revert(0, 0) } // solidity calls check that a contract actually exists at the destination, so we do the same if iszero(extcodesize(target)) { revert(0, 0) } // call and return whether we succeeded. ignore return data success := call(gasAmount, target, 0, add(data, 0x20), mload(data), 0, 0) } return success; } /** * @dev calls the Upkeep target with the performData param passed in by the * keeper and the exact gas required by the Upkeep */ function _performUpkeepWithParams(PerformParams memory params) private nonReentrant returns (bool success) { Upkeep memory upkeep = s_upkeep[params.id]; if (upkeep.maxValidBlocknumber <= block.number) revert UpkeepCancelled(); _prePerformUpkeep(upkeep, params.from, params.maxLinkPayment); uint256 gasUsed = gasleft(); bytes memory callData = abi.encodeWithSelector(PERFORM_SELECTOR, params.performData); success = _callWithExactGas(params.gasLimit, upkeep.target, callData); gasUsed = gasUsed - gasleft(); uint96 payment = _calculatePaymentAmount(gasUsed, params.fastGasWei, params.linkEth, true); s_upkeep[params.id].balance = s_upkeep[params.id].balance - payment; s_upkeep[params.id].amountSpent = s_upkeep[params.id].amountSpent + payment; s_upkeep[params.id].lastKeeper = params.from; s_keeperInfo[params.from].balance = s_keeperInfo[params.from].balance + payment; emit UpkeepPerformed(params.id, success, params.from, payment, params.performData); return success; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; abstract contract TypeAndVersionInterface { function typeAndVersion() external pure virtual returns (string memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.6; interface ERC677ReceiverInterface { function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../ConfirmedOwner.sol"; import "../interfaces/KeeperCompatibleInterface.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; /** * @title The EthBalanceMonitor contract * @notice A keeper-compatible contract that monitors and funds eth addresses */ contract EthBalanceMonitor is ConfirmedOwner, Pausable, KeeperCompatibleInterface { // observed limit of 45K + 10k buffer uint256 private constant MIN_GAS_FOR_TRANSFER = 55_000; event FundsAdded(uint256 amountAdded, uint256 newBalance, address sender); event FundsWithdrawn(uint256 amountWithdrawn, address payee); event TopUpSucceeded(address indexed recipient); event TopUpFailed(address indexed recipient); event KeeperRegistryAddressUpdated(address oldAddress, address newAddress); event MinWaitPeriodUpdated(uint256 oldMinWaitPeriod, uint256 newMinWaitPeriod); error InvalidWatchList(); error OnlyKeeperRegistry(); error DuplicateAddress(address duplicate); struct Target { bool isActive; uint96 minBalanceWei; uint96 topUpAmountWei; uint56 lastTopUpTimestamp; // enough space for 2 trillion years } address private s_keeperRegistryAddress; uint256 private s_minWaitPeriodSeconds; address[] private s_watchList; mapping(address => Target) internal s_targets; /** * @param keeperRegistryAddress The address of the keeper registry contract * @param minWaitPeriodSeconds The minimum wait period for addresses between funding */ constructor(address keeperRegistryAddress, uint256 minWaitPeriodSeconds) ConfirmedOwner(msg.sender) { setKeeperRegistryAddress(keeperRegistryAddress); setMinWaitPeriodSeconds(minWaitPeriodSeconds); } /** * @notice Sets the list of addresses to watch and their funding parameters * @param addresses the list of addresses to watch * @param minBalancesWei the minimum balances for each address * @param topUpAmountsWei the amount to top up each address */ function setWatchList( address[] calldata addresses, uint96[] calldata minBalancesWei, uint96[] calldata topUpAmountsWei ) external onlyOwner { if (addresses.length != minBalancesWei.length || addresses.length != topUpAmountsWei.length) { revert InvalidWatchList(); } address[] memory oldWatchList = s_watchList; for (uint256 idx = 0; idx < oldWatchList.length; idx++) { s_targets[oldWatchList[idx]].isActive = false; } for (uint256 idx = 0; idx < addresses.length; idx++) { if (s_targets[addresses[idx]].isActive) { revert DuplicateAddress(addresses[idx]); } if (addresses[idx] == address(0)) { revert InvalidWatchList(); } if (topUpAmountsWei[idx] == 0) { revert InvalidWatchList(); } s_targets[addresses[idx]] = Target({ isActive: true, minBalanceWei: minBalancesWei[idx], topUpAmountWei: topUpAmountsWei[idx], lastTopUpTimestamp: 0 }); } s_watchList = addresses; } /** * @notice Gets a list of addresses that are under funded * @return list of addresses that are underfunded */ function getUnderfundedAddresses() public view returns (address[] memory) { address[] memory watchList = s_watchList; address[] memory needsFunding = new address[](watchList.length); uint256 count = 0; uint256 minWaitPeriod = s_minWaitPeriodSeconds; uint256 balance = address(this).balance; Target memory target; for (uint256 idx = 0; idx < watchList.length; idx++) { target = s_targets[watchList[idx]]; if ( target.lastTopUpTimestamp + minWaitPeriod <= block.timestamp && balance >= target.topUpAmountWei && watchList[idx].balance < target.minBalanceWei ) { needsFunding[count] = watchList[idx]; count++; balance -= target.topUpAmountWei; } } if (count != watchList.length) { assembly { mstore(needsFunding, count) } } return needsFunding; } /** * @notice Send funds to the addresses provided * @param needsFunding the list of addresses to fund (addresses must be pre-approved) */ function topUp(address[] memory needsFunding) public whenNotPaused { uint256 minWaitPeriodSeconds = s_minWaitPeriodSeconds; Target memory target; for (uint256 idx = 0; idx < needsFunding.length; idx++) { target = s_targets[needsFunding[idx]]; if ( target.isActive && target.lastTopUpTimestamp + minWaitPeriodSeconds <= block.timestamp && needsFunding[idx].balance < target.minBalanceWei ) { bool success = payable(needsFunding[idx]).send(target.topUpAmountWei); if (success) { s_targets[needsFunding[idx]].lastTopUpTimestamp = uint56(block.timestamp); emit TopUpSucceeded(needsFunding[idx]); } else { emit TopUpFailed(needsFunding[idx]); } } if (gasleft() < MIN_GAS_FOR_TRANSFER) { return; } } } /** * @notice Get list of addresses that are underfunded and return keeper-compatible payload * @return upkeepNeeded signals if upkeep is needed, performData is an abi encoded list of addresses that need funds */ function checkUpkeep(bytes calldata) external view override whenNotPaused returns (bool upkeepNeeded, bytes memory performData) { address[] memory needsFunding = getUnderfundedAddresses(); upkeepNeeded = needsFunding.length > 0; performData = abi.encode(needsFunding); return (upkeepNeeded, performData); } /** * @notice Called by keeper to send funds to underfunded addresses * @param performData The abi encoded list of addresses to fund */ function performUpkeep(bytes calldata performData) external override onlyKeeperRegistry whenNotPaused { address[] memory needsFunding = abi.decode(performData, (address[])); topUp(needsFunding); } /** * @notice Withdraws the contract balance * @param amount The amount of eth (in wei) to withdraw * @param payee The address to pay */ function withdraw(uint256 amount, address payable payee) external onlyOwner { require(payee != address(0)); emit FundsWithdrawn(amount, payee); payee.transfer(amount); } /** * @notice Receive funds */ receive() external payable { emit FundsAdded(msg.value, address(this).balance, msg.sender); } /** * @notice Sets the keeper registry address */ function setKeeperRegistryAddress(address keeperRegistryAddress) public onlyOwner { require(keeperRegistryAddress != address(0)); emit KeeperRegistryAddressUpdated(s_keeperRegistryAddress, keeperRegistryAddress); s_keeperRegistryAddress = keeperRegistryAddress; } /** * @notice Sets the minimum wait period (in seconds) for addresses between funding */ function setMinWaitPeriodSeconds(uint256 period) public onlyOwner { emit MinWaitPeriodUpdated(s_minWaitPeriodSeconds, period); s_minWaitPeriodSeconds = period; } /** * @notice Gets the keeper registry address */ function getKeeperRegistryAddress() external view returns (address keeperRegistryAddress) { return s_keeperRegistryAddress; } /** * @notice Gets the minimum wait period */ function getMinWaitPeriodSeconds() external view returns (uint256) { return s_minWaitPeriodSeconds; } /** * @notice Gets the list of addresses being watched */ function getWatchList() external view returns (address[] memory) { return s_watchList; } /** * @notice Gets configuration information for an address on the watchlist */ function getAccountInfo(address targetAddress) external view returns ( bool isActive, uint96 minBalanceWei, uint96 topUpAmountWei, uint56 lastTopUpTimestamp ) { Target memory target = s_targets[targetAddress]; return (target.isActive, target.minBalanceWei, target.topUpAmountWei, target.lastTopUpTimestamp); } /** * @notice Pauses the contract, which prevents executing performUpkeep */ function pause() external onlyOwner { _pause(); } /** * @notice Unpauses the contract */ function unpause() external onlyOwner { _unpause(); } modifier onlyKeeperRegistry() { if (msg.sender != s_keeperRegistryAddress) { revert OnlyKeeperRegistry(); } _; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "./KeeperBase.sol"; import "./ConfirmedOwner.sol"; import "./interfaces/TypeAndVersionInterface.sol"; import "./interfaces/AggregatorV3Interface.sol"; import "./interfaces/LinkTokenInterface.sol"; import "./interfaces/KeeperCompatibleInterface.sol"; import "./interfaces/KeeperRegistryInterface1_2.sol"; import "./interfaces/MigratableKeeperRegistryInterface.sol"; import "./interfaces/UpkeepTranscoderInterface.sol"; import "./interfaces/ERC677ReceiverInterface.sol"; /** * @notice Registry for adding work for Chainlink Keepers to perform on client * contracts. Clients must support the Upkeep interface. */ contract KeeperRegistry1_2 is TypeAndVersionInterface, ConfirmedOwner, KeeperBase, ReentrancyGuard, Pausable, KeeperRegistryExecutableInterface, MigratableKeeperRegistryInterface, ERC677ReceiverInterface { using Address for address; using EnumerableSet for EnumerableSet.UintSet; address private constant ZERO_ADDRESS = address(0); address private constant IGNORE_ADDRESS = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF; bytes4 private constant CHECK_SELECTOR = KeeperCompatibleInterface.checkUpkeep.selector; bytes4 private constant PERFORM_SELECTOR = KeeperCompatibleInterface.performUpkeep.selector; uint256 private constant PERFORM_GAS_MIN = 2_300; uint256 private constant CANCELATION_DELAY = 50; uint256 private constant PERFORM_GAS_CUSHION = 5_000; uint256 private constant REGISTRY_GAS_OVERHEAD = 80_000; uint256 private constant PPB_BASE = 1_000_000_000; uint64 private constant UINT64_MAX = 2**64 - 1; uint96 private constant LINK_TOTAL_SUPPLY = 1e27; address[] private s_keeperList; EnumerableSet.UintSet private s_upkeepIDs; mapping(uint256 => Upkeep) private s_upkeep; mapping(address => KeeperInfo) private s_keeperInfo; mapping(address => address) private s_proposedPayee; mapping(uint256 => bytes) private s_checkData; mapping(address => MigrationPermission) private s_peerRegistryMigrationPermission; Storage private s_storage; uint256 private s_fallbackGasPrice; // not in config object for gas savings uint256 private s_fallbackLinkPrice; // not in config object for gas savings uint96 private s_ownerLinkBalance; uint256 private s_expectedLinkBalance; address private s_transcoder; address private s_registrar; LinkTokenInterface public immutable LINK; AggregatorV3Interface public immutable LINK_ETH_FEED; AggregatorV3Interface public immutable FAST_GAS_FEED; /** * @notice versions: * - KeeperRegistry 1.2.0: allow funding within performUpkeep * : allow configurable registry maxPerformGas * : add function to let admin change upkeep gas limit * : add minUpkeepSpend requirement : upgrade to solidity v0.8 * - KeeperRegistry 1.1.0: added flatFeeMicroLink * - KeeperRegistry 1.0.0: initial release */ string public constant override typeAndVersion = "KeeperRegistry 1.2.0"; error CannotCancel(); error UpkeepNotActive(); error MigrationNotPermitted(); error UpkeepNotCanceled(); error UpkeepNotNeeded(); error NotAContract(); error PaymentGreaterThanAllLINK(); error OnlyActiveKeepers(); error InsufficientFunds(); error KeepersMustTakeTurns(); error ParameterLengthError(); error OnlyCallableByOwnerOrAdmin(); error OnlyCallableByLINKToken(); error InvalidPayee(); error DuplicateEntry(); error ValueNotChanged(); error IndexOutOfRange(); error TranscoderNotSet(); error ArrayHasNoEntries(); error GasLimitOutsideRange(); error OnlyCallableByPayee(); error OnlyCallableByProposedPayee(); error GasLimitCanOnlyIncrease(); error OnlyCallableByAdmin(); error OnlyCallableByOwnerOrRegistrar(); error InvalidRecipient(); error InvalidDataLength(); error TargetCheckReverted(bytes reason); enum MigrationPermission { NONE, OUTGOING, INCOMING, BIDIRECTIONAL } /** * @notice storage of the registry, contains a mix of config and state data */ struct Storage { uint32 paymentPremiumPPB; uint32 flatFeeMicroLink; uint24 blockCountPerTurn; uint32 checkGasLimit; uint24 stalenessSeconds; uint16 gasCeilingMultiplier; uint96 minUpkeepSpend; // 1 evm word uint32 maxPerformGas; uint32 nonce; // 2 evm words } struct Upkeep { uint96 balance; address lastKeeper; // 1 storage slot full uint32 executeGas; uint64 maxValidBlocknumber; address target; // 2 storage slots full uint96 amountSpent; address admin; // 3 storage slots full } struct KeeperInfo { address payee; uint96 balance; bool active; } struct PerformParams { address from; uint256 id; bytes performData; uint256 maxLinkPayment; uint256 gasLimit; uint256 adjustedGasWei; uint256 linkEth; } event UpkeepRegistered(uint256 indexed id, uint32 executeGas, address admin); event UpkeepPerformed( uint256 indexed id, bool indexed success, address indexed from, uint96 payment, bytes performData ); event UpkeepCanceled(uint256 indexed id, uint64 indexed atBlockHeight); event FundsAdded(uint256 indexed id, address indexed from, uint96 amount); event FundsWithdrawn(uint256 indexed id, uint256 amount, address to); event OwnerFundsWithdrawn(uint96 amount); event UpkeepMigrated(uint256 indexed id, uint256 remainingBalance, address destination); event UpkeepReceived(uint256 indexed id, uint256 startingBalance, address importedFrom); event ConfigSet(Config config); event KeepersUpdated(address[] keepers, address[] payees); event PaymentWithdrawn(address indexed keeper, uint256 indexed amount, address indexed to, address payee); event PayeeshipTransferRequested(address indexed keeper, address indexed from, address indexed to); event PayeeshipTransferred(address indexed keeper, address indexed from, address indexed to); event UpkeepGasLimitSet(uint256 indexed id, uint96 gasLimit); /** * @param link address of the LINK Token * @param linkEthFeed address of the LINK/ETH price feed * @param fastGasFeed address of the Fast Gas price feed * @param config registry config settings */ constructor( address link, address linkEthFeed, address fastGasFeed, Config memory config ) ConfirmedOwner(msg.sender) { LINK = LinkTokenInterface(link); LINK_ETH_FEED = AggregatorV3Interface(linkEthFeed); FAST_GAS_FEED = AggregatorV3Interface(fastGasFeed); setConfig(config); } // ACTIONS /** * @notice adds a new upkeep * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep */ function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData ) external override onlyOwnerOrRegistrar returns (uint256 id) { id = uint256(keccak256(abi.encodePacked(blockhash(block.number - 1), address(this), s_storage.nonce))); _createUpkeep(id, target, gasLimit, admin, 0, checkData); s_storage.nonce++; emit UpkeepRegistered(id, gasLimit, admin); return id; } /** * @notice simulated by keepers via eth_call to see if the upkeep needs to be * performed. If upkeep is needed, the call then simulates performUpkeep * to make sure it succeeds. Finally, it returns the success status along with * payment information and the perform data payload. * @param id identifier of the upkeep to check * @param from the address to simulate performing the upkeep from */ function checkUpkeep(uint256 id, address from) external override cannotExecute returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ) { Upkeep memory upkeep = s_upkeep[id]; bytes memory callData = abi.encodeWithSelector(CHECK_SELECTOR, s_checkData[id]); (bool success, bytes memory result) = upkeep.target.call{gas: s_storage.checkGasLimit}(callData); if (!success) revert TargetCheckReverted(result); (success, performData) = abi.decode(result, (bool, bytes)); if (!success) revert UpkeepNotNeeded(); PerformParams memory params = _generatePerformParams(from, id, performData, false); _prePerformUpkeep(upkeep, params.from, params.maxLinkPayment); return (performData, params.maxLinkPayment, params.gasLimit, params.adjustedGasWei, params.linkEth); } /** * @notice executes the upkeep with the perform data returned from * checkUpkeep, validates the keeper's permissions, and pays the keeper. * @param id identifier of the upkeep to execute the data with. * @param performData calldata parameter to be passed to the target upkeep. */ function performUpkeep(uint256 id, bytes calldata performData) external override whenNotPaused returns (bool success) { return _performUpkeepWithParams(_generatePerformParams(msg.sender, id, performData, true)); } /** * @notice prevent an upkeep from being performed in the future * @param id upkeep to be canceled */ function cancelUpkeep(uint256 id) external override { uint64 maxValid = s_upkeep[id].maxValidBlocknumber; bool canceled = maxValid != UINT64_MAX; bool isOwner = msg.sender == owner(); if (canceled && !(isOwner && maxValid > block.number)) revert CannotCancel(); if (!isOwner && msg.sender != s_upkeep[id].admin) revert OnlyCallableByOwnerOrAdmin(); uint256 height = block.number; if (!isOwner) { height = height + CANCELATION_DELAY; } s_upkeep[id].maxValidBlocknumber = uint64(height); s_upkeepIDs.remove(id); emit UpkeepCanceled(id, uint64(height)); } /** * @notice adds LINK funding for an upkeep by transferring from the sender's * LINK balance * @param id upkeep to fund * @param amount number of LINK to transfer */ function addFunds(uint256 id, uint96 amount) external override onlyActiveUpkeep(id) { s_upkeep[id].balance = s_upkeep[id].balance + amount; s_expectedLinkBalance = s_expectedLinkBalance + amount; LINK.transferFrom(msg.sender, address(this), amount); emit FundsAdded(id, msg.sender, amount); } /** * @notice uses LINK's transferAndCall to LINK and add funding to an upkeep * @dev safe to cast uint256 to uint96 as total LINK supply is under UINT96MAX * @param sender the account which transferred the funds * @param amount number of LINK transfer */ function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external override { if (msg.sender != address(LINK)) revert OnlyCallableByLINKToken(); if (data.length != 32) revert InvalidDataLength(); uint256 id = abi.decode(data, (uint256)); if (s_upkeep[id].maxValidBlocknumber != UINT64_MAX) revert UpkeepNotActive(); s_upkeep[id].balance = s_upkeep[id].balance + uint96(amount); s_expectedLinkBalance = s_expectedLinkBalance + amount; emit FundsAdded(id, sender, uint96(amount)); } /** * @notice removes funding from a canceled upkeep * @param id upkeep to withdraw funds from * @param to destination address for sending remaining funds */ function withdrawFunds(uint256 id, address to) external validRecipient(to) onlyUpkeepAdmin(id) { if (s_upkeep[id].maxValidBlocknumber > block.number) revert UpkeepNotCanceled(); uint96 minUpkeepSpend = s_storage.minUpkeepSpend; uint96 amountLeft = s_upkeep[id].balance; uint96 amountSpent = s_upkeep[id].amountSpent; uint96 cancellationFee = 0; // cancellationFee is supposed to be min(max(minUpkeepSpend - amountSpent,0), amountLeft) if (amountSpent < minUpkeepSpend) { cancellationFee = minUpkeepSpend - amountSpent; if (cancellationFee > amountLeft) { cancellationFee = amountLeft; } } uint96 amountToWithdraw = amountLeft - cancellationFee; s_upkeep[id].balance = 0; s_ownerLinkBalance = s_ownerLinkBalance + cancellationFee; s_expectedLinkBalance = s_expectedLinkBalance - amountToWithdraw; emit FundsWithdrawn(id, amountToWithdraw, to); LINK.transfer(to, amountToWithdraw); } /** * @notice withdraws LINK funds collected through cancellation fees */ function withdrawOwnerFunds() external onlyOwner { uint96 amount = s_ownerLinkBalance; s_expectedLinkBalance = s_expectedLinkBalance - amount; s_ownerLinkBalance = 0; emit OwnerFundsWithdrawn(amount); LINK.transfer(msg.sender, amount); } /** * @notice allows the admin of an upkeep to modify gas limit * @param id upkeep to be change the gas limit for * @param gasLimit new gas limit for the upkeep */ function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external override onlyActiveUpkeep(id) onlyUpkeepAdmin(id) { if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); s_upkeep[id].executeGas = gasLimit; emit UpkeepGasLimitSet(id, gasLimit); } /** * @notice recovers LINK funds improperly transferred to the registry * @dev In principle this function’s execution cost could exceed block * gas limit. However, in our anticipated deployment, the number of upkeeps and * keepers will be low enough to avoid this problem. */ function recoverFunds() external onlyOwner { uint256 total = LINK.balanceOf(address(this)); LINK.transfer(msg.sender, total - s_expectedLinkBalance); } /** * @notice withdraws a keeper's payment, callable only by the keeper's payee * @param from keeper address * @param to address to send the payment to */ function withdrawPayment(address from, address to) external validRecipient(to) { KeeperInfo memory keeper = s_keeperInfo[from]; if (keeper.payee != msg.sender) revert OnlyCallableByPayee(); s_keeperInfo[from].balance = 0; s_expectedLinkBalance = s_expectedLinkBalance - keeper.balance; emit PaymentWithdrawn(from, keeper.balance, to, msg.sender); LINK.transfer(to, keeper.balance); } /** * @notice proposes the safe transfer of a keeper's payee to another address * @param keeper address of the keeper to transfer payee role * @param proposed address to nominate for next payeeship */ function transferPayeeship(address keeper, address proposed) external { if (s_keeperInfo[keeper].payee != msg.sender) revert OnlyCallableByPayee(); if (proposed == msg.sender) revert ValueNotChanged(); if (s_proposedPayee[keeper] != proposed) { s_proposedPayee[keeper] = proposed; emit PayeeshipTransferRequested(keeper, msg.sender, proposed); } } /** * @notice accepts the safe transfer of payee role for a keeper * @param keeper address to accept the payee role for */ function acceptPayeeship(address keeper) external { if (s_proposedPayee[keeper] != msg.sender) revert OnlyCallableByProposedPayee(); address past = s_keeperInfo[keeper].payee; s_keeperInfo[keeper].payee = msg.sender; s_proposedPayee[keeper] = ZERO_ADDRESS; emit PayeeshipTransferred(keeper, past, msg.sender); } /** * @notice signals to keepers that they should not perform upkeeps until the * contract has been unpaused */ function pause() external onlyOwner { _pause(); } /** * @notice signals to keepers that they can perform upkeeps once again after * having been paused */ function unpause() external onlyOwner { _unpause(); } // SETTERS /** * @notice updates the configuration of the registry * @param config registry config fields */ function setConfig(Config memory config) public onlyOwner { if (config.maxPerformGas < s_storage.maxPerformGas) revert GasLimitCanOnlyIncrease(); s_storage = Storage({ paymentPremiumPPB: config.paymentPremiumPPB, flatFeeMicroLink: config.flatFeeMicroLink, blockCountPerTurn: config.blockCountPerTurn, checkGasLimit: config.checkGasLimit, stalenessSeconds: config.stalenessSeconds, gasCeilingMultiplier: config.gasCeilingMultiplier, minUpkeepSpend: config.minUpkeepSpend, maxPerformGas: config.maxPerformGas, nonce: s_storage.nonce }); s_fallbackGasPrice = config.fallbackGasPrice; s_fallbackLinkPrice = config.fallbackLinkPrice; s_transcoder = config.transcoder; s_registrar = config.registrar; emit ConfigSet(config); } /** * @notice update the list of keepers allowed to perform upkeep * @param keepers list of addresses allowed to perform upkeep * @param payees addresses corresponding to keepers who are allowed to * move payments which have been accrued */ function setKeepers(address[] calldata keepers, address[] calldata payees) external onlyOwner { if (keepers.length != payees.length || keepers.length < 2) revert ParameterLengthError(); for (uint256 i = 0; i < s_keeperList.length; i++) { address keeper = s_keeperList[i]; s_keeperInfo[keeper].active = false; } for (uint256 i = 0; i < keepers.length; i++) { address keeper = keepers[i]; KeeperInfo storage s_keeper = s_keeperInfo[keeper]; address oldPayee = s_keeper.payee; address newPayee = payees[i]; if ( (newPayee == ZERO_ADDRESS) || (oldPayee != ZERO_ADDRESS && oldPayee != newPayee && newPayee != IGNORE_ADDRESS) ) revert InvalidPayee(); if (s_keeper.active) revert DuplicateEntry(); s_keeper.active = true; if (newPayee != IGNORE_ADDRESS) { s_keeper.payee = newPayee; } } s_keeperList = keepers; emit KeepersUpdated(keepers, payees); } // GETTERS /** * @notice read all of the details about an upkeep */ function getUpkeep(uint256 id) external view override returns ( address target, uint32 executeGas, bytes memory checkData, uint96 balance, address lastKeeper, address admin, uint64 maxValidBlocknumber, uint96 amountSpent ) { Upkeep memory reg = s_upkeep[id]; return ( reg.target, reg.executeGas, s_checkData[id], reg.balance, reg.lastKeeper, reg.admin, reg.maxValidBlocknumber, reg.amountSpent ); } /** * @notice retrieve active upkeep IDs * @param startIndex starting index in list * @param maxCount max count to retrieve (0 = unlimited) * @dev the order of IDs in the list is **not guaranteed**, therefore, if making successive calls, one * should consider keeping the blockheight constant to ensure a wholistic picture of the contract state */ function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view override returns (uint256[] memory) { uint256 maxIdx = s_upkeepIDs.length(); if (startIndex >= maxIdx) revert IndexOutOfRange(); if (maxCount == 0) { maxCount = maxIdx - startIndex; } uint256[] memory ids = new uint256[](maxCount); for (uint256 idx = 0; idx < maxCount; idx++) { ids[idx] = s_upkeepIDs.at(startIndex + idx); } return ids; } /** * @notice read the current info about any keeper address */ function getKeeperInfo(address query) external view override returns ( address payee, bool active, uint96 balance ) { KeeperInfo memory keeper = s_keeperInfo[query]; return (keeper.payee, keeper.active, keeper.balance); } /** * @notice read the current state of the registry */ function getState() external view override returns ( State memory state, Config memory config, address[] memory keepers ) { Storage memory store = s_storage; state.nonce = store.nonce; state.ownerLinkBalance = s_ownerLinkBalance; state.expectedLinkBalance = s_expectedLinkBalance; state.numUpkeeps = s_upkeepIDs.length(); config.paymentPremiumPPB = store.paymentPremiumPPB; config.flatFeeMicroLink = store.flatFeeMicroLink; config.blockCountPerTurn = store.blockCountPerTurn; config.checkGasLimit = store.checkGasLimit; config.stalenessSeconds = store.stalenessSeconds; config.gasCeilingMultiplier = store.gasCeilingMultiplier; config.minUpkeepSpend = store.minUpkeepSpend; config.maxPerformGas = store.maxPerformGas; config.fallbackGasPrice = s_fallbackGasPrice; config.fallbackLinkPrice = s_fallbackLinkPrice; config.transcoder = s_transcoder; config.registrar = s_registrar; return (state, config, s_keeperList); } /** * @notice calculates the minimum balance required for an upkeep to remain eligible * @param id the upkeep id to calculate minimum balance for */ function getMinBalanceForUpkeep(uint256 id) external view returns (uint96 minBalance) { return getMaxPaymentForGas(s_upkeep[id].executeGas); } /** * @notice calculates the maximum payment for a given gas limit * @param gasLimit the gas to calculate payment for */ function getMaxPaymentForGas(uint256 gasLimit) public view returns (uint96 maxPayment) { (uint256 gasWei, uint256 linkEth) = _getFeedData(); uint256 adjustedGasWei = _adjustGasPrice(gasWei, false); return _calculatePaymentAmount(gasLimit, adjustedGasWei, linkEth); } /** * @notice retrieves the migration permission for a peer registry */ function getPeerRegistryMigrationPermission(address peer) external view returns (MigrationPermission) { return s_peerRegistryMigrationPermission[peer]; } /** * @notice sets the peer registry migration permission */ function setPeerRegistryMigrationPermission(address peer, MigrationPermission permission) external onlyOwner { s_peerRegistryMigrationPermission[peer] = permission; } /** * @inheritdoc MigratableKeeperRegistryInterface */ function migrateUpkeeps(uint256[] calldata ids, address destination) external override { if ( s_peerRegistryMigrationPermission[destination] != MigrationPermission.OUTGOING && s_peerRegistryMigrationPermission[destination] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); if (s_transcoder == ZERO_ADDRESS) revert TranscoderNotSet(); if (ids.length == 0) revert ArrayHasNoEntries(); uint256 id; Upkeep memory upkeep; uint256 totalBalanceRemaining; bytes[] memory checkDatas = new bytes[](ids.length); Upkeep[] memory upkeeps = new Upkeep[](ids.length); for (uint256 idx = 0; idx < ids.length; idx++) { id = ids[idx]; upkeep = s_upkeep[id]; if (upkeep.admin != msg.sender) revert OnlyCallableByAdmin(); if (upkeep.maxValidBlocknumber != UINT64_MAX) revert UpkeepNotActive(); upkeeps[idx] = upkeep; checkDatas[idx] = s_checkData[id]; totalBalanceRemaining = totalBalanceRemaining + upkeep.balance; delete s_upkeep[id]; delete s_checkData[id]; s_upkeepIDs.remove(id); emit UpkeepMigrated(id, upkeep.balance, destination); } s_expectedLinkBalance = s_expectedLinkBalance - totalBalanceRemaining; bytes memory encodedUpkeeps = abi.encode(ids, upkeeps, checkDatas); MigratableKeeperRegistryInterface(destination).receiveUpkeeps( UpkeepTranscoderInterface(s_transcoder).transcodeUpkeeps( UpkeepFormat.V1, MigratableKeeperRegistryInterface(destination).upkeepTranscoderVersion(), encodedUpkeeps ) ); LINK.transfer(destination, totalBalanceRemaining); } /** * @inheritdoc MigratableKeeperRegistryInterface */ UpkeepFormat public constant override upkeepTranscoderVersion = UpkeepFormat.V1; /** * @inheritdoc MigratableKeeperRegistryInterface */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external override { if ( s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.INCOMING && s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); (uint256[] memory ids, Upkeep[] memory upkeeps, bytes[] memory checkDatas) = abi.decode( encodedUpkeeps, (uint256[], Upkeep[], bytes[]) ); for (uint256 idx = 0; idx < ids.length; idx++) { _createUpkeep( ids[idx], upkeeps[idx].target, upkeeps[idx].executeGas, upkeeps[idx].admin, upkeeps[idx].balance, checkDatas[idx] ); emit UpkeepReceived(ids[idx], upkeeps[idx].balance, msg.sender); } } /** * @notice creates a new upkeep with the given fields * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep */ function _createUpkeep( uint256 id, address target, uint32 gasLimit, address admin, uint96 balance, bytes memory checkData ) internal whenNotPaused { if (!target.isContract()) revert NotAContract(); if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); s_upkeep[id] = Upkeep({ target: target, executeGas: gasLimit, balance: balance, admin: admin, maxValidBlocknumber: UINT64_MAX, lastKeeper: ZERO_ADDRESS, amountSpent: 0 }); s_expectedLinkBalance = s_expectedLinkBalance + balance; s_checkData[id] = checkData; s_upkeepIDs.add(id); } /** * @dev retrieves feed data for fast gas/eth and link/eth prices. if the feed * data is stale it uses the configured fallback price. Once a price is picked * for gas it takes the min of gas price in the transaction or the fast gas * price in order to reduce costs for the upkeep clients. */ function _getFeedData() private view returns (uint256 gasWei, uint256 linkEth) { uint32 stalenessSeconds = s_storage.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; uint256 timestamp; int256 feedValue; (, feedValue, , timestamp, ) = FAST_GAS_FEED.latestRoundData(); if ((staleFallback && stalenessSeconds < block.timestamp - timestamp) || feedValue <= 0) { gasWei = s_fallbackGasPrice; } else { gasWei = uint256(feedValue); } (, feedValue, , timestamp, ) = LINK_ETH_FEED.latestRoundData(); if ((staleFallback && stalenessSeconds < block.timestamp - timestamp) || feedValue <= 0) { linkEth = s_fallbackLinkPrice; } else { linkEth = uint256(feedValue); } return (gasWei, linkEth); } /** * @dev calculates LINK paid for gas spent plus a configure premium percentage */ function _calculatePaymentAmount( uint256 gasLimit, uint256 gasWei, uint256 linkEth ) private view returns (uint96 payment) { uint256 weiForGas = gasWei * (gasLimit + REGISTRY_GAS_OVERHEAD); uint256 premium = PPB_BASE + s_storage.paymentPremiumPPB; uint256 total = ((weiForGas * (1e9) * (premium)) / (linkEth)) + (uint256(s_storage.flatFeeMicroLink) * (1e12)); if (total > LINK_TOTAL_SUPPLY) revert PaymentGreaterThanAllLINK(); return uint96(total); // LINK_TOTAL_SUPPLY < UINT96_MAX } /** * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available */ function _callWithExactGas( uint256 gasAmount, address target, bytes memory data ) private returns (bool success) { assembly { let g := gas() // Compute g -= PERFORM_GAS_CUSHION and check for underflow if lt(g, PERFORM_GAS_CUSHION) { revert(0, 0) } g := sub(g, PERFORM_GAS_CUSHION) // if g - g//64 <= gasAmount, revert // (we subtract g//64 because of EIP-150) if iszero(gt(sub(g, div(g, 64)), gasAmount)) { revert(0, 0) } // solidity calls check that a contract actually exists at the destination, so we do the same if iszero(extcodesize(target)) { revert(0, 0) } // call and return whether we succeeded. ignore return data success := call(gasAmount, target, 0, add(data, 0x20), mload(data), 0, 0) } return success; } /** * @dev calls the Upkeep target with the performData param passed in by the * keeper and the exact gas required by the Upkeep */ function _performUpkeepWithParams(PerformParams memory params) private nonReentrant validUpkeep(params.id) returns (bool success) { Upkeep memory upkeep = s_upkeep[params.id]; _prePerformUpkeep(upkeep, params.from, params.maxLinkPayment); uint256 gasUsed = gasleft(); bytes memory callData = abi.encodeWithSelector(PERFORM_SELECTOR, params.performData); success = _callWithExactGas(params.gasLimit, upkeep.target, callData); gasUsed = gasUsed - gasleft(); uint96 payment = _calculatePaymentAmount(gasUsed, params.adjustedGasWei, params.linkEth); s_upkeep[params.id].balance = s_upkeep[params.id].balance - payment; s_upkeep[params.id].amountSpent = s_upkeep[params.id].amountSpent + payment; s_upkeep[params.id].lastKeeper = params.from; s_keeperInfo[params.from].balance = s_keeperInfo[params.from].balance + payment; emit UpkeepPerformed(params.id, success, params.from, payment, params.performData); return success; } /** * @dev ensures all required checks are passed before an upkeep is performed */ function _prePerformUpkeep( Upkeep memory upkeep, address from, uint256 maxLinkPayment ) private view { if (!s_keeperInfo[from].active) revert OnlyActiveKeepers(); if (upkeep.balance < maxLinkPayment) revert InsufficientFunds(); if (upkeep.lastKeeper == from) revert KeepersMustTakeTurns(); } /** * @dev adjusts the gas price to min(ceiling, tx.gasprice) or just uses the ceiling if tx.gasprice is disabled */ function _adjustGasPrice(uint256 gasWei, bool useTxGasPrice) private view returns (uint256 adjustedPrice) { adjustedPrice = gasWei * s_storage.gasCeilingMultiplier; if (useTxGasPrice && tx.gasprice < adjustedPrice) { adjustedPrice = tx.gasprice; } } /** * @dev generates a PerformParams struct for use in _performUpkeepWithParams() */ function _generatePerformParams( address from, uint256 id, bytes memory performData, bool useTxGasPrice ) private view returns (PerformParams memory) { uint256 gasLimit = s_upkeep[id].executeGas; (uint256 gasWei, uint256 linkEth) = _getFeedData(); uint256 adjustedGasWei = _adjustGasPrice(gasWei, useTxGasPrice); uint96 maxLinkPayment = _calculatePaymentAmount(gasLimit, adjustedGasWei, linkEth); return PerformParams({ from: from, id: id, performData: performData, maxLinkPayment: maxLinkPayment, gasLimit: gasLimit, adjustedGasWei: adjustedGasWei, linkEth: linkEth }); } // MODIFIERS /** * @dev ensures a upkeep is valid */ modifier validUpkeep(uint256 id) { if (s_upkeep[id].maxValidBlocknumber <= block.number) revert UpkeepNotActive(); _; } /** * @dev Reverts if called by anyone other than the admin of upkeep #id */ modifier onlyUpkeepAdmin(uint256 id) { if (msg.sender != s_upkeep[id].admin) revert OnlyCallableByAdmin(); _; } /** * @dev Reverts if called on a cancelled upkeep */ modifier onlyActiveUpkeep(uint256 id) { if (s_upkeep[id].maxValidBlocknumber != UINT64_MAX) revert UpkeepNotActive(); _; } /** * @dev ensures that burns don't accidentally happen by sending to the zero * address */ modifier validRecipient(address to) { if (to == ZERO_ADDRESS) revert InvalidRecipient(); _; } /** * @dev Reverts if called by anyone other than the contract owner or registrar. */ modifier onlyOwnerOrRegistrar() { if (msg.sender != owner() && msg.sender != s_registrar) revert OnlyCallableByOwnerOrRegistrar(); _; } }
// SPDX-License-Identifier: MIT /** * @notice This is a deprecated interface. Please use AutomationBase directly. */ pragma solidity ^0.8.0; import {AutomationBase as KeeperBase} from "./AutomationBase.sol";
// SPDX-License-Identifier: MIT /** * @notice This is a deprecated interface. Please use AutomationRegistryInterface1_2 directly. */ pragma solidity ^0.8.0; import {Config, State} from "./AutomationRegistryInterface1_2.sol"; import {AutomationRegistryBaseInterface as KeeperRegistryBaseInterface} from "./AutomationRegistryInterface1_2.sol"; import {AutomationRegistryInterface as KeeperRegistryInterface} from "./AutomationRegistryInterface1_2.sol"; import {AutomationRegistryExecutableInterface as KeeperRegistryExecutableInterface} from "./AutomationRegistryInterface1_2.sol";
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract AutomationBase { error OnlySimulatedBackend(); /** * @notice method that allows it to be simulated via eth_call by checking that * the sender is the zero address. */ function preventExecution() internal view { if (tx.origin != address(0)) { revert OnlySimulatedBackend(); } } /** * @notice modifier that allows it to be simulated via eth_call by checking * that the sender is the zero address. */ modifier cannotExecute() { preventExecution(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice config of the registry * @dev only used in params and return values * @member paymentPremiumPPB payment premium rate oracles receive on top of * being reimbursed for gas, measured in parts per billion * @member flatFeeMicroLink flat fee paid to oracles for performing upkeeps, * priced in MicroLink; can be used in conjunction with or independently of * paymentPremiumPPB * @member blockCountPerTurn number of blocks each oracle has during their turn to * perform upkeep before it will be the next keeper's turn to submit * @member checkGasLimit gas limit when checking for upkeep * @member stalenessSeconds number of seconds that is allowed for feed data to * be stale before switching to the fallback pricing * @member gasCeilingMultiplier multiplier to apply to the fast gas feed price * when calculating the payment ceiling for keepers * @member minUpkeepSpend minimum LINK that an upkeep must spend before cancelling * @member maxPerformGas max executeGas allowed for an upkeep on this registry * @member fallbackGasPrice gas price used if the gas price feed is stale * @member fallbackLinkPrice LINK price used if the LINK price feed is stale * @member transcoder address of the transcoder contract * @member registrar address of the registrar contract */ struct Config { uint32 paymentPremiumPPB; uint32 flatFeeMicroLink; // min 0.000001 LINK, max 4294 LINK uint24 blockCountPerTurn; uint32 checkGasLimit; uint24 stalenessSeconds; uint16 gasCeilingMultiplier; uint96 minUpkeepSpend; uint32 maxPerformGas; uint256 fallbackGasPrice; uint256 fallbackLinkPrice; address transcoder; address registrar; } /** * @notice state of the registry * @dev only used in params and return values * @member nonce used for ID generation * @member ownerLinkBalance withdrawable balance of LINK by contract owner * @member expectedLinkBalance the expected balance of LINK of the registry * @member numUpkeeps total number of upkeeps on the registry */ struct State { uint32 nonce; uint96 ownerLinkBalance; uint256 expectedLinkBalance; uint256 numUpkeeps; } interface AutomationRegistryBaseInterface { function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData ) external returns (uint256 id); function performUpkeep(uint256 id, bytes calldata performData) external returns (bool success); function cancelUpkeep(uint256 id) external; function addFunds(uint256 id, uint96 amount) external; function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external; function getUpkeep(uint256 id) external view returns ( address target, uint32 executeGas, bytes memory checkData, uint96 balance, address lastKeeper, address admin, uint64 maxValidBlocknumber, uint96 amountSpent ); function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view returns (uint256[] memory); function getKeeperInfo(address query) external view returns ( address payee, bool active, uint96 balance ); function getState() external view returns ( State memory, Config memory, address[] memory ); } /** * @dev The view methods are not actually marked as view in the implementation * but we want them to be easily queried off-chain. Solidity will not compile * if we actually inherit from this interface, so we document it here. */ interface AutomationRegistryInterface is AutomationRegistryBaseInterface { function checkUpkeep(uint256 upkeepId, address from) external view returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, int256 gasWei, int256 linkEth ); } interface AutomationRegistryExecutableInterface is AutomationRegistryBaseInterface { function checkUpkeep(uint256 upkeepId, address from) external returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "./interfaces/LinkTokenInterface.sol"; import "./interfaces/KeeperRegistryInterface1_2.sol"; import "./interfaces/TypeAndVersionInterface.sol"; import "./ConfirmedOwner.sol"; import "./interfaces/ERC677ReceiverInterface.sol"; /** * @notice Contract to accept requests for upkeep registrations * @dev There are 2 registration workflows in this contract * Flow 1. auto approve OFF / manual registration - UI calls `register` function on this contract, this contract owner at a later time then manually * calls `approve` to register upkeep and emit events to inform UI and others interested. * Flow 2. auto approve ON / real time registration - UI calls `register` function as before, which calls the `registerUpkeep` function directly on * keeper registry and then emits approved event to finish the flow automatically without manual intervention. * The idea is to have same interface(functions,events) for UI or anyone using this contract irrespective of auto approve being enabled or not. * they can just listen to `RegistrationRequested` & `RegistrationApproved` events and know the status on registrations. */ contract KeeperRegistrar is TypeAndVersionInterface, ConfirmedOwner, ERC677ReceiverInterface { /** * DISABLED: No auto approvals, all new upkeeps should be approved manually. * ENABLED_SENDER_ALLOWLIST: Auto approvals for allowed senders subject to max allowed. Manual for rest. * ENABLED_ALL: Auto approvals for all new upkeeps subject to max allowed. */ enum AutoApproveType { DISABLED, ENABLED_SENDER_ALLOWLIST, ENABLED_ALL } bytes4 private constant REGISTER_REQUEST_SELECTOR = this.register.selector; mapping(bytes32 => PendingRequest) private s_pendingRequests; LinkTokenInterface public immutable LINK; /** * @notice versions: * - KeeperRegistrar 1.1.0: Add functionality for sender allowlist in auto approve * : Remove rate limit and add max allowed for auto approve * - KeeperRegistrar 1.0.0: initial release */ string public constant override typeAndVersion = "KeeperRegistrar 1.1.0"; struct Config { AutoApproveType autoApproveConfigType; uint32 autoApproveMaxAllowed; uint32 approvedCount; KeeperRegistryBaseInterface keeperRegistry; uint96 minLINKJuels; } struct PendingRequest { address admin; uint96 balance; } Config private s_config; // Only applicable if s_config.configType is ENABLED_SENDER_ALLOWLIST mapping(address => bool) private s_autoApproveAllowedSenders; event RegistrationRequested( bytes32 indexed hash, string name, bytes encryptedEmail, address indexed upkeepContract, uint32 gasLimit, address adminAddress, bytes checkData, uint96 amount, uint8 indexed source ); event RegistrationApproved(bytes32 indexed hash, string displayName, uint256 indexed upkeepId); event RegistrationRejected(bytes32 indexed hash); event AutoApproveAllowedSenderSet(address indexed senderAddress, bool allowed); event ConfigChanged( AutoApproveType autoApproveConfigType, uint32 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ); error InvalidAdminAddress(); error RequestNotFound(); error HashMismatch(); error OnlyAdminOrOwner(); error InsufficientPayment(); error RegistrationRequestFailed(); error OnlyLink(); error AmountMismatch(); error SenderMismatch(); error FunctionNotPermitted(); error LinkTransferFailed(address to); error InvalidDataLength(); /* * @param LINKAddress Address of Link token * @param autoApproveConfigType setting for auto-approve registrations * @param autoApproveMaxAllowed max number of registrations that can be auto approved * @param keeperRegistry keeper registry address * @param minLINKJuels minimum LINK that new registrations should fund their upkeep with */ constructor( address LINKAddress, AutoApproveType autoApproveConfigType, uint16 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ) ConfirmedOwner(msg.sender) { LINK = LinkTokenInterface(LINKAddress); setRegistrationConfig(autoApproveConfigType, autoApproveMaxAllowed, keeperRegistry, minLINKJuels); } //EXTERNAL /** * @notice register can only be called through transferAndCall on LINK contract * @param name string of the upkeep to be registered * @param encryptedEmail email address of upkeep contact * @param upkeepContract address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when performing upkeep * @param adminAddress address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep * @param amount quantity of LINK upkeep is funded with (specified in Juels) * @param source application sending this request * @param sender address of the sender making the request */ function register( string memory name, bytes calldata encryptedEmail, address upkeepContract, uint32 gasLimit, address adminAddress, bytes calldata checkData, uint96 amount, uint8 source, address sender ) external onlyLINK { if (adminAddress == address(0)) { revert InvalidAdminAddress(); } bytes32 hash = keccak256(abi.encode(upkeepContract, gasLimit, adminAddress, checkData)); emit RegistrationRequested( hash, name, encryptedEmail, upkeepContract, gasLimit, adminAddress, checkData, amount, source ); Config memory config = s_config; if (_shouldAutoApprove(config, sender)) { s_config.approvedCount = config.approvedCount + 1; _approve(name, upkeepContract, gasLimit, adminAddress, checkData, amount, hash); } else { uint96 newBalance = s_pendingRequests[hash].balance + amount; s_pendingRequests[hash] = PendingRequest({admin: adminAddress, balance: newBalance}); } } /** * @dev register upkeep on KeeperRegistry contract and emit RegistrationApproved event */ function approve( string memory name, address upkeepContract, uint32 gasLimit, address adminAddress, bytes calldata checkData, bytes32 hash ) external onlyOwner { PendingRequest memory request = s_pendingRequests[hash]; if (request.admin == address(0)) { revert RequestNotFound(); } bytes32 expectedHash = keccak256(abi.encode(upkeepContract, gasLimit, adminAddress, checkData)); if (hash != expectedHash) { revert HashMismatch(); } delete s_pendingRequests[hash]; _approve(name, upkeepContract, gasLimit, adminAddress, checkData, request.balance, hash); } /** * @notice cancel will remove a registration request and return the refunds to the msg.sender * @param hash the request hash */ function cancel(bytes32 hash) external { PendingRequest memory request = s_pendingRequests[hash]; if (!(msg.sender == request.admin || msg.sender == owner())) { revert OnlyAdminOrOwner(); } if (request.admin == address(0)) { revert RequestNotFound(); } delete s_pendingRequests[hash]; bool success = LINK.transfer(msg.sender, request.balance); if (!success) { revert LinkTransferFailed(msg.sender); } emit RegistrationRejected(hash); } /** * @notice owner calls this function to set if registration requests should be sent directly to the Keeper Registry * @param autoApproveConfigType setting for auto-approve registrations * note: autoApproveAllowedSenders list persists across config changes irrespective of type * @param autoApproveMaxAllowed max number of registrations that can be auto approved * @param keeperRegistry new keeper registry address * @param minLINKJuels minimum LINK that new registrations should fund their upkeep with */ function setRegistrationConfig( AutoApproveType autoApproveConfigType, uint16 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ) public onlyOwner { uint32 approvedCount = s_config.approvedCount; s_config = Config({ autoApproveConfigType: autoApproveConfigType, autoApproveMaxAllowed: autoApproveMaxAllowed, approvedCount: approvedCount, minLINKJuels: minLINKJuels, keeperRegistry: KeeperRegistryBaseInterface(keeperRegistry) }); emit ConfigChanged(autoApproveConfigType, autoApproveMaxAllowed, keeperRegistry, minLINKJuels); } /** * @notice owner calls this function to set allowlist status for senderAddress * @param senderAddress senderAddress to set the allowlist status for * @param allowed true if senderAddress needs to be added to allowlist, false if needs to be removed */ function setAutoApproveAllowedSender(address senderAddress, bool allowed) external onlyOwner { s_autoApproveAllowedSenders[senderAddress] = allowed; emit AutoApproveAllowedSenderSet(senderAddress, allowed); } /** * @notice read the allowlist status of senderAddress * @param senderAddress address to read the allowlist status for */ function getAutoApproveAllowedSender(address senderAddress) external view returns (bool) { return s_autoApproveAllowedSenders[senderAddress]; } /** * @notice read the current registration configuration */ function getRegistrationConfig() external view returns ( AutoApproveType autoApproveConfigType, uint32 autoApproveMaxAllowed, uint32 approvedCount, address keeperRegistry, uint256 minLINKJuels ) { Config memory config = s_config; return ( config.autoApproveConfigType, config.autoApproveMaxAllowed, config.approvedCount, address(config.keeperRegistry), config.minLINKJuels ); } /** * @notice gets the admin address and the current balance of a registration request */ function getPendingRequest(bytes32 hash) external view returns (address, uint96) { PendingRequest memory request = s_pendingRequests[hash]; return (request.admin, request.balance); } /** * @notice Called when LINK is sent to the contract via `transferAndCall` * @param sender Address of the sender transfering LINK * @param amount Amount of LINK sent (specified in Juels) * @param data Payload of the transaction */ function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external override onlyLINK permittedFunctionsForLINK(data) isActualAmount(amount, data) isActualSender(sender, data) { if (data.length < 292) revert InvalidDataLength(); if (amount < s_config.minLINKJuels) { revert InsufficientPayment(); } (bool success, ) = address(this).delegatecall(data); // calls register if (!success) { revert RegistrationRequestFailed(); } } //PRIVATE /** * @dev register upkeep on KeeperRegistry contract and emit RegistrationApproved event */ function _approve( string memory name, address upkeepContract, uint32 gasLimit, address adminAddress, bytes calldata checkData, uint96 amount, bytes32 hash ) private { KeeperRegistryBaseInterface keeperRegistry = s_config.keeperRegistry; // register upkeep uint256 upkeepId = keeperRegistry.registerUpkeep(upkeepContract, gasLimit, adminAddress, checkData); // fund upkeep bool success = LINK.transferAndCall(address(keeperRegistry), amount, abi.encode(upkeepId)); if (!success) { revert LinkTransferFailed(address(keeperRegistry)); } emit RegistrationApproved(hash, name, upkeepId); } /** * @dev verify sender allowlist if needed and check max limit */ function _shouldAutoApprove(Config memory config, address sender) private returns (bool) { if (config.autoApproveConfigType == AutoApproveType.DISABLED) { return false; } if ( config.autoApproveConfigType == AutoApproveType.ENABLED_SENDER_ALLOWLIST && (!s_autoApproveAllowedSenders[sender]) ) { return false; } if (config.approvedCount < config.autoApproveMaxAllowed) { return true; } return false; } //MODIFIERS /** * @dev Reverts if not sent from the LINK token */ modifier onlyLINK() { if (msg.sender != address(LINK)) { revert OnlyLink(); } _; } /** * @dev Reverts if the given data does not begin with the `register` function selector * @param _data The data payload of the request */ modifier permittedFunctionsForLINK(bytes memory _data) { bytes4 funcSelector; assembly { // solhint-disable-next-line avoid-low-level-calls funcSelector := mload(add(_data, 32)) // First 32 bytes contain length of data } if (funcSelector != REGISTER_REQUEST_SELECTOR) { revert FunctionNotPermitted(); } _; } /** * @dev Reverts if the actual amount passed does not match the expected amount * @param expected amount that should match the actual amount * @param data bytes */ modifier isActualAmount(uint256 expected, bytes memory data) { uint256 actual; assembly { actual := mload(add(data, 228)) } if (expected != actual) { revert AmountMismatch(); } _; } /** * @dev Reverts if the actual sender address does not match the expected sender address * @param expected address that should match the actual sender address * @param data bytes */ modifier isActualSender(address expected, bytes memory data) { address actual; assembly { actual := mload(add(data, 292)) } if (expected != actual) { revert SenderMismatch(); } _; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import {AutomationRegistryExecutableInterface} from "../interfaces/AutomationRegistryInterface1_2.sol"; import {ConfirmedOwner} from "../ConfirmedOwner.sol"; /** * @notice This contract serves as a wrapper around a keeper registry's checkUpkeep function. */ contract KeeperRegistryCheckUpkeepGasUsageWrapper1_2 is ConfirmedOwner { AutomationRegistryExecutableInterface private immutable i_keeperRegistry; /** * @param keeperRegistry address of a keeper registry */ constructor(AutomationRegistryExecutableInterface keeperRegistry) ConfirmedOwner(msg.sender) { i_keeperRegistry = keeperRegistry; } /** * @return the keeper registry */ function getKeeperRegistry() external view returns (AutomationRegistryExecutableInterface) { return i_keeperRegistry; } /** * @notice This function is called by monitoring service to estimate how much gas checkUpkeep functions will consume. * @param id identifier of the upkeep to check * @param from the address to simulate performing the upkeep from */ function measureCheckGas(uint256 id, address from) external returns ( bool, bytes memory, uint256 ) { uint256 startGas = gasleft(); try i_keeperRegistry.checkUpkeep(id, from) returns ( bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth ) { uint256 gasUsed = startGas - gasleft(); return (true, performData, gasUsed); } catch { uint256 gasUsed = startGas - gasleft(); return (false, "", gasUsed); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../interfaces/KeeperCompatibleInterface.sol"; import "../interfaces/KeeperRegistryInterface1_2.sol"; import "../ConfirmedOwner.sol"; error NoKeeperNodes(); error InsufficientInterval(); /** * @notice A canary upkeep which requires a different keeper to service its upkeep at an interval. This makes sure that * all keepers are in a healthy state. */ contract CanaryUpkeep1_2 is KeeperCompatibleInterface, ConfirmedOwner { uint256 private s_keeperIndex; uint256 private s_interval; uint256 private s_timestamp; KeeperRegistryExecutableInterface private immutable i_keeperRegistry; /** * @param keeperRegistry address of a keeper registry */ constructor(KeeperRegistryExecutableInterface keeperRegistry, uint256 interval) ConfirmedOwner(msg.sender) { i_keeperRegistry = keeperRegistry; s_timestamp = block.timestamp; s_interval = interval; s_keeperIndex = 0; } /** * @return the current keeper index */ function getKeeperIndex() external view returns (uint256) { return s_keeperIndex; } /** * @return the current timestamp */ function getTimestamp() external view returns (uint256) { return s_timestamp; } /** * @return the current interval */ function getInterval() external view returns (uint256) { return s_interval; } /** * @return the keeper registry */ function getKeeperRegistry() external view returns (KeeperRegistryExecutableInterface) { return i_keeperRegistry; } /** * @notice updates the interval * @param interval the new interval */ function setInterval(uint256 interval) external onlyOwner { s_interval = interval; } /** * @notice returns true if keeper array is not empty and sufficient time has passed */ function checkUpkeep( bytes calldata /* checkData */ ) external view override returns (bool, bytes memory) { bool upkeepNeeded = block.timestamp >= s_interval + s_timestamp; return (upkeepNeeded, bytes("")); } /** * @notice checks keepers array limit, timestamp limit, and requires transaction origin must be the anticipated keeper. * If all checks pass, update the keeper index and timestamp. Otherwise, revert this transaction. */ function performUpkeep( bytes calldata /* performData */ ) external override { (State memory _s, Config memory _c, address[] memory keepers) = i_keeperRegistry.getState(); if (keepers.length == 0) { revert NoKeeperNodes(); } if (block.timestamp < s_interval + s_timestamp) { revert InsufficientInterval(); } // if keepers array is shortened, this statement will make sure keeper index is always valid if (s_keeperIndex >= keepers.length) { s_keeperIndex = 0; } require(tx.origin == keepers[s_keeperIndex], "transaction origin is not the anticipated keeper."); s_keeperIndex = (s_keeperIndex + 1) % keepers.length; s_timestamp = block.timestamp; } }
// SPDX-License-Identifier: MIT /** The Cron contract is a chainlink keepers-powered cron job runner for smart contracts. The contract enables developers to trigger actions on various targets using cron strings to specify the cadence. For example, a user may have 3 tasks that require regular service in their dapp ecosystem: 1) 0xAB..CD, update(1), "0 0 * * *" --> runs update(1) on 0xAB..CD daily at midnight 2) 0xAB..CD, update(2), "30 12 * * 0-4" --> runs update(2) on 0xAB..CD weekdays at 12:30 3) 0x12..34, trigger(), "0 * * * *" --> runs trigger() on 0x12..34 hourly To use this contract, a user first deploys this contract and registers it on the chainlink keeper registry. Then the user adds cron jobs by following these steps: 1) Convert a cron string to an encoded cron spec by calling encodeCronString() 2) Take the encoding, target, and handler, and create a job by sending a tx to createCronJob() 3) Cron job is running :) */ pragma solidity 0.8.6; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "../ConfirmedOwner.sol"; import "../KeeperBase.sol"; import "../interfaces/KeeperCompatibleInterface.sol"; import {Cron as CronInternal, Spec} from "../libraries/internal/Cron.sol"; import {Cron as CronExternal} from "../libraries/external/Cron.sol"; import {getRevertMsg} from "../utils/utils.sol"; /** * @title The CronUpkeep contract * @notice A keeper-compatible contract that runs various tasks on cron schedules. * Users must use the encodeCronString() function to encode their cron jobs before * setting them. This keeps all the string manipulation off chain and reduces gas costs. */ contract CronUpkeep is KeeperCompatibleInterface, KeeperBase, ConfirmedOwner, Pausable, Proxy { using EnumerableSet for EnumerableSet.UintSet; event CronJobExecuted(uint256 indexed id, uint256 timestamp); event CronJobCreated(uint256 indexed id, address target, bytes handler); event CronJobUpdated(uint256 indexed id, address target, bytes handler); event CronJobDeleted(uint256 indexed id); error CallFailed(uint256 id, string reason); error CronJobIDNotFound(uint256 id); error ExceedsMaxJobs(); error InvalidHandler(); error TickInFuture(); error TickTooOld(); error TickDoesntMatchSpec(); address immutable s_delegate; uint256 public immutable s_maxJobs; uint256 private s_nextCronJobID = 1; EnumerableSet.UintSet private s_activeCronJobIDs; mapping(uint256 => uint256) private s_lastRuns; mapping(uint256 => Spec) private s_specs; mapping(uint256 => address) private s_targets; mapping(uint256 => bytes) private s_handlers; mapping(uint256 => bytes32) private s_handlerSignatures; /** * @param owner the initial owner of the contract * @param delegate the contract to delegate checkUpkeep calls to * @param maxJobs the max number of cron jobs this contract will support * @param firstJob an optional encoding of the first cron job */ constructor( address owner, address delegate, uint256 maxJobs, bytes memory firstJob ) ConfirmedOwner(owner) { s_delegate = delegate; s_maxJobs = maxJobs; if (firstJob.length > 0) { (address target, bytes memory handler, Spec memory spec) = abi.decode(firstJob, (address, bytes, Spec)); createCronJobFromSpec(target, handler, spec); } } /** * @notice Executes the cron job with id encoded in performData * @param performData abi encoding of cron job ID and the cron job's next run-at datetime */ function performUpkeep(bytes calldata performData) external override whenNotPaused { (uint256 id, uint256 tickTime, address target, bytes memory handler) = abi.decode( performData, (uint256, uint256, address, bytes) ); validate(id, tickTime, target, handler); s_lastRuns[id] = block.timestamp; (bool success, bytes memory payload) = target.call(handler); if (!success) { revert CallFailed(id, getRevertMsg(payload)); } emit CronJobExecuted(id, block.timestamp); } /** * @notice Creates a cron job from the given encoded spec * @param target the destination contract of a cron job * @param handler the function signature on the target contract to call * @param encodedCronSpec abi encoding of a cron spec */ function createCronJobFromEncodedSpec( address target, bytes memory handler, bytes memory encodedCronSpec ) external onlyOwner { if (s_activeCronJobIDs.length() >= s_maxJobs) { revert ExceedsMaxJobs(); } Spec memory spec = abi.decode(encodedCronSpec, (Spec)); createCronJobFromSpec(target, handler, spec); } /** * @notice Updates a cron job from the given encoded spec * @param id the id of the cron job to update * @param newTarget the destination contract of a cron job * @param newHandler the function signature on the target contract to call * @param newEncodedCronSpec abi encoding of a cron spec */ function updateCronJob( uint256 id, address newTarget, bytes memory newHandler, bytes memory newEncodedCronSpec ) external onlyOwner onlyValidCronID(id) { Spec memory newSpec = abi.decode(newEncodedCronSpec, (Spec)); s_targets[id] = newTarget; s_handlers[id] = newHandler; s_specs[id] = newSpec; s_handlerSignatures[id] = handlerSig(newTarget, newHandler); emit CronJobUpdated(id, newTarget, newHandler); } /** * @notice Deletes the cron job matching the provided id. Reverts if * the id is not found. * @param id the id of the cron job to delete */ function deleteCronJob(uint256 id) external onlyOwner onlyValidCronID(id) { delete s_lastRuns[id]; delete s_specs[id]; delete s_targets[id]; delete s_handlers[id]; delete s_handlerSignatures[id]; s_activeCronJobIDs.remove(id); emit CronJobDeleted(id); } /** * @notice Pauses the contract, which prevents executing performUpkeep */ function pause() external onlyOwner { _pause(); } /** * @notice Unpauses the contract */ function unpause() external onlyOwner { _unpause(); } /** * @notice Get the id of an eligible cron job * @return upkeepNeeded signals if upkeep is needed, performData is an abi encoding * of the id and "next tick" of the elligible cron job */ function checkUpkeep(bytes calldata) external override whenNotPaused cannotExecute returns (bool, bytes memory) { _delegate(s_delegate); } /** * @notice gets a list of active cron job IDs * @return list of active cron job IDs */ function getActiveCronJobIDs() external view returns (uint256[] memory) { uint256 length = s_activeCronJobIDs.length(); uint256[] memory jobIDs = new uint256[](length); for (uint256 idx = 0; idx < length; idx++) { jobIDs[idx] = s_activeCronJobIDs.at(idx); } return jobIDs; } /** * @notice gets a cron job * @param id the cron job ID * @return target - the address a cron job forwards the eth tx to handler - the encoded function sig to execute when forwarding a tx cronString - the string representing the cron job nextTick - the timestamp of the next time the cron job will run */ function getCronJob(uint256 id) external view onlyValidCronID(id) returns ( address target, bytes memory handler, string memory cronString, uint256 nextTick ) { Spec memory spec = s_specs[id]; return (s_targets[id], s_handlers[id], CronExternal.toCronString(spec), CronExternal.nextTick(spec)); } /** * @notice Adds a cron spec to storage and the ID to the list of jobs * @param target the destination contract of a cron job * @param handler the function signature on the target contract to call * @param spec the cron spec to create */ function createCronJobFromSpec( address target, bytes memory handler, Spec memory spec ) internal { uint256 newID = s_nextCronJobID; s_activeCronJobIDs.add(newID); s_targets[newID] = target; s_handlers[newID] = handler; s_specs[newID] = spec; s_lastRuns[newID] = block.timestamp; s_handlerSignatures[newID] = handlerSig(target, handler); s_nextCronJobID++; emit CronJobCreated(newID, target, handler); } function _implementation() internal view override returns (address) { return s_delegate; } /** * @notice validates the input to performUpkeep * @param id the id of the cron job * @param tickTime the observed tick time * @param target the contract to forward the tx to * @param handler the handler of the contract receiving the forwarded tx */ function validate( uint256 id, uint256 tickTime, address target, bytes memory handler ) private { tickTime = tickTime - (tickTime % 60); // remove seconds from tick time if (block.timestamp < tickTime) { revert TickInFuture(); } if (tickTime <= s_lastRuns[id]) { revert TickTooOld(); } if (!CronInternal.matches(s_specs[id], tickTime)) { revert TickDoesntMatchSpec(); } if (handlerSig(target, handler) != s_handlerSignatures[id]) { revert InvalidHandler(); } } /** * @notice returns a unique identifier for target/handler pairs * @param target the contract to forward the tx to * @param handler the handler of the contract receiving the forwarded tx * @return a hash of the inputs */ function handlerSig(address target, bytes memory handler) private pure returns (bytes32) { return keccak256(abi.encodePacked(target, handler)); } modifier onlyValidCronID(uint256 id) { if (!s_activeCronJobIDs.contains(id)) { revert CronJobIDNotFound(id); } _; } }
// SPDX-License-Identifier: MIT /* The Cron contract serves two primary functions: * parsing cron-formatted strings like "0 0 * * *" into structs called "Specs" * computing the "next tick" of a cron spec Because manipulating strings is gas-expensive in solidity, the intended use of this contract is for users to first convert their cron strings to encoded Spec structs via toEncodedSpec(). Then, the user stores the Spec on chain. Finally, users use the nextTick(), function to determine the datetime of the next cron job run. Cron jobs are interpreted according to this format: ┌───────────── minute (0 - 59) │ ┌───────────── hour (0 - 23) │ │ ┌───────────── day of the month (1 - 31) │ │ │ ┌───────────── month (1 - 12) │ │ │ │ ┌───────────── day of the week (0 - 6) (Monday to Sunday) │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ * * * * * Special limitations: * there is no year field * no special characters: ? L W # * lists can have a max length of 26 * no words like JAN / FEB or MON / TUES */ pragma solidity 0.8.6; import "../../vendor/Strings.sol"; import "../../vendor/DateTime.sol"; // The fields of a cron spec, by name string constant MINUTE = "minute"; string constant HOUR = "hour"; string constant DAY = "day"; string constant MONTH = "month"; string constant DAY_OF_WEEK = "day of week"; error UnknownFieldType(); error InvalidSpec(string reason); error InvalidField(string field, string reason); error ListTooLarge(); // Set of enums representing a cron field type enum FieldType { WILD, EXACT, INTERVAL, RANGE, LIST } // A spec represents a cron job by decomposing it into 5 fields struct Spec { Field minute; Field hour; Field day; Field month; Field dayOfWeek; } // A field represents a single element in a cron spec. There are 5 types // of fields (see above). Not all properties of this struct are present at once. struct Field { FieldType fieldType; uint8 singleValue; uint8 interval; uint8 rangeStart; uint8 rangeEnd; uint8 listLength; uint8[26] list; } /** * @title The Cron library * @notice A utility contract for encoding/decoding cron strings (ex: 0 0 * * *) into an * abstraction called a Spec. The library also includes a spec function, nextTick(), which * determines the next time a cron job should fire based on the current block timestamp. */ library Cron { using strings for *; /** * @notice nextTick calculates the next datetime that a spec "ticks", starting * from the current block timestamp. This is gas-intensive and therefore should * only be called off-chain. * @param spec the spec to evaluate * @return the next tick * @dev this is the internal version of the library. There is also an external version. */ function nextTick(Spec memory spec) internal view returns (uint256) { uint16 year = DateTime.getYear(block.timestamp); uint8 month = DateTime.getMonth(block.timestamp); uint8 day = DateTime.getDay(block.timestamp); uint8 hour = DateTime.getHour(block.timestamp); uint8 minute = DateTime.getMinute(block.timestamp); uint8 dayOfWeek; for (; true; year++) { for (; month <= 12; month++) { if (!matches(spec.month, month)) { day = 1; hour = 0; minute = 0; continue; } uint8 maxDay = DateTime.getDaysInMonth(month, year); for (; day <= maxDay; day++) { if (!matches(spec.day, day)) { hour = 0; minute = 0; continue; } dayOfWeek = DateTime.getWeekday(DateTime.toTimestamp(year, month, day)); if (!matches(spec.dayOfWeek, dayOfWeek)) { hour = 0; minute = 0; continue; } for (; hour < 24; hour++) { if (!matches(spec.hour, hour)) { minute = 0; continue; } for (; minute < 60; minute++) { if (!matches(spec.minute, minute)) { continue; } return DateTime.toTimestamp(year, month, day, hour, minute); } minute = 0; } hour = 0; } day = 1; } month = 1; } } /** * @notice lastTick calculates the previous datetime that a spec "ticks", starting * from the current block timestamp. This is gas-intensive and therefore should * only be called off-chain. * @param spec the spec to evaluate * @return the next tick */ function lastTick(Spec memory spec) internal view returns (uint256) { uint16 year = DateTime.getYear(block.timestamp); uint8 month = DateTime.getMonth(block.timestamp); uint8 day = DateTime.getDay(block.timestamp); uint8 hour = DateTime.getHour(block.timestamp); uint8 minute = DateTime.getMinute(block.timestamp); uint8 dayOfWeek; bool resetDay; for (; true; year--) { for (; month > 0; month--) { if (!matches(spec.month, month)) { resetDay = true; hour = 23; minute = 59; continue; } if (resetDay) { day = DateTime.getDaysInMonth(month, year); } for (; day > 0; day--) { if (!matches(spec.day, day)) { hour = 23; minute = 59; continue; } dayOfWeek = DateTime.getWeekday(DateTime.toTimestamp(year, month, day)); if (!matches(spec.dayOfWeek, dayOfWeek)) { hour = 23; minute = 59; continue; } for (; hour >= 0; hour--) { if (!matches(spec.hour, hour)) { minute = 59; if (hour == 0) { break; } continue; } for (; minute >= 0; minute--) { if (!matches(spec.minute, minute)) { if (minute == 0) { break; } continue; } return DateTime.toTimestamp(year, month, day, hour, minute); } minute = 59; if (hour == 0) { break; } } hour = 23; } resetDay = true; } month = 12; } } /** * @notice matches evaluates whether or not a spec "ticks" at a given timestamp * @param spec the spec to evaluate * @param timestamp the timestamp to compare against * @return true / false if they match */ function matches(Spec memory spec, uint256 timestamp) internal view returns (bool) { DateTime._DateTime memory dt = DateTime.parseTimestamp(timestamp); return matches(spec.month, dt.month) && matches(spec.day, dt.day) && matches(spec.hour, dt.hour) && matches(spec.minute, dt.minute); } /** * @notice toSpec converts a cron string to a spec struct. This is gas-intensive * and therefore should only be called off-chain. * @param cronString the cron string * @return the spec struct */ function toSpec(string memory cronString) internal pure returns (Spec memory) { strings.slice memory space = strings.toSlice(" "); strings.slice memory cronSlice = strings.toSlice(cronString); if (cronSlice.count(space) != 4) { revert InvalidSpec("4 spaces required"); } strings.slice memory minuteSlice = cronSlice.split(space); strings.slice memory hourSlice = cronSlice.split(space); strings.slice memory daySlice = cronSlice.split(space); strings.slice memory monthSlice = cronSlice.split(space); // DEV: dayOfWeekSlice = cronSlice // The cronSlice now contains the last section of the cron job, // which corresponds to the day of week if ( minuteSlice.len() == 0 || hourSlice.len() == 0 || daySlice.len() == 0 || monthSlice.len() == 0 || cronSlice.len() == 0 ) { revert InvalidSpec("some fields missing"); } return validate( Spec({ minute: sliceToField(minuteSlice), hour: sliceToField(hourSlice), day: sliceToField(daySlice), month: sliceToField(monthSlice), dayOfWeek: sliceToField(cronSlice) }) ); } /** * @notice toEncodedSpec converts a cron string to an abi-encoded spec. This is gas-intensive * and therefore should only be called off-chain. * @param cronString the cron string * @return the abi-encoded spec */ function toEncodedSpec(string memory cronString) internal pure returns (bytes memory) { return abi.encode(toSpec(cronString)); } /** * @notice toCronString converts a cron spec to a human-readable cron string. This is gas-intensive * and therefore should only be called off-chain. * @param spec the cron spec * @return the corresponding cron string */ function toCronString(Spec memory spec) internal pure returns (string memory) { return string( bytes.concat( fieldToBstring(spec.minute), " ", fieldToBstring(spec.hour), " ", fieldToBstring(spec.day), " ", fieldToBstring(spec.month), " ", fieldToBstring(spec.dayOfWeek) ) ); } /** * @notice matches evaluates if a values matches a field. * ex: 3 matches *, 3 matches 0-5, 3 does not match 0,2,4 * @param field the field struct to match against * @param value the value of a field * @return true / false if they match */ function matches(Field memory field, uint8 value) private pure returns (bool) { if (field.fieldType == FieldType.WILD) { return true; } else if (field.fieldType == FieldType.INTERVAL) { return value % field.interval == 0; } else if (field.fieldType == FieldType.EXACT) { return value == field.singleValue; } else if (field.fieldType == FieldType.RANGE) { return value >= field.rangeStart && value <= field.rangeEnd; } else if (field.fieldType == FieldType.LIST) { for (uint256 idx = 0; idx < field.listLength; idx++) { if (value == field.list[idx]) { return true; } } return false; } revert UnknownFieldType(); } // VALIDATIONS /** * @notice validate validates a spec, reverting if any errors are found * @param spec the spec to validate * @return the original spec */ function validate(Spec memory spec) private pure returns (Spec memory) { validateField(spec.dayOfWeek, DAY_OF_WEEK, 0, 6); validateField(spec.month, MONTH, 1, 12); uint8 maxDay = maxDayForMonthField(spec.month); validateField(spec.day, DAY, 1, maxDay); validateField(spec.hour, HOUR, 0, 23); validateField(spec.minute, MINUTE, 0, 59); return spec; } /** * @notice validateField validates the value of a field. It reverts if an error is found. * @param field the field to validate * @param fieldName the name of the field ex "minute" or "hour" * @param min the minimum value a field can have (usually 1 or 0) * @param max the maximum value a field can have (ex minute = 59, hour = 23) */ function validateField( Field memory field, string memory fieldName, uint8 min, uint8 max ) private pure { if (field.fieldType == FieldType.WILD) { return; } else if (field.fieldType == FieldType.EXACT) { if (field.singleValue < min || field.singleValue > max) { string memory reason = string( bytes.concat("value must be >=,", uintToBString(min), " and <=", uintToBString(max)) ); revert InvalidField(fieldName, reason); } } else if (field.fieldType == FieldType.INTERVAL) { if (field.interval < 1 || field.interval > max) { string memory reason = string( bytes.concat("inverval must be */(", uintToBString(1), "-", uintToBString(max), ")") ); revert InvalidField(fieldName, reason); } } else if (field.fieldType == FieldType.RANGE) { if (field.rangeEnd > max || field.rangeEnd <= field.rangeStart) { string memory reason = string( bytes.concat("inverval must be within ", uintToBString(min), "-", uintToBString(max)) ); revert InvalidField(fieldName, reason); } } else if (field.fieldType == FieldType.LIST) { if (field.listLength < 2) { revert InvalidField(fieldName, "lists must have at least 2 items"); } string memory reason = string( bytes.concat("items in list must be within ", uintToBString(min), "-", uintToBString(max)) ); uint8 listItem; for (uint256 idx = 0; idx < field.listLength; idx++) { listItem = field.list[idx]; if (listItem < min || listItem > max) { revert InvalidField(fieldName, reason); } } } else { revert UnknownFieldType(); } } /** * @notice maxDayForMonthField returns the maximum valid day given the month field * @param month the month field * @return the max day */ function maxDayForMonthField(Field memory month) private pure returns (uint8) { // DEV: ranges are always safe because any two consecutive months will always // contain a month with 31 days if (month.fieldType == FieldType.WILD || month.fieldType == FieldType.RANGE) { return 31; } else if (month.fieldType == FieldType.EXACT) { // DEV: assume leap year in order to get max value return DateTime.getDaysInMonth(month.singleValue, 4); } else if (month.fieldType == FieldType.INTERVAL) { if (month.interval == 9 || month.interval == 11) { return 30; } else { return 31; } } else if (month.fieldType == FieldType.LIST) { uint8 result; for (uint256 idx = 0; idx < month.listLength; idx++) { // DEV: assume leap year in order to get max value uint8 daysInMonth = DateTime.getDaysInMonth(month.list[idx], 4); if (daysInMonth == 31) { return daysInMonth; } if (daysInMonth > result) { result = daysInMonth; } } return result; } else { revert UnknownFieldType(); } } /** * @notice sliceToField converts a strings.slice to a field struct * @param fieldSlice the slice of a string representing the field of a cron job * @return the field */ function sliceToField(strings.slice memory fieldSlice) private pure returns (Field memory) { strings.slice memory star = strings.toSlice("*"); strings.slice memory dash = strings.toSlice("-"); strings.slice memory slash = strings.toSlice("/"); strings.slice memory comma = strings.toSlice(","); Field memory field; if (fieldSlice.equals(star)) { field.fieldType = FieldType.WILD; } else if (fieldSlice.contains(dash)) { field.fieldType = FieldType.RANGE; strings.slice memory start = fieldSlice.split(dash); field.rangeStart = sliceToUint8(start); field.rangeEnd = sliceToUint8(fieldSlice); } else if (fieldSlice.contains(slash)) { field.fieldType = FieldType.INTERVAL; fieldSlice.split(slash); field.interval = sliceToUint8(fieldSlice); } else if (fieldSlice.contains(comma)) { field.fieldType = FieldType.LIST; strings.slice memory token; while (fieldSlice.len() > 0) { if (field.listLength > 25) { revert ListTooLarge(); } token = fieldSlice.split(comma); field.list[field.listLength] = sliceToUint8(token); field.listLength++; } } else { // needs input validation field.fieldType = FieldType.EXACT; field.singleValue = sliceToUint8(fieldSlice); } return field; } /** * @notice fieldToBstring converts a field to the bytes representation of that field string * @param field the field to stringify * @return bytes representing the string, ex: bytes("*") */ function fieldToBstring(Field memory field) private pure returns (bytes memory) { if (field.fieldType == FieldType.WILD) { return "*"; } else if (field.fieldType == FieldType.EXACT) { return uintToBString(uint256(field.singleValue)); } else if (field.fieldType == FieldType.RANGE) { return bytes.concat(uintToBString(field.rangeStart), "-", uintToBString(field.rangeEnd)); } else if (field.fieldType == FieldType.INTERVAL) { return bytes.concat("*/", uintToBString(uint256(field.interval))); } else if (field.fieldType == FieldType.LIST) { bytes memory result = uintToBString(field.list[0]); for (uint256 idx = 1; idx < field.listLength; idx++) { result = bytes.concat(result, ",", uintToBString(field.list[idx])); } return result; } revert UnknownFieldType(); } /** * @notice uintToBString converts a uint256 to a bytes representation of that uint as a string * @param n the number to stringify * @return bytes representing the string, ex: bytes("1") */ function uintToBString(uint256 n) private pure returns (bytes memory) { if (n == 0) { return "0"; } uint256 j = n; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint256 k = len; while (n != 0) { k = k - 1; uint8 temp = (48 + uint8(n - (n / 10) * 10)); bytes1 b1 = bytes1(temp); bstr[k] = b1; n /= 10; } return bstr; } /** * @notice sliceToUint8 converts a strings.slice to uint8 * @param slice the string slice to convert to a uint8 * @return the number that the string represents ex: "20" --> 20 */ function sliceToUint8(strings.slice memory slice) private pure returns (uint8) { bytes memory b = bytes(slice.toString()); uint8 i; uint8 result = 0; for (i = 0; i < b.length; i++) { uint8 c = uint8(b[i]); if (c >= 48 && c <= 57) { result = result * 10 + (c - 48); } } return result; } }
pragma solidity 0.8.6; import {Cron as CronInternal, Spec} from "../internal/Cron.sol"; /** * @title The Cron library * @notice A utility contract for encoding/decoding cron strings (ex: 0 0 * * *) into an * abstraction called a Spec. The library also includes a spec function, nextTick(), which * determines the next time a cron job should fire based on the current block timestamp. * @dev this is the external version of the library, which relies on the internal library * by the same name. */ library Cron { using CronInternal for Spec; using CronInternal for string; /** * @notice nextTick calculates the next datetime that a spec "ticks", starting * from the current block timestamp. This is gas-intensive and therefore should * only be called off-chain. * @param spec the spec to evaluate * @return the next tick */ function nextTick(Spec calldata spec) public view returns (uint256) { return spec.nextTick(); } /** * @notice lastTick calculates the previous datetime that a spec "ticks", starting * from the current block timestamp. This is gas-intensive and therefore should * only be called off-chain. * @param spec the spec to evaluate * @return the next tick */ function lastTick(Spec calldata spec) public view returns (uint256) { return spec.lastTick(); } /** * @notice matches evaluates whether or not a spec "ticks" at a given timestamp * @param spec the spec to evaluate * @param timestamp the timestamp to compare against * @return true / false if they match */ function matches(Spec calldata spec, uint256 timestamp) public view returns (bool) { return spec.matches(timestamp); } /** * @notice toSpec converts a cron string to a spec struct. This is gas-intensive * and therefore should only be called off-chain. * @param cronString the cron string * @return the spec struct */ function toSpec(string calldata cronString) public pure returns (Spec memory) { return cronString.toSpec(); } /** * @notice toEncodedSpec converts a cron string to an abi-encoded spec. This is gas-intensive * and therefore should only be called off-chain. * @param cronString the cron string * @return the abi-encoded spec */ function toEncodedSpec(string calldata cronString) public pure returns (bytes memory) { return cronString.toEncodedSpec(); } /** * @notice toCronString converts a cron spec to a human-readable cron string. This is gas-intensive * and therefore should only be called off-chain. * @param spec the cron spec * @return the corresponding cron string */ function toCronString(Spec calldata spec) public pure returns (string memory) { return spec.toCronString(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice getRevertMsg extracts a revert reason from a failed contract call */ function getRevertMsg(bytes memory payload) pure returns (string memory) { if (payload.length < 68) return "transaction reverted silently"; assembly { payload := add(payload, 0x04) } return abi.decode(payload, (string)); }
// SPDX-License-Identifier: Apache 2.0 /* * @title String & slice utility library for Solidity contracts. * @author Nick Johnson <[email protected]> * * @dev Functionality in this library is largely implemented using an * abstraction called a 'slice'. A slice represents a part of a string - * anything from the entire string to a single character, or even no * characters at all (a 0-length slice). Since a slice only has to specify * an offset and a length, copying and manipulating slices is a lot less * expensive than copying and manipulating the strings they reference. * * To further reduce gas costs, most functions on slice that need to return * a slice modify the original one instead of allocating a new one; for * instance, `s.split(".")` will return the text up to the first '.', * modifying s to only contain the remainder of the string after the '.'. * In situations where you do not want to modify the original slice, you * can make a copy first with `.copy()`, for example: * `s.copy().split(".")`. Try and avoid using this idiom in loops; since * Solidity has no memory management, it will result in allocating many * short-lived slices that are later discarded. * * Functions that return two slices come in two versions: a non-allocating * version that takes the second slice as an argument, modifying it in * place, and an allocating version that allocates and returns the second * slice; see `nextRune` for example. * * Functions that have to copy string data will return strings rather than * slices; these can be cast back to slices for further processing if * required. * * For convenience, some functions are provided with non-modifying * variants that create a new slice and return both; for instance, * `s.splitNew('.')` leaves s unmodified, and returns two values * corresponding to the left and right parts of the string. */ pragma solidity ^0.8.0; library strings { struct slice { uint256 _len; uint256 _ptr; } function memcpy( uint256 dest, uint256 src, uint256 len ) private pure { // Copy word-length chunks while possible for (; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint256 mask = type(uint256).max; if (len > 0) { mask = 256**(32 - len) - 1; } assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } } /* * @dev Returns a slice containing the entire string. * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */ function toSlice(string memory self) internal pure returns (slice memory) { uint256 ptr; assembly { ptr := add(self, 0x20) } return slice(bytes(self).length, ptr); } /* * @dev Returns the length of a null-terminated bytes32 string. * @param self The value to find the length of. * @return The length of the string, from 0 to 32. */ function len(bytes32 self) internal pure returns (uint256) { uint256 ret; if (self == 0) return 0; if (uint256(self) & type(uint128).max == 0) { ret += 16; self = bytes32(uint256(self) / 0x100000000000000000000000000000000); } if (uint256(self) & type(uint64).max == 0) { ret += 8; self = bytes32(uint256(self) / 0x10000000000000000); } if (uint256(self) & type(uint32).max == 0) { ret += 4; self = bytes32(uint256(self) / 0x100000000); } if (uint256(self) & type(uint16).max == 0) { ret += 2; self = bytes32(uint256(self) / 0x10000); } if (uint256(self) & type(uint8).max == 0) { ret += 1; } return 32 - ret; } /* * @dev Returns a slice containing the entire bytes32, interpreted as a * null-terminated utf-8 string. * @param self The bytes32 value to convert to a slice. * @return A new slice containing the value of the input argument up to the * first null. */ function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { // Allocate space for `self` in memory, copy it there, and point ret at it assembly { let ptr := mload(0x40) mstore(0x40, add(ptr, 0x20)) mstore(ptr, self) mstore(add(ret, 0x20), ptr) } ret._len = len(self); } /* * @dev Returns a new slice containing the same data as the current slice. * @param self The slice to copy. * @return A new slice containing the same data as `self`. */ function copy(slice memory self) internal pure returns (slice memory) { return slice(self._len, self._ptr); } /* * @dev Copies a slice to a new string. * @param self The slice to copy. * @return A newly allocated string containing the slice's text. */ function toString(slice memory self) internal pure returns (string memory) { string memory ret = new string(self._len); uint256 retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); return ret; } /* * @dev Returns the length in runes of the slice. Note that this operation * takes time proportional to the length of the slice; avoid using it * in loops, and call `slice.empty()` if you only need to know whether * the slice is empty or not. * @param self The slice to operate on. * @return The length of the slice in runes. */ function len(slice memory self) internal pure returns (uint256 l) { // Starting at ptr-31 means the LSB will be the byte we care about uint256 ptr = self._ptr - 31; uint256 end = ptr + self._len; for (l = 0; ptr < end; l++) { uint8 b; assembly { b := and(mload(ptr), 0xFF) } if (b < 0x80) { ptr += 1; } else if (b < 0xE0) { ptr += 2; } else if (b < 0xF0) { ptr += 3; } else if (b < 0xF8) { ptr += 4; } else if (b < 0xFC) { ptr += 5; } else { ptr += 6; } } } /* * @dev Returns true if the slice is empty (has a length of 0). * @param self The slice to operate on. * @return True if the slice is empty, False otherwise. */ function empty(slice memory self) internal pure returns (bool) { return self._len == 0; } /* * @dev Returns a positive number if `other` comes lexicographically after * `self`, a negative number if it comes before, or zero if the * contents of the two slices are equal. Comparison is done per-rune, * on unicode codepoints. * @param self The first slice to compare. * @param other The second slice to compare. * @return The result of the comparison. */ function compare(slice memory self, slice memory other) internal pure returns (int256) { uint256 shortest = self._len; if (other._len < self._len) shortest = other._len; uint256 selfptr = self._ptr; uint256 otherptr = other._ptr; for (uint256 idx = 0; idx < shortest; idx += 32) { uint256 a; uint256 b; assembly { a := mload(selfptr) b := mload(otherptr) } if (a != b) { // Mask out irrelevant bytes and check again uint256 mask = type(uint256).max; // 0xffff... if (shortest < 32) { mask = ~(2**(8 * (32 - shortest + idx)) - 1); } unchecked { uint256 diff = (a & mask) - (b & mask); if (diff != 0) return int256(diff); } } selfptr += 32; otherptr += 32; } return int256(self._len) - int256(other._len); } /* * @dev Returns true if the two slices contain the same text. * @param self The first slice to compare. * @param self The second slice to compare. * @return True if the slices are equal, false otherwise. */ function equals(slice memory self, slice memory other) internal pure returns (bool) { return compare(self, other) == 0; } /* * @dev Extracts the first rune in the slice into `rune`, advancing the * slice to point to the next rune and returning `self`. * @param self The slice to operate on. * @param rune The slice that will contain the first rune. * @return `rune`. */ function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { rune._ptr = self._ptr; if (self._len == 0) { rune._len = 0; return rune; } uint256 l; uint256 b; // Load the first byte of the rune into the LSBs of b assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } if (b < 0x80) { l = 1; } else if (b < 0xE0) { l = 2; } else if (b < 0xF0) { l = 3; } else { l = 4; } // Check for truncated codepoints if (l > self._len) { rune._len = self._len; self._ptr += self._len; self._len = 0; return rune; } self._ptr += l; self._len -= l; rune._len = l; return rune; } /* * @dev Returns the first rune in the slice, advancing the slice to point * to the next rune. * @param self The slice to operate on. * @return A slice containing only the first rune from `self`. */ function nextRune(slice memory self) internal pure returns (slice memory ret) { nextRune(self, ret); } /* * @dev Returns the number of the first codepoint in the slice. * @param self The slice to operate on. * @return The number of the first codepoint in the slice. */ function ord(slice memory self) internal pure returns (uint256 ret) { if (self._len == 0) { return 0; } uint256 word; uint256 length; uint256 divisor = 2**248; // Load the rune into the MSBs of b assembly { word := mload(mload(add(self, 32))) } uint256 b = word / divisor; if (b < 0x80) { ret = b; length = 1; } else if (b < 0xE0) { ret = b & 0x1F; length = 2; } else if (b < 0xF0) { ret = b & 0x0F; length = 3; } else { ret = b & 0x07; length = 4; } // Check for truncated codepoints if (length > self._len) { return 0; } for (uint256 i = 1; i < length; i++) { divisor = divisor / 256; b = (word / divisor) & 0xFF; if (b & 0xC0 != 0x80) { // Invalid UTF-8 sequence return 0; } ret = (ret * 64) | (b & 0x3F); } return ret; } /* * @dev Returns the keccak-256 hash of the slice. * @param self The slice to hash. * @return The hash of the slice. */ function keccak(slice memory self) internal pure returns (bytes32 ret) { assembly { ret := keccak256(mload(add(self, 32)), mload(self)) } } /* * @dev Returns true if `self` starts with `needle`. * @param self The slice to operate on. * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { if (self._len < needle._len) { return false; } if (self._ptr == needle._ptr) { return true; } bool equal; assembly { let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } return equal; } /* * @dev If `self` starts with `needle`, `needle` is removed from the * beginning of `self`. Otherwise, `self` is unmodified. * @param self The slice to operate on. * @param needle The slice to search for. * @return `self` */ function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { if (self._len < needle._len) { return self; } bool equal = true; if (self._ptr != needle._ptr) { assembly { let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } } if (equal) { self._len -= needle._len; self._ptr += needle._len; } return self; } /* * @dev Returns true if the slice ends with `needle`. * @param self The slice to operate on. * @param needle The slice to search for. * @return True if the slice starts with the provided text, false otherwise. */ function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { if (self._len < needle._len) { return false; } uint256 selfptr = self._ptr + self._len - needle._len; if (selfptr == needle._ptr) { return true; } bool equal; assembly { let length := mload(needle) let needleptr := mload(add(needle, 0x20)) equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } return equal; } /* * @dev If `self` ends with `needle`, `needle` is removed from the * end of `self`. Otherwise, `self` is unmodified. * @param self The slice to operate on. * @param needle The slice to search for. * @return `self` */ function until(slice memory self, slice memory needle) internal pure returns (slice memory) { if (self._len < needle._len) { return self; } uint256 selfptr = self._ptr + self._len - needle._len; bool equal = true; if (selfptr != needle._ptr) { assembly { let length := mload(needle) let needleptr := mload(add(needle, 0x20)) equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } } if (equal) { self._len -= needle._len; } return self; } // Returns the memory address of the first byte of the first occurrence of // `needle` in `self`, or the first byte after `self` if not found. function findPtr( uint256 selflen, uint256 selfptr, uint256 needlelen, uint256 needleptr ) private pure returns (uint256) { uint256 ptr = selfptr; uint256 idx; if (needlelen <= selflen) { if (needlelen <= 32) { bytes32 mask; if (needlelen > 0) { mask = bytes32(~(2**(8 * (32 - needlelen)) - 1)); } bytes32 needledata; assembly { needledata := and(mload(needleptr), mask) } uint256 end = selfptr + selflen - needlelen; bytes32 ptrdata; assembly { ptrdata := and(mload(ptr), mask) } while (ptrdata != needledata) { if (ptr >= end) return selfptr + selflen; ptr++; assembly { ptrdata := and(mload(ptr), mask) } } return ptr; } else { // For long needles, use hashing bytes32 hash; assembly { hash := keccak256(needleptr, needlelen) } for (idx = 0; idx <= selflen - needlelen; idx++) { bytes32 testHash; assembly { testHash := keccak256(ptr, needlelen) } if (hash == testHash) return ptr; ptr += 1; } } } return selfptr + selflen; } // Returns the memory address of the first byte after the last occurrence of // `needle` in `self`, or the address of `self` if not found. function rfindPtr( uint256 selflen, uint256 selfptr, uint256 needlelen, uint256 needleptr ) private pure returns (uint256) { uint256 ptr; if (needlelen <= selflen) { if (needlelen <= 32) { bytes32 mask; if (needlelen > 0) { mask = bytes32(~(2**(8 * (32 - needlelen)) - 1)); } bytes32 needledata; assembly { needledata := and(mload(needleptr), mask) } ptr = selfptr + selflen - needlelen; bytes32 ptrdata; assembly { ptrdata := and(mload(ptr), mask) } while (ptrdata != needledata) { if (ptr <= selfptr) return selfptr; ptr--; assembly { ptrdata := and(mload(ptr), mask) } } return ptr + needlelen; } else { // For long needles, use hashing bytes32 hash; assembly { hash := keccak256(needleptr, needlelen) } ptr = selfptr + (selflen - needlelen); while (ptr >= selfptr) { bytes32 testHash; assembly { testHash := keccak256(ptr, needlelen) } if (hash == testHash) return ptr + needlelen; ptr -= 1; } } } return selfptr; } /* * @dev Modifies `self` to contain everything from the first occurrence of * `needle` to the end of the slice. `self` is set to the empty slice * if `needle` is not found. * @param self The slice to search and modify. * @param needle The text to search for. * @return `self`. */ function find(slice memory self, slice memory needle) internal pure returns (slice memory) { uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); self._len -= ptr - self._ptr; self._ptr = ptr; return self; } /* * @dev Modifies `self` to contain the part of the string from the start of * `self` to the end of the first occurrence of `needle`. If `needle` * is not found, `self` is set to the empty slice. * @param self The slice to search and modify. * @param needle The text to search for. * @return `self`. */ function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); self._len = ptr - self._ptr; return self; } /* * @dev Splits the slice, setting `self` to everything after the first * occurrence of `needle`, and `token` to everything before it. If * `needle` does not occur in `self`, `self` is set to the empty slice, * and `token` is set to the entirety of `self`. * @param self The slice to split. * @param needle The text to search for in `self`. * @param token An output parameter to which the first token is written. * @return `token`. */ function split( slice memory self, slice memory needle, slice memory token ) internal pure returns (slice memory) { uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); token._ptr = self._ptr; token._len = ptr - self._ptr; if (ptr == self._ptr + self._len) { // Not found self._len = 0; } else { self._len -= token._len + needle._len; self._ptr = ptr + needle._len; } return token; } /* * @dev Splits the slice, setting `self` to everything after the first * occurrence of `needle`, and returning everything before it. If * `needle` does not occur in `self`, `self` is set to the empty slice, * and the entirety of `self` is returned. * @param self The slice to split. * @param needle The text to search for in `self`. * @return The part of `self` up to the first occurrence of `delim`. */ function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { split(self, needle, token); } /* * @dev Splits the slice, setting `self` to everything before the last * occurrence of `needle`, and `token` to everything after it. If * `needle` does not occur in `self`, `self` is set to the empty slice, * and `token` is set to the entirety of `self`. * @param self The slice to split. * @param needle The text to search for in `self`. * @param token An output parameter to which the first token is written. * @return `token`. */ function rsplit( slice memory self, slice memory needle, slice memory token ) internal pure returns (slice memory) { uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); token._ptr = ptr; token._len = self._len - (ptr - self._ptr); if (ptr == self._ptr) { // Not found self._len = 0; } else { self._len -= token._len + needle._len; } return token; } /* * @dev Splits the slice, setting `self` to everything before the last * occurrence of `needle`, and returning everything after it. If * `needle` does not occur in `self`, `self` is set to the empty slice, * and the entirety of `self` is returned. * @param self The slice to split. * @param needle The text to search for in `self`. * @return The part of `self` after the last occurrence of `delim`. */ function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { rsplit(self, needle, token); } /* * @dev Counts the number of nonoverlapping occurrences of `needle` in `self`. * @param self The slice to search. * @param needle The text to search for in `self`. * @return The number of occurrences of `needle` found in `self`. */ function count(slice memory self, slice memory needle) internal pure returns (uint256 cnt) { uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; while (ptr <= self._ptr + self._len) { cnt++; ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; } } /* * @dev Returns True if `self` contains `needle`. * @param self The slice to search. * @param needle The text to search for in `self`. * @return True if `needle` is found in `self`, false otherwise. */ function contains(slice memory self, slice memory needle) internal pure returns (bool) { return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; } /* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */ function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint256 retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); memcpy(retptr + self._len, other._ptr, other._len); return ret; } /* * @dev Joins an array of slices, using `self` as a delimiter, returning a * newly allocated string. * @param self The delimiter to use. * @param parts A list of slices to join. * @return A newly allocated string containing all the slices in `parts`, * joined with `self`. */ function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { if (parts.length == 0) return ""; uint256 length = self._len * (parts.length - 1); for (uint256 i = 0; i < parts.length; i++) length += parts[i]._len; string memory ret = new string(length); uint256 retptr; assembly { retptr := add(ret, 32) } for (uint256 i = 0; i < parts.length; i++) { memcpy(retptr, parts[i]._ptr, parts[i]._len); retptr += parts[i]._len; if (i < parts.length - 1) { memcpy(retptr, self._ptr, self._len); retptr += self._len; } } return ret; } }
// SPDX-License-Identifier: MIT // sourced from https://github.com/pipermerriam/ethereum-datetime pragma solidity ^0.8.0; library DateTime { /* * Date and Time utilities for ethereum contracts * */ struct _DateTime { uint16 year; uint8 month; uint8 day; uint8 hour; uint8 minute; uint8 second; uint8 weekday; } uint256 constant DAY_IN_SECONDS = 86400; uint256 constant YEAR_IN_SECONDS = 31536000; uint256 constant LEAP_YEAR_IN_SECONDS = 31622400; uint256 constant HOUR_IN_SECONDS = 3600; uint256 constant MINUTE_IN_SECONDS = 60; uint16 constant ORIGIN_YEAR = 1970; function isLeapYear(uint16 year) internal pure returns (bool) { if (year % 4 != 0) { return false; } if (year % 100 != 0) { return true; } if (year % 400 != 0) { return false; } return true; } function leapYearsBefore(uint256 year) internal pure returns (uint256) { year -= 1; return year / 4 - year / 100 + year / 400; } function getDaysInMonth(uint8 month, uint16 year) internal pure returns (uint8) { if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) { return 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else if (isLeapYear(year)) { return 29; } else { return 28; } } function parseTimestamp(uint256 timestamp) internal pure returns (_DateTime memory dt) { uint256 secondsAccountedFor = 0; uint256 buf; uint8 i; // Year dt.year = getYear(timestamp); buf = leapYearsBefore(dt.year) - leapYearsBefore(ORIGIN_YEAR); secondsAccountedFor += LEAP_YEAR_IN_SECONDS * buf; secondsAccountedFor += YEAR_IN_SECONDS * (dt.year - ORIGIN_YEAR - buf); // Month uint256 secondsInMonth; for (i = 1; i <= 12; i++) { secondsInMonth = DAY_IN_SECONDS * getDaysInMonth(i, dt.year); if (secondsInMonth + secondsAccountedFor > timestamp) { dt.month = i; break; } secondsAccountedFor += secondsInMonth; } // Day for (i = 1; i <= getDaysInMonth(dt.month, dt.year); i++) { if (DAY_IN_SECONDS + secondsAccountedFor > timestamp) { dt.day = i; break; } secondsAccountedFor += DAY_IN_SECONDS; } // Hour dt.hour = getHour(timestamp); // Minute dt.minute = getMinute(timestamp); // Second dt.second = getSecond(timestamp); // Day of week. dt.weekday = getWeekday(timestamp); } function getYear(uint256 timestamp) internal pure returns (uint16) { uint256 secondsAccountedFor = 0; uint16 year; uint256 numLeapYears; // Year year = uint16(ORIGIN_YEAR + timestamp / YEAR_IN_SECONDS); numLeapYears = leapYearsBefore(year) - leapYearsBefore(ORIGIN_YEAR); secondsAccountedFor += LEAP_YEAR_IN_SECONDS * numLeapYears; secondsAccountedFor += YEAR_IN_SECONDS * (year - ORIGIN_YEAR - numLeapYears); while (secondsAccountedFor > timestamp) { if (isLeapYear(uint16(year - 1))) { secondsAccountedFor -= LEAP_YEAR_IN_SECONDS; } else { secondsAccountedFor -= YEAR_IN_SECONDS; } year -= 1; } return year; } function getMonth(uint256 timestamp) internal pure returns (uint8) { return parseTimestamp(timestamp).month; } function getDay(uint256 timestamp) internal pure returns (uint8) { return parseTimestamp(timestamp).day; } function getHour(uint256 timestamp) internal pure returns (uint8) { return uint8((timestamp / 60 / 60) % 24); } function getMinute(uint256 timestamp) internal pure returns (uint8) { return uint8((timestamp / 60) % 60); } function getSecond(uint256 timestamp) internal pure returns (uint8) { return uint8(timestamp % 60); } function getWeekday(uint256 timestamp) internal pure returns (uint8) { return uint8((timestamp / DAY_IN_SECONDS + 4) % 7); } function toTimestamp( uint16 year, uint8 month, uint8 day ) internal pure returns (uint256 timestamp) { return toTimestamp(year, month, day, 0, 0, 0); } function toTimestamp( uint16 year, uint8 month, uint8 day, uint8 hour ) internal pure returns (uint256 timestamp) { return toTimestamp(year, month, day, hour, 0, 0); } function toTimestamp( uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute ) internal pure returns (uint256 timestamp) { return toTimestamp(year, month, day, hour, minute, 0); } function toTimestamp( uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute, uint8 second ) internal pure returns (uint256 timestamp) { uint16 i; // Year for (i = ORIGIN_YEAR; i < year; i++) { if (isLeapYear(i)) { timestamp += LEAP_YEAR_IN_SECONDS; } else { timestamp += YEAR_IN_SECONDS; } } // Month uint8[12] memory monthDayCounts; monthDayCounts[0] = 31; if (isLeapYear(year)) { monthDayCounts[1] = 29; } else { monthDayCounts[1] = 28; } monthDayCounts[2] = 31; monthDayCounts[3] = 30; monthDayCounts[4] = 31; monthDayCounts[5] = 30; monthDayCounts[6] = 31; monthDayCounts[7] = 31; monthDayCounts[8] = 30; monthDayCounts[9] = 31; monthDayCounts[10] = 30; monthDayCounts[11] = 31; for (i = 1; i < month; i++) { timestamp += DAY_IN_SECONDS * monthDayCounts[i - 1]; } // Day timestamp += DAY_IN_SECONDS * (day - 1); // Hour timestamp += HOUR_IN_SECONDS * (hour); // Minute timestamp += MINUTE_IN_SECONDS * (minute); // Second timestamp += second; return timestamp; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../upkeeps/CronUpkeep.sol"; import {Cron, Spec} from "../libraries/internal/Cron.sol"; /** * @title The CronUpkeepTestHelper contract * @notice This contract exposes core functionality of the CronUpkeep contract. * It is only intended for use in tests. */ contract CronUpkeepTestHelper is CronUpkeep { using Cron for Spec; using Cron for string; constructor( address owner, address delegate, uint256 maxJobs, bytes memory firstJob ) CronUpkeep(owner, delegate, maxJobs, firstJob) {} /** * @notice createCronJobFromString is a helper function for creating cron jobs * directly from strings. This is gas-intensive and shouldn't be done outside * of testing environments. */ function createCronJobFromString( address target, bytes memory handler, string memory cronString ) external { Spec memory spec = cronString.toSpec(); createCronJobFromSpec(target, handler, spec); } /** * @notice txCheckUpkeep is a helper function for sending real txs to the * checkUpkeep function. This allows us to do gas analysis on it. */ function txCheckUpkeep(bytes calldata checkData) external { address(this).call(abi.encodeWithSelector(bytes4(keccak256("checkUpkeep(bytes)")), checkData)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import {Cron as CronInternal, Spec} from "../libraries/internal/Cron.sol"; import {Cron as CronExternal} from "../libraries/external/Cron.sol"; /** * @title The CronInternalTestHelper contract * @notice This contract exposes core functionality of the internal/Cron library. * It is only intended for use in tests. */ contract CronInternalTestHelper { /** * @notice Converts a cron string to a Spec, validates the spec, and encodes the spec. * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to convert and encode * @return the abi encoding of the Spec struct representing the cron string */ function encodeCronString(string memory cronString) external pure returns (bytes memory) { return CronInternal.toEncodedSpec(cronString); } /** * @notice encodedSpecToString is a helper function for turning an * encoded spec back into a string. There is limited or no use for this outside * of tests. */ function encodedSpecToString(bytes memory encodedSpec) public pure returns (string memory) { Spec memory spec = abi.decode(encodedSpec, (Spec)); return CronInternal.toCronString(spec); } /** * @notice calculateNextTick calculates the next time a cron job should "tick". * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to consider * @return the timestamp in UTC of the next "tick" */ function calculateNextTick(string memory cronString) external view returns (uint256) { return CronInternal.nextTick(CronInternal.toSpec(cronString)); } /** * @notice calculateLastTick calculates the last time a cron job "ticked". * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to consider * @return the timestamp in UTC of the last "tick" */ function calculateLastTick(string memory cronString) external view returns (uint256) { return CronInternal.lastTick(CronInternal.toSpec(cronString)); } } /** * @title The CronExternalTestHelper contract * @notice This contract exposes core functionality of the external/Cron library. * It is only intended for use in tests. */ contract CronExternalTestHelper { /** * @notice Converts a cron string to a Spec, validates the spec, and encodes the spec. * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to convert and encode * @return the abi encoding of the Spec struct representing the cron string */ function encodeCronString(string memory cronString) external pure returns (bytes memory) { return CronExternal.toEncodedSpec(cronString); } /** * @notice encodedSpecToString is a helper function for turning an * encoded spec back into a string. There is limited or no use for this outside * of tests. */ function encodedSpecToString(bytes memory encodedSpec) public pure returns (string memory) { Spec memory spec = abi.decode(encodedSpec, (Spec)); return CronExternal.toCronString(spec); } /** * @notice calculateNextTick calculates the next time a cron job should "tick". * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to consider * @return the timestamp in UTC of the next "tick" */ function calculateNextTick(string memory cronString) external view returns (uint256) { return CronExternal.nextTick(CronExternal.toSpec(cronString)); } /** * @notice calculateLastTick calculates the last time a cron job "ticked". * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to consider * @return the timestamp in UTC of the last "tick" */ function calculateLastTick(string memory cronString) external view returns (uint256) { return CronExternal.lastTick(CronExternal.toSpec(cronString)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../upkeeps/CronUpkeep.sol"; import "../upkeeps/CronUpkeepDelegate.sol"; import "../ConfirmedOwner.sol"; import {Spec, Cron as CronExternal} from "../libraries/external/Cron.sol"; /** * @title The CronUpkeepFactory contract * @notice This contract serves as a delegate for all instances of CronUpkeep. Those contracts * delegate their checkUpkeep calls onto this contract. Utilizing this pattern reduces the size * of the CronUpkeep contracts. */ contract CronUpkeepFactory is ConfirmedOwner { event NewCronUpkeepCreated(address upkeep, address owner); address private immutable s_cronDelegate; uint256 public s_maxJobs = 5; constructor() ConfirmedOwner(msg.sender) { s_cronDelegate = address(new CronUpkeepDelegate()); } /** * @notice Creates a new CronUpkeep contract, with msg.sender as the owner */ function newCronUpkeep() external { newCronUpkeepWithJob(bytes("")); } /** * @notice Creates a new CronUpkeep contract, with msg.sender as the owner, and registers a cron job */ function newCronUpkeepWithJob(bytes memory encodedJob) public { emit NewCronUpkeepCreated(address(new CronUpkeep(msg.sender, s_cronDelegate, s_maxJobs, encodedJob)), msg.sender); } /** * @notice Sets the max job limit on new cron upkeeps */ function setMaxJobs(uint256 maxJobs) external onlyOwner { s_maxJobs = maxJobs; } /** * @notice Gets the address of the delegate contract * @return the address of the delegate contract */ function cronDelegateAddress() external view returns (address) { return s_cronDelegate; } /** * @notice Converts a cron string to a Spec, validates the spec, and encodes the spec. * This should only be called off-chain, as it is gas expensive! * @param cronString the cron string to convert and encode * @return the abi encoding of the Spec struct representing the cron string */ function encodeCronString(string memory cronString) external pure returns (bytes memory) { return CronExternal.toEncodedSpec(cronString); } /** * @notice Converts, validates, and encodes a full cron spec. This payload is then passed to newCronUpkeepWithJob. * @param target the destination contract of a cron job * @param handler the function signature on the target contract to call * @param cronString the cron string to convert and encode * @return the abi encoding of the entire cron job */ function encodeCronJob( address target, bytes memory handler, string memory cronString ) external pure returns (bytes memory) { Spec memory spec = CronExternal.toSpec(cronString); return abi.encode(target, handler, spec); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import {Cron, Spec} from "../libraries/internal/Cron.sol"; /** * @title The CronUpkeepDelegate contract * @notice This contract serves as a delegate for all instances of CronUpkeep. Those contracts * delegate their checkUpkeep calls onto this contract. Utilizing this pattern reduces the size * of the CronUpkeep contracts. */ contract CronUpkeepDelegate { using EnumerableSet for EnumerableSet.UintSet; using Cron for Spec; address private s_owner; // from ConfirmedOwner address private s_delegate; uint256 private s_nextCronJobID; EnumerableSet.UintSet private s_activeCronJobIDs; mapping(uint256 => uint256) private s_lastRuns; mapping(uint256 => Spec) private s_specs; mapping(uint256 => address) private s_targets; mapping(uint256 => bytes) private s_handlers; /** * @notice Get the id of an eligible cron job * @return upkeepNeeded signals if upkeep is needed, performData is an abi encoding * of the id and "next tick" of the eligible cron job */ function checkUpkeep(bytes calldata) external view returns (bool, bytes memory) { // DEV: start at a random spot in the list so that checks are // spread evenly among cron jobs uint256 numCrons = s_activeCronJobIDs.length(); if (numCrons == 0) { return (false, bytes("")); } uint256 startIdx = block.number % numCrons; bool result; bytes memory payload; (result, payload) = checkInRange(startIdx, numCrons); if (result) { return (result, payload); } (result, payload) = checkInRange(0, startIdx); if (result) { return (result, payload); } return (false, bytes("")); } /** * @notice checks the cron jobs in a given range * @param start the starting id to check (inclusive) * @param end the ending id to check (exclusive) * @return upkeepNeeded signals if upkeep is needed, performData is an abi encoding * of the id and "next tick" of the eligible cron job */ function checkInRange(uint256 start, uint256 end) private view returns (bool, bytes memory) { uint256 id; uint256 lastTick; for (uint256 idx = start; idx < end; idx++) { id = s_activeCronJobIDs.at(idx); lastTick = s_specs[id].lastTick(); if (lastTick > s_lastRuns[id]) { return (true, abi.encode(id, lastTick, s_targets[id], s_handlers[id])); } } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "@openzeppelin/contracts/utils/Address.sol"; import "./ConfirmedOwner.sol"; /** * @title PermissionedForwardProxy * @notice This proxy is used to forward calls from sender to target. It maintains * a permission list to check which sender is allowed to call which target */ contract PermissionedForwardProxy is ConfirmedOwner { using Address for address; error PermissionNotSet(); event PermissionSet(address indexed sender, address target); event PermissionRemoved(address indexed sender); mapping(address => address) private s_forwardPermissionList; constructor() ConfirmedOwner(msg.sender) {} /** * @notice Verifies if msg.sender has permission to forward to target address and then forwards the handler * @param target address of the contract to forward the handler to * @param handler bytes to be passed to target in call data */ function forward(address target, bytes calldata handler) external { if (s_forwardPermissionList[msg.sender] != target) { revert PermissionNotSet(); } target.functionCall(handler); } /** * @notice Adds permission for sender to forward calls to target via this proxy. * Note that it allows to overwrite an existing permission * @param sender The address who will use this proxy to forward calls * @param target The address where sender will be allowed to forward calls */ function setPermission(address sender, address target) external onlyOwner { s_forwardPermissionList[sender] = target; emit PermissionSet(sender, target); } /** * @notice Removes permission for sender to forward calls via this proxy * @param sender The address who will use this proxy to forward calls */ function removePermission(address sender) external onlyOwner { delete s_forwardPermissionList[sender]; emit PermissionRemoved(sender); } /** * @notice Returns the target address that the sender can use this proxy for * @param sender The address to fetch the permissioned target for */ function getPermission(address sender) external view returns (address) { return s_forwardPermissionList[sender]; } }
pragma solidity 0.8.6; import "../vendor/@eth-optimism/contracts/0.8.6/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; contract OptimismPriceTest { OVM_GasPriceOracle public immutable OPTIMISM_ORACLE = OVM_GasPriceOracle(0x420000000000000000000000000000000000000F); uint256 public gas0; uint256 public gas1; uint256 public l1CostWei; function test(bytes calldata performData) external { gas0 = gasleft(); l1CostWei = OPTIMISM_ORACLE.getL1Fee(performData); gas1 = gasleft(); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import "../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol"; import "../vendor/@eth-optimism/contracts/0.8.6/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; import "../ExecutionPrevention.sol"; import {OnchainConfig, State, UpkeepFailureReason} from "../interfaces/KeeperRegistryInterface2_0.sol"; import "../ConfirmedOwner.sol"; import "../interfaces/AggregatorV3Interface.sol"; import "../interfaces/LinkTokenInterface.sol"; import "../interfaces/KeeperCompatibleInterface.sol"; import "../interfaces/UpkeepTranscoderInterface.sol"; /** * @notice Base Keeper Registry contract, contains shared logic between * KeeperRegistry and KeeperRegistryLogic */ abstract contract KeeperRegistryBase2_0 is ConfirmedOwner, ExecutionPrevention { address internal constant ZERO_ADDRESS = address(0); address internal constant IGNORE_ADDRESS = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF; bytes4 internal constant CHECK_SELECTOR = KeeperCompatibleInterface.checkUpkeep.selector; bytes4 internal constant PERFORM_SELECTOR = KeeperCompatibleInterface.performUpkeep.selector; uint256 internal constant PERFORM_GAS_MIN = 2_300; uint256 internal constant CANCELLATION_DELAY = 50; uint256 internal constant PERFORM_GAS_CUSHION = 5_000; uint256 internal constant PPB_BASE = 1_000_000_000; uint32 internal constant UINT32_MAX = type(uint32).max; uint96 internal constant LINK_TOTAL_SUPPLY = 1e27; // The first byte of the mask can be 0, because we only ever have 31 oracles uint256 internal constant ORACLE_MASK = 0x0001010101010101010101010101010101010101010101010101010101010101; UpkeepFormat internal constant UPKEEP_TRANSCODER_VERSION_BASE = UpkeepFormat.V3; // L1_FEE_DATA_PADDING includes 35 bytes for L1 data padding for Optimism bytes internal constant L1_FEE_DATA_PADDING = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; uint256 internal constant REGISTRY_GAS_OVERHEAD = 65_000; // Used only in maxPayment estimation, not in actual payment uint256 internal constant REGISTRY_PER_PERFORM_BYTE_GAS_OVERHEAD = 20; // Used only in maxPayment estimation, not in actual payment. Value scales with performData length. uint256 internal constant REGISTRY_PER_SIGNER_GAS_OVERHEAD = 7_500; // Used only in maxPayment estimation, not in actual payment. Value scales with f. uint256 internal constant ACCOUNTING_FIXED_GAS_OVERHEAD = 26_900; // Used in actual payment. Fixed overhead per tx uint256 internal constant ACCOUNTING_PER_SIGNER_GAS_OVERHEAD = 1_100; // Used in actual payment. overhead per signer uint256 internal constant ACCOUNTING_PER_UPKEEP_GAS_OVERHEAD = 5_800; // Used in actual payment. overhead per upkeep performed OVM_GasPriceOracle internal constant OPTIMISM_ORACLE = OVM_GasPriceOracle(0x420000000000000000000000000000000000000F); ArbGasInfo internal constant ARB_NITRO_ORACLE = ArbGasInfo(0x000000000000000000000000000000000000006C); LinkTokenInterface internal immutable i_link; AggregatorV3Interface internal immutable i_linkNativeFeed; AggregatorV3Interface internal immutable i_fastGasFeed; PaymentModel internal immutable i_paymentModel; // @dev - The storage is gas optimised for one and only function - transmit. All the storage accessed in transmit // is stored compactly. Rest of the storage layout is not of much concern as transmit is the only hot path // Upkeep storage EnumerableSet.UintSet internal s_upkeepIDs; mapping(uint256 => Upkeep) internal s_upkeep; // accessed during transmit mapping(uint256 => address) internal s_upkeepAdmin; mapping(uint256 => address) internal s_proposedAdmin; mapping(uint256 => bytes) internal s_checkData; // Registry config and state mapping(address => Transmitter) internal s_transmitters; mapping(address => Signer) internal s_signers; address[] internal s_signersList; // s_signersList contains the signing address of each oracle address[] internal s_transmittersList; // s_transmittersList contains the transmission address of each oracle mapping(address => address) internal s_transmitterPayees; // s_payees contains the mapping from transmitter to payee. mapping(address => address) internal s_proposedPayee; // proposed payee for a transmitter bytes32 internal s_latestConfigDigest; // Read on transmit path in case of signature verification HotVars internal s_hotVars; // Mixture of config and state, used in transmit Storage internal s_storage; // Mixture of config and state, not used in transmit uint256 internal s_fallbackGasPrice; uint256 internal s_fallbackLinkPrice; uint256 internal s_expectedLinkBalance; // Used in case of erroneous LINK transfers to contract mapping(address => MigrationPermission) internal s_peerRegistryMigrationPermission; // Permissions for migration to and fro mapping(uint256 => bytes) internal s_upkeepOffchainConfig; // general configuration preferences error ArrayHasNoEntries(); error CannotCancel(); error DuplicateEntry(); error GasLimitCanOnlyIncrease(); error GasLimitOutsideRange(); error IndexOutOfRange(); error InsufficientFunds(); error InvalidDataLength(); error InvalidPayee(); error InvalidRecipient(); error MigrationNotPermitted(); error NotAContract(); error OnlyActiveTransmitters(); error OnlyCallableByAdmin(); error OnlyCallableByLINKToken(); error OnlyCallableByOwnerOrAdmin(); error OnlyCallableByOwnerOrRegistrar(); error OnlyCallableByPayee(); error OnlyCallableByProposedAdmin(); error OnlyCallableByProposedPayee(); error OnlyPausedUpkeep(); error OnlyUnpausedUpkeep(); error ParameterLengthError(); error PaymentGreaterThanAllLINK(); error TargetCheckReverted(bytes reason); error TranscoderNotSet(); error UpkeepCancelled(); error UpkeepNotCanceled(); error UpkeepNotNeeded(); error ValueNotChanged(); error ConfigDigestMismatch(); error IncorrectNumberOfSignatures(); error OnlyActiveSigners(); error DuplicateSigners(); error StaleReport(); error TooManyOracles(); error IncorrectNumberOfSigners(); error IncorrectNumberOfFaultyOracles(); error RepeatedSigner(); error RepeatedTransmitter(); error OnchainConfigNonEmpty(); error CheckDataExceedsLimit(); error MaxCheckDataSizeCanOnlyIncrease(); error MaxPerformDataSizeCanOnlyIncrease(); error InvalidReport(); error RegistryPaused(); error ReentrantCall(); error UpkeepAlreadyExists(); enum MigrationPermission { NONE, OUTGOING, INCOMING, BIDIRECTIONAL } enum PaymentModel { DEFAULT, ARBITRUM, OPTIMISM } // Config + State storage struct which is on hot transmit path struct HotVars { uint8 f; // maximum number of faulty oracles uint32 paymentPremiumPPB; // premium percentage charged to user over tx cost uint32 flatFeeMicroLink; // flat fee charged to user for every perform uint24 stalenessSeconds; // Staleness tolerance for feeds uint16 gasCeilingMultiplier; // multiplier on top of fast gas feed for upper bound bool paused; // pause switch for all upkeeps in the registry bool reentrancyGuard; // guard against reentrancy uint96 totalPremium; // total historical payment to oracles for premium uint32 latestEpoch; // latest epoch for which a report was transmitted // 1 EVM word full } // Config + State storage struct which is not on hot transmit path struct Storage { uint96 minUpkeepSpend; // Minimum amount an upkeep must spend address transcoder; // Address of transcoder contract used in migrations // 1 EVM word full uint96 ownerLinkBalance; // Balance of owner, accumulates minUpkeepSpend in case it is not spent address registrar; // Address of registrar used to register upkeeps // 2 EVM word full uint32 checkGasLimit; // Gas limit allowed in checkUpkeep uint32 maxPerformGas; // Max gas an upkeep can use on this registry uint32 nonce; // Nonce for each upkeep created uint32 configCount; // incremented each time a new config is posted, The count // is incorporated into the config digest to prevent replay attacks. uint32 latestConfigBlockNumber; // makes it easier for offchain systems to extract config from logs uint32 maxCheckDataSize; // max length of checkData bytes uint32 maxPerformDataSize; // max length of performData bytes // 4 bytes to 3rd EVM word } struct Transmitter { bool active; uint8 index; // Index of oracle in s_signersList/s_transmittersList uint96 balance; uint96 lastCollected; } struct Signer { bool active; // Index of oracle in s_signersList/s_transmittersList uint8 index; } // This struct is used to pack information about the user's check function struct PerformDataWrapper { uint32 checkBlockNumber; // Block number-1 on which check was simulated bytes32 checkBlockhash; // blockhash of checkBlockNumber. Used for reorg protection bytes performData; // actual performData that user's check returned } // Report transmitted by OCR to transmit function struct Report { uint256 fastGasWei; uint256 linkNative; uint256[] upkeepIds; // Ids of upkeeps PerformDataWrapper[] wrappedPerformDatas; // Contains checkInfo and performData for the corresponding upkeeps } /** * @notice relevant state of an upkeep which is used in transmit function * @member balance the balance of this upkeep * @member target the contract which needs to be serviced * @member amountSpent the amount this upkeep has spent * @member executeGas the gas limit of upkeep execution * @member maxValidBlocknumber until which block this upkeep is valid * @member lastPerformBlockNumber the last block number when this upkeep was performed * @member paused if this upkeep has been paused */ struct Upkeep { uint32 executeGas; uint32 maxValidBlocknumber; bool paused; address target; // 3 bytes left in 1st EVM word - not written to in transmit uint96 amountSpent; uint96 balance; uint32 lastPerformBlockNumber; // 4 bytes left in 2nd EVM word - written in transmit path } event FundsAdded(uint256 indexed id, address indexed from, uint96 amount); event FundsWithdrawn(uint256 indexed id, uint256 amount, address to); event OwnerFundsWithdrawn(uint96 amount); event PayeesUpdated(address[] transmitters, address[] payees); event PayeeshipTransferRequested(address indexed transmitter, address indexed from, address indexed to); event PayeeshipTransferred(address indexed transmitter, address indexed from, address indexed to); event PaymentWithdrawn(address indexed transmitter, uint256 indexed amount, address indexed to, address payee); event UpkeepAdminTransferRequested(uint256 indexed id, address indexed from, address indexed to); event UpkeepAdminTransferred(uint256 indexed id, address indexed from, address indexed to); event UpkeepCanceled(uint256 indexed id, uint64 indexed atBlockHeight); event UpkeepCheckDataUpdated(uint256 indexed id, bytes newCheckData); event UpkeepGasLimitSet(uint256 indexed id, uint96 gasLimit); event UpkeepOffchainConfigSet(uint256 indexed id, bytes offchainConfig); event UpkeepMigrated(uint256 indexed id, uint256 remainingBalance, address destination); event UpkeepPaused(uint256 indexed id); event UpkeepPerformed( uint256 indexed id, bool indexed success, uint32 checkBlockNumber, uint256 gasUsed, uint256 gasOverhead, uint96 totalPayment ); event UpkeepReceived(uint256 indexed id, uint256 startingBalance, address importedFrom); event UpkeepUnpaused(uint256 indexed id); event UpkeepRegistered(uint256 indexed id, uint32 executeGas, address admin); event StaleUpkeepReport(uint256 indexed id); event ReorgedUpkeepReport(uint256 indexed id); event InsufficientFundsUpkeepReport(uint256 indexed id); event CancelledUpkeepReport(uint256 indexed id); event Paused(address account); event Unpaused(address account); /** * @param paymentModel the payment model of default, Arbitrum, or Optimism * @param link address of the LINK Token * @param linkNativeFeed address of the LINK/Native price feed * @param fastGasFeed address of the Fast Gas price feed */ constructor( PaymentModel paymentModel, address link, address linkNativeFeed, address fastGasFeed ) ConfirmedOwner(msg.sender) { i_paymentModel = paymentModel; i_link = LinkTokenInterface(link); i_linkNativeFeed = AggregatorV3Interface(linkNativeFeed); i_fastGasFeed = AggregatorV3Interface(fastGasFeed); } //////// // GETTERS //////// function getPaymentModel() external view returns (PaymentModel) { return i_paymentModel; } function getLinkAddress() external view returns (address) { return address(i_link); } function getLinkNativeFeedAddress() external view returns (address) { return address(i_linkNativeFeed); } function getFastGasFeedAddress() external view returns (address) { return address(i_fastGasFeed); } //////// // INTERNAL //////// /** * @dev retrieves feed data for fast gas/native and link/native prices. if the feed * data is stale it uses the configured fallback price. Once a price is picked * for gas it takes the min of gas price in the transaction or the fast gas * price in order to reduce costs for the upkeep clients. */ function _getFeedData(HotVars memory hotVars) internal view returns (uint256 gasWei, uint256 linkNative) { uint32 stalenessSeconds = hotVars.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; uint256 timestamp; int256 feedValue; (, feedValue, , timestamp, ) = i_fastGasFeed.latestRoundData(); if ( feedValue <= 0 || block.timestamp < timestamp || (staleFallback && stalenessSeconds < block.timestamp - timestamp) ) { gasWei = s_fallbackGasPrice; } else { gasWei = uint256(feedValue); } (, feedValue, , timestamp, ) = i_linkNativeFeed.latestRoundData(); if ( feedValue <= 0 || block.timestamp < timestamp || (staleFallback && stalenessSeconds < block.timestamp - timestamp) ) { linkNative = s_fallbackLinkPrice; } else { linkNative = uint256(feedValue); } return (gasWei, linkNative); } /** * @dev calculates LINK paid for gas spent plus a configure premium percentage * @param gasLimit the amount of gas used * @param gasOverhead the amount of gas overhead * @param fastGasWei the fast gas price * @param linkNative the exchange ratio between LINK and Native token * @param numBatchedUpkeeps the number of upkeeps in this batch. Used to divide the L1 cost * @param isExecution if this is triggered by a perform upkeep function */ function _calculatePaymentAmount( HotVars memory hotVars, uint256 gasLimit, uint256 gasOverhead, uint256 fastGasWei, uint256 linkNative, uint16 numBatchedUpkeeps, bool isExecution ) internal view returns (uint96, uint96) { uint256 gasWei = fastGasWei * hotVars.gasCeilingMultiplier; // in case it's actual execution use actual gas price, capped by fastGasWei * gasCeilingMultiplier if (isExecution && tx.gasprice < gasWei) { gasWei = tx.gasprice; } uint256 l1CostWei = 0; if (i_paymentModel == PaymentModel.OPTIMISM) { bytes memory txCallData = new bytes(0); if (isExecution) { txCallData = bytes.concat(msg.data, L1_FEE_DATA_PADDING); } else { // @dev fee is 4 per 0 byte, 16 per non-zero byte. Worst case we can have // s_storage.maxPerformDataSize non zero-bytes. Instead of setting bytes to non-zero // we initialize 'new bytes' of length 4*maxPerformDataSize to cover for zero bytes. txCallData = new bytes(4 * s_storage.maxPerformDataSize); } l1CostWei = OPTIMISM_ORACLE.getL1Fee(txCallData); } else if (i_paymentModel == PaymentModel.ARBITRUM) { l1CostWei = ARB_NITRO_ORACLE.getCurrentTxL1GasFees(); } // if it's not performing upkeeps, use gas ceiling multiplier to estimate the upper bound if (!isExecution) { l1CostWei = hotVars.gasCeilingMultiplier * l1CostWei; } // Divide l1CostWei among all batched upkeeps. Spare change from division is not charged l1CostWei = l1CostWei / numBatchedUpkeeps; uint256 gasPayment = ((gasWei * (gasLimit + gasOverhead) + l1CostWei) * 1e18) / linkNative; uint256 premium = (((gasWei * gasLimit) + l1CostWei) * 1e9 * hotVars.paymentPremiumPPB) / linkNative + uint256(hotVars.flatFeeMicroLink) * 1e12; // LINK_TOTAL_SUPPLY < UINT96_MAX if (gasPayment + premium > LINK_TOTAL_SUPPLY) revert PaymentGreaterThanAllLINK(); return (uint96(gasPayment), uint96(premium)); } /** * @dev generates the max link payment for an upkeep */ function _getMaxLinkPayment( HotVars memory hotVars, uint32 executeGas, uint32 performDataLength, uint256 fastGasWei, uint256 linkNative, bool isExecution // Whether this is an actual perform execution or just a simulation ) internal view returns (uint96) { uint256 gasOverhead = _getMaxGasOverhead(performDataLength, hotVars.f); (uint96 reimbursement, uint96 premium) = _calculatePaymentAmount( hotVars, executeGas, gasOverhead, fastGasWei, linkNative, 1, // Consider only 1 upkeep in batch to get maxPayment isExecution ); return reimbursement + premium; } /** * @dev returns the max gas overhead that can be charged for an upkeep */ function _getMaxGasOverhead(uint32 performDataLength, uint8 f) internal pure returns (uint256) { // performData causes additional overhead in report length and memory operations return REGISTRY_GAS_OVERHEAD + (REGISTRY_PER_SIGNER_GAS_OVERHEAD * (f + 1)) + (REGISTRY_PER_PERFORM_BYTE_GAS_OVERHEAD * performDataLength); } /** * @dev move a transmitter's balance from total pool to withdrawable balance */ function _updateTransmitterBalanceFromPool( address transmitterAddress, uint96 totalPremium, uint96 payeeCount ) internal returns (uint96) { Transmitter memory transmitter = s_transmitters[transmitterAddress]; uint96 uncollected = totalPremium - transmitter.lastCollected; uint96 due = uncollected / payeeCount; transmitter.balance += due; transmitter.lastCollected = totalPremium; // Transfer spare change to owner s_storage.ownerLinkBalance += (uncollected - due * payeeCount); s_transmitters[transmitterAddress] = transmitter; return transmitter.balance; } /** * @notice replicates Open Zeppelin's ReentrancyGuard but optimized to fit our storage */ modifier nonReentrant() { if (s_hotVars.reentrancyGuard) revert ReentrantCall(); s_hotVars.reentrancyGuard = true; _; s_hotVars.reentrancyGuard = false; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice OnchainConfig of the registry * @dev only used in params and return values * @member paymentPremiumPPB payment premium rate oracles receive on top of * being reimbursed for gas, measured in parts per billion * @member flatFeeMicroLink flat fee paid to oracles for performing upkeeps, * priced in MicroLink; can be used in conjunction with or independently of * paymentPremiumPPB * @member checkGasLimit gas limit when checking for upkeep * @member stalenessSeconds number of seconds that is allowed for feed data to * be stale before switching to the fallback pricing * @member gasCeilingMultiplier multiplier to apply to the fast gas feed price * when calculating the payment ceiling for keepers * @member minUpkeepSpend minimum LINK that an upkeep must spend before cancelling * @member maxPerformGas max executeGas allowed for an upkeep on this registry * @member fallbackGasPrice gas price used if the gas price feed is stale * @member fallbackLinkPrice LINK price used if the LINK price feed is stale * @member transcoder address of the transcoder contract * @member registrar address of the registrar contract */ struct OnchainConfig { uint32 paymentPremiumPPB; uint32 flatFeeMicroLink; // min 0.000001 LINK, max 4294 LINK uint32 checkGasLimit; uint24 stalenessSeconds; uint16 gasCeilingMultiplier; uint96 minUpkeepSpend; uint32 maxPerformGas; uint32 maxCheckDataSize; uint32 maxPerformDataSize; uint256 fallbackGasPrice; uint256 fallbackLinkPrice; address transcoder; address registrar; } /** * @notice state of the registry * @dev only used in params and return values * @member nonce used for ID generation * @member ownerLinkBalance withdrawable balance of LINK by contract owner * @member expectedLinkBalance the expected balance of LINK of the registry * @member totalPremium the total premium collected on registry so far * @member numUpkeeps total number of upkeeps on the registry * @member configCount ordinal number of current config, out of all configs applied to this contract so far * @member latestConfigBlockNumber last block at which this config was set * @member latestConfigDigest domain-separation tag for current config * @member latestEpoch for which a report was transmitted * @member paused freeze on execution scoped to the entire registry */ struct State { uint32 nonce; uint96 ownerLinkBalance; uint256 expectedLinkBalance; uint96 totalPremium; uint256 numUpkeeps; uint32 configCount; uint32 latestConfigBlockNumber; bytes32 latestConfigDigest; uint32 latestEpoch; bool paused; } /** * @notice all information about an upkeep * @dev only used in return values * @member target the contract which needs to be serviced * @member executeGas the gas limit of upkeep execution * @member checkData the checkData bytes for this upkeep * @member balance the balance of this upkeep * @member admin for this upkeep * @member maxValidBlocknumber until which block this upkeep is valid * @member lastPerformBlockNumber the last block number when this upkeep was performed * @member amountSpent the amount this upkeep has spent * @member paused if this upkeep has been paused * @member skipSigVerification skip signature verification in transmit for a low security low cost model */ struct UpkeepInfo { address target; uint32 executeGas; bytes checkData; uint96 balance; address admin; uint64 maxValidBlocknumber; uint32 lastPerformBlockNumber; uint96 amountSpent; bool paused; bytes offchainConfig; } enum UpkeepFailureReason { NONE, UPKEEP_CANCELLED, UPKEEP_PAUSED, TARGET_CHECK_REVERTED, UPKEEP_NOT_NEEDED, PERFORM_DATA_EXCEEDS_LIMIT, INSUFFICIENT_BALANCE } interface KeeperRegistryBaseInterface { function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData, bytes calldata offchainConfig ) external returns (uint256 id); function cancelUpkeep(uint256 id) external; function pauseUpkeep(uint256 id) external; function unpauseUpkeep(uint256 id) external; function transferUpkeepAdmin(uint256 id, address proposed) external; function acceptUpkeepAdmin(uint256 id) external; function updateCheckData(uint256 id, bytes calldata newCheckData) external; function addFunds(uint256 id, uint96 amount) external; function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external; function setUpkeepOffchainConfig(uint256 id, bytes calldata config) external; function getUpkeep(uint256 id) external view returns (UpkeepInfo memory upkeepInfo); function getActiveUpkeepIDs(uint256 startIndex, uint256 maxCount) external view returns (uint256[] memory); function getTransmitterInfo(address query) external view returns ( bool active, uint8 index, uint96 balance, uint96 lastCollected, address payee ); function getState() external view returns ( State memory state, OnchainConfig memory config, address[] memory signers, address[] memory transmitters, uint8 f ); } /** * @dev The view methods are not actually marked as view in the implementation * but we want them to be easily queried off-chain. Solidity will not compile * if we actually inherit from this interface, so we document it here. */ interface KeeperRegistryInterface is KeeperRegistryBaseInterface { function checkUpkeep(uint256 upkeepId) external view returns ( bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed, uint256 fastGasWei, uint256 linkNative ); } interface KeeperRegistryExecutableInterface is KeeperRegistryBaseInterface { function checkUpkeep(uint256 upkeepId) external returns ( bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed, uint256 fastGasWei, uint256 linkNative ); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol"; import "./KeeperRegistryBase2_0.sol"; import "../interfaces/MigratableKeeperRegistryInterface.sol"; import "../interfaces/UpkeepTranscoderInterface.sol"; /** * @notice Logic contract, works in tandem with KeeperRegistry as a proxy */ contract KeeperRegistryLogic2_0 is KeeperRegistryBase2_0 { using Address for address; using EnumerableSet for EnumerableSet.UintSet; /** * @param paymentModel one of Default, Arbitrum, Optimism * @param link address of the LINK Token * @param linkNativeFeed address of the LINK/Native price feed * @param fastGasFeed address of the Fast Gas price feed */ constructor( PaymentModel paymentModel, address link, address linkNativeFeed, address fastGasFeed ) KeeperRegistryBase2_0(paymentModel, link, linkNativeFeed, fastGasFeed) {} function checkUpkeep(uint256 id) external cannotExecute returns ( bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed, uint256 fastGasWei, uint256 linkNative ) { HotVars memory hotVars = s_hotVars; Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) return (false, bytes(""), UpkeepFailureReason.UPKEEP_CANCELLED, gasUsed, 0, 0); if (upkeep.paused) return (false, bytes(""), UpkeepFailureReason.UPKEEP_PAUSED, gasUsed, 0, 0); (fastGasWei, linkNative) = _getFeedData(hotVars); uint96 maxLinkPayment = _getMaxLinkPayment( hotVars, upkeep.executeGas, s_storage.maxPerformDataSize, fastGasWei, linkNative, false ); if (upkeep.balance < maxLinkPayment) return (false, bytes(""), UpkeepFailureReason.INSUFFICIENT_BALANCE, gasUsed, fastGasWei, linkNative); gasUsed = gasleft(); bytes memory callData = abi.encodeWithSelector(CHECK_SELECTOR, s_checkData[id]); (bool success, bytes memory result) = upkeep.target.call{gas: s_storage.checkGasLimit}(callData); gasUsed = gasUsed - gasleft(); if (!success) return (false, bytes(""), UpkeepFailureReason.TARGET_CHECK_REVERTED, gasUsed, fastGasWei, linkNative); bytes memory userPerformData; (upkeepNeeded, userPerformData) = abi.decode(result, (bool, bytes)); if (!upkeepNeeded) return (false, bytes(""), UpkeepFailureReason.UPKEEP_NOT_NEEDED, gasUsed, fastGasWei, linkNative); if (userPerformData.length > s_storage.maxPerformDataSize) return (false, bytes(""), UpkeepFailureReason.PERFORM_DATA_EXCEEDS_LIMIT, gasUsed, fastGasWei, linkNative); performData = abi.encode( PerformDataWrapper({ checkBlockNumber: uint32(block.number - 1), checkBlockhash: blockhash(block.number - 1), performData: userPerformData }) ); return (true, performData, UpkeepFailureReason.NONE, gasUsed, fastGasWei, linkNative); } /** * @dev Called through KeeperRegistry main contract */ function withdrawOwnerFunds() external onlyOwner { uint96 amount = s_storage.ownerLinkBalance; s_expectedLinkBalance = s_expectedLinkBalance - amount; s_storage.ownerLinkBalance = 0; emit OwnerFundsWithdrawn(amount); i_link.transfer(msg.sender, amount); } /** * @dev Called through KeeperRegistry main contract */ function recoverFunds() external onlyOwner { uint256 total = i_link.balanceOf(address(this)); i_link.transfer(msg.sender, total - s_expectedLinkBalance); } /** * @dev Called through KeeperRegistry main contract */ function setPayees(address[] calldata payees) external onlyOwner { if (s_transmittersList.length != payees.length) revert ParameterLengthError(); for (uint256 i = 0; i < s_transmittersList.length; i++) { address transmitter = s_transmittersList[i]; address oldPayee = s_transmitterPayees[transmitter]; address newPayee = payees[i]; if ( (newPayee == ZERO_ADDRESS) || (oldPayee != ZERO_ADDRESS && oldPayee != newPayee && newPayee != IGNORE_ADDRESS) ) revert InvalidPayee(); if (newPayee != IGNORE_ADDRESS) { s_transmitterPayees[transmitter] = newPayee; } } emit PayeesUpdated(s_transmittersList, payees); } /** * @dev Called through KeeperRegistry main contract */ function pause() external onlyOwner { s_hotVars.paused = true; emit Paused(msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function unpause() external onlyOwner { s_hotVars.paused = false; emit Unpaused(msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function setPeerRegistryMigrationPermission(address peer, MigrationPermission permission) external onlyOwner { s_peerRegistryMigrationPermission[peer] = permission; } /** * @dev Called through KeeperRegistry main contract */ function registerUpkeep( address target, uint32 gasLimit, address admin, bytes calldata checkData, bytes calldata offchainConfig ) external returns (uint256 id) { if (msg.sender != owner() && msg.sender != s_storage.registrar) revert OnlyCallableByOwnerOrRegistrar(); id = uint256(keccak256(abi.encode(blockhash(block.number - 1), address(this), s_storage.nonce))); _createUpkeep(id, target, gasLimit, admin, 0, checkData, false); s_storage.nonce++; s_upkeepOffchainConfig[id] = offchainConfig; emit UpkeepRegistered(id, gasLimit, admin); return id; } /** * @dev Called through KeeperRegistry main contract */ function cancelUpkeep(uint256 id) external { Upkeep memory upkeep = s_upkeep[id]; bool canceled = upkeep.maxValidBlocknumber != UINT32_MAX; bool isOwner = msg.sender == owner(); if (canceled && !(isOwner && upkeep.maxValidBlocknumber > block.number)) revert CannotCancel(); if (!isOwner && msg.sender != s_upkeepAdmin[id]) revert OnlyCallableByOwnerOrAdmin(); uint256 height = block.number; if (!isOwner) { height = height + CANCELLATION_DELAY; } s_upkeep[id].maxValidBlocknumber = uint32(height); s_upkeepIDs.remove(id); // charge the cancellation fee if the minUpkeepSpend is not met uint96 minUpkeepSpend = s_storage.minUpkeepSpend; uint96 cancellationFee = 0; // cancellationFee is supposed to be min(max(minUpkeepSpend - amountSpent,0), amountLeft) if (upkeep.amountSpent < minUpkeepSpend) { cancellationFee = minUpkeepSpend - upkeep.amountSpent; if (cancellationFee > upkeep.balance) { cancellationFee = upkeep.balance; } } s_upkeep[id].balance = upkeep.balance - cancellationFee; s_storage.ownerLinkBalance = s_storage.ownerLinkBalance + cancellationFee; emit UpkeepCanceled(id, uint64(height)); } /** * @dev Called through KeeperRegistry main contract */ function addFunds(uint256 id, uint96 amount) external { Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); s_upkeep[id].balance = upkeep.balance + amount; s_expectedLinkBalance = s_expectedLinkBalance + amount; i_link.transferFrom(msg.sender, address(this), amount); emit FundsAdded(id, msg.sender, amount); } /** * @dev Called through KeeperRegistry main contract */ function withdrawFunds(uint256 id, address to) external nonReentrant { if (to == ZERO_ADDRESS) revert InvalidRecipient(); Upkeep memory upkeep = s_upkeep[id]; if (s_upkeepAdmin[id] != msg.sender) revert OnlyCallableByAdmin(); if (upkeep.maxValidBlocknumber > block.number) revert UpkeepNotCanceled(); uint96 amountToWithdraw = s_upkeep[id].balance; s_expectedLinkBalance = s_expectedLinkBalance - amountToWithdraw; s_upkeep[id].balance = 0; i_link.transfer(to, amountToWithdraw); emit FundsWithdrawn(id, amountToWithdraw, to); } /** * @dev Called through KeeperRegistry main contract */ function setUpkeepGasLimit(uint256 id, uint32 gasLimit) external { if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); _requireAdminAndNotCancelled(id); s_upkeep[id].executeGas = gasLimit; emit UpkeepGasLimitSet(id, gasLimit); } /** * @dev Called through KeeperRegistry main contract */ function setUpkeepOffchainConfig(uint256 id, bytes calldata config) external { _requireAdminAndNotCancelled(id); s_upkeepOffchainConfig[id] = config; emit UpkeepOffchainConfigSet(id, config); } /** * @dev Called through KeeperRegistry main contract */ function withdrawPayment(address from, address to) external { if (to == ZERO_ADDRESS) revert InvalidRecipient(); if (s_transmitterPayees[from] != msg.sender) revert OnlyCallableByPayee(); uint96 balance = _updateTransmitterBalanceFromPool(from, s_hotVars.totalPremium, uint96(s_transmittersList.length)); s_transmitters[from].balance = 0; s_expectedLinkBalance = s_expectedLinkBalance - balance; i_link.transfer(to, balance); emit PaymentWithdrawn(from, balance, to, msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function transferPayeeship(address transmitter, address proposed) external { if (s_transmitterPayees[transmitter] != msg.sender) revert OnlyCallableByPayee(); if (proposed == msg.sender) revert ValueNotChanged(); if (s_proposedPayee[transmitter] != proposed) { s_proposedPayee[transmitter] = proposed; emit PayeeshipTransferRequested(transmitter, msg.sender, proposed); } } /** * @dev Called through KeeperRegistry main contract */ function acceptPayeeship(address transmitter) external { if (s_proposedPayee[transmitter] != msg.sender) revert OnlyCallableByProposedPayee(); address past = s_transmitterPayees[transmitter]; s_transmitterPayees[transmitter] = msg.sender; s_proposedPayee[transmitter] = ZERO_ADDRESS; emit PayeeshipTransferred(transmitter, past, msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function transferUpkeepAdmin(uint256 id, address proposed) external { _requireAdminAndNotCancelled(id); if (proposed == msg.sender) revert ValueNotChanged(); if (proposed == ZERO_ADDRESS) revert InvalidRecipient(); if (s_proposedAdmin[id] != proposed) { s_proposedAdmin[id] = proposed; emit UpkeepAdminTransferRequested(id, msg.sender, proposed); } } /** * @dev Called through KeeperRegistry main contract */ function acceptUpkeepAdmin(uint256 id) external { Upkeep memory upkeep = s_upkeep[id]; if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); if (s_proposedAdmin[id] != msg.sender) revert OnlyCallableByProposedAdmin(); address past = s_upkeepAdmin[id]; s_upkeepAdmin[id] = msg.sender; s_proposedAdmin[id] = ZERO_ADDRESS; emit UpkeepAdminTransferred(id, past, msg.sender); } /** * @dev Called through KeeperRegistry main contract */ function pauseUpkeep(uint256 id) external { _requireAdminAndNotCancelled(id); Upkeep memory upkeep = s_upkeep[id]; if (upkeep.paused) revert OnlyUnpausedUpkeep(); s_upkeep[id].paused = true; s_upkeepIDs.remove(id); emit UpkeepPaused(id); } /** * @dev Called through KeeperRegistry main contract */ function unpauseUpkeep(uint256 id) external { _requireAdminAndNotCancelled(id); Upkeep memory upkeep = s_upkeep[id]; if (!upkeep.paused) revert OnlyPausedUpkeep(); s_upkeep[id].paused = false; s_upkeepIDs.add(id); emit UpkeepUnpaused(id); } /** * @dev Called through KeeperRegistry main contract */ function updateCheckData(uint256 id, bytes calldata newCheckData) external { _requireAdminAndNotCancelled(id); if (newCheckData.length > s_storage.maxCheckDataSize) revert CheckDataExceedsLimit(); s_checkData[id] = newCheckData; emit UpkeepCheckDataUpdated(id, newCheckData); } /** * @dev Called through KeeperRegistry main contract */ function migrateUpkeeps(uint256[] calldata ids, address destination) external { if ( s_peerRegistryMigrationPermission[destination] != MigrationPermission.OUTGOING && s_peerRegistryMigrationPermission[destination] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); if (s_storage.transcoder == ZERO_ADDRESS) revert TranscoderNotSet(); if (ids.length == 0) revert ArrayHasNoEntries(); uint256 id; Upkeep memory upkeep; uint256 totalBalanceRemaining; bytes[] memory checkDatas = new bytes[](ids.length); address[] memory admins = new address[](ids.length); Upkeep[] memory upkeeps = new Upkeep[](ids.length); for (uint256 idx = 0; idx < ids.length; idx++) { id = ids[idx]; upkeep = s_upkeep[id]; _requireAdminAndNotCancelled(id); upkeeps[idx] = upkeep; checkDatas[idx] = s_checkData[id]; admins[idx] = s_upkeepAdmin[id]; totalBalanceRemaining = totalBalanceRemaining + upkeep.balance; delete s_upkeep[id]; delete s_checkData[id]; // nullify existing proposed admin change if an upkeep is being migrated delete s_proposedAdmin[id]; s_upkeepIDs.remove(id); emit UpkeepMigrated(id, upkeep.balance, destination); } s_expectedLinkBalance = s_expectedLinkBalance - totalBalanceRemaining; bytes memory encodedUpkeeps = abi.encode(ids, upkeeps, checkDatas, admins); MigratableKeeperRegistryInterface(destination).receiveUpkeeps( UpkeepTranscoderInterface(s_storage.transcoder).transcodeUpkeeps( UPKEEP_TRANSCODER_VERSION_BASE, MigratableKeeperRegistryInterface(destination).upkeepTranscoderVersion(), encodedUpkeeps ) ); i_link.transfer(destination, totalBalanceRemaining); } /** * @dev Called through KeeperRegistry main contract */ function receiveUpkeeps(bytes calldata encodedUpkeeps) external { if ( s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.INCOMING && s_peerRegistryMigrationPermission[msg.sender] != MigrationPermission.BIDIRECTIONAL ) revert MigrationNotPermitted(); (uint256[] memory ids, Upkeep[] memory upkeeps, bytes[] memory checkDatas, address[] memory upkeepAdmins) = abi .decode(encodedUpkeeps, (uint256[], Upkeep[], bytes[], address[])); for (uint256 idx = 0; idx < ids.length; idx++) { _createUpkeep( ids[idx], upkeeps[idx].target, upkeeps[idx].executeGas, upkeepAdmins[idx], upkeeps[idx].balance, checkDatas[idx], upkeeps[idx].paused ); emit UpkeepReceived(ids[idx], upkeeps[idx].balance, msg.sender); } } /** * @notice creates a new upkeep with the given fields * @param target address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when * performing upkeep * @param admin address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep * @param paused if this upkeep is paused */ function _createUpkeep( uint256 id, address target, uint32 gasLimit, address admin, uint96 balance, bytes memory checkData, bool paused ) internal { if (s_hotVars.paused) revert RegistryPaused(); if (!target.isContract()) revert NotAContract(); if (checkData.length > s_storage.maxCheckDataSize) revert CheckDataExceedsLimit(); if (gasLimit < PERFORM_GAS_MIN || gasLimit > s_storage.maxPerformGas) revert GasLimitOutsideRange(); if (s_upkeep[id].target != address(0)) revert UpkeepAlreadyExists(); s_upkeep[id] = Upkeep({ target: target, executeGas: gasLimit, balance: balance, maxValidBlocknumber: UINT32_MAX, lastPerformBlockNumber: 0, amountSpent: 0, paused: paused }); s_upkeepAdmin[id] = admin; s_expectedLinkBalance = s_expectedLinkBalance + balance; s_checkData[id] = checkData; s_upkeepIDs.add(id); } /** * @dev ensures the upkeep is not cancelled and the caller is the upkeep admin */ function _requireAdminAndNotCancelled(uint256 upkeepId) internal view { if (msg.sender != s_upkeepAdmin[upkeepId]) revert OnlyCallableByAdmin(); if (s_upkeep[upkeepId].maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overridden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overridden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./interfaces/TypeAndVersionInterface.sol"; abstract contract OCR2Abstract is TypeAndVersionInterface { // Maximum number of oracles the offchain reporting protocol is designed for uint256 internal constant maxNumOracles = 31; uint256 private constant prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00 uint256 private constant prefix = 0x0001 << (256 - 16); // 0x000100..00 /** * @notice triggers a new run of the offchain reporting protocol * @param previousConfigBlockNumber block in which the previous config was set, to simplify historic analysis * @param configDigest configDigest of this configuration * @param configCount ordinal number of this config setting among all config settings over the life of this contract * @param signers ith element is address ith oracle uses to sign a report * @param transmitters ith element is address ith oracle uses to transmit a report via the transmit method * @param f maximum number of faulty/dishonest oracles the protocol can tolerate while still working correctly * @param onchainConfig serialized configuration used by the contract (and possibly oracles) * @param offchainConfigVersion version of the serialization format used for "offchainConfig" parameter * @param offchainConfig serialized configuration used by the oracles exclusively and only passed through the contract */ event ConfigSet( uint32 previousConfigBlockNumber, bytes32 configDigest, uint64 configCount, address[] signers, address[] transmitters, uint8 f, bytes onchainConfig, uint64 offchainConfigVersion, bytes offchainConfig ); /** * @notice sets offchain reporting protocol configuration incl. participating oracles * @param signers addresses with which oracles sign the reports * @param transmitters addresses oracles use to transmit the reports * @param f number of faulty oracles the system can tolerate * @param onchainConfig serialized configuration used by the contract (and possibly oracles) * @param offchainConfigVersion version number for offchainEncoding schema * @param offchainConfig serialized configuration used by the oracles exclusively and only passed through the contract */ function setConfig( address[] memory signers, address[] memory transmitters, uint8 f, bytes memory onchainConfig, uint64 offchainConfigVersion, bytes memory offchainConfig ) external virtual; /** * @notice information about current offchain reporting protocol configuration * @return configCount ordinal number of current config, out of all configs applied to this contract so far * @return blockNumber block at which this config was set * @return configDigest domain-separation tag for current config (see _configDigestFromConfigData) */ function latestConfigDetails() external view virtual returns ( uint32 configCount, uint32 blockNumber, bytes32 configDigest ); function _configDigestFromConfigData( uint256 chainId, address contractAddress, uint64 configCount, address[] memory signers, address[] memory transmitters, uint8 f, bytes memory onchainConfig, uint64 offchainConfigVersion, bytes memory offchainConfig ) internal pure returns (bytes32) { uint256 h = uint256( keccak256( abi.encode( chainId, contractAddress, configCount, signers, transmitters, f, onchainConfig, offchainConfigVersion, offchainConfig ) ) ); return bytes32((prefix & prefixMask) | (h & ~prefixMask)); } /** * @notice optionally emited to indicate the latest configDigest and epoch for which a report was successfully transmited. Alternatively, the contract may use latestConfigDigestAndEpoch with scanLogs set to false. */ event Transmitted(bytes32 configDigest, uint32 epoch); /** * @notice optionally returns the latest configDigest and epoch for which a report was successfully transmitted. Alternatively, the contract may return scanLogs set to true and use Transmitted events to provide this information to offchain watchers. * @return scanLogs indicates whether to rely on the configDigest and epoch returned or whether to scan logs for the Transmitted event instead. * @return configDigest * @return epoch */ function latestConfigDigestAndEpoch() external view virtual returns ( bool scanLogs, bytes32 configDigest, uint32 epoch ); /** * @notice transmit is called to post a new report to the contract * @param reportContext [0]: ConfigDigest, [1]: 27 byte padding, 4-byte epoch and 1-byte round, [2]: ExtraHash * @param report serialized report, which the signatures are signing. * @param rs ith element is the R components of the ith signature on report. Must have at most maxNumOracles entries * @param ss ith element is the S components of the ith signature on report. Must have at most maxNumOracles entries * @param rawVs ith element is the the V component of the ith signature */ function transmit( // NOTE: If these parameters are changed, expectedMsgDataLength and/or // TRANSMIT_MSGDATA_CONSTANT_LENGTH_COMPONENT need to be changed accordingly bytes32[3] calldata reportContext, bytes calldata report, bytes32[] calldata rs, bytes32[] calldata ss, bytes32 rawVs // signatures ) external virtual; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../interfaces/LinkTokenInterface.sol"; import "../interfaces/KeeperRegistryInterface2_0.sol"; import "../interfaces/TypeAndVersionInterface.sol"; import "../ConfirmedOwner.sol"; import "../interfaces/ERC677ReceiverInterface.sol"; /** * @notice Contract to accept requests for upkeep registrations * @dev There are 2 registration workflows in this contract * Flow 1. auto approve OFF / manual registration - UI calls `register` function on this contract, this contract owner at a later time then manually * calls `approve` to register upkeep and emit events to inform UI and others interested. * Flow 2. auto approve ON / real time registration - UI calls `register` function as before, which calls the `registerUpkeep` function directly on * keeper registry and then emits approved event to finish the flow automatically without manual intervention. * The idea is to have same interface(functions,events) for UI or anyone using this contract irrespective of auto approve being enabled or not. * they can just listen to `RegistrationRequested` & `RegistrationApproved` events and know the status on registrations. */ contract KeeperRegistrar2_0 is TypeAndVersionInterface, ConfirmedOwner, ERC677ReceiverInterface { /** * DISABLED: No auto approvals, all new upkeeps should be approved manually. * ENABLED_SENDER_ALLOWLIST: Auto approvals for allowed senders subject to max allowed. Manual for rest. * ENABLED_ALL: Auto approvals for all new upkeeps subject to max allowed. */ enum AutoApproveType { DISABLED, ENABLED_SENDER_ALLOWLIST, ENABLED_ALL } bytes4 private constant REGISTER_REQUEST_SELECTOR = this.register.selector; mapping(bytes32 => PendingRequest) private s_pendingRequests; LinkTokenInterface public immutable LINK; /** * @notice versions: * - KeeperRegistrar 2.0.0: Remove source from register * Breaks our example of "Register an Upkeep using your own deployed contract" * - KeeperRegistrar 1.1.0: Add functionality for sender allowlist in auto approve * : Remove rate limit and add max allowed for auto approve * - KeeperRegistrar 1.0.0: initial release */ string public constant override typeAndVersion = "KeeperRegistrar 2.0.0"; struct RegistrarConfig { AutoApproveType autoApproveConfigType; uint32 autoApproveMaxAllowed; uint32 approvedCount; KeeperRegistryBaseInterface keeperRegistry; uint96 minLINKJuels; } struct PendingRequest { address admin; uint96 balance; } struct RegistrationParams { string name; bytes encryptedEmail; address upkeepContract; uint32 gasLimit; address adminAddress; bytes checkData; bytes offchainConfig; uint96 amount; } RegistrarConfig private s_config; // Only applicable if s_config.configType is ENABLED_SENDER_ALLOWLIST mapping(address => bool) private s_autoApproveAllowedSenders; event RegistrationRequested( bytes32 indexed hash, string name, bytes encryptedEmail, address indexed upkeepContract, uint32 gasLimit, address adminAddress, bytes checkData, uint96 amount ); event RegistrationApproved(bytes32 indexed hash, string displayName, uint256 indexed upkeepId); event RegistrationRejected(bytes32 indexed hash); event AutoApproveAllowedSenderSet(address indexed senderAddress, bool allowed); event ConfigChanged( AutoApproveType autoApproveConfigType, uint32 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ); error InvalidAdminAddress(); error RequestNotFound(); error HashMismatch(); error OnlyAdminOrOwner(); error InsufficientPayment(); error RegistrationRequestFailed(); error OnlyLink(); error AmountMismatch(); error SenderMismatch(); error FunctionNotPermitted(); error LinkTransferFailed(address to); error InvalidDataLength(); /* * @param LINKAddress Address of Link token * @param autoApproveConfigType setting for auto-approve registrations * @param autoApproveMaxAllowed max number of registrations that can be auto approved * @param keeperRegistry keeper registry address * @param minLINKJuels minimum LINK that new registrations should fund their upkeep with */ constructor( address LINKAddress, AutoApproveType autoApproveConfigType, uint16 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ) ConfirmedOwner(msg.sender) { LINK = LinkTokenInterface(LINKAddress); setRegistrationConfig(autoApproveConfigType, autoApproveMaxAllowed, keeperRegistry, minLINKJuels); } //EXTERNAL /** * @notice register can only be called through transferAndCall on LINK contract * @param name string of the upkeep to be registered * @param encryptedEmail email address of upkeep contact * @param upkeepContract address to perform upkeep on * @param gasLimit amount of gas to provide the target contract when performing upkeep * @param adminAddress address to cancel upkeep and withdraw remaining funds * @param checkData data passed to the contract when checking for upkeep * @param amount quantity of LINK upkeep is funded with (specified in Juels) * @param offchainConfig offchainConfig for upkeep in bytes * @param sender address of the sender making the request */ function register( string memory name, bytes calldata encryptedEmail, address upkeepContract, uint32 gasLimit, address adminAddress, bytes calldata checkData, bytes calldata offchainConfig, uint96 amount, address sender ) external onlyLINK { _register( RegistrationParams({ name: name, encryptedEmail: encryptedEmail, upkeepContract: upkeepContract, gasLimit: gasLimit, adminAddress: adminAddress, checkData: checkData, offchainConfig: offchainConfig, amount: amount }), sender ); } /** * @notice Allows external users to register upkeeps; assumes amount is approved for transfer by the contract * @param requestParams struct of all possible registration parameters */ function registerUpkeep(RegistrationParams calldata requestParams) external returns (uint256) { if (requestParams.amount < s_config.minLINKJuels) { revert InsufficientPayment(); } LINK.transferFrom(msg.sender, address(this), requestParams.amount); return _register(requestParams, msg.sender); } /** * @dev register upkeep on KeeperRegistry contract and emit RegistrationApproved event */ function approve( string memory name, address upkeepContract, uint32 gasLimit, address adminAddress, bytes calldata checkData, bytes calldata offchainConfig, bytes32 hash ) external onlyOwner { PendingRequest memory request = s_pendingRequests[hash]; if (request.admin == address(0)) { revert RequestNotFound(); } bytes32 expectedHash = keccak256(abi.encode(upkeepContract, gasLimit, adminAddress, checkData, offchainConfig)); if (hash != expectedHash) { revert HashMismatch(); } delete s_pendingRequests[hash]; _approve( RegistrationParams({ name: name, encryptedEmail: "", upkeepContract: upkeepContract, gasLimit: gasLimit, adminAddress: adminAddress, checkData: checkData, offchainConfig: offchainConfig, amount: request.balance }), expectedHash ); } /** * @notice cancel will remove a registration request and return the refunds to the request.admin * @param hash the request hash */ function cancel(bytes32 hash) external { PendingRequest memory request = s_pendingRequests[hash]; if (!(msg.sender == request.admin || msg.sender == owner())) { revert OnlyAdminOrOwner(); } if (request.admin == address(0)) { revert RequestNotFound(); } delete s_pendingRequests[hash]; bool success = LINK.transfer(request.admin, request.balance); if (!success) { revert LinkTransferFailed(request.admin); } emit RegistrationRejected(hash); } /** * @notice owner calls this function to set if registration requests should be sent directly to the Keeper Registry * @param autoApproveConfigType setting for auto-approve registrations * note: autoApproveAllowedSenders list persists across config changes irrespective of type * @param autoApproveMaxAllowed max number of registrations that can be auto approved * @param keeperRegistry new keeper registry address * @param minLINKJuels minimum LINK that new registrations should fund their upkeep with */ function setRegistrationConfig( AutoApproveType autoApproveConfigType, uint16 autoApproveMaxAllowed, address keeperRegistry, uint96 minLINKJuels ) public onlyOwner { uint32 approvedCount = s_config.approvedCount; s_config = RegistrarConfig({ autoApproveConfigType: autoApproveConfigType, autoApproveMaxAllowed: autoApproveMaxAllowed, approvedCount: approvedCount, minLINKJuels: minLINKJuels, keeperRegistry: KeeperRegistryBaseInterface(keeperRegistry) }); emit ConfigChanged(autoApproveConfigType, autoApproveMaxAllowed, keeperRegistry, minLINKJuels); } /** * @notice owner calls this function to set allowlist status for senderAddress * @param senderAddress senderAddress to set the allowlist status for * @param allowed true if senderAddress needs to be added to allowlist, false if needs to be removed */ function setAutoApproveAllowedSender(address senderAddress, bool allowed) external onlyOwner { s_autoApproveAllowedSenders[senderAddress] = allowed; emit AutoApproveAllowedSenderSet(senderAddress, allowed); } /** * @notice read the allowlist status of senderAddress * @param senderAddress address to read the allowlist status for */ function getAutoApproveAllowedSender(address senderAddress) external view returns (bool) { return s_autoApproveAllowedSenders[senderAddress]; } /** * @notice read the current registration configuration */ function getRegistrationConfig() external view returns ( AutoApproveType autoApproveConfigType, uint32 autoApproveMaxAllowed, uint32 approvedCount, address keeperRegistry, uint256 minLINKJuels ) { RegistrarConfig memory config = s_config; return ( config.autoApproveConfigType, config.autoApproveMaxAllowed, config.approvedCount, address(config.keeperRegistry), config.minLINKJuels ); } /** * @notice gets the admin address and the current balance of a registration request */ function getPendingRequest(bytes32 hash) external view returns (address, uint96) { PendingRequest memory request = s_pendingRequests[hash]; return (request.admin, request.balance); } /** * @notice Called when LINK is sent to the contract via `transferAndCall` * @param sender Address of the sender transfering LINK * @param amount Amount of LINK sent (specified in Juels) * @param data Payload of the transaction */ function onTokenTransfer( address sender, uint256 amount, bytes calldata data ) external override onlyLINK permittedFunctionsForLINK(data) isActualAmount(amount, data) isActualSender(sender, data) { if (data.length < 292) revert InvalidDataLength(); if (amount < s_config.minLINKJuels) { revert InsufficientPayment(); } (bool success, ) = address(this).delegatecall(data); // calls register if (!success) { revert RegistrationRequestFailed(); } } //PRIVATE /** * @dev verify registration request and emit RegistrationRequested event */ function _register(RegistrationParams memory params, address sender) private returns (uint256) { if (params.adminAddress == address(0)) { revert InvalidAdminAddress(); } bytes32 hash = keccak256( abi.encode(params.upkeepContract, params.gasLimit, params.adminAddress, params.checkData, params.offchainConfig) ); emit RegistrationRequested( hash, params.name, params.encryptedEmail, params.upkeepContract, params.gasLimit, params.adminAddress, params.checkData, params.amount ); uint256 upkeepId; RegistrarConfig memory config = s_config; if (_shouldAutoApprove(config, sender)) { s_config.approvedCount = config.approvedCount + 1; upkeepId = _approve(params, hash); } else { uint96 newBalance = s_pendingRequests[hash].balance + params.amount; s_pendingRequests[hash] = PendingRequest({admin: params.adminAddress, balance: newBalance}); } return upkeepId; } /** * @dev register upkeep on KeeperRegistry contract and emit RegistrationApproved event */ function _approve(RegistrationParams memory params, bytes32 hash) private returns (uint256) { KeeperRegistryBaseInterface keeperRegistry = s_config.keeperRegistry; // register upkeep uint256 upkeepId = keeperRegistry.registerUpkeep( params.upkeepContract, params.gasLimit, params.adminAddress, params.checkData, params.offchainConfig ); // fund upkeep bool success = LINK.transferAndCall(address(keeperRegistry), params.amount, abi.encode(upkeepId)); if (!success) { revert LinkTransferFailed(address(keeperRegistry)); } emit RegistrationApproved(hash, params.name, upkeepId); return upkeepId; } /** * @dev verify sender allowlist if needed and check max limit */ function _shouldAutoApprove(RegistrarConfig memory config, address sender) private view returns (bool) { if (config.autoApproveConfigType == AutoApproveType.DISABLED) { return false; } if ( config.autoApproveConfigType == AutoApproveType.ENABLED_SENDER_ALLOWLIST && (!s_autoApproveAllowedSenders[sender]) ) { return false; } if (config.approvedCount < config.autoApproveMaxAllowed) { return true; } return false; } //MODIFIERS /** * @dev Reverts if not sent from the LINK token */ modifier onlyLINK() { if (msg.sender != address(LINK)) { revert OnlyLink(); } _; } /** * @dev Reverts if the given data does not begin with the `register` function selector * @param _data The data payload of the request */ modifier permittedFunctionsForLINK(bytes memory _data) { bytes4 funcSelector; assembly { // solhint-disable-next-line avoid-low-level-calls funcSelector := mload(add(_data, 32)) // First 32 bytes contain length of data } if (funcSelector != REGISTER_REQUEST_SELECTOR) { revert FunctionNotPermitted(); } _; } /** * @dev Reverts if the actual amount passed does not match the expected amount * @param expected amount that should match the actual amount * @param data bytes */ modifier isActualAmount(uint256 expected, bytes calldata data) { // decode register function arguments to get actual amount (, , , , , , , uint96 amount, ) = abi.decode( data[4:], (string, bytes, address, uint32, address, bytes, bytes, uint96, address) ); if (expected != amount) { revert AmountMismatch(); } _; } /** * @dev Reverts if the actual sender address does not match the expected sender address * @param expected address that should match the actual sender address * @param data bytes */ modifier isActualSender(address expected, bytes calldata data) { // decode register function arguments to get actual sender (, , , , , , , , address sender) = abi.decode( data[4:], (string, bytes, address, uint32, address, bytes, bytes, uint96, address) ); if (expected != sender) { revert SenderMismatch(); } _; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; /* External Imports */ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title OVM_GasPriceOracle * @dev This contract exposes the current l2 gas price, a measure of how congested the network * currently is. This measure is used by the Sequencer to determine what fee to charge for * transactions. When the system is more congested, the l2 gas price will increase and fees * will also increase as a result. * * All public variables are set while generating the initial L2 state. The * constructor doesn't run in practice as the L2 state generation script uses * the deployed bytecode instead of running the initcode. */ contract OVM_GasPriceOracle is Ownable { /************* * Variables * *************/ // Current L2 gas price uint256 public gasPrice; // Current L1 base fee uint256 public l1BaseFee; // Amortized cost of batch submission per transaction uint256 public overhead; // Value to scale the fee up by uint256 public scalar; // Number of decimals of the scalar uint256 public decimals; /*************** * Constructor * ***************/ /** * @param _owner Address that will initially own this contract. */ constructor(address _owner) Ownable() { transferOwnership(_owner); } /********** * Events * **********/ event GasPriceUpdated(uint256); event L1BaseFeeUpdated(uint256); event OverheadUpdated(uint256); event ScalarUpdated(uint256); event DecimalsUpdated(uint256); /******************** * Public Functions * ********************/ /** * Allows the owner to modify the l2 gas price. * @param _gasPrice New l2 gas price. */ // slither-disable-next-line external-function function setGasPrice(uint256 _gasPrice) public onlyOwner { gasPrice = _gasPrice; emit GasPriceUpdated(_gasPrice); } /** * Allows the owner to modify the l1 base fee. * @param _baseFee New l1 base fee */ // slither-disable-next-line external-function function setL1BaseFee(uint256 _baseFee) public onlyOwner { l1BaseFee = _baseFee; emit L1BaseFeeUpdated(_baseFee); } /** * Allows the owner to modify the overhead. * @param _overhead New overhead */ // slither-disable-next-line external-function function setOverhead(uint256 _overhead) public onlyOwner { overhead = _overhead; emit OverheadUpdated(_overhead); } /** * Allows the owner to modify the scalar. * @param _scalar New scalar */ // slither-disable-next-line external-function function setScalar(uint256 _scalar) public onlyOwner { scalar = _scalar; emit ScalarUpdated(_scalar); } /** * Allows the owner to modify the decimals. * @param _decimals New decimals */ // slither-disable-next-line external-function function setDecimals(uint256 _decimals) public onlyOwner { decimals = _decimals; emit DecimalsUpdated(_decimals); } /** * Computes the L1 portion of the fee * based on the size of the RLP encoded tx * and the current l1BaseFee * @param _data Unsigned RLP encoded tx, 6 elements * @return L1 fee that should be paid for the tx */ // slither-disable-next-line external-function function getL1Fee(bytes memory _data) public view returns (uint256) { uint256 l1GasUsed = getL1GasUsed(_data); uint256 l1Fee = l1GasUsed * l1BaseFee; uint256 divisor = 10**decimals; uint256 unscaled = l1Fee * scalar; uint256 scaled = unscaled / divisor; return scaled; } // solhint-disable max-line-length /** * Computes the amount of L1 gas used for a transaction * The overhead represents the per batch gas overhead of * posting both transaction and state roots to L1 given larger * batch sizes. * 4 gas for 0 byte * https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L33 * 16 gas for non zero byte * https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L87 * This will need to be updated if calldata gas prices change * Account for the transaction being unsigned * Padding is added to account for lack of signature on transaction * 1 byte for RLP V prefix * 1 byte for V * 1 byte for RLP R prefix * 32 bytes for R * 1 byte for RLP S prefix * 32 bytes for S * Total: 68 bytes of padding * @param _data Unsigned RLP encoded tx, 6 elements * @return Amount of L1 gas used for a transaction */ // solhint-enable max-line-length function getL1GasUsed(bytes memory _data) public view returns (uint256) { uint256 total = 0; for (uint256 i = 0; i < _data.length; i++) { if (_data[i] == 0) { total += 4; } else { total += 16; } } uint256 unsigned = total + overhead; return unsigned + (68 * 16); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../upkeeps/EthBalanceMonitor.sol"; contract EthBalanceMonitorExposed is EthBalanceMonitor { constructor(address keeperRegistryAddress, uint256 minWaitPeriod) EthBalanceMonitor(keeperRegistryAddress, minWaitPeriod) {} function setLastTopUpXXXTestOnly(address target, uint56 lastTopUpTimestamp) external { s_targets[target].lastTopUpTimestamp = lastTopUpTimestamp; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../interfaces/AutomationCompatibleInterface.sol"; contract PerformDataChecker is AutomationCompatibleInterface { uint256 public counter; bytes public s_expectedData; constructor(bytes memory expectedData) { s_expectedData = expectedData; } function setExpectedData(bytes calldata expectedData) external { s_expectedData = expectedData; } function checkUpkeep(bytes calldata checkData) external view override returns (bool upkeepNeeded, bytes memory performData) { return (keccak256(checkData) == keccak256(s_expectedData), checkData); } function performUpkeep(bytes calldata performData) external override { if (keccak256(performData) == keccak256(s_expectedData)) { counter++; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.6; import "../interfaces/AutomationCompatibleInterface.sol"; contract CounterWithPerformData is AutomationCompatibleInterface { /** * Public counter variable */ uint256 public counter; bytes internal constant DATA_PADDING = "0xfffffffffffffffffffffffffffffffffffffffffff"; /** * Use an interval in seconds and a timestamp to slow execution of Upkeep */ uint256 public immutable interval; uint256 public lastTimeStamp; event Logger(string message, uint256 timestamp, uint256 blocknbr, bytes abc); constructor(uint256 updateInterval) { interval = updateInterval; lastTimeStamp = block.timestamp; counter = 0; } function checkUpkeep(bytes calldata checkData) external view override returns (bool upkeepNeeded, bytes memory performData) { upkeepNeeded = (block.timestamp - lastTimeStamp) > interval; bytes memory performData = bytes.concat(DATA_PADDING, checkData); return (upkeepNeeded, performData); } function performUpkeep(bytes calldata performData) external override { //We highly recommend revalidating the upkeep in the performUpkeep function if ((block.timestamp - lastTimeStamp) > interval) { lastTimeStamp = block.timestamp; counter = counter + 1; emit Logger("add 1", block.timestamp, block.number, performData); } } }
{ "optimizer": { "enabled": true, "runs": 1000000 }, "metadata": { "bytecodeHash": "none" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
[{"inputs":[{"internalType":"contract KeeperRegistryBase2_0","name":"keeperRegistryLogic","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ArrayHasNoEntries","type":"error"},{"inputs":[],"name":"CannotCancel","type":"error"},{"inputs":[],"name":"CheckDataExceedsLimit","type":"error"},{"inputs":[],"name":"ConfigDigestMismatch","type":"error"},{"inputs":[],"name":"DuplicateEntry","type":"error"},{"inputs":[],"name":"DuplicateSigners","type":"error"},{"inputs":[],"name":"GasLimitCanOnlyIncrease","type":"error"},{"inputs":[],"name":"GasLimitOutsideRange","type":"error"},{"inputs":[],"name":"IncorrectNumberOfFaultyOracles","type":"error"},{"inputs":[],"name":"IncorrectNumberOfSignatures","type":"error"},{"inputs":[],"name":"IncorrectNumberOfSigners","type":"error"},{"inputs":[],"name":"IndexOutOfRange","type":"error"},{"inputs":[],"name":"InsufficientFunds","type":"error"},{"inputs":[],"name":"InvalidDataLength","type":"error"},{"inputs":[],"name":"InvalidPayee","type":"error"},{"inputs":[],"name":"InvalidRecipient","type":"error"},{"inputs":[],"name":"InvalidReport","type":"error"},{"inputs":[],"name":"MaxCheckDataSizeCanOnlyIncrease","type":"error"},{"inputs":[],"name":"MaxPerformDataSizeCanOnlyIncrease","type":"error"},{"inputs":[],"name":"MigrationNotPermitted","type":"error"},{"inputs":[],"name":"NotAContract","type":"error"},{"inputs":[],"name":"OnchainConfigNonEmpty","type":"error"},{"inputs":[],"name":"OnlyActiveSigners","type":"error"},{"inputs":[],"name":"OnlyActiveTransmitters","type":"error"},{"inputs":[],"name":"OnlyCallableByAdmin","type":"error"},{"inputs":[],"name":"OnlyCallableByLINKToken","type":"error"},{"inputs":[],"name":"OnlyCallableByOwnerOrAdmin","type":"error"},{"inputs":[],"name":"OnlyCallableByOwnerOrRegistrar","type":"error"},{"inputs":[],"name":"OnlyCallableByPayee","type":"error"},{"inputs":[],"name":"OnlyCallableByProposedAdmin","type":"error"},{"inputs":[],"name":"OnlyCallableByProposedPayee","type":"error"},{"inputs":[],"name":"OnlyPausedUpkeep","type":"error"},{"inputs":[],"name":"OnlySimulatedBackend","type":"error"},{"inputs":[],"name":"OnlyUnpausedUpkeep","type":"error"},{"inputs":[],"name":"ParameterLengthError","type":"error"},{"inputs":[],"name":"PaymentGreaterThanAllLINK","type":"error"},{"inputs":[],"name":"ReentrantCall","type":"error"},{"inputs":[],"name":"RegistryPaused","type":"error"},{"inputs":[],"name":"RepeatedSigner","type":"error"},{"inputs":[],"name":"RepeatedTransmitter","type":"error"},{"inputs":[],"name":"StaleReport","type":"error"},{"inputs":[{"internalType":"bytes","name":"reason","type":"bytes"}],"name":"TargetCheckReverted","type":"error"},{"inputs":[],"name":"TooManyOracles","type":"error"},{"inputs":[],"name":"TranscoderNotSet","type":"error"},{"inputs":[],"name":"UpkeepAlreadyExists","type":"error"},{"inputs":[],"name":"UpkeepCancelled","type":"error"},{"inputs":[],"name":"UpkeepNotCanceled","type":"error"},{"inputs":[],"name":"UpkeepNotNeeded","type":"error"},{"inputs":[],"name":"ValueNotChanged","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"CancelledUpkeepReport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"previousConfigBlockNumber","type":"uint32"},{"indexed":false,"internalType":"bytes32","name":"configDigest","type":"bytes32"},{"indexed":false,"internalType":"uint64","name":"configCount","type":"uint64"},{"indexed":false,"internalType":"address[]","name":"signers","type":"address[]"},{"indexed":false,"internalType":"address[]","name":"transmitters","type":"address[]"},{"indexed":false,"internalType":"uint8","name":"f","type":"uint8"},{"indexed":false,"internalType":"bytes","name":"onchainConfig","type":"bytes"},{"indexed":false,"internalType":"uint64","name":"offchainConfigVersion","type":"uint64"},{"indexed":false,"internalType":"bytes","name":"offchainConfig","type":"bytes"}],"name":"ConfigSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"}],"name":"FundsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"FundsWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"InsufficientFundsUpkeepReport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"}],"name":"OwnerFundsWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"OwnershipTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"transmitters","type":"address[]"},{"indexed":false,"internalType":"address[]","name":"payees","type":"address[]"}],"name":"PayeesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"transmitter","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"PayeeshipTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"transmitter","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"PayeeshipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"transmitter","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"payee","type":"address"}],"name":"PaymentWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"ReorgedUpkeepReport","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"StaleUpkeepReport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"configDigest","type":"bytes32"},{"indexed":false,"internalType":"uint32","name":"epoch","type":"uint32"}],"name":"Transmitted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"UpkeepAdminTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"UpkeepAdminTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"uint64","name":"atBlockHeight","type":"uint64"}],"name":"UpkeepCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"newCheckData","type":"bytes"}],"name":"UpkeepCheckDataUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint96","name":"gasLimit","type":"uint96"}],"name":"UpkeepGasLimitSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingBalance","type":"uint256"},{"indexed":false,"internalType":"address","name":"destination","type":"address"}],"name":"UpkeepMigrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"offchainConfig","type":"bytes"}],"name":"UpkeepOffchainConfigSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"UpkeepPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"uint32","name":"checkBlockNumber","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"gasUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"gasOverhead","type":"uint256"},{"indexed":false,"internalType":"uint96","name":"totalPayment","type":"uint96"}],"name":"UpkeepPerformed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startingBalance","type":"uint256"},{"indexed":false,"internalType":"address","name":"importedFrom","type":"address"}],"name":"UpkeepReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"executeGas","type":"uint32"},{"indexed":false,"internalType":"address","name":"admin","type":"address"}],"name":"UpkeepRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"UpkeepUnpaused","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"transmitter","type":"address"}],"name":"acceptPayeeship","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"acceptUpkeepAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint96","name":"amount","type":"uint96"}],"name":"addFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"cancelUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"upkeepNeeded","type":"bool"},{"internalType":"bytes","name":"performData","type":"bytes"},{"internalType":"enum UpkeepFailureReason","name":"upkeepFailureReason","type":"uint8"},{"internalType":"uint256","name":"gasUsed","type":"uint256"},{"internalType":"uint256","name":"fastGasWei","type":"uint256"},{"internalType":"uint256","name":"linkNative","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"startIndex","type":"uint256"},{"internalType":"uint256","name":"maxCount","type":"uint256"}],"name":"getActiveUpkeepIDs","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFastGasFeedAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getKeeperRegistryLogicAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLinkAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLinkNativeFeedAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"gasLimit","type":"uint32"}],"name":"getMaxPaymentForGas","outputs":[{"internalType":"uint96","name":"maxPayment","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getMinBalanceForUpkeep","outputs":[{"internalType":"uint96","name":"minBalance","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPaymentModel","outputs":[{"internalType":"enum KeeperRegistryBase2_0.PaymentModel","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"peer","type":"address"}],"name":"getPeerRegistryMigrationPermission","outputs":[{"internalType":"enum KeeperRegistryBase2_0.MigrationPermission","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"query","type":"address"}],"name":"getSignerInfo","outputs":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"uint8","name":"index","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getState","outputs":[{"components":[{"internalType":"uint32","name":"nonce","type":"uint32"},{"internalType":"uint96","name":"ownerLinkBalance","type":"uint96"},{"internalType":"uint256","name":"expectedLinkBalance","type":"uint256"},{"internalType":"uint96","name":"totalPremium","type":"uint96"},{"internalType":"uint256","name":"numUpkeeps","type":"uint256"},{"internalType":"uint32","name":"configCount","type":"uint32"},{"internalType":"uint32","name":"latestConfigBlockNumber","type":"uint32"},{"internalType":"bytes32","name":"latestConfigDigest","type":"bytes32"},{"internalType":"uint32","name":"latestEpoch","type":"uint32"},{"internalType":"bool","name":"paused","type":"bool"}],"internalType":"struct State","name":"state","type":"tuple"},{"components":[{"internalType":"uint32","name":"paymentPremiumPPB","type":"uint32"},{"internalType":"uint32","name":"flatFeeMicroLink","type":"uint32"},{"internalType":"uint32","name":"checkGasLimit","type":"uint32"},{"internalType":"uint24","name":"stalenessSeconds","type":"uint24"},{"internalType":"uint16","name":"gasCeilingMultiplier","type":"uint16"},{"internalType":"uint96","name":"minUpkeepSpend","type":"uint96"},{"internalType":"uint32","name":"maxPerformGas","type":"uint32"},{"internalType":"uint32","name":"maxCheckDataSize","type":"uint32"},{"internalType":"uint32","name":"maxPerformDataSize","type":"uint32"},{"internalType":"uint256","name":"fallbackGasPrice","type":"uint256"},{"internalType":"uint256","name":"fallbackLinkPrice","type":"uint256"},{"internalType":"address","name":"transcoder","type":"address"},{"internalType":"address","name":"registrar","type":"address"}],"internalType":"struct OnchainConfig","name":"config","type":"tuple"},{"internalType":"address[]","name":"signers","type":"address[]"},{"internalType":"address[]","name":"transmitters","type":"address[]"},{"internalType":"uint8","name":"f","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"query","type":"address"}],"name":"getTransmitterInfo","outputs":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"uint8","name":"index","type":"uint8"},{"internalType":"uint96","name":"balance","type":"uint96"},{"internalType":"uint96","name":"lastCollected","type":"uint96"},{"internalType":"address","name":"payee","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getUpkeep","outputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint32","name":"executeGas","type":"uint32"},{"internalType":"bytes","name":"checkData","type":"bytes"},{"internalType":"uint96","name":"balance","type":"uint96"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"uint64","name":"maxValidBlocknumber","type":"uint64"},{"internalType":"uint32","name":"lastPerformBlockNumber","type":"uint32"},{"internalType":"uint96","name":"amountSpent","type":"uint96"},{"internalType":"bool","name":"paused","type":"bool"},{"internalType":"bytes","name":"offchainConfig","type":"bytes"}],"internalType":"struct UpkeepInfo","name":"upkeepInfo","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestConfigDetails","outputs":[{"internalType":"uint32","name":"configCount","type":"uint32"},{"internalType":"uint32","name":"blockNumber","type":"uint32"},{"internalType":"bytes32","name":"configDigest","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestConfigDigestAndEpoch","outputs":[{"internalType":"bool","name":"scanLogs","type":"bool"},{"internalType":"bytes32","name":"configDigest","type":"bytes32"},{"internalType":"uint32","name":"epoch","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"address","name":"destination","type":"address"}],"name":"migrateUpkeeps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onTokenTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"pauseUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"encodedUpkeeps","type":"bytes"}],"name":"receiveUpkeeps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recoverFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint32","name":"gasLimit","type":"uint32"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"bytes","name":"checkData","type":"bytes"},{"internalType":"bytes","name":"offchainConfig","type":"bytes"}],"name":"registerUpkeep","outputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"signers","type":"address[]"},{"internalType":"address[]","name":"transmitters","type":"address[]"},{"internalType":"uint8","name":"f","type":"uint8"},{"internalType":"bytes","name":"onchainConfig","type":"bytes"},{"internalType":"uint64","name":"offchainConfigVersion","type":"uint64"},{"internalType":"bytes","name":"offchainConfig","type":"bytes"}],"name":"setConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"payees","type":"address[]"}],"name":"setPayees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"peer","type":"address"},{"internalType":"enum KeeperRegistryBase2_0.MigrationPermission","name":"permission","type":"uint8"}],"name":"setPeerRegistryMigrationPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint32","name":"gasLimit","type":"uint32"}],"name":"setUpkeepGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"config","type":"bytes"}],"name":"setUpkeepOffchainConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"performData","type":"bytes"}],"name":"simulatePerformUpkeep","outputs":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"uint256","name":"gasUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"transmitter","type":"address"},{"internalType":"address","name":"proposed","type":"address"}],"name":"transferPayeeship","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"proposed","type":"address"}],"name":"transferUpkeepAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[3]","name":"reportContext","type":"bytes32[3]"},{"internalType":"bytes","name":"rawReport","type":"bytes"},{"internalType":"bytes32[]","name":"rs","type":"bytes32[]"},{"internalType":"bytes32[]","name":"ss","type":"bytes32[]"},{"internalType":"bytes32","name":"rawVs","type":"bytes32"}],"name":"transmit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"typeAndVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"unpauseUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"newCheckData","type":"bytes"}],"name":"updateCheckData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upkeepTranscoderVersion","outputs":[{"internalType":"enum UpkeepFormat","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawOwnerFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawPayment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
6101206040523480156200001257600080fd5b506040516200612a3803806200612a8339810160408190526200003591620003a7565b806001600160a01b031663f15701416040518163ffffffff1660e01b815260040160206040518083038186803b1580156200006f57600080fd5b505afa15801562000084573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000aa9190620003ce565b816001600160a01b031663ca30e6036040518163ffffffff1660e01b815260040160206040518083038186803b158015620000e457600080fd5b505afa158015620000f9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200011f9190620003a7565b826001600160a01b031663b10b673c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200015957600080fd5b505afa1580156200016e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001949190620003a7565b836001600160a01b0316636709d0e56040518163ffffffff1660e01b815260040160206040518083038186803b158015620001ce57600080fd5b505afa158015620001e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002099190620003a7565b3380600081620002605760405162461bcd60e51b815260206004820152601860248201527f43616e6e6f7420736574206f776e657220746f207a65726f000000000000000060448201526064015b60405180910390fd5b600080546001600160a01b0319166001600160a01b038481169190911790915581161562000293576200029381620002fb565b505050836002811115620002ab57620002ab620003f1565b60e0816002811115620002c257620002c2620003f1565b60f81b9052506001600160601b0319606093841b811660805291831b821660a052821b811660c05292901b909116610100525062000420565b6001600160a01b038116331415620003565760405162461bcd60e51b815260206004820152601760248201527f43616e6e6f74207472616e7366657220746f2073656c66000000000000000000604482015260640162000257565b600180546001600160a01b0319166001600160a01b0383811691821790925560008054604051929316917fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae12789190a350565b600060208284031215620003ba57600080fd5b8151620003c78162000407565b9392505050565b600060208284031215620003e157600080fd5b815160038110620003c757600080fd5b634e487b7160e01b600052602160045260246000fd5b6001600160a01b03811681146200041d57600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160f81c6101005160601c615c8c6200049e600039600081816105410152610a50015260008181610982015281816141ff01526143b601526000818161059501526133eb0152600081816107f401526134d40152600081816108af01526112ef0152615c8c6000f3fe60806040526004361061030c5760003560e01c80638e86139b1161019a578063b657bc9c116100e1578063eb5dcd6c1161008a578063f2fde38b11610064578063f2fde38b146109a6578063f7d334ba146109c6578063faa3e996146109f85761031b565b8063eb5dcd6c14610722578063ed56b3e1146108f3578063f1570141146109735761031b565b8063c8048022116100bb578063c804802214610512578063ca30e603146108a0578063e3d0e712146108d35761031b565b8063b657bc9c14610853578063b79550be14610468578063c7c3a19a146108735761031b565b8063aed2e92911610143578063b121e1471161011d578063b121e14714610818578063b148ab6b14610512578063b1dc65a4146108335761031b565b8063aed2e92914610758578063afcb95d71461078f578063b10b673c146107e55761031b565b8063a4c0ed3611610174578063a4c0ed3614610702578063a710b22114610722578063a72aa27e1461073d5761031b565b80638e86139b146106cc578063948108f7146106e75780639fab4386146106b15761031b565b8063572e05e11161025e57806381ff7048116102075780638765ecbe116101e15780638765ecbe146105125780638da5cb5b146106865780638dcf0fe7146106b15761031b565b806381ff7048146105fc5780638456cb591461046857806385c1b0ba146106665761031b565b8063744bfe6111610238578063744bfe611461043257806379ba5097146105e75780637d9b97e0146104685761031b565b8063572e05e1146105325780636709d0e5146105865780636ded9eae146105b95761031b565b80631a2af011116102c0578063421d183b1161029a578063421d183b1461047d57806348013d7b146104f05780635165f2f5146105125761031b565b80631a2af011146104325780633b9cce591461044d5780633f4ba83a146104685761031b565b8063181f5a77116102f1578063181f5a77146103965780631865c57d146103ec578063187256e8146104125761031b565b806306e3b632146103235780630e08ae84146103595761031b565b3661031b57610319610a4b565b005b610319610a4b565b34801561032f57600080fd5b5061034361033e366004614f40565b610a76565b60405161035091906152ef565b60405180910390f35b34801561036557600080fd5b50610379610374366004615082565b610b70565b6040516bffffffffffffffffffffffff9091168152602001610350565b3480156103a257600080fd5b506103df6040518060400160405280601481526020017f4b6565706572526567697374727920322e302e3000000000000000000000000081525081565b604051610350919061539d565b3480156103f857600080fd5b50610401610cb3565b6040516103509594939291906153d7565b34801561041e57600080fd5b5061031961042d366004614a24565b611076565b34801561043e57600080fd5b5061031961042d366004614ecf565b34801561045957600080fd5b5061031961042d366004614b5a565b34801561047457600080fd5b50610319611082565b34801561048957600080fd5b5061049d6104983660046149ce565b61108a565b60408051951515865260ff90941660208601526bffffffffffffffffffffffff9283169385019390935216606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a001610350565b3480156104fc57600080fd5b50610505600281565b60405161035091906153ca565b34801561051e57600080fd5b5061031961052d366004614e9d565b6111a8565b34801561053e57600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610350565b34801561059257600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610561565b3480156105c557600080fd5b506105d96105d4366004614ab2565b6111b3565b604051908152602001610350565b3480156105f357600080fd5b506103196111c8565b34801561060857600080fd5b50610643601254600e5463ffffffff6c0100000000000000000000000083048116937001000000000000000000000000000000009093041691565b6040805163ffffffff948516815293909216602084015290820152606001610350565b34801561067257600080fd5b50610319610681366004614d20565b6112ca565b34801561069257600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff16610561565b3480156106bd57600080fd5b50610319610681366004614ef4565b3480156106d857600080fd5b5061031961042d366004614d77565b3480156106f357600080fd5b5061031961042d36600461505d565b34801561070e57600080fd5b5061031961071d366004614a56565b6112d7565b34801561072e57600080fd5b5061031961042d3660046149eb565b34801561074957600080fd5b5061031961042d366004615038565b34801561076457600080fd5b50610778610773366004614ef4565b6114f2565b604080519215158352602083019190915201610350565b34801561079b57600080fd5b50600e54600f54604080516000815260208101939093527c010000000000000000000000000000000000000000000000000000000090910463ffffffff1690820152606001610350565b3480156107f157600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610561565b34801561082457600080fd5b5061031961052d3660046149ce565b34801561083f57600080fd5b5061031961084e366004614c69565b61165d565b34801561085f57600080fd5b5061037961086e366004614e9d565b612233565b34801561087f57600080fd5b5061089361088e366004614e9d565b612257565b60405161035091906154e4565b3480156108ac57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610561565b3480156108df57600080fd5b506103196108ee366004614b9c565b612582565b3480156108ff57600080fd5b5061095a61090e3660046149ce565b73ffffffffffffffffffffffffffffffffffffffff1660009081526009602090815260409182902082518084019093525460ff8082161515808552610100909204169290910182905291565b60408051921515835260ff909116602083015201610350565b34801561097f57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610505565b3480156109b257600080fd5b506103196109c13660046149ce565b613353565b3480156109d257600080fd5b506109e66109e1366004614e9d565b613364565b60405161035096959493929190615333565b348015610a0457600080fd5b50610a3e610a133660046149ce565b73ffffffffffffffffffffffffffffffffffffffff1660009081526016602052604090205460ff1690565b60405161035091906153b0565b610a747f0000000000000000000000000000000000000000000000000000000000000000613387565b565b60606000610a8460026133ab565b9050808410610abf576040517f1390f2a100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82610ad157610ace84826159f1565b92505b60008367ffffffffffffffff811115610aec57610aec615baa565b604051908082528060200260200182016040528015610b15578160200160208202803683370190505b50905060005b84811015610b6757610b38610b308288615872565b6002906133b5565b828281518110610b4a57610b4a615b7b565b602090810291909101015280610b5f81615ab5565b915050610b1b565b50949350505050565b6040805161012081018252600f5460ff808216835263ffffffff6101008084048216602086015265010000000000840482169585019590955262ffffff6901000000000000000000840416606085015261ffff6c0100000000000000000000000084041660808501526e01000000000000000000000000000083048216151560a08501526f010000000000000000000000000000008304909116151560c08401526bffffffffffffffffffffffff70010000000000000000000000000000000083041660e08401527c010000000000000000000000000000000000000000000000000000000090910416918101919091526000908180610c6f836133c8565b6012549193509150610caa90849087907801000000000000000000000000000000000000000000000000900463ffffffff16858560006135c4565b95945050505050565b6040805161014081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810191909152604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081018290526101608101829052610180810191909152604080516101408101825260125468010000000000000000900463ffffffff1681526011546bffffffffffffffffffffffff908116602083015260155492820192909252600f54700100000000000000000000000000000000900490911660608083019190915290819060009060808101610de860026133ab565b815260125463ffffffff6c01000000000000000000000000808304821660208086019190915270010000000000000000000000000000000084048316604080870191909152600e54606080880191909152600f547c0100000000000000000000000000000000000000000000000000000000810486166080808a019190915260ff6e01000000000000000000000000000083048116151560a09a8b015284516101a0810186526101008085048a1682526501000000000085048a1682890152898b168288015262ffffff69010000000000000000008604169582019590955261ffff88850416928101929092526010546bffffffffffffffffffffffff81169a83019a909a526401000000008904881660c0830152740100000000000000000000000000000000000000008904881660e083015278010000000000000000000000000000000000000000000000009098049096169186019190915260135461012086015260145461014086015273ffffffffffffffffffffffffffffffffffffffff96849004871661016086015260115493909304909516610180840152600a8054865181840281018401909752808752969b509299508a958a959394600b9493169291859190830182828015610ff557602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610fca575b505050505092508180548060200260200160405190810160405280929190818152602001828054801561105e57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611033575b50505050509150945094509450945094509091929394565b61107e610a4b565b5050565b610a74610a4b565b73ffffffffffffffffffffffffffffffffffffffff811660009081526008602090815260408083208151608081018352905460ff80821615158352610100820416938201939093526bffffffffffffffffffffffff6201000084048116928201929092526e010000000000000000000000000000909204811660608301819052600f54849384938493849384926111369291700100000000000000000000000000000000900416615a08565b600b549091506000906111499083615909565b90508260000151836020015182856040015161116591906158ce565b6060959095015173ffffffffffffffffffffffffffffffffffffffff9b8c166000908152600c6020526040902054929c919b959a50985093169550919350505050565b6111b0610a4b565b50565b60006111bd610a4b565b979650505050505050565b60015473ffffffffffffffffffffffffffffffffffffffff16331461124e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4d7573742062652070726f706f736564206f776e65720000000000000000000060448201526064015b60405180910390fd5b60008054337fffffffffffffffffffffffff00000000000000000000000000000000000000008083168217845560018054909116905560405173ffffffffffffffffffffffffffffffffffffffff90921692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a350565b6112d2610a4b565b505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614611346576040517fc8bad78d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208114611380576040517fdfe9309000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061138e82840184614e9d565b600081815260046020526040902054909150640100000000900463ffffffff908116146113e7576040517f9c0083a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000818152600460205260409020600101546114229085906c0100000000000000000000000090046bffffffffffffffffffffffff166158ce565b600082815260046020526040902060010180546bffffffffffffffffffffffff929092166c01000000000000000000000000027fffffffffffffffff000000000000000000000000ffffffffffffffffffffffff90921691909117905560155461148d908590615872565b6015556040516bffffffffffffffffffffffff8516815273ffffffffffffffffffffffffffffffffffffffff86169082907fafd24114486da8ebfc32f3626dada8863652e187461aa74d4bfa7348915062039060200160405180910390a35050505050565b6000806114fd61360f565b600f546e010000000000000000000000000000900460ff161561154c576040517f24522f3400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600085815260046020908152604091829020825160e081018452815463ffffffff8082168352640100000000820481168386015268010000000000000000820460ff16151583870152690100000000000000000090910473ffffffffffffffffffffffffffffffffffffffff1660608301526001909201546bffffffffffffffffffffffff80821660808401526c0100000000000000000000000082041660a08301527801000000000000000000000000000000000000000000000000900490911660c08201528251601f87018390048302810183019093528583529161165091839190889088908190840183828082843760009201919091525061364792505050565b9250925050935093915050565b60005a6040805161012081018252600f5460ff808216835261010080830463ffffffff90811660208601526501000000000084048116958501959095526901000000000000000000830462ffffff1660608501526c01000000000000000000000000830461ffff1660808501526e0100000000000000000000000000008304821615801560a08601526f010000000000000000000000000000008404909216151560c085015270010000000000000000000000000000000083046bffffffffffffffffffffffff1660e08501527c01000000000000000000000000000000000000000000000000000000009092049093169082015291925061178b576040517f24522f3400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3360009081526008602052604090205460ff166117d4576040517f1099ed7500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006118158a8a8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506137ad92505050565b9050600081604001515167ffffffffffffffff81111561183757611837615baa565b6040519080825280602002602001820160405280156118eb57816020015b604080516101a081018252600060c0820181815260e083018290526101008301829052610120830182905261014083018290526101608301829052610180830182905282526020808301829052928201819052606082018190526080820181905260a082015282527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092019101816118555790505b5090506000805b836040015151811015611b9757600460008560400151838151811061191957611919615b7b565b6020908102919091018101518252818101929092526040908101600020815160e081018352815463ffffffff8082168352640100000000820481169583019590955268010000000000000000810460ff16151593820193909352690100000000000000000090920473ffffffffffffffffffffffffffffffffffffffff166060830152600101546bffffffffffffffffffffffff80821660808401526c0100000000000000000000000082041660a08301527801000000000000000000000000000000000000000000000000900490911660c08201528351849083908110611a0357611a03615b7b565b602002602001015160000181905250611a6c85848381518110611a2857611a28615b7b565b6020026020010151600001516000015186606001518481518110611a4e57611a4e615b7b565b602002602001015160400151518760000151886020015160016135c4565b838281518110611a7e57611a7e615b7b565b6020026020010151604001906bffffffffffffffffffffffff1690816bffffffffffffffffffffffff1681525050611b2c84604001518281518110611ac557611ac5615b7b565b602002602001015185606001518381518110611ae357611ae3615b7b565b6020026020010151858481518110611afd57611afd615b7b565b602002602001015160000151868581518110611b1b57611b1b615b7b565b602002602001015160400151613859565b838281518110611b3e57611b3e615b7b565b60200260200101516020019015159081151581525050828181518110611b6657611b66615b7b565b60200260200101516020015115611b8557611b8260018361584c565b91505b80611b8f81615ab5565b9150506118f2565b5061ffff8116611bd3576040517ff803a2ca00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e548d3514611c0f576040517fdfdcf8e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8351611c1c9060016158a9565b60ff1689141580611c2d5750888714155b15611c64576040517f0244f71a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611c748d8d8d8d8d8d8d8d61399b565b60005b836040015151811015611e5057828181518110611c9657611c96615b7b565b60200260200101516020015115611e3e574363ffffffff166004600086604001518481518110611cc857611cc8615b7b565b6020026020010151815260200190815260200160002060010160189054906101000a900463ffffffff1663ffffffff161415611d30576040517fb55ac75400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611d78838281518110611d4557611d45615b7b565b60200260200101516000015185606001518381518110611d6757611d67615b7b565b602002602001015160400151613647565b848381518110611d8a57611d8a615b7b565b6020026020010151606001858481518110611da757611da7615b7b565b60200260200101516080018281525082151515158152505050828181518110611dd257611dd2615b7b565b60200260200101516080015186611de991906159f1565b9550436004600086604001518481518110611e0657611e06615b7b565b6020026020010151815260200190815260200160002060010160186101000a81548163ffffffff021916908363ffffffff1602179055505b80611e4881615ab5565b915050611c77565b508351611e5e9060016158a9565b611e6d9060ff1661044c615934565b616914611e7b8d6010615934565b5a611e8690896159f1565b611e909190615872565b611e9a9190615872565b611ea49190615872565b94506116a8611eb761ffff8316876158f5565b611ec19190615872565b945060008060008060005b8760400151518110156120cc57868181518110611eeb57611eeb615b7b565b602002602001015160200151156120ba57611f2d8a89606001518381518110611f1657611f16615b7b565b602002602001015160400151518b60000151613c04565b878281518110611f3f57611f3f615b7b565b602002602001015160a0018181525050611f9b8989604001518381518110611f6957611f69615b7b565b6020026020010151898481518110611f8357611f83615b7b565b60200260200101518b600001518c602001518b613c22565b9093509150611faa82856158ce565b9350611fb683866158ce565b9450868181518110611fca57611fca615b7b565b602002602001015160600151151588604001518281518110611fee57611fee615b7b565b60200260200101517f29233ba1d7b302b8fe230ad0b81423aba5371b2a6f6b821228212385ee6a44208a60600151848151811061202d5761202d615b7b565b6020026020010151600001518a858151811061204b5761204b615b7b565b6020026020010151608001518b868151811061206957612069615b7b565b602002602001015160a00151878961208191906158ce565b6040805163ffffffff90951685526020850193909352918301526bffffffffffffffffffffffff16606082015260800160405180910390a35b806120c481615ab5565b915050611ecc565b505033600090815260086020526040902080548492506002906121049084906201000090046bffffffffffffffffffffffff166158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555080600f60000160108282829054906101000a90046bffffffffffffffffffffffff1661215e91906158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555060008f6001600381106121a1576121a1615b7b565b602002013560001c9050600060088264ffffffffff16901c905087610100015163ffffffff168163ffffffff16111561222057600f80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff8416021790555b5050505050505050505050505050505050565b6000818152600460205260408120546122519063ffffffff16610b70565b92915050565b604080516101408101825260008082526020820181905260609282018390528282018190526080820181905260a0820181905260c0820181905260e082018190526101008201526101208101919091526000828152600460209081526040808320815160e081018352815463ffffffff8082168352640100000000820481168387015268010000000000000000820460ff16151583860152690100000000000000000090910473ffffffffffffffffffffffffffffffffffffffff908116606084019081526001909401546bffffffffffffffffffffffff80821660808601526c0100000000000000000000000082041660a085015278010000000000000000000000000000000000000000000000009004821660c08401528451610140810186529351168352815116828501528685526007909352928190208054929392918301916123a390615a61565b80601f01602080910402602001604051908101604052809291908181526020018280546123cf90615a61565b801561241c5780601f106123f15761010080835404028352916020019161241c565b820191906000526020600020905b8154815290600101906020018083116123ff57829003601f168201915b505050505081526020018260a001516bffffffffffffffffffffffff1681526020016005600086815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001826020015163ffffffff1667ffffffffffffffff1681526020018260c0015163ffffffff16815260200182608001516bffffffffffffffffffffffff1681526020018260400151151581526020016017600086815260200190815260200160002080546124f990615a61565b80601f016020809104026020016040519081016040528092919081815260200182805461252590615a61565b80156125725780601f1061254757610100808354040283529160200191612572565b820191906000526020600020905b81548152906001019060200180831161255557829003601f168201915b5050505050815250915050919050565b61258a613d15565b601f865111156125c6576040517f25d0209c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60ff8416612600576040517fe77dba5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8451865114158061261f575061261784600361599d565b60ff16865111155b15612656576040517f1d2d1c5800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f54600b547001000000000000000000000000000000009091046bffffffffffffffffffffffff169060005b816bffffffffffffffffffffffff168110156126eb576126d8600b82815481106126af576126af615b7b565b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff168484613d96565b50806126e381615ab5565b915050612683565b5060008060005b836bffffffffffffffffffffffff168110156127f457600a818154811061271b5761271b615b7b565b600091825260209091200154600b805473ffffffffffffffffffffffffffffffffffffffff9092169450908290811061275657612756615b7b565b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff868116845260098352604080852080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001690559116808452600890925290912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690559150806127ec81615ab5565b9150506126f2565b50612801600a60006145f5565b61280d600b60006145f5565b604080516080810182526000808252602082018190529181018290526060810182905290805b8c51811015612b9157600960008e838151811061285257612852615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff1682528101919091526040016000205460ff16156128bd576040517f77cea0fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180604001604052806001151581526020018260ff16815250600960008f84815181106128ee576128ee615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff1682528181019290925260400160002082518154939092015160ff16610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff921515929092167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000909316929092171790558b518c908290811061299657612996615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff81166000908152600883526040908190208151608081018352905460ff80821615801584526101008304909116958301959095526bffffffffffffffffffffffff6201000082048116938301939093526e0100000000000000000000000000009004909116606082015294509250612a5b576040517f6a7281ad00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001835260ff80821660208086019182526bffffffffffffffffffffffff808b166060880190815273ffffffffffffffffffffffffffffffffffffffff871660009081526008909352604092839020885181549551948a0151925184166e010000000000000000000000000000027fffffffffffff000000000000000000000000ffffffffffffffffffffffffffff939094166201000002929092167fffffffffffff000000000000000000000000000000000000000000000000ffff94909616610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff921515929092167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00009095169490941717919091169290921791909117905580612b8981615ab5565b915050612833565b50508a51612ba79150600a9060208d0190614613565b508851612bbb90600b9060208c0190614613565b50600087806020019051810190612bd29190614dad565b60125460c082015191925063ffffffff640100000000909104811691161015612c27576040517f39abc10400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60125460e082015163ffffffff74010000000000000000000000000000000000000000909204821691161015612c89576040517f1fa9bdcb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60125461010082015163ffffffff7801000000000000000000000000000000000000000000000000909204821691161015612cf0576040517fd1d5faa800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040518061012001604052808a60ff168152602001826000015163ffffffff168152602001826020015163ffffffff168152602001826060015162ffffff168152602001826080015161ffff168152602001600015158152602001600015158152602001866bffffffffffffffffffffffff168152602001600063ffffffff16815250600f60008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160056101000a81548163ffffffff021916908363ffffffff16021790555060608201518160000160096101000a81548162ffffff021916908362ffffff160217905550608082015181600001600c6101000a81548161ffff021916908361ffff16021790555060a082015181600001600e6101000a81548160ff02191690831515021790555060c082015181600001600f6101000a81548160ff02191690831515021790555060e08201518160000160106101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555061010082015181600001601c6101000a81548163ffffffff021916908363ffffffff1602179055509050506040518061016001604052808260a001516bffffffffffffffffffffffff16815260200182610160015173ffffffffffffffffffffffffffffffffffffffff168152602001601060010160009054906101000a90046bffffffffffffffffffffffff166bffffffffffffffffffffffff16815260200182610180015173ffffffffffffffffffffffffffffffffffffffff168152602001826040015163ffffffff1681526020018260c0015163ffffffff168152602001601060020160089054906101000a900463ffffffff1663ffffffff1681526020016010600201600c9054906101000a900463ffffffff1663ffffffff168152602001601060020160109054906101000a900463ffffffff1663ffffffff1681526020018260e0015163ffffffff16815260200182610100015163ffffffff16815250601060008201518160000160006101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff160217905550602082015181600001600c6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160010160006101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff160217905550606082015181600101600c6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060808201518160020160006101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160020160046101000a81548163ffffffff021916908363ffffffff16021790555060c08201518160020160086101000a81548163ffffffff021916908363ffffffff16021790555060e082015181600201600c6101000a81548163ffffffff021916908363ffffffff1602179055506101008201518160020160106101000a81548163ffffffff021916908363ffffffff1602179055506101208201518160020160146101000a81548163ffffffff021916908363ffffffff1602179055506101408201518160020160186101000a81548163ffffffff021916908363ffffffff1602179055509050508061012001516013819055508061014001516014819055506000601060020160109054906101000a900463ffffffff16905043601060020160106101000a81548163ffffffff021916908363ffffffff16021790555060016010600201600c8282829054906101000a900463ffffffff16613297919061588a565b92506101000a81548163ffffffff021916908363ffffffff1602179055506132e146306010600201600c9054906101000a900463ffffffff1663ffffffff168f8f8f8f8f8f613fbd565b600e819055507f1591690b8638f5fb2dbec82ac741805ac5da8b45dc5263f4875b0496fdce4e0581600e546010600201600c9054906101000a900463ffffffff168f8f8f8f8f8f60405161333d999897969594939291906156c0565b60405180910390a1505050505050505050505050565b61335b613d15565b6111b081614067565b6000606060008060008061337661360f565b61337e610a4b565b91939550919395565b3660008037600080366000845af43d6000803e8080156133a6573d6000f35b3d6000fd5b6000612251825490565b60006133c1838361415d565b9392505050565b6000806000836060015162ffffff1690506000808263ffffffff161190506000807f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561344f57600080fd5b505afa158015613463573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613487919061509f565b509450909250505060008113158061349e57508142105b806134bf57508280156134bf57506134b682426159f1565b8463ffffffff16105b156134ce5760135495506134d2565b8095505b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561353857600080fd5b505afa15801561354c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613570919061509f565b509450909250505060008113158061358757508142105b806135a857508280156135a8575061359f82426159f1565b8463ffffffff16105b156135b75760145494506135bb565b8094505b50505050915091565b6000806135d5868960000151614187565b90506000806135f08a8a63ffffffff16858a8a60018b6141ca565b90925090506135ff81836158ce565b93505050505b9695505050505050565b3215610a74576040517fb60ac5db00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f5460009081906f01000000000000000000000000000000900460ff161561369c576040517f37ed32e800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f80547fffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffff166f010000000000000000000000000000001790555a90506000634585e33b60e01b846040516024016136f4919061539d565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905061376c856000015163ffffffff168660600151836145a9565b92505a61377990836159f1565b915050600f80547fffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffff16905590939092509050565b6137d86040518060800160405280600081526020016000815260200160608152602001606081525090565b600080600080858060200190518101906137f29190614f62565b93509350935093508051825114613835576040517fb55ac75400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60408051608081018252948552602085019390935291830152606082015292915050565b60008260c0015163ffffffff16846000015163ffffffff1610156138aa5760405185907f5aa44821f7938098502bff537fbbdc9aaaa2fa655c10740646fce27e54987a8990600090a2506000613993565b6020840151845163ffffffff1640146138f05760405185907f561ff77e59394941a01a456497a9418dea82e2a39abb3ecebfb1cef7e0bfdc1390600090a2506000613993565b43836020015163ffffffff16116139345760405185907fd84831b6a3a7fbd333f42fe7f9104a139da6cca4cc1507aef4ddad79b31d017f90600090a2506000613993565b816bffffffffffffffffffffffff168360a001516bffffffffffffffffffffffff16101561398f5760405185907f7895fdfe292beab0842d5beccd078e85296b9e17a30eaee4c261a2696b84eb9690600090a2506000613993565b5060015b949350505050565b600087876040516139ad9291906152b8565b6040519081900381206139c4918b90602001615383565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815282825280516020918201208383019092526000808452908301819052909250906000805b88811015613b9b57600185878360208110613a3057613a30615b7b565b613a3d91901a601b6158a9565b8c8c85818110613a4f57613a4f615b7b565b905060200201358b8b86818110613a6857613a68615b7b565b9050602002013560405160008152602001604052604051613aa5949392919093845260ff9290921660208401526040830152606082015260800190565b6020604051602081039080840390855afa158015613ac7573d6000803e3d6000fd5b5050604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081015173ffffffffffffffffffffffffffffffffffffffff811660009081526009602090815290849020838501909452925460ff8082161515808552610100909204169383019390935290955093509050613b75576040517f0f4c073700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826020015160080260ff166001901b840193508080613b9390615ab5565b915050613a13565b50827e01010101010101010101010101010101010101010101010101010101010101841614613bf6576040517fc103be2e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050505050565b6000613c108383614187565b9050808410156133c157509192915050565b600080613c3d8887608001518860a0015188888860016141ca565b90925090506000613c4e82846158ce565b600089815260046020526040902060010180549192508291600c90613c929084906c0100000000000000000000000090046bffffffffffffffffffffffff16615a08565b82546101009290920a6bffffffffffffffffffffffff81810219909316918316021790915560008a815260046020526040812060010180548594509092613cdb918591166158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555050965096945050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610a74576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e6572000000000000000000006044820152606401611245565b73ffffffffffffffffffffffffffffffffffffffff831660009081526008602090815260408083208151608081018352905460ff80821615158352610100820416938201939093526bffffffffffffffffffffffff6201000084048116928201929092526e01000000000000000000000000000090920416606082018190528290613e219086615a08565b90506000613e2f8583615909565b90508083604001818151613e4391906158ce565b6bffffffffffffffffffffffff9081169091528716606085015250613e6885826159c6565b613e729083615a08565b60118054600090613e929084906bffffffffffffffffffffffff166158ce565b825461010092830a6bffffffffffffffffffffffff81810219909216928216029190911790925573ffffffffffffffffffffffffffffffffffffffff999099166000908152600860209081526040918290208751815492890151938901516060909901517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00009093169015157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff161760ff909316909b02919091177fffffffffffff000000000000000000000000000000000000000000000000ffff1662010000878416027fffffffffffff000000000000000000000000ffffffffffffffffffffffffffff16176e010000000000000000000000000000919092160217909755509095945050505050565b6000808a8a8a8a8a8a8a8a8a604051602001613fe19998979695949392919061561b565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001815291905280516020909101207dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167e01000000000000000000000000000000000000000000000000000000000000179b9a5050505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff81163314156140e7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f43616e6e6f74207472616e7366657220746f2073656c660000000000000000006044820152606401611245565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83811691821790925560008054604051929316917fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae12789190a350565b600082600001828154811061417457614174615b7b565b9060005260206000200154905092915050565b600061419a63ffffffff84166014615934565b6141a58360016158a9565b6141b49060ff16611d4c615934565b6141c09061fde8615872565b6133c19190615872565b6000806000896080015161ffff16876141e39190615934565b90508380156141f15750803a105b156141f957503a5b600060027f0000000000000000000000000000000000000000000000000000000000000000600281111561422f5761422f615b4c565b14156143b257604080516000815260208101909152851561428e57600036604051806080016040528060488152602001615c3860489139604051602001614278939291906152c8565b604051602081830303815290604052905061430a565b6012546142be907801000000000000000000000000000000000000000000000000900463ffffffff166004615971565b63ffffffff1667ffffffffffffffff8111156142dc576142dc615baa565b6040519080825280601f01601f191660200182016040528015614306576020820181803683370190505b5090505b6040517f49948e0e00000000000000000000000000000000000000000000000000000000815273420000000000000000000000000000000000000f906349948e0e9061435a90849060040161539d565b60206040518083038186803b15801561437257600080fd5b505afa158015614386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143aa9190614eb6565b91505061446e565b60017f000000000000000000000000000000000000000000000000000000000000000060028111156143e6576143e6615b4c565b141561446e57606c73ffffffffffffffffffffffffffffffffffffffff1663c6f7de0e6040518163ffffffff1660e01b815260040160206040518083038186803b15801561443357600080fd5b505afa158015614447573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061446b9190614eb6565b90505b8461448a57808b6080015161ffff166144879190615934565b90505b61449861ffff8716826158f5565b9050600087826144a88c8e615872565b6144b29086615934565b6144bc9190615872565b6144ce90670de0b6b3a7640000615934565b6144d891906158f5565b905060008c6040015163ffffffff1664e8d4a510006144f79190615934565b898e6020015163ffffffff16858f886145109190615934565b61451a9190615872565b61452890633b9aca00615934565b6145329190615934565b61453c91906158f5565b6145469190615872565b90506b033b2e3c9fd0803ce800000061455f8284615872565b1115614597576040517f2ad7547a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b909c909b509950505050505050505050565b60005a6113888110156145bb57600080fd5b6113888103905084604082048203116145d357600080fd5b50823b6145df57600080fd5b60008083516020850160008789f1949350505050565b50805460008255906000526020600020908101906111b0919061469d565b82805482825590600052602060002090810192821561468d579160200282015b8281111561468d57825182547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff909116178255602090920191600190910190614633565b5061469992915061469d565b5090565b5b80821115614699576000815560010161469e565b80516146bd81615be9565b919050565b60008083601f8401126146d457600080fd5b50813567ffffffffffffffff8111156146ec57600080fd5b6020830191508360208260051b850101111561470757600080fd5b9250929050565b600082601f83011261471f57600080fd5b8135602061473461472f836157e2565b615793565b80838252828201915082860187848660051b890101111561475457600080fd5b60005b8581101561477c57813561476a81615be9565b84529284019290840190600101614757565b5090979650505050505050565b600082601f83011261479a57600080fd5b815160206147aa61472f836157e2565b80838252828201915082860187848660051b89010111156147ca57600080fd5b60005b8581101561477c57815167ffffffffffffffff808211156147ed57600080fd5b818a0191506060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0848e0301121561482557600080fd5b61482d615746565b8884015161483a81615c0b565b81526040848101518a83015291840151918383111561485857600080fd5b82850194508d603f86011261486c57600080fd5b89850151935061487e61472f85615806565b92508383528d8185870101111561489457600080fd5b6148a3848b8501838801615a35565b8101919091528652505092840192908401906001016147cd565b60008083601f8401126148cf57600080fd5b50813567ffffffffffffffff8111156148e757600080fd5b60208301915083602082850101111561470757600080fd5b600082601f83011261491057600080fd5b813561491e61472f82615806565b81815284602083860101111561493357600080fd5b816020850160208301376000918101602001919091529392505050565b805161ffff811681146146bd57600080fd5b805162ffffff811681146146bd57600080fd5b80516146bd81615c0b565b803567ffffffffffffffff811681146146bd57600080fd5b803560ff811681146146bd57600080fd5b805169ffffffffffffffffffff811681146146bd57600080fd5b80516146bd81615c1d565b6000602082840312156149e057600080fd5b81356133c181615be9565b600080604083850312156149fe57600080fd5b8235614a0981615be9565b91506020830135614a1981615be9565b809150509250929050565b60008060408385031215614a3757600080fd5b8235614a4281615be9565b9150602083013560048110614a1957600080fd5b60008060008060608587031215614a6c57600080fd5b8435614a7781615be9565b935060208501359250604085013567ffffffffffffffff811115614a9a57600080fd5b614aa6878288016148bd565b95989497509550505050565b600080600080600080600060a0888a031215614acd57600080fd5b8735614ad881615be9565b96506020880135614ae881615c0b565b95506040880135614af881615be9565b9450606088013567ffffffffffffffff80821115614b1557600080fd5b614b218b838c016148bd565b909650945060808a0135915080821115614b3a57600080fd5b50614b478a828b016148bd565b989b979a50959850939692959293505050565b60008060208385031215614b6d57600080fd5b823567ffffffffffffffff811115614b8457600080fd5b614b90858286016146c2565b90969095509350505050565b60008060008060008060c08789031215614bb557600080fd5b863567ffffffffffffffff80821115614bcd57600080fd5b614bd98a838b0161470e565b97506020890135915080821115614bef57600080fd5b614bfb8a838b0161470e565b9650614c0960408a01614998565b95506060890135915080821115614c1f57600080fd5b614c2b8a838b016148ff565b9450614c3960808a01614980565b935060a0890135915080821115614c4f57600080fd5b50614c5c89828a016148ff565b9150509295509295509295565b60008060008060008060008060e0898b031215614c8557600080fd5b606089018a811115614c9657600080fd5b8998503567ffffffffffffffff80821115614cb057600080fd5b614cbc8c838d016148bd565b909950975060808b0135915080821115614cd557600080fd5b614ce18c838d016146c2565b909750955060a08b0135915080821115614cfa57600080fd5b50614d078b828c016146c2565b999c989b50969995989497949560c00135949350505050565b600080600060408486031215614d3557600080fd5b833567ffffffffffffffff811115614d4c57600080fd5b614d58868287016146c2565b9094509250506020840135614d6c81615be9565b809150509250925092565b60008060208385031215614d8a57600080fd5b823567ffffffffffffffff811115614da157600080fd5b614b90858286016148bd565b60006101a08284031215614dc057600080fd5b614dc861576f565b614dd183614975565b8152614ddf60208401614975565b6020820152614df060408401614975565b6040820152614e0160608401614962565b6060820152614e1260808401614950565b6080820152614e2360a084016149c3565b60a0820152614e3460c08401614975565b60c0820152614e4560e08401614975565b60e0820152610100614e58818501614975565b9082015261012083810151908201526101408084015190820152610160614e808185016146b2565b90820152610180614e928482016146b2565b908201529392505050565b600060208284031215614eaf57600080fd5b5035919050565b600060208284031215614ec857600080fd5b5051919050565b60008060408385031215614ee257600080fd5b823591506020830135614a1981615be9565b600080600060408486031215614f0957600080fd5b83359250602084013567ffffffffffffffff811115614f2757600080fd5b614f33868287016148bd565b9497909650939450505050565b60008060408385031215614f5357600080fd5b50508035926020909101359150565b60008060008060808587031215614f7857600080fd5b845193506020808601519350604086015167ffffffffffffffff80821115614f9f57600080fd5b818801915088601f830112614fb357600080fd5b8151614fc161472f826157e2565b8082825285820191508585018c878560051b8801011115614fe157600080fd5b600095505b83861015615004578051835260019590950194918601918601614fe6565b5060608b0151909750945050508083111561501e57600080fd5b505061502c87828801614789565b91505092959194509250565b6000806040838503121561504b57600080fd5b823591506020830135614a1981615c0b565b6000806040838503121561507057600080fd5b823591506020830135614a1981615c1d565b60006020828403121561509457600080fd5b81356133c181615c0b565b600080600080600060a086880312156150b757600080fd5b6150c0866149a9565b94506020860151935060408601519250606086015191506150e3608087016149a9565b90509295509295909350565b600081518084526020808501945080840160005b8381101561513557815173ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101615103565b509495945050505050565b60008151808452615158816020860160208601615a35565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b805163ffffffff16825260208101516151ab602084018263ffffffff169052565b5060408101516151c3604084018263ffffffff169052565b5060608101516151da606084018262ffffff169052565b5060808101516151f0608084018261ffff169052565b5060a081015161521060a08401826bffffffffffffffffffffffff169052565b5060c081015161522860c084018263ffffffff169052565b5060e081015161524060e084018263ffffffff169052565b506101008181015163ffffffff8116848301525050610120818101519083015261014080820151908301526101608082015173ffffffffffffffffffffffffffffffffffffffff81168285015250506101808181015173ffffffffffffffffffffffffffffffffffffffff8116848301525b50505050565b8183823760009101908152919050565b8284823760008382016000815283516152e5818360208801615a35565b0195945050505050565b6020808252825182820181905260009190848201906040850190845b818110156153275783518352928401929184019160010161530b565b50909695505050505050565b861515815260c06020820152600061534e60c0830188615140565b90506007861061536057615360615b4c565b8560408301528460608301528360808301528260a0830152979650505050505050565b828152608081016060836020840137600081529392505050565b6020815260006133c16020830184615140565b60208101600483106153c4576153c4615b4c565b91905290565b602081016153c483615bd9565b855163ffffffff1681526000610340602088015161540560208501826bffffffffffffffffffffffff169052565b5060408801516040840152606088015161542f60608501826bffffffffffffffffffffffff169052565b506080880151608084015260a088015161545160a085018263ffffffff169052565b5060c088015161546960c085018263ffffffff169052565b5060e088015160e08401526101008089015161548c8286018263ffffffff169052565b5050610120888101511515908401526154a961014084018861518a565b806102e08401526154bc818401876150ef565b90508281036103008401526154d181866150ef565b91505061360561032083018460ff169052565b6020815261550b60208201835173ffffffffffffffffffffffffffffffffffffffff169052565b60006020830151615524604084018263ffffffff169052565b506040830151610140806060850152615541610160850183615140565b9150606085015161556260808601826bffffffffffffffffffffffff169052565b50608085015173ffffffffffffffffffffffffffffffffffffffff811660a08601525060a085015167ffffffffffffffff811660c08601525060c085015163ffffffff811660e08601525060e08501516101006155ce818701836bffffffffffffffffffffffff169052565b86015190506101206155e38682018315159052565b8601518584037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0018387015290506136058382615140565b60006101208b835273ffffffffffffffffffffffffffffffffffffffff8b16602084015267ffffffffffffffff808b1660408501528160608501526156628285018b6150ef565b91508382036080850152615676828a6150ef565b915060ff881660a085015283820360c08501526156938288615140565b90861660e085015283810361010085015290506156b08185615140565b9c9b505050505050505050505050565b600061012063ffffffff808d1684528b6020850152808b166040850152508060608401526156f08184018a6150ef565b9050828103608084015261570481896150ef565b905060ff871660a084015282810360c08401526157218187615140565b905067ffffffffffffffff851660e08401528281036101008401526156b08185615140565b6040516060810167ffffffffffffffff8111828210171561576957615769615baa565b60405290565b6040516101a0810167ffffffffffffffff8111828210171561576957615769615baa565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156157da576157da615baa565b604052919050565b600067ffffffffffffffff8211156157fc576157fc615baa565b5060051b60200190565b600067ffffffffffffffff82111561582057615820615baa565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600061ffff80831681851680830382111561586957615869615aee565b01949350505050565b6000821982111561588557615885615aee565b500190565b600063ffffffff80831681851680830382111561586957615869615aee565b600060ff821660ff84168060ff038211156158c6576158c6615aee565b019392505050565b60006bffffffffffffffffffffffff80831681851680830382111561586957615869615aee565b60008261590457615904615b1d565b500490565b60006bffffffffffffffffffffffff8084168061592857615928615b1d565b92169190910492915050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561596c5761596c615aee565b500290565b600063ffffffff8083168185168183048111821515161561599457615994615aee565b02949350505050565b600060ff821660ff84168160ff04811182151516156159be576159be615aee565b029392505050565b60006bffffffffffffffffffffffff8083168185168183048111821515161561599457615994615aee565b600082821015615a0357615a03615aee565b500390565b60006bffffffffffffffffffffffff83811690831681811015615a2d57615a2d615aee565b039392505050565b60005b83811015615a50578181015183820152602001615a38565b838111156152b25750506000910152565b600181811c90821680615a7557607f821691505b60208210811415615aaf577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415615ae757615ae7615aee565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600381106111b0576111b0615b4c565b73ffffffffffffffffffffffffffffffffffffffff811681146111b057600080fd5b63ffffffff811681146111b057600080fd5b6bffffffffffffffffffffffff811681146111b057600080fdfe307866666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666a164736f6c6343000806000a00000000000000000000000096d2971f181bf01f7b61f254e0ded20bb1657e7b
Deployed Bytecode
0x60806040526004361061030c5760003560e01c80638e86139b1161019a578063b657bc9c116100e1578063eb5dcd6c1161008a578063f2fde38b11610064578063f2fde38b146109a6578063f7d334ba146109c6578063faa3e996146109f85761031b565b8063eb5dcd6c14610722578063ed56b3e1146108f3578063f1570141146109735761031b565b8063c8048022116100bb578063c804802214610512578063ca30e603146108a0578063e3d0e712146108d35761031b565b8063b657bc9c14610853578063b79550be14610468578063c7c3a19a146108735761031b565b8063aed2e92911610143578063b121e1471161011d578063b121e14714610818578063b148ab6b14610512578063b1dc65a4146108335761031b565b8063aed2e92914610758578063afcb95d71461078f578063b10b673c146107e55761031b565b8063a4c0ed3611610174578063a4c0ed3614610702578063a710b22114610722578063a72aa27e1461073d5761031b565b80638e86139b146106cc578063948108f7146106e75780639fab4386146106b15761031b565b8063572e05e11161025e57806381ff7048116102075780638765ecbe116101e15780638765ecbe146105125780638da5cb5b146106865780638dcf0fe7146106b15761031b565b806381ff7048146105fc5780638456cb591461046857806385c1b0ba146106665761031b565b8063744bfe6111610238578063744bfe611461043257806379ba5097146105e75780637d9b97e0146104685761031b565b8063572e05e1146105325780636709d0e5146105865780636ded9eae146105b95761031b565b80631a2af011116102c0578063421d183b1161029a578063421d183b1461047d57806348013d7b146104f05780635165f2f5146105125761031b565b80631a2af011146104325780633b9cce591461044d5780633f4ba83a146104685761031b565b8063181f5a77116102f1578063181f5a77146103965780631865c57d146103ec578063187256e8146104125761031b565b806306e3b632146103235780630e08ae84146103595761031b565b3661031b57610319610a4b565b005b610319610a4b565b34801561032f57600080fd5b5061034361033e366004614f40565b610a76565b60405161035091906152ef565b60405180910390f35b34801561036557600080fd5b50610379610374366004615082565b610b70565b6040516bffffffffffffffffffffffff9091168152602001610350565b3480156103a257600080fd5b506103df6040518060400160405280601481526020017f4b6565706572526567697374727920322e302e3000000000000000000000000081525081565b604051610350919061539d565b3480156103f857600080fd5b50610401610cb3565b6040516103509594939291906153d7565b34801561041e57600080fd5b5061031961042d366004614a24565b611076565b34801561043e57600080fd5b5061031961042d366004614ecf565b34801561045957600080fd5b5061031961042d366004614b5a565b34801561047457600080fd5b50610319611082565b34801561048957600080fd5b5061049d6104983660046149ce565b61108a565b60408051951515865260ff90941660208601526bffffffffffffffffffffffff9283169385019390935216606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a001610350565b3480156104fc57600080fd5b50610505600281565b60405161035091906153ca565b34801561051e57600080fd5b5061031961052d366004614e9d565b6111a8565b34801561053e57600080fd5b507f00000000000000000000000096d2971f181bf01f7b61f254e0ded20bb1657e7b5b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610350565b34801561059257600080fd5b507f00000000000000000000000099d94f528cea3ee1791ab7b476a1facb4297ca17610561565b3480156105c557600080fd5b506105d96105d4366004614ab2565b6111b3565b604051908152602001610350565b3480156105f357600080fd5b506103196111c8565b34801561060857600080fd5b50610643601254600e5463ffffffff6c0100000000000000000000000083048116937001000000000000000000000000000000009093041691565b6040805163ffffffff948516815293909216602084015290820152606001610350565b34801561067257600080fd5b50610319610681366004614d20565b6112ca565b34801561069257600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff16610561565b3480156106bd57600080fd5b50610319610681366004614ef4565b3480156106d857600080fd5b5061031961042d366004614d77565b3480156106f357600080fd5b5061031961042d36600461505d565b34801561070e57600080fd5b5061031961071d366004614a56565b6112d7565b34801561072e57600080fd5b5061031961042d3660046149eb565b34801561074957600080fd5b5061031961042d366004615038565b34801561076457600080fd5b50610778610773366004614ef4565b6114f2565b604080519215158352602083019190915201610350565b34801561079b57600080fd5b50600e54600f54604080516000815260208101939093527c010000000000000000000000000000000000000000000000000000000090910463ffffffff1690820152606001610350565b3480156107f157600080fd5b507f00000000000000000000000042585ed362b3f1bca95c640fdff35ef899212734610561565b34801561082457600080fd5b5061031961052d3660046149ce565b34801561083f57600080fd5b5061031961084e366004614c69565b61165d565b34801561085f57600080fd5b5061037961086e366004614e9d565b612233565b34801561087f57600080fd5b5061089361088e366004614e9d565b612257565b60405161035091906154e4565b3480156108ac57600080fd5b507f000000000000000000000000779877a7b0d9e8603169ddbd7836e478b4624789610561565b3480156108df57600080fd5b506103196108ee366004614b9c565b612582565b3480156108ff57600080fd5b5061095a61090e3660046149ce565b73ffffffffffffffffffffffffffffffffffffffff1660009081526009602090815260409182902082518084019093525460ff8082161515808552610100909204169290910182905291565b60408051921515835260ff909116602083015201610350565b34801561097f57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610505565b3480156109b257600080fd5b506103196109c13660046149ce565b613353565b3480156109d257600080fd5b506109e66109e1366004614e9d565b613364565b60405161035096959493929190615333565b348015610a0457600080fd5b50610a3e610a133660046149ce565b73ffffffffffffffffffffffffffffffffffffffff1660009081526016602052604090205460ff1690565b60405161035091906153b0565b610a747f00000000000000000000000096d2971f181bf01f7b61f254e0ded20bb1657e7b613387565b565b60606000610a8460026133ab565b9050808410610abf576040517f1390f2a100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82610ad157610ace84826159f1565b92505b60008367ffffffffffffffff811115610aec57610aec615baa565b604051908082528060200260200182016040528015610b15578160200160208202803683370190505b50905060005b84811015610b6757610b38610b308288615872565b6002906133b5565b828281518110610b4a57610b4a615b7b565b602090810291909101015280610b5f81615ab5565b915050610b1b565b50949350505050565b6040805161012081018252600f5460ff808216835263ffffffff6101008084048216602086015265010000000000840482169585019590955262ffffff6901000000000000000000840416606085015261ffff6c0100000000000000000000000084041660808501526e01000000000000000000000000000083048216151560a08501526f010000000000000000000000000000008304909116151560c08401526bffffffffffffffffffffffff70010000000000000000000000000000000083041660e08401527c010000000000000000000000000000000000000000000000000000000090910416918101919091526000908180610c6f836133c8565b6012549193509150610caa90849087907801000000000000000000000000000000000000000000000000900463ffffffff16858560006135c4565b95945050505050565b6040805161014081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810191909152604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081018290526101608101829052610180810191909152604080516101408101825260125468010000000000000000900463ffffffff1681526011546bffffffffffffffffffffffff908116602083015260155492820192909252600f54700100000000000000000000000000000000900490911660608083019190915290819060009060808101610de860026133ab565b815260125463ffffffff6c01000000000000000000000000808304821660208086019190915270010000000000000000000000000000000084048316604080870191909152600e54606080880191909152600f547c0100000000000000000000000000000000000000000000000000000000810486166080808a019190915260ff6e01000000000000000000000000000083048116151560a09a8b015284516101a0810186526101008085048a1682526501000000000085048a1682890152898b168288015262ffffff69010000000000000000008604169582019590955261ffff88850416928101929092526010546bffffffffffffffffffffffff81169a83019a909a526401000000008904881660c0830152740100000000000000000000000000000000000000008904881660e083015278010000000000000000000000000000000000000000000000009098049096169186019190915260135461012086015260145461014086015273ffffffffffffffffffffffffffffffffffffffff96849004871661016086015260115493909304909516610180840152600a8054865181840281018401909752808752969b509299508a958a959394600b9493169291859190830182828015610ff557602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610fca575b505050505092508180548060200260200160405190810160405280929190818152602001828054801561105e57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611033575b50505050509150945094509450945094509091929394565b61107e610a4b565b5050565b610a74610a4b565b73ffffffffffffffffffffffffffffffffffffffff811660009081526008602090815260408083208151608081018352905460ff80821615158352610100820416938201939093526bffffffffffffffffffffffff6201000084048116928201929092526e010000000000000000000000000000909204811660608301819052600f54849384938493849384926111369291700100000000000000000000000000000000900416615a08565b600b549091506000906111499083615909565b90508260000151836020015182856040015161116591906158ce565b6060959095015173ffffffffffffffffffffffffffffffffffffffff9b8c166000908152600c6020526040902054929c919b959a50985093169550919350505050565b6111b0610a4b565b50565b60006111bd610a4b565b979650505050505050565b60015473ffffffffffffffffffffffffffffffffffffffff16331461124e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4d7573742062652070726f706f736564206f776e65720000000000000000000060448201526064015b60405180910390fd5b60008054337fffffffffffffffffffffffff00000000000000000000000000000000000000008083168217845560018054909116905560405173ffffffffffffffffffffffffffffffffffffffff90921692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a350565b6112d2610a4b565b505050565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000779877a7b0d9e8603169ddbd7836e478b46247891614611346576040517fc8bad78d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208114611380576040517fdfe9309000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061138e82840184614e9d565b600081815260046020526040902054909150640100000000900463ffffffff908116146113e7576040517f9c0083a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000818152600460205260409020600101546114229085906c0100000000000000000000000090046bffffffffffffffffffffffff166158ce565b600082815260046020526040902060010180546bffffffffffffffffffffffff929092166c01000000000000000000000000027fffffffffffffffff000000000000000000000000ffffffffffffffffffffffff90921691909117905560155461148d908590615872565b6015556040516bffffffffffffffffffffffff8516815273ffffffffffffffffffffffffffffffffffffffff86169082907fafd24114486da8ebfc32f3626dada8863652e187461aa74d4bfa7348915062039060200160405180910390a35050505050565b6000806114fd61360f565b600f546e010000000000000000000000000000900460ff161561154c576040517f24522f3400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600085815260046020908152604091829020825160e081018452815463ffffffff8082168352640100000000820481168386015268010000000000000000820460ff16151583870152690100000000000000000090910473ffffffffffffffffffffffffffffffffffffffff1660608301526001909201546bffffffffffffffffffffffff80821660808401526c0100000000000000000000000082041660a08301527801000000000000000000000000000000000000000000000000900490911660c08201528251601f87018390048302810183019093528583529161165091839190889088908190840183828082843760009201919091525061364792505050565b9250925050935093915050565b60005a6040805161012081018252600f5460ff808216835261010080830463ffffffff90811660208601526501000000000084048116958501959095526901000000000000000000830462ffffff1660608501526c01000000000000000000000000830461ffff1660808501526e0100000000000000000000000000008304821615801560a08601526f010000000000000000000000000000008404909216151560c085015270010000000000000000000000000000000083046bffffffffffffffffffffffff1660e08501527c01000000000000000000000000000000000000000000000000000000009092049093169082015291925061178b576040517f24522f3400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3360009081526008602052604090205460ff166117d4576040517f1099ed7500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006118158a8a8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506137ad92505050565b9050600081604001515167ffffffffffffffff81111561183757611837615baa565b6040519080825280602002602001820160405280156118eb57816020015b604080516101a081018252600060c0820181815260e083018290526101008301829052610120830182905261014083018290526101608301829052610180830182905282526020808301829052928201819052606082018190526080820181905260a082015282527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092019101816118555790505b5090506000805b836040015151811015611b9757600460008560400151838151811061191957611919615b7b565b6020908102919091018101518252818101929092526040908101600020815160e081018352815463ffffffff8082168352640100000000820481169583019590955268010000000000000000810460ff16151593820193909352690100000000000000000090920473ffffffffffffffffffffffffffffffffffffffff166060830152600101546bffffffffffffffffffffffff80821660808401526c0100000000000000000000000082041660a08301527801000000000000000000000000000000000000000000000000900490911660c08201528351849083908110611a0357611a03615b7b565b602002602001015160000181905250611a6c85848381518110611a2857611a28615b7b565b6020026020010151600001516000015186606001518481518110611a4e57611a4e615b7b565b602002602001015160400151518760000151886020015160016135c4565b838281518110611a7e57611a7e615b7b565b6020026020010151604001906bffffffffffffffffffffffff1690816bffffffffffffffffffffffff1681525050611b2c84604001518281518110611ac557611ac5615b7b565b602002602001015185606001518381518110611ae357611ae3615b7b565b6020026020010151858481518110611afd57611afd615b7b565b602002602001015160000151868581518110611b1b57611b1b615b7b565b602002602001015160400151613859565b838281518110611b3e57611b3e615b7b565b60200260200101516020019015159081151581525050828181518110611b6657611b66615b7b565b60200260200101516020015115611b8557611b8260018361584c565b91505b80611b8f81615ab5565b9150506118f2565b5061ffff8116611bd3576040517ff803a2ca00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e548d3514611c0f576040517fdfdcf8e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8351611c1c9060016158a9565b60ff1689141580611c2d5750888714155b15611c64576040517f0244f71a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611c748d8d8d8d8d8d8d8d61399b565b60005b836040015151811015611e5057828181518110611c9657611c96615b7b565b60200260200101516020015115611e3e574363ffffffff166004600086604001518481518110611cc857611cc8615b7b565b6020026020010151815260200190815260200160002060010160189054906101000a900463ffffffff1663ffffffff161415611d30576040517fb55ac75400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611d78838281518110611d4557611d45615b7b565b60200260200101516000015185606001518381518110611d6757611d67615b7b565b602002602001015160400151613647565b848381518110611d8a57611d8a615b7b565b6020026020010151606001858481518110611da757611da7615b7b565b60200260200101516080018281525082151515158152505050828181518110611dd257611dd2615b7b565b60200260200101516080015186611de991906159f1565b9550436004600086604001518481518110611e0657611e06615b7b565b6020026020010151815260200190815260200160002060010160186101000a81548163ffffffff021916908363ffffffff1602179055505b80611e4881615ab5565b915050611c77565b508351611e5e9060016158a9565b611e6d9060ff1661044c615934565b616914611e7b8d6010615934565b5a611e8690896159f1565b611e909190615872565b611e9a9190615872565b611ea49190615872565b94506116a8611eb761ffff8316876158f5565b611ec19190615872565b945060008060008060005b8760400151518110156120cc57868181518110611eeb57611eeb615b7b565b602002602001015160200151156120ba57611f2d8a89606001518381518110611f1657611f16615b7b565b602002602001015160400151518b60000151613c04565b878281518110611f3f57611f3f615b7b565b602002602001015160a0018181525050611f9b8989604001518381518110611f6957611f69615b7b565b6020026020010151898481518110611f8357611f83615b7b565b60200260200101518b600001518c602001518b613c22565b9093509150611faa82856158ce565b9350611fb683866158ce565b9450868181518110611fca57611fca615b7b565b602002602001015160600151151588604001518281518110611fee57611fee615b7b565b60200260200101517f29233ba1d7b302b8fe230ad0b81423aba5371b2a6f6b821228212385ee6a44208a60600151848151811061202d5761202d615b7b565b6020026020010151600001518a858151811061204b5761204b615b7b565b6020026020010151608001518b868151811061206957612069615b7b565b602002602001015160a00151878961208191906158ce565b6040805163ffffffff90951685526020850193909352918301526bffffffffffffffffffffffff16606082015260800160405180910390a35b806120c481615ab5565b915050611ecc565b505033600090815260086020526040902080548492506002906121049084906201000090046bffffffffffffffffffffffff166158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555080600f60000160108282829054906101000a90046bffffffffffffffffffffffff1661215e91906158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555060008f6001600381106121a1576121a1615b7b565b602002013560001c9050600060088264ffffffffff16901c905087610100015163ffffffff168163ffffffff16111561222057600f80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff8416021790555b5050505050505050505050505050505050565b6000818152600460205260408120546122519063ffffffff16610b70565b92915050565b604080516101408101825260008082526020820181905260609282018390528282018190526080820181905260a0820181905260c0820181905260e082018190526101008201526101208101919091526000828152600460209081526040808320815160e081018352815463ffffffff8082168352640100000000820481168387015268010000000000000000820460ff16151583860152690100000000000000000090910473ffffffffffffffffffffffffffffffffffffffff908116606084019081526001909401546bffffffffffffffffffffffff80821660808601526c0100000000000000000000000082041660a085015278010000000000000000000000000000000000000000000000009004821660c08401528451610140810186529351168352815116828501528685526007909352928190208054929392918301916123a390615a61565b80601f01602080910402602001604051908101604052809291908181526020018280546123cf90615a61565b801561241c5780601f106123f15761010080835404028352916020019161241c565b820191906000526020600020905b8154815290600101906020018083116123ff57829003601f168201915b505050505081526020018260a001516bffffffffffffffffffffffff1681526020016005600086815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001826020015163ffffffff1667ffffffffffffffff1681526020018260c0015163ffffffff16815260200182608001516bffffffffffffffffffffffff1681526020018260400151151581526020016017600086815260200190815260200160002080546124f990615a61565b80601f016020809104026020016040519081016040528092919081815260200182805461252590615a61565b80156125725780601f1061254757610100808354040283529160200191612572565b820191906000526020600020905b81548152906001019060200180831161255557829003601f168201915b5050505050815250915050919050565b61258a613d15565b601f865111156125c6576040517f25d0209c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60ff8416612600576040517fe77dba5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8451865114158061261f575061261784600361599d565b60ff16865111155b15612656576040517f1d2d1c5800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f54600b547001000000000000000000000000000000009091046bffffffffffffffffffffffff169060005b816bffffffffffffffffffffffff168110156126eb576126d8600b82815481106126af576126af615b7b565b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff168484613d96565b50806126e381615ab5565b915050612683565b5060008060005b836bffffffffffffffffffffffff168110156127f457600a818154811061271b5761271b615b7b565b600091825260209091200154600b805473ffffffffffffffffffffffffffffffffffffffff9092169450908290811061275657612756615b7b565b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff868116845260098352604080852080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001690559116808452600890925290912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690559150806127ec81615ab5565b9150506126f2565b50612801600a60006145f5565b61280d600b60006145f5565b604080516080810182526000808252602082018190529181018290526060810182905290805b8c51811015612b9157600960008e838151811061285257612852615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff1682528101919091526040016000205460ff16156128bd576040517f77cea0fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180604001604052806001151581526020018260ff16815250600960008f84815181106128ee576128ee615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff1682528181019290925260400160002082518154939092015160ff16610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff921515929092167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000909316929092171790558b518c908290811061299657612996615b7b565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff81166000908152600883526040908190208151608081018352905460ff80821615801584526101008304909116958301959095526bffffffffffffffffffffffff6201000082048116938301939093526e0100000000000000000000000000009004909116606082015294509250612a5b576040517f6a7281ad00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001835260ff80821660208086019182526bffffffffffffffffffffffff808b166060880190815273ffffffffffffffffffffffffffffffffffffffff871660009081526008909352604092839020885181549551948a0151925184166e010000000000000000000000000000027fffffffffffff000000000000000000000000ffffffffffffffffffffffffffff939094166201000002929092167fffffffffffff000000000000000000000000000000000000000000000000ffff94909616610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff921515929092167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00009095169490941717919091169290921791909117905580612b8981615ab5565b915050612833565b50508a51612ba79150600a9060208d0190614613565b508851612bbb90600b9060208c0190614613565b50600087806020019051810190612bd29190614dad565b60125460c082015191925063ffffffff640100000000909104811691161015612c27576040517f39abc10400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60125460e082015163ffffffff74010000000000000000000000000000000000000000909204821691161015612c89576040517f1fa9bdcb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60125461010082015163ffffffff7801000000000000000000000000000000000000000000000000909204821691161015612cf0576040517fd1d5faa800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040518061012001604052808a60ff168152602001826000015163ffffffff168152602001826020015163ffffffff168152602001826060015162ffffff168152602001826080015161ffff168152602001600015158152602001600015158152602001866bffffffffffffffffffffffff168152602001600063ffffffff16815250600f60008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160056101000a81548163ffffffff021916908363ffffffff16021790555060608201518160000160096101000a81548162ffffff021916908362ffffff160217905550608082015181600001600c6101000a81548161ffff021916908361ffff16021790555060a082015181600001600e6101000a81548160ff02191690831515021790555060c082015181600001600f6101000a81548160ff02191690831515021790555060e08201518160000160106101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555061010082015181600001601c6101000a81548163ffffffff021916908363ffffffff1602179055509050506040518061016001604052808260a001516bffffffffffffffffffffffff16815260200182610160015173ffffffffffffffffffffffffffffffffffffffff168152602001601060010160009054906101000a90046bffffffffffffffffffffffff166bffffffffffffffffffffffff16815260200182610180015173ffffffffffffffffffffffffffffffffffffffff168152602001826040015163ffffffff1681526020018260c0015163ffffffff168152602001601060020160089054906101000a900463ffffffff1663ffffffff1681526020016010600201600c9054906101000a900463ffffffff1663ffffffff168152602001601060020160109054906101000a900463ffffffff1663ffffffff1681526020018260e0015163ffffffff16815260200182610100015163ffffffff16815250601060008201518160000160006101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff160217905550602082015181600001600c6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160010160006101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff160217905550606082015181600101600c6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060808201518160020160006101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160020160046101000a81548163ffffffff021916908363ffffffff16021790555060c08201518160020160086101000a81548163ffffffff021916908363ffffffff16021790555060e082015181600201600c6101000a81548163ffffffff021916908363ffffffff1602179055506101008201518160020160106101000a81548163ffffffff021916908363ffffffff1602179055506101208201518160020160146101000a81548163ffffffff021916908363ffffffff1602179055506101408201518160020160186101000a81548163ffffffff021916908363ffffffff1602179055509050508061012001516013819055508061014001516014819055506000601060020160109054906101000a900463ffffffff16905043601060020160106101000a81548163ffffffff021916908363ffffffff16021790555060016010600201600c8282829054906101000a900463ffffffff16613297919061588a565b92506101000a81548163ffffffff021916908363ffffffff1602179055506132e146306010600201600c9054906101000a900463ffffffff1663ffffffff168f8f8f8f8f8f613fbd565b600e819055507f1591690b8638f5fb2dbec82ac741805ac5da8b45dc5263f4875b0496fdce4e0581600e546010600201600c9054906101000a900463ffffffff168f8f8f8f8f8f60405161333d999897969594939291906156c0565b60405180910390a1505050505050505050505050565b61335b613d15565b6111b081614067565b6000606060008060008061337661360f565b61337e610a4b565b91939550919395565b3660008037600080366000845af43d6000803e8080156133a6573d6000f35b3d6000fd5b6000612251825490565b60006133c1838361415d565b9392505050565b6000806000836060015162ffffff1690506000808263ffffffff161190506000807f00000000000000000000000099d94f528cea3ee1791ab7b476a1facb4297ca1773ffffffffffffffffffffffffffffffffffffffff1663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561344f57600080fd5b505afa158015613463573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613487919061509f565b509450909250505060008113158061349e57508142105b806134bf57508280156134bf57506134b682426159f1565b8463ffffffff16105b156134ce5760135495506134d2565b8095505b7f00000000000000000000000042585ed362b3f1bca95c640fdff35ef89921273473ffffffffffffffffffffffffffffffffffffffff1663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561353857600080fd5b505afa15801561354c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613570919061509f565b509450909250505060008113158061358757508142105b806135a857508280156135a8575061359f82426159f1565b8463ffffffff16105b156135b75760145494506135bb565b8094505b50505050915091565b6000806135d5868960000151614187565b90506000806135f08a8a63ffffffff16858a8a60018b6141ca565b90925090506135ff81836158ce565b93505050505b9695505050505050565b3215610a74576040517fb60ac5db00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f5460009081906f01000000000000000000000000000000900460ff161561369c576040517f37ed32e800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600f80547fffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffff166f010000000000000000000000000000001790555a90506000634585e33b60e01b846040516024016136f4919061539d565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905061376c856000015163ffffffff168660600151836145a9565b92505a61377990836159f1565b915050600f80547fffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffff16905590939092509050565b6137d86040518060800160405280600081526020016000815260200160608152602001606081525090565b600080600080858060200190518101906137f29190614f62565b93509350935093508051825114613835576040517fb55ac75400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60408051608081018252948552602085019390935291830152606082015292915050565b60008260c0015163ffffffff16846000015163ffffffff1610156138aa5760405185907f5aa44821f7938098502bff537fbbdc9aaaa2fa655c10740646fce27e54987a8990600090a2506000613993565b6020840151845163ffffffff1640146138f05760405185907f561ff77e59394941a01a456497a9418dea82e2a39abb3ecebfb1cef7e0bfdc1390600090a2506000613993565b43836020015163ffffffff16116139345760405185907fd84831b6a3a7fbd333f42fe7f9104a139da6cca4cc1507aef4ddad79b31d017f90600090a2506000613993565b816bffffffffffffffffffffffff168360a001516bffffffffffffffffffffffff16101561398f5760405185907f7895fdfe292beab0842d5beccd078e85296b9e17a30eaee4c261a2696b84eb9690600090a2506000613993565b5060015b949350505050565b600087876040516139ad9291906152b8565b6040519081900381206139c4918b90602001615383565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815282825280516020918201208383019092526000808452908301819052909250906000805b88811015613b9b57600185878360208110613a3057613a30615b7b565b613a3d91901a601b6158a9565b8c8c85818110613a4f57613a4f615b7b565b905060200201358b8b86818110613a6857613a68615b7b565b9050602002013560405160008152602001604052604051613aa5949392919093845260ff9290921660208401526040830152606082015260800190565b6020604051602081039080840390855afa158015613ac7573d6000803e3d6000fd5b5050604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081015173ffffffffffffffffffffffffffffffffffffffff811660009081526009602090815290849020838501909452925460ff8082161515808552610100909204169383019390935290955093509050613b75576040517f0f4c073700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826020015160080260ff166001901b840193508080613b9390615ab5565b915050613a13565b50827e01010101010101010101010101010101010101010101010101010101010101841614613bf6576040517fc103be2e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050505050505050565b6000613c108383614187565b9050808410156133c157509192915050565b600080613c3d8887608001518860a0015188888860016141ca565b90925090506000613c4e82846158ce565b600089815260046020526040902060010180549192508291600c90613c929084906c0100000000000000000000000090046bffffffffffffffffffffffff16615a08565b82546101009290920a6bffffffffffffffffffffffff81810219909316918316021790915560008a815260046020526040812060010180548594509092613cdb918591166158ce565b92506101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff16021790555050965096945050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610a74576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f6e6c792063616c6c61626c65206279206f776e6572000000000000000000006044820152606401611245565b73ffffffffffffffffffffffffffffffffffffffff831660009081526008602090815260408083208151608081018352905460ff80821615158352610100820416938201939093526bffffffffffffffffffffffff6201000084048116928201929092526e01000000000000000000000000000090920416606082018190528290613e219086615a08565b90506000613e2f8583615909565b90508083604001818151613e4391906158ce565b6bffffffffffffffffffffffff9081169091528716606085015250613e6885826159c6565b613e729083615a08565b60118054600090613e929084906bffffffffffffffffffffffff166158ce565b825461010092830a6bffffffffffffffffffffffff81810219909216928216029190911790925573ffffffffffffffffffffffffffffffffffffffff999099166000908152600860209081526040918290208751815492890151938901516060909901517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00009093169015157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff161760ff909316909b02919091177fffffffffffff000000000000000000000000000000000000000000000000ffff1662010000878416027fffffffffffff000000000000000000000000ffffffffffffffffffffffffffff16176e010000000000000000000000000000919092160217909755509095945050505050565b6000808a8a8a8a8a8a8a8a8a604051602001613fe19998979695949392919061561b565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001815291905280516020909101207dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167e01000000000000000000000000000000000000000000000000000000000000179b9a5050505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff81163314156140e7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f43616e6e6f74207472616e7366657220746f2073656c660000000000000000006044820152606401611245565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83811691821790925560008054604051929316917fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae12789190a350565b600082600001828154811061417457614174615b7b565b9060005260206000200154905092915050565b600061419a63ffffffff84166014615934565b6141a58360016158a9565b6141b49060ff16611d4c615934565b6141c09061fde8615872565b6133c19190615872565b6000806000896080015161ffff16876141e39190615934565b90508380156141f15750803a105b156141f957503a5b600060027f0000000000000000000000000000000000000000000000000000000000000000600281111561422f5761422f615b4c565b14156143b257604080516000815260208101909152851561428e57600036604051806080016040528060488152602001615c3860489139604051602001614278939291906152c8565b604051602081830303815290604052905061430a565b6012546142be907801000000000000000000000000000000000000000000000000900463ffffffff166004615971565b63ffffffff1667ffffffffffffffff8111156142dc576142dc615baa565b6040519080825280601f01601f191660200182016040528015614306576020820181803683370190505b5090505b6040517f49948e0e00000000000000000000000000000000000000000000000000000000815273420000000000000000000000000000000000000f906349948e0e9061435a90849060040161539d565b60206040518083038186803b15801561437257600080fd5b505afa158015614386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143aa9190614eb6565b91505061446e565b60017f000000000000000000000000000000000000000000000000000000000000000060028111156143e6576143e6615b4c565b141561446e57606c73ffffffffffffffffffffffffffffffffffffffff1663c6f7de0e6040518163ffffffff1660e01b815260040160206040518083038186803b15801561443357600080fd5b505afa158015614447573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061446b9190614eb6565b90505b8461448a57808b6080015161ffff166144879190615934565b90505b61449861ffff8716826158f5565b9050600087826144a88c8e615872565b6144b29086615934565b6144bc9190615872565b6144ce90670de0b6b3a7640000615934565b6144d891906158f5565b905060008c6040015163ffffffff1664e8d4a510006144f79190615934565b898e6020015163ffffffff16858f886145109190615934565b61451a9190615872565b61452890633b9aca00615934565b6145329190615934565b61453c91906158f5565b6145469190615872565b90506b033b2e3c9fd0803ce800000061455f8284615872565b1115614597576040517f2ad7547a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b909c909b509950505050505050505050565b60005a6113888110156145bb57600080fd5b6113888103905084604082048203116145d357600080fd5b50823b6145df57600080fd5b60008083516020850160008789f1949350505050565b50805460008255906000526020600020908101906111b0919061469d565b82805482825590600052602060002090810192821561468d579160200282015b8281111561468d57825182547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff909116178255602090920191600190910190614633565b5061469992915061469d565b5090565b5b80821115614699576000815560010161469e565b80516146bd81615be9565b919050565b60008083601f8401126146d457600080fd5b50813567ffffffffffffffff8111156146ec57600080fd5b6020830191508360208260051b850101111561470757600080fd5b9250929050565b600082601f83011261471f57600080fd5b8135602061473461472f836157e2565b615793565b80838252828201915082860187848660051b890101111561475457600080fd5b60005b8581101561477c57813561476a81615be9565b84529284019290840190600101614757565b5090979650505050505050565b600082601f83011261479a57600080fd5b815160206147aa61472f836157e2565b80838252828201915082860187848660051b89010111156147ca57600080fd5b60005b8581101561477c57815167ffffffffffffffff808211156147ed57600080fd5b818a0191506060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0848e0301121561482557600080fd5b61482d615746565b8884015161483a81615c0b565b81526040848101518a83015291840151918383111561485857600080fd5b82850194508d603f86011261486c57600080fd5b89850151935061487e61472f85615806565b92508383528d8185870101111561489457600080fd5b6148a3848b8501838801615a35565b8101919091528652505092840192908401906001016147cd565b60008083601f8401126148cf57600080fd5b50813567ffffffffffffffff8111156148e757600080fd5b60208301915083602082850101111561470757600080fd5b600082601f83011261491057600080fd5b813561491e61472f82615806565b81815284602083860101111561493357600080fd5b816020850160208301376000918101602001919091529392505050565b805161ffff811681146146bd57600080fd5b805162ffffff811681146146bd57600080fd5b80516146bd81615c0b565b803567ffffffffffffffff811681146146bd57600080fd5b803560ff811681146146bd57600080fd5b805169ffffffffffffffffffff811681146146bd57600080fd5b80516146bd81615c1d565b6000602082840312156149e057600080fd5b81356133c181615be9565b600080604083850312156149fe57600080fd5b8235614a0981615be9565b91506020830135614a1981615be9565b809150509250929050565b60008060408385031215614a3757600080fd5b8235614a4281615be9565b9150602083013560048110614a1957600080fd5b60008060008060608587031215614a6c57600080fd5b8435614a7781615be9565b935060208501359250604085013567ffffffffffffffff811115614a9a57600080fd5b614aa6878288016148bd565b95989497509550505050565b600080600080600080600060a0888a031215614acd57600080fd5b8735614ad881615be9565b96506020880135614ae881615c0b565b95506040880135614af881615be9565b9450606088013567ffffffffffffffff80821115614b1557600080fd5b614b218b838c016148bd565b909650945060808a0135915080821115614b3a57600080fd5b50614b478a828b016148bd565b989b979a50959850939692959293505050565b60008060208385031215614b6d57600080fd5b823567ffffffffffffffff811115614b8457600080fd5b614b90858286016146c2565b90969095509350505050565b60008060008060008060c08789031215614bb557600080fd5b863567ffffffffffffffff80821115614bcd57600080fd5b614bd98a838b0161470e565b97506020890135915080821115614bef57600080fd5b614bfb8a838b0161470e565b9650614c0960408a01614998565b95506060890135915080821115614c1f57600080fd5b614c2b8a838b016148ff565b9450614c3960808a01614980565b935060a0890135915080821115614c4f57600080fd5b50614c5c89828a016148ff565b9150509295509295509295565b60008060008060008060008060e0898b031215614c8557600080fd5b606089018a811115614c9657600080fd5b8998503567ffffffffffffffff80821115614cb057600080fd5b614cbc8c838d016148bd565b909950975060808b0135915080821115614cd557600080fd5b614ce18c838d016146c2565b909750955060a08b0135915080821115614cfa57600080fd5b50614d078b828c016146c2565b999c989b50969995989497949560c00135949350505050565b600080600060408486031215614d3557600080fd5b833567ffffffffffffffff811115614d4c57600080fd5b614d58868287016146c2565b9094509250506020840135614d6c81615be9565b809150509250925092565b60008060208385031215614d8a57600080fd5b823567ffffffffffffffff811115614da157600080fd5b614b90858286016148bd565b60006101a08284031215614dc057600080fd5b614dc861576f565b614dd183614975565b8152614ddf60208401614975565b6020820152614df060408401614975565b6040820152614e0160608401614962565b6060820152614e1260808401614950565b6080820152614e2360a084016149c3565b60a0820152614e3460c08401614975565b60c0820152614e4560e08401614975565b60e0820152610100614e58818501614975565b9082015261012083810151908201526101408084015190820152610160614e808185016146b2565b90820152610180614e928482016146b2565b908201529392505050565b600060208284031215614eaf57600080fd5b5035919050565b600060208284031215614ec857600080fd5b5051919050565b60008060408385031215614ee257600080fd5b823591506020830135614a1981615be9565b600080600060408486031215614f0957600080fd5b83359250602084013567ffffffffffffffff811115614f2757600080fd5b614f33868287016148bd565b9497909650939450505050565b60008060408385031215614f5357600080fd5b50508035926020909101359150565b60008060008060808587031215614f7857600080fd5b845193506020808601519350604086015167ffffffffffffffff80821115614f9f57600080fd5b818801915088601f830112614fb357600080fd5b8151614fc161472f826157e2565b8082825285820191508585018c878560051b8801011115614fe157600080fd5b600095505b83861015615004578051835260019590950194918601918601614fe6565b5060608b0151909750945050508083111561501e57600080fd5b505061502c87828801614789565b91505092959194509250565b6000806040838503121561504b57600080fd5b823591506020830135614a1981615c0b565b6000806040838503121561507057600080fd5b823591506020830135614a1981615c1d565b60006020828403121561509457600080fd5b81356133c181615c0b565b600080600080600060a086880312156150b757600080fd5b6150c0866149a9565b94506020860151935060408601519250606086015191506150e3608087016149a9565b90509295509295909350565b600081518084526020808501945080840160005b8381101561513557815173ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101615103565b509495945050505050565b60008151808452615158816020860160208601615a35565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b805163ffffffff16825260208101516151ab602084018263ffffffff169052565b5060408101516151c3604084018263ffffffff169052565b5060608101516151da606084018262ffffff169052565b5060808101516151f0608084018261ffff169052565b5060a081015161521060a08401826bffffffffffffffffffffffff169052565b5060c081015161522860c084018263ffffffff169052565b5060e081015161524060e084018263ffffffff169052565b506101008181015163ffffffff8116848301525050610120818101519083015261014080820151908301526101608082015173ffffffffffffffffffffffffffffffffffffffff81168285015250506101808181015173ffffffffffffffffffffffffffffffffffffffff8116848301525b50505050565b8183823760009101908152919050565b8284823760008382016000815283516152e5818360208801615a35565b0195945050505050565b6020808252825182820181905260009190848201906040850190845b818110156153275783518352928401929184019160010161530b565b50909695505050505050565b861515815260c06020820152600061534e60c0830188615140565b90506007861061536057615360615b4c565b8560408301528460608301528360808301528260a0830152979650505050505050565b828152608081016060836020840137600081529392505050565b6020815260006133c16020830184615140565b60208101600483106153c4576153c4615b4c565b91905290565b602081016153c483615bd9565b855163ffffffff1681526000610340602088015161540560208501826bffffffffffffffffffffffff169052565b5060408801516040840152606088015161542f60608501826bffffffffffffffffffffffff169052565b506080880151608084015260a088015161545160a085018263ffffffff169052565b5060c088015161546960c085018263ffffffff169052565b5060e088015160e08401526101008089015161548c8286018263ffffffff169052565b5050610120888101511515908401526154a961014084018861518a565b806102e08401526154bc818401876150ef565b90508281036103008401526154d181866150ef565b91505061360561032083018460ff169052565b6020815261550b60208201835173ffffffffffffffffffffffffffffffffffffffff169052565b60006020830151615524604084018263ffffffff169052565b506040830151610140806060850152615541610160850183615140565b9150606085015161556260808601826bffffffffffffffffffffffff169052565b50608085015173ffffffffffffffffffffffffffffffffffffffff811660a08601525060a085015167ffffffffffffffff811660c08601525060c085015163ffffffff811660e08601525060e08501516101006155ce818701836bffffffffffffffffffffffff169052565b86015190506101206155e38682018315159052565b8601518584037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0018387015290506136058382615140565b60006101208b835273ffffffffffffffffffffffffffffffffffffffff8b16602084015267ffffffffffffffff808b1660408501528160608501526156628285018b6150ef565b91508382036080850152615676828a6150ef565b915060ff881660a085015283820360c08501526156938288615140565b90861660e085015283810361010085015290506156b08185615140565b9c9b505050505050505050505050565b600061012063ffffffff808d1684528b6020850152808b166040850152508060608401526156f08184018a6150ef565b9050828103608084015261570481896150ef565b905060ff871660a084015282810360c08401526157218187615140565b905067ffffffffffffffff851660e08401528281036101008401526156b08185615140565b6040516060810167ffffffffffffffff8111828210171561576957615769615baa565b60405290565b6040516101a0810167ffffffffffffffff8111828210171561576957615769615baa565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156157da576157da615baa565b604052919050565b600067ffffffffffffffff8211156157fc576157fc615baa565b5060051b60200190565b600067ffffffffffffffff82111561582057615820615baa565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600061ffff80831681851680830382111561586957615869615aee565b01949350505050565b6000821982111561588557615885615aee565b500190565b600063ffffffff80831681851680830382111561586957615869615aee565b600060ff821660ff84168060ff038211156158c6576158c6615aee565b019392505050565b60006bffffffffffffffffffffffff80831681851680830382111561586957615869615aee565b60008261590457615904615b1d565b500490565b60006bffffffffffffffffffffffff8084168061592857615928615b1d565b92169190910492915050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561596c5761596c615aee565b500290565b600063ffffffff8083168185168183048111821515161561599457615994615aee565b02949350505050565b600060ff821660ff84168160ff04811182151516156159be576159be615aee565b029392505050565b60006bffffffffffffffffffffffff8083168185168183048111821515161561599457615994615aee565b600082821015615a0357615a03615aee565b500390565b60006bffffffffffffffffffffffff83811690831681811015615a2d57615a2d615aee565b039392505050565b60005b83811015615a50578181015183820152602001615a38565b838111156152b25750506000910152565b600181811c90821680615a7557607f821691505b60208210811415615aaf577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415615ae757615ae7615aee565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600381106111b0576111b0615b4c565b73ffffffffffffffffffffffffffffffffffffffff811681146111b057600080fd5b63ffffffff811681146111b057600080fd5b6bffffffffffffffffffffffff811681146111b057600080fdfe307866666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666a164736f6c6343000806000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000096d2971f181bf01f7b61f254e0ded20bb1657e7b
-----Decoded View---------------
Arg [0] : keeperRegistryLogic (address): 0x96d2971f181BF01F7b61f254e0DeD20BB1657e7b
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000096d2971f181bf01f7b61f254e0ded20bb1657e7b
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.