diff --git a/contracts/common/Snaplink.sol b/contracts/common/Snaplink.sol new file mode 100644 index 0000000000..16200c3f27 --- /dev/null +++ b/contracts/common/Snaplink.sol @@ -0,0 +1,61 @@ +/* + This file is part of The Colony Network. + + The Colony Network is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + The Colony Network is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Colony Network. If not, see . +*/ + +pragma solidity 0.7.3; +pragma experimental ABIEncoderV2; + +import "@chainlink/contracts/src/v0.7/ChainlinkClient.sol"; +import "./../../lib/dappsys/erc20.sol"; + + +contract Snaplink is ChainlinkClient { + using Chainlink for Chainlink.Request; + + uint256 public volume; + + address private oracle; + bytes32 private jobId; + uint256 private fee; + + uint256 constant WAD = 10 ** 18; + bytes4 constant SELECTOR = bytes4(keccak256("fulfill(bytes32,uint256")); + + constructor() public { + setPublicChainlinkToken(); + oracle = 0x3A56aE4a2831C3d3514b5D7Af5578E45eBDb7a40; + jobId = "b7ca0d48c7a4b2da9268456665d11ae"; + fee = WAD / 10; + } + + function requestVolumeData() public returns (bytes32 requestId) { + Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), SELECTOR); + + request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"); + request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); + request.addInt("times", int256(WAD)); + + require(ERC20(chainlinkTokenAddress()).balanceOf(address(this)) >= fee, "insufficient-balance"); + requestId = sendChainlinkRequestTo(oracle, request, fee); + } + + function fulfill(bytes32 _requestId, uint256 _volume) + public + recordChainlinkFulfillment(_requestId) + { + volume = _volume; + } +} diff --git a/lib/colonyToken b/lib/colonyToken index 8e51395860..506d8ac3b3 160000 --- a/lib/colonyToken +++ b/lib/colonyToken @@ -1 +1 @@ -Subproject commit 8e5139586018fbaa53e9cf971e040b3ae2a4bb92 +Subproject commit 506d8ac3b36c30e401c908e5a2d4529d8fb6dac0 diff --git a/package.json b/package.json index c611028401..91ce6ecffc 100644 --- a/package.json +++ b/package.json @@ -130,6 +130,7 @@ "packages/*" ], "dependencies": { + "@chainlink/contracts": "^0.3.0", "eslint-plugin-no-only-tests": "^2.4.0" } } diff --git a/truffle.js b/truffle.js index 2b4ecf53f1..b888b4723d 100644 --- a/truffle.js +++ b/truffle.js @@ -43,13 +43,19 @@ module.exports = { }, goerli: { provider: () => { - return new HDWalletProvider("replace-with-private-key-when-using", "https://goerli.infura.io/v3/e21146aa267845a2b7b4da025178196d"); + return new HDWalletProvider("private-key", "https://goerli.infura.io/v3/infura-key"); }, network_id: "5", }, + rinkeby: { + provider: () => { + return new HDWalletProvider("private-key", "https://rinkeby.infura.io/v3/infura-key"); + }, + network_id: "4", + }, mainnet: { provider: () => { - return new HDWalletProvider("replace-with-private-key-when-using", "https://mainnet.infura.io/v3/e21146aa267845a2b7b4da025178196d"); + return new HDWalletProvider("private-key", "https://mainnet.infura.io/v3/infura-key"); }, network_id: "1", }, diff --git a/yarn.lock b/yarn.lock index cc964f6800..743398960e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -861,6 +861,11 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" +"@chainlink/contracts@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@chainlink/contracts/-/contracts-0.3.0.tgz#b388615acab5d9353bc15b5357250cf0662bc8fe" + integrity sha512-Pxu5qMTa0gc28Sxf9hyBkvwhPMn3HD62cGXy54RkL9PcabOHlUsk1i3BoFf3rwFr7T30N/obYn4de3ZrG12PDA== + "@codechecks/client@^0.1.5": version "0.1.10" resolved "https://registry.yarnpkg.com/@codechecks/client/-/client-0.1.10.tgz#41fe736c424976d9feb8116b131fb9c1f099d105"