From 64f143afa35c616a9f40516485e4b07f071486b8 Mon Sep 17 00:00:00 2001 From: Zubin Pratap Date: Mon, 19 Aug 2024 15:05:08 +1000 Subject: [PATCH 1/2] remove AnyApi Code --- README.md | 1 - script/APIConsumer.s.sol | 30 ------------------------------ test/APIConsumer.t.sol | 39 --------------------------------------- 3 files changed, 70 deletions(-) delete mode 100644 script/APIConsumer.s.sol delete mode 100644 test/APIConsumer.t.sol diff --git a/README.md b/README.md index dbea15e..de5ca60 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,6 @@ Implementation of the following 4 Chainlink services using the [Foundry] (https: - [Chainlink Price Feeds](https://docs.chain.link/docs/using-chainlink-reference-contracts) - [Chainlink VRF V2](https://docs.chain.link/docs/chainlink-vrf) - [Chainlink Automation](https://docs.chain.link/chainlink-automation/introduction) -- [Request & Receive data (AnyAPI)](https://docs.chain.link/any-api/introduction) For [Chainlink Functions](https://docs.chain.link/chainlink-functions) please go to these starter kits: [Hardhat](https://github.com/smartcontractkit/functions-hardhat-starter-kit) | [Foundry (coming soon)](https://github.com/smartcontractkit/functions-foundry-starter-kit) diff --git a/script/APIConsumer.s.sol b/script/APIConsumer.s.sol deleted file mode 100644 index 756bf15..0000000 --- a/script/APIConsumer.s.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.7; - -import "forge-std/Script.sol"; -import "../src/APIConsumer.sol"; -import "./HelperConfig.sol"; -import "../test/mocks/MockOracle.sol"; -import "../test//mocks/LinkToken.sol"; - -contract DeployAPIConsumer is Script, HelperConfig { - function run() external { - HelperConfig helperConfig = new HelperConfig(); - - (address oracle, bytes32 jobId, uint256 chainlinkFee, address link,,,,,) = helperConfig.activeNetworkConfig(); - - if (link == address(0)) { - link = address(new LinkToken()); - } - - if (oracle == address(0)) { - oracle = address(new MockOracle(link)); - } - - vm.startBroadcast(); - - new APIConsumer(oracle, jobId, chainlinkFee, link); - - vm.stopBroadcast(); - } -} diff --git a/test/APIConsumer.t.sol b/test/APIConsumer.t.sol deleted file mode 100644 index 7a29343..0000000 --- a/test/APIConsumer.t.sol +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import "../src/APIConsumer.sol"; -import "./mocks/LinkToken.sol"; -import "forge-std/Test.sol"; -import "./mocks/MockOracle.sol"; - -contract APIConsumerTest is Test { - APIConsumer public apiConsumer; - LinkToken public linkToken; - MockOracle public mockOracle; - - bytes32 jobId; - uint256 fee; - bytes32 blank_bytes32; - - uint256 constant AMOUNT = 1 * 10 ** 18; - uint256 constant RESPONSE = 777; - - function setUp() public { - linkToken = new LinkToken(); - mockOracle = new MockOracle(address(linkToken)); - apiConsumer = new APIConsumer(address(mockOracle), jobId, fee, address(linkToken)); - linkToken.transfer(address(apiConsumer), AMOUNT); - } - - function testCanMakeRequest() public { - bytes32 requestId = apiConsumer.requestVolumeData(); - assertTrue(requestId != blank_bytes32); - } - - function testCanGetResponse() public { - bytes32 requestId = apiConsumer.requestVolumeData(); - mockOracle.fulfillOracleRequest(requestId, bytes32(RESPONSE)); - assertTrue(apiConsumer.volume() == RESPONSE); - } -} From 5bcb5ffcc67da4154abb0245019e749b35040d96 Mon Sep 17 00:00:00 2001 From: Zubin Pratap Date: Tue, 20 Aug 2024 20:29:15 +1000 Subject: [PATCH 2/2] remove APIConsumer in src --- src/APIConsumer.sol | 81 --------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/APIConsumer.sol diff --git a/src/APIConsumer.sol b/src/APIConsumer.sol deleted file mode 100644 index b87dc5d..0000000 --- a/src/APIConsumer.sol +++ /dev/null @@ -1,81 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.7; - -import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; - -/** - * @title The APIConsumer contract - * @notice An API Consumer contract that makes GET requests to obtain 24h trading volume of ETH in USD - */ -contract APIConsumer is ChainlinkClient { - using Chainlink for Chainlink.Request; - - uint256 public volume; - address private immutable oracle; - bytes32 private immutable jobId; - uint256 private immutable fee; - - event DataFullfilled(uint256 volume); - - constructor(address _oracle, bytes32 _jobId, uint256 _fee, address _link) { - if (_link == address(0)) { - _setPublicChainlinkToken(); - } else { - _setChainlinkToken(_link); - } - oracle = _oracle; - jobId = _jobId; - fee = _fee; - } - - /** - * @notice Creates a Chainlink request to retrieve API response, find the target - * data, then multiply by 1000000000000000000 (to remove decimal places from data). - * - * @return requestId - id of the request - */ - function requestVolumeData() public returns (bytes32 requestId) { - Chainlink.Request memory request = _buildChainlinkRequest(jobId, address(this), this.fulfill.selector); - - // Set the URL to perform the GET request on - request._add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"); - - // Set the path to find the desired data in the API response, where the response format is: - // {"RAW": - // {"ETH": - // {"USD": - // { - // "VOLUME24HOUR": xxx.xxx, - // } - // } - // } - // } - // Chainlink node versions prior to 1.0.0 supported this format - // request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); - request._add("path", "RAW,ETH,USD,VOLUME24HOUR"); - - // Multiply the result by 1000000000000000000 to remove decimals - int256 timesAmount = 10 ** 18; - request._addInt("times", timesAmount); - - // Sends the request - return _sendChainlinkRequestTo(oracle, request, fee); - } - - /** - * @notice Receives the response in the form of uint256 - * - * @param _requestId - id of the request - * @param _volume - response; requested 24h trading volume of ETH in USD - */ - function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) { - volume = _volume; - emit DataFullfilled(_volume); - } - - /** - * @notice Witdraws LINK from the contract - * @dev Implement a withdraw function to avoid locking your LINK in the contract - */ - function withdrawLink() external {} -}