pyth.move 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. module pyth::pyth {
  2. use pyth::batch_price_attestation::{Self};
  3. use pyth::price_identifier::{Self, PriceIdentifier};
  4. use pyth::price_info::{Self, PriceInfo};
  5. use pyth::price_feed::{Self};
  6. use aptos_framework::coin::{Self, Coin};
  7. use aptos_framework::aptos_coin::{AptosCoin};
  8. use pyth::price::Price;
  9. use pyth::price;
  10. use pyth::data_source::{Self, DataSource};
  11. use aptos_framework::timestamp;
  12. use std::vector;
  13. use pyth::state;
  14. use wormhole::vaa;
  15. use wormhole::u16;
  16. use wormhole::external_address;
  17. use std::account;
  18. use std::signer;
  19. use deployer::deployer;
  20. use pyth::error;
  21. use pyth::event;
  22. #[test_only]
  23. friend pyth::pyth_test;
  24. // -----------------------------------------------------------------------------
  25. // Initialisation functions
  26. public entry fun init(
  27. deployer: &signer,
  28. stale_price_threshold: u64,
  29. governance_emitter_chain_id: u64,
  30. governance_emitter_address: vector<u8>,
  31. data_sources_emitter_chain_ids: vector<u64>,
  32. data_sources_emitter_addresses: vector<vector<u8>>,
  33. update_fee: u64,
  34. ) {
  35. // Claim the signer capability from the deployer. Note that this is a one-time operation,
  36. // so that this function can only be called once.
  37. let signer_capability = deployer::claim_signer_capability(deployer, @pyth);
  38. init_internal(
  39. signer_capability,
  40. stale_price_threshold,
  41. governance_emitter_chain_id,
  42. governance_emitter_address,
  43. parse_data_sources(
  44. data_sources_emitter_chain_ids,
  45. data_sources_emitter_addresses,
  46. ),
  47. update_fee
  48. )
  49. }
  50. fun init_internal(
  51. signer_capability: account::SignerCapability,
  52. stale_price_threshold: u64,
  53. governance_emitter_chain_id: u64,
  54. governance_emitter_address: vector<u8>,
  55. data_sources: vector<DataSource>,
  56. update_fee: u64) {
  57. let pyth = account::create_signer_with_capability(&signer_capability);
  58. state::init(
  59. &pyth,
  60. stale_price_threshold,
  61. update_fee,
  62. data_source::new(
  63. governance_emitter_chain_id,
  64. external_address::from_bytes(governance_emitter_address)),
  65. data_sources,
  66. signer_capability
  67. );
  68. event::init(&pyth);
  69. if (!coin::is_account_registered<AptosCoin>(signer::address_of(&pyth))) {
  70. coin::register<AptosCoin>(&pyth);
  71. }
  72. }
  73. fun parse_data_sources(
  74. emitter_chain_ids: vector<u64>,
  75. emitter_addresses: vector<vector<u8>>): vector<DataSource> {
  76. assert!(vector::length(&emitter_chain_ids) == vector::length(&emitter_addresses),
  77. error::data_source_emitter_address_and_chain_ids_different_lengths());
  78. let sources = vector::empty();
  79. let i = 0;
  80. while (i < vector::length(&emitter_chain_ids)) {
  81. vector::push_back(&mut sources, data_source::new(
  82. *vector::borrow(&emitter_chain_ids, i),
  83. external_address::from_bytes(*vector::borrow(&emitter_addresses, i))
  84. ));
  85. i = i + 1;
  86. };
  87. sources
  88. }
  89. #[test_only]
  90. /// Expose a public initialization function for use in tests
  91. public fun init_test(
  92. signer_capability: account::SignerCapability,
  93. stale_price_threshold: u64,
  94. governance_emitter_chain_id: u64,
  95. governance_emitter_address: vector<u8>,
  96. data_sources: vector<DataSource>,
  97. update_fee: u64,
  98. ) {
  99. init_internal(
  100. signer_capability,
  101. stale_price_threshold,
  102. governance_emitter_chain_id,
  103. governance_emitter_address,
  104. data_sources,
  105. update_fee
  106. )
  107. }
  108. // -----------------------------------------------------------------------------
  109. // Update the cached prices
  110. //
  111. // Pyth uses an uses an on-demand update model, where consumers need to update the
  112. /// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
  113. /// Update the cached price feeds with the data in the given VAAs. This is a
  114. /// convenience wrapper around update_price_feeds(), which allows you to update the price feeds
  115. /// using an entry function.
  116. ///
  117. /// If possible, it is recommended to use update_price_feeds() instead, which avoids the need
  118. /// to pass a signer account. update_price_feeds_with_funder() should only be used when
  119. /// you need to call an entry function.
  120. ///
  121. /// This function will charge an update fee, transferring some AptosCoin's
  122. /// from the given funder account to the Pyth contract. The amount of coins that will be transferred
  123. /// to perform this update can be queried with get_update_fee(&vaas). The signer must have sufficient
  124. /// account balance to pay this fee, otherwise the transaction will abort.
  125. ///
  126. /// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
  127. public entry fun update_price_feeds_with_funder(account: &signer, vaas: vector<vector<u8>>) {
  128. let coins = coin::withdraw<AptosCoin>(account, get_update_fee(&vaas));
  129. update_price_feeds(vaas, coins);
  130. }
  131. /// Update the cached price feeds with the data in the given VAAs.
  132. /// The vaas argument is a vector of VAAs encoded as bytes.
  133. ///
  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. ///
  138. /// The given fee must contain a sufficient number of coins to pay the update fee for the given vaas.
  139. /// The update fee amount can be queried by calling get_update_fee(&vaas).
  140. ///
  141. /// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
  142. public fun update_price_feeds(vaas: vector<vector<u8>>, fee: Coin<AptosCoin>) {
  143. // Charge the message update fee
  144. assert!(get_update_fee(&vaas) <= coin::value(&fee), error::insufficient_fee());
  145. coin::deposit(@pyth, fee);
  146. // Update the price feed from each VAA
  147. while (!vector::is_empty(&vaas)) {
  148. update_price_feed_from_single_vaa(vector::pop_back(&mut vaas));
  149. };
  150. }
  151. fun update_price_feed_from_single_vaa(vaa: vector<u8>) {
  152. // Deserialize the VAA
  153. let vaa = vaa::parse_and_verify(vaa);
  154. // Check that the VAA is from a valid data source (emitter)
  155. assert!(
  156. state::is_valid_data_source(
  157. data_source::new(
  158. u16::to_u64(vaa::get_emitter_chain(&vaa)),
  159. vaa::get_emitter_address(&vaa))),
  160. error::invalid_data_source());
  161. // Deserialize the batch price attestation
  162. update_cache(batch_price_attestation::destroy(batch_price_attestation::deserialize(vaa::destroy(vaa))));
  163. }
  164. /// Update the cache with given price updates, if they are newer than the ones currently cached.
  165. public(friend) fun update_cache(updates: vector<PriceInfo>) {
  166. while (!vector::is_empty(&updates)) {
  167. let update = vector::pop_back(&mut updates);
  168. if (is_fresh_update(&update)) {
  169. let price_feed = *price_info::get_price_feed(&update);
  170. let price_identifier = price_feed::get_price_identifier(&price_feed);
  171. state::set_latest_price_info(
  172. *price_identifier,
  173. update,
  174. );
  175. event::emit_price_feed_update(price_feed, timestamp::now_microseconds());
  176. }
  177. };
  178. vector::destroy_empty(updates);
  179. }
  180. /// A convenience wrapper around update_price_feeds_if_fresh(), allowing you to conditionally
  181. /// update the price feeds using an entry function.
  182. ///
  183. /// If possible, it is recommended to use update_price_feeds_if_fresh() instead, which avoids the need
  184. /// to pass a signer account. update_price_feeds_if_fresh_with_funder() should only be used when
  185. /// you need to call an entry function.
  186. public entry fun update_price_feeds_if_fresh_with_funder(
  187. account: &signer,
  188. vaas: vector<vector<u8>>,
  189. price_identifiers: vector<vector<u8>>,
  190. publish_times: vector<u64>) {
  191. let coins = coin::withdraw<AptosCoin>(account, get_update_fee(&vaas));
  192. update_price_feeds_if_fresh(vaas, price_identifiers, publish_times, coins);
  193. }
  194. /// Update the cached price feeds with the data in the given VAAs, using
  195. /// update_price_feeds(). However, this function will only have an effect if any of the
  196. /// prices in the update are fresh. The price_identifiers and publish_times parameters
  197. /// are used to determine if the update is fresh without doing any serialisation or verification
  198. /// of the VAAs, potentially saving time and gas. If the update contains no fresh data, this function
  199. /// will revert with error::no_fresh_data().
  200. ///
  201. /// For a given price update i in the batch, that price is considered fresh if the current cached
  202. /// price for price_identifiers[i] is older than publish_times[i].
  203. public entry fun update_price_feeds_if_fresh(
  204. vaas: vector<vector<u8>>,
  205. price_identifiers: vector<vector<u8>>,
  206. publish_times: vector<u64>,
  207. fee: Coin<AptosCoin>) {
  208. assert!(vector::length(&price_identifiers) == vector::length(&publish_times),
  209. error::invalid_publish_times_length());
  210. let fresh_data = false;
  211. let i = 0;
  212. while (i < vector::length(&publish_times)) {
  213. let price_identifier = price_identifier::from_byte_vec(
  214. *vector::borrow(&price_identifiers, i));
  215. if (!state::price_info_cached(price_identifier)) {
  216. fresh_data = true;
  217. break
  218. };
  219. let cached_timestamp = price::get_timestamp(&get_price_unsafe(price_identifier));
  220. if (cached_timestamp < *vector::borrow(&publish_times, i)) {
  221. fresh_data = true;
  222. break
  223. };
  224. i = i + 1;
  225. };
  226. assert!(fresh_data, error::no_fresh_data());
  227. update_price_feeds(vaas, fee);
  228. }
  229. /// Determine if the given price update is "fresh": we have nothing newer already cached for that
  230. /// price feed.
  231. fun is_fresh_update(update: &PriceInfo): bool {
  232. // Get the timestamp of the update's current price
  233. let price_feed = price_info::get_price_feed(update);
  234. let update_timestamp = price::get_timestamp(&price_feed::get_price(price_feed));
  235. // Get the timestamp of the cached data for the price identifier
  236. let price_identifier = price_feed::get_price_identifier(price_feed);
  237. if (!price_feed_exists(*price_identifier)) {
  238. return true
  239. };
  240. let cached_timestamp = price::get_timestamp(&get_price_unsafe(*price_identifier));
  241. update_timestamp > cached_timestamp
  242. }
  243. // -----------------------------------------------------------------------------
  244. // Query the cached prices
  245. //
  246. // It is strongly recommended to update the cached prices using the functions above,
  247. // before using the functions below to query the cached data.
  248. /// Determine if a price feed for the given price_identifier exists
  249. public fun price_feed_exists(price_identifier: PriceIdentifier): bool {
  250. state::price_info_cached(price_identifier)
  251. }
  252. /// Get the latest available price cached for the given price identifier, if that price is
  253. /// no older than the stale price threshold.
  254. ///
  255. /// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for
  256. /// how to how this price safely.
  257. ///
  258. /// Important: Pyth uses an on-demand update model, where consumers need to update the
  259. /// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
  260. /// get_price() is likely to abort unless you call update_price_feeds() to update the cached price
  261. /// beforehand, as the cached prices may be older than the stale price threshold.
  262. ///
  263. /// Note that the price_identifier does not correspond to a seperate Aptos account:
  264. /// all price feeds are stored in the single pyth account. The price identifier is an
  265. /// opaque identifier for a price feed.
  266. public fun get_price(price_identifier: PriceIdentifier): Price {
  267. get_price_no_older_than(price_identifier, state::get_stale_price_threshold_secs())
  268. }
  269. /// Get the latest available price cached for the given price identifier, if that price is
  270. /// no older than the given age.
  271. public fun get_price_no_older_than(price_identifier: PriceIdentifier, max_age_secs: u64): Price {
  272. let price = get_price_unsafe(price_identifier);
  273. check_price_is_fresh(&price, max_age_secs);
  274. price
  275. }
  276. /// Get the latest available price cached for the given price identifier.
  277. ///
  278. /// WARNING: the returned price can be from arbitrarily far in the past.
  279. /// This function makes no guarantees that the returned price is recent or
  280. /// useful for any particular application. Users of this function should check
  281. /// the returned timestamp to ensure that the returned price is sufficiently
  282. /// recent for their application. The checked get_price_no_older_than()
  283. /// function should be used in preference to this.
  284. public fun get_price_unsafe(price_identifier: PriceIdentifier): Price {
  285. price_feed::get_price(
  286. price_info::get_price_feed(&state::get_latest_price_info(price_identifier)))
  287. }
  288. fun abs_diff(x: u64, y: u64): u64 {
  289. if (x > y) {
  290. return x - y
  291. } else {
  292. return y - x
  293. }
  294. }
  295. /// Get the stale price threshold: the amount of time after which a cached price
  296. /// is considered stale and no longer returned by get_price()/get_ema_price().
  297. public fun get_stale_price_threshold_secs(): u64 {
  298. state::get_stale_price_threshold_secs()
  299. }
  300. fun check_price_is_fresh(price: &Price, max_age_secs: u64) {
  301. let age = abs_diff(timestamp::now_seconds(), price::get_timestamp(price));
  302. assert!(age < max_age_secs, error::stale_price_update());
  303. }
  304. /// Get the latest available exponentially moving average price cached for the given
  305. /// price identifier, if that price is no older than the stale price threshold.
  306. ///
  307. /// Important: Pyth uses an on-demand update model, where consumers need to update the
  308. /// cached prices before using them. Please read more about this at https://docs.pyth.network/consume-data/on-demand.
  309. /// get_ema_price() is likely to abort unless you call update_price_feeds() to update the cached price
  310. /// beforehand, as the cached prices may be older than the stale price threshold.
  311. public fun get_ema_price(price_identifier: PriceIdentifier): Price {
  312. get_ema_price_no_older_than(price_identifier, state::get_stale_price_threshold_secs())
  313. }
  314. /// Get the latest available exponentially moving average price cached for the given price identifier,
  315. /// if that price is no older than the given age.
  316. public fun get_ema_price_no_older_than(price_identifier: PriceIdentifier, max_age_secs: u64): Price {
  317. let price = get_ema_price_unsafe(price_identifier);
  318. check_price_is_fresh(&price, max_age_secs);
  319. price
  320. }
  321. /// Get the latest available exponentially moving average price cached for the given price identifier.
  322. ///
  323. /// WARNING: the returned price can be from arbitrarily far in the past.
  324. /// This function makes no guarantees that the returned price is recent or
  325. /// useful for any particular application. Users of this function should check
  326. /// the returned timestamp to ensure that the returned price is sufficiently
  327. /// recent for their application. The checked get_ema_price_no_older_than()
  328. /// function should be used in preference to this.
  329. public fun get_ema_price_unsafe(price_identifier: PriceIdentifier): Price {
  330. price_feed::get_ema_price(
  331. price_info::get_price_feed(&state::get_latest_price_info(price_identifier)))
  332. }
  333. /// Get the number of AptosCoin's required to perform the given price updates.
  334. ///
  335. /// Please read more information about the update fee here: https://docs.pyth.network/consume-data/on-demand#fees
  336. public fun get_update_fee(update_data: &vector<vector<u8>>): u64 {
  337. state::get_base_update_fee() * vector::length(update_data)
  338. }
  339. }
  340. // -----------------------------------------------------------------------------
  341. // Tests
  342. #[test_only]
  343. module pyth::pyth_test {
  344. use pyth::pyth;
  345. use pyth::price_identifier::{Self};
  346. use pyth::price_info::{Self, PriceInfo};
  347. use pyth::price_feed::{Self};
  348. use aptos_framework::coin::{Self, Coin, BurnCapability, MintCapability};
  349. use aptos_framework::aptos_coin::{Self, AptosCoin};
  350. use pyth::i64;
  351. use pyth::price;
  352. use pyth::data_source::{Self, DataSource};
  353. use aptos_framework::timestamp;
  354. use std::vector;
  355. use wormhole::external_address;
  356. use std::account;
  357. use std::signer;
  358. #[test_only]
  359. fun setup_test(
  360. aptos_framework: &signer,
  361. stale_price_threshold: u64,
  362. governance_emitter_chain_id: u64,
  363. governance_emitter_address: vector<u8>,
  364. data_sources: vector<DataSource>,
  365. update_fee: u64,
  366. to_mint: u64): (BurnCapability<AptosCoin>, MintCapability<AptosCoin>, Coin<AptosCoin>) {
  367. // Initialize wormhole with a large message collection fee
  368. wormhole::wormhole_test::setup(100000);
  369. // Set the current time
  370. timestamp::update_global_time_for_test_secs(1663680745);
  371. // Deploy and initialize a test instance of the Pyth contract
  372. let deployer = account::create_signer_with_capability(&
  373. account::create_test_signer_cap(@0x277fa055b6a73c42c0662d5236c65c864ccbf2d4abd21f174a30c8b786eab84b));
  374. let (_pyth, signer_capability) = account::create_resource_account(&deployer, b"pyth");
  375. pyth::init_test(signer_capability, stale_price_threshold, governance_emitter_chain_id, governance_emitter_address, data_sources, update_fee);
  376. let (burn_capability, mint_capability) = aptos_coin::initialize_for_test(aptos_framework);
  377. let coins = coin::mint(to_mint, &mint_capability);
  378. (burn_capability, mint_capability, coins)
  379. }
  380. #[test_only]
  381. fun cleanup_test(burn_capability: BurnCapability<AptosCoin>, mint_capability: MintCapability<AptosCoin>) {
  382. coin::destroy_mint_cap(mint_capability);
  383. coin::destroy_burn_cap(burn_capability);
  384. }
  385. #[test_only]
  386. fun get_mock_price_infos(): vector<PriceInfo> {
  387. vector<PriceInfo>[
  388. price_info::new(
  389. 1663680747,
  390. 1663074349,
  391. price_feed::new(
  392. price_identifier::from_byte_vec(x"c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1"),
  393. price::new(i64::new(1557, false), 7, i64::new(5, true), 1663680740),
  394. price::new(i64::new(1500, false), 3, i64::new(5, true), 1663680740),
  395. ),
  396. ),
  397. price_info::new(
  398. 1663680747,
  399. 1663074349,
  400. price_feed::new(
  401. price_identifier::from_byte_vec(x"3b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe"),
  402. price::new(i64::new(1050, false), 3, i64::new(5, true), 1663680745),
  403. price::new(i64::new(1483, false), 3, i64::new(5, true), 1663680745),
  404. ),
  405. ),
  406. price_info::new(
  407. 1663680747,
  408. 1663074349,
  409. price_feed::new(
  410. price_identifier::from_byte_vec(x"33832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d"),
  411. price::new(i64::new(1010, false), 2, i64::new(5, true), 1663680745),
  412. price::new(i64::new(1511, false), 3, i64::new(5, true), 1663680745),
  413. ),
  414. ),
  415. price_info::new(
  416. 1663680747,
  417. 1663074349,
  418. price_feed::new(
  419. price_identifier::from_byte_vec(x"21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db8"),
  420. price::new(i64::new(1739, false), 1, i64::new(5, true), 1663680745),
  421. price::new(i64::new(1508, false), 3, i64::new(5, true), 1663680745),
  422. ),
  423. ),
  424. ]
  425. }
  426. #[test_only]
  427. /// A vector containing a single VAA with:
  428. /// - emitter chain ID 17
  429. /// - emitter address 0x71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b
  430. /// - payload corresponding to the batch price attestation of the prices returned by get_mock_price_infos()
  431. const TEST_VAAS: vector<vector<u8>> = vector[x"0100000000010036eb563b80a24f4253bee6150eb8924e4bdf6e4fa1dfc759a6664d2e865b4b134651a7b021b7f1ce3bd078070b688b6f2e37ce2de0d9b48e6a78684561e49d5201527e4f9b00000001001171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b0000000000000001005032574800030000000102000400951436e0be37536be96f0896366089506a59763d036728332d3e3038047851aea7c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1000000000000049a0000000000000008fffffffb00000000000005dc0000000000000003000000000100000001000000006329c0eb000000006329c0e9000000006329c0e400000000000006150000000000000007215258d81468614f6b7e194c5d145609394f67b041e93e6695dcc616faadd0603b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe000000000000041a0000000000000003fffffffb00000000000005cb0000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e4000000000000048600000000000000078ac9cf3ab299af710d735163726fdae0db8465280502eb9f801f74b3c1bd190333832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d00000000000003f20000000000000002fffffffb00000000000005e70000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e40000000000000685000000000000000861db714e9ff987b6fedf00d01f9fea6db7c30632d6fc83b7bc9459d7192bc44a21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db800000000000006cb0000000000000001fffffffb00000000000005e40000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e400000000000007970000000000000001"];
  432. #[test_only]
  433. /// Allow anyone to update the cache with given updates. For testing purpose only.
  434. public fun update_cache_for_test(updates: vector<PriceInfo>) {
  435. pyth::update_cache(updates);
  436. }
  437. #[test(aptos_framework = @aptos_framework)]
  438. fun test_get_update_fee(aptos_framework: &signer) {
  439. let single_update_fee = 50;
  440. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", vector[], 50, 0);
  441. // Pass in a single VAA
  442. assert!(pyth::get_update_fee(&vector[
  443. x"fb1543888001083cf2e6ef3afdcf827e89b11efd87c563638df6e1995ada9f93",
  444. ]) == single_update_fee, 1);
  445. // Pass in multiple VAAs
  446. assert!(pyth::get_update_fee(&vector[
  447. x"4ee17a1a4524118de513fddcf82b77454e51be5d6fc9e29fc72dd6c204c0e4fa",
  448. x"c72fdf81cfc939d4286c93fbaaae2eec7bae28a5926fa68646b43a279846ccc1",
  449. x"d9a8123a793529c31200339820a3210059ecace6c044f81ecad62936e47ca049",
  450. x"84e4f21b3e65cef47fda25d15b4eddda1edf720a1d062ccbf441d6396465fbe6",
  451. x"9e73f9041476a93701a0b9c7501422cc2aa55d16100bec628cf53e0281b6f72f"
  452. ]) == 250, 1);
  453. coin::destroy_zero(coins);
  454. cleanup_test(burn_capability, mint_capability);
  455. }
  456. #[test(aptos_framework = @aptos_framework)]
  457. #[expected_failure(abort_code = 6)]
  458. fun test_update_price_feeds_corrupt_vaa(aptos_framework: &signer) {
  459. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", vector[], 50, 100);
  460. // Pass in a corrupt VAA, which should fail deseriaizing
  461. let corrupt_vaa = x"90F8bf6A479f320ead074411a4B0e7944Ea8c9C1";
  462. pyth::update_price_feeds(vector[corrupt_vaa], coins);
  463. cleanup_test(burn_capability, mint_capability);
  464. }
  465. #[test(aptos_framework = @aptos_framework)]
  466. #[expected_failure(abort_code = 65539)]
  467. fun test_update_price_feeds_invalid_data_source(aptos_framework: &signer) {
  468. // Initialize the contract with some valid data sources, excluding our test VAA's source
  469. let data_sources = vector<DataSource>[
  470. data_source::new(
  471. 4, external_address::from_bytes(x"0000000000000000000000000000000000000000000000000000000000007742")),
  472. data_source::new(
  473. 5, external_address::from_bytes(x"0000000000000000000000000000000000000000000000000000000000007637"))
  474. ];
  475. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources, 50, 100);
  476. pyth::update_price_feeds(TEST_VAAS, coins);
  477. cleanup_test(burn_capability, mint_capability);
  478. }
  479. #[test_only]
  480. fun data_sources_for_test_vaa(): vector<DataSource> {
  481. // Set some valid data sources, including our test VAA's source
  482. vector<DataSource>[
  483. data_source::new(
  484. 1, external_address::from_bytes(x"0000000000000000000000000000000000000000000000000000000000000004")),
  485. data_source::new(
  486. 5, external_address::from_bytes(x"0000000000000000000000000000000000000000000000000000000000007637")),
  487. data_source::new(
  488. 17, external_address::from_bytes(x"71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b"))
  489. ]
  490. }
  491. #[test(aptos_framework = @aptos_framework)]
  492. #[expected_failure(abort_code = 65542)]
  493. fun test_update_price_feeds_insufficient_fee(aptos_framework: &signer) {
  494. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1,
  495. x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92",
  496. data_sources_for_test_vaa(),
  497. // Update fee
  498. 50,
  499. // Coins provided to update < update fee
  500. 20);
  501. pyth::update_price_feeds(TEST_VAAS, coins);
  502. cleanup_test(burn_capability, mint_capability);
  503. }
  504. #[test(aptos_framework = @aptos_framework)]
  505. fun test_update_price_feeds_success(aptos_framework: &signer) {
  506. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 100);
  507. // Update the price feeds from the VAA
  508. pyth::update_price_feeds(TEST_VAAS, coins);
  509. // Check that the cache has been updated
  510. let expected = get_mock_price_infos();
  511. check_price_feeds_cached(&expected);
  512. cleanup_test(burn_capability, mint_capability);
  513. }
  514. #[test(aptos_framework = @aptos_framework)]
  515. fun test_update_price_feeds_with_funder(aptos_framework: &signer) {
  516. let update_fee = 50;
  517. let initial_balance = 75;
  518. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), update_fee, initial_balance);
  519. // Create a test funder account and register it to store funds
  520. let funder_addr = @0xbfbffd8e2af9a3e3ce20d2d2b22bd640;
  521. let funder = account::create_account_for_test(funder_addr);
  522. coin::register<AptosCoin>(&funder);
  523. coin::deposit(funder_addr, coins);
  524. assert!(pyth::get_update_fee(&TEST_VAAS) == update_fee, 1);
  525. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance, 1);
  526. assert!(coin::balance<AptosCoin>(@pyth) == 0, 1);
  527. // Update the price feeds using the funder
  528. pyth::update_price_feeds_with_funder(&funder, TEST_VAAS);
  529. // Check that the price feeds are now cached
  530. check_price_feeds_cached(&get_mock_price_infos());
  531. // Check that the funder's balance has decreased by the update_fee amount
  532. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance - pyth::get_update_fee(&TEST_VAAS), 1);
  533. // Check that the amount has been transferred to the Pyth contract
  534. assert!(coin::balance<AptosCoin>(@pyth) == pyth::get_update_fee(&TEST_VAAS), 1);
  535. cleanup_test(burn_capability, mint_capability);
  536. }
  537. #[test(aptos_framework = @aptos_framework)]
  538. #[expected_failure(abort_code = 65542)]
  539. fun test_update_price_feeds_with_funder_insufficient_balance(aptos_framework: &signer) {
  540. let update_fee = 50;
  541. let initial_balance = 25;
  542. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), update_fee, initial_balance);
  543. // Create a test funder account and register it to store funds
  544. let funder_addr = @0xbfbffd8e2af9a3e3ce20d2d2b22bd640;
  545. let funder = account::create_account_for_test(funder_addr);
  546. coin::register<AptosCoin>(&funder);
  547. coin::deposit(funder_addr, coins);
  548. assert!(pyth::get_update_fee(&TEST_VAAS) == update_fee, 1);
  549. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance, 1);
  550. assert!(coin::balance<AptosCoin>(@pyth) == 0, 1);
  551. // Update the price feeds using the funder
  552. pyth::update_price_feeds_with_funder(&funder, TEST_VAAS);
  553. cleanup_test(burn_capability, mint_capability);
  554. }
  555. #[test_only]
  556. fun check_price_feeds_cached(expected: &vector<PriceInfo>) {
  557. // Check that we can retrieve the correct current price and ema price for each price feed
  558. let i = 0;
  559. while (i < vector::length(expected)) {
  560. let price_feed = price_info::get_price_feed(vector::borrow(expected, i));
  561. let price = price_feed::get_price(price_feed);
  562. let price_identifier = *price_feed::get_price_identifier(price_feed);
  563. assert!(pyth::price_feed_exists(price_identifier), 1);
  564. let cached_price = pyth::get_price(price_identifier);
  565. assert!(cached_price == price, 1);
  566. let ema_price = price_feed::get_ema_price(price_feed);
  567. let cached_ema_price = pyth::get_ema_price(price_identifier);
  568. assert!(cached_ema_price == ema_price, 1);
  569. i = i + 1;
  570. };
  571. }
  572. #[test(aptos_framework = @aptos_framework)]
  573. fun test_update_cache(aptos_framework: &signer) {
  574. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 0);
  575. let updates = get_mock_price_infos();
  576. // Check that initially the price feeds are not cached
  577. let i = 0;
  578. while (i < vector::length(&updates)) {
  579. let price_feed = price_info::get_price_feed(vector::borrow(&updates, i));
  580. assert!(!pyth::price_feed_exists(*price_feed::get_price_identifier(price_feed)), 1);
  581. i = i + 1;
  582. };
  583. // Submit the updates
  584. pyth::update_cache(updates);
  585. // Check that the price feeds are now cached
  586. check_price_feeds_cached(&updates);
  587. cleanup_test(burn_capability, mint_capability);
  588. coin::destroy_zero(coins);
  589. }
  590. #[test(aptos_framework = @aptos_framework)]
  591. fun test_update_cache_old_update(aptos_framework: &signer) {
  592. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 1000, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 0);
  593. // Submit a price update
  594. let timestamp = 1663680700;
  595. let price_identifier = price_identifier::from_byte_vec(x"baa284eaf23edf975b371ba2818772f93dbae72836bbdea28b07d40f3cf8b485");
  596. let price = price::new(i64::new(7648, false), 674, i64::new(8, true), timestamp);
  597. let ema_price = price::new(i64::new(1536, true), 869, i64::new(100, false), timestamp);
  598. let update = price_info::new(
  599. 1257278600,
  600. 1690226180,
  601. price_feed::new(
  602. price_identifier,
  603. price,
  604. ema_price,
  605. )
  606. );
  607. pyth::update_cache(vector<PriceInfo>[update]);
  608. // Check that we can retrieve the current price
  609. assert!(pyth::get_price(price_identifier) == price, 1);
  610. // Attempt to update the price with an update older than the current cached one
  611. let old_price = price::new(i64::new(1243, true), 9802, i64::new(6, false), timestamp - 200);
  612. let old_ema_price = price::new(i64::new(8976, true), 234, i64::new(897, false), timestamp - 200);
  613. let old_update = price_info::new(
  614. 1257278600,
  615. 1690226180,
  616. price_feed::new(
  617. price_identifier,
  618. old_price,
  619. old_ema_price,
  620. )
  621. );
  622. pyth::update_cache(vector<PriceInfo>[old_update]);
  623. // Confirm that the current price and ema price didn't change
  624. assert!(pyth::get_price(price_identifier) == price, 1);
  625. assert!(pyth::get_ema_price(price_identifier) == ema_price, 1);
  626. // Update the cache with a fresh update
  627. let fresh_price = price::new(i64::new(4857, true), 9979, i64::new(243, false), timestamp + 200);
  628. let fresh_ema_price = price::new(i64::new(74637, false), 9979, i64::new(1433, false), timestamp + 1);
  629. let fresh_update = price_info::new(
  630. 1257278600,
  631. 1690226180,
  632. price_feed::new(
  633. price_identifier,
  634. fresh_price,
  635. fresh_ema_price,
  636. )
  637. );
  638. pyth::update_cache(vector<PriceInfo>[fresh_update]);
  639. // Confirm that the current price was updated
  640. assert!(pyth::get_price(price_identifier) == fresh_price, 1);
  641. assert!(pyth::get_ema_price(price_identifier) == fresh_ema_price, 1);
  642. cleanup_test(burn_capability, mint_capability);
  643. coin::destroy_zero(coins);
  644. }
  645. #[test(aptos_framework = @aptos_framework)]
  646. #[expected_failure(abort_code = 524292)]
  647. fun test_stale_price_threshold_exceeded(aptos_framework: &signer) {
  648. let stale_price_threshold = 500;
  649. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, stale_price_threshold, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 0);
  650. // Submit a price update
  651. let current_timestamp = timestamp::now_seconds();
  652. let price_identifier = price_identifier::from_byte_vec(x"baa284eaf23edf975b371ba2818772f93dbae72836bbdea28b07d40f3cf8b485");
  653. let price = price::new(i64::new(7648, false), 674, i64::new(8, true), current_timestamp);
  654. let update = price_info::new(
  655. 1257278600,
  656. 1690226180,
  657. price_feed::new(
  658. price_identifier,
  659. price,
  660. price::new(i64::new(1536, true), 869, i64::new(100, false), 1257212500),
  661. )
  662. );
  663. pyth::update_cache(vector<PriceInfo>[update]);
  664. assert!(pyth::get_price(price_identifier) == price, 1);
  665. // Now advance the clock on the target chain, until the age of the cached update exceeds the
  666. // stale_price_threshold.
  667. timestamp::update_global_time_for_test_secs(current_timestamp + stale_price_threshold);
  668. // Check that we can access the price if we increase the threshold by 1
  669. assert!(pyth::get_price_no_older_than(
  670. price_identifier, pyth::get_stale_price_threshold_secs() + 1) == price, 1);
  671. // However, retrieving the latest price fails
  672. assert!(pyth::get_price(price_identifier) == price, 1);
  673. cleanup_test(burn_capability, mint_capability);
  674. coin::destroy_zero(coins);
  675. }
  676. #[test(aptos_framework = @aptos_framework)]
  677. #[expected_failure(abort_code = 524292)]
  678. fun test_stale_price_threshold_exceeded_ema(aptos_framework: &signer) {
  679. let stale_price_threshold = 500;
  680. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, stale_price_threshold, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 0);
  681. // Submit a price update
  682. let current_timestamp = timestamp::now_seconds();
  683. let price_identifier = price_identifier::from_byte_vec(x"baa284eaf23edf975b371ba2818772f93dbae72836bbdea28b07d40f3cf8b485");
  684. let ema_price = price::new(i64::new(1536, true), 869, i64::new(100, false), current_timestamp);
  685. let update = price_info::new(
  686. 1257278600,
  687. 1690226180,
  688. price_feed::new(
  689. price_identifier,
  690. price::new(i64::new(7648, false), 674, i64::new(8, true), 1257212500),
  691. ema_price,
  692. )
  693. );
  694. pyth::update_cache(vector<PriceInfo>[update]);
  695. // Check that the EMA price has been updated
  696. assert!(pyth::get_ema_price(price_identifier) == ema_price, 1);
  697. // Now advance the clock on the target chain, until the age of the cached update exceeds the
  698. // stale_price_threshold.
  699. timestamp::update_global_time_for_test_secs(current_timestamp + stale_price_threshold);
  700. // Check that we can access the EMA price if we increase the threshold by 1
  701. assert!(pyth::get_ema_price_no_older_than(
  702. price_identifier, pyth::get_stale_price_threshold_secs() + 1) == ema_price, 1);
  703. // However, retrieving the latest EMA price fails
  704. assert!(pyth::get_ema_price(price_identifier) == ema_price, 1);
  705. cleanup_test(burn_capability, mint_capability);
  706. coin::destroy_zero(coins);
  707. }
  708. #[test(aptos_framework = @aptos_framework)]
  709. #[expected_failure(abort_code = 65541)]
  710. fun test_update_price_feeds_if_fresh_invalid_length(aptos_framework: &signer) {
  711. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 0);
  712. // Update the price feeds
  713. let bytes = vector[vector[0u8, 1u8, 2u8]];
  714. let price_identifiers = vector[
  715. x"baa284eaf23edf975b371ba2818772f93dbae72836bbdea28b07d40f3cf8b485",
  716. x"c9d5fe0d836688f4c88c221415d23e4bcabee21a6a21124bfcc9a5410a297818",
  717. x"eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
  718. ];
  719. let publish_times = vector[
  720. 734639463
  721. ];
  722. pyth::update_price_feeds_if_fresh(bytes, price_identifiers, publish_times, coins);
  723. cleanup_test(burn_capability, mint_capability);
  724. }
  725. #[test(aptos_framework = @aptos_framework)]
  726. fun test_update_price_feeds_if_fresh_fresh_data(aptos_framework: &signer) {
  727. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 50);
  728. // Update the price feeds
  729. let bytes = TEST_VAAS;
  730. let price_identifiers = vector[
  731. x"c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1",
  732. x"3b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe",
  733. x"33832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d",
  734. x"21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db8",
  735. ];
  736. let publish_times = vector[
  737. 1663680745, 1663680730, 1663680760, 1663680720
  738. ];
  739. pyth::update_price_feeds_if_fresh(bytes, price_identifiers, publish_times, coins);
  740. // Check that the cache has been updated
  741. let expected = get_mock_price_infos();
  742. check_price_feeds_cached(&expected);
  743. cleanup_test(burn_capability, mint_capability);
  744. }
  745. #[test(aptos_framework = @aptos_framework)]
  746. fun test_update_price_feeds_if_fresh_with_funder_fresh_data(aptos_framework: &signer) {
  747. let update_fee = 50;
  748. let initial_balance = 75;
  749. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), update_fee, initial_balance);
  750. // Create a test funder account and register it to store funds
  751. let funder_addr = @0xbfbffd8e2af9a3e3ce20d2d2b22bd640;
  752. let funder = account::create_account_for_test(funder_addr);
  753. coin::register<AptosCoin>(&funder);
  754. coin::deposit(funder_addr, coins);
  755. assert!(pyth::get_update_fee(&TEST_VAAS) == update_fee, 1);
  756. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance, 1);
  757. assert!(coin::balance<AptosCoin>(@pyth) == 0, 1);
  758. // Update the price feeds using the funder
  759. let bytes = TEST_VAAS;
  760. let price_identifiers = vector[
  761. x"c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1",
  762. x"3b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe",
  763. x"33832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d",
  764. x"21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db8",
  765. ];
  766. let publish_times = vector[
  767. 1663680790, 1663680730, 1663680760, 1663680720
  768. ];
  769. pyth::update_price_feeds_if_fresh_with_funder(&funder, bytes, price_identifiers, publish_times);
  770. // Check that the price feeds are now cached
  771. check_price_feeds_cached(&get_mock_price_infos());
  772. // Check that the funder's balance has decreased by the update_fee amount
  773. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance - pyth::get_update_fee(&TEST_VAAS), 1);
  774. // Check that the amount has been transferred to the Pyth contract
  775. assert!(coin::balance<AptosCoin>(@pyth) == pyth::get_update_fee(&TEST_VAAS), 1);
  776. cleanup_test(burn_capability, mint_capability);
  777. }
  778. #[test(aptos_framework = @aptos_framework)]
  779. #[expected_failure(abort_code = 524295)]
  780. fun test_update_price_feeds_if_fresh_stale_data(aptos_framework: &signer) {
  781. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 1, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), 50, 50);
  782. // First populate the cache
  783. pyth::update_cache(get_mock_price_infos());
  784. // Now attempt to update the price feeds with publish_times that are older than those we have cached
  785. // This should abort with error::no_fresh_data()
  786. let bytes = TEST_VAAS;
  787. let price_identifiers = vector[
  788. x"c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1",
  789. x"3b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe",
  790. x"33832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d",
  791. x"21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db8",
  792. ];
  793. let publish_times = vector[
  794. 67, 35, 26, 64
  795. ];
  796. pyth::update_price_feeds_if_fresh(bytes, price_identifiers, publish_times, coins);
  797. cleanup_test(burn_capability, mint_capability);
  798. }
  799. #[test(aptos_framework = @aptos_framework)]
  800. #[expected_failure(abort_code = 524295)]
  801. fun test_update_price_feeds_if_fresh_with_funder_stale_data(aptos_framework: &signer) {
  802. let update_fee = 50;
  803. let initial_balance = 75;
  804. let (burn_capability, mint_capability, coins) = setup_test(aptos_framework, 500, 23, x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92", data_sources_for_test_vaa(), update_fee, initial_balance);
  805. // Create a test funder account and register it to store funds
  806. let funder_addr = @0xbfbffd8e2af9a3e3ce20d2d2b22bd640;
  807. let funder = account::create_account_for_test(funder_addr);
  808. coin::register<AptosCoin>(&funder);
  809. coin::deposit(funder_addr, coins);
  810. assert!(pyth::get_update_fee(&TEST_VAAS) == update_fee, 1);
  811. assert!(coin::balance<AptosCoin>(signer::address_of(&funder)) == initial_balance, 1);
  812. assert!(coin::balance<AptosCoin>(@pyth) == 0, 1);
  813. // First populate the cache
  814. pyth::update_cache(get_mock_price_infos());
  815. // Now attempt to update the price feeds with publish_times that are older than those we have cached
  816. // This should abort with error::no_fresh_data()
  817. let bytes = TEST_VAAS;
  818. let price_identifiers = vector[
  819. x"c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1",
  820. x"3b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe",
  821. x"33832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d",
  822. x"21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db8",
  823. ];
  824. let publish_times = vector[
  825. 100, 76, 29, 64
  826. ];
  827. pyth::update_price_feeds_if_fresh_with_funder(&funder, bytes, price_identifiers, publish_times);
  828. cleanup_test(burn_capability, mint_capability);
  829. }
  830. }