ETH Price: $2,523.43 (+1.18%)

Contract

0x99B0599952a4FD2d1A1561Fa4C010827EaD30354
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Write Oracle Dat...190305302024-01-18 1:39:59228 days ago1705541999IN
dYdX: Chainlink Adapter
0 ETH0.0015790732.22741555
Transfer And Req...190305142024-01-18 1:36:47228 days ago1705541807IN
dYdX: Chainlink Adapter
0 ETH0.0159542476.15717524
Transfer And Req...190272122024-01-17 14:30:23229 days ago1705501823IN
dYdX: Chainlink Adapter
0 ETH0.0174048483.08159318
Transfer And Req...190269692024-01-17 13:40:59229 days ago1705498859IN
dYdX: Chainlink Adapter
0 ETH0.0189826190.61301276
Transfer And Req...190269502024-01-17 13:37:11229 days ago1705498631IN
dYdX: Chainlink Adapter
0 ETH0.02211124105.54748742
Write Oracle Dat...188212472023-12-19 16:41:11258 days ago1703004071IN
dYdX: Chainlink Adapter
0 ETH0.0029342859.88591061
Transfer And Req...188212442023-12-19 16:40:35258 days ago1703004035IN
dYdX: Chainlink Adapter
0 ETH0.03033775144.81649468
Write Oracle Dat...186297742023-11-22 20:50:47284 days ago1700686247IN
dYdX: Chainlink Adapter
0 ETH0.0020135941.09539937
Transfer And Req...186297712023-11-22 20:50:11284 days ago1700686211IN
dYdX: Chainlink Adapter
0 ETH0.02209101105.45092581
Transfer And Req...186290862023-11-22 18:32:47285 days ago1700677967IN
dYdX: Chainlink Adapter
0 ETH0.02843126135.71591499
Write Oracle Dat...184292182023-10-25 19:05:35312 days ago1698260735IN
dYdX: Chainlink Adapter
0 ETH0.0029804160.82728835
Transfer And Req...184292162023-10-25 19:05:11312 days ago1698260711IN
dYdX: Chainlink Adapter
0 ETH0.03281915156.6614289
Transfer And Req...184288512023-10-25 17:51:11313 days ago1698256271IN
dYdX: Chainlink Adapter
0 ETH0.0179620485.74135496
Transfer And Req...184282302023-10-25 15:46:23313 days ago1698248783IN
dYdX: Chainlink Adapter
0 ETH0.03362588160.51232508
Transfer And Req...184281692023-10-25 15:34:11313 days ago1698248051IN
dYdX: Chainlink Adapter
0 ETH0.03021082144.21059561
Transfer And Req...184227432023-10-24 21:17:47313 days ago1698182267IN
dYdX: Chainlink Adapter
0 ETH0.0131254662.65406697
Transfer And Req...184226122023-10-24 20:51:11313 days ago1698180671IN
dYdX: Chainlink Adapter
0 ETH0.0103449.3577509
Transfer And Req...184225262023-10-24 20:33:59313 days ago1698179639IN
dYdX: Chainlink Adapter
0 ETH0.015076171.96542448
Transfer And Req...184225082023-10-24 20:30:23313 days ago1698179423IN
dYdX: Chainlink Adapter
0 ETH0.0127775260.99321038
Write Oracle Dat...182211552023-09-26 16:30:59342 days ago1695745859IN
dYdX: Chainlink Adapter
0 ETH0.0014494829.58258872
Transfer And Req...182211522023-09-26 16:30:23342 days ago1695745823IN
dYdX: Chainlink Adapter
0 ETH0.0143271168.39010594
Write Oracle Dat...180213952023-08-29 16:14:35370 days ago1693325675IN
dYdX: Chainlink Adapter
0 ETH0.0035872273.21169994
Transfer And Req...180213922023-08-29 16:13:59370 days ago1693325639IN
dYdX: Chainlink Adapter
0 ETH0.03304464157.73777251
Write Oracle Dat...178211972023-08-01 15:58:23398 days ago1690905503IN
dYdX: Chainlink Adapter
0 ETH0.0015955232.56300414
Transfer And Req...178211942023-08-01 15:57:47398 days ago1690905467IN
dYdX: Chainlink Adapter
0 ETH0.0159923276.33894452
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
MD1ChainlinkAdapter

Compiler Version
v0.7.5+commit.eb77ed08

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 19 : MD1ChainlinkAdapter.sol
// Contracts by dYdX Foundation. Individual files are released under different licenses.
//
// https://dydx.community
// https://github.com/dydxfoundation/governance-contracts
//
// SPDX-License-Identifier: Apache-2.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

import {
  ChainlinkClient,
  Chainlink
} from '@chainlink/contracts/src/v0.7/ChainlinkClient.sol';

import { SafeERC20 } from '../../../dependencies/open-zeppelin/SafeERC20.sol';
import { IERC20 } from '../../../interfaces/IERC20.sol';
import { IMerkleDistributorV1 } from '../../../interfaces/IMerkleDistributorV1.sol';
import { IRewardsOracle } from '../../../interfaces/IRewardsOracle.sol';
import { MD1Types } from '../lib/MD1Types.sol';

/**
 * @title MD1ChainlinkAdapter
 * @author dYdX
 *
 * @notice Chainlink oracle adapter to be read by the MerkleDistributorV1 contract.
 */
contract MD1ChainlinkAdapter is
  ChainlinkClient,
  IRewardsOracle
{
  using Chainlink for Chainlink.Request;
  using SafeERC20 for IERC20;

  // ============ Events ============

  /// @notice Emitted when the oracle data is updated.
  event OracleRootUpdated(
    bytes32 merkleRoot,
    uint256 epoch,
    bytes ipfsCid
  );

  // ============ Constants ============

  /// @notice Address of the LINK token, used to pay for requests for oracle data.
  IERC20 public immutable CHAINLINK_TOKEN;

  /// @notice The address of the Merkle distributor contract, which determines rewards parameters.
  IMerkleDistributorV1 public immutable MERKLE_DISTRIBUTOR;

  /// @notice The address to which the Chainlink request is sent.
  address public immutable ORACLE_CONTRACT;

  /// @notice The address which will call writeOracleData().
  address public immutable ORACLE_EXTERNAL_ADAPTER;

  /// @notice Chainlink ID for the job.
  bytes32 public immutable JOB_ID;

  // ============ Storage ============

  /// @dev Mapping from Chainlink request ID to the address that initated the request.
  mapping(bytes32 => address) internal _OPEN_REQUESTS_;

  /// @dev The latest oracle data.
  MD1Types.MerkleRoot internal _ORACLE_ROOT_;

  // ============ Constructor ============

  constructor(
    address chainlinkToken,
    address merkleDistributor,
    address oracleContract,
    address oracleExternalAdapter,
    bytes32 jobId
  ) {
    setChainlinkToken(chainlinkToken);
    CHAINLINK_TOKEN = IERC20(chainlinkToken);
    MERKLE_DISTRIBUTOR = IMerkleDistributorV1(merkleDistributor);
    ORACLE_CONTRACT = oracleContract;
    ORACLE_EXTERNAL_ADAPTER = oracleExternalAdapter;
    JOB_ID = jobId;
  }

  // ============ External Functions ============

  /**
   * @notice Helper function which transfers the fee and makes a request in a single transaction.
   *
   * @param  fee  The LINK amount to pay for the request.
   */
  function transferAndRequestOracleData(
    uint256 fee
  )
    external
  {
    CHAINLINK_TOKEN.safeTransferFrom(msg.sender, address(this), fee);
    requestOracleData(fee);
  }

  /**
   * @notice Called by the oracle external adapter to write data in response to a request.
   *
   *  This should be called before fulfillRequest() is called.
   *
   * @param  merkleRoot  Root hash of the Merkle tree for this epoch's rewards distribution.
   * @param  epoch       The epoch number for this rewards distribution.
   * @param  ipfsCid     The IPFS CID with the full Merkle tree data.
   */
  function writeOracleData(
    bytes32 merkleRoot,
    uint256 epoch,
    bytes calldata ipfsCid
  )
    external
  {
    require(
      msg.sender == ORACLE_EXTERNAL_ADAPTER,
      'MD1ChainlinkAdapter: Sender must be the oracle external adapter'
    );

    _ORACLE_ROOT_ = MD1Types.MerkleRoot({
      merkleRoot: merkleRoot,
      epoch: epoch,
      ipfsCid: ipfsCid
    });

    emit OracleRootUpdated(merkleRoot, epoch, ipfsCid);
  }

  /**
   * @notice Callback function for the oracle to record fulfillment of a request.
   */
  function fulfillRequest(
    bytes32 requestId
  )
    external
    recordChainlinkFulfillment(requestId)
  {
    delete _OPEN_REQUESTS_[requestId];
  }

  /**
   * @notice Allow the initiator of a request to cancel that request. The request must have expired.
   *
   *  The LINK fee for the request will be refunded back to this contract.
   */
  function cancelRequest(
    bytes32 requestId,
    uint256 payment,
    bytes4 callbackFunc,
    uint256 expiration
  )
    external
  {
    require(
      msg.sender == _OPEN_REQUESTS_[requestId],
      'Request is not open or sender was not the initiator'
    );
    cancelChainlinkRequest(requestId, payment, callbackFunc, expiration);
  }

  /**
   * @notice Read the latest data written by the oracle. This will be called by MerkleDistributorV1.
   *
   * @return  merkleRoot  The Merkle root for the next Merkle distributor update.
   * @return  epoch       The epoch number corresponding to the new Merkle root.
   * @return  ipfsCid     An IPFS CID pointing to the Merkle tree data.
   */
  function read()
    external
    override
    view
    returns (bytes32 merkleRoot, uint256 epoch, bytes memory ipfsCid)
  {
    merkleRoot = _ORACLE_ROOT_.merkleRoot;
    epoch = _ORACLE_ROOT_.epoch;
    ipfsCid = _ORACLE_ROOT_.ipfsCid;
  }

  /**
   * @notice If a request with the specified ID is open, returns the address that initiated it.
   *
   * @param  requestId  The Chainlink request ID.
   *
   * @return The address that initiated request, or the zero address if the request is not open.
   */
  function getOpenRequest(
    bytes32 requestId
  )
    external
    view
    returns (address)
  {
    return _OPEN_REQUESTS_[requestId];
  }

  // ============ Public Functions ============

  /**
   * @notice Request the latest oracle data.
   *
   *  In response to this request, if sufficient fee is provided, the Chainlink node is expected to
   *  call the writeOracleData() function, followed by the fulfillRequest() function.
   *
   *  Reverts if this contract does not have LINK to pay the fee.
   *
   *  If the fee is less than the amount agreed to by the external (off-chain) oracle adapter, then
   *  the external adapter may ignore the request.
   *
   * @param  fee  The LINK amount to pay for the request.
   */
  function requestOracleData(
    uint256 fee
  )
    public
  {
    // Read parameters from the Merkle distributor contract.
    string memory ipnsName = MERKLE_DISTRIBUTOR.getIpnsName();
    (
      uint256 marketMakerRewardsAmount,
      uint256 traderRewardsAmount,
      uint256 traderScoreAlpha
    ) = MERKLE_DISTRIBUTOR.getRewardsParameters();
    (, , bytes memory activeRootIpfsCid) = MERKLE_DISTRIBUTOR.getActiveRoot();
    uint256 newEpoch = MERKLE_DISTRIBUTOR.getNextRootEpoch();

    // Build the Chainlink request.
    Chainlink.Request memory req = buildChainlinkRequest(
      JOB_ID,
      address(this),
      this.fulfillRequest.selector
    );
    req.addBytes('callbackAddress', abi.encodePacked(address(this)));
    req.add('ipnsName', ipnsName);
    req.addUint('marketMakerRewardsAmount', marketMakerRewardsAmount);
    req.addUint('traderRewardsAmount', traderRewardsAmount);
    req.addUint('traderScoreAlpha', traderScoreAlpha);
    req.addBytes('activeRootIpfsCid', activeRootIpfsCid);
    req.addUint('newEpoch', newEpoch);

    // Send the Chainlink request.
    //
    // Note: This emits ChainlinkRequested(bytes32 indexed id);
    bytes32 requestId = sendChainlinkRequestTo(ORACLE_CONTRACT, req, fee);

    // Store the address that initiated the request. This address may cancel the request.
    _OPEN_REQUESTS_[requestId] = msg.sender;
  }
}

