Skip to content

Commit 1dd467a

Browse files
committed
chore(derive-cross-rate)-add-svm
1 parent 7cc7ef2 commit 1dd467a

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

pages/price-feeds/derive-cross-rate.mdx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
import { Callout } from "nextra/components";
1+
import { Callout, Tabs } from "nextra/components";
22

33
# Derive Cross Rate
44

55
This guide shows how to combine two price feeds to derive a cross rate. These are also known as "synthetic" price feeds.
66
Cross rates or Synthetic Price feeds are useful for trading pairs that are not directly supported by Pyth.
77

8-
<Callout type="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+
<Tabs items={["EVM", "SVM"]}>
9+
<Tabs.Tab>
10+
### EVM
1411

1512
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}`**.
1613

1714
$$
1815
\large{\text{ETH/EUR} = \text{ETH/USD} \div \text{EUR/USD}}
1916
$$
2017

21-
## Derive a cross rate
18+
### Derive a cross rate
2219

23-
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.
2421
This method is available in [Pyth solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ethereum/sdk/solidity).
2522

2623
This method takes the following parameters:
@@ -35,7 +32,7 @@ Returns:
3532

3633
- `crossRate`: The computed cross rate (a / c), scaled to targetExponent.
3734

38-
## Example
35+
### Example
3936

4037
```solidity copy
4138
pragma solidity ^0.8.0;
@@ -81,21 +78,43 @@ contract ExampleCrossRate {
8178
8279
```
8380

84-
### ⚠️ Things to Keep in Mind
81+
#### ⚠️ Things to Keep in Mind
8582

8683
- The function reverts if either price is **negative**, or if any exponent is **less than -255**.
8784
- The result is rounded down. If the result is smaller than 1 in the given `targetExponent{:jsx}`, it will return 0.
8885
- Confidence intervals are not derived in this function. If needed, you have to derive them manually.
8986
- Reverts with `PythErrors.ExponentOverflow{:jsx}` if `targetExponent + expo1 - expo2{:jsx}` is outside the range **[-58, 58]**.
9087

91-
## Additional Resources
88+
### Additional Resources
9289

9390
You may find these additional resources helpful.
9491

95-
### How to use real-time data in EVM contracts
92+
#### How to use real-time data in EVM contracts
9693

9794
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.
9895

99-
### Price Feed IDs
96+
#### Price Feed IDs
10097

10198
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).
107+
108+
### Example
109+
110+
```rust copy
111+
let btc_usd: Price = ...;
112+
let eth_usd: Price = ...;
113+
// -8 is the desired exponent for the result
114+
let btc_eth: Price = btc_usd.get_price_in_quote(&eth_usd, -8);
115+
println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);
116+
```
117+
118+
</Tabs.Tab>
119+
120+
</Tabs>

0 commit comments

Comments
 (0)