Skip to content

Commit 0a4f8b3

Browse files
committed
Create base Snaplink contract
1 parent e06f781 commit 0a4f8b3

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

contracts/common/Snaplink.sol

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
This file is part of The Colony Network.
3+
4+
The Colony Network is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
The Colony Network is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
pragma solidity 0.7.3;
19+
pragma experimental ABIEncoderV2;
20+
21+
import "@chainlink/contracts/src/v0.7/ChainlinkClient.sol";
22+
23+
24+
contract Snaplink is ChainlinkClient {
25+
using Chainlink for Chainlink.Request;
26+
27+
uint256 public volume;
28+
29+
address private oracle;
30+
bytes32 private jobId;
31+
uint256 private fee;
32+
33+
uint256 constant WAD = 10 ** 18;
34+
bytes4 constant SELECTOR = bytes4(keccak256("fulfill(bytes32,uint256"));
35+
36+
constructor(address _oracle, bytes32 _jobId, uint256 _fee) public {
37+
setPublicChainlinkToken();
38+
oracle = _oracle; // 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
39+
jobId = _jobId; // "d5270d1c311941d0b08bead21fea7747";
40+
fee = _fee; // 0.1 * WAD
41+
}
42+
43+
function requestVolumeData() public returns (bytes32 requestId) {
44+
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), SELECTOR);
45+
46+
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
47+
request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
48+
request.addInt("times", int256(WAD));
49+
50+
return sendChainlinkRequestTo(oracle, request, fee);
51+
}
52+
53+
function fulfill(bytes32 _requestId, uint256 _volume)
54+
public
55+
recordChainlinkFulfillment(_requestId)
56+
{
57+
volume = _volume;
58+
}
59+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"packages/*"
131131
],
132132
"dependencies": {
133+
"@chainlink/contracts": "^0.3.0",
133134
"eslint-plugin-no-only-tests": "^2.4.0"
134135
}
135136
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,11 @@
861861
lodash "^4.17.19"
862862
to-fast-properties "^2.0.0"
863863

864+
"@chainlink/contracts@^0.3.0":
865+
version "0.3.0"
866+
resolved "https://registry.yarnpkg.com/@chainlink/contracts/-/contracts-0.3.0.tgz#b388615acab5d9353bc15b5357250cf0662bc8fe"
867+
integrity sha512-Pxu5qMTa0gc28Sxf9hyBkvwhPMn3HD62cGXy54RkL9PcabOHlUsk1i3BoFf3rwFr7T30N/obYn4de3ZrG12PDA==
868+
864869
"@codechecks/client@^0.1.5":
865870
version "0.1.10"
866871
resolved "https://registry.yarnpkg.com/@codechecks/client/-/client-0.1.10.tgz#41fe736c424976d9feb8116b131fb9c1f099d105"

0 commit comments

Comments
 (0)