chainlinnk 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -0
- package/bvh7av34.cjs +1 -0
- 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 +50 -0
- 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,411 @@
|
|
1
|
+
pragma solidity 0.5.0;
|
2
|
+
|
3
|
+
import "./CoordinatorInterface.sol";
|
4
|
+
import "../interfaces/ChainlinkRequestInterface.sol";
|
5
|
+
import "../interfaces/LinkTokenInterface.sol";
|
6
|
+
import "../vendor/SafeMath.sol";
|
7
|
+
import "./ServiceAgreementDecoder.sol";
|
8
|
+
import "./OracleSignaturesDecoder.sol";
|
9
|
+
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @title The Chainlink Coordinator handles oracle service aggreements between one or more oracles
|
13
|
+
*/
|
14
|
+
contract Coordinator is ChainlinkRequestInterface, CoordinatorInterface, ServiceAgreementDecoder, OracleSignaturesDecoder {
|
15
|
+
using SafeMath for uint256;
|
16
|
+
|
17
|
+
uint256 constant public EXPIRY_TIME = 5 minutes;
|
18
|
+
LinkTokenInterface internal LINK;
|
19
|
+
|
20
|
+
struct Callback {
|
21
|
+
bytes32 sAId;
|
22
|
+
uint256 amount;
|
23
|
+
address addr;
|
24
|
+
bytes4 functionId;
|
25
|
+
uint64 cancelExpiration;
|
26
|
+
uint8 responseCount;
|
27
|
+
mapping(address => uint256) responses;
|
28
|
+
}
|
29
|
+
|
30
|
+
mapping(bytes32 => Callback) private callbacks;
|
31
|
+
mapping(bytes32 => mapping(address => bool)) private allowedOracles;
|
32
|
+
mapping(bytes32 => ServiceAgreement) public serviceAgreements;
|
33
|
+
mapping(address => uint256) public withdrawableTokens;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @notice Deploy with the address of the LINK token
|
37
|
+
* @dev Sets the LinkToken address for the imported LinkTokenInterface
|
38
|
+
* @param _link The address of the LINK token
|
39
|
+
*/
|
40
|
+
constructor(address _link) public {
|
41
|
+
LINK = LinkTokenInterface(_link);
|
42
|
+
}
|
43
|
+
|
44
|
+
event OracleRequest(
|
45
|
+
bytes32 indexed sAId,
|
46
|
+
address requester,
|
47
|
+
bytes32 requestId,
|
48
|
+
uint256 payment,
|
49
|
+
address callbackAddr,
|
50
|
+
bytes4 callbackFunctionId,
|
51
|
+
uint256 cancelExpiration,
|
52
|
+
uint256 dataVersion,
|
53
|
+
bytes data
|
54
|
+
);
|
55
|
+
|
56
|
+
event NewServiceAgreement(
|
57
|
+
bytes32 indexed said,
|
58
|
+
bytes32 indexed requestDigest
|
59
|
+
);
|
60
|
+
|
61
|
+
event CancelOracleRequest(
|
62
|
+
bytes32 internalId
|
63
|
+
);
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @notice Creates the Chainlink request
|
67
|
+
* @dev Stores the params on-chain in a callback for the request.
|
68
|
+
* Emits OracleRequest event for Chainlink nodes to detect.
|
69
|
+
* @param _sender The sender of the request
|
70
|
+
* @param _amount The amount of payment given (specified in wei)
|
71
|
+
* @param _sAId The Service Agreement ID
|
72
|
+
* @param _callbackAddress The callback address for the response
|
73
|
+
* @param _callbackFunctionId The callback function ID for the response
|
74
|
+
* @param _nonce The nonce sent by the requester
|
75
|
+
* @param _dataVersion The specified data version
|
76
|
+
* @param _data The CBOR payload of the request
|
77
|
+
*/
|
78
|
+
function oracleRequest(
|
79
|
+
address _sender,
|
80
|
+
uint256 _amount,
|
81
|
+
bytes32 _sAId,
|
82
|
+
address _callbackAddress,
|
83
|
+
bytes4 _callbackFunctionId,
|
84
|
+
uint256 _nonce,
|
85
|
+
uint256 _dataVersion,
|
86
|
+
bytes calldata _data
|
87
|
+
)
|
88
|
+
external
|
89
|
+
onlyLINK
|
90
|
+
sufficientLINK(_amount, _sAId)
|
91
|
+
checkCallbackAddress(_callbackAddress)
|
92
|
+
// checkServiceAgreementPresence(_sAId) // TODO: exhausts the stack
|
93
|
+
{
|
94
|
+
bytes32 requestId = keccak256(abi.encodePacked(_sender, _nonce));
|
95
|
+
require(callbacks[requestId].cancelExpiration == 0, "Must use a unique ID");
|
96
|
+
callbacks[requestId].sAId = _sAId;
|
97
|
+
callbacks[requestId].amount = _amount;
|
98
|
+
callbacks[requestId].addr = _callbackAddress;
|
99
|
+
callbacks[requestId].functionId = _callbackFunctionId;
|
100
|
+
// solhint-disable-next-line not-rely-on-time
|
101
|
+
callbacks[requestId].cancelExpiration = uint64(now.add(EXPIRY_TIME));
|
102
|
+
|
103
|
+
emit OracleRequest(
|
104
|
+
_sAId,
|
105
|
+
_sender,
|
106
|
+
requestId,
|
107
|
+
_amount,
|
108
|
+
_callbackAddress,
|
109
|
+
_callbackFunctionId,
|
110
|
+
now.add(EXPIRY_TIME), // solhint-disable-line not-rely-on-time
|
111
|
+
_dataVersion,
|
112
|
+
_data);
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* @notice Stores a Service Agreement which has been signed by the given oracles
|
117
|
+
* @dev Validates that each oracle has a valid signature.
|
118
|
+
* Emits NewServiceAgreement event.
|
119
|
+
* @return The Service Agreement ID
|
120
|
+
*/
|
121
|
+
function initiateServiceAgreement(
|
122
|
+
bytes memory _serviceAgreementData,
|
123
|
+
bytes memory _oracleSignaturesData
|
124
|
+
)
|
125
|
+
public
|
126
|
+
returns (bytes32 serviceAgreementID)
|
127
|
+
{
|
128
|
+
|
129
|
+
ServiceAgreement memory _agreement = decodeServiceAgreement(_serviceAgreementData);
|
130
|
+
OracleSignatures memory _signatures = decodeOracleSignatures(_oracleSignaturesData);
|
131
|
+
|
132
|
+
require(
|
133
|
+
_agreement.oracles.length == _signatures.vs.length &&
|
134
|
+
_signatures.vs.length == _signatures.rs.length &&
|
135
|
+
_signatures.rs.length == _signatures.ss.length,
|
136
|
+
"Must pass in as many signatures as oracles"
|
137
|
+
);
|
138
|
+
// solhint-disable-next-line not-rely-on-time
|
139
|
+
require(_agreement.endAt > block.timestamp,
|
140
|
+
"ServiceAgreement must end in the future");
|
141
|
+
require(serviceAgreements[serviceAgreementID].endAt == 0,
|
142
|
+
"serviceAgreement already initiated");
|
143
|
+
serviceAgreementID = getId(_agreement);
|
144
|
+
|
145
|
+
registerOracleSignatures(
|
146
|
+
serviceAgreementID,
|
147
|
+
_agreement.oracles,
|
148
|
+
_signatures
|
149
|
+
);
|
150
|
+
|
151
|
+
serviceAgreements[serviceAgreementID] = _agreement;
|
152
|
+
emit NewServiceAgreement(serviceAgreementID, _agreement.requestDigest);
|
153
|
+
// solhint-disable-next-line avoid-low-level-calls
|
154
|
+
(bool ok, bytes memory response) = _agreement.aggregator.call(
|
155
|
+
abi.encodeWithSelector(
|
156
|
+
_agreement.aggInitiateJobSelector,
|
157
|
+
serviceAgreementID,
|
158
|
+
_serviceAgreementData
|
159
|
+
)
|
160
|
+
);
|
161
|
+
require(ok, "Aggregator failed to initiate Service Agreement");
|
162
|
+
require(response.length > 0, "probably wrong address/selector");
|
163
|
+
(bool success, bytes memory message) = abi.decode(response, (bool, bytes));
|
164
|
+
if ((!success) && message.length == 0) {
|
165
|
+
// Revert with a non-empty message to give user a hint where to look
|
166
|
+
require(success, "initiation failed; empty message");
|
167
|
+
}
|
168
|
+
require(success, string(message));
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* @dev Validates that each signer address matches for the given oracles
|
173
|
+
* @param _serviceAgreementID Service agreement ID
|
174
|
+
* @param _oracles Array of oracle addresses which agreed to the service agreement
|
175
|
+
* @param _signatures contains the collected parts(v, r, and s) of each oracle's signature.
|
176
|
+
*/
|
177
|
+
function registerOracleSignatures(
|
178
|
+
bytes32 _serviceAgreementID,
|
179
|
+
address[] memory _oracles,
|
180
|
+
OracleSignatures memory _signatures
|
181
|
+
)
|
182
|
+
private
|
183
|
+
{
|
184
|
+
for (uint i = 0; i < _oracles.length; i++) {
|
185
|
+
address signer = getOracleAddressFromSASignature(
|
186
|
+
_serviceAgreementID,
|
187
|
+
_signatures.vs[i],
|
188
|
+
_signatures.rs[i],
|
189
|
+
_signatures.ss[i]
|
190
|
+
);
|
191
|
+
require(_oracles[i] == signer, "Invalid oracle signature specified in SA");
|
192
|
+
allowedOracles[_serviceAgreementID][_oracles[i]] = true;
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* @dev Recovers the address of the signer for a service agreement
|
199
|
+
* @param _serviceAgreementID Service agreement ID
|
200
|
+
* @param _v Recovery ID of the oracle signature
|
201
|
+
* @param _r First 32 bytes of the oracle signature
|
202
|
+
* @param _s Second 32 bytes of the oracle signature
|
203
|
+
* @return The address of the signer
|
204
|
+
*/
|
205
|
+
function getOracleAddressFromSASignature(
|
206
|
+
bytes32 _serviceAgreementID,
|
207
|
+
uint8 _v,
|
208
|
+
bytes32 _r,
|
209
|
+
bytes32 _s
|
210
|
+
)
|
211
|
+
private pure returns (address)
|
212
|
+
{
|
213
|
+
bytes32 prefixedHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _serviceAgreementID));
|
214
|
+
return ecrecover(prefixedHash, _v, _r, _s);
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* @notice Called by the Chainlink node to fulfill requests
|
219
|
+
* @dev Response must have a valid callback, and will delete the associated callback storage
|
220
|
+
* before calling the external contract.
|
221
|
+
* @param _requestId The fulfillment request ID that must match the requester's
|
222
|
+
* @param _data The data to return to the consuming contract
|
223
|
+
* @return Status if the external call was successful
|
224
|
+
*/
|
225
|
+
function fulfillOracleRequest(
|
226
|
+
bytes32 _requestId,
|
227
|
+
bytes32 _data
|
228
|
+
) external isValidRequest(_requestId) returns (bool) {
|
229
|
+
Callback memory callback = callbacks[_requestId];
|
230
|
+
ServiceAgreement memory sA = serviceAgreements[callback.sAId];
|
231
|
+
// solhint-disable-next-line avoid-low-level-calls
|
232
|
+
(bool ok, bytes memory aggResponse) = sA.aggregator.call(
|
233
|
+
abi.encodeWithSelector(
|
234
|
+
sA.aggFulfillSelector, _requestId, callback.sAId, msg.sender, _data));
|
235
|
+
require(ok, "aggregator.fulfill failed");
|
236
|
+
require(aggResponse.length > 0, "probably wrong address/selector");
|
237
|
+
(bool aggSuccess, bool aggComplete, bytes memory response, int256[] memory paymentAmounts) = abi.decode( // solhint-disable-line
|
238
|
+
aggResponse, (bool, bool, bytes, int256[]));
|
239
|
+
require(aggSuccess, string(response));
|
240
|
+
if (aggComplete) {
|
241
|
+
require(paymentAmounts.length == sA.oracles.length, "wrong paymentAmounts.length");
|
242
|
+
for (uint256 oIdx = 0; oIdx < sA.oracles.length; oIdx++) { // pay oracles
|
243
|
+
withdrawableTokens[sA.oracles[oIdx]] = uint256(int256(
|
244
|
+
withdrawableTokens[sA.oracles[oIdx]]) + paymentAmounts[oIdx]);
|
245
|
+
} // solhint-disable-next-line avoid-low-level-calls
|
246
|
+
(bool success,) = callback.addr.call(abi.encodeWithSelector( // report final result
|
247
|
+
callback.functionId, _requestId, abi.decode(response, (bytes32))));
|
248
|
+
return success;
|
249
|
+
}
|
250
|
+
return true;
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* @dev Allows the oracle operator to withdraw their LINK
|
255
|
+
* @param _recipient is the address the funds will be sent to
|
256
|
+
* @param _amount is the amount of LINK transfered from the Coordinator contract
|
257
|
+
*/
|
258
|
+
function withdraw(address _recipient, uint256 _amount)
|
259
|
+
external
|
260
|
+
hasAvailableFunds(_amount)
|
261
|
+
{
|
262
|
+
withdrawableTokens[msg.sender] = withdrawableTokens[msg.sender].sub(_amount);
|
263
|
+
assert(LINK.transfer(_recipient, _amount));
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* @dev Necessary to implement ChainlinkRequestInterface
|
268
|
+
*/
|
269
|
+
function cancelOracleRequest(bytes32, uint256, bytes4, uint256)
|
270
|
+
external
|
271
|
+
{} // solhint-disable-line no-empty-blocks
|
272
|
+
|
273
|
+
/**
|
274
|
+
* @notice Called when LINK is sent to the contract via `transferAndCall`
|
275
|
+
* @dev The data payload's first 2 words will be overwritten by the `_sender` and `_amount`
|
276
|
+
* values to ensure correctness. Calls oracleRequest.
|
277
|
+
* @param _sender Address of the sender
|
278
|
+
* @param _amount Amount of LINK sent (specified in wei)
|
279
|
+
* @param _data Payload of the transaction
|
280
|
+
*/
|
281
|
+
function onTokenTransfer(
|
282
|
+
address _sender,
|
283
|
+
uint256 _amount,
|
284
|
+
bytes memory _data
|
285
|
+
)
|
286
|
+
public
|
287
|
+
onlyLINK
|
288
|
+
permittedFunctionsForLINK
|
289
|
+
{
|
290
|
+
assembly { // solhint-disable-line no-inline-assembly
|
291
|
+
mstore(add(_data, 36), _sender) // ensure correct sender is passed
|
292
|
+
mstore(add(_data, 68), _amount) // ensure correct amount is passed
|
293
|
+
}
|
294
|
+
// solhint-disable-next-line avoid-low-level-calls
|
295
|
+
(bool success,) = address(this).delegatecall(_data); // calls oracleRequest or depositFunds
|
296
|
+
require(success, "Unable to create request");
|
297
|
+
}
|
298
|
+
|
299
|
+
/**
|
300
|
+
* @notice Retrieve the Service Agreement ID for the given parameters
|
301
|
+
* @param _agreementData contains all of the terms of the service agreement that can be verified on-chain.
|
302
|
+
* @return The Service Agreement ID, a keccak256 hash of the input params
|
303
|
+
*/
|
304
|
+
function getId(bytes memory _agreementData) public pure returns (bytes32)
|
305
|
+
{
|
306
|
+
ServiceAgreement memory _agreement = decodeServiceAgreement(_agreementData);
|
307
|
+
return getId(_agreement);
|
308
|
+
}
|
309
|
+
|
310
|
+
function getId(ServiceAgreement memory _agreement) internal pure returns (bytes32)
|
311
|
+
{
|
312
|
+
return keccak256(
|
313
|
+
abi.encodePacked(
|
314
|
+
_agreement.payment,
|
315
|
+
_agreement.expiration,
|
316
|
+
_agreement.endAt,
|
317
|
+
_agreement.oracles,
|
318
|
+
_agreement.requestDigest,
|
319
|
+
_agreement.aggregator,
|
320
|
+
_agreement.aggInitiateJobSelector,
|
321
|
+
_agreement.aggFulfillSelector
|
322
|
+
));
|
323
|
+
}
|
324
|
+
|
325
|
+
/**
|
326
|
+
* @notice Called when LINK is sent to the contract via `transferAndCall`
|
327
|
+
* @param _sender Address of the sender
|
328
|
+
* @param _amount Amount of LINK sent (specified in wei)
|
329
|
+
*/
|
330
|
+
function depositFunds(address _sender, uint256 _amount) external onlyLINK
|
331
|
+
{
|
332
|
+
withdrawableTokens[_sender] = withdrawableTokens[_sender].add(_amount);
|
333
|
+
}
|
334
|
+
|
335
|
+
/**
|
336
|
+
* @param _account Address to check balance of
|
337
|
+
* @return Balance of account (specified in wei)
|
338
|
+
*/
|
339
|
+
function balanceOf(address _account) public view returns (uint256)
|
340
|
+
{
|
341
|
+
return withdrawableTokens[_account];
|
342
|
+
}
|
343
|
+
|
344
|
+
/**
|
345
|
+
* @dev Reverts if the callback address is the LINK token
|
346
|
+
* @param _to The callback address
|
347
|
+
*/
|
348
|
+
modifier checkCallbackAddress(address _to) {
|
349
|
+
require(_to != address(LINK), "Cannot callback to LINK");
|
350
|
+
_;
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* @dev Reverts if amount requested is greater than withdrawable balance
|
355
|
+
* @param _amount The given amount to compare to `withdrawableTokens`
|
356
|
+
*/
|
357
|
+
modifier hasAvailableFunds(uint256 _amount) {
|
358
|
+
require(withdrawableTokens[msg.sender] >= _amount, "Amount requested is greater than withdrawable balance");
|
359
|
+
_;
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* @dev Reverts if request ID does not exist
|
364
|
+
* @param _requestId The given request ID to check in stored `callbacks`
|
365
|
+
*/
|
366
|
+
modifier isValidRequest(bytes32 _requestId) {
|
367
|
+
require(callbacks[_requestId].addr != address(0), "Must have a valid requestId");
|
368
|
+
require(allowedOracles[callbacks[_requestId].sAId][msg.sender], "Oracle not recognized on service agreement");
|
369
|
+
_;
|
370
|
+
}
|
371
|
+
|
372
|
+
/**
|
373
|
+
* @dev Reverts if amount is not at least what was agreed upon in the service agreement
|
374
|
+
* @param _amount The payment for the request
|
375
|
+
* @param _sAId The service agreement ID which the request is for
|
376
|
+
*/
|
377
|
+
modifier sufficientLINK(uint256 _amount, bytes32 _sAId) {
|
378
|
+
require(_amount >= serviceAgreements[_sAId].payment, "Below agreed payment");
|
379
|
+
_;
|
380
|
+
}
|
381
|
+
|
382
|
+
/**
|
383
|
+
* @dev Reverts if the given data does not begin with the `oracleRequest` or
|
384
|
+
* `depositFunds` function selector
|
385
|
+
*/
|
386
|
+
modifier permittedFunctionsForLINK() {
|
387
|
+
bytes4[1] memory funcSelector;
|
388
|
+
assembly { // solhint-disable-line no-inline-assembly
|
389
|
+
calldatacopy(funcSelector, 132, 4) // grab function selector from calldata
|
390
|
+
}
|
391
|
+
require(
|
392
|
+
funcSelector[0] == this.oracleRequest.selector || funcSelector[0] == this.depositFunds.selector,
|
393
|
+
"Must use whitelisted functions"
|
394
|
+
);
|
395
|
+
_;
|
396
|
+
}
|
397
|
+
|
398
|
+
modifier checkServiceAgreementPresence(bytes32 _sAId) {
|
399
|
+
require(uint256(serviceAgreements[_sAId].requestDigest) != 0,
|
400
|
+
"Must reference an existing ServiceAgreement");
|
401
|
+
_;
|
402
|
+
}
|
403
|
+
|
404
|
+
/**
|
405
|
+
* @dev Reverts if not sent from the LINK token
|
406
|
+
*/
|
407
|
+
modifier onlyLINK() {
|
408
|
+
require(msg.sender == address(LINK), "Must use LINK token");
|
409
|
+
_;
|
410
|
+
}
|
411
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
pragma solidity 0.5.0;
|
2
|
+
|
3
|
+
contract CoordinatorInterface {
|
4
|
+
|
5
|
+
function initiateServiceAgreement(
|
6
|
+
bytes memory _serviceAgreementData,
|
7
|
+
bytes memory _oracleSignaturesData)
|
8
|
+
public returns (bytes32);
|
9
|
+
|
10
|
+
function fulfillOracleRequest(
|
11
|
+
bytes32 _requestId,
|
12
|
+
bytes32 _aggregatorArgs)
|
13
|
+
external returns (bool);
|
14
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
pragma solidity 0.5.0;
|
2
|
+
|
3
|
+
contract OracleSignaturesDecoder {
|
4
|
+
|
5
|
+
struct OracleSignatures {
|
6
|
+
uint8[] vs;
|
7
|
+
bytes32[] rs;
|
8
|
+
bytes32[] ss;
|
9
|
+
}
|
10
|
+
|
11
|
+
function decodeOracleSignatures(
|
12
|
+
bytes memory _oracleSignaturesData
|
13
|
+
)
|
14
|
+
internal
|
15
|
+
pure
|
16
|
+
returns(OracleSignatures memory)
|
17
|
+
{
|
18
|
+
// solhint-disable indent
|
19
|
+
OracleSignatures memory signatures;
|
20
|
+
( signatures.vs, signatures.rs, signatures.ss) =
|
21
|
+
abi.decode(_oracleSignaturesData, ( uint8[], bytes32[], bytes32[] ));
|
22
|
+
return signatures;
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
pragma solidity 0.5.0;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @title The Owned contract
|
5
|
+
* @notice A contract with helpers for basic contract ownership.
|
6
|
+
*/
|
7
|
+
contract Owned {
|
8
|
+
|
9
|
+
address public owner;
|
10
|
+
address private pendingOwner;
|
11
|
+
|
12
|
+
event OwnershipTransferRequested(
|
13
|
+
address indexed from,
|
14
|
+
address indexed to
|
15
|
+
);
|
16
|
+
event OwnershipTransfered(
|
17
|
+
address indexed from,
|
18
|
+
address indexed to
|
19
|
+
);
|
20
|
+
|
21
|
+
constructor() public {
|
22
|
+
owner = msg.sender;
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @dev Allows an owner to begin transferring ownership to a new address,
|
27
|
+
* pending.
|
28
|
+
*/
|
29
|
+
function transferOwnership(address _to)
|
30
|
+
external
|
31
|
+
onlyOwner()
|
32
|
+
{
|
33
|
+
pendingOwner = _to;
|
34
|
+
|
35
|
+
emit OwnershipTransferRequested(owner, _to);
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @dev Allows an ownership transfer to be completed by the recipient.
|
40
|
+
*/
|
41
|
+
function acceptOwnership()
|
42
|
+
external
|
43
|
+
{
|
44
|
+
require(msg.sender == pendingOwner, "Must be proposed owner");
|
45
|
+
|
46
|
+
address oldOwner = owner;
|
47
|
+
owner = msg.sender;
|
48
|
+
pendingOwner = address(0);
|
49
|
+
|
50
|
+
emit OwnershipTransfered(oldOwner, msg.sender);
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @dev Reverts if called by anyone other than the contract owner.
|
55
|
+
*/
|
56
|
+
modifier onlyOwner() {
|
57
|
+
require(msg.sender == owner, "Only callable by owner");
|
58
|
+
_;
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|