You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-26Lines changed: 49 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,52 +148,75 @@ Below are some common scenarios illustrating how you can combine these proxies:
148
148
149
149
**Scenario 1: Inverting and Scaling a dAPI**
150
150
151
-
Imagine your dApp requires a USD/ETH price feed with 8 decimal places, but the available API3 dAPI provides ETH/USD with 18 decimals.
151
+
Imagine your dApp requires a USD/ETH price feed with 8 decimal places, but the available Api3 dAPI provides ETH/USD with 18 decimals.
152
152
153
153
1. **Deploy `InverseApi3ReaderProxyV1`**:
154
154
155
155
- Input `PROXY`: Address of the ETH/USD `IApi3ReaderProxy` dAPI.
156
-
- Output: An `IApi3ReaderProxy` contract (`InverseProxy_ETHUSD`) that reads USD/ETH.
156
+
- Output: An `IApi3ReaderProxy` contract. This deployed instance of `InverseApi3ReaderProxyV1` reads USD/ETH.
157
157
- Example command: `NETWORK=your_network PROXY=0xAddressOfEthUsdDapi pnpm deploy:InverseApi3ReaderProxyV1`
158
158
159
159
2. **Deploy `ScaledApi3FeedProxyV1`**:
160
-
- Input `PROXY`: Address of `InverseProxy_ETHUSD` (from step 1).
160
+
161
+
- Input `PROXY`: Address of the `InverseApi3ReaderProxyV1` instance deployed in step 1.
161
162
- Input `DECIMALS`: `8`.
162
-
- Output: An `AggregatorV2V3Interface` contract that reads USD/ETH scaled to 8 decimals.
163
-
- Example command: `NETWORK=your_network PROXY=0xAddressOfInverseProxyEthUsd DECIMALS=8 pnpm deploy:ScaledApi3FeedProxyV1`
163
+
- Output: An `AggregatorV2V3Interface` contract. This deployed instance of `ScaledApi3FeedProxyV1` reads USD/ETH scaled to 8 decimals.
164
+
- Example command: `NETWORK=your_network PROXY=0xAddressOfDeployedInverseApi3ReaderProxyV1FromStep1 DECIMALS=8 pnpm deploy:ScaledApi3FeedProxyV1`
165
+
_Note: Replace `0xAddressOfDeployedInverseApi3ReaderProxyV1FromStep1` with the actual address obtained from the deployment artifact of step 1._
164
166
165
-
**Scenario 2: Creating a Cross-Currency Pair (e.g., BTC/ETH) and Adapting its Interface**
167
+
This pipeline successfully provides the dApp with the required USD/ETH feed at the desired precision and interface.
166
168
167
-
Suppose your dApp needs a BTC/ETH price feed, and you have access to BTC/USD and ETH/USD dAPIs. You also want the final feed to be Chainlink-compatible.
169
+
**Scenario 2: Deriving a Real-World Feed (stETH/USD) by Combining Custom On-Chain Data with an Api3 dAPI**
168
170
169
-
1. **Deploy `InverseApi3ReaderProxyV1` for ETH/USD**:
171
+
Suppose your dApp needs an `stETH/USD` price feed. This specific feed might not be directly available, but you can construct it using:
170
172
171
-
- Input `PROXY`: Address of the ETH/USD `IApi3ReaderProxy` dAPI.
172
-
- Output: An `IApi3ReaderProxy` contract (`InverseProxy_ETHUSD`) that reads USD/ETH.
173
+
1. The `stETH/wstETH` exchange rate, obtainable directly from the `wstETH` smart contract (e.g., via its `stEthPerToken()` function).
174
+
2. An existing Api3 dAPI for `wstETH/USD`
173
175
174
-
2. **Deploy `ProductApi3ReaderProxyV1`**:
176
+
To achieve this, you would:
175
177
176
-
- Input `PROXY1`: Address of the BTC/USD `IApi3ReaderProxy` dAPI.
177
-
- Input `PROXY2`: Address of `InverseProxy_ETHUSD` (from step 1).
178
-
- Output: An `IApi3ReaderProxy` contract (`ProductProxy_BTCETH`) that reads BTC/ETH (calculated as BTC/USD \* USD/ETH).
178
+
1. **Create and Deploy a Custom `IApi3ReaderProxy` for `stETH/wstETH`**:
179
179
180
-
3. **Deploy `ScaledApi3FeedProxyV1` (Optional, for interface adaptation and scaling)**:
181
-
- Input `PROXY`: Address of `ProductProxy_BTCETH` (from step 2).
182
-
- Input `DECIMALS`: Desired decimals (e.g., `8` or `18`).
183
-
- Output: An `AggregatorV2V3Interface` contract providing the BTC/ETH price, compatible with systems expecting a Chainlink feed.
180
+
- Since the `wstETH` contract's `stEthPerToken()`functiondoesn't directly implement the `IApi3ReaderProxy` interface, you'd first deploy a simple wrapper contract. This wrapper (let's call it `WstETHApi3ReaderProxyV1`) would call `stEthPerToken()` and expose the result (`stETH` amount for 1 `wstETH` with 18 decimals) and the current block timestamp via the `read()` method of `IApi3ReaderProxy`.
181
+
_Note: An example of such a deployed custom proxy is `WstETHApi3ReaderProxyV1` at `0x3EA363B8CE16A26BFF70484883587DcF7E53C27d` on Ethereum mainnet. The development of this custom wrapper is outside the scope of the data-feed-proxy-combinators repository but illustrates how any data source can be adapted to be `IApi3ReaderProxy` compatible._
184
182
185
-
**Scenario 3: Normalizing an External Feed and Then Inverting It**
183
+
2. **Deploy `ProductApi3ReaderProxyV1` to calculate `stETH/USD`**:
186
184
187
-
Your dApp wants to use an external (e.g., Chainlink) EUR/USD feed but requires it as USD/EUR and prefers to interact with it via the API3 `IApi3ReaderProxy` interface.
185
+
- This step multiplies the `stETH/wstETH` rate (from your custom proxy) by the `wstETH/USD` rate (from the Api3 dAPI).
186
+
- Input `PROXY1`: Address of `WstETHApi3ReaderProxyV1` (e.g., `0x3EA363B8CE16A26BFF70484883587DcF7E53C27d` on Ethereum mainnet).
187
+
- Input `PROXY2`: Address of the Api3 `wstETH/USD` dAPI proxy (e.g., `0x37422cC8e1487a0452cc0D0BF75877d86c63c88A` on Ethereum mainnet).
188
+
- Output: An `IApi3ReaderProxy` contract. This deployed instance of `ProductApi3ReaderProxyV1` (e.g., the one at `0xeC4031539b851eEc918b41FE3e03d7236fEc7be8` on Ethereum mainnet) reads `stETH/USD`.
- Example command: `NETWORK=ethereum-mainnet PROXY1=0x3EA363B8CE16A26BFF70484883587DcF7E53C27d PROXY2=0x37422cC8e1487a0452cc0D0BF75877d86c63c88A pnpm deploy:ProductApi3ReaderProxyV1`
188
191
189
-
1. **Deploy `NormalizedApi3ReaderProxyV1`**:
192
+
This scenario effectively demonstrates how `ProductApi3ReaderProxyV1` can be used with a mix of standard Api3 dAPIs and custom `IApi3ReaderProxy`-compatible sources, including those that bring on-chain calculations into the combinator ecosystem.
193
+
194
+
**Scenario 3: Normalizing an External Feed and Combining it with an Api3 dAPI**
190
195
191
-
- Input `FEED`: Address of the external EUR/USD `AggregatorV2V3Interface` feed.
192
-
- Output: An `IApi3ReaderProxy` contract (`NormalizedProxy_EURUSD`) that reads EUR/USD.
196
+
Suppose your dApp needs a price fora less common asset, like "UnsupportedStakedETH" (uStETH),in terms of USD (uStETH/USD). This specific feed (uStETH/USD) might not be directly available as an Api3 dAPI, but you have access to:
197
+
198
+
1. An Api3 dAPI for ETH/USD.
199
+
2. An external, Chainlink-compatible feed for uStETH/ETH (e.g., from a DEX or a specialized provider). This uStETH/ETH feed is not listed on the Api3 market, perhaps due to specific listing requirements or its niche nature.
200
+
201
+
To derive the desired uStETH/USD feed and make it compatible with the Api3 ecosystem, you can combine these feeds:
202
+
203
+
1. **Deploy `NormalizedApi3ReaderProxyV1`**:
193
204
194
-
2. **Deploy `InverseApi3ReaderProxyV1`**:
195
-
- Input `PROXY`: Address of `NormalizedProxy_EURUSD` (from step 1).
196
-
- Output: An `IApi3ReaderProxy` contract that reads USD/EUR.
205
+
- This step adapts the external uStETH/ETH feed, which implements the `AggregatorV2V3Interface`, to the `IApi3ReaderProxy` interface. A key functionof`NormalizedApi3ReaderProxyV1` is to read the `decimals()` from the external feed and automatically scale its value to the 18 decimal places expected by the `IApi3ReaderProxy` interface. For instance, if the uStETH/ETH feed returns its value with a different precision (e.g., 8 or 36 decimals), this proxy will normalize it.
206
+
- Input `FEED`: Address of the external uStETH/ETH `AggregatorV2V3Interface` feed.
207
+
- Output: An `IApi3ReaderProxy` contract. This deployed instance of `NormalizedApi3ReaderProxyV1` reads uStETH/ETH, with its value normalized to 18 decimals.
208
+
- Example command: `NETWORK=your_network FEED=0xAddressOfExternal_uStETH_ETH_Feed pnpm deploy:NormalizedApi3ReaderProxyV1`
209
+
210
+
2. **Deploy `ProductApi3ReaderProxyV1` to calculate uStETH/USD**:
211
+
- This step multiplies the normalized uStETH/ETH rate by the ETH/USD rate from the Api3 dAPI.
212
+
- Input `PROXY1`: Address of the `NormalizedApi3ReaderProxyV1` instance deployed in step 1.
213
+
- Input `PROXY2`: Address of the existing ETH/USD `IApi3ReaderProxy` dAPI.
214
+
- Output: An `IApi3ReaderProxy` contract. This deployed instance of `ProductApi3ReaderProxyV1` reads uStETH/USD.
- Example command: `NETWORK=your_network PROXY1=0xAddressOfDeployedNormalizedApi3ReaderProxyV1FromStep1 PROXY2=0xAddressOfApi3EthUsdDapi pnpm deploy:ProductApi3ReaderProxyV1`
217
+
_(Note: Replace `0xAddressOfDeployedNormalizedApi3ReaderProxyV1FromStep1` with the actual address obtained from the deployment artifact of step 1)._
218
+
219
+
This scenario highlights how `NormalizedApi3ReaderProxyV1` serves as a crucial bridge, enabling dApps to integrate valuable data from external sources (that may not meet Api3 dAPI listing criteria or are simply outside the current offerings) and combine it with trusted Api3 dAPIs using the standard set of combinator tools.
197
220
198
221
When deploying a combinator that depends on another already deployed combinator, you will need the address of the prerequisite contract. You can find this address in the deployment artifact file (e.g., `deployments/<network_name>/<ContractName>_SomeHash.json`) generated in the previous step.
0 commit comments