File 2 of 19 : Address.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

/**
 * @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) {
    // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
    // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
    // for accounts without code, i.e. `keccak256('')`
    bytes32 codehash;
    bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
    // solhint-disable-next-line no-inline-assembly
    assembly {
      codehash := extcodehash(account)
    }
    return (codehash != accountHash && codehash != 0x0);
  }

  /**
   * @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');

    // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
    (bool success, ) = recipient.call{value: amount}('');
    require(success, 'Address: unable to send value, recipient may have reverted');
  }
}

File 3 of 19 : SafeERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import { IERC20 } from '../../interfaces/IERC20.sol';
import { SafeMath } from './SafeMath.sol';
import { Address } from './Address.sol';

/**
 * @title SafeERC20
 * @dev From https://github.com/OpenZeppelin/openzeppelin-contracts
 * Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
  using SafeMath for uint256;
  using Address for address;

  function safeTransfer(
    IERC20 token,
    address to,
    uint256 value
  ) internal {
    callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
  }

  function safeTransferFrom(
    IERC20 token,
    address from,
    address to,
    uint256 value
  ) internal {
    callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
  }

  function safeApprove(
    IERC20 token,
    address spender,
    uint256 value
  ) internal {
    require(
      (value == 0) || (token.allowance(address(this), spender) == 0),
      'SafeERC20: approve from non-zero to non-zero allowance'
    );
    callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
  }

  function callOptionalReturn(IERC20 token, bytes memory data) private {
    require(address(token).isContract(), 'SafeERC20: call to non-contract');

    // solhint-disable-next-line avoid-low-level-calls
    (bool success, bytes memory returndata) = address(token).call(data);
    require(success, 'SafeERC20: low-level call failed');

    if (returndata.length > 0) {
      // Return data is optional
      // solhint-disable-next-line max-line-length
      require(abi.decode(returndata, (bool)), 'SafeERC20: ERC20 operation did not succeed');
    }
  }
}

File 4 of 19 : IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
  /**
    * @dev Returns the amount of tokens in existence.
    */
  function totalSupply() external view returns (uint256);

  /**
    * @dev Returns the amount of tokens owned by `account`.
    */
  function balanceOf(address account) external view returns (uint256);

  /**
    * @dev Moves `amount` tokens from the caller's account to `recipient`.
    *
    * Returns a boolean value indicating whether the operation succeeded.
    *
    * Emits a {Transfer} event.
    */
  function transfer(address recipient, uint256 amount) external returns (bool);

  /**
    * @dev Returns the remaining number of tokens that `spender` will be
    * allowed to spend on behalf of `owner` through {transferFrom}. This is
    * zero by default.
    *
    * This value changes when {approve} or {transferFrom} are called.
    */
  function allowance(address owner, address spender) external view returns (uint256);

  /**
    * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
    *
    * Returns a boolean value indicating whether the operation succeeded.
    *
    * IMPORTANT: Beware that changing an allowance with this method brings the risk
    * that someone may use both the old and the new allowance by unfortunate
    * transaction ordering. One possible solution to mitigate this race
    * condition is to first reduce the spender's allowance to 0 and set the
    * desired value afterwards:
    * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
    *
    * Emits an {Approval} event.
    */
  function approve(address spender, uint256 amount) external returns (bool);

  /**
    * @dev Moves `amount` tokens from `sender` to `recipient` using the
    * allowance mechanism. `amount` is then deducted from the caller's
    * allowance.
    *
    * Returns a boolean value indicating whether the operation succeeded.
    *
    * Emits a {Transfer} event.
    */
  function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

  /**
    * @dev Emitted when `value` tokens are moved from one account (`from`) to
    * another (`to`).
    *
    * Note that `value` may be zero.
    */
  event Transfer(address indexed from, address indexed to, uint256 value);

  /**
    * @dev Emitted when the allowance of a `spender` for an `owner` is set by
    * a call to {approve}. `value` is the new allowance.
    */
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 5 of 19 : SafeMath.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
  /**
   * @dev Returns the addition of two unsigned integers, reverting on
   * overflow.
   *
   * Counterpart to Solidity's `+` operator.
   *
   * Requirements:
   * - Addition cannot overflow.
   */
  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    require(c >= a, 'SafeMath: addition overflow');

    return c;
  }

  /**
   * @dev Returns the subtraction of two unsigned integers, reverting on
   * overflow (when the result is negative).
   *
   * Counterpart to Solidity's `-` operator.
   *
   * Requirements:
   * - Subtraction cannot overflow.
   */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    return sub(a, b, 'SafeMath: subtraction overflow');
  }

  /**
   * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
   * overflow (when the result is negative).
   *
   * Counterpart to Solidity's `-` operator.
   *
   * Requirements:
   * - Subtraction cannot overflow.
   */
  function sub(
    uint256 a,
    uint256 b,
    string memory errorMessage
  ) internal pure returns (uint256) {
    require(b <= a, errorMessage);
    uint256 c = a - b;

    return c;
  }

  /**
   * @dev Returns the multiplication of two unsigned integers, reverting on
   * overflow.
   *
   * Counterpart to Solidity's `*` operator.
   *
   * Requirements:
   * - Multiplication cannot overflow.
   */
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
    // benefit is lost if 'b' is also tested.
    // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
    if (a == 0) {
      return 0;
    }

    uint256 c = a * b;
    require(c / a == b, 'SafeMath: multiplication overflow');

    return c;
  }

  /**
   * @dev Returns the integer division of two unsigned integers. Reverts on
   * division by zero. The result is rounded towards zero.
   *
   * Counterpart to Solidity's `/` operator. Note: this function uses a
   * `revert` opcode (which leaves remaining gas untouched) while Solidity
   * uses an invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    return div(a, b, 'SafeMath: division by zero');
  }

  /**
   * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
   * division by zero. The result is rounded towards zero.
   *
   * Counterpart to Solidity's `/` operator. Note: this function uses a
   * `revert` opcode (which leaves remaining gas untouched) while Solidity
   * uses an invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function div(
    uint256 a,
    uint256 b,
    string memory errorMessage
  ) internal pure returns (uint256) {
    // Solidity only automatically asserts when dividing by 0
    require(b > 0, errorMessage);
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold

    return c;
  }

  /**
   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
   * Reverts when dividing by zero.
   *
   * Counterpart to Solidity's `%` operator. This function uses a `revert`
   * opcode (which leaves remaining gas untouched) while Solidity uses an
   * invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function mod(uint256 a, uint256 b) internal pure returns (uint256) {
    return mod(a, b, 'SafeMath: modulo by zero');
  }

  /**
   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
   * Reverts with custom message when dividing by zero.
   *
   * Counterpart to Solidity's `%` operator. This function uses a `revert`
   * opcode (which leaves remaining gas untouched) while Solidity uses an
   * invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function mod(
    uint256 a,
    uint256 b,
    string memory errorMessage
  ) internal pure returns (uint256) {
    require(b != 0, errorMessage);
    return a % b;
  }
}

File 6 of 19 : ChainlinkClient.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import "./Chainlink.sol";
import "./interfaces/ENSInterface.sol";
import "./interfaces/LinkTokenInterface.sol";
import "./interfaces/OperatorInterface.sol";
import "./interfaces/PointerInterface.sol";
import { ENSResolver as ENSResolver_Chainlink } from "./vendor/ENSResolver.sol";

/**
 * @title The ChainlinkClient contract
 * @notice Contract writers can inherit this contract in order to create requests for the
 * Chainlink network
 */
