Skip to content

Commit 207616d

Browse files
authored
Add explanatory comments (#335)
* Add explanatory comments * Add second best practices link
1 parent 660160b commit 207616d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

aptos/contracts/sources/pyth.move

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ module pyth::pyth {
131131
/// Update the cached price feeds with the data in the given VAAs.
132132
/// The vaas argument is a vector of VAAs encoded as bytes.
133133
///
134+
/// The javascript https://github.com/pyth-network/pyth-js/tree/main/pyth-aptos-js package
135+
/// should be used to fetch these VAAs from the Price Service. More information about this
136+
/// process can be found at https://docs.pyth.network/consume-data.
137+
///
134138
/// The given fee must contain a sufficient number of coins to pay the update fee.
135139
/// The update fee amount can be queried by calling get_update_fee().
136140
public fun update_price_feeds(vaas: vector<vector<u8>>, fee: Coin<AptosCoin>) {
@@ -264,9 +268,16 @@ module pyth::pyth {
264268
/// Get the latest available price cached for the given price identifier, if that price is
265269
/// no older than the stale price threshold.
266270
///
271+
/// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for
272+
/// how to how this price safely.
273+
///
267274
/// Important: it is recommended to call update_price_feeds() to update the cached price
268275
/// before calling this function, as get_price() will abort if the cached price is older
269276
/// than the stale price threshold.
277+
///
278+
/// Note that the price_identifier does not correspond to a seperate Aptos account:
279+
/// all price feeds are stored in the single pyth account. The price identifier is an
280+
/// opaque identifier for a price feed.
270281
public fun get_price(price_identifier: PriceIdentifier): Price {
271282
get_price_no_older_than(price_identifier, state::get_stale_price_threshold_secs())
272283
}

aptos/contracts/sources/state.move

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module pyth::state {
3838
}
3939

4040
/// Mapping of cached price information
41+
///
42+
/// WARNING: do not directly read out of this table, instead use
43+
/// the checked `pyth::get_price` method. This ensures that the price
44+
/// is recent enough.
4145
struct LatestPriceInfo has key {
4246
info: Table<PriceIdentifier, PriceInfo>,
4347
}

aptos/example/sources/example.move

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ module example::example {
66

77
/// Updates the Pyth price feeds using the given pyth_update_data, and then returns
88
/// the BTC/USD price.
9+
///
10+
/// https://github.com/pyth-network/pyth-js/tree/main/pyth-aptos-js should be used to
11+
/// fetch the pyth_update_data off-chain and pass it in. More information about how this
12+
/// works can be found at https://docs.pyth.network/consume-data
913
public fun get_btc_usd_price(user: &signer, pyth_update_data: vector<vector<u8>>): Price {
1014

1115
// First update the Pyth price feeds

0 commit comments

Comments
 (0)