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,320 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "./vendor/Ownable.sol";
|
4
|
+
import "./vendor/SafeMath.sol";
|
5
|
+
import "./interfaces/ChainlinkRequestInterface.sol";
|
6
|
+
import "./interfaces/OracleInterface.sol";
|
7
|
+
import "./interfaces/LinkTokenInterface.sol";
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @title The Chainlink Oracle contract
|
11
|
+
* @notice Node operators can deploy this contract to fulfill requests sent to them
|
12
|
+
*/
|
13
|
+
contract Oracle is ChainlinkRequestInterface, OracleInterface, Ownable {
|
14
|
+
using SafeMath for uint256;
|
15
|
+
|
16
|
+
uint256 constant public EXPIRY_TIME = 5 minutes;
|
17
|
+
uint256 constant private MINIMUM_CONSUMER_GAS_LIMIT = 400000;
|
18
|
+
// We initialize fields to 1 instead of 0 so that the first invocation
|
19
|
+
// does not cost more gas.
|
20
|
+
uint256 constant private ONE_FOR_CONSISTENT_GAS_COST = 1;
|
21
|
+
uint256 constant private SELECTOR_LENGTH = 4;
|
22
|
+
uint256 constant private EXPECTED_REQUEST_WORDS = 2;
|
23
|
+
uint256 constant private MINIMUM_REQUEST_LENGTH = SELECTOR_LENGTH + (32 * EXPECTED_REQUEST_WORDS);
|
24
|
+
|
25
|
+
LinkTokenInterface internal LinkToken;
|
26
|
+
mapping(bytes32 => bytes32) private commitments;
|
27
|
+
mapping(address => bool) private authorizedNodes;
|
28
|
+
uint256 private withdrawableTokens = ONE_FOR_CONSISTENT_GAS_COST;
|
29
|
+
|
30
|
+
event OracleRequest(
|
31
|
+
bytes32 indexed specId,
|
32
|
+
address requester,
|
33
|
+
bytes32 requestId,
|
34
|
+
uint256 payment,
|
35
|
+
address callbackAddr,
|
36
|
+
bytes4 callbackFunctionId,
|
37
|
+
uint256 cancelExpiration,
|
38
|
+
uint256 dataVersion,
|
39
|
+
bytes data
|
40
|
+
);
|
41
|
+
|
42
|
+
event CancelOracleRequest(
|
43
|
+
bytes32 indexed requestId
|
44
|
+
);
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @notice Deploy with the address of the LINK token
|
48
|
+
* @dev Sets the LinkToken address for the imported LinkTokenInterface
|
49
|
+
* @param _link The address of the LINK token
|
50
|
+
*/
|
51
|
+
constructor(address _link) public Ownable() {
|
52
|
+
LinkToken = LinkTokenInterface(_link); // external but already deployed and unalterable
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @notice Called when LINK is sent to the contract via `transferAndCall`
|
57
|
+
* @dev The data payload's first 2 words will be overwritten by the `_sender` and `_amount`
|
58
|
+
* values to ensure correctness. Calls oracleRequest.
|
59
|
+
* @param _sender Address of the sender
|
60
|
+
* @param _amount Amount of LINK sent (specified in wei)
|
61
|
+
* @param _data Payload of the transaction
|
62
|
+
*/
|
63
|
+
function onTokenTransfer(
|
64
|
+
address _sender,
|
65
|
+
uint256 _amount,
|
66
|
+
bytes _data
|
67
|
+
)
|
68
|
+
public
|
69
|
+
onlyLINK
|
70
|
+
validRequestLength(_data)
|
71
|
+
permittedFunctionsForLINK(_data)
|
72
|
+
{
|
73
|
+
assembly { // solhint-disable-line no-inline-assembly
|
74
|
+
mstore(add(_data, 36), _sender) // ensure correct sender is passed
|
75
|
+
mstore(add(_data, 68), _amount) // ensure correct amount is passed
|
76
|
+
}
|
77
|
+
// solhint-disable-next-line avoid-low-level-calls
|
78
|
+
require(address(this).delegatecall(_data), "Unable to create request"); // calls oracleRequest
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @notice Creates the Chainlink request
|
83
|
+
* @dev Stores the hash of the params as the on-chain commitment for the request.
|
84
|
+
* Emits OracleRequest event for the Chainlink node to detect.
|
85
|
+
* @param _sender The sender of the request
|
86
|
+
* @param _payment The amount of payment given (specified in wei)
|
87
|
+
* @param _specId The Job Specification ID
|
88
|
+
* @param _callbackAddress The callback address for the response
|
89
|
+
* @param _callbackFunctionId The callback function ID for the response
|
90
|
+
* @param _nonce The nonce sent by the requester
|
91
|
+
* @param _dataVersion The specified data version
|
92
|
+
* @param _data The CBOR payload of the request
|
93
|
+
*/
|
94
|
+
function oracleRequest(
|
95
|
+
address _sender,
|
96
|
+
uint256 _payment,
|
97
|
+
bytes32 _specId,
|
98
|
+
address _callbackAddress,
|
99
|
+
bytes4 _callbackFunctionId,
|
100
|
+
uint256 _nonce,
|
101
|
+
uint256 _dataVersion,
|
102
|
+
bytes _data
|
103
|
+
)
|
104
|
+
external
|
105
|
+
onlyLINK
|
106
|
+
checkCallbackAddress(_callbackAddress)
|
107
|
+
{
|
108
|
+
bytes32 requestId = keccak256(abi.encodePacked(_sender, _nonce));
|
109
|
+
require(commitments[requestId] == 0, "Must use a unique ID");
|
110
|
+
// solhint-disable-next-line not-rely-on-time
|
111
|
+
uint256 expiration = now.add(EXPIRY_TIME);
|
112
|
+
|
113
|
+
commitments[requestId] = keccak256(
|
114
|
+
abi.encodePacked(
|
115
|
+
_payment,
|
116
|
+
_callbackAddress,
|
117
|
+
_callbackFunctionId,
|
118
|
+
expiration
|
119
|
+
)
|
120
|
+
);
|
121
|
+
|
122
|
+
emit OracleRequest(
|
123
|
+
_specId,
|
124
|
+
_sender,
|
125
|
+
requestId,
|
126
|
+
_payment,
|
127
|
+
_callbackAddress,
|
128
|
+
_callbackFunctionId,
|
129
|
+
expiration,
|
130
|
+
_dataVersion,
|
131
|
+
_data);
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @notice Called by the Chainlink node to fulfill requests
|
136
|
+
* @dev Given params must hash back to the commitment stored from `oracleRequest`.
|
137
|
+
* Will call the callback address' callback function without bubbling up error
|
138
|
+
* checking in a `require` so that the node can get paid.
|
139
|
+
* @param _requestId The fulfillment request ID that must match the requester's
|
140
|
+
* @param _payment The payment amount that will be released for the oracle (specified in wei)
|
141
|
+
* @param _callbackAddress The callback address to call for fulfillment
|
142
|
+
* @param _callbackFunctionId The callback function ID to use for fulfillment
|
143
|
+
* @param _expiration The expiration that the node should respond by before the requester can cancel
|
144
|
+
* @param _data The data to return to the consuming contract
|
145
|
+
* @return Status if the external call was successful
|
146
|
+
*/
|
147
|
+
function fulfillOracleRequest(
|
148
|
+
bytes32 _requestId,
|
149
|
+
uint256 _payment,
|
150
|
+
address _callbackAddress,
|
151
|
+
bytes4 _callbackFunctionId,
|
152
|
+
uint256 _expiration,
|
153
|
+
bytes32 _data
|
154
|
+
)
|
155
|
+
external
|
156
|
+
onlyAuthorizedNode
|
157
|
+
isValidRequest(_requestId)
|
158
|
+
returns (bool)
|
159
|
+
{
|
160
|
+
bytes32 paramsHash = keccak256(
|
161
|
+
abi.encodePacked(
|
162
|
+
_payment,
|
163
|
+
_callbackAddress,
|
164
|
+
_callbackFunctionId,
|
165
|
+
_expiration
|
166
|
+
)
|
167
|
+
);
|
168
|
+
require(commitments[_requestId] == paramsHash, "Params do not match request ID");
|
169
|
+
withdrawableTokens = withdrawableTokens.add(_payment);
|
170
|
+
delete commitments[_requestId];
|
171
|
+
require(gasleft() >= MINIMUM_CONSUMER_GAS_LIMIT, "Must provide consumer enough gas");
|
172
|
+
// All updates to the oracle's fulfillment should come before calling the
|
173
|
+
// callback(addr+functionId) as it is untrusted.
|
174
|
+
// See: https://solidity.readthedocs.io/en/develop/security-considerations.html#use-the-checks-effects-interactions-pattern
|
175
|
+
return _callbackAddress.call(_callbackFunctionId, _requestId, _data); // solhint-disable-line avoid-low-level-calls
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* @notice Use this to check if a node is authorized for fulfilling requests
|
180
|
+
* @param _node The address of the Chainlink node
|
181
|
+
* @return The authorization status of the node
|
182
|
+
*/
|
183
|
+
function getAuthorizationStatus(address _node) external view returns (bool) {
|
184
|
+
return authorizedNodes[_node];
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* @notice Sets the fulfillment permission for a given node. Use `true` to allow, `false` to disallow.
|
189
|
+
* @param _node The address of the Chainlink node
|
190
|
+
* @param _allowed Bool value to determine if the node can fulfill requests
|
191
|
+
*/
|
192
|
+
function setFulfillmentPermission(address _node, bool _allowed) external onlyOwner {
|
193
|
+
authorizedNodes[_node] = _allowed;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @notice Allows the node operator to withdraw earned LINK to a given address
|
198
|
+
* @dev The owner of the contract can be another wallet and does not have to be a Chainlink node
|
199
|
+
* @param _recipient The address to send the LINK token to
|
200
|
+
* @param _amount The amount to send (specified in wei)
|
201
|
+
*/
|
202
|
+
function withdraw(address _recipient, uint256 _amount)
|
203
|
+
external
|
204
|
+
onlyOwner
|
205
|
+
hasAvailableFunds(_amount)
|
206
|
+
{
|
207
|
+
withdrawableTokens = withdrawableTokens.sub(_amount);
|
208
|
+
assert(LinkToken.transfer(_recipient, _amount));
|
209
|
+
}
|
210
|
+
|
211
|
+
/**
|
212
|
+
* @notice Displays the amount of LINK that is available for the node operator to withdraw
|
213
|
+
* @dev We use `ONE_FOR_CONSISTENT_GAS_COST` in place of 0 in storage
|
214
|
+
* @return The amount of withdrawable LINK on the contract
|
215
|
+
*/
|
216
|
+
function withdrawable() external view onlyOwner returns (uint256) {
|
217
|
+
return withdrawableTokens.sub(ONE_FOR_CONSISTENT_GAS_COST);
|
218
|
+
}
|
219
|
+
|
220
|
+
/**
|
221
|
+
* @notice Allows requesters to cancel requests sent to this oracle contract. Will transfer the LINK
|
222
|
+
* sent for the request back to the requester's address.
|
223
|
+
* @dev Given params must hash to a commitment stored on the contract in order for the request to be valid
|
224
|
+
* Emits CancelOracleRequest event.
|
225
|
+
* @param _requestId The request ID
|
226
|
+
* @param _payment The amount of payment given (specified in wei)
|
227
|
+
* @param _callbackFunc The requester's specified callback address
|
228
|
+
* @param _expiration The time of the expiration for the request
|
229
|
+
*/
|
230
|
+
function cancelOracleRequest(
|
231
|
+
bytes32 _requestId,
|
232
|
+
uint256 _payment,
|
233
|
+
bytes4 _callbackFunc,
|
234
|
+
uint256 _expiration
|
235
|
+
) external {
|
236
|
+
bytes32 paramsHash = keccak256(
|
237
|
+
abi.encodePacked(
|
238
|
+
_payment,
|
239
|
+
msg.sender,
|
240
|
+
_callbackFunc,
|
241
|
+
_expiration)
|
242
|
+
);
|
243
|
+
require(paramsHash == commitments[_requestId], "Params do not match request ID");
|
244
|
+
// solhint-disable-next-line not-rely-on-time
|
245
|
+
require(_expiration <= now, "Request is not expired");
|
246
|
+
|
247
|
+
delete commitments[_requestId];
|
248
|
+
emit CancelOracleRequest(_requestId);
|
249
|
+
|
250
|
+
assert(LinkToken.transfer(msg.sender, _payment));
|
251
|
+
}
|
252
|
+
|
253
|
+
// MODIFIERS
|
254
|
+
|
255
|
+
/**
|
256
|
+
* @dev Reverts if amount requested is greater than withdrawable balance
|
257
|
+
* @param _amount The given amount to compare to `withdrawableTokens`
|
258
|
+
*/
|
259
|
+
modifier hasAvailableFunds(uint256 _amount) {
|
260
|
+
require(withdrawableTokens >= _amount.add(ONE_FOR_CONSISTENT_GAS_COST), "Amount requested is greater than withdrawable balance");
|
261
|
+
_;
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* @dev Reverts if request ID does not exist
|
266
|
+
* @param _requestId The given request ID to check in stored `commitments`
|
267
|
+
*/
|
268
|
+
modifier isValidRequest(bytes32 _requestId) {
|
269
|
+
require(commitments[_requestId] != 0, "Must have a valid requestId");
|
270
|
+
_;
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* @dev Reverts if `msg.sender` is not authorized to fulfill requests
|
275
|
+
*/
|
276
|
+
modifier onlyAuthorizedNode() {
|
277
|
+
require(authorizedNodes[msg.sender] || msg.sender == owner, "Not an authorized node to fulfill requests");
|
278
|
+
_;
|
279
|
+
}
|
280
|
+
|
281
|
+
/**
|
282
|
+
* @dev Reverts if not sent from the LINK token
|
283
|
+
*/
|
284
|
+
modifier onlyLINK() {
|
285
|
+
require(msg.sender == address(LinkToken), "Must use LINK token");
|
286
|
+
_;
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* @dev Reverts if the given data does not begin with the `oracleRequest` function selector
|
291
|
+
* @param _data The data payload of the request
|
292
|
+
*/
|
293
|
+
modifier permittedFunctionsForLINK(bytes _data) {
|
294
|
+
bytes4 funcSelector;
|
295
|
+
assembly { // solhint-disable-line no-inline-assembly
|
296
|
+
funcSelector := mload(add(_data, 32))
|
297
|
+
}
|
298
|
+
require(funcSelector == this.oracleRequest.selector, "Must use whitelisted functions");
|
299
|
+
_;
|
300
|
+
}
|
301
|
+
|
302
|
+
/**
|
303
|
+
* @dev Reverts if the callback address is the LINK token
|
304
|
+
* @param _to The callback address
|
305
|
+
*/
|
306
|
+
modifier checkCallbackAddress(address _to) {
|
307
|
+
require(_to != address(LinkToken), "Cannot callback to LINK");
|
308
|
+
_;
|
309
|
+
}
|
310
|
+
|
311
|
+
/**
|
312
|
+
* @dev Reverts if the given payload is less than needed to create a request
|
313
|
+
* @param _data The request payload
|
314
|
+
*/
|
315
|
+
modifier validRequestLength(bytes _data) {
|
316
|
+
require(_data.length >= MINIMUM_REQUEST_LENGTH, "Invalid request length");
|
317
|
+
_;
|
318
|
+
}
|
319
|
+
|
320
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
pragma solidity ^0.4.24;
|
2
|
+
|
3
|
+
interface AggregatorInterface {
|
4
|
+
function latestAnswer() external view returns (int256);
|
5
|
+
function latestTimestamp() external view returns (uint256);
|
6
|
+
function latestRound() external view returns (uint256);
|
7
|
+
function getAnswer(uint256 roundId) external view returns (int256);
|
8
|
+
function getTimestamp(uint256 roundId) external view returns (uint256);
|
9
|
+
|
10
|
+
event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
|
11
|
+
event NewRound(uint256 indexed roundId, address indexed startedBy);
|
12
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
pragma solidity ^0.4.24;
|
2
|
+
|
3
|
+
interface ChainlinkRequestInterface {
|
4
|
+
function oracleRequest(
|
5
|
+
address sender,
|
6
|
+
uint256 payment,
|
7
|
+
bytes32 id,
|
8
|
+
address callbackAddress,
|
9
|
+
bytes4 callbackFunctionId,
|
10
|
+
uint256 nonce,
|
11
|
+
uint256 version,
|
12
|
+
bytes 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.4.24;
|
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.4.24;
|
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 tokenName);
|
11
|
+
function symbol() external returns (string 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 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.4.24;
|
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
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "./Consumer.sol";
|
4
|
+
|
5
|
+
contract BasicConsumer is Consumer {
|
6
|
+
|
7
|
+
constructor(address _link, address _oracle, bytes32 _specId) public {
|
8
|
+
setChainlinkToken(_link);
|
9
|
+
setChainlinkOracle(_oracle);
|
10
|
+
specId = _specId;
|
11
|
+
}
|
12
|
+
|
13
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../Chainlink.sol";
|
4
|
+
import "../vendor/CBOR.sol";
|
5
|
+
|
6
|
+
contract ConcreteChainlink {
|
7
|
+
using Chainlink for Chainlink.Request;
|
8
|
+
using CBOR for Buffer.buffer;
|
9
|
+
|
10
|
+
Chainlink.Request private req;
|
11
|
+
|
12
|
+
event RequestData(bytes payload);
|
13
|
+
|
14
|
+
function closeEvent() public {
|
15
|
+
emit RequestData(req.buf.buf);
|
16
|
+
}
|
17
|
+
|
18
|
+
function setBuffer(bytes data) public {
|
19
|
+
Chainlink.Request memory r2 = req;
|
20
|
+
r2.setBuffer(data);
|
21
|
+
req = r2;
|
22
|
+
}
|
23
|
+
|
24
|
+
function add(string _key, string _value) public {
|
25
|
+
Chainlink.Request memory r2 = req;
|
26
|
+
r2.add(_key, _value);
|
27
|
+
req = r2;
|
28
|
+
}
|
29
|
+
|
30
|
+
function addBytes(string _key, bytes _value) public {
|
31
|
+
Chainlink.Request memory r2 = req;
|
32
|
+
r2.addBytes(_key, _value);
|
33
|
+
req = r2;
|
34
|
+
}
|
35
|
+
|
36
|
+
function addInt(string _key, int256 _value) public {
|
37
|
+
Chainlink.Request memory r2 = req;
|
38
|
+
r2.addInt(_key, _value);
|
39
|
+
req = r2;
|
40
|
+
}
|
41
|
+
|
42
|
+
function addUint(string _key, uint256 _value) public {
|
43
|
+
Chainlink.Request memory r2 = req;
|
44
|
+
r2.addUint(_key, _value);
|
45
|
+
req = r2;
|
46
|
+
}
|
47
|
+
|
48
|
+
// Temporarily have method receive bytes32[] memory until experimental
|
49
|
+
// string[] memory can be invoked from truffle tests.
|
50
|
+
function addStringArray(string _key, bytes32[] memory _values) public {
|
51
|
+
string[] memory strings = new string[](_values.length);
|
52
|
+
for (uint256 i = 0; i < _values.length; i++) {
|
53
|
+
strings[i] = bytes32ToString(_values[i]);
|
54
|
+
}
|
55
|
+
Chainlink.Request memory r2 = req;
|
56
|
+
r2.addStringArray(_key, strings);
|
57
|
+
req = r2;
|
58
|
+
}
|
59
|
+
|
60
|
+
function bytes32ToString(bytes32 x) private pure returns (string) {
|
61
|
+
bytes memory bytesString = new bytes(32);
|
62
|
+
uint charCount = 0;
|
63
|
+
for (uint j = 0; j < 32; j++) {
|
64
|
+
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
|
65
|
+
if (char != 0) {
|
66
|
+
bytesString[charCount] = char;
|
67
|
+
charCount++;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
bytes memory bytesStringTrimmed = new bytes(charCount);
|
71
|
+
for (j = 0; j < charCount; j++) {
|
72
|
+
bytesStringTrimmed[j] = bytesString[j];
|
73
|
+
}
|
74
|
+
return string(bytesStringTrimmed);
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../Chainlinked.sol";
|
4
|
+
|
5
|
+
|
6
|
+
contract ConcreteChainlinked is Chainlinked {
|
7
|
+
|
8
|
+
constructor(address _link, address _oracle) public {
|
9
|
+
setLinkToken(_link);
|
10
|
+
setOracle(_oracle);
|
11
|
+
}
|
12
|
+
|
13
|
+
event Request(
|
14
|
+
bytes32 id,
|
15
|
+
address callbackAddress,
|
16
|
+
bytes4 callbackfunctionSelector,
|
17
|
+
bytes data
|
18
|
+
);
|
19
|
+
|
20
|
+
function publicNewRequest(
|
21
|
+
bytes32 _id,
|
22
|
+
address _address,
|
23
|
+
bytes _fulfillmentSignature
|
24
|
+
)
|
25
|
+
public
|
26
|
+
{
|
27
|
+
Chainlink.Request memory req = newRequest(
|
28
|
+
_id, _address, bytes4(keccak256(_fulfillmentSignature)));
|
29
|
+
emit Request(
|
30
|
+
req.id,
|
31
|
+
req.callbackAddress,
|
32
|
+
req.callbackFunctionId,
|
33
|
+
req.buf.buf
|
34
|
+
);
|
35
|
+
}
|
36
|
+
|
37
|
+
function publicRequest(
|
38
|
+
bytes32 _id,
|
39
|
+
address _address,
|
40
|
+
bytes _fulfillmentSignature,
|
41
|
+
uint256 _wei
|
42
|
+
)
|
43
|
+
public
|
44
|
+
{
|
45
|
+
Chainlink.Request memory req = newRequest(
|
46
|
+
_id, _address, bytes4(keccak256(_fulfillmentSignature)));
|
47
|
+
chainlinkRequest(req, _wei);
|
48
|
+
}
|
49
|
+
|
50
|
+
function publicRequestRunTo(
|
51
|
+
address _oracle,
|
52
|
+
bytes32 _id,
|
53
|
+
address _address,
|
54
|
+
bytes _fulfillmentSignature,
|
55
|
+
uint256 _wei
|
56
|
+
)
|
57
|
+
public
|
58
|
+
{
|
59
|
+
Chainlink.Request memory run = newRequest(_id, _address, bytes4(keccak256(_fulfillmentSignature)));
|
60
|
+
chainlinkRequestTo(_oracle, run, _wei);
|
61
|
+
}
|
62
|
+
|
63
|
+
function publicCancelRequest(
|
64
|
+
bytes32 _requestId,
|
65
|
+
uint256 _payment,
|
66
|
+
bytes4 _callbackFunctionId,
|
67
|
+
uint256 _expiration
|
68
|
+
) public {
|
69
|
+
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
|
70
|
+
}
|
71
|
+
|
72
|
+
function publicChainlinkToken() public view returns (address) {
|
73
|
+
return chainlinkToken();
|
74
|
+
}
|
75
|
+
|
76
|
+
function fulfillRequest(bytes32 _requestId, bytes32)
|
77
|
+
public
|
78
|
+
recordChainlinkFulfillment(_requestId)
|
79
|
+
{} // solhint-disable-line no-empty-blocks
|
80
|
+
|
81
|
+
function publicFulfillChainlinkRequest(bytes32 _requestId, bytes32) public {
|
82
|
+
fulfillChainlinkRequest(_requestId);
|
83
|
+
}
|
84
|
+
|
85
|
+
event LinkAmount(uint256 amount);
|
86
|
+
|
87
|
+
function publicLINK(uint256 _amount) public {
|
88
|
+
emit LinkAmount(LINK.mul(_amount));
|
89
|
+
}
|
90
|
+
|
91
|
+
function publicOracleAddress() public view returns (address) {
|
92
|
+
return oracleAddress();
|
93
|
+
}
|
94
|
+
|
95
|
+
function publicAddExternalRequest(address _oracle, bytes32 _requestId)
|
96
|
+
public
|
97
|
+
{
|
98
|
+
addExternalRequest(_oracle, _requestId);
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../vendor/SignedSafeMath.sol";
|
4
|
+
|
5
|
+
contract ConcreteSignedSafeMath {
|
6
|
+
using SignedSafeMath for int256;
|
7
|
+
|
8
|
+
function testAdd(int256 _a, int256 _b)
|
9
|
+
external
|
10
|
+
pure
|
11
|
+
returns (int256)
|
12
|
+
{
|
13
|
+
return _a.add(_b);
|
14
|
+
}
|
15
|
+
|
16
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../ChainlinkClient.sol";
|
4
|
+
|
5
|
+
contract Consumer is ChainlinkClient {
|
6
|
+
bytes32 internal specId;
|
7
|
+
bytes32 public currentPrice;
|
8
|
+
|
9
|
+
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
|
10
|
+
|
11
|
+
event RequestFulfilled(
|
12
|
+
bytes32 indexed requestId, // User-defined ID
|
13
|
+
bytes32 indexed price
|
14
|
+
);
|
15
|
+
|
16
|
+
function requestEthereumPrice(string _currency) public {
|
17
|
+
Chainlink.Request memory req = buildChainlinkRequest(specId, this, this.fulfill.selector);
|
18
|
+
req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY");
|
19
|
+
string[] memory path = new string[](1);
|
20
|
+
path[0] = _currency;
|
21
|
+
req.addStringArray("path", path);
|
22
|
+
sendChainlinkRequest(req, ORACLE_PAYMENT);
|
23
|
+
}
|
24
|
+
|
25
|
+
function cancelRequest(
|
26
|
+
bytes32 _requestId,
|
27
|
+
uint256 _payment,
|
28
|
+
bytes4 _callbackFunctionId,
|
29
|
+
uint256 _expiration
|
30
|
+
) public {
|
31
|
+
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
|
32
|
+
}
|
33
|
+
|
34
|
+
function withdrawLink() public {
|
35
|
+
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
|
36
|
+
require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
|
37
|
+
}
|
38
|
+
|
39
|
+
function fulfill(bytes32 _requestId, bytes32 _price)
|
40
|
+
public
|
41
|
+
recordChainlinkFulfillment(_requestId)
|
42
|
+
{
|
43
|
+
emit RequestFulfilled(_requestId, _price);
|
44
|
+
currentPrice = _price;
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|