@@ -126,11 +126,11 @@ module pyth::pyth {
126
126
/// you need to call an entry function.
127
127
///
128
128
/// This function will charge an update fee, transferring some AptosCoin's
129
- /// from the given funder account to the Pyth contract. The amount of coins transferred can be
130
- /// queried with get_update_fee(). The signer must have sufficient account balance to
131
- /// pay this fee, otherwise the transaction will abort.
129
+ /// from the given funder account to the Pyth contract. The amount of coins that will be transferred
130
+ /// to perform this update can be queried with get_update_fee(&vaas ). The signer must have sufficient
131
+ /// account balance to pay this fee, otherwise the transaction will abort.
132
132
public entry fun update_price_feeds_with_funder (account: &signer , vaas: vector <vector <u8 >>) {
133
- let coins = coin::withdraw <AptosCoin >(account, get_update_fee ());
133
+ let coins = coin::withdraw <AptosCoin >(account, get_update_fee (&vaas ));
134
134
update_price_feeds (vaas, coins);
135
135
}
136
136
@@ -141,17 +141,17 @@ module pyth::pyth {
141
141
/// should be used to fetch these VAAs from the Price Service. More information about this
142
142
/// process can be found at https://docs.pyth.network/consume-data.
143
143
///
144
- /// The given fee must contain a sufficient number of coins to pay the update fee.
145
- /// The update fee amount can be queried by calling get_update_fee().
144
+ /// The given fee must contain a sufficient number of coins to pay the update fee for the given vaas .
145
+ /// The update fee amount can be queried by calling get_update_fee(&vaas ).
146
146
public fun update_price_feeds (vaas: vector <vector <u8 >>, fee: Coin <AptosCoin >) {
147
+ // Charge the message update fee
148
+ assert !(get_update_fee (&vaas) <= coin::value (&fee), error::insufficient_fee ());
149
+ coin::deposit (@pyth , fee);
150
+
147
151
// Update the price feed from each VAA
148
152
while (!vector ::is_empty (&vaas)) {
149
153
update_price_feed_from_single_vaa (vector ::pop_back (&mut vaas));
150
154
};
151
-
152
- // Charge the message update fee
153
- assert !(get_update_fee () <= coin::value (&fee), error::insufficient_fee ());
154
- coin::deposit (@pyth , fee);
155
155
}
156
156
157
157
fun update_price_feed_from_single_vaa (vaa: vector <u8 >) {
@@ -198,7 +198,7 @@ module pyth::pyth {
198
198
vaas: vector <vector <u8 >>,
199
199
price_identifiers: vector <vector <u8 >>,
200
200
publish_times: vector <u64 >) {
201
- let coins = coin::withdraw <AptosCoin >(account, get_update_fee ());
201
+ let coins = coin::withdraw <AptosCoin >(account, get_update_fee (&vaas ));
202
202
update_price_feeds_if_fresh (vaas, price_identifiers, publish_times, coins);
203
203
}
204
204
@@ -361,9 +361,9 @@ module pyth::pyth {
361
361
price_info::get_price_feed (&state::get_latest_price_info (price_identifier)))
362
362
}
363
363
364
- /// Get the number of AptosCoin's required to perform one batch update
365
- public fun get_update_fee (): u64 {
366
- state::get_update_fee ( )
364
+ /// Get the number of AptosCoin's required to perform the given price updates.
365
+ public fun get_update_fee (update_data: & vector < vector < u8 >> ): u64 {
366
+ state::get_base_update_fee () * vector :: length (update_data )
367
367
}
368
368
369
369
// -----------------------------------------------------------------------------
@@ -450,6 +450,29 @@ module pyth::pyth {
450
450
/// - payload corresponding to the batch price attestation of the prices returned by get_mock_price_infos()
451
451
const TEST_VAAS: vector<vector<u8>> = vector[x"0100000000010036eb563b80a24f4253bee6150eb8924e4bdf6e4fa1dfc759a6664d2e865b4b134651a7b021b7f1ce3bd078070b688b6f2e37ce2de0d9b48e6a78684561e49d5201527e4f9b00000001001171f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b0000000000000001005032574800030000000102000400951436e0be37536be96f0896366089506a59763d036728332d3e3038047851aea7c6c75c89f14810ec1c54c03ab8f1864a4c4032791f05747f560faec380a695d1000000000000049a0000000000000008fffffffb00000000000005dc0000000000000003000000000100000001000000006329c0eb000000006329c0e9000000006329c0e400000000000006150000000000000007215258d81468614f6b7e194c5d145609394f67b041e93e6695dcc616faadd0603b9551a68d01d954d6387aff4df1529027ffb2fee413082e509feb29cc4904fe000000000000041a0000000000000003fffffffb00000000000005cb0000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e4000000000000048600000000000000078ac9cf3ab299af710d735163726fdae0db8465280502eb9f801f74b3c1bd190333832fad6e36eb05a8972fe5f219b27b5b2bb2230a79ce79beb4c5c5e7ecc76d00000000000003f20000000000000002fffffffb00000000000005e70000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e40000000000000685000000000000000861db714e9ff987b6fedf00d01f9fea6db7c30632d6fc83b7bc9459d7192bc44a21a28b4c6619968bd8c20e95b0aaed7df2187fd310275347e0376a2cd7427db800000000000006cb0000000000000001fffffffb00000000000005e40000000000000003010000000100000001000000006329c0eb000000006329c0e9000000006329c0e400000000000007970000000000000001"];
452
452
453
+ #[test(aptos_framework = @aptos_framework )]
454
+ fun test_get_update_fee (aptos_framework: &signer ) {
455
+ let single_update_fee = 50 ;
456
+ let (burn_capability, mint_capability, coins) = setup_test (aptos_framework, 500 , 23 , x"5d1f252d5de865279b00c84bce362774c2804294ed53299bc4a0389a5defef92 ", vector [], 50 , 0 );
457
+
458
+ // Pass in a single VAA
459
+ assert !(get_update_fee (&vector [
460
+ x"fb1543888001083cf2e6ef3afdcf827e89b11efd87c563638df6e1995ada9f93 ",
461
+ ]) == single_update_fee, 1 );
462
+
463
+ // Pass in multiple VAAs
464
+ assert !(get_update_fee (&vector [
465
+ x"4ee17a1a4524118de513fddcf82b77454e51be5d6fc9e29fc72dd6c204c0e4fa ",
466
+ x"c72fdf81cfc939d4286c93fbaaae2eec7bae28a5926fa68646b43a279846ccc1 ",
467
+ x"d9a8123a793529c31200339820a3210059ecace6c044f81ecad62936e47ca049 ",
468
+ x"84e4f21b3e65cef47fda25d15b4eddda1edf720a1d062ccbf441d6396465fbe6 ",
469
+ x"9e73f9041476a93701a0b9c7501422cc2aa55d16100bec628cf53e0281b6f72f "
470
+ ]) == 250 , 1 );
471
+
472
+ coin::destroy_zero (coins);
473
+ cleanup_test (burn_capability, mint_capability);
474
+ }
475
+
453
476
#[test(aptos_framework = @aptos_framework )]
454
477
#[expected_failure(abort_code = 6 )]
455
478
fun test_update_price_feeds_corrupt_vaa (aptos_framework: &signer ) {
@@ -534,7 +557,7 @@ module pyth::pyth {
534
557
coin::register <AptosCoin >(&funder);
535
558
coin::deposit (funder_addr, coins);
536
559
537
- assert !(get_update_fee () == update_fee, 1 );
560
+ assert !(get_update_fee (& TEST_VAAS ) == update_fee, 1 );
538
561
assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance, 1 );
539
562
assert !(coin::balance <AptosCoin >(@pyth ) == 0 , 1 );
540
563
@@ -545,10 +568,10 @@ module pyth::pyth {
545
568
check_price_feeds_cached (&get_mock_price_infos ());
546
569
547
570
// Check that the funder's balance has decreased by the update_fee amount
548
- assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance - get_update_fee (), 1 );
571
+ assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance - get_update_fee (& TEST_VAAS ), 1 );
549
572
550
573
// Check that the amount has been transferred to the Pyth contract
551
- assert !(coin::balance <AptosCoin >(@pyth ) == get_update_fee (), 1 );
574
+ assert !(coin::balance <AptosCoin >(@pyth ) == get_update_fee (& TEST_VAAS ), 1 );
552
575
553
576
cleanup_test (burn_capability, mint_capability);
554
577
}
@@ -566,7 +589,7 @@ module pyth::pyth {
566
589
coin::register <AptosCoin >(&funder);
567
590
coin::deposit (funder_addr, coins);
568
591
569
- assert !(get_update_fee () == update_fee, 1 );
592
+ assert !(get_update_fee (& TEST_VAAS ) == update_fee, 1 );
570
593
assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance, 1 );
571
594
assert !(coin::balance <AptosCoin >(@pyth ) == 0 , 1 );
572
595
@@ -820,7 +843,7 @@ module pyth::pyth {
820
843
coin::register <AptosCoin >(&funder);
821
844
coin::deposit (funder_addr, coins);
822
845
823
- assert !(get_update_fee () == update_fee, 1 );
846
+ assert !(get_update_fee (& TEST_VAAS ) == update_fee, 1 );
824
847
assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance, 1 );
825
848
assert !(coin::balance <AptosCoin >(@pyth ) == 0 , 1 );
826
849
@@ -841,10 +864,10 @@ module pyth::pyth {
841
864
check_price_feeds_cached (&get_mock_price_infos ());
842
865
843
866
// Check that the funder's balance has decreased by the update_fee amount
844
- assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance - get_update_fee (), 1 );
867
+ assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance - get_update_fee (& TEST_VAAS ), 1 );
845
868
846
869
// Check that the amount has been transferred to the Pyth contract
847
- assert !(coin::balance <AptosCoin >(@pyth ) == get_update_fee (), 1 );
870
+ assert !(coin::balance <AptosCoin >(@pyth ) == get_update_fee (& TEST_VAAS ), 1 );
848
871
849
872
cleanup_test (burn_capability, mint_capability);
850
873
}
@@ -887,7 +910,7 @@ module pyth::pyth {
887
910
coin::register <AptosCoin >(&funder);
888
911
coin::deposit (funder_addr, coins);
889
912
890
- assert !(get_update_fee () == update_fee, 1 );
913
+ assert !(get_update_fee (& TEST_VAAS ) == update_fee, 1 );
891
914
assert !(coin::balance <AptosCoin >(signer ::address_of (&funder)) == initial_balance, 1 );
892
915
assert !(coin::balance <AptosCoin >(@pyth ) == 0 , 1 );
893
916
0 commit comments