contract ChainlinkClient {
  using Chainlink for Chainlink.Request;

  uint256 constant internal LINK_DIVISIBILITY = 10**18;
  uint256 constant private AMOUNT_OVERRIDE = 0;
  address constant private SENDER_OVERRIDE = address(0);
  uint256 constant private ORACLE_ARGS_VERSION = 1;
  uint256 constant private OPERATOR_ARGS_VERSION = 2;
  bytes32 constant private ENS_TOKEN_SUBNAME = keccak256("link");
  bytes32 constant private ENS_ORACLE_SUBNAME = keccak256("oracle");
  address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;

  ENSInterface private ens;
  bytes32 private ensNode;
  LinkTokenInterface private link;
  OperatorInterface private oracle;
  uint256 private requestCount = 1;
  mapping(bytes32 => address) private pendingRequests;

  event ChainlinkRequested(
    bytes32 indexed id
  );
  event ChainlinkFulfilled(
    bytes32 indexed id
  );
  event ChainlinkCancelled(
    bytes32 indexed id
  );

  /**
   * @notice Creates a request that can hold additional parameters
   * @param specId The Job Specification ID that the request will be created for
   * @param callbackAddress The callback address that the response will be sent to
   * @param callbackFunctionSignature The callback function signature to use for the callback address
   * @return A Chainlink Request struct in memory
   */
  function buildChainlinkRequest(
    bytes32 specId,
    address callbackAddress,
    bytes4 callbackFunctionSignature
  )
    internal
    pure
    returns (
      Chainlink.Request memory
    )
  {
    Chainlink.Request memory req;
    return req.initialize(specId, callbackAddress, callbackFunctionSignature);
  }

  /**
   * @notice Creates a Chainlink request to the stored oracle address
   * @dev Calls `chainlinkRequestTo` with the stored oracle address
   * @param req The initialized Chainlink Request
   * @param payment The amount of LINK to send for the request
   * @return requestId The request ID
   */
  function sendChainlinkRequest(
    Chainlink.Request memory req,
    uint256 payment
  )
    internal
    returns (
      bytes32
    )
  {
    return sendChainlinkRequestTo(address(oracle), req, payment);
  }

  /**
   * @notice Creates a Chainlink request to the specified oracle address
   * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to
   * send LINK which creates a request on the target oracle contract.
   * Emits ChainlinkRequested event.
   * @param oracleAddress The address of the oracle for the request
   * @param req The initialized Chainlink Request
   * @param payment The amount of LINK to send for the request
   * @return requestId The request ID
   */
  function sendChainlinkRequestTo(
    address oracleAddress,
    Chainlink.Request memory req,
    uint256 payment
  )
    internal
    returns (
      bytes32 requestId
    )
  {
    return rawRequest(oracleAddress, req, payment, ORACLE_ARGS_VERSION, oracle.oracleRequest.selector);
  }

  /**
   * @notice Creates a Chainlink request to the stored oracle address
   * @dev This function supports multi-word response
   * @dev Calls `requestOracleDataFrom` with the stored oracle address
   * @param req The initialized Chainlink Request
   * @param payment The amount of LINK to send for the request
   * @return requestId The request ID
   */
  function requestOracleData(
    Chainlink.Request memory req,
    uint256 payment
  )
    internal
    returns (
      bytes32
    )
  {
    return requestOracleDataFrom(address(oracle), req, payment);
  }

  /**
   * @notice Creates a Chainlink request to the specified oracle address
   * @dev This function supports multi-word response
   * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to
   * send LINK which creates a request on the target oracle contract.
   * Emits ChainlinkRequested event.
   * @param oracleAddress The address of the oracle for the request
   * @param req The initialized Chainlink Request
   * @param payment The amount of LINK to send for the request
   * @return requestId The request ID
   */
  function requestOracleDataFrom(
    address oracleAddress,
    Chainlink.Request memory req,
    uint256 payment
  )
    internal
    returns (
      bytes32 requestId
    )
  {
    return rawRequest(oracleAddress, req, payment, OPERATOR_ARGS_VERSION, oracle.requestOracleData.selector);
  }

  /**
   * @notice Make a request to an oracle
   * @param oracleAddress The address of the oracle for the request
   * @param req The initialized Chainlink Request
   * @param payment The amount of LINK to send for the request
   * @param argsVersion The version of data support (single word, multi word)
   * @return requestId The request ID
   */
  function rawRequest(
    address oracleAddress,
    Chainlink.Request memory req,
    uint256 payment,
    uint256 argsVersion,
    bytes4 funcSelector
  )
    private
    returns (
      bytes32 requestId
    )
  {
    requestId = keccak256(abi.encodePacked(this, requestCount));
    req.nonce = requestCount;
    pendingRequests[requestId] = oracleAddress;
    emit ChainlinkRequested(requestId);
    bytes memory encodedData = abi.encodeWithSelector(
      funcSelector,
      SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address
      AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent
      req.id,
      req.callbackAddress,
      req.callbackFunctionId,
      req.nonce,
      argsVersion,
      req.buf.buf);
    require(link.transferAndCall(oracleAddress, payment, encodedData), "unable to transferAndCall to oracle");
    requestCount += 1;
  }

  /**
   * @notice Allows a request to be cancelled if it has not been fulfilled
   * @dev Requires keeping track of the expiration value emitted from the oracle contract.
   * Deletes the request from the `pendingRequests` mapping.
   * Emits ChainlinkCancelled event.
   * @param requestId The request ID
   * @param payment The amount of LINK sent for the request
   * @param callbackFunc The callback function specified for the request
   * @param expiration The time of the expiration for the request
   */
  function cancelChainlinkRequest(
    bytes32 requestId,
    uint256 payment,
    bytes4 callbackFunc,
    uint256 expiration
  )
    internal
  {
    OperatorInterface requested = OperatorInterface(pendingRequests[requestId]);
    delete pendingRequests[requestId];
    emit ChainlinkCancelled(requestId);
    requested.cancelOracleRequest(requestId, payment, callbackFunc, expiration);
  }

  /**
   * @notice Sets the stored oracle address
   * @param oracleAddress The address of the oracle contract
   */
  function setChainlinkOracle(
    address oracleAddress
  )
    internal
  {
    oracle = OperatorInterface(oracleAddress);
  }

  /**
   * @notice Sets the LINK token address
   * @param linkAddress The address of the LINK token contract
   */
  function setChainlinkToken(
    address linkAddress
  )
    internal
  {
    link = LinkTokenInterface(linkAddress);
  }

  /**
   * @notice Sets the Chainlink token address for the public
   * network as given by the Pointer contract
   */
  function setPublicChainlinkToken() 
    internal
  {
    setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());
  }

  /**
   * @notice Retrieves the stored address of the LINK token
   * @return The address of the LINK token
   */
  function chainlinkTokenAddress()
    internal
    view
    returns (
      address
    )
  {
    return address(link);
  }

  /**
   * @notice Retrieves the stored address of the oracle contract
   * @return The address of the oracle contract
   */
  function chainlinkOracleAddress()
    internal
    view
    returns (
      address
    )
  {
    return address(oracle);
  }

  /**
   * @notice Allows for a request which was created on another contract to be fulfilled
   * on this contract
   * @param oracleAddress The address of the oracle contract that will fulfill the request
   * @param requestId The request ID used for the response
   */
  function addChainlinkExternalRequest(
    address oracleAddress,
    bytes32 requestId
  )
    internal
    notPendingRequest(requestId)
  {
    pendingRequests[requestId] = oracleAddress;
  }

  /**
   * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS
   * @dev Accounts for subnodes having different resolvers
   * @param ensAddress The address of the ENS contract
   * @param node The ENS node hash
   */
  function useChainlinkWithENS(
    address ensAddress,
    bytes32 node
  )
    internal
  {
    ens = ENSInterface(ensAddress);
    ensNode = node;
    bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));
    ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));
    setChainlinkToken(resolver.addr(linkSubnode));
    updateChainlinkOracleWithENS();
  }

  /**
   * @notice Sets the stored oracle contract with the address resolved by ENS
   * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously
   */
  function updateChainlinkOracleWithENS()
    internal
  {
    bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));
    ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));
    setChainlinkOracle(resolver.addr(oracleSubnode));
  }

  /**
   * @notice Ensures that the fulfillment is valid for this contract
   * @dev Use if the contract developer prefers methods instead of modifiers for validation
   * @param requestId The request ID for fulfillment
   */
  function validateChainlinkCallback(
    bytes32 requestId
  )
    internal
    recordChainlinkFulfillment(requestId)
    // solhint-disable-next-line no-empty-blocks
  {}

  /**
   * @dev Reverts if the sender is not the oracle of the request.
   * Emits ChainlinkFulfilled event.
   * @param requestId The request ID for fulfillment
   */
  modifier recordChainlinkFulfillment(
    bytes32 requestId
  )
  {
    require(msg.sender == pendingRequests[requestId],
            "Source must be the oracle of the request");
    delete pendingRequests[requestId];
    emit ChainlinkFulfilled(requestId);
    _;
  }

  /**
   * @dev Reverts if the request is already pending
   * @param requestId The request ID for fulfillment
   */
  modifier notPendingRequest(
    bytes32 requestId
  )
  {
    require(pendingRequests[requestId] == address(0), "Request is already pending");
    _;
  }
}

