pyth-crosschain/aptos/example/sources/example.move

24 lines
886 B
Plaintext

module example::example {
use pyth::pyth;
use pyth::price::Price;
use pyth::price_identifier;
use aptos_framework::coin;
/// Updates the Pyth price feeds using the given pyth_update_data, and then returns
/// the BTC/USD price.
public fun get_btc_usd_price(user: &signer, pyth_update_data: vector<vector<u8>>): Price {
// First update the Pyth price feeds
let coins = coin::withdraw(user, pyth::get_update_fee());
pyth::update_price_feeds(pyth_update_data, coins);
// Price Feed Identifier of BTC/USD in Testnet
let btc_price_identifier = x"f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b";
// Now we can use the prices which we have just updated
let btc_usd_price_id = price_identifier::from_byte_vec(btc_price_identifier);
pyth::get_price(btc_usd_price_id)
}
}