From 86773f195dfb7d15d982d69c6f90c699e3de3b03 Mon Sep 17 00:00:00 2001 From: Sukanya Parashar Date: Wed, 14 Aug 2024 15:41:14 +0530 Subject: [PATCH 1/2] Add API3 data feeds integration documentation (#171) * Add API3 page to the sidebar * Add API3 integration page --- .../integrate/oracles/integrating_api3.md | 196 ++++++++++++++++++ sidebars.js | 5 +- 2 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 docs/developing/integrate/oracles/integrating_api3.md diff --git a/docs/developing/integrate/oracles/integrating_api3.md b/docs/developing/integrate/oracles/integrating_api3.md new file mode 100644 index 00000000..551046ea --- /dev/null +++ b/docs/developing/integrate/oracles/integrating_api3.md @@ -0,0 +1,196 @@ +--- +title: API3 +proofedDate: 20240717 +iterationBy: na +includedInSite: false +approvedBy: na +comment: +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import mm_p_key from '@site/static/img/doc-images/developing/deploy_facilities/foundry-metamask.png'; + +## Introduction + +API3 dAPIs (decentralized APIs) offer a state-of-the-art solution for connecting off-chain data sources with on-chain applications. They use first-party oracles managed directly by API providers, ensuring reliable and continuously updated data feeds. These oracles provide cryptographically signed data, which is then aggregated on-chain into a secure and tamper-proof data feed known as a beacon set. + +Developers can easily integrate dAPIs into their decentralized applications (dApps), enabling real-time access to off-chain data, such as price feeds, without requiring extensive technical implementation. The integration process is simplified through a proxy address that represents the dAPI requester, facilitating the interaction between the dApp and the data feed. API3 has made it straightforward for dApp owners to read on-chain values from these beacons, enhancing the functionality and reliability of their applications. + +Each API3 data feed is available via its own proxy contract. To use a feed, you create a "hybrid" smart contract, i.e. you build the integration with the feed proxy contract into your own smart contract and deploy that. Learn more from [API3's documentation](https://docs.api3.org/explore/dapis/what-are-dapis.html), or examine the [boilerplate provided](#boilerplate-contract). + +## Deployed feeds + +:::important +Activation of API3 price feeds is permissionless and anyone can activate the price feeds with a transaction on Neon EVM Mainnet and Devnet. +::: + +The proxy contract addresses of the price feeds are available both on Neon EVM Mainnet and Devnet. + + + + + +| Currency pair | API3 proxy contract feed address | +| :-----------: | :----------------------------------------: | +| USDT/USD | 0xF00249f594f11c3F98F2D73433274D10098906B6 | + + + + + +| Currency pair | API3 proxy contract feed address | +| :-----------: | :----------------------------------------: | +| BTC/USD | 0x81A64473D102b38eDcf35A7675654768D11d7e24 | +| ETH/USD | 0xa47Fd122b11CdD7aad7c3e8B740FB91D83Ce43D1 | +| SOL/USD | 0xCa81409D8dF6d34a21d93B5c0EF79557Bc5fb4be | +| USDC/USD | 0xa790a882bB695D0286C391C0935a05c347290bdB | +| USDT/USD | 0xF00249f594f11c3F98F2D73433274D10098906B6 | +| NEON/USD | 0x383CC331Cd5669b7B6460a24b1B45cD9220B28a8 | +| LINK/USD | 0xB102ec41347F26E8493B8C98cA1c10b69903Dc57 | + + + + + +## Boilerplate contract + +[View GitHub example](https://github.com/neonlabsorg/neon-tutorials/blob/main/hardhat/contracts/TestAPI3/TestAPI3.sol) + +``` +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import "@api3/contracts/api3-server-v1/proxies/interfaces/IProxy.sol"; + +contract TestAPI3 { + // Use your proxy address as the argument + function readDataFeed(address proxy) public view returns (int224 value, uint32 timestamp) { + (value, timestamp) = IProxy(proxy).read(); + // If you have any assumptions about `value` and `timestamp`, make sure + // to validate them right after reading from the proxy. For example, + // if the value you are reading is the spot price of an asset, you may + // want to reject non-positive values... + require(value > 0, "Value not positive"); + // ...and if the data feed is being updated with a one day-heartbeat + // interval, you may want to check for that. + require( + timestamp + 1 days > block.timestamp, + "Timestamp older than one day" + ); + } +} +``` + +## How to integrate with the API3 contract + +:::important +Before trying out the tutorial in the next steps, please make sure that the price feeds are activated for **[Neon EVM Mainnet](https://market.api3.org/neon-evm)** and **[Neon EVM Devnet](https://market.api3.org/neon-evm-testnet)**. +::: + +The example this tutorial is based on is located in [this repository](https://github.com/neonlabsorg/neon-tutorials/tree/main/hardhat). + +By the end of this tutorial, you will deploy a contract which reads API3 price feeds. + +### Step 1: Installation + +> **Note:** This page is just a quickstart based on a specific example program. For more details on installing Hardhat, refer to the _[Hardhat documentation](https://hardhat.org/hardhat-runner/docs/getting-started#overview)_. + +Using Git, clone the example Hardhat project from the remote repository and navigate to it: + +```sh +git clone https://github.com/neonlabsorg/neon-tutorials +cd neon-tutorials/hardhat +``` + +Then, run the following command: + +```sh +npm install +``` + +This will install all the necessary packages to continue with the example. These packages include the `Hardhat` library. + +If the above command results in an error, run: + +```sh +npm cache clear --force +npm install +``` + +### Step 2: Set Up MetaMask Accounts + +:::info +This step requires an EVM-compatible wallet such as MetaMask, connected to Neon Devnet, with a balance in Devnet NEON available from [NeonFaucet](https://neonfaucet.org/). + +The following tutorials assist you to meet these prerequisites: + +- Learn how to [install a MetaMask wallet and connect it to Devnet](/docs/wallet/metamask_setup) + + > Or [connect an existing wallet to Devnet](/docs/developing/connect_rpc#connect-via-chainlist) + > ::: + + 2.1 Obtain the private key for your wallet account. + +> To obtain the private key from MetaMask, from the hamburger menu, click **Account Details** > **Show Private Key**, enter your password, and click **Confirm** for access to the private key for that account. +> + +2.2 Create a .env file and add these lines: + +``` +PRIVATE_KEY_OWNER=`YOUR_PRIVATE_KEY` +``` + +:::important +Replace `YOUR_PRIVATE_KEY` with your data. +::: + +### Step 3: Compile Contracts + +All of the contracts are located in the project's `contracts/` directory. Before these contracts can be run, they must first be compiled. To compile the project's contracts, run the following command: + +```sh +npx hardhat compile +``` + +After running this step, you should see output similar to the following: + +``` +Compiled 23 Solidity files successfully +``` + +### Step 4: Deploy Contract + +`NEON_CONFIG` contains the proxy price feed addresses on Neon EVM Mainnet and Devnet for reading API3 price feeds. + +To deploy the project's hybrid contract, simply run the command below to run the deployment script in the `scripts/` directory: + +```sh +npx hardhat run scripts/TestAPI3/deploy.js --network neondevnet +``` + +The output should look like: + +``` +TestAPI3 deployed to 0xB8747279e8029108720BcB5386511D70B9129D68 +BTC_USD Result(2) [ 64547812100000000000000n, 1721241637n ] +ETH_USD Result(2) [ 3431460000000000000000n, 1721274476n ] +SOL_USD Result(2) [ 159776804400000000000n, 1721284955n ] +USDC_USD Result(2) [ 999900024820969500n, 1721220644n ] +USDT_USD Result(2) [ 1000188700000000000n, 1721220738n ] +NEON_USD Result(2) [ 392570000000000000n, 1721270758n ] +LINK_USD Result(2) [ 13807707000000000000n, 1721291017n ] +``` + +> The result represents an array with the following parameters: +> +> - 1st parameter - Price +> - 2nd parameter - Timestamp of the last price push + +:::info +To deploy on Neon EVM Mainnet, change `--network neondevnet` to `--network neonmainnet` in the command line. +::: + +:::important +If a dApp wants to recapture OEV (https://api3.org/oev/), they can contact us, and API3 will assist them in obtaining a unique proxy for their dApp. You can join their [Discord](https://discord.com/invite/qnRrcfnm5W) and reach out to the API3 team in the OEV section. +::: diff --git a/sidebars.js b/sidebars.js index 5c90a34e..04130249 100644 --- a/sidebars.js +++ b/sidebars.js @@ -60,9 +60,7 @@ const sidebars = { { type: 'category', label: 'Dev Recommendations', - items: [ - 'developing/dev_recommendations/global_variables' - ] + items: ['developing/dev_recommendations/global_variables'] }, { type: 'category', @@ -82,6 +80,7 @@ const sidebars = { 'developing/integrate/wallets/integrating_web3auth', 'developing/integrate/oracles/integrating_chainlink', 'developing/integrate/oracles/integrating_pyth', + 'developing/integrate/oracles/integrating_api3', 'developing/integrate/middleware/the-graph', 'developing/integrate/indexer/flair', 'developing/integrate/indexer/envio', From bfb968c8e95d8f5f26b5ee0aa9c9a3ef6e7eb45a Mon Sep 17 00:00:00 2001 From: Sukanya Parashar Date: Wed, 14 Aug 2024 15:41:45 +0530 Subject: [PATCH 2/2] Add WHALE token to the Mainnet token list (#169) * Add whale token to the ERC-20 token list * Fix typo in transfer-spl-token page --- docs/composability/using_composability/transfer_spl_token.md | 2 +- docs/tokens/token_list.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/composability/using_composability/transfer_spl_token.md b/docs/composability/using_composability/transfer_spl_token.md index 041c64ee..9bb84858 100644 --- a/docs/composability/using_composability/transfer_spl_token.md +++ b/docs/composability/using_composability/transfer_spl_token.md @@ -378,7 +378,7 @@ Result(3) [ rentEpoch: 18446744073709552000, space: 165 } getAccountInfo SenderAccount -Minting SPLTokens to SenderAccount and transfering them to ReceiverAccount ... +Minting SPLTokens to SenderAccount and transferring them to ReceiverAccount ... Executing batchExecuteComposabilityMethod ... ContractTransactionResponse { provider: HardhatEthersProvider { diff --git a/docs/tokens/token_list.md b/docs/tokens/token_list.md index 74061ba0..4f58c2d9 100644 --- a/docs/tokens/token_list.md +++ b/docs/tokens/token_list.md @@ -55,6 +55,7 @@ The following tables provide the addresses of ERC-20 interface contracts for the | | $WIF | `0xF86934c2b05c31f3bBE3BCd6E3a8aA7790cAd9c1` | `EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm` | | | WEN | `0xc61e8aB62666D25F0854C5723587507A7E92E289` | `WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk` | | | POPCAT | `0xb89c62e960457d1d2c5f20135bedfd215d2466de` | `7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr` | +| | WHALE | `0x663572b924db12e0e3822c6160df29154630c8e3` | `9uhHjyfc5tKdaZnjstLLKoLGcF889ub8zX9wtwhtzgK6` |