Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create chainlink integration #1010

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions contracts/common/Snaplink.sol
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"packages/*"
],
"dependencies": {
"@chainlink/contracts": "^0.3.0",
"eslint-plugin-no-only-tests": "^2.4.0"
}
}
10 changes: 8 additions & 2 deletions truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down