This package stores all of chainlink's smart contracts, previously known as the `evm/` directory. The previous package was called `chainlink`, now it is `@chainlink/contracts`.
## Installation
```sh
# via Yarn
$ yarn add @chainlink/contracts
# via npm
$ npm install @chainlink/contracts --save
```
## Directory Structure
This package makes use of `@chainlink/belt` to output artifacts along with ethers.js and truffle contract abstractions from the smart contracts stored within `src`. The resulting structure of the package when published looks like:
```sh
contracts
├── abi # abi output from src/
│ ├── v0.4
│ ├── v0.5
│ ├── v0.6
│ ├── v0.7
│ └── v0.8
├── ethers # ethers contract abstractions codegenned from abis
│ ├── v0.4
│ ├── v0.5
│ ├── v0.6
│ ├── v0.7
│ └── v0.8
├── src # the contracts themselves, in .sol form
│ ├── v0.4
│ ├── v0.5
│ ├── v0.6
│ ├── v0.7
│ └── v0.8
└── truffle # truffle contract abstractions codegenned from abis
├── v0.4
├── v0.5
├── v0.6
├── v0.7
└── v0.8
```
## Usage
These smart contracts can be imported as a dependency in various ways described below.
### Solidity
The solidity smart contracts themselves can simply be imported via the `src` directory of `@chainlink/contracts`. If you wanted to consume the v0.4.x version of our Oracle smart contract, you could do the following:
JSON artifacts generated by [sol-compiler](https://sol-compiler.com/) are available under the `abi` directory. If you wanted to consume the v0.4.x version of our Oracle JSON artifact with Javascript, you could do the following:
This library ships with [ethers.js](https://github.com/ethers-io/ethers.js/) contract abstractions generated by [typechain](https://github.com/ethereum-ts/TypeChain). To use these, make sure you have ethers.js installed as a dependency:
```sh
# via Yarn
$ yarn add ethers@^4.0.44
# via npm
$ npm install ethers@^4.0.44 --save
```
If you wanted to consume the v0.4.x version of our Oracle with JavaScript, you could do the following:
This gives a fully typed (if using TypeScript) version of a ethers.js contract factory. See the [ethers.js](https://docs.ethers.io/ethers.js/html/api-contract.html) documentation on usage.
### Truffle
This library ships with [@truffle/contract](https://github.com/trufflesuite/truffle/tree/master/packages/contract#readme) abstractions of each of our smart contracts. To use these, make sure you have @truffle/contract as a dependency.
```sh
# via Yarn
$ yarn add @truffle/contract@^4.1.8
# via npm
$ npm install @truffle/contract@^4.1.8 --save
```
If you wanted to consume the v0.4.x version of our Oracle with JavaScript, you could do the following:
For usage, see the [@truffle/contract](https://github.com/trufflesuite/truffle/tree/master/packages/contract#readme) documentation.
For ease of use with testing, if the environment variable `NODE_ENV` is set, the imported truffle contract abstraction will automatically set its provider to `web3.currentProvider`, avoiding the need to perform a `setProvider` call before using it during your truffle tests.
```sh
NODE_ENV=true yarn truffle test
```
## Development
Note: Contracts in `src/v0.7/dev` are under active development and not yet stable.
"_expiration":"is the time when the request expires",
"_payment":"is the amount of LINK paid to the oracle for the request",
"_requestId":"is the identifier for the chainlink request being cancelled"
}
},
"chainlinkCallback(bytes32,int256)":{
"details":"This function can only be called by the oracle that received the request.",
"params":{
"_clRequestId":"The Chainlink request ID associated with the answer",
"_response":"The answer provided by the Chainlink node"
}
},
"getAnswer(uint256)":{
"params":{
"_roundId":"the answer number to retrieve the answer for"
}
},
"getTimestamp(uint256)":{
"params":{
"_roundId":"the answer number to retrieve the updated timestamp for"
}
},
"renounceOwnership()":{
"details":"Allows the current owner to relinquish control of the contract."
},
"requestRateUpdate()":{
"details":"This example does not include request parameters. Reference any documentation associated with the Job IDs used to determine the required parameters per-request."
},
"setAuthorization(address,bool)":{
"params":{
"_allowed":"boolean that determines whether the requester is permissioned or not",
"_requester":"the address whose permissions are being set"
}
},
"transferLINK(address,uint256)":{
"details":"The contract will need to have a LINK balance in order to create requests.",
"params":{
"_amount":"The amount of LINK to send from the contract",
"_recipient":"The address to receive the LINK tokens"
}
},
"transferOwnership(address)":{
"details":"Allows the current owner to transfer control of the contract to a newOwner.",
"params":{
"_newOwner":"The address to transfer ownership to."
"metadata":"{\"compiler\":{\"version\":\"0.4.24+commit.e67f0147\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":false,\"inputs\":[{\"name\":\"_requestId\",\"type\":\"bytes32\"},{\"name\":\"_payment\",\"type\":\"uint256\"},{\"name\":\"_expiration\",\"type\":\"uint256\"}],\"name\":\"cancelRequest\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"authorizedRequesters\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"jobIds\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"latestAnswer\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minimumResponses\",\"outputs\":[{\"name\":\"\",\"type\":\"uint128\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"oracles\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_recipient\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"transferLINK\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"latestRound\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_clRequestId\",\"type\":\"bytes32\"},{\"name\":\"_response\",\"type\":\"int256\"}],\"name\":\"chainlinkCallback\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_paymentAmount\",\"type\":\"uint128\"},{\"name\":\"_minimumResponses\",\"type\":\"uint128\"},{\"name\":\"_oracles\",\"type\":\"address[]\"},{\"name\":\"_jobIds\",\"type\":\"bytes32[]\"}],\"name\":\"updateRequestDetails\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"latestTimestamp\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"destroy\",\"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\":\"_roundId\",\"type\":\"uint256\"}],\"name\":\"getAnswer\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_roundId\",\"type\":\"uint256\"}],\"name\":\"getTimestamp\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"paymentAmount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint128\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"requestRateUpdate\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_requester\",\"type\":\"address\"},{\"name\":\"_allowed\",\"type\":\"bool\"}],\"name\":\"setAuthorization\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_link\",\"type\":\"address\"},{\"name\":\"_paymentAmount\",\"type\":\"uint128\"},{\"name\":\"_minimumResponses\",\"type\":\"uint128\"},{\"name\":\"_oracles\",\"type\":\"address[]\"},{\"name\":\"_jobIds\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"response\",\"type\":\"int256\"},{\"indexed\":true,\"name\":\"answerId\",\"type\":\"uint256\"},{\"indexed\":true,\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"ResponseReceived\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"}],\"name\":\"OwnershipRenounced\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"ChainlinkRequested\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"ChainlinkFulfilled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"ChainlinkCancelled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"current\",\"type\":\"int256\"},{\"indexed\":true,\"name\":\"roundId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"timestamp\",\"type\":\"uint256\"}],\"name\":\"AnswerUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"roundId\",\"type\":\"uint256\"},{\"indexed\":true,\"name\":\"startedBy\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"startedAt\",\"type\":\"uint256\"}],\"name\":\"NewRound\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"cancelRequest(bytes32,uint256,uint256)\":{\"params\":{\"_expiration\":\"is the time when the request expires\",\"_payment\":\"is the amount of LINK paid to the oracle for the request\",\"_requestId\":\"is the identifier for the chainlink request being cancelled\"}},\"chainlinkCallback(bytes32,int256)\":{\"details\":\"This function can only be called by the oracle that received the request.\",\"params\":{\"_clRequestId\":\"The Chainlink request ID associated with the answer\",\"_response\":\"The answer provided by the Chainlink node\"}},\"getAnswer(uint256)\":{\"params\":{\"_roundId\":\"the answer number to retrieve the answer for\"}},\"getTimestamp(uint256)\":{\"params\":{\"_roundId\":\"the answer number to retrieve the updated timestamp for\"}},\"renounceOwnership()\":{\"details\":\"Allows the current owner to relinquish control of the contract.\"},\"requestRateUpdate()\":{\"details\":\"This example does not include request parameters. Reference any documentation associated with the Job IDs used to determine the required parameters per-request.\"},\"setAuthorization(address,bool)\":{\"params\":{\"_allowed\":\"boolean that determines whether the requester is permissioned or not\",\"_requester\":\"the address whose permissions are being set\"}},\"transferLINK(address,uint256)\":{\"details\":\"The contract will need to have a LINK balance in order to create requests.\",\"params\":{\"_amount\":\"The amount of LINK to send from the contract\",\"_recipient\":\"The address to receive the LINK tokens\"}},\"transferOwnership(address)\":{\"details\":\"Allows the current owner to transfer control of the contract to a newOwner.\",\"params\":{\"_newOwner\":\"The address to transfer ownership to.\"}},\"updateRequestDetails(uint128,uint128,address[],bytes32[])\":{\"details\":\"Arrays are validated to be equal length.\",\"params\":{\"_jobIds\":\"An array of Job IDs\",\"_minimumResponses\":\"the minimum number of responses before an answer will be calculated\",\"_oracles\":\"An array of oracle addresses\",\"_paymentAmount\":\"the amount of LINK to be sent to each oracle for each request\"}}},\"title\":\"An example Chainlink contract with aggregation\"},\"userdoc\":{\"methods\":{\"cancelRequest(bytes32,uint256,uint256)\":{\"notice\":\"Cancels an outstanding Chainlink request. The oracle contract requires the request ID and additional metadata to validate the cancellation. Only old answers can be cancelled.\"},\"chainlinkCallback(bytes32,int256)\":{\"notice\":\"Receives the answer from the Chainlink node.\"},\"destroy()\":{\"notice\":\"Called by the owner to kill the contract. This transfers all LINK balance and ETH balance (if there is any) to the owner.\"},\"getAnswer(uint256)\":{\"notice\":\"get past rounds answers\"},\"getTimestamp(uint256)\":{\"notice\":\"get block timestamp when an answer was last updated\"},\"latestAnswer()\":{\"notice\":\"get the most recently reported answer\"},\"latestRound()\":{\"notice\":\"get the latest completed round where the answer was updated\"},\"latestTimestamp()\":{\"notice\":\"get the last updated at block timestamp\"},\"renounceOwnership()\":{\"notice\":\"Renouncing to ownership will leave the contract without an owner. It will not be possible to call the functions with the `onlyOwner` modifier anymore.\"},\"requestRateUpdate()\":{\"notice\":\"Creates a Chainlink request for each oracle in the oracles array.\"},\"setAuthorization(address,bool)\":{\"notice\":\"Called by the owner to permission other addresses to generate new requests to oracles.\"},\"transferLINK(address,uint256)\":{\"notice\":\"Allows the owner of the contract to withdraw any LINK balance available on the contract.\"},\"updateRequestDetails(uint128,uint128,address[],bytes32[])\":{\"notice\":\"Updates the arrays of oracles and jobIds with new values, overwriting the old values.\"}}}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/Aggregator.sol\":\"Aggregator\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/Aggregator.sol\":{\"keccak256\":\"0x6894b629d1a332fcf970e765f36a4c6561eb0b6cc7d53973712860ed92ccc684\",\"urls\":[\"bzzr://1669ba7f4f8af6071b89d3a15842b1bc903ab5ceaaa628a4d9f4413aaed1b9aa\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/Chainlink.sol\":{\"keccak256\":\"0x3e8d01f8aead4e1eac6b3332d366ed8bc2ef5d889c2c8c344777b981d4071f63\",\"urls\":[\"bzzr://7be4bdda81bc444446593968124112fb399d460f529d80761e50c47874b9cb4f\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/ChainlinkClient.sol\":{\"keccak256\":\"0xc36504687b2b37000d8e6e25830cdb613c3e88509b0253aa09220e18876dc380\",\"urls\":[\"bzzr://a678a44b26b199a1600d422f4f6eda5d805f00a360245037a1c465b48274fe6d\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/AggregatorInterface.sol\":{\"keccak256\":\"0xb21fa756e241d3fbfe7546158a7e1bb4a98f261744751c4e9dfe5f474ea46338\",\"urls\":[\"bzzr://acb860d28a70616f38d2d7d72ce5c82a2221734deefe67ace468112e92679bf7\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/ChainlinkRequestInterface.sol\":{\"keccak256\":\"0x7d3983584065248fba8f0ce75fd86feac43ade43784466f87ea502254ddec992\",\"urls\":[\"bzzr://30de07df8cb9fb4ec53aff0f115f88d65936ffd6e90d2aeb031a05d6bf4de6c1\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/ENSInterface.sol\":{\"keccak256\":\"0xd0b1a6134b5d6c0213bc4db5df8693ec41e13de3d97d43cc8d19639e516f9767\",\"urls\":[\"bzzr://93d66e26b4b5cf6cfa8c6a5d04cb56ff27d49a2aee8f54858ac3db7658355b1f\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/LinkTokenInterface.sol\":{\"keccak256\":\"0x37f31fbd4f4f28ba236cbd9a61ae9b6f7806ea7fe0a684a855e4835f808f8b92\",\"urls\":[\"bzzr://5518135de15ba1afd8bdac829875935dea5520b152d1f602cdc34551d3c0b806\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/PointerInterface.sol\":{\"keccak256\":\"0x8019f30a207af4ee80a8b2774e42aba721641254ed0a97826a54f33d7caef218\",\"urls\":[\"bzzr://8ddbb9ae67ec27aed40d6013d6ea176c05f7cd61d4f6fa95492a03fa086d90af\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/Buffer.sol\":{\"keccak256\":\"0x900b4c8ab35b4876d89835a8b050c96107ace250a70f64c5bba6a78a60f03883\",\"urls\":[\"bzzr://408340da4e8fa35e608196ee508f11f9d44f6f70a10f0db0083ab20b5a894d59\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/CBOR.sol\":{\"keccak256\":\"0x93faa5cd4bb12e81f73ee0edd3c1fe4fa6dbb0a0a7ab550e46b3c3d845268c9d\",\"urls\":[\"bzzr://c7f8bd088823a62b35a8138d5b2ff380d0527a030121a226c2a47559ea7d3679\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/ENSResolver.sol\":{\"keccak256\":\"0x08965df63f00cb8d164d6fc36a0c388740725906b0bfb79b17391d5dfeabf683\",\"urls\":[\"bzzr://0700cb12e032ed8ed8327e446dfd805ae9fa28785a2909a73def511fe374b8cd\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/Ownable.sol\":{\"keccak256\":\"0x84c7090c27cf3657b73d9e26b6b316975fa0bd233b8169f254de0c3b3acfaefc\",\"urls\":[\"bzzr://b983355647976c1daa5de581a1b6a41be9c5adc17cce257b8679649db78f8a11\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/SafeMathChainlink.sol\":{\"keccak256\":\"0xb822782dea15f1fa4992c27639e9f9e4a4758b2c2fd8b12ec90c4de336de9074\",\"urls\":[\"bzzr://1328bb1e33d56d48209e5bbea79fa18b212e8df3f449ac9a75d20962cc36cce5\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/SignedSafeMath.sol\":{\"keccak256\":\"0xc4d1131c258388162b46ce765e2ceeb68122dbf586447c47f99101d65d5f75af\",\"urls\":[\"bzzr://305e6947adba7e8d4eb6b8e4bc989d874780507df4a2c1fb5cc29d139f2f4efa\"]}},\"version\":1}",
"userdoc":{
"methods":{
"cancelRequest(bytes32,uint256,uint256)":{
"notice":"Cancels an outstanding Chainlink request. The oracle contract requires the request ID and additional metadata to validate the cancellation. Only old answers can be cancelled."
},
"chainlinkCallback(bytes32,int256)":{
"notice":"Receives the answer from the Chainlink node."
},
"destroy()":{
"notice":"Called by the owner to kill the contract. This transfers all LINK balance and ETH balance (if there is any) to the owner."
},
"getAnswer(uint256)":{
"notice":"get past rounds answers"
},
"getTimestamp(uint256)":{
"notice":"get block timestamp when an answer was last updated"
},
"latestAnswer()":{
"notice":"get the most recently reported answer"
},
"latestRound()":{
"notice":"get the latest completed round where the answer was updated"
},
"latestTimestamp()":{
"notice":"get the last updated at block timestamp"
},
"renounceOwnership()":{
"notice":"Renouncing to ownership will leave the contract without an owner. It will not be possible to call the functions with the `onlyOwner` modifier anymore."
},
"requestRateUpdate()":{
"notice":"Creates a Chainlink request for each oracle in the oracles array."
},
"setAuthorization(address,bool)":{
"notice":"Called by the owner to permission other addresses to generate new requests to oracles."
},
"transferLINK(address,uint256)":{
"notice":"Allows the owner of the contract to withdraw any LINK balance available on the contract."
"notice":"Updates the arrays of oracles and jobIds with new values, overwriting the old values."
}
}
}
},
"sources":{
"Aggregator.sol":{
"id":0
},
"ChainlinkClient.sol":{
"id":2
},
"Chainlink.sol":{
"id":1
},
"vendor/CBOR.sol":{
"id":34
},
"vendor/Buffer.sol":{
"id":33
},
"interfaces/ENSInterface.sol":{
"id":12
},
"interfaces/LinkTokenInterface.sol":{
"id":18
},
"interfaces/ChainlinkRequestInterface.sol":{
"id":11
},
"interfaces/PointerInterface.sol":{
"id":20
},
"vendor/ENSResolver.sol":{
"id":37
},
"interfaces/AggregatorInterface.sol":{
"id":9
},
"vendor/SignedSafeMath.sol":{
"id":41
},
"vendor/Ownable.sol":{
"id":38
},
"vendor/SafeMathChainlink.sol":{
"id":40
}
},
"sourceCodes":{
"Aggregator.sol":"pragma solidity 0.4.24;\n\nimport \"./ChainlinkClient.sol\";\nimport \"./interfaces/AggregatorInterface.sol\";\nimport \"./vendor/SignedSafeMath.sol\";\nimport \"./vendor/Ownable.sol\";\nimport \"./vendor/SafeMathChainlink.sol\";\n\n/**\n * @title An example Chainlink contract with aggregation\n * @notice Requesters can use this contract as a framework for creating\n * requests to multiple Chainlink nodes and running aggregation\n * as the contract receives answers.\n */\ncontract Aggregator is AggregatorInterface, ChainlinkClient, Ownable {\n using SafeMathChainlink for uint256;\n using SignedSafeMath for int256;\n\n struct Answer {\n uint128 minimumResponses;\n uint128 maxResponses;\n int256[] responses;\n }\n\n event ResponseReceived(int256 indexed response, uint256 indexed answerId, address indexed sender);\n\n int256 private currentAnswerValue;\n uint256 private updatedTimestampValue;\n uint256 private latestCompletedAnswer;\n uint128 public paymentAmount;\n uint128 public minimumResponses;\n bytes32[] public jobIds;\n address[] public oracles;\n\n uint256 private answerCounter = 1;\n mapping(address => bool) public authorizedRequesters;\n mapping(bytes32 => uint256) private requestAnswers;\n mapping(uint256 => Answer) private answers;\n mapping(uint256 => int256) private currentAnswers;\n mapping(uint256 => uint256) private updatedTimestamps;\n\n uint256 constant private MAX_ORACLE_COUNT = 28;\n\n /**\n * @notice Deploy with the address of the LINK token and arrays of matching\n * length containing the addresses of the oracles and their corresponding\n * Job IDs.\n * @dev Sets the LinkToken address for the network, addresses of the oracles,\n * and jobIds in storage.\n * @param _link The address of the LINK token\n * @param _paymentAmount the amount of LINK to be sent to each oracle for each request\n * @param _minimumResponses the minimum number of responses\n * before an answer will be calculated\n * @param _oracles An array of oracle addresses\n * @param _jobIds An array of Job IDs\n */\n constructor(\n address _link,\n uint128 _paymentAmount,\n uint128 _minimumResponses,\n address[] _oracles,\n bytes32[] _jobIds\n ) public Ownable() {\n setChainlinkToken(_link);\n updateRequestDetails(_paymentAmount, _minimumResponses, _oracles, _jobIds);\n }\n\n /**\n * @notice Creates a Chainlink request for each oracle in the oracles array.\n * @dev This example does not include request parameters. Reference any documentation\n * associated with the Job IDs used to determine the required parameters per-request.\n */\n function requestRateUpdate()\n external\n ensureAuthorizedRequester()\n {\n Chainlink.Request memory request;\n bytes32 requestId;\n uint256 oraclePayment = paymentAmount;\n\n for (uint i = 0; i < oracles.length; i++) {\n request = buildChainlinkRequest(jobIds[i], this, this.chainlinkCallback.selector);\n requestId = sendChainlinkRequestTo(oracles[i], request, oraclePayment);\n requestAnswers[requestId] = answerCounter;\n }\n answers[answerCounter].minimumResponses = minimumResponses;\n answers[answerCounter].maxResponses = uint128(oracles.length);\n\n emit NewRound(answerCounter, msg.sender, block.timestamp);\n\n answerCounter = answerCounter.add(1);\n }\n\n /**\n * @notice Receives the answer from the Chainlink node.\n * @dev This function can only be called by the oracle that received the request.\n * @param _clRequestId The Chainlink request ID associated with the answer\n * @param _response The answer provided by the Chainlink node\n */\n function chainlinkCallback(bytes32 _clRequestId, int256 _response)\n external\n {\n validateChainlinkCallback(_clRequestId);\n\n uint256 answerId = requestAnswers[_clRequestId];\n delete requestAnswers[_clRequestId];\n\n answers[answerId].responses.push(_response);\n emit ResponseReceived(_response, answerId, msg.sender);\n updateLatestAnswer(answerId);\n deleteAnswer(answerId);\n }\n\n /**\n * @notice Updates the arrays of oracles and jobIds with new values,\n * overwriting the old values.\n * @dev Arrays are validated to be equal length.\n * @param _paymentAmount the amount of LINK to be sent to each oracle for each request\n * @param _minimumResponses the minimum number of responses\n * before an answer will be calculated\n * @param _oracles An array of oracle addresses\n * @param _jobIds An array of Job IDs\n */\n function updateRequestDetails(\n uint128 _paymentAmount,\n uint128 _minimumResponses,\n address[] _oracles,\n bytes32[] _jobIds\n )\n public\n onlyOwner()\n validateAnswerRequirements(_minimumResponses, _oracles, _jobIds)\n {\n paymentAmount = _paymentAmount;\n minimumResponses = _minimumResponses;\n jobIds = _jobIds;\n oracles = _oracles;\n }\n\n /**\n * @notice Allows the owner of the contract to withdraw any LINK balance\n * available on the contract.\n * @dev The contract will need to have a LINK balance in order to create requests.\n * @param _recipient The address to receive the LINK tokens\n * @param _amount The amount of LINK to send from the contract\n */\n function transferLINK(address _recipient, uint256 _amount)\n public\n onlyOwner()\n {\n LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());\n require(linkToken.transfer(_recipient, _amount), \"LINK transfer failed\");\n }\n\n /**\n * @notice Called by the owner to permission other addresses to generate new\n * requests to oracles.\n * @param _requester the address whose permissions are being set\n * @param _allowed boolean that determines whether the requester is\n * permissioned or not\n */\n function setAuthorization(address _requester, bool _allowed)\n external\n onlyOwner()\n {\n authorizedRequesters[_requester] = _allowed;\n }\n\n /**\n * @notice Cancels an outstanding Chainlink request.\n * The oracle contract requires the request ID and additional metadata to\n * validate the cancellation. Only old answers can be cancelled.\n * @param _requestId is the identifier for the chainlink request being cancelled\n * @param _payment is the amount of LINK paid to the oracle for the request\n * @param _expiration is the time when the request expires\n */\n function cancelRequest(\n bytes32 _requestId,\n uint256 _payment,\n uint256 _expiration\n )\n external\n ensureAuthorizedRequester()\n {\n uint256 answerId = requestAnswers[_requestId];\n require(answerId < latestCompletedAnswer, \"Cannot modify an in-progress answer\");\n\n delete requestAnswers[_requestId];\n answers[answerId].responses.push(0);\n deleteAnswer(answerId);\n\n cancelChainlinkRequest(\n _requestId,\n _payment,\n this.chainlinkCallback.selector,\n _expiration\n );\n }\n\n /**\n * @notice Called by the owner to kill the contract. This transfers all LINK\n * balance and ETH balance (if there is any) to the owner.\n */\n function destroy()\n external\n onlyOwner()\n {\n LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());\n transferLINK(owner, linkToken.balanceOf(address(this)));\n selfdestruct(owner);\n }\n\n /**\n * @dev Performs aggregation of the answers received from the Chainlink nodes.\n * Assumes that at least half the oracles are honest and so can't contol the\n * middle of the ordered responses.\n * @param _answerId The answer ID associated with the group of requests\n */\n function updateLatestAnswer(uint256 _answerId)\n private\n ensureMinResponsesReceived(_answerId)\n ensureOnlyLatestAnswer(_answerId)\n {\n uint256 responseLength = answers[_answerId].responses.length;\n uint256 middleIndex = responseLength.div(2);\n int256 currentAnswerTemp;\n if (responseLength % 2 == 0) {\n int256 median1 = quickselect(answers[_answerId].responses, middleIndex);\n int256 median2 = quickselect(answers[_answerId].responses, middleIndex.add(1)); // quickselect is 1 indexed\n currentAnswerTemp = median1.add(median2) / 2; // signed integers are not supported by SafeMath\n } else {\n currentAnswerTemp = quickselect(answers[_answerId].responses, middleIndex.add(1)); // quickselect is 1 indexed\n }\n currentAnswerValue = currentAnswerTemp;\n latestCompletedAnswer = _answerId;\n updatedTimestampValue = now;\n updatedTimestamps[_answerId] = now;\n currentAnswers[_answerId] = currentAnswerTemp;\n emit AnswerUpdated(currentAnswerTemp, _answerId, now);\n }\n\n /**\n * @notice get the most recently reported answer\n */\n function latestAnswer()\n external\n view\n returns (int256)\n {\n return currentAnswers[latestCompletedAnswer];\n }\n\n /**\n * @notice get the last updated at block timestamp\n */\n function latestTimestamp()\n external\n view\n returns (uint256)\n {\n return updatedTimestamps[latestCompletedAnswer];\n }\n\n /**\n * @notice get past rounds answers\n * @param _roundId the answer number to retrieve the answer for\n */\n function getAnswer(uint256 _roundId)\n external\n view\n returns (int256)\n {\n return currentAnswers[_roundId];\n }\n\n /**\n * @notice get block timestamp when an answer was last updated\n * @param _roundId the answer number to retrieve the updated timestamp for\n */\n function getTimestamp(uint256 _roundId)\n external\n view\n returns (uint256)\n {\n return updatedTimestamps[_roundId];\n }\n\n /**\n * @notice get the latest completed round where the answer was updated\n */\n function latestRound()\n external\n view\n returns (uint256)\n {\n return latestCompletedAnswer;\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 Cleans up the answer record if all responses have been received.\n * @param _answerId The identifier of the answer to be deleted\n */\n function deleteAnswer(uint256 _answerId)\n private\n ensureAllResponsesReceived(_answerId)\n {\n delete answers[_answerId];\n }\n\n /**\n * @dev Prevents taking an action if the minimum number of responses has not\n * been received for an answer.\n * @param _answerId The the identifier of the answer that keeps track of the responses.\n */\n modifier ensureMinResponsesReceived(uint256 _answerId) {\n if (answers[_answerId].responses.length >= answers[_answerId].minimumResponses) {\n _;\n }\n }\n\n /**\n * @dev Prevents taking an action if not all responses are received for an answer.\n * @param _answerId The the identifier of the answer that keeps track of the responses.\n */\n modifier ensureAllResponsesReceived(uint256 _answerId) {\n if (answers[_answerId].responses.length == answers[_answerId].maxResponses) {\n _;\n }\n }\n\n /**\n * @dev Prevents taking an action if a newer answer has been recorded.\n * @param _answerId The current answer's identifier.\n * Answer IDs are in ascending order.\n */\n modifier ensureOnlyLatestAnswer(uint256 _answerId) {\n if (latestCompletedAnswer <= _answerId) {\n _;\n }\n }\n\n /**\n * @dev Ensures corresponding number of oracles and jobs.\n * @param _oracles The list of oracles.\n * @param _jobIds The list of jobs.\n */\n modifier validateAnswerRequirements(\n uint256 _minimumResponses,\n address[] _oracles,\n bytes32[] _jobIds\n ) {\n require(_oracles.length <= MAX_ORACLE_COUNT, \"cannot have more than 45 oracles\");\n require(_oracles.length >= _minimumResponses, \"must have at least as many oracles as responses\");\n require(_oracles.length == _jobIds.length, \"must have exactly as many oracles as job IDs\");\n _;\n }\n\n /**\n * @dev Reverts if `msg.sender` is not authorized to make requests.\n */\n modifier ensureAuthorizedRequester() {\n require(authorizedRequesters[msg.sender] || msg.sender == owner, \"Not an authorized address for creating requests\");\n _;\n }\n\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"vendor/SignedSafeMath.sol":"pragma solidity 0.4.24;\n\n/**\n * @title SignedSafeMath\n * @dev Signed math operations with safety checks that revert on error.\n */\nlibrary SignedSafeMath {\n int256 constant private _INT256_MIN = -2**255;\n\n /**\n * @dev Multiplies two signed integers, reverts on overflow.\n */\n function mul(int256 a, int256 b) internal pure returns (int256) {\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-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n require(!(a == -1 && b == _INT256_MIN), \"SignedSafeMath: multiplication overflow\");\n\n int256 c = a * b;\n require(c / a == b, \"SignedSafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Integer division of two signed integers truncating the quotient, reverts on division by zero.\n */\n function div(int256 a, int256 b) internal pure returns (int256) {\n require(b != 0, \"SignedSafeMath: division by zero\");\n require(!(b == -1 && a == _INT256_MIN), \"SignedSafeMath: division overflow\");\n\n int256 c = a / b;\n\n return c;\n }\n\n /**\n * @dev Subtracts two signed integers, reverts on overflow.\n */\n function sub(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a - b;\n require((b >= 0 && c <= a) || (b < 0 && c > a), \"SignedSafeMath: subtraction overflow\");\n\n return c;\n }\n\n /**\n * @dev Adds two signed integers, reverts on overflow.\n */\n function add(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a + b;\n require((b >= 0 && c >= a) || (b < 0 && c < a), \"SignedSafeMath: addition overflow\");\n\n return c;\n }\n}\n",
"vendor/Ownable.sol":"pragma solidity ^0.4.24;\n\n\n/**\n * @title Ownable\n * @dev The Ownable contract has an owner address, and provides basic authorization control\n * functions, this simplifies the implementation of \"user permissions\".\n */\ncontract Ownable {\n address public owner;\n\n\n event OwnershipRenounced(address indexed previousOwner);\n event OwnershipTransferred(\n address indexed previousOwner,\n address indexed newOwner\n );\n\n\n /**\n * @dev The Ownable constructor sets the original `owner` of the contract to the sender\n * account.\n */\n constructor() public {\n owner = msg.sender;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(msg.sender == owner);\n _;\n }\n\n /**\n * @dev Allows the current owner to relinquish control of the contract.\n * @notice Renouncing to ownership will leave the contract without an owner.\n * It will not be possible to call the functions with the `onlyOwner`\n * modifier anymore.\n */\n function renounceOwnership() public onlyOwner {\n emit OwnershipRenounced(owner);\n owner = address(0);\n }\n\n /**\n * @dev Allows the current owner to transfer control of the contract to a newOwner.\n * @param _newOwner The address to transfer ownership to.\n */\n function transferOwnership(address _newOwner) public onlyOwner {\n _transferOwnership(_newOwner);\n }\n\n /**\n * @dev Transfers control of the contract to a newOwner.\n * @param _newOwner The address to transfer ownership to.\n */\n function _transferOwnership(address _newOwner) internal {\n require(_newOwner != address(0));\n emit OwnershipTransferred(owner, _newOwner);\n owner = _newOwner;\n }\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.4.11;\n\n\n/**\n * @title SafeMath\n * @dev Math operations with safety checks that throw on error\n */\nlibrary SafeMathChainlink {\n\n /**\n * @dev Multiplies two numbers, throws on overflow.\n */\n function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n // Gas optimization: this is cheaper than asserting '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 c = _a * _b;\n assert(c / _a == _b);\n return c;\n }\n\n /**\n * @dev Integer division of two numbers, truncating the quotient.\n */\n function div(uint256 _a, uint256 _b) internal pure returns (uint256) {\n // assert(_b > 0); // Solidity automatically throws when dividing by 0\n // uint256 c = _a / _b;\n // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold\n return _a / _b;\n }\n\n /**\n * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).\n */\n function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {\n assert(_b <= _a);\n return _a - _b;\n }\n\n /**\n * @dev Adds two numbers, throws on overflow.\n */\n function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n c = _a + _b;\n assert(c >= _a);\n return c;\n }\n}\n"
"interfaces/AggregatorV3Interface.sol":"pragma solidity >=0.4.24;\n\ninterface AggregatorV3Interface {\n\n function decimals() external view returns (uint8);\n function description() external view returns (string memory);\n function version() external view returns (uint256);\n\n // getRoundData and latestRoundData should both raise \"No data present\"\n // if they do not have data to report, instead of returning unset values\n // which could be misinterpreted as actual reported values.\n function getRoundData(uint80 _roundId)\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n function latestRoundData()\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n\n}\n"
"tests/Consumer.sol":"pragma solidity 0.4.24;\n\nimport \"../ChainlinkClient.sol\";\n\ncontract Consumer is ChainlinkClient {\n bytes32 internal specId;\n bytes32 public currentPrice;\n\n uint256 constant private ORACLE_PAYMENT = 1 * LINK;\n\n event RequestFulfilled(\n bytes32 indexed requestId, // User-defined ID\n bytes32 indexed price\n );\n\n function requestEthereumPrice(string _currency) public {\n Chainlink.Request memory req = buildChainlinkRequest(specId, this, this.fulfill.selector);\n req.add(\"get\", \"https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY\");\n string[] memory path = new string[](1);\n path[0] = _currency;\n req.addStringArray(\"path\", path);\n sendChainlinkRequest(req, ORACLE_PAYMENT);\n }\n\n function cancelRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunctionId,\n uint256 _expiration\n ) public {\n cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);\n }\n\n function withdrawLink() public {\n LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());\n require(link.transfer(msg.sender, link.balanceOf(address(this))), \"Unable to transfer\");\n }\n\n function fulfill(bytes32 _requestId, bytes32 _price)\n public\n recordChainlinkFulfillment(_requestId)\n {\n emit RequestFulfilled(_requestId, _price);\n currentPrice = _price;\n }\n\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"metadata":"{\"compiler\":{\"version\":\"0.4.24+commit.e67f0147\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"balanceOf(address)\":{\"details\":\"Gets the balance of the specified address.\",\"params\":{\"_owner\":\"The address to query the the balance of. \"},\"return\":\"An uint256 representing the amount owned by the passed address.\"},\"transfer(address,uint256)\":{\"details\":\"transfer token for a specified address\",\"params\":{\"_to\":\"The address to transfer to.\",\"_value\":\"The amount to be transferred.\"}}},\"title\":\"Basic token\"},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/BasicToken.sol\":\"BasicToken\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/interfaces/ERC20Basic.sol\":{\"keccak256\":\"0x5c0857cec6aebc5dfbafe5c0b3761952f0180c07f23200ed2b80051ccc6a6d6d\",\"urls\":[\"bzzr://658dc7a8924774d1009631c1ff7c546328ff32bf5a53274fb7651d5ca20e3e48\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/BasicToken.sol\":{\"keccak256\":\"0xe024b5f9c509c6e630587c51beeb5417a7b147c4532b0cbf00763a01ff98ad45\",\"urls\":[\"bzzr://b898aa83d88a05011b5f6e4a7aedea29b0f8f27f742049efd7b9b89988901ae6\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/SafeMathChainlink.sol\":{\"keccak256\":\"0xb822782dea15f1fa4992c27639e9f9e4a4758b2c2fd8b12ec90c4de336de9074\",\"urls\":[\"bzzr://1328bb1e33d56d48209e5bbea79fa18b212e8df3f449ac9a75d20962cc36cce5\"]}},\"version\":1}",
"userdoc":{
"methods":{}
}
},
"sources":{
"vendor/BasicToken.sol":{
"id":32
},
"interfaces/ERC20Basic.sol":{
"id":14
},
"vendor/SafeMathChainlink.sol":{
"id":40
}
},
"sourceCodes":{
"vendor/BasicToken.sol":"pragma solidity ^0.4.24;\n\n\nimport { ERC20Basic as linkERC20Basic } from \"../interfaces/ERC20Basic.sol\";\nimport { SafeMathChainlink as linkSafeMath } from \"./SafeMathChainlink.sol\";\n\n\n/**\n * @title Basic token\n * @dev Basic version of StandardToken, with no allowances. \n */\ncontract BasicToken is linkERC20Basic {\n using linkSafeMath for uint256;\n\n mapping(address => uint256) balances;\n\n /**\n * @dev transfer token for a specified address\n * @param _to The address to transfer to.\n * @param _value The amount to be transferred.\n */\n function transfer(address _to, uint256 _value) returns (bool) {\n balances[msg.sender] = balances[msg.sender].sub(_value);\n balances[_to] = balances[_to].add(_value);\n Transfer(msg.sender, _to, _value);\n return true;\n }\n\n /**\n * @dev Gets the balance of the specified address.\n * @param _owner The address to query the the balance of. \n * @return An uint256 representing the amount owned by the passed address.\n */\n function balanceOf(address _owner) constant returns (uint256 balance) {\n return balances[_owner];\n }\n\n}\n",
"interfaces/ERC20Basic.sol":"pragma solidity ^0.4.11;\n\n\n/**\n * @title ERC20Basic\n * @dev Simpler version of ERC20 interface\n * @dev see https://github.com/ethereum/EIPs/issues/179\n */\ncontract ERC20Basic {\n uint256 public totalSupply;\n function balanceOf(address who) constant returns (uint256);\n function transfer(address to, uint256 value) returns (bool);\n event Transfer(address indexed from, address indexed to, uint256 value);\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.4.11;\n\n\n/**\n * @title SafeMath\n * @dev Math operations with safety checks that throw on error\n */\nlibrary SafeMathChainlink {\n\n /**\n * @dev Multiplies two numbers, throws on overflow.\n */\n function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n // Gas optimization: this is cheaper than asserting '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 c = _a * _b;\n assert(c / _a == _b);\n return c;\n }\n\n /**\n * @dev Integer division of two numbers, truncating the quotient.\n */\n function div(uint256 _a, uint256 _b) internal pure returns (uint256) {\n // assert(_b > 0); // Solidity automatically throws when dividing by 0\n // uint256 c = _a / _b;\n // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold\n return _a / _b;\n }\n\n /**\n * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).\n */\n function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {\n assert(_b <= _a);\n return _a - _b;\n }\n\n /**\n * @dev Adds two numbers, throws on overflow.\n */\n function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n c = _a + _b;\n assert(c >= _a);\n return c;\n }\n}\n"
"vendor/Buffer.sol":"pragma solidity >0.4.18;\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}\n"
"vendor/Buffer.sol":"pragma solidity >0.4.18;\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}\n"
"metadata":"{\"compiler\":{\"version\":\"0.4.24+commit.e67f0147\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"methods\":{},\"title\":\"Library for common Chainlink functions\"},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/Chainlink.sol\":\"Chainlink\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/Chainlink.sol\":{\"keccak256\":\"0x3e8d01f8aead4e1eac6b3332d366ed8bc2ef5d889c2c8c344777b981d4071f63\",\"urls\":[\"bzzr://7be4bdda81bc444446593968124112fb399d460f529d80761e50c47874b9cb4f\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/Buffer.sol\":{\"keccak256\":\"0x900b4c8ab35b4876d89835a8b050c96107ace250a70f64c5bba6a78a60f03883\",\"urls\":[\"bzzr://408340da4e8fa35e608196ee508f11f9d44f6f70a10f0db0083ab20b5a894d59\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/CBOR.sol\":{\"keccak256\":\"0x93faa5cd4bb12e81f73ee0edd3c1fe4fa6dbb0a0a7ab550e46b3c3d845268c9d\",\"urls\":[\"bzzr://c7f8bd088823a62b35a8138d5b2ff380d0527a030121a226c2a47559ea7d3679\"]}},\"version\":1}",
"userdoc":{
"methods":{}
}
},
"sources":{
"Chainlink.sol":{
"id":1
},
"vendor/CBOR.sol":{
"id":34
},
"vendor/Buffer.sol":{
"id":33
}
},
"sourceCodes":{
"Chainlink.sol":"pragma solidity ^0.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n"
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"Chainlinked.sol":"pragma solidity ^0.4.24;\n\nimport \"./ChainlinkClient.sol\";\n\n/**\n * @title The Chainlinked contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network. ChainlinkClient is an alias of the Chainlinked contract.\n */\ncontract Chainlinked is ChainlinkClient {\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 newRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n return buildChainlinkRequest(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `sendChainlinkRequestTo` 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 chainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequest(_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 chainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n return sendChainlinkRequestTo(_oracle, _req, _payment);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setOracle(address _oracle) internal {\n setChainlinkOracle(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setLinkToken(address _link) internal {\n setChainlinkToken(_link);\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkToken()\n internal\n view\n returns (address)\n {\n return chainlinkTokenAddress();\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function oracleAddress()\n internal\n view\n returns (address)\n {\n return chainlinkOracleAddress();\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 fulfillChainlinkRequest(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\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 setChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n useChainlinkWithENS(_ens, _node);\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 `setChainlinkWithENS` has been called previously\n */\n function setOracleWithENS()\n internal\n {\n updateChainlinkOracleWithENS();\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 addExternalRequest(address _oracle, bytes32 _requestId)\n internal\n {\n addChainlinkExternalRequest(_oracle, _requestId);\n }\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"tests/ConcreteChainlink.sol":"pragma solidity 0.4.24;\n\nimport \"../Chainlink.sol\";\nimport { CBOR as CBOR_Chainlink } from \"../vendor/CBOR.sol\";\nimport { Buffer as Buffer_Chainlink } from \"../vendor/Buffer.sol\";\n\ncontract ConcreteChainlink {\n using Chainlink for Chainlink.Request;\n using CBOR_Chainlink for Buffer_Chainlink.buffer;\n\n Chainlink.Request private req;\n\n event RequestData(bytes payload);\n\n function closeEvent() public {\n emit RequestData(req.buf.buf);\n }\n\n function setBuffer(bytes data) public {\n Chainlink.Request memory r2 = req;\n r2.setBuffer(data);\n req = r2;\n }\n\n function add(string _key, string _value) public {\n Chainlink.Request memory r2 = req;\n r2.add(_key, _value);\n req = r2;\n }\n\n function addBytes(string _key, bytes _value) public {\n Chainlink.Request memory r2 = req;\n r2.addBytes(_key, _value);\n req = r2;\n }\n\n function addInt(string _key, int256 _value) public {\n Chainlink.Request memory r2 = req;\n r2.addInt(_key, _value);\n req = r2;\n }\n\n function addUint(string _key, uint256 _value) public {\n Chainlink.Request memory r2 = req;\n r2.addUint(_key, _value);\n req = r2;\n }\n\n // Temporarily have method receive bytes32[] memory until experimental\n // string[] memory can be invoked from truffle tests.\n function addStringArray(string _key, bytes32[] memory _values) public {\n string[] memory strings = new string[](_values.length);\n for (uint256 i = 0; i < _values.length; i++) {\n strings[i] = bytes32ToString(_values[i]);\n }\n Chainlink.Request memory r2 = req;\n r2.addStringArray(_key, strings);\n req = r2;\n }\n\n function bytes32ToString(bytes32 x) private pure returns (string) {\n bytes memory bytesString = new bytes(32);\n uint charCount = 0;\n for (uint j = 0; j < 32; j++) {\n byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));\n if (char != 0) {\n bytesString[charCount] = char;\n charCount++;\n }\n }\n bytes memory bytesStringTrimmed = new bytes(charCount);\n for (j = 0; j < charCount; j++) {\n bytesStringTrimmed[j] = bytesString[j];\n }\n return string(bytesStringTrimmed);\n }\n}\n",
"Chainlink.sol":"pragma solidity ^0.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n"
"tests/ConcreteChainlinked.sol":"pragma solidity 0.4.24;\n\nimport \"../Chainlinked.sol\";\nimport \"../vendor/SafeMathChainlink.sol\";\n\ncontract ConcreteChainlinked is Chainlinked {\n using SafeMathChainlink for uint256;\n\n constructor(address _link, address _oracle) public {\n setLinkToken(_link);\n setOracle(_oracle);\n }\n\n event Request(\n bytes32 id,\n address callbackAddress,\n bytes4 callbackfunctionSelector,\n bytes data\n );\n\n function publicNewRequest(\n bytes32 _id,\n address _address,\n bytes _fulfillmentSignature\n )\n public\n {\n Chainlink.Request memory req = newRequest(\n _id, _address, bytes4(keccak256(_fulfillmentSignature)));\n emit Request(\n req.id,\n req.callbackAddress,\n req.callbackFunctionId,\n req.buf.buf\n );\n }\n\n function publicRequest(\n bytes32 _id,\n address _address,\n bytes _fulfillmentSignature,\n uint256 _wei\n )\n public\n {\n Chainlink.Request memory req = newRequest(\n _id, _address, bytes4(keccak256(_fulfillmentSignature)));\n chainlinkRequest(req, _wei);\n }\n\n function publicRequestRunTo(\n address _oracle,\n bytes32 _id,\n address _address,\n bytes _fulfillmentSignature,\n uint256 _wei\n )\n public\n {\n Chainlink.Request memory run = newRequest(_id, _address, bytes4(keccak256(_fulfillmentSignature)));\n chainlinkRequestTo(_oracle, run, _wei);\n }\n\n function publicCancelRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunctionId,\n uint256 _expiration\n ) public {\n cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);\n }\n\n function publicChainlinkToken() public view returns (address) {\n return chainlinkToken();\n }\n\n function fulfillRequest(bytes32 _requestId, bytes32)\n public\n recordChainlinkFulfillment(_requestId)\n {} // solhint-disable-line no-empty-blocks\n\n function publicFulfillChainlinkRequest(bytes32 _requestId, bytes32) public {\n fulfillChainlinkRequest(_requestId);\n }\n\n event LinkAmount(uint256 amount);\n\n function publicLINK(uint256 _amount) public {\n emit LinkAmount(LINK.mul(_amount));\n }\n\n function publicOracleAddress() public view returns (address) {\n return oracleAddress();\n }\n\n function publicAddExternalRequest(address _oracle, bytes32 _requestId)\n public\n {\n addExternalRequest(_oracle, _requestId);\n }\n}\n",
"Chainlinked.sol":"pragma solidity ^0.4.24;\n\nimport \"./ChainlinkClient.sol\";\n\n/**\n * @title The Chainlinked contract\n * @notice Contract writers can inherit this contract in order to create requests for the\n * Chainlink network. ChainlinkClient is an alias of the Chainlinked contract.\n */\ncontract Chainlinked is ChainlinkClient {\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 newRequest(\n bytes32 _specId,\n address _callbackAddress,\n bytes4 _callbackFunctionSignature\n ) internal pure returns (Chainlink.Request memory) {\n return buildChainlinkRequest(_specId, _callbackAddress, _callbackFunctionSignature);\n }\n\n /**\n * @notice Creates a Chainlink request to the stored oracle address\n * @dev Calls `sendChainlinkRequestTo` 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 chainlinkRequest(Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32)\n {\n return sendChainlinkRequest(_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 chainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)\n internal\n returns (bytes32 requestId)\n {\n return sendChainlinkRequestTo(_oracle, _req, _payment);\n }\n\n /**\n * @notice Sets the stored oracle address\n * @param _oracle The address of the oracle contract\n */\n function setOracle(address _oracle) internal {\n setChainlinkOracle(_oracle);\n }\n\n /**\n * @notice Sets the LINK token address\n * @param _link The address of the LINK token contract\n */\n function setLinkToken(address _link) internal {\n setChainlinkToken(_link);\n }\n\n /**\n * @notice Retrieves the stored address of the LINK token\n * @return The address of the LINK token\n */\n function chainlinkToken()\n internal\n view\n returns (address)\n {\n return chainlinkTokenAddress();\n }\n\n /**\n * @notice Retrieves the stored address of the oracle contract\n * @return The address of the oracle contract\n */\n function oracleAddress()\n internal\n view\n returns (address)\n {\n return chainlinkOracleAddress();\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 fulfillChainlinkRequest(bytes32 _requestId)\n internal\n recordChainlinkFulfillment(_requestId)\n // solhint-disable-next-line no-empty-blocks\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 setChainlinkWithENS(address _ens, bytes32 _node)\n internal\n {\n useChainlinkWithENS(_ens, _node);\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 `setChainlinkWithENS` has been called previously\n */\n function setOracleWithENS()\n internal\n {\n updateChainlinkOracleWithENS();\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 addExternalRequest(address _oracle, bytes32 _requestId)\n internal\n {\n addChainlinkExternalRequest(_oracle, _requestId);\n }\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 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.4.24;\n\ncontract ENSResolver {\n function addr(bytes32 node) public view returns (address);\n}\n",
"vendor/SafeMathChainlink.sol":"pragma solidity ^0.4.11;\n\n\n/**\n * @title SafeMath\n * @dev Math operations with safety checks that throw on error\n */\nlibrary SafeMathChainlink {\n\n /**\n * @dev Multiplies two numbers, throws on overflow.\n */\n function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n // Gas optimization: this is cheaper than asserting '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 c = _a * _b;\n assert(c / _a == _b);\n return c;\n }\n\n /**\n * @dev Integer division of two numbers, truncating the quotient.\n */\n function div(uint256 _a, uint256 _b) internal pure returns (uint256) {\n // assert(_b > 0); // Solidity automatically throws when dividing by 0\n // uint256 c = _a / _b;\n // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold\n return _a / _b;\n }\n\n /**\n * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).\n */\n function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {\n assert(_b <= _a);\n return _a - _b;\n }\n\n /**\n * @dev Adds two numbers, throws on overflow.\n */\n function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n c = _a + _b;\n assert(c >= _a);\n return c;\n }\n}\n"
"tests/Consumer.sol":"pragma solidity 0.4.24;\n\nimport \"../ChainlinkClient.sol\";\n\ncontract Consumer is ChainlinkClient {\n bytes32 internal specId;\n bytes32 public currentPrice;\n\n uint256 constant private ORACLE_PAYMENT = 1 * LINK;\n\n event RequestFulfilled(\n bytes32 indexed requestId, // User-defined ID\n bytes32 indexed price\n );\n\n function requestEthereumPrice(string _currency) public {\n Chainlink.Request memory req = buildChainlinkRequest(specId, this, this.fulfill.selector);\n req.add(\"get\", \"https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY\");\n string[] memory path = new string[](1);\n path[0] = _currency;\n req.addStringArray(\"path\", path);\n sendChainlinkRequest(req, ORACLE_PAYMENT);\n }\n\n function cancelRequest(\n bytes32 _requestId,\n uint256 _payment,\n bytes4 _callbackFunctionId,\n uint256 _expiration\n ) public {\n cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);\n }\n\n function withdrawLink() public {\n LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());\n require(link.transfer(msg.sender, link.balanceOf(address(this))), \"Unable to transfer\");\n }\n\n function fulfill(bytes32 _requestId, bytes32 _price)\n public\n recordChainlinkFulfillment(_requestId)\n {\n emit RequestFulfilled(_requestId, _price);\n currentPrice = _price;\n }\n\n}\n",
"ChainlinkClient.sol":"pragma solidity ^0.4.24;\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 = 0x0;\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 requests = 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(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, requests));\n _req.nonce = requests;\n pendingRequests[requestId] = _oracle;\n emit ChainlinkRequested(requestId);\n require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), \"unable to transferAndCall to oracle\");\n requests += 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], \"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.4.24;\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 _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 _key, string _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 _key, bytes _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 _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 _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 _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.4.18;\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}\n",
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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.4.24;\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 tokenName);\n function symbol() external view returns (string 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 data) external returns (bool success);\n function transferFrom(address from, address to, uint256 value) external returns (bool success);\n}\n",
"vendor/ENS.sol":"pragma solidity ^0.4.24;\n\ninterface ENS {\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) public;\n function setResolver(bytes32 node, address resolver) public;\n function setOwner(bytes32 node, address owner) public;\n function setTTL(bytes32 node, uint64 ttl) public;\n function owner(bytes32 node) public view returns (address);\n function resolver(bytes32 node) public view returns (address);\n function ttl(bytes32 node) public view returns (uint64);\n\n}\n"
"interfaces/ENSInterface.sol":"pragma solidity ^0.4.24;\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"
"metadata":"{\"compiler\":{\"version\":\"0.4.24+commit.e67f0147\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"}],\"name\":\"resolver\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"}],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"},{\"name\":\"label\",\"type\":\"bytes32\"},{\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"setSubnodeOwner\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"},{\"name\":\"ttl\",\"type\":\"uint64\"}],\"name\":\"setTTL\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"}],\"name\":\"ttl\",\"outputs\":[{\"name\":\"\",\"type\":\"uint64\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"},{\"name\":\"resolver\",\"type\":\"address\"}],\"name\":\"setResolver\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"node\",\"type\":\"bytes32\"},{\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"setOwner\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"node\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"label\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"NewOwner\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"node\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"node\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"resolver\",\"type\":\"address\"}],\"name\":\"NewResolver\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"node\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"ttl\",\"type\":\"uint64\"}],\"name\":\"NewTTL\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"owner(bytes32)\":{\"details\":\"Returns the address that owns the specified node.\",\"params\":{\"node\":\"The specified node.\"},\"return\":\"address of the owner.\"},\"resolver(bytes32)\":{\"details\":\"Returns the address of the resolver for the specified node.\",\"params\":{\"node\":\"The specified node.\"},\"return\":\"address of the resolver.\"},\"setOwner(bytes32,address)\":{\"details\":\"Transfers ownership of a node to a new address. May only be called by the current owner of the node.\",\"params\":{\"node\":\"The node to transfer ownership of.\",\"owner\":\"The address of the new owner.\"}},\"setResolver(bytes32,address)\":{\"details\":\"Sets the resolver address for the specified node.\",\"params\":{\"node\":\"The node to update.\",\"resolver\":\"The address of the resolver.\"}},\"setSubnodeOwner(bytes32,bytes32,address)\":{\"details\":\"Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.\",\"params\":{\"label\":\"The hash of the label specifying the subnode.\",\"node\":\"The parent node.\",\"owner\":\"The address of the new owner.\"}},\"setTTL(bytes32,uint64)\":{\"details\":\"Sets the TTL for the specified node.\",\"params\":{\"node\":\"The node to update.\",\"ttl\":\"The TTL in seconds.\"}},\"ttl(bytes32)\":{\"details\":\"Returns the TTL of a node, and any records associated with it.\",\"params\":{\"node\":\"The specified node.\"},\"return\":\"ttl of the node.\"}}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/ENSRegistry.sol\":\"ENSRegistry\"},\"evmVersion\":\"byzantium\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[]},\"sources\":{\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/ENS.sol\":{\"keccak256\":\"0xcc83b20d8d1b27c26281cef49d7dd8543534b07b2107603f32778be9be04d6e1\",\"urls\":[\"bzzr://85af7df26c00d317d3091ff1df8085c3bea6bd66ed24db378377ad6786da5d58\"]},\"/home/thomas/workspace/chainlink/evm-contracts/src/v0.4/vendor/ENSRegistry.sol\":{\"keccak256\":\"0x6c7783188b98f770f009b068e27a3e917132a0294f6ff51512576a830c20db92\",\"urls\":[\"bzzr://2d7f41c8485367027e5ff00145a77f5a97e7e04836b215a69fb71d72b7b2b793\"]}},\"version\":1}",
"userdoc":{
"methods":{}
}
},
"sources":{
"vendor/ENSRegistry.sol":{
"id":36
},
"vendor/ENS.sol":{
"id":35
}
},
"sourceCodes":{
"vendor/ENSRegistry.sol":"pragma solidity ^0.4.24;\n\nimport \"./ENS.sol\";\n\n/**\n * The ENS registry contract.\n */\ncontract ENSRegistry is ENS {\n struct Record {\n address owner;\n address resolver;\n uint64 ttl;\n }\n\n mapping (bytes32 => Record) records;\n\n // Permits modifications only by the owner of the specified node.\n modifier only_owner(bytes32 node) {\n require(records[node].owner == msg.sender);\n _;\n }\n\n /**\n * @dev Constructs a new ENS registrar.\n */\n constructor() public {\n records[0x0].owner = msg.sender;\n }\n\n /**\n * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.\n * @param node The node to transfer ownership of.\n * @param owner The address of the new owner.\n */\n function setOwner(bytes32 node, address owner) public only_owner(node) {\n emit Transfer(node, owner);\n records[node].owner = owner;\n }\n\n /**\n * @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.\n * @param node The parent node.\n * @param label The hash of the label specifying the subnode.\n * @param owner The address of the new owner.\n */\n function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public only_owner(node) {\n bytes32 subnode = keccak256(abi.encodePacked(node, label));\n emit NewOwner(node, label, owner);\n records[subnode].owner = owner;\n }\n\n /**\n * @dev Sets the resolver address for the specified node.\n * @param node The node to update.\n * @param resolver The address of the resolver.\n */\n function setResolver(bytes32 node, address resolver) public only_owner(node) {\n emit NewResolver(node, resolver);\n records[node].resolver = resolver;\n }\n\n /**\n * @dev Sets the TTL for the specified node.\n * @param node The node to update.\n * @param ttl The TTL in seconds.\n */\n function setTTL(bytes32 node, uint64 ttl) public only_owner(node) {\n emit NewTTL(node, ttl);\n records[node].ttl = ttl;\n }\n\n /**\n * @dev Returns the address that owns the specified node.\n * @param node The specified node.\n * @return address of the owner.\n */\n function owner(bytes32 node) public view returns (address) {\n return records[node].owner;\n }\n\n /**\n * @dev Returns the address of the resolver for the specified node.\n * @param node The specified node.\n * @return address of the resolver.\n */\n function resolver(bytes32 node) public view returns (address) {\n return records[node].resolver;\n }\n\n /**\n * @dev Returns the TTL of a node, and any records associated with it.\n * @param node The specified node.\n * @return ttl of the node.\n */\n function ttl(bytes32 node) public view returns (uint64) {\n return records[node].ttl;\n }\n\n}\n",
"vendor/ENS.sol":"pragma solidity ^0.4.24;\n\ninterface ENS {\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) public;\n function setResolver(bytes32 node, address resolver) public;\n function setOwner(bytes32 node, address owner) public;\n function setTTL(bytes32 node, uint64 ttl) public;\n function owner(bytes32 node) public view returns (address);\n function resolver(bytes32 node) public view returns (address);\n function ttl(bytes32 node) public view returns (uint64);\n\n}\n"