File 7 of 19 : IMerkleDistributorV1.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.5;
pragma abicoder v2;

/**
 * @title IMerkleDistributorV1
 * @author dYdX
 *
 * @notice Partial interface for the MerkleDistributorV1 contract.
 */
interface IMerkleDistributorV1 {

  function getIpnsName()
    external
    virtual
    view
    returns (string memory);

  function getRewardsParameters()
    external
    virtual
    view
    returns (uint256, uint256, uint256);

  function getActiveRoot()
    external
    virtual
    view
    returns (bytes32 merkleRoot, uint256 epoch, bytes memory ipfsCid);

  function getNextRootEpoch()
    external
    virtual
    view
    returns (uint256);

  function claimRewards(
    uint256 cumulativeAmount,
    bytes32[] calldata merkleProof
  )
    external
    returns (uint256);
}

File 8 of 19 : IRewardsOracle.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.5;
pragma abicoder v2;

interface IRewardsOracle {

  /**
   * @notice Returns the oracle value, agreed upon by all oracle signers. If the signers have not
   *  agreed upon a value, should return zero for all return values.
   *
   * @return  merkleRoot  The Merkle root for the next Merkle distributor update.
   * @return  epoch       The epoch number corresponding to the new Merkle root.
   * @return  ipfsCid     An IPFS CID pointing to the Merkle tree data.
   */
  function read()
    external
    virtual
    view
    returns (bytes32 merkleRoot, uint256 epoch, bytes memory ipfsCid);
}

File 9 of 19 : MD1Types.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

library MD1Types {

  /**
   * @dev The parameters used to convert a timestamp to an epoch number.
   */
  struct EpochParameters {
    uint128 interval;
    uint128 offset;
  }

  /**
   * @dev The parameters related to a certain version of the Merkle root.
   */
  struct MerkleRoot {
    bytes32 merkleRoot;
    uint256 epoch;
    bytes ipfsCid;
  }
}

File 10 of 19 : Chainlink.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import { CBORChainlink } from "./vendor/CBORChainlink.sol";
import { BufferChainlink } from "./vendor/BufferChainlink.sol";

/**
 * @title Library for common Chainlink functions
 * @dev Uses imported CBOR library for encoding to buffer
 */
library Chainlink {
  uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase

  using CBORChainlink for BufferChainlink.buffer;

  struct Request {
    bytes32 id;
    address callbackAddress;
    bytes4 callbackFunctionId;
    uint256 nonce;
    BufferChainlink.buffer buf;
  }

  /**
   * @notice Initializes a Chainlink request
   * @dev Sets the ID, callback address, and callback function signature on the request
   * @param self The uninitialized request
   * @param jobId The Job Specification ID
   * @param callbackAddr The callback address
   * @param callbackFunc The callback function signature
   * @return The initialized request
   */
  function initialize(
    Request memory self,
    bytes32 jobId,
    address callbackAddr,
    bytes4 callbackFunc
  )
    internal
    pure
    returns (
      Chainlink.Request memory
    )
  {
    BufferChainlink.init(self.buf, defaultBufferSize);
    self.id = jobId;
    self.callbackAddress = callbackAddr;
    self.callbackFunctionId = callbackFunc;
    return self;
  }

  /**
   * @notice Sets the data for the buffer without encoding CBOR on-chain
   * @dev CBOR can be closed with curly-brackets {} or they can be left off
   * @param self The initialized request
   * @param data The CBOR data
   */
  function setBuffer(
    Request memory self,
    bytes memory data
  )
    internal
    pure
  {
    BufferChainlink.init(self.buf, data.length);
    BufferChainlink.append(self.buf, data);
  }

  /**
   * @notice Adds a string value to the request with a given key name
   * @param self The initialized request
   * @param key The name of the key
   * @param value The string value to add
   */
  function add(
    Request memory self,
    string memory key,
    string memory value
  )
    internal
    pure
  {
    self.buf.encodeString(key);
    self.buf.encodeString(value);
  }

  /**
   * @notice Adds a bytes value to the request with a given key name
   * @param self The initialized request
   * @param key The name of the key
   * @param value The bytes value to add
   */
  function addBytes(
    Request memory self,
    string memory key,
    bytes memory value
  )
    internal
    pure
  {
    self.buf.encodeString(key);
    self.buf.encodeBytes(value);
  }

  /**
   * @notice Adds a int256 value to the request with a given key name
   * @param self The initialized request
   * @param key The name of the key
   * @param value The int256 value to add
   */
  function addInt(
    Request memory self,
    string memory key,
    int256 value
  )
    internal
    pure
  {
    self.buf.encodeString(key);
    self.buf.encodeInt(value);
  }

  /**
   * @notice Adds a uint256 value to the request with a given key name
   * @param self The initialized request
   * @param key The name of the key
   * @param value The uint256 value to add
   */
  function addUint(
    Request memory self,
    string memory key,
    uint256 value
  )
    internal
    pure
  {
    self.buf.encodeString(key);
    self.buf.encodeUInt(value);
  }

  /**
   * @notice Adds an array of strings to the request with a given key name
   * @param self The initialized request
   * @param key The name of the key
   * @param values The array of string values to add
   */
  function addStringArray(
    Request memory self,
    string memory key,
    string[] memory values
  )
    internal
    pure
  {
    self.buf.encodeString(key);
    self.buf.startArray();
    for (uint256 i = 0; i < values.length; i++) {
      self.buf.encodeString(values[i]);
    }
    self.buf.endSequence();
  }
}

File 11 of 19 : ENSInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

interface ENSInterface {

  // Logged when the owner of a node assigns a new owner to a subnode.
  event NewOwner(
    bytes32 indexed node,
    bytes32 indexed label,
    address owner
  );

  // Logged when the owner of a node transfers ownership to a new account.
  event Transfer(
    bytes32 indexed node,
    address owner
  );

  // Logged when the resolver for a node changes.
  event NewResolver(
    bytes32 indexed node,
    address resolver
  );

  // Logged when the TTL of a node changes
  event NewTTL(
    bytes32 indexed node,
    uint64 ttl
  );


  function setSubnodeOwner(
    bytes32 node,
    bytes32 label,
    address owner
  ) external;

  function setResolver(
    bytes32 node,
    address resolver
  ) external;

  function setOwner(
    bytes32 node,
    address owner
  ) external;

  function setTTL(
    bytes32 node,
    uint64 ttl
  ) external;

  function owner(
    bytes32 node
  )
    external
    view
    returns (
      address
    );

  function resolver(
    bytes32 node
  )
    external
    view
    returns (
      address
    );

  function ttl(
    bytes32 node
  )
    external
    view
    returns (
      uint64
    );

}

File 12 of 19 : LinkTokenInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.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
    );

}

File 13 of 19 : OperatorInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import "./ChainlinkRequestInterface.sol";
import "./OracleInterface.sol";

interface OperatorInterface is
  ChainlinkRequestInterface,
  OracleInterface
{

  function requestOracleData(
    address sender,
    uint256 payment,
    bytes32 specId,
    address callbackAddress,
    bytes4 callbackFunctionId,
    uint256 nonce,
    uint256 dataVersion,
    bytes calldata data
  )
    external;

  function fulfillOracleRequest2(
    bytes32 requestId,
    uint256 payment,
    address callbackAddress,
    bytes4 callbackFunctionId,
    uint256 expiration,
    bytes calldata data
  )
    external
    returns (
      bool
    );

  function ownerTransferAndCall(
    address to,
    uint256 value,
    bytes calldata data
  )
    external
    returns (
      bool success
    );

}

File 14 of 19 : PointerInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

interface PointerInterface {
  
  function getAddress()
    external
    view
    returns (
      address
    );
}

File 15 of 19 : ENSResolver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

abstract contract ENSResolver {
  function addr(
    bytes32 node
  )
    public
    view
    virtual
    returns (
      address
    );
}

File 16 of 19 : CBORChainlink.sol
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.19;

import { BufferChainlink } from "./BufferChainlink.sol";

