Address Contract Verified
Address
0x2Ea4aDE144485895B923466B4521F5ebC03a0AeF
Balance
0 ETH
Nonce
1
Code Size
3100 bytes
Creator
0xfaAD873a...b2eA at tx 0x6161faaf...03574f
Indexed Transactions
0
Contract Bytecode
3100 bytes
0x608060405234801561001057600080fd5b50600436106100935760003560e01c806342cde4e81161006657806342cde4e81461013f5780634e8b1dd5146101745780635c1bba381461019b5780638dce54b7146101c2578063d2ec5fca146101e357600080fd5b80631d2ab000146100985780633414d32a146100ad57806336569e77146100f1578063365a86fc14610118575b600080fd5b6100ab6100a63660046108e0565b610203565b005b6100d47f0000000000000000000000005a464c28d19848f44199d003bef5ecc87d090f8781565b6040516001600160a01b0390911681526020015b60405180910390f35b6100d47f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b81565b6100d47f00000000000000000000000012f36cdea3a28c35ac8c6cc71d9265c17c74a27f81565b6101667f00000000000000000000000000000000000000000000000000000000000001f481565b6040519081526020016100e8565b6101667f000000000000000000000000000000000000000000000000000000000000025881565b6100d47f000000000000000000000000238b4e35daed6100c6162fae4510261f88996ec981565b6101d56101d036600461095c565b6105d7565b6040516100e89291906109c2565b6101666101f136600461095c565b60006020819052908152604090205481565b604051637c530f1360e01b8152600481018490527f000000000000000000000000238b4e35daed6100c6162fae4510261f88996ec96001600160a01b031690637c530f1390602401602060405180830381865afa158015610268573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061028c91906109e5565b6102b157604051636ac204fb60e11b8152600481018490526024015b60405180910390fd5b60006102bf8284018461095c565b600081815260208190526040902054909150428111156102fc57604051630f0c87f560e21b815260048101839052602481018290526044016102a8565b6040516236f48960e71b8152600481018390526000907f00000000000000000000000012f36cdea3a28c35ac8c6cc71d9265c17c74a27f6001600160a01b031690631b7a448090602401602060405180830381865afa158015610363573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103879190610a0e565b6040516309092f9760e21b8152600481018590526001600160a01b0380831660248301529192506000917f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b1690632424be5c906044016040805180830381865afa1580156103f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041d9190610a37565b60405163b5e98b3b60e01b8152600481018790529092507f00000000000000000000000012f36cdea3a28c35ac8c6cc71d9265c17c74a27f6001600160a01b0316915063b5e98b3b90602401600060405180830381600087803b15801561048357600080fd5b505af1158015610497573d6000803e3d6000fd5b50506040516309092f9760e21b8152600481018790526001600160a01b038581166024830152600093507f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b169150632424be5c906044016040805180830381865afa15801561050a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052e9190610a37565b91505061053b828261081b565b61056957604051632b0f392f60e11b81526004810186905260248101839052604481018290526064016102a8565b6105937f000000000000000000000000000000000000000000000000000000000000025842610a71565b60008681526020819052604080822092909255905189917f35397c1b811675273db66fd6835f814cb03d51d1595e9234d1646329e1d7e57b91a25050505050505050565b604051637c530f1360e01b8152600481018290526000906060906001600160a01b037f000000000000000000000000238b4e35daed6100c6162fae4510261f88996ec91690637c530f1390602401602060405180830381865afa158015610642573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061066691906109e5565b6106a05750506040805180820190915260158152742732ba3bb7b9359034b9903737ba1036b0b9ba32b960591b6020820152600092909150565b60007f0000000000000000000000005a464c28d19848f44199d003bef5ecc87d090f876001600160a01b0316630f560cd76040518163ffffffff1660e01b8152600401600060405180830381865afa158015610700573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526107289190810190610a9f565b905060005b81518110156107e857600082828151811061074a5761074a610b5d565b602002602001015160405160200161076491815260200190565b60408051601f19818403018152908290526201d2ab60ec1b825291503090631d2ab000906107989089908590600401610b73565b600060405180830381600087803b1580156107b257600080fd5b505af19250505080156107c3575060015b156107d5576001969095509350505050565b50806107e081610b8c565b91505061072d565b5060006040518060400160405280600d81526020016c4e6f20696c6b7320726561647960981b8152509250925050915091565b60008215801561082a57508115155b15610837575060016108da565b8215801590610844575081155b15610851575060016108da565b8215801561085d575081155b1561086a575060006108da565b60008361087961271085610ba5565b6108839190610bc4565b90506127108110156108a9578061089c61271080610ba5565b6108a69190610bc4565b90505b6108d57f00000000000000000000000000000000000000000000000000000000000001f4612710610a71565b111590505b92915050565b6000806000604084860312156108f557600080fd5b83359250602084013567ffffffffffffffff8082111561091457600080fd5b818601915086601f83011261092857600080fd5b81358181111561093757600080fd5b87602082850101111561094957600080fd5b6020830194508093505050509250925092565b60006020828403121561096e57600080fd5b5035919050565b6000815180845260005b8181101561099b5760208185018101518683018201520161097f565b818111156109ad576000602083870101525b50601f01601f19169290920160200192915050565b82151581526040602082015260006109dd6040830184610975565b949350505050565b6000602082840312156109f757600080fd5b81518015158114610a0757600080fd5b9392505050565b600060208284031215610a2057600080fd5b81516001600160a01b0381168114610a0757600080fd5b60008060408385031215610a4a57600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b60008219821115610a8457610a84610a5b565b500190565b634e487b7160e01b600052604160045260246000fd5b60006020808385031215610ab257600080fd5b825167ffffffffffffffff80821115610aca57600080fd5b818501915085601f830112610ade57600080fd5b815181811115610af057610af0610a89565b8060051b604051601f19603f83011681018181108582111715610b1557610b15610a89565b604052918252848201925083810185019188831115610b3357600080fd5b938501935b82851015610b5157845184529385019392850192610b38565b98975050505050505050565b634e487b7160e01b600052603260045260246000fd5b8281526040602082015260006109dd6040830184610975565b600060018201610b9e57610b9e610a5b565b5060010190565b6000816000190483118215151615610bbf57610bbf610a5b565b500290565b600082610be157634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220dfd8b772a844971a9d6b7fed6d16a523e617c149d9ef7cd50f723b6eef3cb8c064736f6c634300080d0033
Verified Source Code Full Match
Compiler: v0.8.13+commit.abaa5c0e
EVM: london
Optimization: Yes (200 runs)
D3MJob.sol 117 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity 0.8.13;
import {IJob} from "./interfaces/IJob.sol";
interface SequencerLike {
function isMaster(bytes32 network) external view returns (bool);
}
interface IlkRegistryLike {
function list() external view returns (bytes32[] memory);
}
interface VatLike {
function urns(bytes32, address) external view returns (uint256, uint256);
}
interface D3MHubLike {
function vat() external view returns (VatLike);
function pool(bytes32) external view returns (address);
function exec(bytes32) external;
}
/// @title Trigger D3M updates based on threshold
contract D3MJob is IJob {
uint256 constant internal BPS = 10 ** 4;
SequencerLike public immutable sequencer;
IlkRegistryLike public immutable ilkRegistry;
D3MHubLike public immutable hub;
VatLike public immutable vat;
uint256 public immutable threshold; // Threshold deviation to kick off exec [BPS]
uint256 public immutable ttl; // Cooldown before you can call exec again [seconds]
mapping (bytes32 => uint256) public expiry; // Timestamp of when exec is allowed again
// --- Errors ---
error NotMaster(bytes32 network);
error Cooldown(bytes32 ilk, uint256 expiry);
error ShouldNotTrigger(bytes32 ilk, uint256 part, uint256 nart);
// --- Events ---
event Work(bytes32 indexed network);
constructor(address _sequencer, address _ilkRegistry, address _hub, uint256 _threshold, uint256 _ttl) {
sequencer = SequencerLike(_sequencer);
ilkRegistry = IlkRegistryLike(_ilkRegistry);
hub = D3MHubLike(_hub);
vat = hub.vat();
threshold = _threshold;
ttl = _ttl;
}
function shouldTrigger(uint256 part, uint256 nart) internal view returns (bool) {
if (part == 0 && nart != 0) return true; // From zero to non-zero
if (part != 0 && nart == 0) return true; // From non-zero to zero
if (part == 0 && nart == 0) return false; // No change at zero
// Check if the delta is above the threshold
uint256 delta = nart * BPS / part;
if (delta < BPS) delta = BPS * BPS / delta; // Flip decreases to increase
return delta >= (BPS + threshold);
}
function work(bytes32 network, bytes calldata args) external override {
if (!sequencer.isMaster(network)) revert NotMaster(network);
bytes32 ilk = abi.decode(args, (bytes32));
uint256 _expiry = expiry[ilk];
if (block.timestamp < _expiry) revert Cooldown(ilk, _expiry);
address pool = hub.pool(ilk);
(, uint256 part) = vat.urns(ilk, pool);
hub.exec(ilk);
(, uint256 nart) = vat.urns(ilk, pool);
if (!shouldTrigger(part, nart)) revert ShouldNotTrigger(ilk, part, nart);
expiry[ilk] = block.timestamp + ttl;
emit Work(network);
}
function workable(bytes32 network) external override returns (bool, bytes memory) {
if (!sequencer.isMaster(network)) return (false, bytes("Network is not master"));
bytes32[] memory ilks = ilkRegistry.list();
for (uint256 i = 0; i < ilks.length; i++) {
bytes memory args = abi.encode(ilks[i]);
try this.work(network, args) {
// Found a valid execution
return (true, args);
} catch {
// For some reason this errored -- carry on
}
}
return (false, bytes("No ilks ready"));
}
}
IJob.sol 36 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity >=0.8.0;
/// @title Maker Keeper Network Job
/// @notice A job represents an independant unit of work that can be done by a keeper
interface IJob {
/// @notice Executes this unit of work
/// @dev Should revert iff workable() returns canWork of false
/// @param network The name of the external keeper network
/// @param args Custom arguments supplied to the job, should be copied from workable response
function work(bytes32 network, bytes calldata args) external;
/// @notice Ask this job if it has a unit of work available
/// @dev This should never revert, only return false if nothing is available
/// @dev This should normally be a view, but sometimes that's not possible
/// @param network The name of the external keeper network
/// @return canWork Returns true if a unit of work is available
/// @return args The custom arguments to be provided to work() or an error string if canWork is false
function workable(bytes32 network) external returns (bool canWork, bytes memory args);
}
Read Contract
expiry 0xd2ec5fca → uint256
hub 0x365a86fc → address
ilkRegistry 0x3414d32a → address
sequencer 0x5c1bba38 → address
threshold 0x42cde4e8 → uint256
ttl 0x4e8b1dd5 → uint256
vat 0x36569e77 → address
Write Contract 2 functions
These functions modify contract state and require a wallet transaction to execute.
work 0x1d2ab000
bytes32 network
bytes args
workable 0x8dce54b7
bytes32 network
returns: bool, bytes
Recent Transactions
No transactions found for this address