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: pages/price-feeds/derive-cross-rate.mdx
+33-14Lines changed: 33 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,23 @@
1
-
import { Callout } from"nextra/components";
1
+
import { Callout, Tabs } from"nextra/components";
2
2
3
3
# Derive Cross Rate
4
4
5
5
This guide shows how to combine two price feeds to derive a cross rate. These are also known as "synthetic" price feeds.
6
6
Cross rates or Synthetic Price feeds are useful for trading pairs that are not directly supported by Pyth.
7
7
8
-
<Callouttype="info"emoji="ℹ️">
9
-
This guide is for developers who are building applications on **EVM
10
-
blockchains** using **solidity only**.
11
-
</Callout>
12
-
13
-
## Example
8
+
<Tabsitems={["EVM", "SVM"]}>
9
+
<Tabs.Tab>
10
+
### EVM
14
11
15
12
For example, if you want to trade the price of **`ETH/EUR{:jsx}`**, which is not directly supported by Pyth, you can combine the price of **`ETH/USD{:jsx}`** and **`EUR/USD{:jsx}`** to derive the price of **`ETH/EUR{:jsx}`**.
The Pyth Solidity SDKprovides[`deriveCrossRate`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/PythUtils.sol#L77) function to combine two price feeds.
20
+
The Pyth Solidity SDK provides[`deriveCrossRate`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/PythUtils.sol#L77) function to combine two price feeds.
24
21
This method is available in [Pyth solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ethereum/sdk/solidity).
25
22
26
23
This method takes the following parameters:
@@ -35,7 +32,7 @@ Returns:
35
32
36
33
-`crossRate`: The computed cross rate (a / c), scaled to targetExponent.
37
34
38
-
## Example
35
+
###Example
39
36
40
37
```solidity copy
41
38
pragma solidity ^0.8.0;
@@ -81,21 +78,43 @@ contract ExampleCrossRate {
81
78
82
79
```
83
80
84
-
### ⚠️ Things to Keep in Mind
81
+
####⚠️ Things to Keep in Mind
85
82
86
83
- The function reverts if either price is **negative**, or if any exponent is **less than -255**.
87
84
- The result is rounded down. If the result is smaller than 1 in the given `targetExponent{:jsx}`, it will return 0.
88
85
- Confidence intervals are not derived in this function. If needed, you have to derive them manually.
89
86
- Reverts with `PythErrors.ExponentOverflow{:jsx}` if `targetExponent + expo1 - expo2{:jsx}` is outside the range **[-58, 58]**.
90
87
91
-
## Additional Resources
88
+
###Additional Resources
92
89
93
90
You may find these additional resources helpful.
94
91
95
-
### How to use real-time data in EVM contracts
92
+
####How to use real-time data in EVM contracts
96
93
97
94
The [How to use real-time data in EVM contracts](./use-real-time-data/evm) guide provides a step-by-step guide on how to use real-time data in EVM contracts.
98
95
99
-
### Price Feed IDs
96
+
####Price Feed IDs
100
97
101
98
The [Price Feed IDs](./price-feeds.mdx) page lists the price feed IDs for each asset supported by Pyth.
99
+
100
+
</Tabs.Tab>
101
+
102
+
<Tabs.Tab>
103
+
### SVM
104
+
105
+
The Pyth Rust SDK provides [`get_price_in_quote`](https://github.com/pyth-network/pyth-sdk-rs/blob/d6598dcf8b556cd97bb597661cdc012398371be1/pyth-sdk/src/price.rs#L90) function to combine two price feeds.
106
+
This method is available in [Pyth Rust SDK](https://github.com/pyth-network/pyth-sdk-rs/tree/main/pyth-sdk).
0 commit comments