fix broken links (#945)
* fix broken links * undo import order changes * Fix more links * Fix more broken links * Fix more broken links * Fix more broken links * Fix precommit --------- Co-authored-by: Thomaz Leite <thomaz@pyth.network> Co-authored-by: Guillermo Bescos <g.bescos@yahoo.com>
This commit is contained in:
parent
2a4045504d
commit
8752291aa2
|
@ -8,7 +8,7 @@ Pyth is a cross-chain oracle that streams price updates over the peer-to-peer [W
|
|||
These price updates can be consumed on any chain that has a deployment of the Pyth contract.
|
||||
By default, Pyth does not automatically update the on-chain price every time the off-chain price changes;
|
||||
instead, anyone can permissionlessly update the on-chain price prior to using it.
|
||||
For more information please refer to [this document](https://docs.pyth.network/design-overview).
|
||||
For more information please refer to [this document](https://docs.pyth.network/documentation/how-pyth-works).
|
||||
|
||||
Protocols integrating with can update the on-chain Pyth prices in two different ways.
|
||||
The first approach is on-demand updates: package a Pyth price update together with each transaction that depends on it.
|
||||
|
|
|
@ -27,35 +27,35 @@ export default {
|
|||
"pyth-package-id": {
|
||||
description:
|
||||
"Pyth Package Id. Can be found here" +
|
||||
"https://docs.pyth.network/pythnet-price-feeds/sui",
|
||||
"https://docs.pyth.network/documentation/pythnet-price-feeds/sui",
|
||||
type: "string",
|
||||
required: true,
|
||||
} as Options,
|
||||
"pyth-state-id": {
|
||||
description:
|
||||
"Pyth State Id. Can be found here" +
|
||||
"https://docs.pyth.network/pythnet-price-feeds/sui",
|
||||
"https://docs.pyth.network/documentation/pythnet-price-feeds/sui",
|
||||
type: "string",
|
||||
required: true,
|
||||
} as Options,
|
||||
"wormhole-package-id": {
|
||||
description:
|
||||
"Wormhole Package Id. Can be found here" +
|
||||
"https://docs.pyth.network/pythnet-price-feeds/sui",
|
||||
"https://docs.pyth.network/documentation/pythnet-price-feeds/sui",
|
||||
type: "string",
|
||||
required: true,
|
||||
} as Options,
|
||||
"wormhole-state-id": {
|
||||
description:
|
||||
"Wormhole State Id. Can be found here" +
|
||||
"https://docs.pyth.network/pythnet-price-feeds/sui",
|
||||
"https://docs.pyth.network/documentation/pythnet-price-feeds/sui",
|
||||
type: "string",
|
||||
required: true,
|
||||
} as Options,
|
||||
"price-feed-to-price-info-object-table-id": {
|
||||
description:
|
||||
"This is the id of the table which stored the information related to price data. You can find it here: " +
|
||||
"https://docs.pyth.network/pythnet-price-feeds/sui",
|
||||
"https://docs.pyth.network/documentation/pythnet-price-feeds/sui",
|
||||
type: "string",
|
||||
required: true,
|
||||
} as Options,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
The Pyth JavaScript SDK provides definitions and utilities for Pyth data structures.
|
||||
|
||||
Please see the [pyth.network documentation](https://docs.pyth.network/) for more information on how to use Pyth prices in various blockchains.
|
||||
Please see the [pyth.network documentation](https://docs.pyth.network/documentation/) for more information on how to use Pyth prices in various blockchains.
|
||||
|
||||
## Releases
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ wormhole = "_"
|
|||
|
||||
[dev-addresses]
|
||||
# Note that these are localnet addresses, for use in testing. The contracts are deployed to the real networks at the
|
||||
# addresses documented at https://docs.pyth.network/consume-data/aptos#addresses
|
||||
# addresses documented at https://docs.pyth.network/documentation/pythnet-price-feeds/aptos#addresses
|
||||
pyth = "0x377f0d7c4aaeea8dd73a7a2c6bc817e59aea569e1f9ae0d2f4a80ea1be93bf01"
|
||||
deployer = "0x277fa055b6a73c42c0662d5236c65c864ccbf2d4abd21f174a30c8b786eab84b"
|
||||
wormhole = "0xde0036a9600559e295d5f6802ef6f3f802f510366e0c23912b0655d972166017"
|
||||
|
|
|
@ -7,7 +7,7 @@ module pyth::price {
|
|||
/// Both the price and confidence are stored in a fixed-point numeric representation,
|
||||
/// `x * (10^expo)`, where `expo` is the exponent.
|
||||
//
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
|
||||
/// to how this price safely.
|
||||
struct Price has copy, drop, store {
|
||||
price: I64,
|
||||
|
|
|
@ -128,7 +128,7 @@ module pyth::pyth {
|
|||
// Update the cached prices
|
||||
//
|
||||
// Pyth uses an uses an on-demand update model, where consumers need to update the
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand.
|
||||
|
||||
/// Update the cached price feeds with the data in the given VAAs. This is a
|
||||
/// convenience wrapper around update_price_feeds(), which allows you to update the price feeds
|
||||
|
@ -143,7 +143,7 @@ module pyth::pyth {
|
|||
/// to perform this update can be queried with get_update_fee(&vaas). The signer must have sufficient
|
||||
/// account balance to pay this fee, otherwise the transaction will abort.
|
||||
///
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees
|
||||
public entry fun update_price_feeds_with_funder(account: &signer, vaas: vector<vector<u8>>) {
|
||||
let coins = coin::withdraw<AptosCoin>(account, get_update_fee(&vaas));
|
||||
update_price_feeds(vaas, coins);
|
||||
|
@ -154,12 +154,12 @@ module pyth::pyth {
|
|||
///
|
||||
/// The javascript https://github.com/pyth-network/pyth-js/tree/main/pyth-aptos-js package
|
||||
/// should be used to fetch these VAAs from the Price Service. More information about this
|
||||
/// process can be found at https://docs.pyth.network/consume-data.
|
||||
/// process can be found at https://docs.pyth.network/documentation/pythnet-price-feeds.
|
||||
///
|
||||
/// The given fee must contain a sufficient number of coins to pay the update fee for the given vaas.
|
||||
/// The update fee amount can be queried by calling get_update_fee(&vaas).
|
||||
///
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees
|
||||
public fun update_price_feeds(vaas: vector<vector<u8>>, fee: Coin<AptosCoin>) {
|
||||
// Charge the message update fee
|
||||
assert!(get_update_fee(&vaas) <= coin::value(&fee), error::insufficient_fee());
|
||||
|
@ -395,11 +395,11 @@ module pyth::pyth {
|
|||
/// Get the latest available price cached for the given price identifier, if that price is
|
||||
/// no older than the stale price threshold.
|
||||
///
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for
|
||||
/// how to how this price safely.
|
||||
///
|
||||
/// Important: Pyth uses an on-demand update model, where consumers need to update the
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand.
|
||||
/// get_price() is likely to abort unless you call update_price_feeds() to update the cached price
|
||||
/// beforehand, as the cached prices may be older than the stale price threshold.
|
||||
///
|
||||
|
@ -455,7 +455,7 @@ module pyth::pyth {
|
|||
/// price identifier, if that price is no older than the stale price threshold.
|
||||
///
|
||||
/// Important: Pyth uses an on-demand update model, where consumers need to update the
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand.
|
||||
/// get_ema_price() is likely to abort unless you call update_price_feeds() to update the cached price
|
||||
/// beforehand, as the cached prices may be older than the stale price threshold.
|
||||
public fun get_ema_price(price_identifier: PriceIdentifier): Price {
|
||||
|
@ -486,7 +486,7 @@ module pyth::pyth {
|
|||
|
||||
/// Get the number of AptosCoin's required to perform the given price updates.
|
||||
///
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees
|
||||
public fun get_update_fee(update_data: &vector<vector<u8>>): u64 {
|
||||
let i = 0;
|
||||
let total_updates = 0;
|
||||
|
|
|
@ -9,7 +9,7 @@ Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "
|
|||
[addresses]
|
||||
example = "0xac74082dfffb80824955aaefb2b0a98634b1368e37f42cbff14564ea430b97dc"
|
||||
# On deployment, these should be overridden with --named-addresses using the addresses
|
||||
# documented at https://docs.pyth.network/consume-data/aptos#addresses
|
||||
# documented at https://docs.pyth.network/documentation/pythnet-price-feeds/aptos#addresses
|
||||
pyth = "_"
|
||||
deployer = "_"
|
||||
wormhole = "_"
|
||||
|
|
|
@ -9,7 +9,7 @@ module example::example {
|
|||
///
|
||||
/// https://github.com/pyth-network/pyth-js/tree/main/pyth-aptos-js should be used to
|
||||
/// fetch the pyth_update_data off-chain and pass it in. More information about how this
|
||||
/// works can be found at https://docs.pyth.network/consume-data
|
||||
/// works can be found at https://docs.pyth.network/documentation/pythnet-price-feeds/aptos
|
||||
public fun get_btc_usd_price(user: &signer, pyth_update_data: vector<vector<u8>>): Price {
|
||||
|
||||
// First update the Pyth price feeds
|
||||
|
|
|
@ -9,7 +9,7 @@ AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "a
|
|||
Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "aptos/contracts", rev = "main" }
|
||||
|
||||
[addresses]
|
||||
# These are testnet addresses https://docs.pyth.network/consume-data/aptos#addresses
|
||||
# These are testnet addresses https://docs.pyth.network/documentation/pythnet-price-feeds/aptos#addresses
|
||||
aptos_framework = "0x1"
|
||||
mint_nft = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"
|
||||
pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import React from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
import { Price, PriceFeed } from "@pythnetwork/pyth-common-js";
|
||||
import { AptosPriceServiceConnection } from "@pythnetwork/pyth-aptos-js";
|
||||
import { Price, PriceFeed } from "@pythnetwork/pyth-common-js";
|
||||
import React from "react";
|
||||
import "./App.css";
|
||||
import logo from "./logo.svg";
|
||||
|
||||
// Please read https://docs.pyth.network/consume-data before building on Pyth
|
||||
// Please read https://docs.pyth.network/documentation/pythnet-price-feeds before building on Pyth
|
||||
|
||||
// Rpc endpoint
|
||||
const TESTNET_PRICE_SERVICE = "https://xc-testnet.pyth.network";
|
||||
|
@ -18,7 +18,7 @@ const testnetConnection = new AptosPriceServiceConnection(
|
|||
const APT_USD_TESTNET_PRICE_ID =
|
||||
"0x44a93dddd8effa54ea51076c4e851b6cbbfd938e82eb90197de38fe8876bb66e";
|
||||
|
||||
// Aptos modules : These are testnet addresses https://docs.pyth.network/consume-data/aptos#addresses
|
||||
// Aptos modules : These are testnet addresses https://docs.pyth.network/documentation/pythnet-price-feeds/aptos
|
||||
const MINT_NFT_MODULE =
|
||||
"0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7";
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ module mint_nft::minting {
|
|||
coin::transfer<aptos_coin::AptosCoin>(receiver, @mint_nft, price_in_aptos_coin); // Pay for the NFT
|
||||
}
|
||||
|
||||
/// Please read https://docs.pyth.network/consume-data/best-practices before using a `Price` in your application
|
||||
/// Please read https://docs.pyth.network/documentation/pythnet-price-feeds before using a `Price` in your application
|
||||
fun update_and_fetch_price(receiver : &signer, vaas : vector<vector<u8>>) : Price {
|
||||
let coins = coin::withdraw<aptos_coin::AptosCoin>(receiver, pyth::get_update_fee(&vaas)); // Get coins to pay for the update
|
||||
pyth::update_price_feeds(vaas, coins); // Update price feed with the provided vaas
|
||||
|
|
|
@ -19,7 +19,7 @@ $ yarn add @pythnetwork/pyth-aptos-js
|
|||
## Quickstart
|
||||
|
||||
Pyth stores prices off-chain to minimize gas fees, which allows us to offer a wider selection of products and faster update times.
|
||||
See [On-Demand Updates](https://docs.pyth.network/consume-data/on-demand) for more information about this approach.
|
||||
See [On-Demand Updates](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand) for more information about this approach.
|
||||
To use Pyth prices on chain,
|
||||
they must be fetched from an off-chain price service. The `AptosPriceServiceConnection` class can be used to interact with these services,
|
||||
providing a way to fetch these prices directly in your code. The following example wraps an existing RPC provider and shows how to obtain
|
||||
|
@ -79,7 +79,7 @@ module example::your_module {
|
|||
}
|
||||
```
|
||||
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/consume-data/best-practices).
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices).
|
||||
|
||||
### Off-chain prices
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@
|
|||
"type": "string"
|
||||
},
|
||||
"Price": {
|
||||
"description": "A price with a degree of uncertainty at a certain time, represented as a price +- a confidence interval.\n\nPlease refer to the documentation at https://docs.pyth.network/consumers/best-practices for using this price safely.\n\nThe confidence interval roughly corresponds to the standard error of a normal distribution. Both the price and confidence are stored in a fixed-point numeric representation, `x * 10^expo`, where `expo` is the exponent. For example:\n\n``` use pyth_sdk::Price; Price { price: 12345, conf: 267, expo: -2, publish_time: 100 }; // represents 123.45 +- 2.67 published at UnixTimestamp 100 Price { price: 123, conf: 1, expo: 2, publish_time: 100 }; // represents 12300 +- 100 published at UnixTimestamp 100 ```\n\n`Price` supports a limited set of mathematical operations. All of these operations will propagate any uncertainty in the arguments into the result. However, the uncertainty in the result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to computational limitations. Furthermore, all of these operations may return `None` if their result cannot be represented within the numeric representation (e.g., the exponent is so small that the price does not fit into an i64). Users of these methods should (1) select their exponents to avoid this problem, and (2) handle the `None` case gracefully.",
|
||||
"description": "A price with a degree of uncertainty at a certain time, represented as a price +- a confidence interval.\n\nPlease refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for using this price safely.\n\nThe confidence interval roughly corresponds to the standard error of a normal distribution. Both the price and confidence are stored in a fixed-point numeric representation, `x * 10^expo`, where `expo` is the exponent. For example:\n\n``` use pyth_sdk::Price; Price { price: 12345, conf: 267, expo: -2, publish_time: 100 }; // represents 123.45 +- 2.67 published at UnixTimestamp 100 Price { price: 123, conf: 1, expo: 2, publish_time: 100 }; // represents 12300 +- 100 published at UnixTimestamp 100 ```\n\n`Price` supports a limited set of mathematical operations. All of these operations will propagate any uncertainty in the arguments into the result. However, the uncertainty in the result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to computational limitations. Furthermore, all of these operations may return `None` if their result cannot be represented within the numeric representation (e.g., the exponent is so small that the price does not fit into an i64). Users of these methods should (1) select their exponents to avoid this problem, and (2) handle the `None` case gracefully.",
|
||||
"type": "object",
|
||||
"required": ["conf", "expo", "price", "publish_time"],
|
||||
"properties": {
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"Price": {
|
||||
"description": "A price with a degree of uncertainty at a certain time, represented as a price +- a confidence interval.\n\nPlease refer to the documentation at https://docs.pyth.network/consumers/best-practices for using this price safely.\n\nThe confidence interval roughly corresponds to the standard error of a normal distribution. Both the price and confidence are stored in a fixed-point numeric representation, `x * 10^expo`, where `expo` is the exponent. For example:\n\n``` use pyth_sdk::Price; Price { price: 12345, conf: 267, expo: -2, publish_time: 100 }; // represents 123.45 +- 2.67 published at UnixTimestamp 100 Price { price: 123, conf: 1, expo: 2, publish_time: 100 }; // represents 12300 +- 100 published at UnixTimestamp 100 ```\n\n`Price` supports a limited set of mathematical operations. All of these operations will propagate any uncertainty in the arguments into the result. However, the uncertainty in the result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to computational limitations. Furthermore, all of these operations may return `None` if their result cannot be represented within the numeric representation (e.g., the exponent is so small that the price does not fit into an i64). Users of these methods should (1) select their exponents to avoid this problem, and (2) handle the `None` case gracefully.",
|
||||
"description": "A price with a degree of uncertainty at a certain time, represented as a price +- a confidence interval.\n\nPlease refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for using this price safely.\n\nThe confidence interval roughly corresponds to the standard error of a normal distribution. Both the price and confidence are stored in a fixed-point numeric representation, `x * 10^expo`, where `expo` is the exponent. For example:\n\n``` use pyth_sdk::Price; Price { price: 12345, conf: 267, expo: -2, publish_time: 100 }; // represents 123.45 +- 2.67 published at UnixTimestamp 100 Price { price: 123, conf: 1, expo: 2, publish_time: 100 }; // represents 12300 +- 100 published at UnixTimestamp 100 ```\n\n`Price` supports a limited set of mathematical operations. All of these operations will propagate any uncertainty in the arguments into the result. However, the uncertainty in the result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to computational limitations. Furthermore, all of these operations may return `None` if their result cannot be represented within the numeric representation (e.g., the exponent is so small that the price does not fit into an i64). Users of these methods should (1) select their exponents to avoid this problem, and (2) handle the `None` case gracefully.",
|
||||
"type": "object",
|
||||
"required": ["conf", "expo", "price", "publish_time"],
|
||||
"properties": {
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
use std::time::Duration;
|
||||
|
||||
#[cfg(not(feature = "library"))]
|
||||
use cosmwasm_std::entry_point;
|
||||
use cosmwasm_std::{
|
||||
to_binary,
|
||||
Binary,
|
||||
Deps,
|
||||
DepsMut,
|
||||
Env,
|
||||
MessageInfo,
|
||||
Response,
|
||||
StdError,
|
||||
StdResult,
|
||||
Coin,
|
||||
};
|
||||
|
||||
use pyth_sdk_cw::{
|
||||
PriceFeedResponse,
|
||||
get_update_fee,
|
||||
get_valid_time_period,
|
||||
query_price_feed,
|
||||
};
|
||||
|
||||
use crate::msg::{
|
||||
ExecuteMsg,
|
||||
FetchPriceResponse,
|
||||
InstantiateMsg,
|
||||
MigrateMsg,
|
||||
QueryMsg,
|
||||
};
|
||||
use crate::state::{
|
||||
State,
|
||||
STATE,
|
||||
use {
|
||||
crate::{
|
||||
msg::{
|
||||
ExecuteMsg,
|
||||
FetchPriceResponse,
|
||||
InstantiateMsg,
|
||||
MigrateMsg,
|
||||
QueryMsg,
|
||||
},
|
||||
state::{
|
||||
State,
|
||||
STATE,
|
||||
},
|
||||
},
|
||||
cosmwasm_std::{
|
||||
to_binary,
|
||||
Binary,
|
||||
Coin,
|
||||
Deps,
|
||||
DepsMut,
|
||||
Env,
|
||||
MessageInfo,
|
||||
Response,
|
||||
StdError,
|
||||
StdResult,
|
||||
},
|
||||
pyth_sdk_cw::{
|
||||
get_update_fee,
|
||||
get_valid_time_period,
|
||||
query_price_feed,
|
||||
PriceFeedResponse,
|
||||
},
|
||||
std::time::Duration,
|
||||
};
|
||||
|
||||
#[cfg_attr(not(feature = "library"), entry_point)]
|
||||
|
@ -90,7 +91,8 @@ fn query_fetch_price(deps: Deps, env: Env) -> StdResult<FetchPriceResponse> {
|
|||
// price feed. The result is a PriceFeed object with fields for the current price and other
|
||||
// useful information. The function will fail if the contract address or price feed id are
|
||||
// invalid.
|
||||
let price_feed_response: PriceFeedResponse = query_price_feed(&deps.querier, state.pyth_contract_addr, state.price_feed_id)?;
|
||||
let price_feed_response: PriceFeedResponse =
|
||||
query_price_feed(&deps.querier, state.pyth_contract_addr, state.price_feed_id)?;
|
||||
let price_feed = price_feed_response.price_feed;
|
||||
|
||||
// Get the current price and confidence interval from the price feed.
|
||||
|
@ -99,7 +101,7 @@ fn query_fetch_price(deps: Deps, env: Env) -> StdResult<FetchPriceResponse> {
|
|||
// specific times, or network outages may prevent the price feed from updating.
|
||||
//
|
||||
// The example code below throws an error if the price is not available. It is recommended that
|
||||
// you handle this scenario more carefully. Consult the [consumer best practices](https://docs.pyth.network/consumers/best-practices)
|
||||
// you handle this scenario more carefully. Consult the [consumer best practices](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices)
|
||||
// for recommendations.
|
||||
let current_price = price_feed
|
||||
.get_price_no_older_than(env.block.time.seconds() as i64, 60)
|
||||
|
@ -131,37 +133,41 @@ fn query_fetch_valid_time_period(deps: Deps) -> StdResult<Duration> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use cosmwasm_std::testing::{
|
||||
mock_dependencies,
|
||||
mock_env,
|
||||
MockApi,
|
||||
MockQuerier,
|
||||
MockStorage,
|
||||
use {
|
||||
super::*,
|
||||
cosmwasm_std::{
|
||||
from_binary,
|
||||
testing::{
|
||||
mock_dependencies,
|
||||
mock_env,
|
||||
MockApi,
|
||||
MockQuerier,
|
||||
MockStorage,
|
||||
},
|
||||
Addr,
|
||||
Coin,
|
||||
OwnedDeps,
|
||||
QuerierResult,
|
||||
SystemError,
|
||||
SystemResult,
|
||||
Timestamp,
|
||||
WasmQuery,
|
||||
},
|
||||
pyth_sdk_cw::{
|
||||
testing::MockPyth,
|
||||
Price,
|
||||
PriceFeed,
|
||||
PriceIdentifier,
|
||||
UnixTimestamp,
|
||||
},
|
||||
std::{
|
||||
convert::TryFrom,
|
||||
time::Duration,
|
||||
},
|
||||
};
|
||||
use cosmwasm_std::{
|
||||
from_binary,
|
||||
Addr,
|
||||
Coin,
|
||||
OwnedDeps,
|
||||
QuerierResult,
|
||||
SystemError,
|
||||
SystemResult,
|
||||
Timestamp,
|
||||
WasmQuery,
|
||||
};
|
||||
use pyth_sdk_cw::testing::MockPyth;
|
||||
use pyth_sdk_cw::{
|
||||
Price,
|
||||
PriceFeed,
|
||||
PriceIdentifier,
|
||||
UnixTimestamp,
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
use std::time::Duration;
|
||||
|
||||
// Dummy contract address for testing.
|
||||
// For real deployments, see list of contract addresses here https://docs.pyth.network/pythnet-price-feeds/cosmwasm
|
||||
// For real deployments, see list of contract addresses here https://docs.pyth.network/documentation/pythnet-price-feeds/cosmwasm
|
||||
const PYTH_CONTRACT_ADDR: &str = "pyth_contract_addr";
|
||||
// For real deployments, see list of price feed ids here https://pyth.network/developers/price-feed-ids
|
||||
const PRICE_ID: &str = "63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3";
|
||||
|
@ -261,8 +267,8 @@ mod test {
|
|||
let (deps, env) = setup_test(&default_state(), &mock_pyth, current_unix_time);
|
||||
|
||||
let msg = QueryMsg::FetchValidTimePeriod {};
|
||||
let result = query(deps.as_ref(), env, msg)
|
||||
.and_then(|binary| from_binary::<Duration>(&binary));
|
||||
let result =
|
||||
query(deps.as_ref(), env, msg).and_then(|binary| from_binary::<Duration>(&binary));
|
||||
|
||||
assert_eq!(result.map(|r| r.as_secs()), Ok(60));
|
||||
}
|
||||
|
@ -275,9 +281,10 @@ mod test {
|
|||
let mock_pyth = MockPyth::new(Duration::from_secs(60), Coin::new(1, "foo"), &[]);
|
||||
let (deps, env) = setup_test(&default_state(), &mock_pyth, current_unix_time);
|
||||
|
||||
let msg = QueryMsg::FetchUpdateFee { vaas: vec![Binary(vec![1,2,3])] };
|
||||
let result = query(deps.as_ref(), env, msg)
|
||||
.and_then(|binary| from_binary::<Coin>(&binary));
|
||||
assert_eq!(result.map( |r| r.to_string()), Ok(String::from("1foo")))
|
||||
let msg = QueryMsg::FetchUpdateFee {
|
||||
vaas: vec![Binary(vec![1, 2, 3])],
|
||||
};
|
||||
let result = query(deps.as_ref(), env, msg).and_then(|binary| from_binary::<Coin>(&binary));
|
||||
assert_eq!(result.map(|r| r.to_string()), Ok(String::from("1foo")))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ const tx = await wallet.createAndSignTx({
|
|||
});
|
||||
```
|
||||
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/consume-data/best-practices).
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices).
|
||||
|
||||
### Examples
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ The oracle AMM manages a pool of two tokens and allows a user to trade with the
|
|||
This application has two components. The first component is a smart contract (in the `contract` directory) that manages the pool and implements the trading functionality.
|
||||
The second is a frontend application (in the `app` directory) that communicates with the smart contract.
|
||||
|
||||
Please see the [Pyth documentation](https://docs.pyth.network/pythnet-price-feeds) for more information about Pyth and how to integrate it into your application.
|
||||
Please see the [Pyth documentation](https://docs.pyth.network/documentation/pythnet-price-feeds) for more information about Pyth and how to integrate it into your application.
|
||||
|
||||
**Warning** this AMM is intended only as a demonstration of Pyth price feeds and is **not for production use**.
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# (e.g., this deploys to goerli optimism testnet)
|
||||
RPC_URL=https://endpoints.omniatech.io/v1/matic/mumbai/public
|
||||
|
||||
# The address of the Pyth contract on your network. See the list of contract addresses here https://docs.pyth.network/pythnet-price-feeds/evm
|
||||
# The address of the Pyth contract on your network. See the list of contract addresses here https://docs.pyth.network/documentation/pythnet-price-feeds/evm
|
||||
PYTH_CONTRACT_ADDRESS="0xff1a0f4744e8582DF1aE09D5611b887B6a12925C"
|
||||
# The Pyth price feed ids of the base and quote tokens. The list of ids is available here https://pyth.network/developers/price-feed-ids
|
||||
# Note that each feed has different ids on mainnet and testnet.
|
||||
|
|
|
@ -19,7 +19,7 @@ $ yarn add @pythnetwork/pyth-evm-js
|
|||
## Quickstart
|
||||
|
||||
Pyth stores prices off-chain to minimize gas fees, which allows us to offer a wider selection of products and faster update times.
|
||||
See [On-Demand Updates](https://docs.pyth.network/consume-data/on-demand) for more information about this approach. In order to use Pyth prices on chain,
|
||||
See [On-Demand Updates](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand) for more information about this approach. In order to use Pyth prices on chain,
|
||||
they must be fetched from an off-chain price service. The `EvmPriceServiceConnection` class can be used to interact with these services,
|
||||
providing a way to fetch these prices directly in your code. The following example wraps an existing RPC provider and shows how to obtain
|
||||
Pyth prices and submit them to the network:
|
||||
|
@ -41,7 +41,7 @@ const priceIds = [
|
|||
const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIds);
|
||||
|
||||
// If the user is paying the price update fee, you need to fetch it from the Pyth contract.
|
||||
// Please refer to https://docs.pyth.network/consume-data/on-demand#fees for more information.
|
||||
// Please refer to https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees for more information.
|
||||
//
|
||||
// `pythContract` below is a web3.js contract; if you wish to use ethers, you need to change it accordingly.
|
||||
// You can find the Pyth interface ABI in @pythnetwork/pyth-sdk-solidity npm package.
|
||||
|
@ -87,7 +87,7 @@ contract SomeContract {
|
|||
|
||||
```
|
||||
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/consume-data/best-practices).
|
||||
We strongly recommend reading our guide which explains [how to work with Pyth price feeds](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices).
|
||||
|
||||
### Off-chain prices
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import "./PythStructs.sol";
|
|||
import "./IPythEvents.sol";
|
||||
|
||||
/// @title Consume prices from the Pyth Network (https://pyth.network/).
|
||||
/// @dev Please refer to the guidance at https://docs.pyth.network/consumers/best-practices for how to consume prices safely.
|
||||
/// @dev Please refer to the guidance at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how to consume prices safely.
|
||||
/// @author Pyth Data Association
|
||||
interface IPyth is IPythEvents {
|
||||
/// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time
|
||||
|
|
|
@ -8,7 +8,7 @@ contract PythStructs {
|
|||
// Both the price and confidence are stored in a fixed-point numeric representation,
|
||||
// `x * (10^expo)`, where `expo` is the exponent.
|
||||
//
|
||||
// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
|
||||
// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
|
||||
// to how this price safely.
|
||||
struct Price {
|
||||
// Price
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This package provides utilities for consuming prices from the [Pyth Network](https://pyth.network/) Oracle using Solidity. Also, it contains [the Pyth Interface ABI](./abis/IPyth.json) that you can use in your libraries
|
||||
to communicate with the Pyth contract.
|
||||
|
||||
It is **strongly recommended** to follow the [consumer best practices](https://docs.pyth.network/consumers/best-practices) when consuming Pyth data.
|
||||
It is **strongly recommended** to follow the [consumer best practices](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices) when consuming Pyth data.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -56,11 +56,11 @@ Pyth prices are published on Solana, and relayed to EVM chains using the [Wormho
|
|||
|
||||
This signed message can then be submitted to the Pyth contract on the EVM networks along the required update fee for it, which will verify the Wormhole message and update the Pyth contract with the new price.
|
||||
|
||||
Please refer to [Pyth On-Demand Updates page](https://docs.pyth.network/consume-data/on-demand) for more information.
|
||||
Please refer to [Pyth On-Demand Updates page](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand) for more information.
|
||||
|
||||
## Solidity Target Chains
|
||||
|
||||
[This](https://docs.pyth.network/consume-data/evm#networks) document contains list of the EVM networks that Pyth is available on.
|
||||
[This](https://docs.pyth.network/documentation/pythnet-price-feeds/evm#networks) document contains list of the EVM networks that Pyth is available on.
|
||||
|
||||
You can find a list of available price feeds [here](https://pyth.network/developers/price-feed-ids/).
|
||||
|
||||
|
|
|
@ -271,12 +271,12 @@ impl Pyth {
|
|||
/// Get the latest available price cached for the given price identifier, if that price is
|
||||
/// no older than the stale price threshold.
|
||||
///
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for
|
||||
/// how to how this price safely.
|
||||
///
|
||||
/// IMPORTANT:
|
||||
/// Pyth uses an on-demand update model, where consumers need to update the cached prices
|
||||
/// before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
|
||||
/// before using them. Please read more about this at https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand.
|
||||
pub fn get_price(&self, price_identifier: PriceIdentifier) -> Option<Price> {
|
||||
self.get_price_no_older_than(price_identifier, self.stale_threshold)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct PriceIdentifier(pub [u8; 32]);
|
|||
/// Both the price and confidence are stored in a fixed-point numeric representation,
|
||||
/// `x * (10^expo)`, where `expo` is the exponent.
|
||||
//
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
|
||||
/// to how this price safely.
|
||||
#[derive(BorshDeserialize, BorshSerialize, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(crate = "near_sdk::serde")]
|
||||
|
|
|
@ -7,7 +7,7 @@ module pyth::price {
|
|||
/// Both the price and confidence are stored in a fixed-point numeric representation,
|
||||
/// `x * (10^expo)`, where `expo` is the exponent.
|
||||
//
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
|
||||
/// to how this price safely.
|
||||
struct Price has copy, drop, store {
|
||||
price: I64,
|
||||
|
|
|
@ -260,7 +260,7 @@ module pyth::pyth {
|
|||
/// The given fee must contain a sufficient number of coins to pay the update fee for the given vaas.
|
||||
/// The update fee amount can be queried by calling get_update_fee(&vaas).
|
||||
///
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees
|
||||
public fun update_single_price_feed(
|
||||
pyth_state: &PythState,
|
||||
price_updates: HotPotatoVector<PriceInfo>,
|
||||
|
@ -353,11 +353,11 @@ module pyth::pyth {
|
|||
/// Get the latest available price cached for the given price identifier, if that price is
|
||||
/// no older than the stale price threshold.
|
||||
///
|
||||
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for
|
||||
/// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for
|
||||
/// how to how this price safely.
|
||||
///
|
||||
/// Important: Pyth uses an on-demand update model, where consumers need to update the
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
|
||||
/// cached prices before using them. Please read more about this at https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand.
|
||||
/// get_price() is likely to abort unless you call update_price_feeds() to update the cached price
|
||||
/// beforehand, as the cached prices may be older than the stale price threshold.
|
||||
///
|
||||
|
@ -411,7 +411,7 @@ module pyth::pyth {
|
|||
assert!(age < max_age_secs, E_STALE_PRICE_UPDATE);
|
||||
}
|
||||
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
|
||||
/// Please read more information about the update fee here: https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand#fees
|
||||
public fun get_total_update_fee(pyth_state: &PythState, n: u64): u64 {
|
||||
state::get_base_update_fee(pyth_state) * n
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue