From 0a4f8b3fb50f4c4b0d4ff9de76d38f44d03597f3 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Thu, 16 Dec 2021 14:02:18 -0800 Subject: [PATCH 1/3] Create base Snaplink contract --- contracts/common/Snaplink.sol | 59 +++++++++++++++++++++++++++++++++++ lib/colonyToken | 2 +- package.json | 1 + yarn.lock | 5 +++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 contracts/common/Snaplink.sol diff --git a/contracts/common/Snaplink.sol b/contracts/common/Snaplink.sol new file mode 100644 index 0000000000..cec05ecb09 --- /dev/null +++ b/contracts/common/Snaplink.sol @@ -0,0 +1,59 @@ +/* + 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"; + + +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(address _oracle, bytes32 _jobId, uint256 _fee) public { + setPublicChainlinkToken(); + oracle = _oracle; // 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; + jobId = _jobId; // "d5270d1c311941d0b08bead21fea7747"; + fee = _fee; // 0.1 * WAD + } + + 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)); + + return 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/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" From d6bbe3c893c6327e5c2a72637dd076624de2c6c4 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Mon, 20 Dec 2021 10:35:44 -0800 Subject: [PATCH 2/3] Add Ropsten to truffle.js --- truffle.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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", }, From 48682241b6867e9be15b2b7055de06de19e4277f Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Mon, 17 Jan 2022 17:24:22 -0500 Subject: [PATCH 3/3] Add helpful error messages to Snaplink --- contracts/common/Snaplink.sol | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/common/Snaplink.sol b/contracts/common/Snaplink.sol index cec05ecb09..16200c3f27 100644 --- a/contracts/common/Snaplink.sol +++ b/contracts/common/Snaplink.sol @@ -19,6 +19,7 @@ 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 { @@ -33,11 +34,11 @@ contract Snaplink is ChainlinkClient { uint256 constant WAD = 10 ** 18; bytes4 constant SELECTOR = bytes4(keccak256("fulfill(bytes32,uint256")); - constructor(address _oracle, bytes32 _jobId, uint256 _fee) public { + constructor() public { setPublicChainlinkToken(); - oracle = _oracle; // 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; - jobId = _jobId; // "d5270d1c311941d0b08bead21fea7747"; - fee = _fee; // 0.1 * WAD + oracle = 0x3A56aE4a2831C3d3514b5D7Af5578E45eBDb7a40; + jobId = "b7ca0d48c7a4b2da9268456665d11ae"; + fee = WAD / 10; } function requestVolumeData() public returns (bytes32 requestId) { @@ -47,7 +48,8 @@ contract Snaplink is ChainlinkClient { request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); request.addInt("times", int256(WAD)); - return sendChainlinkRequestTo(oracle, request, fee); + require(ERC20(chainlinkTokenAddress()).balanceOf(address(this)) >= fee, "insufficient-balance"); + requestId = sendChainlinkRequestTo(oracle, request, fee); } function fulfill(bytes32 _requestId, uint256 _volume)