"notice":"Called when LINK is sent to the contract via `transferAndCall`"
}
}
}
},
"sources":{
"LinkTokenReceiver.sol":{
"id":2
}
},
"sourceCodes":{
"LinkTokenReceiver.sol":"pragma solidity ^0.5.0;\n\ncontract LinkTokenReceiver {\n\n bytes4 constant private ORACLE_REQUEST_SELECTOR = 0x40429946;\n uint256 constant private SELECTOR_LENGTH = 4;\n uint256 constant private EXPECTED_REQUEST_WORDS = 2;\n uint256 constant private MINIMUM_REQUEST_LENGTH = SELECTOR_LENGTH + (32 * EXPECTED_REQUEST_WORDS);\n /**\n * @notice Called when LINK is sent to the contract via `transferAndCall`\n * @dev The data payload's first 2 words will be overwritten by the `_sender` and `_amount`\n * values to ensure correctness. Calls oracleRequest.\n * @param _sender Address of the sender\n * @param _amount Amount of LINK sent (specified in wei)\n * @param _data Payload of the transaction\n */\n function onTokenTransfer(\n address _sender,\n uint256 _amount,\n bytes memory _data\n )\n public\n onlyLINK\n validRequestLength(_data)\n permittedFunctionsForLINK(_data)\n {\n assembly {\n // solhint-disable-next-line avoid-low-level-calls\n mstore(add(_data, 36), _sender) // ensure correct sender is passed\n // solhint-disable-next-line avoid-low-level-calls\n mstore(add(_data, 68), _amount) // ensure correct amount is passed\n }\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, ) = address(this).delegatecall(_data); // calls oracleRequest\n require(success, \"Unable to create request\");\n }\n\n function getChainlinkToken() public view returns (address);\n\n /**\n * @dev Reverts if not sent from the LINK token\n */\n modifier onlyLINK() {\n require(msg.sender == getChainlinkToken(), \"Must use LINK token\");\n _;\n }\n\n /**\n * @dev Reverts if the given data does not begin with the `oracleRequest` function selector\n * @param _data The data payload of the request\n */\n modifier permittedFunctionsForLINK(bytes memory _data) {\n bytes4 funcSelector;\n assembly {\n // solhint-disable-next-line avoid-low-level-calls\n funcSelector := mload(add(_data, 32))\n }\n require(funcSelector == ORACLE_REQUEST_SELECTOR, \"Must use whitelisted functions\");\n _;\n }\n\n /**\n * @dev Reverts if the given payload is less than needed to create a request\n * @param _data The request payload\n */\n modifier validRequestLength(bytes memory _data) {\n require(_data.length >= MINIMUM_REQUEST_LENGTH, \"Invalid request length\");\n _;\n }\n}"
"vendor/Buffer.sol":"pragma solidity ^0.5.0;\n\n/**\n* @dev A library for working with mutable byte buffers in Solidity.\n*\n* Byte buffers are mutable and expandable, and provide a variety of primitives\n* for writing to them. At any time you can fetch a bytes object containing the\n* current contents of the buffer. The bytes object should not be stored between\n* operations, as it may change due to resizing of the buffer.\n*/\nlibrary Buffer {\n /**\n * @dev Represents a mutable buffer. Buffers have a current value (buf) and\n * a capacity. The capacity may be longer than the current value, in\n * which case it can be extended without the need to allocate more memory.\n */\n struct buffer {\n bytes buf;\n uint capacity;\n }\n\n /**\n * @dev Initializes a buffer with an initial capacity.\n * @param buf The buffer to initialize.\n * @param capacity The number of bytes of space to allocate the buffer.\n * @return The buffer, for chaining.\n */\n function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {\n if (capacity % 32 != 0) {\n capacity += 32 - (capacity % 32);\n }\n // Allocate space for the buffer data\n buf.capacity = capacity;\n assembly {\n let ptr := mload(0x40)\n mstore(buf, ptr)\n mstore(ptr, 0)\n mstore(0x40, add(32, add(ptr, capacity)))\n }\n return buf;\n }\n\n /**\n * @dev Initializes a new buffer from an existing bytes object.\n * Changes to the buffer may mutate the original value.\n * @param b The bytes object to initialize the buffer with.\n * @return A new buffer.\n */\n function fromBytes(bytes memory b) internal pure returns(buffer memory) {\n buffer memory buf;\n buf.buf = b;\n buf.capacity = b.length;\n return buf;\n }\n\n function resize(buffer memory buf, uint capacity) private pure {\n bytes memory oldbuf = buf.buf;\n init(buf, capacity);\n append(buf, oldbuf);\n }\n\n function max(uint a, uint b) private pure returns(uint) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n /**\n * @dev Sets buffer length to 0.\n * @param buf The buffer to truncate.\n * @return The original buffer, for chaining..\n */\n function truncate(buffer memory buf) internal pure returns (buffer memory) {\n assembly {\n let bufptr := mload(buf)\n mstore(bufptr, 0)\n }\n return buf;\n }\n\n /**\n * @dev Writes a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The start offset to write to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {\n require(len <= data.length);\n\n if (off + len > buf.capacity) {\n resize(buf, max(buf.capacity, len + off) * 2);\n }\n\n uint dest;\n uint src;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Start address = buffer address + offset + sizeof(buffer length)\n dest := add(add(bufptr, 32), off)\n // Update buffer length if we're extending it\n if gt(add(len, off), buflen) {\n mstore(bufptr, add(len, off))\n }\n src := add(data, 32)\n }\n\n // Copy word-length chunks while possible\n for (; len >= 32; len -= 32) {\n assembly {\n mstore(dest, mload(src))\n }\n dest += 32;\n src += 32;\n }\n\n // Copy remaining bytes\n uint mask = 256 ** (32 - len) - 1;\n assembly {\n let srcpart := and(mload(src), not(mask))\n let destpart := and(mload(dest), mask)\n mstore(dest, or(destpart, srcpart))\n }\n\n return buf;\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, len);\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, data.length);\n }\n\n /**\n * @dev Writes a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write the byte at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {\n if (off >= buf.capacity) {\n resize(buf, buf.capacity * 2);\n }\n\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Address = buffer address + sizeof(buffer length) + off\n let dest := add(add(bufptr, off), 32)\n mstore8(dest, data)\n // Update buffer length if we extended it\n if eq(off, buflen) {\n mstore(bufptr, add(buflen, 1))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {\n return writeUint8(buf, buf.buf.length, data);\n }\n\n /**\n * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (left-aligned).\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n // Right-align data\n data = data >> (8 * (32 - len));\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + sizeof(buffer length) + off + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, off, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chhaining.\n */\n function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, 32);\n }\n\n /**\n * @dev Writes an integer to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (right-aligned).\n * @return The original buffer, for chaining.\n */\n function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + off + sizeof(buffer length) + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer.\n */\n function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n return writeInt(buf, buf.buf.length, data, len);\n }\n}"
"vendor/Buffer.sol":"pragma solidity ^0.5.0;\n\n/**\n* @dev A library for working with mutable byte buffers in Solidity.\n*\n* Byte buffers are mutable and expandable, and provide a variety of primitives\n* for writing to them. At any time you can fetch a bytes object containing the\n* current contents of the buffer. The bytes object should not be stored between\n* operations, as it may change due to resizing of the buffer.\n*/\nlibrary Buffer {\n /**\n * @dev Represents a mutable buffer. Buffers have a current value (buf) and\n * a capacity. The capacity may be longer than the current value, in\n * which case it can be extended without the need to allocate more memory.\n */\n struct buffer {\n bytes buf;\n uint capacity;\n }\n\n /**\n * @dev Initializes a buffer with an initial capacity.\n * @param buf The buffer to initialize.\n * @param capacity The number of bytes of space to allocate the buffer.\n * @return The buffer, for chaining.\n */\n function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {\n if (capacity % 32 != 0) {\n capacity += 32 - (capacity % 32);\n }\n // Allocate space for the buffer data\n buf.capacity = capacity;\n assembly {\n let ptr := mload(0x40)\n mstore(buf, ptr)\n mstore(ptr, 0)\n mstore(0x40, add(32, add(ptr, capacity)))\n }\n return buf;\n }\n\n /**\n * @dev Initializes a new buffer from an existing bytes object.\n * Changes to the buffer may mutate the original value.\n * @param b The bytes object to initialize the buffer with.\n * @return A new buffer.\n */\n function fromBytes(bytes memory b) internal pure returns(buffer memory) {\n buffer memory buf;\n buf.buf = b;\n buf.capacity = b.length;\n return buf;\n }\n\n function resize(buffer memory buf, uint capacity) private pure {\n bytes memory oldbuf = buf.buf;\n init(buf, capacity);\n append(buf, oldbuf);\n }\n\n function max(uint a, uint b) private pure returns(uint) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n /**\n * @dev Sets buffer length to 0.\n * @param buf The buffer to truncate.\n * @return The original buffer, for chaining..\n */\n function truncate(buffer memory buf) internal pure returns (buffer memory) {\n assembly {\n let bufptr := mload(buf)\n mstore(bufptr, 0)\n }\n return buf;\n }\n\n /**\n * @dev Writes a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The start offset to write to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {\n require(len <= data.length);\n\n if (off + len > buf.capacity) {\n resize(buf, max(buf.capacity, len + off) * 2);\n }\n\n uint dest;\n uint src;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Start address = buffer address + offset + sizeof(buffer length)\n dest := add(add(bufptr, 32), off)\n // Update buffer length if we're extending it\n if gt(add(len, off), buflen) {\n mstore(bufptr, add(len, off))\n }\n src := add(data, 32)\n }\n\n // Copy word-length chunks while possible\n for (; len >= 32; len -= 32) {\n assembly {\n mstore(dest, mload(src))\n }\n dest += 32;\n src += 32;\n }\n\n // Copy remaining bytes\n uint mask = 256 ** (32 - len) - 1;\n assembly {\n let srcpart := and(mload(src), not(mask))\n let destpart := and(mload(dest), mask)\n mstore(dest, or(destpart, srcpart))\n }\n\n return buf;\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, len);\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, data.length);\n }\n\n /**\n * @dev Writes a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write the byte at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {\n if (off >= buf.capacity) {\n resize(buf, buf.capacity * 2);\n }\n\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Address = buffer address + sizeof(buffer length) + off\n let dest := add(add(bufptr, off), 32)\n mstore8(dest, data)\n // Update buffer length if we extended it\n if eq(off, buflen) {\n mstore(bufptr, add(buflen, 1))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {\n return writeUint8(buf, buf.buf.length, data);\n }\n\n /**\n * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (left-aligned).\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n // Right-align data\n data = data >> (8 * (32 - len));\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + sizeof(buffer length) + off + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, off, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chhaining.\n */\n function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, 32);\n }\n\n /**\n * @dev Writes an integer to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (right-aligned).\n * @return The original buffer, for chaining.\n */\n function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + off + sizeof(buffer length) + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer.\n */\n function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n return writeInt(buf, buf.buf.length, data, len);\n }\n}",
"ChainlinkClient.sol":"pragma solidity ^0.5.0;\n\nimport \"./Chainlink.sol\";\nimport \"./interfaces/ENSInterface.sol\";\nimport \"./interfaces/LinkTokenInterface.sol\";\nimport \"./interfaces/ChainlinkRequestInterface.sol\";\nimport \"./interfaces/PointerInterface.sol\";\nimport { ENSResolver as ENSResolver_Chainlink } from \"./vendor/ENSResolver.sol\";\n\n/**\n * @title The ChainlinkClient contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network\n */\ncontract ChainlinkClient {\n using Chainlink for Chainlink.Request;\n\n uint256 constant internal LINK = 10**18;\n uint256 constant private AMOUNT_OVERRIDE = 0;\n address constant private SENDER_OVERRIDE = address(0);\n uint256 constant private ARGS_VERSION = 1;\n bytes32 constant private ENS_TOKEN_SUBNAME = keccak256(\"link\");\n bytes32 constant private ENS_ORACLE_SUBNAME = keccak256(\"oracle\");\n address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;\n\n ENSInterface private ens;\n bytes32 private ensNode;\n LinkTokenInterface private link;\n ChainlinkRequestInterface private oracle;\n uint256 private requestCount = 1;\n mapping(bytes32 => address) private pendingRequests;\n\n event ChainlinkRequested(bytes32 indexed id);\n event ChainlinkFulfilled(bytes32 indexed id);\n event ChainlinkCancelled(bytes32 indexed id);\n\n /**\n * @notice Creates a request that can hold additional parameters\n * @param _specId The Job Specification ID that the request will be created for\n * @param _callbackAddress The callback address that the response will be sent to\n * @param _callbackFunctionSignature The callback function signature to use for the callback address\n * @return A Chainlink Request struct in memory\n */\n function buildChainlinkRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n Chainlink.Request memory req;\n return req.initialize(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `chainlinkRequestTo` with the stored oracle address\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequestTo(address(oracle), _req, _payment);\n }\n\n /**\n * @notice Creates a Chainlink request to the specified oracle address\n * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to\n * send LINK which creates a request on the target oracle contract.\n * Emits ChainlinkRequested event.\n * @param _oracle The address of the oracle for the request\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n requestId = keccak256(abi.encodePacked(this, requestCount));\n _req.nonce = requestCount;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requestCount += 1;\n\n return requestId;\n }\n\n /**\n * @notice Allows a request to be cancelled if it has not been fulfilled\n * @dev Requires keeping track of the expiration value emitted from the oracle contract.\n * Deletes the request from the `pendingRequests` mapping.\n * Emits ChainlinkCancelled event.\n * @param _requestId The request ID\n * @param _payment The amount of LINK sent for the request\n * @param _callbackFunc The callback function specified for the request\n * @param _expiration The time of the expiration for the request\n */\n function cancelChainlinkRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunc,\n uint256 _expiration\n )\n internal\n {\n ChainlinkRequestInterface requested = ChainlinkRequestInterface(pendingRequests[_requestId]);\n delete pendingRequests[_requestId];\n emit ChainlinkCancelled(_requestId);\n requested.cancelOracleRequest(_requestId, _payment, _callbackFunc, _expiration);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setChainlinkOracle(address _oracle) internal {\n oracle = ChainlinkRequestInterface(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setChainlinkToken(address _link) internal {\n link = LinkTokenInterface(_link);\n }\n\n /**\n * @notice Sets the Chainlink token address for the public\n * network as given by the Pointer contract\n */\n function setPublicChainlinkToken() internal {\n setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkTokenAddress()\n internal\n view\n returns (address)\n {\n return address(link);\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function chainlinkOracleAddress()\n internal\n view\n returns (address)\n {\n return address(oracle);\n }\n\n /**\n * @notice Allows for a request which was created on another contract to be fulfilled\n * on this contract\n * @param _oracle The address of the oracle contract that will fulfill the request\n * @param _requestId The request ID used for the response\n */\n function addChainlinkExternalRequest(address _oracle, bytes32 _requestId)\n internal\n notPendingRequest(_requestId)\n {\n pendingRequests[_requestId] = _oracle;\n }\n\n /**\n * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS\n * @dev Accounts for subnodes having different resolvers\n * @param _ens The address of the ENS contract\n * @param _node The ENS node hash\n */\n function useChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n ens = ENSInterface(_ens);\n ensNode = _node;\n bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));\n setChainlinkToken(resolver.addr(linkSubnode));\n updateChainlinkOracleWithENS();\n }\n\n /**\n * @notice Sets the stored oracle contract with the address resolved by ENS\n * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously\n */\n function updateChainlinkOracleWithENS()\n internal\n {\n bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));\n setChainlinkOracle(resolver.addr(oracleSubnode));\n }\n\n /**\n * @notice Encodes the request to be sent to the oracle contract\n * @dev The Chainlink node expects values to be in order for the request to be picked up. Order of types\n * will be validated in the oracle contract.\n * @param _req The initialized Chainlink Request\n * @return The bytes payload for the `transferAndCall` method\n */\n function encodeRequest(Chainlink.Request memory _req)\n private\n view\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n oracle.oracleRequest.selector,\n SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address\n AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent\n _req.id,\n _req.callbackAddress,\n _req.callbackFunctionId,\n _req.nonce,\n ARGS_VERSION,\n _req.buf.buf);\n }\n\n /**\n * @notice Ensures that the fulfillment is valid for this contract\n * @dev Use if the contract developer prefers methods instead of modifiers for validation\n * @param _requestId The request ID for fulfillment\n */\n function validateChainlinkCallback(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\n {}\n\n /**\n * @dev Reverts if the sender is not the oracle of the request.\n * Emits ChainlinkFulfilled event.\n * @param _requestId The request ID for fulfillment\n */\n modifier recordChainlinkFulfillment(bytes32 _requestId) {\n require(msg.sender == pendingRequests[_requestId],\n\"Source must be the oracle of the request\");\n delete pendingRequests[_requestId];\n emit ChainlinkFulfilled(_requestId);\n _;\n }\n\n /**\n * @dev Reverts if the request is already pending\n * @param _requestId The request ID for fulfillment\n */\n modifier notPendingRequest(bytes32 _requestId) {\n require(pendingRequests[_requestId] == address(0), \"Request is already pending\");\n _;\n }\n}\n",
"Chainlink.sol":"pragma solidity ^0.5.0;\n\nimport { CBOR as CBOR_Chainlink } from \"./vendor/CBOR.sol\";\nimport { Buffer as Buffer_Chainlink } from \"./vendor/Buffer.sol\";\n\n/**\n * @title Library for common Chainlink functions\n * @dev Uses imported CBOR library for encoding to buffer\n */\nlibrary Chainlink {\n uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase\n\n using CBOR_Chainlink for Buffer_Chainlink.buffer;\n\n struct Request {\n bytes32 id;\n address callbackAddress;\n bytes4 callbackFunctionId;\n uint256 nonce;\n Buffer_Chainlink.buffer buf;\n }\n\n /**\n * @notice Initializes a Chainlink request\n * @dev Sets the ID, callback address, and callback function signature on the request\n * @param self The uninitialized request\n * @param _id The Job Specification ID\n * @param _callbackAddress The callback address\n * @param _callbackFunction The callback function signature\n * @return The initialized request\n */\n function initialize(\n Request memory self,\n bytes32 _id,\n address _callbackAddress,\n bytes4 _callbackFunction\n ) internal pure returns (Chainlink.Request memory) {\n Buffer_Chainlink.init(self.buf, defaultBufferSize);\n self.id = _id;\n self.callbackAddress = _callbackAddress;\n self.callbackFunctionId = _callbackFunction;\n return self;\n }\n\n /**\n * @notice Sets the data for the buffer without encoding CBOR on-chain\n * @dev CBOR can be closed with curly-brackets {} or they can be left off\n * @param self The initialized request\n * @param _data The CBOR data\n */\n function setBuffer(Request memory self, bytes memory _data)\n internal pure\n {\n Buffer_Chainlink.init(self.buf, _data.length);\n Buffer_Chainlink.append(self.buf, _data);\n }\n\n /**\n * @notice Adds a string value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The string value to add\n */\n function add(Request memory self, string memory _key, string memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeString(_value);\n }\n\n /**\n * @notice Adds a bytes value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The bytes value to add\n */\n function addBytes(Request memory self, string memory _key, bytes memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeBytes(_value);\n }\n\n /**\n * @notice Adds a int256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The int256 value to add\n */\n function addInt(Request memory self, string memory _key, int256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeInt(_value);\n }\n\n /**\n * @notice Adds a uint256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The uint256 value to add\n */\n function addUint(Request memory self, string memory _key, uint256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeUInt(_value);\n }\n\n /**\n * @notice Adds an array of strings to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _values The array of string values to add\n */\n function addStringArray(Request memory self, string memory _key, string[] memory _values)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.startArray();\n for (uint256 i = 0; i < _values.length; i++) {\n self.buf.encodeString(_values[i]);\n }\n self.buf.endSequence();\n }\n}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.5.0;\n\ninterface ENSInterface {\n\n // Logged when the owner of a node assigns a new owner to a subnode.\n event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);\n\n // Logged when the owner of a node transfers ownership to a new account.\n event Transfer(bytes32 indexed node, address owner);\n\n // Logged when the resolver for a node changes.\n event NewResolver(bytes32 indexed node, address resolver);\n\n // Logged when the TTL of a node changes\n event NewTTL(bytes32 indexed node, uint64 ttl);\n\n\n function setSubnodeOwner(bytes32 node, bytes32 label, address _owner) external;\n function setResolver(bytes32 node, address _resolver) external;\n function setOwner(bytes32 node, address _owner) external;\n function setTTL(bytes32 node, uint64 _ttl) external;\n function owner(bytes32 node) external view returns (address);\n function resolver(bytes32 node) external view returns (address);\n function ttl(bytes32 node) external view returns (uint64);\n\n}\n",
"interfaces/LinkTokenInterface.sol":"pragma solidity ^0.5.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n function approve(address spender, uint256 value) external returns (bool success);\n function balanceOf(address owner) external view returns (uint256 balance);\n function decimals() external view returns (uint8 decimalPlaces);\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n function increaseApproval(address spender, uint256 subtractedValue) external;\n function name() external view returns (string memory tokenName);\n function symbol() external view returns (string memory tokenSymbol);\n function totalSupply() external view returns (uint256 totalTokensIssued);\n function transfer(address to, uint256 value) external returns (bool success);\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"vendor/ENSResolver.sol":"pragma solidity ^0.5.0;\n\ncontract ENSResolver {\n function addr(bytes32 node) public view returns (address);\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n"
"tests/MaliciousConsumer.sol":"pragma solidity 0.5.0;\n\nimport \"../ChainlinkClient.sol\";\nimport \"../vendor/SafeMathChainlink.sol\";\n\ncontract MaliciousConsumer is ChainlinkClient {\n using SafeMathChainlink for uint256;\n\n uint256 constant private ORACLE_PAYMENT = 1 * LINK;\n uint256 private expiration;\n\n constructor(address _link, address _oracle) public payable {\n setChainlinkToken(_link);\n setChainlinkOracle(_oracle);\n }\n\n function () external payable {} // solhint-disable-line no-empty-blocks\n\n function requestData(bytes32 _id, bytes memory _callbackFunc) public {\n Chainlink.Request memory req = buildChainlinkRequest(_id, address(this), bytes4(keccak256(_callbackFunc)));\n expiration = now.add(5 minutes); // solhint-disable-line not-rely-on-time\n sendChainlinkRequest(req, ORACLE_PAYMENT);\n }\n\n function assertFail(bytes32, bytes32) public pure {\n assert(1 == 2);\n }\n\n function cancelRequestOnFulfill(bytes32 _requestId, bytes32) public {\n cancelChainlinkRequest(\n _requestId,\n ORACLE_PAYMENT,\n this.cancelRequestOnFulfill.selector,\n expiration);\n }\n\n function remove() public {\n selfdestruct(address(0));\n }\n\n function stealEthCall(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {\n (bool success,) = address(this).call.value(100)(\"\"); // solhint-disable-line avoid-call-value\n require(success, \"Call failed\");\n }\n\n function stealEthSend(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {\n // solhint-disable-next-line check-send-result\n bool success = address(this).send(100); // solhint-disable-line multiple-sends\n require(success, \"Send failed\");\n }\n\n function stealEthTransfer(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {\n address(this).transfer(100);\n }\n\n function doesNothing(bytes32, bytes32) public pure {} // solhint-disable-line no-empty-blocks\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.5.0;\n\nimport \"./Chainlink.sol\";\nimport \"./interfaces/ENSInterface.sol\";\nimport \"./interfaces/LinkTokenInterface.sol\";\nimport \"./interfaces/ChainlinkRequestInterface.sol\";\nimport \"./interfaces/PointerInterface.sol\";\nimport { ENSResolver as ENSResolver_Chainlink } from \"./vendor/ENSResolver.sol\";\n\n/**\n * @title The ChainlinkClient contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network\n */\ncontract ChainlinkClient {\n using Chainlink for Chainlink.Request;\n\n uint256 constant internal LINK = 10**18;\n uint256 constant private AMOUNT_OVERRIDE = 0;\n address constant private SENDER_OVERRIDE = address(0);\n uint256 constant private ARGS_VERSION = 1;\n bytes32 constant private ENS_TOKEN_SUBNAME = keccak256(\"link\");\n bytes32 constant private ENS_ORACLE_SUBNAME = keccak256(\"oracle\");\n address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;\n\n ENSInterface private ens;\n bytes32 private ensNode;\n LinkTokenInterface private link;\n ChainlinkRequestInterface private oracle;\n uint256 private requestCount = 1;\n mapping(bytes32 => address) private pendingRequests;\n\n event ChainlinkRequested(bytes32 indexed id);\n event ChainlinkFulfilled(bytes32 indexed id);\n event ChainlinkCancelled(bytes32 indexed id);\n\n /**\n * @notice Creates a request that can hold additional parameters\n * @param _specId The Job Specification ID that the request will be created for\n * @param _callbackAddress The callback address that the response will be sent to\n * @param _callbackFunctionSignature The callback function signature to use for the callback address\n * @return A Chainlink Request struct in memory\n */\n function buildChainlinkRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n Chainlink.Request memory req;\n return req.initialize(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `chainlinkRequestTo` with the stored oracle address\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequestTo(address(oracle), _req, _payment);\n }\n\n /**\n * @notice Creates a Chainlink request to the specified oracle address\n * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to\n * send LINK which creates a request on the target oracle contract.\n * Emits ChainlinkRequested event.\n * @param _oracle The address of the oracle for the request\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n requestId = keccak256(abi.encodePacked(this, requestCount));\n _req.nonce = requestCount;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requestCount += 1;\n\n return requestId;\n }\n\n /**\n * @notice Allows a request to be cancelled if it has not been fulfilled\n * @dev Requires keeping track of the expiration value emitted from the oracle contract.\n * Deletes the request from the `pendingRequests` mapping.\n * Emits ChainlinkCancelled event.\n * @param _requestId The request ID\n * @param _payment The amount of LINK sent for the request\n * @param _callbackFunc The callback function specified for the request\n * @param _expiration The time of the expiration for the request\n */\n function cancelChainlinkRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunc,\n uint256 _expiration\n )\n internal\n {\n ChainlinkRequestInterface requested = ChainlinkRequestInterface(pendingRequests[_requestId]);\n delete pendingRequests[_requestId];\n emit ChainlinkCancelled(_requestId);\n requested.cancelOracleRequest(_requestId, _payment, _callbackFunc, _expiration);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setChainlinkOracle(address _oracle) internal {\n oracle = ChainlinkRequestInterface(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setChainlinkToken(address _link) internal {\n link = LinkTokenInterface(_link);\n }\n\n /**\n * @notice Sets the Chainlink token address for the public\n * network as given by the Pointer contract\n */\n function setPublicChainlinkToken() internal {\n setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkTokenAddress()\n internal\n view\n returns (address)\n {\n return address(link);\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function chainlinkOracleAddress()\n internal\n view\n returns (address)\n {\n return address(oracle);\n }\n\n /**\n * @notice Allows for a request which was created on another contract to be fulfilled\n * on this contract\n * @param _oracle The address of the oracle contract that will fulfill the request\n * @param _requestId The request ID used for the response\n */\n function addChainlinkExternalRequest(address _oracle, bytes32 _requestId)\n internal\n notPendingRequest(_requestId)\n {\n pendingRequests[_requestId] = _oracle;\n }\n\n /**\n * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS\n * @dev Accounts for subnodes having different resolvers\n * @param _ens The address of the ENS contract\n * @param _node The ENS node hash\n */\n function useChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n ens = ENSInterface(_ens);\n ensNode = _node;\n bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));\n setChainlinkToken(resolver.addr(linkSubnode));\n updateChainlinkOracleWithENS();\n }\n\n /**\n * @notice Sets the stored oracle contract with the address resolved by ENS\n * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously\n */\n function updateChainlinkOracleWithENS()\n internal\n {\n bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));\n setChainlinkOracle(resolver.addr(oracleSubnode));\n }\n\n /**\n * @notice Encodes the request to be sent to the oracle contract\n * @dev The Chainlink node expects values to be in order for the request to be picked up. Order of types\n * will be validated in the oracle contract.\n * @param _req The initialized Chainlink Request\n * @return The bytes payload for the `transferAndCall` method\n */\n function encodeRequest(Chainlink.Request memory _req)\n private\n view\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n oracle.oracleRequest.selector,\n SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address\n AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent\n _req.id,\n _req.callbackAddress,\n _req.callbackFunctionId,\n _req.nonce,\n ARGS_VERSION,\n _req.buf.buf);\n }\n\n /**\n * @notice Ensures that the fulfillment is valid for this contract\n * @dev Use if the contract developer prefers methods instead of modifiers for validation\n * @param _requestId The request ID for fulfillment\n */\n function validateChainlinkCallback(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\n {}\n\n /**\n * @dev Reverts if the sender is not the oracle of the request.\n * Emits ChainlinkFulfilled event.\n * @param _requestId The request ID for fulfillment\n */\n modifier recordChainlinkFulfillment(bytes32 _requestId) {\n require(msg.sender == pendingRequests[_requestId],\n\"Source must be the oracle of the request\");\n delete pendingRequests[_requestId];\n emit ChainlinkFulfilled(_requestId);\n _;\n }\n\n /**\n * @dev Reverts if the request is already pending\n * @param _requestId The request ID for fulfillment\n */\n modifier notPendingRequest(bytes32 _requestId) {\n require(pendingRequests[_requestId] == address(0), \"Request is already pending\");\n _;\n }\n}\n",
"Chainlink.sol":"pragma solidity ^0.5.0;\n\nimport { CBOR as CBOR_Chainlink } from \"./vendor/CBOR.sol\";\nimport { Buffer as Buffer_Chainlink } from \"./vendor/Buffer.sol\";\n\n/**\n * @title Library for common Chainlink functions\n * @dev Uses imported CBOR library for encoding to buffer\n */\nlibrary Chainlink {\n uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase\n\n using CBOR_Chainlink for Buffer_Chainlink.buffer;\n\n struct Request {\n bytes32 id;\n address callbackAddress;\n bytes4 callbackFunctionId;\n uint256 nonce;\n Buffer_Chainlink.buffer buf;\n }\n\n /**\n * @notice Initializes a Chainlink request\n * @dev Sets the ID, callback address, and callback function signature on the request\n * @param self The uninitialized request\n * @param _id The Job Specification ID\n * @param _callbackAddress The callback address\n * @param _callbackFunction The callback function signature\n * @return The initialized request\n */\n function initialize(\n Request memory self,\n bytes32 _id,\n address _callbackAddress,\n bytes4 _callbackFunction\n ) internal pure returns (Chainlink.Request memory) {\n Buffer_Chainlink.init(self.buf, defaultBufferSize);\n self.id = _id;\n self.callbackAddress = _callbackAddress;\n self.callbackFunctionId = _callbackFunction;\n return self;\n }\n\n /**\n * @notice Sets the data for the buffer without encoding CBOR on-chain\n * @dev CBOR can be closed with curly-brackets {} or they can be left off\n * @param self The initialized request\n * @param _data The CBOR data\n */\n function setBuffer(Request memory self, bytes memory _data)\n internal pure\n {\n Buffer_Chainlink.init(self.buf, _data.length);\n Buffer_Chainlink.append(self.buf, _data);\n }\n\n /**\n * @notice Adds a string value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The string value to add\n */\n function add(Request memory self, string memory _key, string memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeString(_value);\n }\n\n /**\n * @notice Adds a bytes value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The bytes value to add\n */\n function addBytes(Request memory self, string memory _key, bytes memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeBytes(_value);\n }\n\n /**\n * @notice Adds a int256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The int256 value to add\n */\n function addInt(Request memory self, string memory _key, int256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeInt(_value);\n }\n\n /**\n * @notice Adds a uint256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The uint256 value to add\n */\n function addUint(Request memory self, string memory _key, uint256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeUInt(_value);\n }\n\n /**\n * @notice Adds an array of strings to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _values The array of string values to add\n */\n function addStringArray(Request memory self, string memory _key, string[] memory _values)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.startArray();\n for (uint256 i = 0; i < _values.length; i++) {\n self.buf.encodeString(_values[i]);\n }\n self.buf.endSequence();\n }\n}\n",
"vendor/Buffer.sol":"pragma solidity ^0.5.0;\n\n/**\n* @dev A library for working with mutable byte buffers in Solidity.\n*\n* Byte buffers are mutable and expandable, and provide a variety of primitives\n* for writing to them. At any time you can fetch a bytes object containing the\n* current contents of the buffer. The bytes object should not be stored between\n* operations, as it may change due to resizing of the buffer.\n*/\nlibrary Buffer {\n /**\n * @dev Represents a mutable buffer. Buffers have a current value (buf) and\n * a capacity. The capacity may be longer than the current value, in\n * which case it can be extended without the need to allocate more memory.\n */\n struct buffer {\n bytes buf;\n uint capacity;\n }\n\n /**\n * @dev Initializes a buffer with an initial capacity.\n * @param buf The buffer to initialize.\n * @param capacity The number of bytes of space to allocate the buffer.\n * @return The buffer, for chaining.\n */\n function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {\n if (capacity % 32 != 0) {\n capacity += 32 - (capacity % 32);\n }\n // Allocate space for the buffer data\n buf.capacity = capacity;\n assembly {\n let ptr := mload(0x40)\n mstore(buf, ptr)\n mstore(ptr, 0)\n mstore(0x40, add(32, add(ptr, capacity)))\n }\n return buf;\n }\n\n /**\n * @dev Initializes a new buffer from an existing bytes object.\n * Changes to the buffer may mutate the original value.\n * @param b The bytes object to initialize the buffer with.\n * @return A new buffer.\n */\n function fromBytes(bytes memory b) internal pure returns(buffer memory) {\n buffer memory buf;\n buf.buf = b;\n buf.capacity = b.length;\n return buf;\n }\n\n function resize(buffer memory buf, uint capacity) private pure {\n bytes memory oldbuf = buf.buf;\n init(buf, capacity);\n append(buf, oldbuf);\n }\n\n function max(uint a, uint b) private pure returns(uint) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n /**\n * @dev Sets buffer length to 0.\n * @param buf The buffer to truncate.\n * @return The original buffer, for chaining..\n */\n function truncate(buffer memory buf) internal pure returns (buffer memory) {\n assembly {\n let bufptr := mload(buf)\n mstore(bufptr, 0)\n }\n return buf;\n }\n\n /**\n * @dev Writes a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The start offset to write to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {\n require(len <= data.length);\n\n if (off + len > buf.capacity) {\n resize(buf, max(buf.capacity, len + off) * 2);\n }\n\n uint dest;\n uint src;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Start address = buffer address + offset + sizeof(buffer length)\n dest := add(add(bufptr, 32), off)\n // Update buffer length if we're extending it\n if gt(add(len, off), buflen) {\n mstore(bufptr, add(len, off))\n }\n src := add(data, 32)\n }\n\n // Copy word-length chunks while possible\n for (; len >= 32; len -= 32) {\n assembly {\n mstore(dest, mload(src))\n }\n dest += 32;\n src += 32;\n }\n\n // Copy remaining bytes\n uint mask = 256 ** (32 - len) - 1;\n assembly {\n let srcpart := and(mload(src), not(mask))\n let destpart := and(mload(dest), mask)\n mstore(dest, or(destpart, srcpart))\n }\n\n return buf;\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, len);\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, data.length);\n }\n\n /**\n * @dev Writes a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write the byte at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {\n if (off >= buf.capacity) {\n resize(buf, buf.capacity * 2);\n }\n\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Address = buffer address + sizeof(buffer length) + off\n let dest := add(add(bufptr, off), 32)\n mstore8(dest, data)\n // Update buffer length if we extended it\n if eq(off, buflen) {\n mstore(bufptr, add(buflen, 1))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {\n return writeUint8(buf, buf.buf.length, data);\n }\n\n /**\n * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (left-aligned).\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n // Right-align data\n data = data >> (8 * (32 - len));\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + sizeof(buffer length) + off + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, off, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chhaining.\n */\n function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, 32);\n }\n\n /**\n * @dev Writes an integer to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (right-aligned).\n * @return The original buffer, for chaining.\n */\n function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + off + sizeof(buffer length) + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer.\n */\n function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n return writeInt(buf, buf.buf.length, data, len);\n }\n}",
"interfaces/ENSInterface.sol":"pragma solidity ^0.5.0;\n\ninterface ENSInterface {\n\n // Logged when the owner of a node assigns a new owner to a subnode.\n event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);\n\n // Logged when the owner of a node transfers ownership to a new account.\n event Transfer(bytes32 indexed node, address owner);\n\n // Logged when the resolver for a node changes.\n event NewResolver(bytes32 indexed node, address resolver);\n\n // Logged when the TTL of a node changes\n event NewTTL(bytes32 indexed node, uint64 ttl);\n\n\n function setSubnodeOwner(bytes32 node, bytes32 label, address _owner) external;\n function setResolver(bytes32 node, address _resolver) external;\n function setOwner(bytes32 node, address _owner) external;\n function setTTL(bytes32 node, uint64 _ttl) external;\n function owner(bytes32 node) external view returns (address);\n function resolver(bytes32 node) external view returns (address);\n function ttl(bytes32 node) external view returns (uint64);\n\n}\n",
"interfaces/LinkTokenInterface.sol":"pragma solidity ^0.5.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n function approve(address spender, uint256 value) external returns (bool success);\n function balanceOf(address owner) external view returns (uint256 balance);\n function decimals() external view returns (uint8 decimalPlaces);\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n function increaseApproval(address spender, uint256 subtractedValue) external;\n function name() external view returns (string memory tokenName);\n function symbol() external view returns (string memory tokenSymbol);\n function totalSupply() external view returns (uint256 totalTokensIssued);\n function transfer(address to, uint256 value) external returns (bool success);\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"vendor/ENSResolver.sol":"pragma solidity ^0.5.0;\n\ncontract ENSResolver {\n function addr(bytes32 node) public view returns (address);\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n"
"vendor/Buffer.sol":"pragma solidity ^0.5.0;\n\n/**\n* @dev A library for working with mutable byte buffers in Solidity.\n*\n* Byte buffers are mutable and expandable, and provide a variety of primitives\n* for writing to them. At any time you can fetch a bytes object containing the\n* current contents of the buffer. The bytes object should not be stored between\n* operations, as it may change due to resizing of the buffer.\n*/\nlibrary Buffer {\n /**\n * @dev Represents a mutable buffer. Buffers have a current value (buf) and\n * a capacity. The capacity may be longer than the current value, in\n * which case it can be extended without the need to allocate more memory.\n */\n struct buffer {\n bytes buf;\n uint capacity;\n }\n\n /**\n * @dev Initializes a buffer with an initial capacity.\n * @param buf The buffer to initialize.\n * @param capacity The number of bytes of space to allocate the buffer.\n * @return The buffer, for chaining.\n */\n function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {\n if (capacity % 32 != 0) {\n capacity += 32 - (capacity % 32);\n }\n // Allocate space for the buffer data\n buf.capacity = capacity;\n assembly {\n let ptr := mload(0x40)\n mstore(buf, ptr)\n mstore(ptr, 0)\n mstore(0x40, add(32, add(ptr, capacity)))\n }\n return buf;\n }\n\n /**\n * @dev Initializes a new buffer from an existing bytes object.\n * Changes to the buffer may mutate the original value.\n * @param b The bytes object to initialize the buffer with.\n * @return A new buffer.\n */\n function fromBytes(bytes memory b) internal pure returns(buffer memory) {\n buffer memory buf;\n buf.buf = b;\n buf.capacity = b.length;\n return buf;\n }\n\n function resize(buffer memory buf, uint capacity) private pure {\n bytes memory oldbuf = buf.buf;\n init(buf, capacity);\n append(buf, oldbuf);\n }\n\n function max(uint a, uint b) private pure returns(uint) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n /**\n * @dev Sets buffer length to 0.\n * @param buf The buffer to truncate.\n * @return The original buffer, for chaining..\n */\n function truncate(buffer memory buf) internal pure returns (buffer memory) {\n assembly {\n let bufptr := mload(buf)\n mstore(bufptr, 0)\n }\n return buf;\n }\n\n /**\n * @dev Writes a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The start offset to write to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {\n require(len <= data.length);\n\n if (off + len > buf.capacity) {\n resize(buf, max(buf.capacity, len + off) * 2);\n }\n\n uint dest;\n uint src;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Start address = buffer address + offset + sizeof(buffer length)\n dest := add(add(bufptr, 32), off)\n // Update buffer length if we're extending it\n if gt(add(len, off), buflen) {\n mstore(bufptr, add(len, off))\n }\n src := add(data, 32)\n }\n\n // Copy word-length chunks while possible\n for (; len >= 32; len -= 32) {\n assembly {\n mstore(dest, mload(src))\n }\n dest += 32;\n src += 32;\n }\n\n // Copy remaining bytes\n uint mask = 256 ** (32 - len) - 1;\n assembly {\n let srcpart := and(mload(src), not(mask))\n let destpart := and(mload(dest), mask)\n mstore(dest, or(destpart, srcpart))\n }\n\n return buf;\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, len);\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, data.length);\n }\n\n /**\n * @dev Writes a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write the byte at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {\n if (off >= buf.capacity) {\n resize(buf, buf.capacity * 2);\n }\n\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Address = buffer address + sizeof(buffer length) + off\n let dest := add(add(bufptr, off), 32)\n mstore8(dest, data)\n // Update buffer length if we extended it\n if eq(off, buflen) {\n mstore(bufptr, add(buflen, 1))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {\n return writeUint8(buf, buf.buf.length, data);\n }\n\n /**\n * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (left-aligned).\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n // Right-align data\n data = data >> (8 * (32 - len));\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + sizeof(buffer length) + off + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, off, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chhaining.\n */\n function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, 32);\n }\n\n /**\n * @dev Writes an integer to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (right-aligned).\n * @return The original buffer, for chaining.\n */\n function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + off + sizeof(buffer length) + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer.\n */\n function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n return writeInt(buf, buf.buf.length, data, len);\n }\n}",
"ChainlinkClient.sol":"pragma solidity ^0.5.0;\n\nimport \"./Chainlink.sol\";\nimport \"./interfaces/ENSInterface.sol\";\nimport \"./interfaces/LinkTokenInterface.sol\";\nimport \"./interfaces/ChainlinkRequestInterface.sol\";\nimport \"./interfaces/PointerInterface.sol\";\nimport { ENSResolver as ENSResolver_Chainlink } from \"./vendor/ENSResolver.sol\";\n\n/**\n * @title The ChainlinkClient contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network\n */\ncontract ChainlinkClient {\n using Chainlink for Chainlink.Request;\n\n uint256 constant internal LINK = 10**18;\n uint256 constant private AMOUNT_OVERRIDE = 0;\n address constant private SENDER_OVERRIDE = address(0);\n uint256 constant private ARGS_VERSION = 1;\n bytes32 constant private ENS_TOKEN_SUBNAME = keccak256(\"link\");\n bytes32 constant private ENS_ORACLE_SUBNAME = keccak256(\"oracle\");\n address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;\n\n ENSInterface private ens;\n bytes32 private ensNode;\n LinkTokenInterface private link;\n ChainlinkRequestInterface private oracle;\n uint256 private requestCount = 1;\n mapping(bytes32 => address) private pendingRequests;\n\n event ChainlinkRequested(bytes32 indexed id);\n event ChainlinkFulfilled(bytes32 indexed id);\n event ChainlinkCancelled(bytes32 indexed id);\n\n /**\n * @notice Creates a request that can hold additional parameters\n * @param _specId The Job Specification ID that the request will be created for\n * @param _callbackAddress The callback address that the response will be sent to\n * @param _callbackFunctionSignature The callback function signature to use for the callback address\n * @return A Chainlink Request struct in memory\n */\n function buildChainlinkRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n Chainlink.Request memory req;\n return req.initialize(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `chainlinkRequestTo` with the stored oracle address\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequestTo(address(oracle), _req, _payment);\n }\n\n /**\n * @notice Creates a Chainlink request to the specified oracle address\n * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to\n * send LINK which creates a request on the target oracle contract.\n * Emits ChainlinkRequested event.\n * @param _oracle The address of the oracle for the request\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n requestId = keccak256(abi.encodePacked(this, requestCount));\n _req.nonce = requestCount;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requestCount += 1;\n\n return requestId;\n }\n\n /**\n * @notice Allows a request to be cancelled if it has not been fulfilled\n * @dev Requires keeping track of the expiration value emitted from the oracle contract.\n * Deletes the request from the `pendingRequests` mapping.\n * Emits ChainlinkCancelled event.\n * @param _requestId The request ID\n * @param _payment The amount of LINK sent for the request\n * @param _callbackFunc The callback function specified for the request\n * @param _expiration The time of the expiration for the request\n */\n function cancelChainlinkRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunc,\n uint256 _expiration\n )\n internal\n {\n ChainlinkRequestInterface requested = ChainlinkRequestInterface(pendingRequests[_requestId]);\n delete pendingRequests[_requestId];\n emit ChainlinkCancelled(_requestId);\n requested.cancelOracleRequest(_requestId, _payment, _callbackFunc, _expiration);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setChainlinkOracle(address _oracle) internal {\n oracle = ChainlinkRequestInterface(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setChainlinkToken(address _link) internal {\n link = LinkTokenInterface(_link);\n }\n\n /**\n * @notice Sets the Chainlink token address for the public\n * network as given by the Pointer contract\n */\n function setPublicChainlinkToken() internal {\n setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkTokenAddress()\n internal\n view\n returns (address)\n {\n return address(link);\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function chainlinkOracleAddress()\n internal\n view\n returns (address)\n {\n return address(oracle);\n }\n\n /**\n * @notice Allows for a request which was created on another contract to be fulfilled\n * on this contract\n * @param _oracle The address of the oracle contract that will fulfill the request\n * @param _requestId The request ID used for the response\n */\n function addChainlinkExternalRequest(address _oracle, bytes32 _requestId)\n internal\n notPendingRequest(_requestId)\n {\n pendingRequests[_requestId] = _oracle;\n }\n\n /**\n * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS\n * @dev Accounts for subnodes having different resolvers\n * @param _ens The address of the ENS contract\n * @param _node The ENS node hash\n */\n function useChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n ens = ENSInterface(_ens);\n ensNode = _node;\n bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));\n setChainlinkToken(resolver.addr(linkSubnode));\n updateChainlinkOracleWithENS();\n }\n\n /**\n * @notice Sets the stored oracle contract with the address resolved by ENS\n * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously\n */\n function updateChainlinkOracleWithENS()\n internal\n {\n bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));\n setChainlinkOracle(resolver.addr(oracleSubnode));\n }\n\n /**\n * @notice Encodes the request to be sent to the oracle contract\n * @dev The Chainlink node expects values to be in order for the request to be picked up. Order of types\n * will be validated in the oracle contract.\n * @param _req The initialized Chainlink Request\n * @return The bytes payload for the `transferAndCall` method\n */\n function encodeRequest(Chainlink.Request memory _req)\n private\n view\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n oracle.oracleRequest.selector,\n SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address\n AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent\n _req.id,\n _req.callbackAddress,\n _req.callbackFunctionId,\n _req.nonce,\n ARGS_VERSION,\n _req.buf.buf);\n }\n\n /**\n * @notice Ensures that the fulfillment is valid for this contract\n * @dev Use if the contract developer prefers methods instead of modifiers for validation\n * @param _requestId The request ID for fulfillment\n */\n function validateChainlinkCallback(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\n {}\n\n /**\n * @dev Reverts if the sender is not the oracle of the request.\n * Emits ChainlinkFulfilled event.\n * @param _requestId The request ID for fulfillment\n */\n modifier recordChainlinkFulfillment(bytes32 _requestId) {\n require(msg.sender == pendingRequests[_requestId],\n\"Source must be the oracle of the request\");\n delete pendingRequests[_requestId];\n emit ChainlinkFulfilled(_requestId);\n _;\n }\n\n /**\n * @dev Reverts if the request is already pending\n * @param _requestId The request ID for fulfillment\n */\n modifier notPendingRequest(bytes32 _requestId) {\n require(pendingRequests[_requestId] == address(0), \"Request is already pending\");\n _;\n }\n}\n",
"Chainlink.sol":"pragma solidity ^0.5.0;\n\nimport { CBOR as CBOR_Chainlink } from \"./vendor/CBOR.sol\";\nimport { Buffer as Buffer_Chainlink } from \"./vendor/Buffer.sol\";\n\n/**\n * @title Library for common Chainlink functions\n * @dev Uses imported CBOR library for encoding to buffer\n */\nlibrary Chainlink {\n uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase\n\n using CBOR_Chainlink for Buffer_Chainlink.buffer;\n\n struct Request {\n bytes32 id;\n address callbackAddress;\n bytes4 callbackFunctionId;\n uint256 nonce;\n Buffer_Chainlink.buffer buf;\n }\n\n /**\n * @notice Initializes a Chainlink request\n * @dev Sets the ID, callback address, and callback function signature on the request\n * @param self The uninitialized request\n * @param _id The Job Specification ID\n * @param _callbackAddress The callback address\n * @param _callbackFunction The callback function signature\n * @return The initialized request\n */\n function initialize(\n Request memory self,\n bytes32 _id,\n address _callbackAddress,\n bytes4 _callbackFunction\n ) internal pure returns (Chainlink.Request memory) {\n Buffer_Chainlink.init(self.buf, defaultBufferSize);\n self.id = _id;\n self.callbackAddress = _callbackAddress;\n self.callbackFunctionId = _callbackFunction;\n return self;\n }\n\n /**\n * @notice Sets the data for the buffer without encoding CBOR on-chain\n * @dev CBOR can be closed with curly-brackets {} or they can be left off\n * @param self The initialized request\n * @param _data The CBOR data\n */\n function setBuffer(Request memory self, bytes memory _data)\n internal pure\n {\n Buffer_Chainlink.init(self.buf, _data.length);\n Buffer_Chainlink.append(self.buf, _data);\n }\n\n /**\n * @notice Adds a string value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The string value to add\n */\n function add(Request memory self, string memory _key, string memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeString(_value);\n }\n\n /**\n * @notice Adds a bytes value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The bytes value to add\n */\n function addBytes(Request memory self, string memory _key, bytes memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeBytes(_value);\n }\n\n /**\n * @notice Adds a int256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The int256 value to add\n */\n function addInt(Request memory self, string memory _key, int256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeInt(_value);\n }\n\n /**\n * @notice Adds a uint256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The uint256 value to add\n */\n function addUint(Request memory self, string memory _key, uint256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeUInt(_value);\n }\n\n /**\n * @notice Adds an array of strings to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _values The array of string values to add\n */\n function addStringArray(Request memory self, string memory _key, string[] memory _values)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.startArray();\n for (uint256 i = 0; i < _values.length; i++) {\n self.buf.encodeString(_values[i]);\n }\n self.buf.endSequence();\n }\n}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.5.0;\n\ninterface ENSInterface {\n\n // Logged when the owner of a node assigns a new owner to a subnode.\n event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);\n\n // Logged when the owner of a node transfers ownership to a new account.\n event Transfer(bytes32 indexed node, address owner);\n\n // Logged when the resolver for a node changes.\n event NewResolver(bytes32 indexed node, address resolver);\n\n // Logged when the TTL of a node changes\n event NewTTL(bytes32 indexed node, uint64 ttl);\n\n\n function setSubnodeOwner(bytes32 node, bytes32 label, address _owner) external;\n function setResolver(bytes32 node, address _resolver) external;\n function setOwner(bytes32 node, address _owner) external;\n function setTTL(bytes32 node, uint64 _ttl) external;\n function owner(bytes32 node) external view returns (address);\n function resolver(bytes32 node) external view returns (address);\n function ttl(bytes32 node) external view returns (uint64);\n\n}\n",
"interfaces/LinkTokenInterface.sol":"pragma solidity ^0.5.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n function approve(address spender, uint256 value) external returns (bool success);\n function balanceOf(address owner) external view returns (uint256 balance);\n function decimals() external view returns (uint8 decimalPlaces);\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n function increaseApproval(address spender, uint256 subtractedValue) external;\n function name() external view returns (string memory tokenName);\n function symbol() external view returns (string memory tokenSymbol);\n function totalSupply() external view returns (uint256 totalTokensIssued);\n function transfer(address to, uint256 value) external returns (bool success);\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"vendor/ENSResolver.sol":"pragma solidity ^0.5.0;\n\ncontract ENSResolver {\n function addr(bytes32 node) public view returns (address);\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n"
"metadata":"{\"compiler\":{\"version\":\"0.5.0+commit.1d4f565a\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":false,\"inputs\":[{\"name\":\"_requestId\",\"type\":\"bytes32\"},{\"name\":\"_sAId\",\"type\":\"bytes32\"},{\"name\":\"_oracle\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"bytes32\"}],\"name\":\"fulfill\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"},{\"name\":\"complete\",\"type\":\"bool\"},{\"name\":\"response\",\"type\":\"bytes\"},{\"name\":\"paymentAmounts\",\"type\":\"int256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sAId\",\"type\":\"bytes32\"},{\"name\":\"_serviceAgreementData\",\"type\":\"bytes\"}],\"name\":\"initiateJob\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"},{\"name\":\"message\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{},\"notice\":\"Computes the mean of the values the oracles pass it via fulfill method\"}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/tests/MeanAggregator.sol\":\"MeanAggregator\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/dev/CoordinatorInterface.sol\":{\"keccak256\":\"0x5e47514ec65553a3cd071eb215a3b70252ac803ed2635140cda3c848265d9ef0\",\"urls\":[\"bzzr://aab94dbeb95e865cfc0f5a8808ce5bc5529e0105a53290b03ee6ccd83430d450\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/dev/ServiceAgreementDecoder.sol\":{\"keccak256\":\"0x809ce1b1bec5b16d0bf0c637fc91b46ecf0707a38f6fc28a342e3336f902006a\",\"urls\":[\"bzzr://62417d69405cc3dc4d2fcfa7322cb491be6b8a73bfa44e779e1ca8d90e4a05fe\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/tests/MeanAggregator.sol\":{\"keccak256\":\"0x7104b729f30c88ab66864d34da94bb7ea475ae3b7a2434a761ec41672a7a8365\",\"urls\":[\"bzzr://3e56acf4879bb3bafcf514a956690b308323d815e6b6060b0bc2606879d9a504\"]}},\"version\":1}",
"userdoc":{
"methods":{},
"notice":"Computes the mean of the values the oracles pass it via fulfill method"
}
},
"sources":{
"tests/MeanAggregator.sol":{
"id":30
},
"dev/CoordinatorInterface.sol":{
"id":7
},
"dev/ServiceAgreementDecoder.sol":{
"id":10
}
},
"sourceCodes":{
"tests/MeanAggregator.sol":"pragma solidity 0.5.0;\n\nimport \"../dev/CoordinatorInterface.sol\";\nimport \"../dev/ServiceAgreementDecoder.sol\";\n\n/// Computes the mean of the values the oracles pass it via fulfill method\ncontract MeanAggregator is ServiceAgreementDecoder {\n\n // Relies on Coordinator's authorization of the oracles (no need to track\n // oracle authorization in this contract.)\n\n mapping(bytes32 /* service agreement ID */ => uint256) payment;\n mapping(bytes32 /* service agreement ID */ => address[]) oracles;\n mapping(bytes32 /* request ID */ => uint256) numberReported;\n mapping(bytes32 /* request ID */ => mapping(address => uint256)) reportingOrder;\n\n // Current total for given request, divided by number of oracles reporting\n mapping(bytes32 /* request ID */ => uint256) average;\n // Remainder of total for given request from division by number of oracles.\n mapping(bytes32 /* request ID */ => uint256) remainder;\n\n function initiateJob(\n bytes32 _sAId, bytes memory _serviceAgreementData)\n public returns (bool success, bytes memory message) {\n ServiceAgreement memory serviceAgreement = decodeServiceAgreement(_serviceAgreementData);\n\n if (oracles[_sAId].length != 0) {\n return (false, bytes(\"job already initiated\"));\n }\n if (serviceAgreement.oracles.length == 0) {\n return (false, bytes(\"must depend on at least one oracle\"));\n }\n oracles[_sAId] = serviceAgreement.oracles;\n payment[_sAId] = serviceAgreement.payment;\n success = true;\n }\n\n function fulfill(bytes32 _requestId, bytes32 _sAId, address _oracle,\n bytes32 _value) public\n returns (bool success, bool complete, bytes memory response,\n int256[] memory paymentAmounts) {\n if (reportingOrder[_requestId][_oracle] != 0 ||\n numberReported[_requestId] == oracles[_sAId].length) {\n return (false, false, \"oracle already reported\", paymentAmounts);\n }\n uint256 oDividend = uint256(_value) / oracles[_sAId].length;\n uint256 oRemainder = uint256(_value) % oracles[_sAId].length;\n uint256 newRemainder = remainder[_requestId] + oRemainder;\n uint256 newAverage = average[_requestId] + oDividend + (newRemainder / oracles[_sAId].length);\n assert(newAverage >= average[_requestId]); // No overflow\n average[_requestId] = newAverage;\n remainder[_requestId] = newRemainder % oracles[_sAId].length;\n numberReported[_requestId] += 1;\n reportingOrder[_requestId][_oracle] = numberReported[_requestId];\n success = true;\n complete = (numberReported[_requestId] == oracles[_sAId].length);\n if (complete) {\n response = abi.encode(average[_requestId]);\n paymentAmounts = calculatePayments(_sAId, _requestId);\n }\n }\n\n function calculatePayments(bytes32 _sAId, bytes32 _requestId) private returns (int256[] memory paymentAmounts) {\n paymentAmounts = new int256[](oracles[_sAId].length);\n uint256 numOracles = oracles[_sAId].length;\n uint256 totalPayment = payment[_sAId];\n for (uint256 oIdx = 0; oIdx < oracles[_sAId].length; oIdx++) {\n // Linearly-decaying payout determined by each oracle's reportingIdx\n uint256 reportingIdx = reportingOrder[_requestId][oracles[_sAId][oIdx]] - 1;\n paymentAmounts[oIdx] = int256(2*(totalPayment/numOracles) - (\n (totalPayment * ((2*reportingIdx) + 1)) / (numOracles**2)));\n delete reportingOrder[_requestId][oracles[_sAId][oIdx]];\n }\n }\n}\n",
"dev/CoordinatorInterface.sol":"pragma solidity 0.5.0;\n\ncontract CoordinatorInterface {\n\n function initiateServiceAgreement(\n bytes memory _serviceAgreementData,\n bytes memory _oracleSignaturesData)\n public returns (bytes32);\n\n function fulfillOracleRequest(\n bytes32 _requestId,\n bytes32 _aggregatorArgs)\n external returns (bool);\n}\n",
"dev/ServiceAgreementDecoder.sol":"pragma solidity 0.5.0;\n\ncontract ServiceAgreementDecoder {\n\n struct ServiceAgreement {\n uint256 payment;\n uint256 expiration;\n uint256 endAt;\n address[] oracles;\n // This effectively functions as an ID tag for the off-chain job of the\n // service agreement. It is calculated as the keccak256 hash of the\n // normalized JSON request to create the ServiceAgreement, but that identity\n // is unused, and its value is essentially arbitrary.\n bytes32 requestDigest;\n // Specification of aggregator interface. See ../tests/MeanAggregator.sol\n // for example\n address aggregator;\n // Selectors for the interface methods must be specified, because their\n // arguments can vary from aggregator to aggregator.\n //\n // Function selector for aggregator initiateJob method\n bytes4 aggInitiateJobSelector;\n // Function selector for aggregator fulfill method\n bytes4 aggFulfillSelector;\n }\n\n function decodeServiceAgreement(\n bytes memory _serviceAgreementData\n )\n internal\n pure\n returns(ServiceAgreement memory)\n {\n // solhint-disable indent\n ServiceAgreement memory agreement;\n\n ( agreement.payment,\n agreement.expiration,\n agreement.endAt,\n agreement.oracles,\n agreement.requestDigest,\n agreement.aggregator,\n agreement.aggInitiateJobSelector,\n agreement.aggFulfillSelector) =\n abi.decode(\n _serviceAgreementData,\n ( uint256,\n uint256,\n uint256,\n address[],\n bytes32,\n address,\n bytes4,\n bytes4 )\n );\n\n return agreement;\n }\n}\n"
"Median.sol":"pragma solidity ^0.5.0;\n\nimport \"./vendor/SafeMathChainlink.sol\";\nimport \"./vendor/SignedSafeMath.sol\";\n\nlibrary Median {\n using SafeMathChainlink for uint256;\n using SignedSafeMath for int256;\n\n /**\n * @dev Returns the sorted middle, or the average of the two middle indexed \n * items if the array has an even number of elements\n * @param _list The list of elements to compare\n */\n function calculate(int256[] memory _list)\n internal\n pure\n returns (int256)\n {\n uint256 answerLength = _list.length;\n uint256 middleIndex = answerLength.div(2);\n if (answerLength % 2 == 0) {\n int256 median1 = quickselect(copy(_list), middleIndex);\n int256 median2 = quickselect(_list, middleIndex.add(1)); // quickselect is 1 indexed\n int256 remainder = (median1 % 2 + median2 % 2) / 2;\n return (median1 / 2).add(median2 / 2).add(remainder); // signed integers are not supported by SafeMath\n } else {\n return quickselect(_list, middleIndex.add(1)); // quickselect is 1 indexed\n }\n }\n\n /**\n * @dev Returns the kth value of the ordered array\n * See: http://www.cs.yale.edu/homes/aspnes/pinewiki/QuickSelect.html\n * @param _a The list of elements to pull from\n * @param _k The index, 1 based, of the elements you want to pull from when ordered\n */\n function quickselect(int256[] memory _a, uint256 _k)\n private\n pure\n returns (int256)\n {\n int256[] memory a = _a;\n uint256 k = _k;\n uint256 aLen = a.length;\n int256[] memory a1 = new int256[](aLen);\n int256[] memory a2 = new int256[](aLen);\n uint256 a1Len;\n uint256 a2Len;\n int256 pivot;\n uint256 i;\n\n while (true) {\n pivot = a[aLen.div(2)];\n a1Len = 0;\n a2Len = 0;\n for (i = 0; i < aLen; i++) {\n if (a[i] < pivot) {\n a1[a1Len] = a[i];\n a1Len++;\n } else if (a[i] > pivot) {\n a2[a2Len] = a[i];\n a2Len++;\n }\n }\n if (k <= a1Len) {\n aLen = a1Len;\n (a, a1) = swap(a, a1);\n } else if (k > (aLen.sub(a2Len))) {\n k = k.sub(aLen.sub(a2Len));\n aLen = a2Len;\n (a, a2) = swap(a, a2);\n } else {\n return pivot;\n }\n }\n }\n\n /**\n * @dev Swaps the pointers to two uint256 arrays in memory\n * @param _a The pointer to the first in memory array\n * @param _b The pointer to the second in memory array\n */\n function swap(int256[] memory _a, int256[] memory _b)\n private\n pure\n returns(int256[] memory, int256[] memory)\n {\n return (_b, _a);\n }\n\n /**\n * @dev Makes an in memory copy of the array passed in\n * @param _list The pointer to the array to be copied\n */\n function copy(int256[] memory _list)\n private\n pure\n returns(int256[] memory)\n {\n int256[] memory list2 = new int256[](_list.length);\n for (uint256 i = 0; i < _list.length; i++) {\n list2[i] = _list[i];\n }\n return list2;\n }\n\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n",
"vendor/SignedSafeMath.sol":"pragma solidity ^0.5.0;\n\nlibrary SignedSafeMath {\n\n /**\n * @dev Adds two int256s and makes sure the result doesn't overflow. Signed\n * integers aren't supported by the SafeMath library, thus this method\n * @param _a The first number to be added\n * @param _a The second number to be added\n */\n function add(int256 _a, int256 _b)\n internal\n pure\n returns (int256)\n {\n // solium-disable-next-line zeppelin/no-arithmetic-operations\n int256 c = _a + _b;\n require((_b >= 0 && c >= _a) || (_b < 0 && c < _a), \"SignedSafeMath: addition overflow\");\n\n return c;\n }\n}"
"Median.sol":"pragma solidity ^0.5.0;\n\nimport \"./vendor/SafeMathChainlink.sol\";\nimport \"./vendor/SignedSafeMath.sol\";\n\nlibrary Median {\n using SafeMathChainlink for uint256;\n using SignedSafeMath for int256;\n\n /**\n * @dev Returns the sorted middle, or the average of the two middle indexed \n * items if the array has an even number of elements\n * @param _list The list of elements to compare\n */\n function calculate(int256[] memory _list)\n internal\n pure\n returns (int256)\n {\n uint256 answerLength = _list.length;\n uint256 middleIndex = answerLength.div(2);\n if (answerLength % 2 == 0) {\n int256 median1 = quickselect(copy(_list), middleIndex);\n int256 median2 = quickselect(_list, middleIndex.add(1)); // quickselect is 1 indexed\n int256 remainder = (median1 % 2 + median2 % 2) / 2;\n return (median1 / 2).add(median2 / 2).add(remainder); // signed integers are not supported by SafeMath\n } else {\n return quickselect(_list, middleIndex.add(1)); // quickselect is 1 indexed\n }\n }\n\n /**\n * @dev Returns the kth value of the ordered array\n * See: http://www.cs.yale.edu/homes/aspnes/pinewiki/QuickSelect.html\n * @param _a The list of elements to pull from\n * @param _k The index, 1 based, of the elements you want to pull from when ordered\n */\n function quickselect(int256[] memory _a, uint256 _k)\n private\n pure\n returns (int256)\n {\n int256[] memory a = _a;\n uint256 k = _k;\n uint256 aLen = a.length;\n int256[] memory a1 = new int256[](aLen);\n int256[] memory a2 = new int256[](aLen);\n uint256 a1Len;\n uint256 a2Len;\n int256 pivot;\n uint256 i;\n\n while (true) {\n pivot = a[aLen.div(2)];\n a1Len = 0;\n a2Len = 0;\n for (i = 0; i < aLen; i++) {\n if (a[i] < pivot) {\n a1[a1Len] = a[i];\n a1Len++;\n } else if (a[i] > pivot) {\n a2[a2Len] = a[i];\n a2Len++;\n }\n }\n if (k <= a1Len) {\n aLen = a1Len;\n (a, a1) = swap(a, a1);\n } else if (k > (aLen.sub(a2Len))) {\n k = k.sub(aLen.sub(a2Len));\n aLen = a2Len;\n (a, a2) = swap(a, a2);\n } else {\n return pivot;\n }\n }\n }\n\n /**\n * @dev Swaps the pointers to two uint256 arrays in memory\n * @param _a The pointer to the first in memory array\n * @param _b The pointer to the second in memory array\n */\n function swap(int256[] memory _a, int256[] memory _b)\n private\n pure\n returns(int256[] memory, int256[] memory)\n {\n return (_b, _a);\n }\n\n /**\n * @dev Makes an in memory copy of the array passed in\n * @param _list The pointer to the array to be copied\n */\n function copy(int256[] memory _list)\n private\n pure\n returns(int256[] memory)\n {\n int256[] memory list2 = new int256[](_list.length);\n for (uint256 i = 0; i < _list.length; i++) {\n list2[i] = _list[i];\n }\n return list2;\n }\n\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n",
"vendor/SignedSafeMath.sol":"pragma solidity ^0.5.0;\n\nlibrary SignedSafeMath {\n\n /**\n * @dev Adds two int256s and makes sure the result doesn't overflow. Signed\n * integers aren't supported by the SafeMath library, thus this method\n * @param _a The first number to be added\n * @param _a The second number to be added\n */\n function add(int256 _a, int256 _b)\n internal\n pure\n returns (int256)\n {\n // solium-disable-next-line zeppelin/no-arithmetic-operations\n int256 c = _a + _b;\n require((_b >= 0 && c >= _a) || (_b < 0 && c < _a), \"SignedSafeMath: addition overflow\");\n\n return c;\n }\n}"
"details":"Given params must hash back to the commitment stored from `oracleRequest`. Will call the callback address' callback function without bubbling up error checking in a `require` so that the node can get paid.",
"params":{
"_callbackAddress":"The callback address to call for fulfillment",
"_callbackFunctionId":"The callback function ID to use for fulfillment",
"_data":"The data to return to the consuming contract",
"_expiration":"The expiration that the node should respond by before the requester can cancel",
"_payment":"The payment amount that will be released for the oracle (specified in wei)",
"_requestId":"The fulfillment request ID that must match the requester's"
},
"return":"Status if the external call was successful"
},
"getAuthorizationStatus(address)":{
"params":{
"_node":"The address of the Chainlink node"
},
"return":"The authorization status of the node"
},
"getChainlinkToken()":{
"details":"This is the public implementation for chainlinkTokenAddress, which is an internal method of the ChainlinkClient contract"
},
"isOwner()":{
"details":"Returns true if the caller is the current owner."
},
"onTokenTransfer(address,uint256,bytes)":{
"details":"The data payload's first 2 words will be overwritten by the `_sender` and `_amount` values to ensure correctness. Calls oracleRequest.",
"params":{
"_amount":"Amount of LINK sent (specified in wei)",
"metadata":"{\"compiler\":{\"version\":\"0.5.0+commit.1d4f565a\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[],\"name\":\"getChainlinkToken\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sender\",\"type\":\"address\"},{\"name\":\"_payment\",\"type\":\"uint256\"},{\"name\":\"_specId\",\"type\":\"bytes32\"},{\"name\":\"_callbackAddress\",\"type\":\"address\"},{\"name\":\"_callbackFunctionId\",\"type\":\"bytes4\"},{\"name\":\"_nonce\",\"type\":\"uint256\"},{\"name\":\"_dataVersion\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"oracleRequest\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_requestId\",\"type\":\"bytes32\"},{\"name\":\"_payment\",\"type\":\"uint256\"},{\"name\":\"_callbackAddress\",\"type\":\"address\"},{\"name\":\"_callbackFunctionId\",\"type\":\"bytes4\"},{\"name\":\"_expiration\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes32\"}],\"name\":\"fulfillOracleRequest\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"EXPIRY_TIME\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"withdrawable\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_requestId\",\"type\":\"bytes32\"},{\"name\":\"_payment\",\"type\":\"uint256\"},{\"name\":\"_callbackFunc\",\"type\":\"bytes4\"},{\"name\":\"_expiration\",\"type\":\"uint256\"}],\"name\":\"cancelOracleRequest\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_node\",\"type\":\"address\"},{\"name\":\"_allowed\",\"type\":\"bool\"}],\"name\":\"setFulfillmentPermission\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"isOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sender\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"onTokenTransfer\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_node\",\"type\":\"address\"}],\"name\":\"getAuthorizationStatus\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_recipient\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_link\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"specId\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"requester\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"requestId\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"payment\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"callbackAddr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"callbackFunctionId\",\"type\":\"bytes4\"},{\"indexed\":false,\"name\":\"cancelExpiration\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"dataVersion\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"OracleRequest\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"requestId\",\"type\":\"bytes32\"}],\"name\":\"CancelOracleRequest\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"cancelOracleRequest(bytes32,uint256,bytes4,uint256)\":{\"details\":\"Given params must hash to a commitment stored on the contract in order for the request to be valid Emits CancelOracleRequest event.\",\"params\":{\"_callbackFunc\":\"The requester's specified callback address\",\"_expiration\":\"The time of the expiration for the request\",\"_payment\":\"The amount of payment given (specified in wei)\",\"_requestId\":\"The request ID\"}},\"constructor\":{\"details\":\"Sets the LinkToken address for the imported LinkTokenInterface\",\"params\":{\"_link\":\"The address of the LINK token\"}},\"fulfillOracleRequest(bytes32,uint256,address,bytes4,uint256,bytes32)\":{\"details\":\"Given params must hash back to the commitment stored from `oracleRequest`. Will call the callback address' callback function without bubbling up error checking in a `require` so that the node can get paid.\",\"params\":{\"_callbackAddress\":\"The callback address to call for fulfillment\",\"_callbackFunctionId\":\"The callback function ID to use for fulfillment\",\"_data\":\"The data to return to the consuming contract\",\"_expiration\":\"The expiration that the node should respond by before the requester can cancel\",\"_payment\":\"The payment amount that will be released for the oracle (specified in wei)\",\"_requestId\":\"The fulfillment request ID that must match the requester's\"},\"return\":\"Status if the external call was successful\"},\"getAuthorizationStatus(address)\":{\"params\":{\"_node\":\"The address of the Chainlink node\"},\"return\":\"The authorization status of the node\"},\"getChainlinkToken()\":{\"details\":\"This is the public implementation for chainlinkTokenAddress, which is an internal method of the ChainlinkClient contract\"},\"isOwner()\":{\"details\":\"Returns true if the caller is the current owner.\"},\"onTokenTransfer(address,uint256,bytes)\":{\"details\":\"The data payload's first 2 words will be overwritten by the `_sender` and `_amount` values to ensure correctness. Calls oracleRequest.\",\"params\":{\"_amount\":\"Amount of LINK sent (specified in wei)\",\"_data\":\"Payload of the transaction\",\"_sender\":\"Address of the sender\"}},\"oracleRequest(address,uint256,bytes32,address,bytes4,uint256,uint256,bytes)\":{\"details\":\"Stores the hash of the params as the on-chain commitment for the request. Emits OracleRequest event for the Chainlink node to detect.\",\"params\":{\"_callbackAddress\":\"The callback address for the response\",\"_callbackFunctionId\":\"The callback function ID for the response\",\"_data\":\"The CBOR payload of the request\",\"_dataVersion\":\"The specified data version\",\"_nonce\":\"The nonce sent by the requester\",\"_payment\":\"The amount of payment given (specified in wei)\",\"_sender\":\"The sender of the request\",\"_specId\":\"The Job Specification ID\"}},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"setFulfillmentPermission(address,bool)\":{\"params\":{\"_allowed\":\"Bool value to determine if the node can fulfill requests\",\"_node\":\"The address of the Chainlink node\"}},\"transferOwnership(address)\":{\"details\":\"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.\"},\"withdraw(address,uint256)\":{\"details\":\"The owner of the contract can be another wallet and does not have to be a Chainlink node\",\"params\":{\"_amount\":\"The amount to send (specified in wei)\",\"_recipient\":\"The address to send the LINK token to\"}},\"withdrawable()\":{\"details\":\"We use `ONE_FOR_CONSISTENT_GAS_COST` in place of 0 in storage\",\"return\":\"The amount of withdrawable LINK on the contract\"}},\"title\":\"The Chainlink Oracle contract\"},\"userdoc\":{\"methods\":{\"cancelOracleRequest(bytes32,uint256,bytes4,uint256)\":{\"notice\":\"Allows requesters to cancel requests sent to this oracle contract. Will transfer the LINK sent for the request back to the requester's address.\"},\"constructor\":\"Deploy with the address of the LINK token\",\"fulfillOracleRequest(bytes32,uint256,address,bytes4,uint256,bytes32)\":{\"notice\":\"Called by the Chainlink node to fulfill requests\"},\"getAuthorizationStatus(address)\":{\"notice\":\"Use this to check if a node is authorized for fulfilling requests\"},\"getChainlinkToken()\":{\"notice\":\"Returns the address of the LINK token\"},\"onTokenTransfer(address,uint256,bytes)\":{\"notice\":\"Called when LINK is sent to the contract via `transferAndCall`\"},\"oracleRequest(address,uint256,bytes32,address,bytes4,uint256,uint256,bytes)\":{\"notice\":\"Creates the Chainlink request\"},\"setFulfillmentPermission(address,bool)\":{\"notice\":\"Sets the fulfillment permission for a given node. Use `true` to allow, `false` to disallow.\"},\"withdraw(address,uint256)\":{\"notice\":\"Allows the node operator to withdraw earned LINK to a given address\"},\"withdrawable()\":{\"notice\":\"Displays the amount of LINK that is available for the node operator to withdraw\"}},\"notice\":\"Node operators can deploy this contract to fulfill requests sent to them\"}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/Oracle.sol\":\"Oracle\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/LinkTokenReceiver.sol\":{\"keccak256\":\"0x7aea15111145093a05ed12403c1dc1a615abb1a629bfc32043a4f43cee1ff929\",\"urls\":[\"bzzr://cf8a3069e266aba2163edf7d62374ab3abc1c65c7ccc6c527e1e2dbe741bad9e\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/Oracle.sol\":{\"keccak256\":\"0x1f9579fe72850f25ba265a601654ae98baf8fe236fb14b62f1eaa57d8f4bd130\",\"urls\":[\"bzzr://8b37f1620eae9023ee894a3ee386de354bb21de1687dadc4adfad05305976550\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/interfaces/ChainlinkRequestInterface.sol\":{\"keccak256\":\"0x8871fe810c2efc580e8173e1751df0023b362f4835e44383bd95ee375c4388b9\",\"urls\":[\"bzzr://1c0bdf40cbcbe3fe7491c673d5db4561e85f3f02bd5f3851c857c6d5f7987c45\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/interfaces/LinkTokenInterface.sol\":{\"keccak256\":\"0x592d87884106ba82cedbe79922de9cfaf28b211a09f9be243ad767d3baa1cb90\",\"urls\":[\"bzzr://1f4a72f8b790700d839354d412df656d5a59877264c6e126a1deae6164de9e7d\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/interfaces/OracleInterface.sol\":{\"keccak256\":\"0xccb79a4ab0f1f0a3c4b9e4475dedf93bf0381b78c365eceebd409186256f8412\",\"urls\":[\"bzzr://582cf21891f1888887c01f1874610846cf6e2dc37d5f5e26f969c470018f7b1c\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/interfaces/WithdrawalInterface.sol\":{\"keccak256\":\"0x39d6b613dafa8377db39b9fe3a05e83652579ba60ff4609229f0b65a034d80e3\",\"urls\":[\"bzzr://29e91407cacf5d464a20d7976179b4b72c3fe49de28442e10b091abb1f924879\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/vendor/Ownable.sol\":{\"keccak256\":\"0xa282b582630c29bff6b88640a32fc3ff7ff8809736aaabde55518cbe1d7bcb11\",\"urls\":[\"bzzr://e856dc34fdda5c4260b5f98d46e2a38f84bcaec640413e77b5aab5259d78461d\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/vendor/SafeMathChainlink.sol\":{\"keccak256\":\"0x796a82f2e4ab35469224050fb62ecd2dc038474e7f9d4dfd7a1023080c009883\",\"urls\":[\"bzzr://6e0bb08f77ca150b228e70773696ea301e939c0b5542fedb05276b683b774e13\"]}},\"version\":1}",
"notice":"Allows requesters to cancel requests sent to this oracle contract. Will transfer the LINK sent for the request back to the requester's address."
},
"constructor":"Deploy with the address of the LINK token",
"notice":"Sets the fulfillment permission for a given node. Use `true` to allow, `false` to disallow."
},
"withdraw(address,uint256)":{
"notice":"Allows the node operator to withdraw earned LINK to a given address"
},
"withdrawable()":{
"notice":"Displays the amount of LINK that is available for the node operator to withdraw"
}
},
"notice":"Node operators can deploy this contract to fulfill requests sent to them"
}
},
"sources":{
"Oracle.sol":{
"id":5
},
"LinkTokenReceiver.sol":{
"id":2
},
"interfaces/ChainlinkRequestInterface.sol":{
"id":14
},
"interfaces/OracleInterface.sol":{
"id":18
},
"interfaces/LinkTokenInterface.sol":{
"id":17
},
"interfaces/WithdrawalInterface.sol":{
"id":20
},
"vendor/Ownable.sol":{
"id":36
},
"vendor/SafeMathChainlink.sol":{
"id":37
}
},
"sourceCodes":{
"Oracle.sol":"pragma solidity ^0.5.0;\n\nimport \"./LinkTokenReceiver.sol\";\nimport \"./interfaces/ChainlinkRequestInterface.sol\";\nimport \"./interfaces/OracleInterface.sol\";\nimport \"./interfaces/LinkTokenInterface.sol\";\nimport \"./interfaces/WithdrawalInterface.sol\";\nimport \"./vendor/Ownable.sol\";\nimport \"./vendor/SafeMathChainlink.sol\";\n\n/**\n * @title The Chainlink Oracle contract\n * @notice Node operators can deploy this contract to fulfill requests sent to them\n */\ncontract Oracle is ChainlinkRequestInterface, OracleInterface, Ownable, LinkTokenReceiver, WithdrawalInterface {\n using SafeMathChainlink for uint256;\n\n uint256 constant public EXPIRY_TIME = 5 minutes;\n uint256 constant private MINIMUM_CONSUMER_GAS_LIMIT = 400000;\n // We initialize fields to 1 instead of 0 so that the first invocation\n // does not cost more gas.\n uint256 constant private ONE_FOR_CONSISTENT_GAS_COST = 1;\n\n LinkTokenInterface internal LinkToken;\n mapping(bytes32 => bytes32) private commitments;\n mapping(address => bool) private authorizedNodes;\n uint256 private withdrawableTokens = ONE_FOR_CONSISTENT_GAS_COST;\n\n event OracleRequest(\n bytes32 indexed specId,\n address requester,\n bytes32 requestId,\n uint256 payment,\n address callbackAddr,\n bytes4 callbackFunctionId,\n uint256 cancelExpiration,\n uint256 dataVersion,\n bytes data\n );\n\n event CancelOracleRequest(\n bytes32 indexed requestId\n );\n\n /**\n * @notice Deploy with the address of the LINK token\n * @dev Sets the LinkToken address for the imported LinkTokenInterface\n * @param _link The address of the LINK token\n */\n constructor(address _link) public Ownable() {\n LinkToken = LinkTokenInterface(_link); // external but already deployed and unalterable\n }\n\n /**\n * @notice Creates the Chainlink request\n * @dev Stores the hash of the params as the on-chain commitment for the request.\n * Emits OracleRequest event for the Chainlink node to detect.\n * @param _sender The sender of the request\n * @param _payment The amount of payment given (specified in wei)\n * @param _specId The Job Specification ID\n * @param _callbackAddress The callback address for the response\n * @param _callbackFunctionId The callback function ID for the response\n * @param _nonce The nonce sent by the requester\n * @param _dataVersion The specified data version\n * @param _data The CBOR payload of the request\n */\n function oracleRequest(\n address _sender,\n uint256 _payment,\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionId,\n uint256 _nonce,\n uint256 _dataVersion,\n bytes calldata _data\n )\n external\n onlyLINK\n checkCallbackAddress(_callbackAddress)\n {\n bytes32 requestId = keccak256(abi.encodePacked(_sender, _nonce));\n require(commitments[requestId] == 0, \"Must use a unique ID\");\n // solhint-disable-next-line not-rely-on-time\n uint256 expiration = now.add(EXPIRY_TIME);\n\n commitments[requestId] = keccak256(\n abi.encodePacked(\n _payment,\n _callbackAddress,\n _callbackFunctionId,\n expiration\n )\n );\n\n emit OracleRequest(\n _specId,\n _sender,\n requestId,\n _payment,\n _callbackAddress,\n _callbackFunctionId,\n expiration,\n _dataVersion,\n _data);\n }\n\n /**\n * @notice Called by the Chainlink node to fulfill requests\n * @dev Given params must hash back to the commitment stored from `oracleRequest`.\n * Will call the callback address' callback function without bubbling up error\n * checking in a `require` so that the node can get paid.\n * @param _requestId The fulfillment request ID that must match the requester's\n * @param _payment The payment amount that will be released for the oracle (specified in wei)\n * @param _callbackAddress The callback address to call for fulfillment\n * @param _callbackFunctionId The callback function ID to use for fulfillment\n * @param _expiration The expiration that the node should respond by before the requester can cancel\n * @param _data The data to return to the consuming contract\n * @return Status if the external call was successful\n */\n function fulfillOracleRequest(\n bytes32 _requestId,\n uint256 _payment,\n address _callbackAddress,\n bytes4 _callbackFunctionId,\n uint256 _expiration,\n bytes32 _data\n )\n external\n onlyAuthorizedNode\n isValidRequest(_requestId)\n returns (bool)\n {\n bytes32 paramsHash = keccak256(\n abi.encodePacked(\n _payment,\n _callbackAddress,\n _callbackFunctionId,\n _expiration\n )\n );\n require(commitments[_requestId] == paramsHash, \"Params do not match request ID\");\n withdrawableTokens = withdrawableTokens.add(_payment);\n delete commitments[_requestId];\n require(gasleft() >= MINIMUM_CONSUMER_GAS_LIMIT, \"Must provide consumer enough gas\");\n // All updates to the oracle's fulfillment should come before calling the\n // callback(addr+functionId) as it is untrusted.\n // See: https://solidity.readthedocs.io/en/develop/security-considerations.html#use-the-checks-effects-interactions-pattern\n (bool success, ) = _callbackAddress.call(abi.encodeWithSelector(_callbackFunctionId, _requestId, _data)); // solhint-disable-line avoid-low-level-calls\n return success;\n }\n\n /**\n * @notice Use this to check if a node is authorized for fulfilling requests\n * @param _node The address of the Chainlink node\n * @return The authorization status of the node\n */\n function getAuthorizationStatus(address _node) external view returns (bool) {\n return authorizedNodes[_node];\n }\n\n /**\n * @notice Sets the fulfillment permission for a given node. Use `true` to allow, `false` to disallow.\n * @param _node The address of the Chainlink node\n * @param _allowed Bool value to determine if the node can fulfill requests\n */\n function setFulfillmentPermission(address _node, bool _allowed) external onlyOwner {\n authorizedNodes[_node] = _allowed;\n }\n\n /**\n * @notice Allows the node operator to withdraw earned LINK to a given address\n * @dev The owner of the contract can be another wallet and does not have to be a Chainlink node\n * @param _recipient The address to send the LINK token to\n * @param _amount The amount to send (specified in wei)\n */\n function withdraw(address _recipient, uint256 _amount)\n external\n onlyOwner\n hasAvailableFunds(_amount)\n {\n withdrawableTokens = withdrawableTokens.sub(_amount);\n assert(LinkToken.transfer(_recipient, _amount));\n }\n\n /**\n * @notice Displays the amount of LINK that is available for the node operator to withdraw\n * @dev We use `ONE_FOR_CONSISTENT_GAS_COST` in place of 0 in storage\n * @return The amount of withdrawable LINK on the contract\n */\n function withdrawable() external view onlyOwner returns (uint256) {\n return withdrawableTokens.sub(ONE_FOR_CONSISTENT_GAS_COST);\n }\n\n /**\n * @notice Allows requesters to cancel requests sent to this oracle contract. Will transfer the LINK\n * sent for the request back to the requester's address.\n * @dev Given params must hash to a commitment stored on the contract in order for the request to be valid\n * Emits CancelOracleRequest event.\n * @param _requestId The request ID\n * @param _payment The amount of payment given (specified in wei)\n * @param _callbackFunc The requester's specified callback address\n * @param _expiration The time of the expiration for the request\n */\n function cancelOracleRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunc,\n uint256 _expiration\n ) external {\n bytes32 paramsHash = keccak256(\n abi.encodePacked(\n _payment,\n msg.sender,\n _callbackFunc,\n _expiration)\n );\n require(paramsHash == commitments[_requestId], \"Params do not match request ID\");\n // solhint-disable-next-line not-rely-on-time\n require(_expiration <= now, \"Request is not expired\");\n\n delete commitments[_requestId];\n emit CancelOracleRequest(_requestId);\n\n assert(LinkToken.transfer(msg.sender, _payment));\n }\n\n /**\n * @notice Returns the address of the LINK token\n * @dev This is the public implementation for chainlinkTokenAddress, which is\n * an internal method of the ChainlinkClient contract\n */\n function getChainlinkToken() public view returns (address) {\n return address(LinkToken);\n }\n\n // MODIFIERS\n\n /**\n * @dev Reverts if amount requested is greater than withdrawable balance\n * @param _amount The given amount to compare to `withdrawableTokens`\n */\n modifier hasAvailableFunds(uint256 _amount) {\n require(withdrawableTokens >= _amount.add(ONE_FOR_CONSISTENT_GAS_COST), \"Amount requested is greater than withdrawable balance\");\n _;\n }\n\n /**\n * @dev Reverts if request ID does not exist\n * @param _requestId The given request ID to check in stored `commitments`\n */\n modifier isValidRequest(bytes32 _requestId) {\n require(commitments[_requestId] != 0, \"Must have a valid requestId\");\n _;\n }\n\n /**\n * @dev Reverts if `msg.sender` is not authorized to fulfill requests\n */\n modifier onlyAuthorizedNode() {\n require(authorizedNodes[msg.sender] || msg.sender == owner(), \"Not an authorized node to fulfill requests\");\n _;\n }\n\n /**\n * @dev Reverts if the callback address is the LINK token\n * @param _to The callback address\n */\n modifier checkCallbackAddress(address _to) {\n require(_to != address(LinkToken), \"Cannot callback to LINK\");\n _;\n }\n\n}\n",
"LinkTokenReceiver.sol":"pragma solidity ^0.5.0;\n\ncontract LinkTokenReceiver {\n\n bytes4 constant private ORACLE_REQUEST_SELECTOR = 0x40429946;\n uint256 constant private SELECTOR_LENGTH = 4;\n uint256 constant private EXPECTED_REQUEST_WORDS = 2;\n uint256 constant private MINIMUM_REQUEST_LENGTH = SELECTOR_LENGTH + (32 * EXPECTED_REQUEST_WORDS);\n /**\n * @notice Called when LINK is sent to the contract via `transferAndCall`\n * @dev The data payload's first 2 words will be overwritten by the `_sender` and `_amount`\n * values to ensure correctness. Calls oracleRequest.\n * @param _sender Address of the sender\n * @param _amount Amount of LINK sent (specified in wei)\n * @param _data Payload of the transaction\n */\n function onTokenTransfer(\n address _sender,\n uint256 _amount,\n bytes memory _data\n )\n public\n onlyLINK\n validRequestLength(_data)\n permittedFunctionsForLINK(_data)\n {\n assembly {\n // solhint-disable-next-line avoid-low-level-calls\n mstore(add(_data, 36), _sender) // ensure correct sender is passed\n // solhint-disable-next-line avoid-low-level-calls\n mstore(add(_data, 68), _amount) // ensure correct amount is passed\n }\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, ) = address(this).delegatecall(_data); // calls oracleRequest\n require(success, \"Unable to create request\");\n }\n\n function getChainlinkToken() public view returns (address);\n\n /**\n * @dev Reverts if not sent from the LINK token\n */\n modifier onlyLINK() {\n require(msg.sender == getChainlinkToken(), \"Must use LINK token\");\n _;\n }\n\n /**\n * @dev Reverts if the given data does not begin with the `oracleRequest` function selector\n * @param _data The data payload of the request\n */\n modifier permittedFunctionsForLINK(bytes memory _data) {\n bytes4 funcSelector;\n assembly {\n // solhint-disable-next-line avoid-low-level-calls\n funcSelector := mload(add(_data, 32))\n }\n require(funcSelector == ORACLE_REQUEST_SELECTOR, \"Must use whitelisted functions\");\n _;\n }\n\n /**\n * @dev Reverts if the given payload is less than needed to create a request\n * @param _data The request payload\n */\n modifier validRequestLength(bytes memory _data) {\n require(_data.length >= MINIMUM_REQUEST_LENGTH, \"Invalid request length\");\n _;\n }\n}",
"interfaces/OracleInterface.sol":"pragma solidity ^0.5.0;\n\ninterface OracleInterface {\n function fulfillOracleRequest(\n bytes32 requestId,\n uint256 payment,\n address callbackAddress,\n bytes4 callbackFunctionId,\n uint256 expiration,\n bytes32 data\n ) external returns (bool);\n function getAuthorizationStatus(address node) external view returns (bool);\n function setFulfillmentPermission(address node, bool allowed) external;\n function withdraw(address recipient, uint256 amount) external;\n function withdrawable() external view returns (uint256);\n}\n",
"interfaces/LinkTokenInterface.sol":"pragma solidity ^0.5.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n function approve(address spender, uint256 value) external returns (bool success);\n function balanceOf(address owner) external view returns (uint256 balance);\n function decimals() external view returns (uint8 decimalPlaces);\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n function increaseApproval(address spender, uint256 subtractedValue) external;\n function name() external view returns (string memory tokenName);\n function symbol() external view returns (string memory tokenSymbol);\n function totalSupply() external view returns (uint256 totalTokensIssued);\n function transfer(address to, uint256 value) external returns (bool success);\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"interfaces/WithdrawalInterface.sol":"pragma solidity ^0.5.0;\n\ninterface WithdrawalInterface {\n /**\n * @notice transfer LINK held by the contract belonging to msg.sender to\n * another address\n * @param recipient is the address to send the LINK to\n * @param amount is the amount of LINK to send\n */\n function withdraw(address recipient, uint256 amount) external;\n\n /**\n * @notice query the available amount of LINK to withdraw by msg.sender\n */\n function withdrawable() external view returns (uint256);\n}\n",
"vendor/Ownable.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be aplied to your functions to restrict their use to\n * the owner.\n *\n * This contract has been modified to remove the revokeOwnership function\n */\ncontract Ownable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor () internal {\n _owner = msg.sender;\n emit OwnershipTransferred(address(0), _owner);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(isOwner(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Returns true if the caller is the current owner.\n */\n function isOwner() public view returns (bool) {\n return msg.sender == _owner;\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public onlyOwner {\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n */\n function _transferOwnership(address newOwner) internal {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n"
"details":"Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. * This module is used through inheritance. It will make available the modifier `onlyOwner`, which can be aplied to your functions to restrict their use to the owner. * This contract has been modified to remove the revokeOwnership function",
"methods":{
"constructor":{
"details":"Initializes the contract setting the deployer as the initial owner."
},
"isOwner()":{
"details":"Returns true if the caller is the current owner."
},
"owner()":{
"details":"Returns the address of the current owner."
},
"transferOwnership(address)":{
"details":"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner."
}
}
},
"evm":{
"bytecode":{
"linkReferences":{},
"object":"0x",
"opcodes":"",
"sourceMap":""
},
"deployedBytecode":{
"linkReferences":{},
"object":"0x",
"opcodes":"",
"sourceMap":""
},
"methodIdentifiers":{
"isOwner()":"8f32d59b",
"owner()":"8da5cb5b",
"transferOwnership(address)":"f2fde38b"
}
},
"metadata":"",
"userdoc":{
"methods":{}
}
},
"sources":{
"vendor/Ownable.sol":{
"id":36
}
},
"sourceCodes":{
"vendor/Ownable.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be aplied to your functions to restrict their use to\n * the owner.\n *\n * This contract has been modified to remove the revokeOwnership function\n */\ncontract Ownable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor () internal {\n _owner = msg.sender;\n emit OwnershipTransferred(address(0), _owner);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(isOwner(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Returns true if the caller is the current owner.\n */\n function isOwner() public view returns (bool) {\n return msg.sender == _owner;\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public onlyOwner {\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n */\n function _transferOwnership(address newOwner) internal {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n}\n"
"details":"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.",
"metadata":"{\"compiler\":{\"version\":\"0.5.0+commit.1d4f565a\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"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.\",\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/vendor/SafeMathChainlink.sol\":\"SafeMathChainlink\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/vendor/SafeMathChainlink.sol\":{\"keccak256\":\"0x796a82f2e4ab35469224050fb62ecd2dc038474e7f9d4dfd7a1023080c009883\",\"urls\":[\"bzzr://6e0bb08f77ca150b228e70773696ea301e939c0b5542fedb05276b683b774e13\"]}},\"version\":1}",
"userdoc":{
"methods":{}
}
},
"sources":{
"vendor/SafeMathChainlink.sol":{
"id":37
}
},
"sourceCodes":{
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.5.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathChainlink {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0, \"SafeMath: division by zero\");\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n}\n"
"details":"See https://en.wikipedia.org/wiki/Schnorr_signature for reference.In what follows, let d be your secret key, PK be your public key, PKx be the x ordinate of your public key, and PKyp be the parity bit for the y ordinate (i.e., 0 if PKy is even, 1 if odd.)**************************************************************************TO CREATE A VALID SIGNATURE FOR THIS METHODFirst PKx must be less than HALF_Q. Then follow these instructions (see evm/test/schnorr_test.js, for an example of carrying them out):1. Hash the target message to a uint256, called msgHash here, using keccak2562. Pick k uniformly and cryptographically securely randomly from {0,...,Q-1}. It is critical that k remains confidential, as your private key can be reconstructed from k and the signature.3. Compute k*g in the secp256k1 group, where g is the group generator. (This is the same as computing the public key from the secret key k. But it's OK if k*g's x ordinate is greater than HALF_Q.)4. Compute the ethereum address for k*g. This is the lower 160 bits of the keccak hash of the concatenated affine coordinates of k*g, as 32-byte big-endians. (For instance, you could pass k to ethereumjs-utils's privateToAddress to compute this, though that should be strictly a development convenience, not for handling live secrets, unless you've locked your javascript environment down very carefully.) Call this address nonceTimesGeneratorAddress.5. Compute e=uint256(keccak256(PKx as a 32-byte big-endian ‖ PKyp as a single byte ‖ msgHash ‖ nonceTimesGeneratorAddress)) This value e is called \"msgChallenge\" in verifySignature's source code below. Here \"‖\" means concatenation of the listed byte arrays.6. Let x be your secret key. Compute s = (k - d * e) % Q. Add Q to it, if it's negative. This is your signature. (d is your secret key.)**************************************************************************TO VERIFY A SIGNATUREGiven a signature (s, e) of msgHash, constructed as above, compute S=e*PK+s*generator in the secp256k1 group law, and then the ethereum address of S, as described in step 4. Call that nonceTimesGeneratorAddress. Then call the verifySignature method as:verifySignature(PKx, PKyp, s, msgHash, nonceTimesGeneratorAddress)**************************************************************************This signging scheme deviates slightly from the classical Schnorr signature, in that the address of k*g is used in place of k*g itself, both when calculating e and when verifying sum S as described in the verification paragraph above. This reduces the difficulty of brute-forcing a signature by trying random secp256k1 points in place of k*g in the signature verification process from 256 bits to 160 bits. However, the difficulty of cracking the public key using \"baby-step, giant-step\" is only 128 bits, so this weakening constitutes no compromise in the security of the signatures or the key.The constraint signingPubKeyX < HALF_Q comes from Eq. (281), p. 24 of Yellow Paper version 78d7b9a. ecrecover only accepts \"s\" inputs less than HALF_Q, to protect against a signature- malleability vulnerability in ECDSA. Schnorr does not have this vulnerability, but we must account for ecrecover's defense anyway. And since we are abusing ecrecover by putting signingPubKeyX in ecrecover's \"s\" argument the constraint applies to signingPubKeyX, even though it represents a value in the base field, and has no natural relationship to the order of the curve's cyclic group.**************************************************************************",
"params":{
"msgHash":"is a 256-bit hash of the message being signed.",
"nonceTimesGeneratorAddress":"is the ethereum address of k*g in the above instructions**************************************************************************",
"pubKeyYParity":"is 0 if the y ordinate of the public key is even, 1 if it's odd.",
"signature":"is the actual signature, described as s in the above instructions.",
"signingPubKeyX":"is the x ordinate of the public key. This must be less than HALF_Q. "
},
"return":"True if passed a valid signature, false otherwise. "
"metadata":"{\"compiler\":{\"version\":\"0.5.0+commit.1d4f565a\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[],\"name\":\"HALF_Q\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"Q\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"signingPubKeyX\",\"type\":\"uint256\"},{\"name\":\"pubKeyYParity\",\"type\":\"uint8\"},{\"name\":\"signature\",\"type\":\"uint256\"},{\"name\":\"msgHash\",\"type\":\"uint256\"},{\"name\":\"nonceTimesGeneratorAddress\",\"type\":\"address\"}],\"name\":\"verifySignature\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"methods\":{\"verifySignature(uint256,uint8,uint256,uint256,address)\":{\"details\":\"See https://en.wikipedia.org/wiki/Schnorr_signature for reference.In what follows, let d be your secret key, PK be your public key, PKx be the x ordinate of your public key, and PKyp be the parity bit for the y ordinate (i.e., 0 if PKy is even, 1 if odd.)**************************************************************************TO CREATE A VALID SIGNATURE FOR THIS METHODFirst PKx must be less than HALF_Q. Then follow these instructions (see evm/test/schnorr_test.js, for an example of carrying them out):1. Hash the target message to a uint256, called msgHash here, using keccak2562. Pick k uniformly and cryptographically securely randomly from {0,...,Q-1}. It is critical that k remains confidential, as your private key can be reconstructed from k and the signature.3. Compute k*g in the secp256k1 group, where g is the group generator. (This is the same as computing the public key from the secret key k. But it's OK if k*g's x ordinate is greater than HALF_Q.)4. Compute the ethereum address for k*g. This is the lower 160 bits of the keccak hash of the concatenated affine coordinates of k*g, as 32-byte big-endians. (For instance, you could pass k to ethereumjs-utils's privateToAddress to compute this, though that should be strictly a development convenience, not for handling live secrets, unless you've locked your javascript environment down very carefully.) Call this address nonceTimesGeneratorAddress.5. Compute e=uint256(keccak256(PKx as a 32-byte big-endian \\u2016 PKyp as a single byte \\u2016 msgHash \\u2016 nonceTimesGeneratorAddress)) This value e is called \\\"msgChallenge\\\" in verifySignature's source code below. Here \\\"\\u2016\\\" means concatenation of the listed byte arrays.6. Let x be your secret key. Compute s = (k - d * e) % Q. Add Q to it, if it's negative. This is your signature. (d is your secret key.)**************************************************************************TO VERIFY A SIGNATUREGiven a signature (s, e) of msgHash, constructed as above, compute S=e*PK+s*generator in the secp256k1 group law, and then the ethereum address of S, as described in step 4. Call that nonceTimesGeneratorAddress. Then call the verifySignature method as:verifySignature(PKx, PKyp, s, msgHash, nonceTimesGeneratorAddress)**************************************************************************This signging scheme deviates slightly from the classical Schnorr signature, in that the address of k*g is used in place of k*g itself, both when calculating e and when verifying sum S as described in the verification paragraph above. This reduces the difficulty of brute-forcing a signature by trying random secp256k1 points in place of k*g in the signature verification process from 256 bits to 160 bits. However, the difficulty of cracking the public key using \\\"baby-step, giant-step\\\" is only 128 bits, so this weakening constitutes no compromise in the security of the signatures or the key.The constraint signingPubKeyX < HALF_Q comes from Eq. (281), p. 24 of Yellow Paper version 78d7b9a. ecrecover only accepts \\\"s\\\" inputs less than HALF_Q, to protect against a signature- malleability vulnerability in ECDSA. Schnorr does not have this vulnerability, but we must account for ecrecover's defense anyway. And since we are abusing ecrecover by putting signingPubKeyX in ecrecover's \\\"s\\\" argument the constraint applies to signingPubKeyX, even though it represents a value in the base field, and has no natural relationship to the order of the curve's cyclic group.**************************************************************************\",\"params\":{\"msgHash\":\"is a 256-bit hash of the message being signed.\",\"nonceTimesGeneratorAddress\":\"is the ethereum address of k*g in the above instructions**************************************************************************\",\"pubKeyYParity\":\"is 0 if the y ordinate of the public key is even, 1 if it's odd.\",\"signature\":\"is the actual signature, described as s in the above instructions.\",\"signingPubKeyX\":\"is the x ordinate of the public key. This must be less than HALF_Q. \"},\"return\":\"True if passed a valid signature, false otherwise. \"}}},\"userdoc\":{\"methods\":{\"verifySignature(uint256,uint8,uint256,uint256,address)\":{\"notice\":\"**************************************************************************verifySignature returns true iff passed a valid Schnorr signature.\"}},\"notice\":\"/////////////////////////////////////////////////////////////////////////////\"}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/dev/SchnorrSECP256K1.sol\":\"SchnorrSECP256K1\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.5/dev/SchnorrSECP256K1.sol\":{\"keccak256\":\"0x5c82b83c6aca50fa2ab07bc0b31bac6ee33c7ade303102ecc688087c351f5317\",\"urls\":[\"bzzr://e4d63d170c40da3609bfe0e10fa679bc4318083e6f9d42dbee72ba5e91312d8d\"]}},\"version\":1}",
"dev/SchnorrSECP256K1.sol":"pragma solidity ^0.5.0;\n\n////////////////////////////////////////////////////////////////////////////////\n// XXX: Do not use in production until this code has been audited.\n////////////////////////////////////////////////////////////////////////////////\n\ncontract SchnorrSECP256K1 {\n // See https://en.bitcoin.it/wiki/Secp256k1 for this constant.\n uint256 constant public Q = // Group order of secp256k1\n // solium-disable-next-line indentation\n 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;\n // solium-disable-next-line zeppelin/no-arithmetic-operations\n uint256 constant public HALF_Q = (Q >> 1) + 1;\n\n /** **************************************************************************\n @notice verifySignature returns true iff passed a valid Schnorr signature.\n\n @dev See https://en.wikipedia.org/wiki/Schnorr_signature for reference.\n\n @dev In what follows, let d be your secret key, PK be your public key,\n PKx be the x ordinate of your public key, and PKyp be the parity bit for\n the y ordinate (i.e., 0 if PKy is even, 1 if odd.)\n **************************************************************************\n @dev TO CREATE A VALID SIGNATURE FOR THIS METHOD\n\n @dev First PKx must be less than HALF_Q. Then follow these instructions\n (see evm/test/schnorr_test.js, for an example of carrying them out):\n @dev 1. Hash the target message to a uint256, called msgHash here, using\n keccak256\n\n @dev 2. Pick k uniformly and cryptographically securely randomly from\n {0,...,Q-1}. It is critical that k remains confidential, as your\n private key can be reconstructed from k and the signature.\n\n @dev 3. Compute k*g in the secp256k1 group, where g is the group\n generator. (This is the same as computing the public key from the\n secret key k. But it's OK if k*g's x ordinate is greater than\n HALF_Q.)\n\n @dev 4. Compute the ethereum address for k*g. This is the lower 160 bits\n of the keccak hash of the concatenated affine coordinates of k*g,\n as 32-byte big-endians. (For instance, you could pass k to\n ethereumjs-utils's privateToAddress to compute this, though that\n should be strictly a development convenience, not for handling\n live secrets, unless you've locked your javascript environment\n down very carefully.) Call this address\n nonceTimesGeneratorAddress.\n\n @dev 5. Compute e=uint256(keccak256(PKx as a 32-byte big-endian\n ‖ PKyp as a single byte\n ‖ msgHash\n ‖ nonceTimesGeneratorAddress))\n This value e is called \"msgChallenge\" in verifySignature's source\n code below. Here \"‖\" means concatenation of the listed byte\n arrays.\n\n @dev 6. Let x be your secret key. Compute s = (k - d * e) % Q. Add Q to\n it, if it's negative. This is your signature. (d is your secret\n key.)\n **************************************************************************\n @dev TO VERIFY A SIGNATURE\n\n @dev Given a signature (s, e) of msgHash, constructed as above, compute\n S=e*PK+s*generator in the secp256k1 group law, and then the ethereum\n address of S, as described in step 4. Call that\n nonceTimesGeneratorAddress. Then call the verifySignature method as:\n\n @dev verifySignature(PKx, PKyp, s, msgHash,\n nonceTimesGeneratorAddress)\n **************************************************************************\n @dev This signging scheme deviates slightly from the classical Schnorr\n signature, in that the address of k*g is used in place of k*g itself,\n both when calculating e and when verifying sum S as described in the\n verification paragraph above. This reduces the difficulty of\n brute-forcing a signature by trying random secp256k1 points in place of\n k*g in the signature verification process from 256 bits to 160 bits.\n However, the difficulty of cracking the public key using \"baby-step,\n giant-step\" is only 128 bits, so this weakening constitutes no compromise\n in the security of the signatures or the key.\n\n @dev The constraint signingPubKeyX < HALF_Q comes from Eq. (281), p. 24\n of Yellow Paper version 78d7b9a. ecrecover only accepts \"s\" inputs less\n than HALF_Q, to protect against a signature- malleability vulnerability in\n ECDSA. Schnorr does not have this vulnerability, but we must account for\n ecrecover's defense anyway. And since we are abusing ecrecover by putting\n signingPubKeyX in ecrecover's \"s\" argument the constraint applies to\n signingPubKeyX, even though it represents a value in the base field, and\n has no natural relationship to the order of the curve's cyclic group.\n **************************************************************************\n @param signingPubKeyX is the x ordinate of the public key. This must be\n less than HALF_Q. \n @param pubKeyYParity is 0 if the y ordinate of the public key is even, 1 \n if it's odd.\n @param signature is the actual signature, described as s in the above\n instructions.\n @param msgHash is a 256-bit hash of the message being signed.\n @param nonceTimesGeneratorAddress is the ethereum address of k*g in the\n above instructions\n **************************************************************************\n @return True if passed a valid signature, false otherwise. */\n function verifySignature(\n uint256 signingPubKeyX,\n uint8 pubKeyYParity,\n uint256 signature,\n uint256 msgHash,\n address nonceTimesGeneratorAddress) external pure returns (bool) {\n require(signingPubKeyX < HALF_Q, \"Public-key x >= HALF_Q\");\n // Avoid signature malleability from multiple representations for ℤ/Qℤ elts\n require(signature < Q, \"signature must be reduced modulo Q\");\n\n // Forbid trivial inputs, to avoid ecrecover edge cases. The main thing to\n // avoid is something which causes ecrecover to return 0x0: then trivial\n // signatures could be constructed with the nonceTimesGeneratorAddress input\n // set to 0x0.\n //\n // solium-disable-next-line indentation\n require(nonceTimesGeneratorAddress != address(0) && signingPubKeyX > 0 &&\n signature > 0 && msgHash > 0, \"no zero inputs allowed\");\n\n // solium-disable-next-line indentation\n uint256 msgChallenge = // \"e\"\n // solium-disable-next-line indentation\n uint256(keccak256(abi.encodePacked(signingPubKeyX, pubKeyYParity,\n msgHash, nonceTimesGeneratorAddress))\n );\n\n // Verify msgChallenge * signingPubKey + signature * generator ==\n // nonce * generator\n //\n // https://ethresear.ch/t/you-can-kinda-abuse-ecrecover-to-do-ecmul-in-secp256k1-today/2384/9\n // The point corresponding to the address returned by\n // ecrecover(-s*r,v,r,e*r) is (r⁻¹ mod Q)*(e*r*R-(-s)*r*g)=e*R+s*g, where R\n // is the (v,r) point. See https://crypto.stackexchange.com/a/18106\n //\n // solium-disable-next-line indentation\n address recoveredAddress = ecrecover(\n // solium-disable-next-line zeppelin/no-arithmetic-operations\n bytes32(Q - mulmod(signingPubKeyX, signature, Q)),\n // https://ethereum.github.io/yellowpaper/paper.pdf p. 24, \"The\n // value 27 represents an even y value and 28 represents an odd\n // y value.\"\n (pubKeyYParity == 0) ? 27 : 28,\n bytes32(signingPubKeyX),\n bytes32(mulmod(msgChallenge, signingPubKeyX, Q)));\n return nonceTimesGeneratorAddress == recoveredAddress;\n }\n}\n"
"tests/ServiceAgreementConsumer.sol":"pragma solidity 0.5.0;\n\nimport \"../ChainlinkClient.sol\";\n\ncontract ServiceAgreementConsumer is ChainlinkClient {\n uint256 constant private ORACLE_PAYMENT = 1 * LINK;\n\n bytes32 internal sAId;\n bytes32 public currentPrice;\n\n constructor(address _link, address _coordinator, bytes32 _sAId) public {\n setChainlinkToken(_link);\n setChainlinkOracle(_coordinator);\n sAId = _sAId;\n }\n\n function requestEthereumPrice(string memory _currency) public {\n Chainlink.Request memory req = buildChainlinkRequest(sAId, address(this), this.fulfill.selector);\n req.add(\"get\", \"https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY\");\n req.add(\"path\", _currency);\n sendChainlinkRequest(req, ORACLE_PAYMENT);\n }\n\n function fulfill(bytes32 _requestId, bytes32 _price)\n public\n recordChainlinkFulfillment(_requestId)\n {\n currentPrice = _price;\n }\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.5.0;\n\nimport \"./Chainlink.sol\";\nimport \"./interfaces/ENSInterface.sol\";\nimport \"./interfaces/LinkTokenInterface.sol\";\nimport \"./interfaces/ChainlinkRequestInterface.sol\";\nimport \"./interfaces/PointerInterface.sol\";\nimport { ENSResolver as ENSResolver_Chainlink } from \"./vendor/ENSResolver.sol\";\n\n/**\n * @title The ChainlinkClient contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network\n */\ncontract ChainlinkClient {\n using Chainlink for Chainlink.Request;\n\n uint256 constant internal LINK = 10**18;\n uint256 constant private AMOUNT_OVERRIDE = 0;\n address constant private SENDER_OVERRIDE = address(0);\n uint256 constant private ARGS_VERSION = 1;\n bytes32 constant private ENS_TOKEN_SUBNAME = keccak256(\"link\");\n bytes32 constant private ENS_ORACLE_SUBNAME = keccak256(\"oracle\");\n address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;\n\n ENSInterface private ens;\n bytes32 private ensNode;\n LinkTokenInterface private link;\n ChainlinkRequestInterface private oracle;\n uint256 private requestCount = 1;\n mapping(bytes32 => address) private pendingRequests;\n\n event ChainlinkRequested(bytes32 indexed id);\n event ChainlinkFulfilled(bytes32 indexed id);\n event ChainlinkCancelled(bytes32 indexed id);\n\n /**\n * @notice Creates a request that can hold additional parameters\n * @param _specId The Job Specification ID that the request will be created for\n * @param _callbackAddress The callback address that the response will be sent to\n * @param _callbackFunctionSignature The callback function signature to use for the callback address\n * @return A Chainlink Request struct in memory\n */\n function buildChainlinkRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n Chainlink.Request memory req;\n return req.initialize(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `chainlinkRequestTo` with the stored oracle address\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequestTo(address(oracle), _req, _payment);\n }\n\n /**\n * @notice Creates a Chainlink request to the specified oracle address\n * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to\n * send LINK which creates a request on the target oracle contract.\n * Emits ChainlinkRequested event.\n * @param _oracle The address of the oracle for the request\n * @param _req The initialized Chainlink Request\n * @param _payment The amount of LINK to send for the request\n * @return The request ID\n */\n function sendChainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n requestId = keccak256(abi.encodePacked(this, requestCount));\n _req.nonce = requestCount;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requestCount += 1;\n\n return requestId;\n }\n\n /**\n * @notice Allows a request to be cancelled if it has not been fulfilled\n * @dev Requires keeping track of the expiration value emitted from the oracle contract.\n * Deletes the request from the `pendingRequests` mapping.\n * Emits ChainlinkCancelled event.\n * @param _requestId The request ID\n * @param _payment The amount of LINK sent for the request\n * @param _callbackFunc The callback function specified for the request\n * @param _expiration The time of the expiration for the request\n */\n function cancelChainlinkRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunc,\n uint256 _expiration\n )\n internal\n {\n ChainlinkRequestInterface requested = ChainlinkRequestInterface(pendingRequests[_requestId]);\n delete pendingRequests[_requestId];\n emit ChainlinkCancelled(_requestId);\n requested.cancelOracleRequest(_requestId, _payment, _callbackFunc, _expiration);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setChainlinkOracle(address _oracle) internal {\n oracle = ChainlinkRequestInterface(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setChainlinkToken(address _link) internal {\n link = LinkTokenInterface(_link);\n }\n\n /**\n * @notice Sets the Chainlink token address for the public\n * network as given by the Pointer contract\n */\n function setPublicChainlinkToken() internal {\n setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkTokenAddress()\n internal\n view\n returns (address)\n {\n return address(link);\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function chainlinkOracleAddress()\n internal\n view\n returns (address)\n {\n return address(oracle);\n }\n\n /**\n * @notice Allows for a request which was created on another contract to be fulfilled\n * on this contract\n * @param _oracle The address of the oracle contract that will fulfill the request\n * @param _requestId The request ID used for the response\n */\n function addChainlinkExternalRequest(address _oracle, bytes32 _requestId)\n internal\n notPendingRequest(_requestId)\n {\n pendingRequests[_requestId] = _oracle;\n }\n\n /**\n * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS\n * @dev Accounts for subnodes having different resolvers\n * @param _ens The address of the ENS contract\n * @param _node The ENS node hash\n */\n function useChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n ens = ENSInterface(_ens);\n ensNode = _node;\n bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));\n setChainlinkToken(resolver.addr(linkSubnode));\n updateChainlinkOracleWithENS();\n }\n\n /**\n * @notice Sets the stored oracle contract with the address resolved by ENS\n * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously\n */\n function updateChainlinkOracleWithENS()\n internal\n {\n bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));\n ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));\n setChainlinkOracle(resolver.addr(oracleSubnode));\n }\n\n /**\n * @notice Encodes the request to be sent to the oracle contract\n * @dev The Chainlink node expects values to be in order for the request to be picked up. Order of types\n * will be validated in the oracle contract.\n * @param _req The initialized Chainlink Request\n * @return The bytes payload for the `transferAndCall` method\n */\n function encodeRequest(Chainlink.Request memory _req)\n private\n view\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n oracle.oracleRequest.selector,\n SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address\n AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent\n _req.id,\n _req.callbackAddress,\n _req.callbackFunctionId,\n _req.nonce,\n ARGS_VERSION,\n _req.buf.buf);\n }\n\n /**\n * @notice Ensures that the fulfillment is valid for this contract\n * @dev Use if the contract developer prefers methods instead of modifiers for validation\n * @param _requestId The request ID for fulfillment\n */\n function validateChainlinkCallback(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\n {}\n\n /**\n * @dev Reverts if the sender is not the oracle of the request.\n * Emits ChainlinkFulfilled event.\n * @param _requestId The request ID for fulfillment\n */\n modifier recordChainlinkFulfillment(bytes32 _requestId) {\n require(msg.sender == pendingRequests[_requestId],\n\"Source must be the oracle of the request\");\n delete pendingRequests[_requestId];\n emit ChainlinkFulfilled(_requestId);\n _;\n }\n\n /**\n * @dev Reverts if the request is already pending\n * @param _requestId The request ID for fulfillment\n */\n modifier notPendingRequest(bytes32 _requestId) {\n require(pendingRequests[_requestId] == address(0), \"Request is already pending\");\n _;\n }\n}\n",
"Chainlink.sol":"pragma solidity ^0.5.0;\n\nimport { CBOR as CBOR_Chainlink } from \"./vendor/CBOR.sol\";\nimport { Buffer as Buffer_Chainlink } from \"./vendor/Buffer.sol\";\n\n/**\n * @title Library for common Chainlink functions\n * @dev Uses imported CBOR library for encoding to buffer\n */\nlibrary Chainlink {\n uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase\n\n using CBOR_Chainlink for Buffer_Chainlink.buffer;\n\n struct Request {\n bytes32 id;\n address callbackAddress;\n bytes4 callbackFunctionId;\n uint256 nonce;\n Buffer_Chainlink.buffer buf;\n }\n\n /**\n * @notice Initializes a Chainlink request\n * @dev Sets the ID, callback address, and callback function signature on the request\n * @param self The uninitialized request\n * @param _id The Job Specification ID\n * @param _callbackAddress The callback address\n * @param _callbackFunction The callback function signature\n * @return The initialized request\n */\n function initialize(\n Request memory self,\n bytes32 _id,\n address _callbackAddress,\n bytes4 _callbackFunction\n ) internal pure returns (Chainlink.Request memory) {\n Buffer_Chainlink.init(self.buf, defaultBufferSize);\n self.id = _id;\n self.callbackAddress = _callbackAddress;\n self.callbackFunctionId = _callbackFunction;\n return self;\n }\n\n /**\n * @notice Sets the data for the buffer without encoding CBOR on-chain\n * @dev CBOR can be closed with curly-brackets {} or they can be left off\n * @param self The initialized request\n * @param _data The CBOR data\n */\n function setBuffer(Request memory self, bytes memory _data)\n internal pure\n {\n Buffer_Chainlink.init(self.buf, _data.length);\n Buffer_Chainlink.append(self.buf, _data);\n }\n\n /**\n * @notice Adds a string value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The string value to add\n */\n function add(Request memory self, string memory _key, string memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeString(_value);\n }\n\n /**\n * @notice Adds a bytes value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The bytes value to add\n */\n function addBytes(Request memory self, string memory _key, bytes memory _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeBytes(_value);\n }\n\n /**\n * @notice Adds a int256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The int256 value to add\n */\n function addInt(Request memory self, string memory _key, int256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeInt(_value);\n }\n\n /**\n * @notice Adds a uint256 value to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _value The uint256 value to add\n */\n function addUint(Request memory self, string memory _key, uint256 _value)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.encodeUInt(_value);\n }\n\n /**\n * @notice Adds an array of strings to the request with a given key name\n * @param self The initialized request\n * @param _key The name of the key\n * @param _values The array of string values to add\n */\n function addStringArray(Request memory self, string memory _key, string[] memory _values)\n internal pure\n {\n self.buf.encodeString(_key);\n self.buf.startArray();\n for (uint256 i = 0; i < _values.length; i++) {\n self.buf.encodeString(_values[i]);\n }\n self.buf.endSequence();\n }\n}\n",
"vendor/Buffer.sol":"pragma solidity ^0.5.0;\n\n/**\n* @dev A library for working with mutable byte buffers in Solidity.\n*\n* Byte buffers are mutable and expandable, and provide a variety of primitives\n* for writing to them. At any time you can fetch a bytes object containing the\n* current contents of the buffer. The bytes object should not be stored between\n* operations, as it may change due to resizing of the buffer.\n*/\nlibrary Buffer {\n /**\n * @dev Represents a mutable buffer. Buffers have a current value (buf) and\n * a capacity. The capacity may be longer than the current value, in\n * which case it can be extended without the need to allocate more memory.\n */\n struct buffer {\n bytes buf;\n uint capacity;\n }\n\n /**\n * @dev Initializes a buffer with an initial capacity.\n * @param buf The buffer to initialize.\n * @param capacity The number of bytes of space to allocate the buffer.\n * @return The buffer, for chaining.\n */\n function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {\n if (capacity % 32 != 0) {\n capacity += 32 - (capacity % 32);\n }\n // Allocate space for the buffer data\n buf.capacity = capacity;\n assembly {\n let ptr := mload(0x40)\n mstore(buf, ptr)\n mstore(ptr, 0)\n mstore(0x40, add(32, add(ptr, capacity)))\n }\n return buf;\n }\n\n /**\n * @dev Initializes a new buffer from an existing bytes object.\n * Changes to the buffer may mutate the original value.\n * @param b The bytes object to initialize the buffer with.\n * @return A new buffer.\n */\n function fromBytes(bytes memory b) internal pure returns(buffer memory) {\n buffer memory buf;\n buf.buf = b;\n buf.capacity = b.length;\n return buf;\n }\n\n function resize(buffer memory buf, uint capacity) private pure {\n bytes memory oldbuf = buf.buf;\n init(buf, capacity);\n append(buf, oldbuf);\n }\n\n function max(uint a, uint b) private pure returns(uint) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n /**\n * @dev Sets buffer length to 0.\n * @param buf The buffer to truncate.\n * @return The original buffer, for chaining..\n */\n function truncate(buffer memory buf) internal pure returns (buffer memory) {\n assembly {\n let bufptr := mload(buf)\n mstore(bufptr, 0)\n }\n return buf;\n }\n\n /**\n * @dev Writes a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The start offset to write to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {\n require(len <= data.length);\n\n if (off + len > buf.capacity) {\n resize(buf, max(buf.capacity, len + off) * 2);\n }\n\n uint dest;\n uint src;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Start address = buffer address + offset + sizeof(buffer length)\n dest := add(add(bufptr, 32), off)\n // Update buffer length if we're extending it\n if gt(add(len, off), buflen) {\n mstore(bufptr, add(len, off))\n }\n src := add(data, 32)\n }\n\n // Copy word-length chunks while possible\n for (; len >= 32; len -= 32) {\n assembly {\n mstore(dest, mload(src))\n }\n dest += 32;\n src += 32;\n }\n\n // Copy remaining bytes\n uint mask = 256 ** (32 - len) - 1;\n assembly {\n let srcpart := and(mload(src), not(mask))\n let destpart := and(mload(dest), mask)\n mstore(dest, or(destpart, srcpart))\n }\n\n return buf;\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @param len The number of bytes to copy.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, len);\n }\n\n /**\n * @dev Appends a byte string to a buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, data.length);\n }\n\n /**\n * @dev Writes a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write the byte at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {\n if (off >= buf.capacity) {\n resize(buf, buf.capacity * 2);\n }\n\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Length of existing buffer data\n let buflen := mload(bufptr)\n // Address = buffer address + sizeof(buffer length) + off\n let dest := add(add(bufptr, off), 32)\n mstore8(dest, data)\n // Update buffer length if we extended it\n if eq(off, buflen) {\n mstore(bufptr, add(buflen, 1))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {\n return writeUint8(buf, buf.buf.length, data);\n }\n\n /**\n * @dev Writes up to 32 bytes to the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (left-aligned).\n * @return The original buffer, for chaining.\n */\n function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n // Right-align data\n data = data >> (8 * (32 - len));\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + sizeof(buffer length) + off + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the\n * capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, off, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chhaining.\n */\n function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, bytes32(data), 20);\n }\n\n /**\n * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer, for chaining.\n */\n function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {\n return write(buf, buf.buf.length, data, 32);\n }\n\n /**\n * @dev Writes an integer to the buffer. Resizes if doing so would exceed\n * the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param off The offset to write at.\n * @param data The data to append.\n * @param len The number of bytes to write (right-aligned).\n * @return The original buffer, for chaining.\n */\n function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {\n if (len + off > buf.capacity) {\n resize(buf, (len + off) * 2);\n }\n\n uint mask = 256 ** len - 1;\n assembly {\n // Memory address of the buffer data\n let bufptr := mload(buf)\n // Address = buffer address + off + sizeof(buffer length) + len\n let dest := add(add(bufptr, off), len)\n mstore(dest, or(and(mload(dest), not(mask)), data))\n // Update buffer length if we extended it\n if gt(add(off, len), mload(bufptr)) {\n mstore(bufptr, add(off, len))\n }\n }\n return buf;\n }\n\n /**\n * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n * exceed the capacity of the buffer.\n * @param buf The buffer to append to.\n * @param data The data to append.\n * @return The original buffer.\n */\n function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n return writeInt(buf, buf.buf.length, data, len);\n }\n}",
"interfaces/ENSInterface.sol":"pragma solidity ^0.5.0;\n\ninterface ENSInterface {\n\n // Logged when the owner of a node assigns a new owner to a subnode.\n event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);\n\n // Logged when the owner of a node transfers ownership to a new account.\n event Transfer(bytes32 indexed node, address owner);\n\n // Logged when the resolver for a node changes.\n event NewResolver(bytes32 indexed node, address resolver);\n\n // Logged when the TTL of a node changes\n event NewTTL(bytes32 indexed node, uint64 ttl);\n\n\n function setSubnodeOwner(bytes32 node, bytes32 label, address _owner) external;\n function setResolver(bytes32 node, address _resolver) external;\n function setOwner(bytes32 node, address _owner) external;\n function setTTL(bytes32 node, uint64 _ttl) external;\n function owner(bytes32 node) external view returns (address);\n function resolver(bytes32 node) external view returns (address);\n function ttl(bytes32 node) external view returns (uint64);\n\n}\n",
"interfaces/LinkTokenInterface.sol":"pragma solidity ^0.5.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n function approve(address spender, uint256 value) external returns (bool success);\n function balanceOf(address owner) external view returns (uint256 balance);\n function decimals() external view returns (uint8 decimalPlaces);\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n function increaseApproval(address spender, uint256 subtractedValue) external;\n function name() external view returns (string memory tokenName);\n function symbol() external view returns (string memory tokenSymbol);\n function totalSupply() external view returns (uint256 totalTokensIssued);\n function transfer(address to, uint256 value) external returns (bool success);\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",