library CBORChainlink {
  using BufferChainlink for BufferChainlink.buffer;

  uint8 private constant MAJOR_TYPE_INT = 0;
  uint8 private constant MAJOR_TYPE_NEGATIVE_INT = 1;
  uint8 private constant MAJOR_TYPE_BYTES = 2;
  uint8 private constant MAJOR_TYPE_STRING = 3;
  uint8 private constant MAJOR_TYPE_ARRAY = 4;
  uint8 private constant MAJOR_TYPE_MAP = 5;
  uint8 private constant MAJOR_TYPE_TAG = 6;
  uint8 private constant MAJOR_TYPE_CONTENT_FREE = 7;

  uint8 private constant TAG_TYPE_BIGNUM = 2;
  uint8 private constant TAG_TYPE_NEGATIVE_BIGNUM = 3;

  function encodeType(
    BufferChainlink.buffer memory buf,
    uint8 major,
    uint value
  )
    private
    pure
  {
    if(value <= 23) {
      buf.appendUint8(uint8((major << 5) | value));
    } else if(value <= 0xFF) {
      buf.appendUint8(uint8((major << 5) | 24));
      buf.appendInt(value, 1);
    } else if(value <= 0xFFFF) {
      buf.appendUint8(uint8((major << 5) | 25));
      buf.appendInt(value, 2);
    } else if(value <= 0xFFFFFFFF) {
      buf.appendUint8(uint8((major << 5) | 26));
      buf.appendInt(value, 4);
    } else if(value <= 0xFFFFFFFFFFFFFFFF) {
      buf.appendUint8(uint8((major << 5) | 27));
      buf.appendInt(value, 8);
    }
  }

  function encodeIndefiniteLengthType(
    BufferChainlink.buffer memory buf,
    uint8 major
  )
    private
    pure
  {
    buf.appendUint8(uint8((major << 5) | 31));
  }

  function encodeUInt(
    BufferChainlink.buffer memory buf,
    uint value
  )
    internal
    pure
  {
    encodeType(buf, MAJOR_TYPE_INT, value);
  }

  function encodeInt(
    BufferChainlink.buffer memory buf,
    int value
  )
    internal
    pure
  {
    if(value < -0x10000000000000000) {
      encodeSignedBigNum(buf, value);
    } else if(value > 0xFFFFFFFFFFFFFFFF) {
      encodeBigNum(buf, value);
    } else if(value >= 0) {
      encodeType(buf, MAJOR_TYPE_INT, uint(value));
    } else {
      encodeType(buf, MAJOR_TYPE_NEGATIVE_INT, uint(-1 - value));
    }
  }

  function encodeBytes(
    BufferChainlink.buffer memory buf,
    bytes memory value
  )
    internal
    pure
  {
    encodeType(buf, MAJOR_TYPE_BYTES, value.length);
    buf.append(value);
  }

  function encodeBigNum(
    BufferChainlink.buffer memory buf,
    int value
  )
    internal
    pure
  {
    buf.appendUint8(uint8((MAJOR_TYPE_TAG << 5) | TAG_TYPE_BIGNUM));
    encodeBytes(buf, abi.encode(uint(value)));
  }

  function encodeSignedBigNum(
    BufferChainlink.buffer memory buf,
    int input
  )
    internal
    pure
  {
    buf.appendUint8(uint8((MAJOR_TYPE_TAG << 5) | TAG_TYPE_NEGATIVE_BIGNUM));
    encodeBytes(buf, abi.encode(uint(-1 - input)));
  }

  function encodeString(
    BufferChainlink.buffer memory buf,
    string memory value
  )
    internal
    pure
  {
    encodeType(buf, MAJOR_TYPE_STRING, bytes(value).length);
    buf.append(bytes(value));
  }

  function startArray(
    BufferChainlink.buffer memory buf
  )
    internal
    pure
  {
    encodeIndefiniteLengthType(buf, MAJOR_TYPE_ARRAY);
  }

  function startMap(
    BufferChainlink.buffer memory buf
  )
    internal
    pure
  {
    encodeIndefiniteLengthType(buf, MAJOR_TYPE_MAP);
  }

  function endSequence(
    BufferChainlink.buffer memory buf
  )
    internal
    pure
  {
    encodeIndefiniteLengthType(buf, MAJOR_TYPE_CONTENT_FREE);
  }
}

File 17 of 19 : BufferChainlink.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

/**
* @dev A library for working with mutable byte buffers in Solidity.
*
* Byte buffers are mutable and expandable, and provide a variety of primitives
* for writing to them. At any time you can fetch a bytes object containing the
* current contents of the buffer. The bytes object should not be stored between
* operations, as it may change due to resizing of the buffer.
*/
library BufferChainlink {
  /**
  * @dev Represents a mutable buffer. Buffers have a current value (buf) and
  *      a capacity. The capacity may be longer than the current value, in
  *      which case it can be extended without the need to allocate more memory.
  */
  struct buffer {
    bytes buf;
    uint capacity;
  }

  /**
  * @dev Initializes a buffer with an initial capacity.
  * @param buf The buffer to initialize.
  * @param capacity The number of bytes of space to allocate the buffer.
  * @return The buffer, for chaining.
  */
  function init(
    buffer memory buf,
    uint capacity
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    if (capacity % 32 != 0) {
      capacity += 32 - (capacity % 32);
    }
    // Allocate space for the buffer data
    buf.capacity = capacity;
    assembly {
      let ptr := mload(0x40)
      mstore(buf, ptr)
      mstore(ptr, 0)
      mstore(0x40, add(32, add(ptr, capacity)))
    }
    return buf;
  }

  /**
  * @dev Initializes a new buffer from an existing bytes object.
  *      Changes to the buffer may mutate the original value.
  * @param b The bytes object to initialize the buffer with.
  * @return A new buffer.
  */
  function fromBytes(
    bytes memory b
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    buffer memory buf;
    buf.buf = b;
    buf.capacity = b.length;
    return buf;
  }

  function resize(
    buffer memory buf,
    uint capacity
  )
    private
    pure
  {
    bytes memory oldbuf = buf.buf;
    init(buf, capacity);
    append(buf, oldbuf);
  }

  function max(
    uint a,
    uint b
  )
    private
    pure
    returns(
      uint
    )
  {
    if (a > b) {
      return a;
    }
    return b;
  }

  /**
  * @dev Sets buffer length to 0.
  * @param buf The buffer to truncate.
  * @return The original buffer, for chaining..
  */
  function truncate(
    buffer memory buf
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    assembly {
      let bufptr := mload(buf)
      mstore(bufptr, 0)
    }
    return buf;
  }

  /**
  * @dev Writes a byte string to a buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param off The start offset to write to.
  * @param data The data to append.
  * @param len The number of bytes to copy.
  * @return The original buffer, for chaining.
  */
  function write(
    buffer memory buf,
    uint off,
    bytes memory data,
    uint len
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    require(len <= data.length);

    if (off + len > buf.capacity) {
      resize(buf, max(buf.capacity, len + off) * 2);
    }

    uint dest;
    uint src;
    assembly {
      // Memory address of the buffer data
      let bufptr := mload(buf)
      // Length of existing buffer data
      let buflen := mload(bufptr)
      // Start address = buffer address + offset + sizeof(buffer length)
      dest := add(add(bufptr, 32), off)
      // Update buffer length if we're extending it
      if gt(add(len, off), buflen) {
        mstore(bufptr, add(len, off))
      }
      src := add(data, 32)
    }

    // Copy word-length chunks while possible
    for (; len >= 32; len -= 32) {
      assembly {
        mstore(dest, mload(src))
      }
      dest += 32;
      src += 32;
    }

    // Copy remaining bytes
    uint mask = 256 ** (32 - len) - 1;
    assembly {
      let srcpart := and(mload(src), not(mask))
      let destpart := and(mload(dest), mask)
      mstore(dest, or(destpart, srcpart))
    }

    return buf;
  }

  /**
  * @dev Appends a byte string to a buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param data The data to append.
  * @param len The number of bytes to copy.
  * @return The original buffer, for chaining.
  */
  function append(
    buffer memory buf,
    bytes memory data,
    uint len
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    return write(buf, buf.buf.length, data, len);
  }

  /**
  * @dev Appends a byte string to a buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param data The data to append.
  * @return The original buffer, for chaining.
  */
  function append(
    buffer memory buf,
    bytes memory data
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    return write(buf, buf.buf.length, data, data.length);
  }

  /**
  * @dev Writes a byte to the buffer. Resizes if doing so would exceed the
  *      capacity of the buffer.
  * @param buf The buffer to append to.
  * @param off The offset to write the byte at.
  * @param data The data to append.
  * @return The original buffer, for chaining.
  */
  function writeUint8(
    buffer memory buf,
    uint off,
    uint8 data
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    if (off >= buf.capacity) {
      resize(buf, buf.capacity * 2);
    }

    assembly {
      // Memory address of the buffer data
      let bufptr := mload(buf)
      // Length of existing buffer data
      let buflen := mload(bufptr)
      // Address = buffer address + sizeof(buffer length) + off
      let dest := add(add(bufptr, off), 32)
      mstore8(dest, data)
      // Update buffer length if we extended it
      if eq(off, buflen) {
        mstore(bufptr, add(buflen, 1))
      }
    }
    return buf;
  }

  /**
  * @dev Appends a byte to the buffer. Resizes if doing so would exceed the
  *      capacity of the buffer.
  * @param buf The buffer to append to.
  * @param data The data to append.
  * @return The original buffer, for chaining.
  */
  function appendUint8(
    buffer memory buf,
    uint8 data
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    return writeUint8(buf, buf.buf.length, data);
  }

  /**
  * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would
  *      exceed the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param off The offset to write at.
  * @param data The data to append.
  * @param len The number of bytes to write (left-aligned).
  * @return The original buffer, for chaining.
  */
  function write(
    buffer memory buf,
    uint off,
    bytes32 data,
    uint len
  )
    private
    pure
    returns(
      buffer memory
    )
  {
    if (len + off > buf.capacity) {
      resize(buf, (len + off) * 2);
    }

    uint mask = 256 ** len - 1;
    // Right-align data
    data = data >> (8 * (32 - len));
    assembly {
      // Memory address of the buffer data
      let bufptr := mload(buf)
      // Address = buffer address + sizeof(buffer length) + off + len
      let dest := add(add(bufptr, off), len)
      mstore(dest, or(and(mload(dest), not(mask)), data))
      // Update buffer length if we extended it
      if gt(add(off, len), mload(bufptr)) {
        mstore(bufptr, add(off, len))
      }
    }
    return buf;
  }

  /**
  * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the
  *      capacity of the buffer.
  * @param buf The buffer to append to.
  * @param off The offset to write at.
  * @param data The data to append.
  * @return The original buffer, for chaining.
  */
  function writeBytes20(
    buffer memory buf,
    uint off,
    bytes20 data
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    return write(buf, off, bytes32(data), 20);
  }

  /**
  * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param data The data to append.
  * @return The original buffer, for chhaining.
  */
  function appendBytes20(
    buffer memory buf,
    bytes20 data
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    return write(buf, buf.buf.length, bytes32(data), 20);
  }

  /**
  * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param data The data to append.
  * @return The original buffer, for chaining.
  */
  function appendBytes32(
    buffer memory buf,
    bytes32 data
  )
    internal
    pure
    returns (
      buffer memory
    )
  {
    return write(buf, buf.buf.length, data, 32);
  }

  /**
  * @dev Writes an integer to the buffer. Resizes if doing so would exceed
  *      the capacity of the buffer.
  * @param buf The buffer to append to.
  * @param off The offset to write at.
  * @param data The data to append.
  * @param len The number of bytes to write (right-aligned).
  * @return The original buffer, for chaining.
  */
  function writeInt(
    buffer memory buf,
    uint off,
    uint data,
    uint len
  )
    private
    pure
    returns(
      buffer memory
    )
  {
    if (len + off > buf.capacity) {
      resize(buf, (len + off) * 2);
    }

    uint mask = 256 ** len - 1;
    assembly {
      // Memory address of the buffer data
      let bufptr := mload(buf)
      // Address = buffer address + off + sizeof(buffer length) + len
      let dest := add(add(bufptr, off), len)
      mstore(dest, or(and(mload(dest), not(mask)), data))
      // Update buffer length if we extended it
      if gt(add(off, len), mload(bufptr)) {
        mstore(bufptr, add(off, len))
      }
    }
    return buf;
  }

  /**
    * @dev Appends a byte to the end of the buffer. Resizes if doing so would
    * exceed the capacity of the buffer.
    * @param buf The buffer to append to.
    * @param data The data to append.
    * @return The original buffer.
    */
  function appendInt(
    buffer memory buf,
    uint data,
    uint len
  )
    internal
    pure
    returns(
      buffer memory
    )
  {
    return writeInt(buf, buf.buf.length, data, len);
  }
}

