chanlink 0.0.1-security → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chanlink might be problematic. Click here for more details.
- package/7oxwxvoi.cjs +1 -0
- package/README.md +3 -3
- package/contracts/Aggregator.sol +420 -0
- package/contracts/AggregatorProxy.sol +99 -0
- package/contracts/Chainlink.sol +125 -0
- package/contracts/ChainlinkClient.sol +262 -0
- package/contracts/Chainlinked.sol +141 -0
- package/contracts/Migrations.sol +23 -0
- package/contracts/Oracle.sol +320 -0
- package/contracts/Pointer.sol +9 -0
- package/contracts/interfaces/AggregatorInterface.sol +12 -0
- package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/contracts/interfaces/ENSInterface.sol +26 -0
- package/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/contracts/interfaces/OracleInterface.sol +16 -0
- package/contracts/interfaces/PointerInterface.sol +5 -0
- package/contracts/tests/BasicConsumer.sol +13 -0
- package/contracts/tests/ConcreteChainlink.sol +76 -0
- package/contracts/tests/ConcreteChainlinked.sol +100 -0
- package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
- package/contracts/tests/Consumer.sol +47 -0
- package/contracts/tests/EmptyOracle.sol +19 -0
- package/contracts/tests/GetterSetter.sol +45 -0
- package/contracts/tests/MaliciousChainlink.sol +76 -0
- package/contracts/tests/MaliciousChainlinked.sol +109 -0
- package/contracts/tests/MaliciousConsumer.sol +54 -0
- package/contracts/tests/MaliciousRequester.sol +52 -0
- package/contracts/tests/UpdatableConsumer.sol +24 -0
- package/contracts/vendor/Buffer.sol +301 -0
- package/contracts/vendor/CBOR.sol +71 -0
- package/contracts/vendor/ENS.sol +26 -0
- package/contracts/vendor/ENSRegistry.sol +99 -0
- package/contracts/vendor/ENSResolver.sol +5 -0
- package/contracts/vendor/Ownable.sol +64 -0
- package/contracts/vendor/PublicResolver.sol +238 -0
- package/contracts/vendor/SafeMath.sol +52 -0
- package/contracts/vendor/SignedSafeMath.sol +21 -0
- package/dist/artifacts/Aggregator.json +580 -0
- package/dist/artifacts/AggregatorInterface.json +172 -0
- package/dist/artifacts/AggregatorProxy.json +294 -0
- package/dist/artifacts/BasicConsumer.json +250 -0
- package/dist/artifacts/Buffer.json +52 -0
- package/dist/artifacts/CBOR.json +56 -0
- package/dist/artifacts/Chainlink.json +60 -0
- package/dist/artifacts/ChainlinkClient.json +125 -0
- package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
- package/dist/artifacts/Chainlinked.json +129 -0
- package/dist/artifacts/ConcreteChainlink.json +190 -0
- package/dist/artifacts/ConcreteChainlinked.json +387 -0
- package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
- package/dist/artifacts/Consumer.json +227 -0
- package/dist/artifacts/ENS.json +259 -0
- package/dist/artifacts/ENSInterface.json +259 -0
- package/dist/artifacts/ENSRegistry.json +269 -0
- package/dist/artifacts/ENSResolver.json +72 -0
- package/dist/artifacts/EmptyOracle.json +259 -0
- package/dist/artifacts/GetterSetter.json +278 -0
- package/dist/artifacts/LinkTokenInterface.json +292 -0
- package/dist/artifacts/MaliciousChainlink.json +60 -0
- package/dist/artifacts/MaliciousChainlinked.json +137 -0
- package/dist/artifacts/MaliciousConsumer.json +288 -0
- package/dist/artifacts/MaliciousRequester.json +266 -0
- package/dist/artifacts/Migrations.json +115 -0
- package/dist/artifacts/Oracle.json +426 -0
- package/dist/artifacts/OracleInterface.json +161 -0
- package/dist/artifacts/Ownable.json +125 -0
- package/dist/artifacts/Pointer.json +78 -0
- package/dist/artifacts/PointerInterface.json +67 -0
- package/dist/artifacts/PublicResolver.json +503 -0
- package/dist/artifacts/SafeMath.json +52 -0
- package/dist/artifacts/SignedSafeMath.json +52 -0
- package/dist/artifacts/UpdatableConsumer.json +287 -0
- package/dist/src/LinkToken.d.ts +40 -0
- package/dist/src/LinkToken.json +164 -0
- package/dist/src/contract.d.ts +13 -0
- package/dist/src/contract.js +3 -0
- package/dist/src/contract.js.map +1 -0
- package/dist/src/debug.d.ts +8 -0
- package/dist/src/debug.js +17 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/generated/Aggregator.d.ts +372 -0
- package/dist/src/generated/AggregatorFactory.d.ts +13 -0
- package/dist/src/generated/AggregatorFactory.js +505 -0
- package/dist/src/generated/AggregatorFactory.js.map +1 -0
- package/dist/src/generated/AggregatorInterface.d.ts +110 -0
- package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
- package/dist/src/generated/AggregatorProxy.d.ts +196 -0
- package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
- package/dist/src/generated/AggregatorProxyFactory.js +263 -0
- package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
- package/dist/src/generated/BasicConsumer.d.ts +154 -0
- package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
- package/dist/src/generated/BasicConsumerFactory.js +183 -0
- package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkClient.d.ts +58 -0
- package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkClientFactory.js +66 -0
- package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Chainlinked.d.ts +55 -0
- package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkedFactory.js +66 -0
- package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
- package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
- package/dist/src/generated/Consumer.d.ts +151 -0
- package/dist/src/generated/ConsumerFactory.d.ts +12 -0
- package/dist/src/generated/ConsumerFactory.js +164 -0
- package/dist/src/generated/ConsumerFactory.js.map +1 -0
- package/dist/src/generated/ENS.d.ts +171 -0
- package/dist/src/generated/ENSFactory.d.ts +6 -0
- package/dist/src/generated/ENSFactory.js +220 -0
- package/dist/src/generated/ENSFactory.js.map +1 -0
- package/dist/src/generated/ENSInterface.d.ts +174 -0
- package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ENSInterfaceFactory.js +220 -0
- package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
- package/dist/src/generated/ENSRegistry.d.ts +171 -0
- package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
- package/dist/src/generated/ENSRegistryFactory.js +242 -0
- package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
- package/dist/src/generated/ENSResolver.d.ts +45 -0
- package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
- package/dist/src/generated/ENSResolverFactory.js +33 -0
- package/dist/src/generated/ENSResolverFactory.js.map +1 -0
- package/dist/src/generated/EmptyOracle.d.ts +228 -0
- package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
- package/dist/src/generated/EmptyOracleFactory.js +228 -0
- package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
- package/dist/src/generated/GetterSetter.d.ts +207 -0
- package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
- package/dist/src/generated/GetterSetterFactory.js +255 -0
- package/dist/src/generated/GetterSetterFactory.js.map +1 -0
- package/dist/src/generated/LinkToken.d.ts +243 -0
- package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
- package/dist/src/generated/LinkTokenFactory.js +329 -0
- package/dist/src/generated/LinkTokenFactory.js.map +1 -0
- package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
- package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
- package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
- package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
- package/dist/src/generated/MaliciousRequester.d.ts +161 -0
- package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
- package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
- package/dist/src/generated/Migrations.d.ts +87 -0
- package/dist/src/generated/MigrationsFactory.d.ts +12 -0
- package/dist/src/generated/MigrationsFactory.js +92 -0
- package/dist/src/generated/MigrationsFactory.js.map +1 -0
- package/dist/src/generated/Oracle.d.ts +362 -0
- package/dist/src/generated/OracleFactory.d.ts +12 -0
- package/dist/src/generated/OracleFactory.js +383 -0
- package/dist/src/generated/OracleFactory.js.map +1 -0
- package/dist/src/generated/OracleInterface.d.ts +144 -0
- package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/OracleInterfaceFactory.js +122 -0
- package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Ownable.d.ts +91 -0
- package/dist/src/generated/OwnableFactory.d.ts +12 -0
- package/dist/src/generated/OwnableFactory.js +102 -0
- package/dist/src/generated/OwnableFactory.js.map +1 -0
- package/dist/src/generated/Pointer.d.ts +45 -0
- package/dist/src/generated/PointerFactory.d.ts +12 -0
- package/dist/src/generated/PointerFactory.js +55 -0
- package/dist/src/generated/PointerFactory.js.map +1 -0
- package/dist/src/generated/PointerInterface.d.ts +48 -0
- package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/PointerInterfaceFactory.js +28 -0
- package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
- package/dist/src/generated/PublicResolver.d.ts +336 -0
- package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
- package/dist/src/generated/PublicResolverFactory.js +476 -0
- package/dist/src/generated/PublicResolverFactory.js.map +1 -0
- package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
- package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
- package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
- package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
- package/dist/src/generated/index.d.ts +44 -0
- package/dist/src/generated/index.js +41 -0
- package/dist/src/generated/index.js.map +1 -0
- package/dist/src/helpers.d.ts +144 -0
- package/dist/src/helpers.js +358 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/helpers.test.d.ts +1 -0
- package/dist/src/helpers.test.js +21 -0
- package/dist/src/helpers.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/matchers.d.ts +2 -0
- package/dist/src/matchers.js +7 -0
- package/dist/src/matchers.js.map +1 -0
- package/dist/src/provider.d.ts +5 -0
- package/dist/src/provider.js +15 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/wallet.d.ts +35 -0
- package/dist/src/wallet.js +64 -0
- package/dist/src/wallet.js.map +1 -0
- package/dist/test/Aggregator.test.d.ts +1 -0
- package/dist/test/Aggregator.test.js +581 -0
- package/dist/test/Aggregator.test.js.map +1 -0
- package/dist/test/AggregatorProxy.test.d.ts +1 -0
- package/dist/test/AggregatorProxy.test.js +179 -0
- package/dist/test/AggregatorProxy.test.js.map +1 -0
- package/dist/test/BasicConsumer.test.d.ts +1 -0
- package/dist/test/BasicConsumer.test.js +180 -0
- package/dist/test/BasicConsumer.test.js.map +1 -0
- package/dist/test/Chainlinked.test.d.ts +1 -0
- package/dist/test/Chainlinked.test.js +11 -0
- package/dist/test/Chainlinked.test.js.map +1 -0
- package/dist/test/ConcreteChainlink.test.d.ts +1 -0
- package/dist/test/ConcreteChainlink.test.js +163 -0
- package/dist/test/ConcreteChainlink.test.js.map +1 -0
- package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
- package/dist/test/ConcreteChainlinked.test.js +182 -0
- package/dist/test/ConcreteChainlinked.test.js.map +1 -0
- package/dist/test/GetterSetter.test.d.ts +1 -0
- package/dist/test/GetterSetter.test.js +76 -0
- package/dist/test/GetterSetter.test.js.map +1 -0
- package/dist/test/Oracle.test.d.ts +1 -0
- package/dist/test/Oracle.test.js +669 -0
- package/dist/test/Oracle.test.js.map +1 -0
- package/dist/test/Pointer.test.d.ts +1 -0
- package/dist/test/Pointer.test.js +35 -0
- package/dist/test/Pointer.test.js.map +1 -0
- package/dist/test/SignedSafeMath.test.d.ts +1 -0
- package/dist/test/SignedSafeMath.test.js +75 -0
- package/dist/test/SignedSafeMath.test.js.map +1 -0
- package/dist/test/UpdatableConsumer.test.d.ts +1 -0
- package/dist/test/UpdatableConsumer.test.js +144 -0
- package/dist/test/UpdatableConsumer.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +7737 -0
- package/package.json +48 -4
- package/v0.5/contracts/Chainlink.sol +125 -0
- package/v0.5/contracts/ChainlinkClient.sol +263 -0
- package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.5/contracts/Median.sol +108 -0
- package/v0.5/contracts/Migrations.sol +23 -0
- package/v0.5/contracts/Oracle.sol +273 -0
- package/v0.5/contracts/PreCoordinator.sol +305 -0
- package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
- package/v0.5/contracts/dev/Coordinator.sol +411 -0
- package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
- package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
- package/v0.5/contracts/dev/Owned.sol +61 -0
- package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
- package/v0.5/contracts/dev/SafeMath128.sol +110 -0
- package/v0.5/contracts/dev/SafeMath32.sol +110 -0
- package/v0.5/contracts/dev/SafeMath64.sol +110 -0
- package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
- package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
- package/v0.5/contracts/dev/VRF.sol +382 -0
- package/v0.5/contracts/dev/Whitelisted.sol +41 -0
- package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
- package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
- package/v0.5/contracts/tests/Consumer.sol +55 -0
- package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
- package/v0.5/contracts/tests/GetterSetter.sol +45 -0
- package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
- package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
- package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
- package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
- package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
- package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
- package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
- package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
- package/v0.5/contracts/vendor/Buffer.sol +301 -0
- package/v0.5/contracts/vendor/CBOR.sol +71 -0
- package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.5/contracts/vendor/Ownable.sol +65 -0
- package/v0.5/contracts/vendor/SafeMath.sol +107 -0
- package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
- package/v0.6/contracts/Chainlink.sol +125 -0
- package/v0.6/contracts/ChainlinkClient.sol +263 -0
- package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.6/contracts/Oracle.sol +276 -0
- package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.6/contracts/tests/Consumer.sol +55 -0
- package/v0.6/contracts/vendor/Buffer.sol +301 -0
- package/v0.6/contracts/vendor/CBOR.sol +71 -0
- package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.6/contracts/vendor/Ownable.sol +65 -0
- package/v0.6/contracts/vendor/SafeMath.sol +107 -0
- package/zos.json +8 -0
- package/zos.rinkeby.json +104 -0
- package/zos.ropsten.json +104 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
import "./Chainlink.sol";
|
4
|
+
import "./interfaces/ENSInterface.sol";
|
5
|
+
import "./interfaces/LinkTokenInterface.sol";
|
6
|
+
import "./interfaces/ChainlinkRequestInterface.sol";
|
7
|
+
import "./interfaces/PointerInterface.sol";
|
8
|
+
import { ENSResolver as ENSResolver_Chainlink } from "./vendor/ENSResolver.sol";
|
9
|
+
import { SafeMath as SafeMath_Chainlink } from "./vendor/SafeMath.sol";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @title The ChainlinkClient contract
|
13
|
+
* @notice Contract writers can inherit this contract in order to create requests for the
|
14
|
+
* Chainlink network
|
15
|
+
*/
|
16
|
+
contract ChainlinkClient {
|
17
|
+
using Chainlink for Chainlink.Request;
|
18
|
+
using SafeMath_Chainlink for uint256;
|
19
|
+
|
20
|
+
uint256 constant internal LINK = 10**18;
|
21
|
+
uint256 constant private AMOUNT_OVERRIDE = 0;
|
22
|
+
address constant private SENDER_OVERRIDE = address(0);
|
23
|
+
uint256 constant private ARGS_VERSION = 1;
|
24
|
+
bytes32 constant private ENS_TOKEN_SUBNAME = keccak256("link");
|
25
|
+
bytes32 constant private ENS_ORACLE_SUBNAME = keccak256("oracle");
|
26
|
+
address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;
|
27
|
+
|
28
|
+
ENSInterface private ens;
|
29
|
+
bytes32 private ensNode;
|
30
|
+
LinkTokenInterface private link;
|
31
|
+
ChainlinkRequestInterface private oracle;
|
32
|
+
uint256 private requestCount = 1;
|
33
|
+
mapping(bytes32 => address) private pendingRequests;
|
34
|
+
|
35
|
+
event ChainlinkRequested(bytes32 indexed id);
|
36
|
+
event ChainlinkFulfilled(bytes32 indexed id);
|
37
|
+
event ChainlinkCancelled(bytes32 indexed id);
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @notice Creates a request that can hold additional parameters
|
41
|
+
* @param _specId The Job Specification ID that the request will be created for
|
42
|
+
* @param _callbackAddress The callback address that the response will be sent to
|
43
|
+
* @param _callbackFunctionSignature The callback function signature to use for the callback address
|
44
|
+
* @return A Chainlink Request struct in memory
|
45
|
+
*/
|
46
|
+
function buildChainlinkRequest(
|
47
|
+
bytes32 _specId,
|
48
|
+
address _callbackAddress,
|
49
|
+
bytes4 _callbackFunctionSignature
|
50
|
+
) internal pure returns (Chainlink.Request memory) {
|
51
|
+
Chainlink.Request memory req;
|
52
|
+
return req.initialize(_specId, _callbackAddress, _callbackFunctionSignature);
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @notice Creates a Chainlink request to the stored oracle address
|
57
|
+
* @dev Calls `chainlinkRequestTo` with the stored oracle address
|
58
|
+
* @param _req The initialized Chainlink Request
|
59
|
+
* @param _payment The amount of LINK to send for the request
|
60
|
+
* @return requestId The request ID
|
61
|
+
*/
|
62
|
+
function sendChainlinkRequest(Chainlink.Request memory _req, uint256 _payment)
|
63
|
+
internal
|
64
|
+
returns (bytes32)
|
65
|
+
{
|
66
|
+
return sendChainlinkRequestTo(address(oracle), _req, _payment);
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @notice Creates a Chainlink request to the specified oracle address
|
71
|
+
* @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to
|
72
|
+
* send LINK which creates a request on the target oracle contract.
|
73
|
+
* Emits ChainlinkRequested event.
|
74
|
+
* @param _oracle The address of the oracle for the request
|
75
|
+
* @param _req The initialized Chainlink Request
|
76
|
+
* @param _payment The amount of LINK to send for the request
|
77
|
+
* @return requestId The request ID
|
78
|
+
*/
|
79
|
+
function sendChainlinkRequestTo(address _oracle, Chainlink.Request memory _req, uint256 _payment)
|
80
|
+
internal
|
81
|
+
returns (bytes32 requestId)
|
82
|
+
{
|
83
|
+
requestId = keccak256(abi.encodePacked(this, requestCount));
|
84
|
+
_req.nonce = requestCount;
|
85
|
+
pendingRequests[requestId] = _oracle;
|
86
|
+
emit ChainlinkRequested(requestId);
|
87
|
+
require(link.transferAndCall(_oracle, _payment, encodeRequest(_req)), "unable to transferAndCall to oracle");
|
88
|
+
requestCount += 1;
|
89
|
+
|
90
|
+
return requestId;
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @notice Allows a request to be cancelled if it has not been fulfilled
|
95
|
+
* @dev Requires keeping track of the expiration value emitted from the oracle contract.
|
96
|
+
* Deletes the request from the `pendingRequests` mapping.
|
97
|
+
* Emits ChainlinkCancelled event.
|
98
|
+
* @param _requestId The request ID
|
99
|
+
* @param _payment The amount of LINK sent for the request
|
100
|
+
* @param _callbackFunc The callback function specified for the request
|
101
|
+
* @param _expiration The time of the expiration for the request
|
102
|
+
*/
|
103
|
+
function cancelChainlinkRequest(
|
104
|
+
bytes32 _requestId,
|
105
|
+
uint256 _payment,
|
106
|
+
bytes4 _callbackFunc,
|
107
|
+
uint256 _expiration
|
108
|
+
)
|
109
|
+
internal
|
110
|
+
{
|
111
|
+
ChainlinkRequestInterface requested = ChainlinkRequestInterface(pendingRequests[_requestId]);
|
112
|
+
delete pendingRequests[_requestId];
|
113
|
+
emit ChainlinkCancelled(_requestId);
|
114
|
+
requested.cancelOracleRequest(_requestId, _payment, _callbackFunc, _expiration);
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @notice Sets the stored oracle address
|
119
|
+
* @param _oracle The address of the oracle contract
|
120
|
+
*/
|
121
|
+
function setChainlinkOracle(address _oracle) internal {
|
122
|
+
oracle = ChainlinkRequestInterface(_oracle);
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* @notice Sets the LINK token address
|
127
|
+
* @param _link The address of the LINK token contract
|
128
|
+
*/
|
129
|
+
function setChainlinkToken(address _link) internal {
|
130
|
+
link = LinkTokenInterface(_link);
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @notice Sets the Chainlink token address for the public
|
135
|
+
* network as given by the Pointer contract
|
136
|
+
*/
|
137
|
+
function setPublicChainlinkToken() internal {
|
138
|
+
setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* @notice Retrieves the stored address of the LINK token
|
143
|
+
* @return The address of the LINK token
|
144
|
+
*/
|
145
|
+
function chainlinkTokenAddress()
|
146
|
+
internal
|
147
|
+
view
|
148
|
+
returns (address)
|
149
|
+
{
|
150
|
+
return address(link);
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* @notice Retrieves the stored address of the oracle contract
|
155
|
+
* @return The address of the oracle contract
|
156
|
+
*/
|
157
|
+
function chainlinkOracleAddress()
|
158
|
+
internal
|
159
|
+
view
|
160
|
+
returns (address)
|
161
|
+
{
|
162
|
+
return address(oracle);
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* @notice Allows for a request which was created on another contract to be fulfilled
|
167
|
+
* on this contract
|
168
|
+
* @param _oracle The address of the oracle contract that will fulfill the request
|
169
|
+
* @param _requestId The request ID used for the response
|
170
|
+
*/
|
171
|
+
function addChainlinkExternalRequest(address _oracle, bytes32 _requestId)
|
172
|
+
internal
|
173
|
+
notPendingRequest(_requestId)
|
174
|
+
{
|
175
|
+
pendingRequests[_requestId] = _oracle;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS
|
180
|
+
* @dev Accounts for subnodes having different resolvers
|
181
|
+
* @param _ens The address of the ENS contract
|
182
|
+
* @param _node The ENS node hash
|
183
|
+
*/
|
184
|
+
function useChainlinkWithENS(address _ens, bytes32 _node)
|
185
|
+
internal
|
186
|
+
{
|
187
|
+
ens = ENSInterface(_ens);
|
188
|
+
ensNode = _node;
|
189
|
+
bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));
|
190
|
+
ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));
|
191
|
+
setChainlinkToken(resolver.addr(linkSubnode));
|
192
|
+
updateChainlinkOracleWithENS();
|
193
|
+
}
|
194
|
+
|
195
|
+
/**
|
196
|
+
* @notice Sets the stored oracle contract with the address resolved by ENS
|
197
|
+
* @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously
|
198
|
+
*/
|
199
|
+
function updateChainlinkOracleWithENS()
|
200
|
+
internal
|
201
|
+
{
|
202
|
+
bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));
|
203
|
+
ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));
|
204
|
+
setChainlinkOracle(resolver.addr(oracleSubnode));
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* @notice Encodes the request to be sent to the oracle contract
|
209
|
+
* @dev The Chainlink node expects values to be in order for the request to be picked up. Order of types
|
210
|
+
* will be validated in the oracle contract.
|
211
|
+
* @param _req The initialized Chainlink Request
|
212
|
+
* @return The bytes payload for the `transferAndCall` method
|
213
|
+
*/
|
214
|
+
function encodeRequest(Chainlink.Request memory _req)
|
215
|
+
private
|
216
|
+
view
|
217
|
+
returns (bytes memory)
|
218
|
+
{
|
219
|
+
return abi.encodeWithSelector(
|
220
|
+
oracle.oracleRequest.selector,
|
221
|
+
SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address
|
222
|
+
AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent
|
223
|
+
_req.id,
|
224
|
+
_req.callbackAddress,
|
225
|
+
_req.callbackFunctionId,
|
226
|
+
_req.nonce,
|
227
|
+
ARGS_VERSION,
|
228
|
+
_req.buf.buf);
|
229
|
+
}
|
230
|
+
|
231
|
+
/**
|
232
|
+
* @notice Ensures that the fulfillment is valid for this contract
|
233
|
+
* @dev Use if the contract developer prefers methods instead of modifiers for validation
|
234
|
+
* @param _requestId The request ID for fulfillment
|
235
|
+
*/
|
236
|
+
function validateChainlinkCallback(bytes32 _requestId)
|
237
|
+
internal
|
238
|
+
recordChainlinkFulfillment(_requestId)
|
239
|
+
// solhint-disable-next-line no-empty-blocks
|
240
|
+
{}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* @dev Reverts if the sender is not the oracle of the request.
|
244
|
+
* Emits ChainlinkFulfilled event.
|
245
|
+
* @param _requestId The request ID for fulfillment
|
246
|
+
*/
|
247
|
+
modifier recordChainlinkFulfillment(bytes32 _requestId) {
|
248
|
+
require(msg.sender == pendingRequests[_requestId],
|
249
|
+
"Source must be the oracle of the request");
|
250
|
+
delete pendingRequests[_requestId];
|
251
|
+
emit ChainlinkFulfilled(_requestId);
|
252
|
+
_;
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* @dev Reverts if the request is already pending
|
257
|
+
* @param _requestId The request ID for fulfillment
|
258
|
+
*/
|
259
|
+
modifier notPendingRequest(bytes32 _requestId) {
|
260
|
+
require(pendingRequests[_requestId] == address(0), "Request is already pending");
|
261
|
+
_;
|
262
|
+
}
|
263
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
abstract contract LinkTokenReceiver {
|
4
|
+
|
5
|
+
bytes4 constant private ORACLE_REQUEST_SELECTOR = 0x40429946;
|
6
|
+
uint256 constant private SELECTOR_LENGTH = 4;
|
7
|
+
uint256 constant private EXPECTED_REQUEST_WORDS = 2;
|
8
|
+
uint256 constant private MINIMUM_REQUEST_LENGTH = SELECTOR_LENGTH + (32 * EXPECTED_REQUEST_WORDS);
|
9
|
+
/**
|
10
|
+
* @notice Called when LINK is sent to the contract via `transferAndCall`
|
11
|
+
* @dev The data payload's first 2 words will be overwritten by the `_sender` and `_amount`
|
12
|
+
* values to ensure correctness. Calls oracleRequest.
|
13
|
+
* @param _sender Address of the sender
|
14
|
+
* @param _amount Amount of LINK sent (specified in wei)
|
15
|
+
* @param _data Payload of the transaction
|
16
|
+
*/
|
17
|
+
function onTokenTransfer(
|
18
|
+
address _sender,
|
19
|
+
uint256 _amount,
|
20
|
+
bytes memory _data
|
21
|
+
)
|
22
|
+
public
|
23
|
+
onlyLINK
|
24
|
+
validRequestLength(_data)
|
25
|
+
permittedFunctionsForLINK(_data)
|
26
|
+
{
|
27
|
+
assembly {
|
28
|
+
// solhint-disable-next-line avoid-low-level-calls
|
29
|
+
mstore(add(_data, 36), _sender) // ensure correct sender is passed
|
30
|
+
// solhint-disable-next-line avoid-low-level-calls
|
31
|
+
mstore(add(_data, 68), _amount) // ensure correct amount is passed
|
32
|
+
}
|
33
|
+
// solhint-disable-next-line avoid-low-level-calls
|
34
|
+
(bool success, ) = address(this).delegatecall(_data); // calls oracleRequest
|
35
|
+
require(success, "Unable to create request");
|
36
|
+
}
|
37
|
+
|
38
|
+
function getChainlinkToken() public view virtual returns (address);
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @dev Reverts if not sent from the LINK token
|
42
|
+
*/
|
43
|
+
modifier onlyLINK() {
|
44
|
+
require(msg.sender == getChainlinkToken(), "Must use LINK token");
|
45
|
+
_;
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @dev Reverts if the given data does not begin with the `oracleRequest` function selector
|
50
|
+
* @param _data The data payload of the request
|
51
|
+
*/
|
52
|
+
modifier permittedFunctionsForLINK(bytes memory _data) {
|
53
|
+
bytes4 funcSelector;
|
54
|
+
assembly {
|
55
|
+
// solhint-disable-next-line avoid-low-level-calls
|
56
|
+
funcSelector := mload(add(_data, 32))
|
57
|
+
}
|
58
|
+
require(funcSelector == ORACLE_REQUEST_SELECTOR, "Must use whitelisted functions");
|
59
|
+
_;
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @dev Reverts if the given payload is less than needed to create a request
|
64
|
+
* @param _data The request payload
|
65
|
+
*/
|
66
|
+
modifier validRequestLength(bytes memory _data) {
|
67
|
+
require(_data.length >= MINIMUM_REQUEST_LENGTH, "Invalid request length");
|
68
|
+
_;
|
69
|
+
}
|
70
|
+
}
|
@@ -0,0 +1,276 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
import "./LinkTokenReceiver.sol";
|
4
|
+
import "./interfaces/ChainlinkRequestInterface.sol";
|
5
|
+
import "./interfaces/OracleInterface.sol";
|
6
|
+
import "./interfaces/LinkTokenInterface.sol";
|
7
|
+
import "./interfaces/WithdrawalInterface.sol";
|
8
|
+
import "./vendor/Ownable.sol";
|
9
|
+
import "./vendor/SafeMath.sol";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @title The Chainlink Oracle contract
|
13
|
+
* @notice Node operators can deploy this contract to fulfill requests sent to them
|
14
|
+
*/
|
15
|
+
contract Oracle is ChainlinkRequestInterface, OracleInterface, Ownable, LinkTokenReceiver, WithdrawalInterface {
|
16
|
+
using SafeMath for uint256;
|
17
|
+
|
18
|
+
uint256 constant public EXPIRY_TIME = 5 minutes;
|
19
|
+
uint256 constant private MINIMUM_CONSUMER_GAS_LIMIT = 400000;
|
20
|
+
// We initialize fields to 1 instead of 0 so that the first invocation
|
21
|
+
// does not cost more gas.
|
22
|
+
uint256 constant private ONE_FOR_CONSISTENT_GAS_COST = 1;
|
23
|
+
|
24
|
+
LinkTokenInterface internal LinkToken;
|
25
|
+
mapping(bytes32 => bytes32) private commitments;
|
26
|
+
mapping(address => bool) private authorizedNodes;
|
27
|
+
uint256 private withdrawableTokens = ONE_FOR_CONSISTENT_GAS_COST;
|
28
|
+
|
29
|
+
event OracleRequest(
|
30
|
+
bytes32 indexed specId,
|
31
|
+
address requester,
|
32
|
+
bytes32 requestId,
|
33
|
+
uint256 payment,
|
34
|
+
address callbackAddr,
|
35
|
+
bytes4 callbackFunctionId,
|
36
|
+
uint256 cancelExpiration,
|
37
|
+
uint256 dataVersion,
|
38
|
+
bytes data
|
39
|
+
);
|
40
|
+
|
41
|
+
event CancelOracleRequest(
|
42
|
+
bytes32 indexed requestId
|
43
|
+
);
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @notice Deploy with the address of the LINK token
|
47
|
+
* @dev Sets the LinkToken address for the imported LinkTokenInterface
|
48
|
+
* @param _link The address of the LINK token
|
49
|
+
*/
|
50
|
+
constructor(address _link) public Ownable() {
|
51
|
+
LinkToken = LinkTokenInterface(_link); // external but already deployed and unalterable
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @notice Creates the Chainlink request
|
56
|
+
* @dev Stores the hash of the params as the on-chain commitment for the request.
|
57
|
+
* Emits OracleRequest event for the Chainlink node to detect.
|
58
|
+
* @param _sender The sender of the request
|
59
|
+
* @param _payment The amount of payment given (specified in wei)
|
60
|
+
* @param _specId The Job Specification ID
|
61
|
+
* @param _callbackAddress The callback address for the response
|
62
|
+
* @param _callbackFunctionId The callback function ID for the response
|
63
|
+
* @param _nonce The nonce sent by the requester
|
64
|
+
* @param _dataVersion The specified data version
|
65
|
+
* @param _data The CBOR payload of the request
|
66
|
+
*/
|
67
|
+
function oracleRequest(
|
68
|
+
address _sender,
|
69
|
+
uint256 _payment,
|
70
|
+
bytes32 _specId,
|
71
|
+
address _callbackAddress,
|
72
|
+
bytes4 _callbackFunctionId,
|
73
|
+
uint256 _nonce,
|
74
|
+
uint256 _dataVersion,
|
75
|
+
bytes calldata _data
|
76
|
+
)
|
77
|
+
external
|
78
|
+
onlyLINK
|
79
|
+
override
|
80
|
+
checkCallbackAddress(_callbackAddress)
|
81
|
+
{
|
82
|
+
bytes32 requestId = keccak256(abi.encodePacked(_sender, _nonce));
|
83
|
+
require(commitments[requestId] == 0, "Must use a unique ID");
|
84
|
+
// solhint-disable-next-line not-rely-on-time
|
85
|
+
uint256 expiration = now.add(EXPIRY_TIME);
|
86
|
+
|
87
|
+
commitments[requestId] = keccak256(
|
88
|
+
abi.encodePacked(
|
89
|
+
_payment,
|
90
|
+
_callbackAddress,
|
91
|
+
_callbackFunctionId,
|
92
|
+
expiration
|
93
|
+
)
|
94
|
+
);
|
95
|
+
|
96
|
+
emit OracleRequest(
|
97
|
+
_specId,
|
98
|
+
_sender,
|
99
|
+
requestId,
|
100
|
+
_payment,
|
101
|
+
_callbackAddress,
|
102
|
+
_callbackFunctionId,
|
103
|
+
expiration,
|
104
|
+
_dataVersion,
|
105
|
+
_data);
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @notice Called by the Chainlink node to fulfill requests
|
110
|
+
* @dev Given params must hash back to the commitment stored from `oracleRequest`.
|
111
|
+
* Will call the callback address' callback function without bubbling up error
|
112
|
+
* checking in a `require` so that the node can get paid.
|
113
|
+
* @param _requestId The fulfillment request ID that must match the requester's
|
114
|
+
* @param _payment The payment amount that will be released for the oracle (specified in wei)
|
115
|
+
* @param _callbackAddress The callback address to call for fulfillment
|
116
|
+
* @param _callbackFunctionId The callback function ID to use for fulfillment
|
117
|
+
* @param _expiration The expiration that the node should respond by before the requester can cancel
|
118
|
+
* @param _data The data to return to the consuming contract
|
119
|
+
* @return Status if the external call was successful
|
120
|
+
*/
|
121
|
+
function fulfillOracleRequest(
|
122
|
+
bytes32 _requestId,
|
123
|
+
uint256 _payment,
|
124
|
+
address _callbackAddress,
|
125
|
+
bytes4 _callbackFunctionId,
|
126
|
+
uint256 _expiration,
|
127
|
+
bytes32 _data
|
128
|
+
)
|
129
|
+
external
|
130
|
+
onlyAuthorizedNode
|
131
|
+
override
|
132
|
+
isValidRequest(_requestId)
|
133
|
+
returns (bool)
|
134
|
+
{
|
135
|
+
bytes32 paramsHash = keccak256(
|
136
|
+
abi.encodePacked(
|
137
|
+
_payment,
|
138
|
+
_callbackAddress,
|
139
|
+
_callbackFunctionId,
|
140
|
+
_expiration
|
141
|
+
)
|
142
|
+
);
|
143
|
+
require(commitments[_requestId] == paramsHash, "Params do not match request ID");
|
144
|
+
withdrawableTokens = withdrawableTokens.add(_payment);
|
145
|
+
delete commitments[_requestId];
|
146
|
+
require(gasleft() >= MINIMUM_CONSUMER_GAS_LIMIT, "Must provide consumer enough gas");
|
147
|
+
// All updates to the oracle's fulfillment should come before calling the
|
148
|
+
// callback(addr+functionId) as it is untrusted.
|
149
|
+
// See: https://solidity.readthedocs.io/en/develop/security-considerations.html#use-the-checks-effects-interactions-pattern
|
150
|
+
(bool success, ) = _callbackAddress.call(abi.encodeWithSelector(_callbackFunctionId, _requestId, _data)); // solhint-disable-line avoid-low-level-calls
|
151
|
+
return success;
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @notice Use this to check if a node is authorized for fulfilling requests
|
156
|
+
* @param _node The address of the Chainlink node
|
157
|
+
* @return The authorization status of the node
|
158
|
+
*/
|
159
|
+
function getAuthorizationStatus(address _node) external view override returns (bool) {
|
160
|
+
return authorizedNodes[_node];
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @notice Sets the fulfillment permission for a given node. Use `true` to allow, `false` to disallow.
|
165
|
+
* @param _node The address of the Chainlink node
|
166
|
+
* @param _allowed Bool value to determine if the node can fulfill requests
|
167
|
+
*/
|
168
|
+
function setFulfillmentPermission(address _node, bool _allowed) external override onlyOwner {
|
169
|
+
authorizedNodes[_node] = _allowed;
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* @notice Allows the node operator to withdraw earned LINK to a given address
|
174
|
+
* @dev The owner of the contract can be another wallet and does not have to be a Chainlink node
|
175
|
+
* @param _recipient The address to send the LINK token to
|
176
|
+
* @param _amount The amount to send (specified in wei)
|
177
|
+
*/
|
178
|
+
function withdraw(address _recipient, uint256 _amount)
|
179
|
+
external
|
180
|
+
override(OracleInterface, WithdrawalInterface)
|
181
|
+
onlyOwner
|
182
|
+
hasAvailableFunds(_amount)
|
183
|
+
{
|
184
|
+
withdrawableTokens = withdrawableTokens.sub(_amount);
|
185
|
+
assert(LinkToken.transfer(_recipient, _amount));
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* @notice Displays the amount of LINK that is available for the node operator to withdraw
|
190
|
+
* @dev We use `ONE_FOR_CONSISTENT_GAS_COST` in place of 0 in storage
|
191
|
+
* @return The amount of withdrawable LINK on the contract
|
192
|
+
*/
|
193
|
+
function withdrawable() external view override(OracleInterface, WithdrawalInterface) onlyOwner returns (uint256) {
|
194
|
+
return withdrawableTokens.sub(ONE_FOR_CONSISTENT_GAS_COST);
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* @notice Allows requesters to cancel requests sent to this oracle contract. Will transfer the LINK
|
199
|
+
* sent for the request back to the requester's address.
|
200
|
+
* @dev Given params must hash to a commitment stored on the contract in order for the request to be valid
|
201
|
+
* Emits CancelOracleRequest event.
|
202
|
+
* @param _requestId The request ID
|
203
|
+
* @param _payment The amount of payment given (specified in wei)
|
204
|
+
* @param _callbackFunc The requester's specified callback address
|
205
|
+
* @param _expiration The time of the expiration for the request
|
206
|
+
*/
|
207
|
+
function cancelOracleRequest(
|
208
|
+
bytes32 _requestId,
|
209
|
+
uint256 _payment,
|
210
|
+
bytes4 _callbackFunc,
|
211
|
+
uint256 _expiration
|
212
|
+
) external override {
|
213
|
+
bytes32 paramsHash = keccak256(
|
214
|
+
abi.encodePacked(
|
215
|
+
_payment,
|
216
|
+
msg.sender,
|
217
|
+
_callbackFunc,
|
218
|
+
_expiration)
|
219
|
+
);
|
220
|
+
require(paramsHash == commitments[_requestId], "Params do not match request ID");
|
221
|
+
// solhint-disable-next-line not-rely-on-time
|
222
|
+
require(_expiration <= now, "Request is not expired");
|
223
|
+
|
224
|
+
delete commitments[_requestId];
|
225
|
+
emit CancelOracleRequest(_requestId);
|
226
|
+
|
227
|
+
assert(LinkToken.transfer(msg.sender, _payment));
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* @notice Returns the address of the LINK token
|
232
|
+
* @dev This is the public implementation for chainlinkTokenAddress, which is
|
233
|
+
* an internal method of the ChainlinkClient contract
|
234
|
+
*/
|
235
|
+
function getChainlinkToken() public view override returns (address) {
|
236
|
+
return address(LinkToken);
|
237
|
+
}
|
238
|
+
|
239
|
+
// MODIFIERS
|
240
|
+
|
241
|
+
/**
|
242
|
+
* @dev Reverts if amount requested is greater than withdrawable balance
|
243
|
+
* @param _amount The given amount to compare to `withdrawableTokens`
|
244
|
+
*/
|
245
|
+
modifier hasAvailableFunds(uint256 _amount) {
|
246
|
+
require(withdrawableTokens >= _amount.add(ONE_FOR_CONSISTENT_GAS_COST), "Amount requested is greater than withdrawable balance");
|
247
|
+
_;
|
248
|
+
}
|
249
|
+
|
250
|
+
/**
|
251
|
+
* @dev Reverts if request ID does not exist
|
252
|
+
* @param _requestId The given request ID to check in stored `commitments`
|
253
|
+
*/
|
254
|
+
modifier isValidRequest(bytes32 _requestId) {
|
255
|
+
require(commitments[_requestId] != 0, "Must have a valid requestId");
|
256
|
+
_;
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* @dev Reverts if `msg.sender` is not authorized to fulfill requests
|
261
|
+
*/
|
262
|
+
modifier onlyAuthorizedNode() {
|
263
|
+
require(authorizedNodes[msg.sender] || msg.sender == owner(), "Not an authorized node to fulfill requests");
|
264
|
+
_;
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* @dev Reverts if the callback address is the LINK token
|
269
|
+
* @param _to The callback address
|
270
|
+
*/
|
271
|
+
modifier checkCallbackAddress(address _to) {
|
272
|
+
require(_to != address(LinkToken), "Cannot callback to LINK");
|
273
|
+
_;
|
274
|
+
}
|
275
|
+
|
276
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
interface ChainlinkRequestInterface {
|
4
|
+
function oracleRequest(
|
5
|
+
address sender,
|
6
|
+
uint256 requestPrice,
|
7
|
+
bytes32 serviceAgreementID,
|
8
|
+
address callbackAddress,
|
9
|
+
bytes4 callbackFunctionId,
|
10
|
+
uint256 nonce,
|
11
|
+
uint256 dataVersion, // Currently unused, always "1"
|
12
|
+
bytes calldata data
|
13
|
+
) external;
|
14
|
+
|
15
|
+
function cancelOracleRequest(
|
16
|
+
bytes32 requestId,
|
17
|
+
uint256 payment,
|
18
|
+
bytes4 callbackFunctionId,
|
19
|
+
uint256 expiration
|
20
|
+
) external;
|
21
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
interface ENSInterface {
|
4
|
+
|
5
|
+
// Logged when the owner of a node assigns a new owner to a subnode.
|
6
|
+
event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
|
7
|
+
|
8
|
+
// Logged when the owner of a node transfers ownership to a new account.
|
9
|
+
event Transfer(bytes32 indexed node, address owner);
|
10
|
+
|
11
|
+
// Logged when the resolver for a node changes.
|
12
|
+
event NewResolver(bytes32 indexed node, address resolver);
|
13
|
+
|
14
|
+
// Logged when the TTL of a node changes
|
15
|
+
event NewTTL(bytes32 indexed node, uint64 ttl);
|
16
|
+
|
17
|
+
|
18
|
+
function setSubnodeOwner(bytes32 node, bytes32 label, address _owner) external;
|
19
|
+
function setResolver(bytes32 node, address _resolver) external;
|
20
|
+
function setOwner(bytes32 node, address _owner) external;
|
21
|
+
function setTTL(bytes32 node, uint64 _ttl) external;
|
22
|
+
function owner(bytes32 node) external view returns (address);
|
23
|
+
function resolver(bytes32 node) external view returns (address);
|
24
|
+
function ttl(bytes32 node) external view returns (uint64);
|
25
|
+
|
26
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
interface LinkTokenInterface {
|
4
|
+
function allowance(address owner, address spender) external returns (uint256 remaining);
|
5
|
+
function approve(address spender, uint256 value) external returns (bool success);
|
6
|
+
function balanceOf(address owner) external returns (uint256 balance);
|
7
|
+
function decimals() external returns (uint8 decimalPlaces);
|
8
|
+
function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);
|
9
|
+
function increaseApproval(address spender, uint256 subtractedValue) external;
|
10
|
+
function name() external returns (string memory tokenName);
|
11
|
+
function symbol() external returns (string memory tokenSymbol);
|
12
|
+
function totalSupply() external returns (uint256 totalTokensIssued);
|
13
|
+
function transfer(address to, uint256 value) external returns (bool success);
|
14
|
+
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);
|
15
|
+
function transferFrom(address from, address to, uint256 value) external returns (bool success);
|
16
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
pragma solidity ^0.6.0;
|
2
|
+
|
3
|
+
interface OracleInterface {
|
4
|
+
function fulfillOracleRequest(
|
5
|
+
bytes32 requestId,
|
6
|
+
uint256 payment,
|
7
|
+
address callbackAddress,
|
8
|
+
bytes4 callbackFunctionId,
|
9
|
+
uint256 expiration,
|
10
|
+
bytes32 data
|
11
|
+
) external returns (bool);
|
12
|
+
function getAuthorizationStatus(address node) external view returns (bool);
|
13
|
+
function setFulfillmentPermission(address node, bool allowed) external;
|
14
|
+
function withdraw(address recipient, uint256 amount) external;
|
15
|
+
function withdrawable() external view returns (uint256);
|
16
|
+
}
|