diff --git a/aptos/example/Move.toml b/aptos/example/Move.toml new file mode 100644 index 00000000..3bd7b38c --- /dev/null +++ b/aptos/example/Move.toml @@ -0,0 +1,20 @@ +[package] +name = "Example Pyth App" +version = "0.0.1" +upgrade_policy = "compatible" + +[dependencies] +Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "aptos/contracts", rev = "main" } + +[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 +pyth = "_" +deployer = "_" +wormhole = "_" + +[dev-addresses] +pyth = "0xe2f37b8ac45d29d5ea23eb7d16dd3f7a7ab6426f5a998d6c23ecd3ae8d9d29eb" +deployer = "0x277fa055b6a73c42c0662d5236c65c864ccbf2d4abd21f174a30c8b786eab84b" +wormhole = "0x251011524cd0f76881f16e7c2d822f0c1c9510bfd2430ba24e1b3d52796df204" diff --git a/aptos/example/sources/example.move b/aptos/example/sources/example.move new file mode 100644 index 00000000..74c2e625 --- /dev/null +++ b/aptos/example/sources/example.move @@ -0,0 +1,23 @@ +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>): 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) + + } +}