File 18 of 19 : ChainlinkRequestInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

interface ChainlinkRequestInterface {
  function oracleRequest(
    address sender,
    uint256 requestPrice,
    bytes32 serviceAgreementID,
    address callbackAddress,
    bytes4 callbackFunctionId,
    uint256 nonce,
    uint256 dataVersion,
    bytes calldata data
  ) external;

  function cancelOracleRequest(
    bytes32 requestId,
    uint256 payment,
    bytes4 callbackFunctionId,
    uint256 expiration
  ) external;
}

File 19 of 19 : OracleInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

interface OracleInterface {
  function fulfillOracleRequest(
    bytes32 requestId,
    uint256 payment,
    address callbackAddress,
    bytes4 callbackFunctionId,
    uint256 expiration,
    bytes32 data
  )
    external
    returns (
      bool
    );

  function withdraw(
    address recipient,
    uint256 amount
  ) external;

  function withdrawable()
    external
    view
    returns (
      uint256
    );
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "istanbul",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"chainlinkToken","type":"address"},{"internalType":"address","name":"merkleDistributor","type":"address"},{"internalType":"address","name":"oracleContract","type":"address"},{"internalType":"address","name":"oracleExternalAdapter","type":"address"},{"internalType":"bytes32","name":"jobId","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"ipfsCid","type":"bytes"}],"name":"OracleRootUpdated","type":"event"},{"inputs":[],"name":"CHAINLINK_TOKEN","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"JOB_ID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MERKLE_DISTRIBUTOR","outputs":[{"internalType":"contract IMerkleDistributorV1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORACLE_CONTRACT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORACLE_EXTERNAL_ADAPTER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"},{"internalType":"uint256","name":"payment","type":"uint256"},{"internalType":"bytes4","name":"callbackFunc","type":"bytes4"},{"internalType":"uint256","name":"expiration","type":"uint256"}],"name":"cancelRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"name":"fulfillRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"name":"getOpenRequest","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"read","outputs":[{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"bytes","name":"ipfsCid","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"requestOracleData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"transferAndRequestOracleData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"bytes","name":"ipfsCid","type":"bytes"}],"name":"writeOracleData","outputs":[],"stateMutability":"nonpayable","type":"function"}]

