Skip to content

Commit

Permalink
Document the new CLI command (#151)
Browse files Browse the repository at this point in the history
* Add warning about taking advice

* Move the auditor tip below

* Move proxy deployment to outside of the contract integration page

* Add instructions for using the CLI command

* Review the OEV Rewards section
  • Loading branch information
bbenligiray authored Jan 17, 2025
1 parent 20e0a37 commit e670a97
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 38 deletions.
54 changes: 54 additions & 0 deletions docs/dapps/integration/api3readerproxyv1-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: Contract integration
pageHeader: dApps → Integration
outline: deep
---

<PageHeader/>

# Api3ReaderProxyV1 deployment

::: info 💡 Tip

If API3 representatives have provided you with [commands to print Api3ReaderProxyV1 addresses](/dapps/integration/contract-integration#printing-dapp-specific-api3readerproxyv1-addresses), your proxies should already be deployed and you do not need to follow this page.

:::

Api3ReaderProxyV1 is designed to be deployed by calling the `deployApi3ReaderProxyV1()` function of Api3ReaderProxyV1Factory.
Purchasing a plan for a data feed on API3 Market deploys a communal Api3ReaderProxyV1 for it automatically, whose address is displayed on the [integration page.](https://market.api3.org/blast/eth-usd/integrate)
Alternatively, [`data-feed-reader-example`](https://github.com/api3dao/data-feed-reader-example) provides [instructions](https://github.com/api3dao/data-feed-reader-example/blob/main/scripts/README.md#deploying-proxy-contracts-programmatically) for how (communal and dApp-specific) Api3ReaderProxyV1 contracts can be deployed programmatically.

::: info 💡 Tip

In short, if your dApp has a [dApp alias](/dapps/oev-rewards/dapp-alias) assigned, deploy your own Api3ReaderProxyV1 contracts by referring to the [instructions in `data-feed-reader-example`.](https://github.com/api3dao/data-feed-reader-example/blob/main/scripts/README.md#deploying-proxy-contracts-programmatically)
Otherwise, use the communal Api3ReaderProxyV1 addresses displayed on the integration pages of the respective data feeds.

With either option, we recommended you to validate the Api3ReaderProxyV1 addresses using [`@api3/contracts`.](/dapps/integration/api3-contracts.md)

:::

## Parameters

Deploying Api3ReaderProxyV1 by calling Api3ReaderProxyV1Factory requires three parameters:

- `dapiName` is the name of the data feed in `bytes32` string form.
For example, `dapiName` for the ETH/USD data feed is [`0x4554482f55534400000000000000000000000000000000000000000000000000`.](https://blastscan.io/address/0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473#readProxyContract#F4)
::: info ℹ️ Info

The term dAPI can be traced back to the [API3 whitepaper](https://github.com/api3dao/api3-whitepaper/blob/master/api3-whitepaper.pdf), and refers to a DAO-governed data feed that is built out of first-party oracles.
For the purposes of this page, you can think of the terms dAPI and data feed to be interchangeable.

:::

- `dappId` is a `uint256` that API3 has assigned to a specific dApp on a specific chain.
It is similar to a chain ID in function.
In Solidity, it can be derived as

```solidity
uint256(keccak256(abi.encodePacked(keccak256(abi.encodePacked(dappAliasAsString)), block.chainid)));
```

For the communal Api3ReaderProxyV1 deployments, `dappId` is [`1`.](https://blastscan.io/address/0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473#readProxyContract#F5)

- While deploying an Api3ReaderProxyV1, a `bytes`-type `metadata` is specified, whose hash is used as the CREATE2 salt.
It should be left [empty](https://blastscan.io/tx/0x0e98bc849985df6d5489396d66b766019c547fedfe3c3fb881276d7fb76ef26e#eventlog#17), i.e., as `0x`.
66 changes: 37 additions & 29 deletions docs/dapps/integration/contract-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ outline: deep
This page provides important information on how to integrate API3 data feeds to a contract.
Please read it in its entirety before attempting an integration.

::: info 💡 Tip
::: info ⚠️ Warning

Your auditors may not be familiar with the best practices in the context of API3 data feeds.
It is a good idea to direct them to this page.
API3 does not authorize any member or affiliate to provide security advice.
You are solely responsible for following the instructions on this page.

:::

Expand All @@ -25,47 +25,48 @@ For example, to read ETH/USD on Blast, one can simply call the `read()` function

The Api3ReaderProxyV1 addresses displayed on API3 Market are communal—they do not belong to a specific dApp.
Alternatively, an Api3ReaderProxyV1 can belong to a specific dApp, which is required for [OEV Rewards](/dapps/oev-rewards/) support.
There is no other functional difference between the two.

### Deployment
### Printing dApp-specific Api3ReaderProxyV1 addresses

Api3ReaderProxyV1 is designed to be deployed by calling the `deployApi3ReaderProxyV1()` function of Api3ReaderProxyV1Factory.
Purchasing a plan for a data feed on API3 Market deploys a communal Api3ReaderProxyV1 for it automatically, whose address is displayed on the [integration page.](https://market.api3.org/blast/eth-usd/integrate)
Alternatively, [`data-feed-reader-example`](https://github.com/api3dao/data-feed-reader-example) provides [instructions](https://github.com/api3dao/data-feed-reader-example/blob/main/scripts/README.md#deploying-proxy-contracts-programmatically) for how (communal and dApp-specific) Api3ReaderProxyV1 contracts can be deployed programmatically.
API3 representatives will assign your [dApp alias](/dapps/oev-rewards/dapp-alias.md), deploy your dApp-specific Api3ReaderProxyV1 contracts, and give you a list of commands that will print their addresses.
By running these commands yourself, you can ensure that you are using the correct addresses.

::: info 💡 Tip

In short, if your dApp has a [dApp alias](/dapps/oev-rewards/dapp-alias) assigned, deploy your own Api3ReaderProxyV1 contracts by referring to the [instructions in `data-feed-reader-example`.](https://github.com/api3dao/data-feed-reader-example/blob/main/scripts/README.md#deploying-proxy-contracts-programmatically)
Otherwise, use the communal Api3ReaderProxyV1 addresses displayed on the integration pages of the respective data feeds.

With either option, we recommended you to validate the Api3ReaderProxyV1 addresses using [`@api3/contracts`.](/dapps/integration/api3-contracts.md)
We try to verify our contracts on all block explorers with varying success due to their practical limitations.
Since Api3ReaderProxyV1 is deployed deterministically, it not being verified on a block explorer is not a security concern.

:::

#### Parameters
These commands should be in the following format, where the dApp alias, chain ID, and dAPI names match your case:

Deploying Api3ReaderProxyV1 by calling Api3ReaderProxyV1Factory requires three parameters:

- `dapiName` is the name of the data feed in `bytes32` string form.
For example, `dapiName` for the ETH/USD data feed is [`0x4554482f55534400000000000000000000000000000000000000000000000000`.](https://blastscan.io/address/0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473#readProxyContract#F4)
::: info ℹ️ Info
```sh
npx @api3/contracts@latest print-api3readerproxyv1-address \
--dapp-alias lendle \
--chain-id 5000 \
--dapi-name ETH/USD
```

The term dAPI can be traced back to the [API3 whitepaper](https://github.com/api3dao/api3-whitepaper/blob/master/api3-whitepaper.pdf), and refers to a DAO-governed data feed that is built out of first-party oracles.
For the purposes of this page, you can think of the terms dAPI and data feed to be interchangeable.
The command above prints:

:::
```
dApp alias: lendle
chain: Mantle
dAPI name: ETH/USD
• Please confirm that https://market.api3.org/mantle/eth-usd points to an active feed.
• Your proxy address is https://mantlescan.xyz/address/0x776E79D916e49BBDb8FEe0F43fF148C2Ed3bE125
Please confirm that there is a contract deployed at this address before using it.
```

- `dappId` is a `uint256` that API3 has assigned to a specific dApp on a specific chain.
It is similar to a chain ID in function.
In Solidity, it can be derived as
Note that if an API3 representative has provided you with this command, you can expect the Market page to point to an active feed and the proxy to be already deployed.
Do not proceed with the integration until you confirm these.

```solidity
uint256(keccak256(abi.encodePacked(keccak256(abi.encodePacked(dappAliasAsString)), block.chainid)));
```
::: info 💡 Tip

For the communal Api3ReaderProxyV1 deployments, `dappId` is [`1`.](https://blastscan.io/address/0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473#readProxyContract#F5)
If you are using the API3 Market in a self-serve manner and want to use dApp-specific Api3ReaderProxyV1 contracts, see the [Api3ReaderProxyV1 deployment guide](/dapps/integration/api3readerproxyv1-deployment).

- While deploying an Api3ReaderProxyV1, a `bytes`-type `metadata` is specified, whose hash is used as the CREATE2 salt.
It should be left [empty](https://blastscan.io/tx/0x0e98bc849985df6d5489396d66b766019c547fedfe3c3fb881276d7fb76ef26e#eventlog#17), i.e., as `0x`.
:::

### Reading the data feed

Expand Down Expand Up @@ -133,6 +134,13 @@ This should be avoided for two reasons:
In general, the only acceptable use of `timestamp` is validating if the heartbeat interval is upheld, as in `require(timestamp + 24 hours > block.timestamp)`.
However, unless your contract design specifically relies on the data feed value being at most a day old (which is unlikely), we do not necessarily recommend this either.

::: info 💡 Tip

Your auditors may not be familiar with the best practices in the context of API3 data feeds.
It is a good idea to direct them to this page.

:::

## Mixed oracle design

Some dApps choose to mix oracle solutions, either by refusing service if they are not in consensus, or by using one primarily and deferring to another in case of inconsistency.
Expand Down
10 changes: 2 additions & 8 deletions docs/dapps/oev-rewards/dapp-alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ You can see the current list of dApps with aliases [here.](https://github.com/ap

## Why do you need to be assigned a dApp alias?

While reading API3 data feeds, dApps must use the Api3ReaderProxyV1 contracts [deployed](/dapps/integration/contract-integration#deployment) with their own dApp alias.
While reading API3 data feeds, dApps must use the [Api3ReaderProxyV1 contracts](/dapps/integration/contract-integration#api3readerproxyv1) deployed with their own dApp alias to be eligible for OEV Rewards.

::: info ⚠️ Warning

Only the dApps that use Api3ReaderProxyV1 contracts deployed with their own dApp aliases are eligible for OEV Rewards.
dApps that use any

- communal Api3ReaderProxyV1 contracts (whose addresses are displayed on API3 Market)
- dApp-specific Api3ReaderProxyV1 contracts that are deployed with the alias of another dApp

are not eligible for OEV Rewards.
dApps that use any dApp-specific Api3ReaderProxyV1 contracts that are deployed with the alias of another dApp are not eligible for OEV Rewards.
They will not receive auction proceeds even if there has been any.

:::
Expand Down
8 changes: 7 additions & 1 deletion docs/dapps/oev-rewards/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ You can drop in API3 data feeds in place of your current data feeds, and immedia
## How to get onboard

1. Get assigned a [dApp alias.](/dapps/oev-rewards/dapp-alias)
2. [Deploy](/dapps/integration/contract-integration#deployment) Api3ReaderProxyV1 contracts with this dApp alias.
2. [Deploy](/dapps/integration/api3readerproxyv1-deployment) Api3ReaderProxyV1 contracts with this dApp alias.
3. [Integrate](/dapps/integration/contract-integration) the Api3ReaderProxyV1 contracts that you have deployed.

::: info 💡 Tip

You can use [this form](https://api3dao.typeform.com/to/FHhFIL41) to get in contact with an API3 representative who can handle the first two steps for you.

:::

At the end of each month, API3 will make available a report and 80% of the auction proceeds in the native gas token of the network on which your dApp is deployed, with the remainder of the auction proceeds retained as the OEV Network protocol fee.

::: info 💰 Financial
Expand Down
4 changes: 4 additions & 0 deletions docs/dapps/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = [
text: 'Contract integration',
link: '/dapps/integration/contract-integration',
},
{
text: 'Api3ReaderProxyV1 deployment',
link: '/dapps/integration/api3readerproxyv1-deployment',
},
{
text: 'AggregatorV2V3Interface',
link: '/dapps/integration/aggregatorv2v3interface',
Expand Down

0 comments on commit e670a97

Please sign in to comment.