Skip to content

Commit c67b0b5

Browse files
committed
feat(dev-hub) Pyth Core pages Part 3
1 parent 6f83f1f commit c67b0b5

36 files changed

+3199
-88
lines changed

apps/developer-hub/content/docs/price-feeds/core/create-tradingview-charts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: How to Create TradingView Charts
2+
title: Create TradingView Charts
33
description: Learn how to build TradingView charts powered by Pyth price feeds
44
slug: /price-feeds/core/create-tradingview-charts
55
---

apps/developer-hub/content/docs/price-feeds/core/derive-cross-rate.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ import { Tab, Tabs } from "fumadocs-ui/components/tabs";
99
This guide shows how to combine two price feeds to derive a cross rate. These are also known as "synthetic" price feeds.
1010
Cross rates or Synthetic Price feeds are useful for trading pairs that are not directly supported by Pyth.
1111

12-
<Tabs items={["EVM", "SVM"]}>
13-
<Tab value="EVM">
14-
### EVM
15-
1612
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}`**.
1713

18-
$$
14+
```math
1915
\large{\text{ETH/EUR} = \text{ETH/USD} \div \text{EUR/USD}}
20-
$$
16+
```
2117

18+
<Tabs items={["EVM", "SVM"]}>
19+
<Tab value="EVM">
2220
### Derive a cross rate
2321

2422
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.

apps/developer-hub/content/docs/price-feeds/core/fetch-price-updates.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: How To Fetch Price Updates
2+
title: Fetch Price Updates
33
description: Learn how to retrieve Pyth price updates via REST, streaming, and SDK
44
slug: /price-feeds/core/fetch-price-updates
55
---

apps/developer-hub/content/docs/price-feeds/core/meta.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
"create-your-first-pyth-app",
66
"---How-To Guides---",
77
"use-real-time-data",
8-
"[Use Historic Price Data](./core/use-historic-price-data)",
9-
"[Fetch Price Updates](./core/fetch-price-updates)",
10-
"[Schedule Price Updates](./core/schedule-price-updates)",
11-
"[Create TradingView Charts](./core/create-tradingview-charts)",
12-
"[Derive Cross Rate](./core/derive-cross-rate)",
13-
"[Migrate an App to Pyth](./core/migrate-an-app-to-pyth)",
14-
"[Use Pyth for Morpho Markets](./core/use-pyth-for-morpho)",
15-
"[Publish Data](./core/publish-data)",
16-
"[Troubleshoot Errors](./core/troubleshoot)",
8+
"use-historic-price-data",
9+
"fetch-price-updates",
10+
"schedule-price-updates",
11+
"create-tradingview-charts",
12+
"derive-cross-rate",
13+
"migrate-an-app-to-pyth",
14+
"use-pyth-for-morpho",
15+
"publish-data",
16+
"troubleshoot",
1717
"---Reference Material---",
18-
"[API Reference](./core/api-reference)",
19-
"[Price Feeds](./core/price-feeds)",
20-
"[Current Fees](./core/current-fees)",
21-
"[Push Feeds](./core/push-updates)",
22-
"[Market Hours](./core/market-hours)",
23-
"[Best Practices](./core/best-practices)",
24-
"[Rate Limits](./core/rate-limits)",
25-
"[Error Codes](./core/error-codes)",
26-
"[API Instances and Providers](./api-instances-and-providers)",
27-
"[Contract Addresses](./contract-addresses)",
28-
"[Pythnet Reference](./core/pythnet-reference)",
18+
"api-reference",
19+
"price-feeds",
20+
"current-fees",
21+
"push-updates",
22+
"market-hours",
23+
"best-practices",
24+
"rate-limits",
25+
"error-codes",
26+
"api-instances-and-providers",
27+
"contract-addresses",
28+
"pythnet-reference",
2929
"[Example Applications \u2197](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds)",
3030
"---Understanding Pyth---",
31-
"[What is a Pull Oracle?](./core/pull-updates)",
32-
"[Why Update Prices](./core/why-update-prices)",
33-
"[How Pyth Works](./core/how-pyth-works)"
31+
"pull-updates",
32+
"why-update-prices",
33+
"how-pyth-works"
3434
]
3535
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: From Chainlink
3+
description: Switch Chainlink AggregatorV3 feeds to Pyth price feeds in EVM applications
4+
slug: /price-feeds/core/migrate-an-app-to-pyth/chainlink
5+
---
6+
7+
This guide explains how to migrate an EVM application that uses Chainlink price feeds to Pyth price feeds.
8+
Pyth provides a Chainlink-compatible interface for its price feeds to make this process simple.
9+
There are two main steps to the migration:
10+
11+
1. Deploy the [`PythAggregatorV3`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/PythAggregatorV3.sol) contract to provide a Chainlink-compatible feed interface.
12+
2. Schedule price updates for the feeds required by your app.
13+
14+
## Install Pyth SDKs
15+
16+
The `PythAggregatorV3` contract is provided in the [Pyth Price Feeds Solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ethereum/sdk/solidity).
17+
Add this SDK to the dependencies of your EVM contract.
18+
19+
**Truffle/Hardhat**
20+
21+
If you are using Truffle or Hardhat, simply install the NPM package:
22+
23+
```bash copy
24+
npm install @pythnetwork/pyth-sdk-solidity
25+
```
26+
27+
**Foundry**
28+
29+
If you are using Foundry, you will need to create an NPM project if you don't already have one.
30+
From the root directory of your project, run:
31+
32+
```bash copy
33+
npm init -y
34+
npm install @pythnetwork/pyth-sdk-solidity
35+
```
36+
37+
Then add the following line to your `remappings.txt` file:
38+
39+
```text copy
40+
@pythnetwork/pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity
41+
```
42+
43+
## Deploy Adapter Contract
44+
45+
First, deploy the `PythAggregatorV3` contract from `@pythnetwork/pyth-sdk-solidity` as a replacement for your application's Chainlink price feeds.
46+
`PythAggregatorV3` is an adapter contract that wraps the Pyth contract and implements Chainlink's `AggregatorV3Interface`.
47+
48+
One important difference between Pyth and Chainlink is that the Pyth contract holds data for all price feeds; in contrast, Chainlink has separate instances of `AggregatorV3Interface` for each feed.
49+
The adapter contract resolves this discrepancy by wrapping a single Pyth price feed.
50+
Users should deploy an instance of this adapter for every required price feed, then point their existing app to the addresses of the deployed adapter contracts.
51+
52+
The following `forge` deployment script demonstrates the expected deployment process:
53+
54+
```solidity copy
55+
// SPDX-License-Identifier: Apache 2
56+
pragma solidity ^0.8.0;
57+
58+
import "forge-std/Script.sol";
59+
import { PythAggregatorV3 } from "@pythnetwork/pyth-sdk-solidity/PythAggregatorV3.sol";
60+
import { ChainlinkApp } from "./ChainlinkApp.sol";
61+
62+
contract PythAggregatorV3Deployment is Script {
63+
function run() external {
64+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
65+
vm.startBroadcast(deployerPrivateKey);
66+
67+
// Get the address for your ecosystem from:
68+
// https://docs.pyth.network/price-feeds/core/contract-addresses/evm
69+
address pythPriceFeedsContract = 0xff1a0f4744e8582DF1aE09D5611b887B6a12925C;
70+
// Get the price feed ids from:
71+
// https://docs.pyth.network/price-feeds/core/price-feeds
72+
bytes32 ethFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
73+
bytes32 solFeedId = 0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d;
74+
75+
// Deploy an instance of PythAggregatorV3 for every feed.
76+
PythAggregatorV3 ethAggregator = new PythAggregatorV3(
77+
pythPriceFeedsContract,
78+
ethFeedId
79+
);
80+
PythAggregatorV3 solAggregator = new PythAggregatorV3(
81+
pythPriceFeedsContract,
82+
solFeedId
83+
);
84+
85+
// Pass the address of the PythAggregatorV3 contract to your chainlink-compatible app.
86+
ChainlinkApp app = new ChainlinkApp(
87+
address(ethAggregator),
88+
address(solAggregator)
89+
);
90+
91+
vm.stopBroadcast();
92+
}
93+
}
94+
95+
```
96+
97+
Please see the [Chainlink Migration Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/evm/chainlink_migration) for a runnable version of the example above.
98+
99+
## Schedule Updates
100+
101+
Chainlink-compatible applications typically expect on-chain price feeds to update on a schedule.
102+
When migrating to Pyth, apps may need to schedule these price updates themselves.
103+
This step is required because Pyth is a pull oracle; see [What is a pull oracle?](/price-feeds/core/pull-updates.mdx) to learn more about this topic.
104+
105+
The [Push Feeds](/price-feeds/core/push-feeds.mdx) page shows a list of feeds that have scheduled on-chain updates.
106+
If the feeds your application needs are not on this list, see [Schedule Price Updates](/price-feeds/core/schedule-price-updates) for several options to solve this problem.

apps/developer-hub/content/docs/price-feeds/core/migrate-an-app-to-pyth/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Migrate to Pyth from Another Oracle
2+
title: Migrate to Pyth
33
description: Resources to help move existing oracle integrations onto Pyth price feeds
44
slug: /price-feeds/core/migrate-an-app-to-pyth
55
---
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"pages": ["[from Chainlink](./chainlink)"]
2+
"pages": ["chainlink"]
33
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Confidence Interval and Crypto Exchange Fees
3+
description: Learn how to calculate the confidence interval and crypto exchange fees
4+
slug: /price-feeds/core/publish-data/confidence-interval-and-crypto-exchange-fees
5+
---
6+
7+
It is very important that publishers consider crypto exchange aggressive fees when calculating their price and confidence intervals from one or more exchange order books. Ask prices should be moved up by the best publicly available aggressive fee rate, and bid prices should be moved down by the same rate.
8+
9+
```sh copy
10+
ask_adjusted = ask * (1.0 + fee_rate)
11+
bid_adjusted = bid * (1.0 - fee_rate)
12+
```
13+
14+
This is to reflect the "after fee" effective prices that could be gotten on that exchange. This is important for crypto markets because the fees are often MUCH larger than the typical bid-ask spread. It is not important for other markets (such as US equities) where fees are small compared with the bid-ask spread. The rationale for this adjustment is that the "fair price" could be above the best ask or below the best bid by as much as the aggressive fees before an informed trader would be able to profitably trade on this exchange and move the best price. Because of that, the best price on the exchange could be "wrong" by as much as +/- the aggressive fees.
15+
16+
Example 1 - Exchange A has best aggressive fee of 10bps
17+
18+
![](/images/Confidence_Interval_and_Crypto_Exchange_Fees_Table_1.png)
19+
20+
Exchange A should publish a price of \$50,000.01 and a confidence of \$50.005 (half the bid-ask spread after fee adjustment). It would be wrong to publish a confidence of \$0.005 based on the "not fee-adjusted" raw exchange bid-ask spread.
21+
22+
Example 2 - Exchange A has a best aggressive fee of 10bps. Exchange B has a best aggressive fee of 1bps, and a publisher is combining them into a single combined book. Exchange books are combined by taking the best ask across both exchanges and the best bid across both exchanges.
23+
24+
![](/images/Confidence_Interval_and_Crypto_Exchange_Fees_Table_2.png)
25+
26+
In this example, if a publisher were combining the books of Exchange A and Exchange B to get a combined price, they should publish a price of \$49,978.13 and confidence of \$28.125, which corresponds to the midprice and half the bid-ask spread of the combined fee-adjusted books. It would be wrong to publish a price of \$50,000.01 and confidence of \$0.01 based on the "not fee-adjusted" raw exchange prices. Note that in this example, not only is the confidence changed by including the exchange fees, but the price reported is also substantially different once fees are properly accounted for.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Publish Data
3+
description: Learn how to publish data to the Pyth Network
4+
slug: /price-feeds/core/publish-data
5+
---
6+
7+
import { Step, Steps } from "fumadocs-ui/components/steps";
8+
9+
Data providers can get started publishing data to the Pyth Network by performing the following steps.
10+
11+
<Steps>
12+
<Step>
13+
## Request access
14+
15+
First, contact the Pyth Data Association and request to become a data provider.
16+
You can reach out on [Discord](https://discord.gg/Ff2XDydUhu) or [Telegram](https://t.me/Pyth_Network).
17+
**Only data providers with first-party data (exchanges, market makers, and trading firms) are allowed to participate in the network.**
18+
19+
</Step>
20+
<Step>
21+
## Generate keypair
22+
23+
Every data provider is identified on the network by a public key, and their prices are signed by the corresponding private key.
24+
You will need a Solana public/private key pair for this purpose.
25+
If you do not already have a keypair, you can create one using the instructions below:
26+
27+
```sh copy
28+
# Install the Solana Tool Suite, needed for creating the key used to sign your transactions.
29+
# See https://docs.solana.com/cli/install-solana-cli-tools for the latest version
30+
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
31+
32+
# Generate a public/private keypair.
33+
solana-keygen new --no-bip39-passphrase --outfile publish_key_pair.json
34+
```
35+
36+
This command will create a public/private keypair in `publish_key_pair.json`.
37+
Please extract the public key from this file and share it with the Pyth Data Association so they can enable you to publish prices.
38+
39+
```sh copy
40+
# Print the public key of the keypair.
41+
solana-keygen pubkey publish_key_pair.json
42+
```
43+
44+
This command will output the public key in base58 encoding and will look something like:
45+
46+
```sh copy
47+
5rYvdyWAunZgD2EC1aKo7hQbutUUnkt7bBFM6xNq2z7Z
48+
```
49+
50+
Most data providers choose to generate two separate keypairs, one for testing and one for production.
51+
If you do so, please share both public keys with the Pyth Data Association.
52+
53+
</Step>
54+
<Step>
55+
## Procure validators
56+
57+
Every data provider to the network will require both a Solana RPC node and a Pythnet validator.
58+
The Pyth Data Association will assist you with this step.
59+
60+
</Step>
61+
<Step>
62+
## pyth-agent
63+
64+
Data providers can publish data to the network using the [pyth-agent](https://github.com/pyth-network/pyth-agent) software package.
65+
This package abstracts away all of the communication with the underlying blockchain and exposes a simple JSON RPC interface for submitting price data.
66+
Please see the [README](https://github.com/pyth-network/pyth-agent) of that package for instructions on using it.
67+
This software requires you to configure both the keypair and validators from the previous steps in order to run.
68+
Please also see the [JSON RPC API documentation](publish-data/pyth-client-websocket-api.md).
69+
Finally, the [example publisher](https://github.com/pyth-network/example-publisher) is a fully-worked example of how to integrate with the pyth-agent API.
70+
71+
</Step>
72+
</Steps>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"pages": [
3-
"[Understanding Publishing Slots](./understanding-publishing-slots)",
4-
"[pyth-client Websocket API](./pyth-client-websocket-api)",
5-
"[Confidence Interval and Crypto Exchange Fees](./confidence-interval-and-crypto-exchange-fees)",
6-
"[Useful Resources for Publishers](./useful-resources-for-publishers)"
3+
"understanding-publishing-slots",
4+
"pyth-client-websocket-api",
5+
"confidence-interval-and-crypto-exchange-fees",
6+
"useful-resources-for-publishers"
77
]
88
}

0 commit comments

Comments
 (0)