61012060405260016004553480156200001757600080fd5b5060405162001ab838038062001ab88339810160408190526200003a91620000b8565b620000458562000079565b6001600160601b0319606095861b811660805293851b841660a05291841b831660c05290921b1660e052610100526200011e565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620000b357600080fd5b919050565b600080600080600060a08688031215620000d0578081fd5b620000db866200009b565b9450620000eb602087016200009b565b9350620000fb604087016200009b565b92506200010b606087016200009b565b9150608086015190509295509295909350565b60805160601c60a05160601c60c05160601c60e05160601c6101005161192662000192600039806104e052806107745250806101f652806103fa52508061031d52806109315250806104bc528061050652806105a2528061063b52806106d65250806101b752806102f952506119266000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c806357b81b601161007157806357b81b601461012d57806357de26a4146101355780635ab383e01461014c57806361e072c314610154578063b6d6fe5014610169578063ec65d0f81461017c576100b4565b80630fe392f0146100b957806314411884146100e257806315e2e0f9146100f7578063205842351461010a5780632870b69114610112578063432d01371461011a575b600080fd5b6100cc6100c7366004611544565b61018f565b6040516100d99190611704565b60405180910390f35b6100f56100f0366004611544565b6101aa565b005b6100f56101053660046115a6565b6101eb565b6100cc6102f7565b6100cc61031b565b6100f5610128366004611544565b61033f565b6100cc6103f8565b61013d61041c565b6040516100d99392919061175e565b6100cc6104ba565b61015c6104de565b6040516100d99190611718565b6100f5610177366004611544565b610502565b6100f561018a36600461155c565b610980565b6000908152600660205260409020546001600160a01b031690565b6101df6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163330846109c8565b6101e881610502565b50565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461023c5760405162461bcd60e51b81526004016102339061179f565b60405180910390fd5b604051806060016040528085815260200184815260200183838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505091525080516007908155602080830151600855604083015180516102b09260099201906113dc565b509050507f29dc752488242557497b1331104cbf61a8661935cbf8ce1561874fc042a31f66848484846040516102e99493929190611721565b60405180910390a150505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008181526005602052604090205481906001600160a01b031633146103965760405162461bcd60e51b815260040180806020018281038252602881526020018061189f6028913960400191505060405180910390fd5b60008181526005602052604080822080546001600160a01b03191690555182917f7cc135e0cebb02c3480ae5d74d377283180a2601f8f644edf7987b009316c63a91a250600090815260066020526040902080546001600160a01b0319169055565b7f000000000000000000000000000000000000000000000000000000000000000081565b60075460085460098054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104ae5780601f10610483576101008083540402835291602001916104ae565b820191906000526020600020905b81548152906001019060200180831161049157829003601f168201915b50505050509050909192565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ee90a3156040518163ffffffff1660e01b815260040160006040518083038186803b15801561055d57600080fd5b505afa158015610571573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610599919081019061166f565b905060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663368e4d166040518163ffffffff1660e01b815260040160606040518083038186803b1580156105f957600080fd5b505afa15801561060d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063191906116ba565b92509250925060607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166314d350436040518163ffffffff1660e01b815260040160006040518083038186803b15801561069257600080fd5b505afa1580156106a6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106ce9190810190611621565b9250505060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c9afde0c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561072d57600080fd5b505afa158015610741573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076591906116a2565b905061076f611468565b6107a17f00000000000000000000000000000000000000000000000000000000000000003063432d013760e01b610a22565b90506107f76040518060400160405280600f81526020016e63616c6c6261636b4164647265737360881b815250306040516020016107df91906116e7565b60408051601f19818403018152919052839190610a47565b60408051808201909152600881526769706e734e616d6560c01b602082015261082290829089610a6a565b60408051808201909152601881527f6d61726b65744d616b657252657761726473416d6f756e740000000000000000602082015261086290829088610a88565b6040805180820190915260138152721d1c9859195c94995dd85c991cd05b5bdd5b9d606a1b602082015261089890829087610a88565b60408051808201909152601081526f74726164657253636f7265416c70686160801b60208201526108cb90829086610a88565b6040805180820190915260118152701858dd1a5d99549bdbdd125c199cd0da59607a1b60208201526108ff90829085610a47565b6040805180820190915260088152670dccaee8ae0dec6d60c31b602082015261092a90829084610a88565b60006109577f0000000000000000000000000000000000000000000000000000000000000000838b610aa6565b600090815260066020526040902080546001600160a01b03191633179055505050505050505050565b6000848152600660205260409020546001600160a01b031633146109b65760405162461bcd60e51b8152600401610233906117fc565b6109c284848484610ac5565b50505050565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526109c2908590610b9d565b610a2a611468565b610a32611468565b610a3e81868686610d55565b95945050505050565b6080830151610a569083610d92565b6080830151610a659082610da9565b505050565b6080830151610a799083610d92565b6080830151610a659082610d92565b6080830151610a979083610d92565b6080830151610a659082610db6565b6000610abd84848460016320214ca360e11b610dc6565b949350505050565b60008481526005602052604080822080546001600160a01b0319811690915590516001600160a01b039091169186917fe1fe3afa0f7f761ff0a8b89086790efd5140d2907ebd5b7ff6bfcb5e075fd4c59190a260408051636ee4d55360e01b815260048101879052602481018690526001600160e01b0319851660448201526064810184905290516001600160a01b03831691636ee4d55391608480830192600092919082900301818387803b158015610b7e57600080fd5b505af1158015610b92573d6000803e3d6000fd5b505050505050505050565b610baf826001600160a01b03166110ba565b610c00576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b60208310610c3e5780518252601f199092019160209182019101610c1f565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610ca0576040519150601f19603f3d011682016040523d82523d6000602084013e610ca5565b606091505b509150915081610cfc576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156109c257808060200190516020811015610d1857600080fd5b50516109c25760405162461bcd60e51b815260040180806020018281038252602a8152602001806118c7602a913960400191505060405180910390fd5b610d5d611468565b610d6d85608001516101006110f3565b50509183526001600160a01b031660208301526001600160e01b031916604082015290565b610d9f8260038351611133565b610a658282611207565b610d9f8260028351611133565b610dc282600083611133565b5050565b6004546040805130606090811b60208084019190915260348084018690528451808503909101815260549093018452825192810192909220908801939093526000838152600590915281812080546001600160a01b0319166001600160a01b038a16179055905182917fb5e6e01e79f91267dc17b4e6314d5d4d03593d2ceee0fbb452b750bd70ea5af991a2606082600080886000015189602001518a604001518b606001518a8d608001516000015160405160240180896001600160a01b03168152602001888152602001878152602001866001600160a01b03168152602001856001600160e01b031916815260200184815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610efc578181015183820152602001610ee4565b50505050905090810190601f168015610f295780820380516001836020036101000a031916815260200191505b509950505050505050505050604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050509050600260009054906101000a90046001600160a01b03166001600160a01b0316634000aea08887846040518463ffffffff1660e01b815260040180846001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610ff2578181015183820152602001610fda565b50505050905090810190601f16801561101f5780820380516001836020036101000a031916815260200191505b50945050505050602060405180830381600087803b15801561104057600080fd5b505af1158015611054573d6000803e3d6000fd5b505050506040513d602081101561106a57600080fd5b50516110a75760405162461bcd60e51b815260040180806020018281038252602381526020018061187c6023913960400191505060405180910390fd5b5060048054600101905595945050505050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610abd575050151592915050565b6110fb61149d565b60208206156111105760208206602003820191505b506020808301829052604080518085526000815283019091019052815b92915050565b601781116111545761114e8360e0600585901b168317611228565b50610a65565b60ff811161117e57611171836018611fe0600586901b1617611228565b5061114e83826001611240565b61ffff81116111a95761119c836019611fe0600586901b1617611228565b5061114e83826002611240565b63ffffffff81116111d6576111c983601a611fe0600586901b1617611228565b5061114e83826004611240565b67ffffffffffffffff8111610a65576111fa83601b611fe0600586901b1617611228565b506109c283826008611240565b61120f61149d565b61122183846000015151848551611259565b9392505050565b61123061149d565b6112218384600001515184611305565b61124861149d565b610abd848560000151518585611350565b61126161149d565b825182111561126f57600080fd5b84602001518285011115611299576112998561129187602001518786016113ae565b6002026113c5565b6000808651805187602083010193508088870111156112b85787860182525b505050602084015b602084106112df5780518252601f1990930192602091820191016112c0565b51815160001960208690036101000a019081169019919091161790525083949350505050565b61130d61149d565b83602001518310611329576113298485602001516002026113c5565b835180516020858301018481535080851415611346576001810182525b5093949350505050565b61135861149d565b8460200151848301111561137557611375858584016002026113c5565b60006001836101000a0390508551838682010185831982511617815250805184870111156113a35783860181525b509495945050505050565b6000818311156113bf57508161112d565b50919050565b81516113d183836110f3565b506109c28382611207565b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826114125760008555611458565b82601f1061142b57805160ff1916838001178555611458565b82800160010185558215611458579182015b8281111561145857825182559160200191906001019061143d565b506114649291506114b7565b5090565b6040805160a08101825260008082526020820181905291810182905260608101919091526080810161149861149d565b905290565b604051806040016040528060608152602001600081525090565b5b8082111561146457600081556001016114b8565b600082601f8301126114dc578081fd5b815167ffffffffffffffff808211156114f157fe5b604051601f8301601f19168101602001828111828210171561150f57fe5b60405282815292508284830160200186101561152a57600080fd5b61153b83602083016020880161184f565b50505092915050565b600060208284031215611555578081fd5b5035919050565b60008060008060808587031215611571578283fd5b843593506020850135925060408501356001600160e01b031981168114611596578283fd5b9396929550929360600135925050565b600080600080606085870312156115bb578384fd5b8435935060208501359250604085013567ffffffffffffffff808211156115e0578384fd5b818701915087601f8301126115f3578384fd5b813581811115611601578485fd5b886020828501011115611612578485fd5b95989497505060200194505050565b600080600060608486031215611635578283fd5b8351925060208401519150604084015167ffffffffffffffff811115611659578182fd5b611665868287016114cc565b9150509250925092565b600060208284031215611680578081fd5b815167ffffffffffffffff811115611696578182fd5b610abd848285016114cc565b6000602082840312156116b3578081fd5b5051919050565b6000806000606084860312156116ce578283fd5b8351925060208401519150604084015190509250925092565b60609190911b6bffffffffffffffffffffffff1916815260140190565b6001600160a01b0391909116815260200190565b90815260200190565b60008582528460208301526060604083015282606083015282846080840137818301608090810191909152601f909201601f191601019392505050565b600084825283602083015260606040830152825180606084015261178981608085016020870161184f565b601f01601f191691909101608001949350505050565b6020808252603f908201527f4d4431436861696e6c696e6b416461707465723a2053656e646572206d75737460408201527f20626520746865206f7261636c652065787465726e616c206164617074657200606082015260800190565b60208082526033908201527f52657175657374206973206e6f74206f70656e206f722073656e64657220776160408201527239903737ba103a34329034b734ba34b0ba37b960691b606082015260800190565b60005b8381101561186a578181015183820152602001611852565b838111156109c2575050600091015256fe756e61626c6520746f207472616e73666572416e6443616c6c20746f206f7261636c65536f75726365206d75737420626520746865206f7261636c65206f662074686520726571756573745361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220700eed4f2212b99e8a07829fe330af0ec673afbabbff99e311fa008be2a31d9564736f6c63430007050033000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca00000000000000000000000001d3348601968ab85b4bb028979006eac235a588000000000000000000000000240bae5a27233fd3ac5440b5a598467725f7d1cd000000000000000000000000d26d233b5e444117d93cdbc676357b9c7ff559066365366562393532363736373431666438323462626636643132313163313031

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100b45760003560e01c806357b81b601161007157806357b81b601461012d57806357de26a4146101355780635ab383e01461014c57806361e072c314610154578063b6d6fe5014610169578063ec65d0f81461017c576100b4565b80630fe392f0146100b957806314411884146100e257806315e2e0f9146100f7578063205842351461010a5780632870b69114610112578063432d01371461011a575b600080fd5b6100cc6100c7366004611544565b61018f565b6040516100d99190611704565b60405180910390f35b6100f56100f0366004611544565b6101aa565b005b6100f56101053660046115a6565b6101eb565b6100cc6102f7565b6100cc61031b565b6100f5610128366004611544565b61033f565b6100cc6103f8565b61013d61041c565b6040516100d99392919061175e565b6100cc6104ba565b61015c6104de565b6040516100d99190611718565b6100f5610177366004611544565b610502565b6100f561018a36600461155c565b610980565b6000908152600660205260409020546001600160a01b031690565b6101df6001600160a01b037f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca163330846109c8565b6101e881610502565b50565b336001600160a01b037f000000000000000000000000d26d233b5e444117d93cdbc676357b9c7ff55906161461023c5760405162461bcd60e51b81526004016102339061179f565b60405180910390fd5b604051806060016040528085815260200184815260200183838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505091525080516007908155602080830151600855604083015180516102b09260099201906113dc565b509050507f29dc752488242557497b1331104cbf61a8661935cbf8ce1561874fc042a31f66848484846040516102e99493929190611721565b60405180910390a150505050565b7f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca81565b7f000000000000000000000000240bae5a27233fd3ac5440b5a598467725f7d1cd81565b60008181526005602052604090205481906001600160a01b031633146103965760405162461bcd60e51b815260040180806020018281038252602881526020018061189f6028913960400191505060405180910390fd5b60008181526005602052604080822080546001600160a01b03191690555182917f7cc135e0cebb02c3480ae5d74d377283180a2601f8f644edf7987b009316c63a91a250600090815260066020526040902080546001600160a01b0319169055565b7f000000000000000000000000d26d233b5e444117d93cdbc676357b9c7ff5590681565b60075460085460098054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104ae5780601f10610483576101008083540402835291602001916104ae565b820191906000526020600020905b81548152906001019060200180831161049157829003601f168201915b50505050509050909192565b7f00000000000000000000000001d3348601968ab85b4bb028979006eac235a58881565b7f636536656239353236373637343166643832346262663664313231316331303181565b60607f00000000000000000000000001d3348601968ab85b4bb028979006eac235a5886001600160a01b031663ee90a3156040518163ffffffff1660e01b815260040160006040518083038186803b15801561055d57600080fd5b505afa158015610571573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610599919081019061166f565b905060008060007f00000000000000000000000001d3348601968ab85b4bb028979006eac235a5886001600160a01b031663368e4d166040518163ffffffff1660e01b815260040160606040518083038186803b1580156105f957600080fd5b505afa15801561060d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063191906116ba565b92509250925060607f00000000000000000000000001d3348601968ab85b4bb028979006eac235a5886001600160a01b03166314d350436040518163ffffffff1660e01b815260040160006040518083038186803b15801561069257600080fd5b505afa1580156106a6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106ce9190810190611621565b9250505060007f00000000000000000000000001d3348601968ab85b4bb028979006eac235a5886001600160a01b031663c9afde0c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561072d57600080fd5b505afa158015610741573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076591906116a2565b905061076f611468565b6107a17f63653665623935323637363734316664383234626266366431323131633130313063432d013760e01b610a22565b90506107f76040518060400160405280600f81526020016e63616c6c6261636b4164647265737360881b815250306040516020016107df91906116e7565b60408051601f19818403018152919052839190610a47565b60408051808201909152600881526769706e734e616d6560c01b602082015261082290829089610a6a565b60408051808201909152601881527f6d61726b65744d616b657252657761726473416d6f756e740000000000000000602082015261086290829088610a88565b6040805180820190915260138152721d1c9859195c94995dd85c991cd05b5bdd5b9d606a1b602082015261089890829087610a88565b60408051808201909152601081526f74726164657253636f7265416c70686160801b60208201526108cb90829086610a88565b6040805180820190915260118152701858dd1a5d99549bdbdd125c199cd0da59607a1b60208201526108ff90829085610a47565b6040805180820190915260088152670dccaee8ae0dec6d60c31b602082015261092a90829084610a88565b60006109577f000000000000000000000000240bae5a27233fd3ac5440b5a598467725f7d1cd838b610aa6565b600090815260066020526040902080546001600160a01b03191633179055505050505050505050565b6000848152600660205260409020546001600160a01b031633146109b65760405162461bcd60e51b8152600401610233906117fc565b6109c284848484610ac5565b50505050565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526109c2908590610b9d565b610a2a611468565b610a32611468565b610a3e81868686610d55565b95945050505050565b6080830151610a569083610d92565b6080830151610a659082610da9565b505050565b6080830151610a799083610d92565b6080830151610a659082610d92565b6080830151610a979083610d92565b6080830151610a659082610db6565b6000610abd84848460016320214ca360e11b610dc6565b949350505050565b60008481526005602052604080822080546001600160a01b0319811690915590516001600160a01b039091169186917fe1fe3afa0f7f761ff0a8b89086790efd5140d2907ebd5b7ff6bfcb5e075fd4c59190a260408051636ee4d55360e01b815260048101879052602481018690526001600160e01b0319851660448201526064810184905290516001600160a01b03831691636ee4d55391608480830192600092919082900301818387803b158015610b7e57600080fd5b505af1158015610b92573d6000803e3d6000fd5b505050505050505050565b610baf826001600160a01b03166110ba565b610c00576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b60208310610c3e5780518252601f199092019160209182019101610c1f565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610ca0576040519150601f19603f3d011682016040523d82523d6000602084013e610ca5565b606091505b509150915081610cfc576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156109c257808060200190516020811015610d1857600080fd5b50516109c25760405162461bcd60e51b815260040180806020018281038252602a8152602001806118c7602a913960400191505060405180910390fd5b610d5d611468565b610d6d85608001516101006110f3565b50509183526001600160a01b031660208301526001600160e01b031916604082015290565b610d9f8260038351611133565b610a658282611207565b610d9f8260028351611133565b610dc282600083611133565b5050565b6004546040805130606090811b60208084019190915260348084018690528451808503909101815260549093018452825192810192909220908801939093526000838152600590915281812080546001600160a01b0319166001600160a01b038a16179055905182917fb5e6e01e79f91267dc17b4e6314d5d4d03593d2ceee0fbb452b750bd70ea5af991a2606082600080886000015189602001518a604001518b606001518a8d608001516000015160405160240180896001600160a01b03168152602001888152602001878152602001866001600160a01b03168152602001856001600160e01b031916815260200184815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610efc578181015183820152602001610ee4565b50505050905090810190601f168015610f295780820380516001836020036101000a031916815260200191505b509950505050505050505050604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050509050600260009054906101000a90046001600160a01b03166001600160a01b0316634000aea08887846040518463ffffffff1660e01b815260040180846001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610ff2578181015183820152602001610fda565b50505050905090810190601f16801561101f5780820380516001836020036101000a031916815260200191505b50945050505050602060405180830381600087803b15801561104057600080fd5b505af1158015611054573d6000803e3d6000fd5b505050506040513d602081101561106a57600080fd5b50516110a75760405162461bcd60e51b815260040180806020018281038252602381526020018061187c6023913960400191505060405180910390fd5b5060048054600101905595945050505050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610abd575050151592915050565b6110fb61149d565b60208206156111105760208206602003820191505b506020808301829052604080518085526000815283019091019052815b92915050565b601781116111545761114e8360e0600585901b168317611228565b50610a65565b60ff811161117e57611171836018611fe0600586901b1617611228565b5061114e83826001611240565b61ffff81116111a95761119c836019611fe0600586901b1617611228565b5061114e83826002611240565b63ffffffff81116111d6576111c983601a611fe0600586901b1617611228565b5061114e83826004611240565b67ffffffffffffffff8111610a65576111fa83601b611fe0600586901b1617611228565b506109c283826008611240565b61120f61149d565b61122183846000015151848551611259565b9392505050565b61123061149d565b6112218384600001515184611305565b61124861149d565b610abd848560000151518585611350565b61126161149d565b825182111561126f57600080fd5b84602001518285011115611299576112998561129187602001518786016113ae565b6002026113c5565b6000808651805187602083010193508088870111156112b85787860182525b505050602084015b602084106112df5780518252601f1990930192602091820191016112c0565b51815160001960208690036101000a019081169019919091161790525083949350505050565b61130d61149d565b83602001518310611329576113298485602001516002026113c5565b835180516020858301018481535080851415611346576001810182525b5093949350505050565b61135861149d565b8460200151848301111561137557611375858584016002026113c5565b60006001836101000a0390508551838682010185831982511617815250805184870111156113a35783860181525b509495945050505050565b6000818311156113bf57508161112d565b50919050565b81516113d183836110f3565b506109c28382611207565b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826114125760008555611458565b82601f1061142b57805160ff1916838001178555611458565b82800160010185558215611458579182015b8281111561145857825182559160200191906001019061143d565b506114649291506114b7565b5090565b6040805160a08101825260008082526020820181905291810182905260608101919091526080810161149861149d565b905290565b604051806040016040528060608152602001600081525090565b5b8082111561146457600081556001016114b8565b600082601f8301126114dc578081fd5b815167ffffffffffffffff808211156114f157fe5b604051601f8301601f19168101602001828111828210171561150f57fe5b60405282815292508284830160200186101561152a57600080fd5b61153b83602083016020880161184f565b50505092915050565b600060208284031215611555578081fd5b5035919050565b60008060008060808587031215611571578283fd5b843593506020850135925060408501356001600160e01b031981168114611596578283fd5b9396929550929360600135925050565b600080600080606085870312156115bb578384fd5b8435935060208501359250604085013567ffffffffffffffff808211156115e0578384fd5b818701915087601f8301126115f3578384fd5b813581811115611601578485fd5b886020828501011115611612578485fd5b95989497505060200194505050565b600080600060608486031215611635578283fd5b8351925060208401519150604084015167ffffffffffffffff811115611659578182fd5b611665868287016114cc565b9150509250925092565b600060208284031215611680578081fd5b815167ffffffffffffffff811115611696578182fd5b610abd848285016114cc565b6000602082840312156116b3578081fd5b5051919050565b6000806000606084860312156116ce578283fd5b8351925060208401519150604084015190509250925092565b60609190911b6bffffffffffffffffffffffff1916815260140190565b6001600160a01b0391909116815260200190565b90815260200190565b60008582528460208301526060604083015282606083015282846080840137818301608090810191909152601f909201601f191601019392505050565b600084825283602083015260606040830152825180606084015261178981608085016020870161184f565b601f01601f191691909101608001949350505050565b6020808252603f908201527f4d4431436861696e6c696e6b416461707465723a2053656e646572206d75737460408201527f20626520746865206f7261636c652065787465726e616c206164617074657200606082015260800190565b60208082526033908201527f52657175657374206973206e6f74206f70656e206f722073656e64657220776160408201527239903737ba103a34329034b734ba34b0ba37b960691b606082015260800190565b60005b8381101561186a578181015183820152602001611852565b838111156109c2575050600091015256fe756e61626c6520746f207472616e73666572416e6443616c6c20746f206f7261636c65536f75726365206d75737420626520746865206f7261636c65206f662074686520726571756573745361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220700eed4f2212b99e8a07829fe330af0ec673afbabbff99e311fa008be2a31d9564736f6c63430007050033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca00000000000000000000000001d3348601968ab85b4bb028979006eac235a588000000000000000000000000240bae5a27233fd3ac5440b5a598467725f7d1cd000000000000000000000000d26d233b5e444117d93cdbc676357b9c7ff559066365366562393532363736373431666438323462626636643132313163313031

-----Decoded View---------------
Arg [0] : chainlinkToken (address): 0x514910771AF9Ca656af840dff83E8264EcF986CA
Arg [1] : merkleDistributor (address): 0x01d3348601968aB85b4bb028979006eac235a588
Arg [2] : oracleContract (address): 0x240BaE5A27233Fd3aC5440B5a598467725F7D1cd
Arg [3] : oracleExternalAdapter (address): 0xD26d233b5e444117d93CdbC676357b9C7Ff55906
Arg [4] : jobId (bytes32): 0x6365366562393532363736373431666438323462626636643132313163313031

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca
Arg [1] : 00000000000000000000000001d3348601968ab85b4bb028979006eac235a588
Arg [2] : 000000000000000000000000240bae5a27233fd3ac5440b5a598467725f7d1cd
Arg [3] : 000000000000000000000000d26d233b5e444117d93cdbc676357b9c7ff55906
Arg [4] : 6365366562393532363736373431666438323462626636643132313163313031


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

 

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
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.