|
|
@@ -53,8 +53,8 @@ use pyth_interface::{
|
|
|
WormholeGuardians,
|
|
|
};
|
|
|
|
|
|
-use sway_libs::ownership::*;
|
|
|
-use standards::src5::{SRC5, State};
|
|
|
+use ownership::*;
|
|
|
+use src5::{SRC5, State};
|
|
|
|
|
|
const GUARDIAN_SET_EXPIRATION_TIME_SECONDS: u64 = 86400; // 24 hours in seconds
|
|
|
configurable {
|
|
|
@@ -209,7 +209,7 @@ impl PythCore for Contract {
|
|
|
while i_2 < number_of_attestations {
|
|
|
let (_, slice) = vm.payload.split_at(attestation_index + 32);
|
|
|
let (price_feed_id, _) = slice.split_at(32);
|
|
|
- let price_feed_id: PriceFeedId = price_feed_id.into();
|
|
|
+ let price_feed_id: PriceFeedId = b256::from_le_bytes(price_feed_id.clone());
|
|
|
|
|
|
if price_feed_id.is_target(target_price_feed_ids) == false {
|
|
|
attestation_index += attestation_size_u16;
|
|
|
@@ -272,7 +272,56 @@ impl PythCore for Contract {
|
|
|
|
|
|
#[storage(read, write), payable]
|
|
|
fn update_price_feeds(update_data: Vec<Bytes>) {
|
|
|
- update_price_feeds(update_data)
|
|
|
+ require(
|
|
|
+ msg_asset_id() == AssetId::base(),
|
|
|
+ PythError::FeesCanOnlyBePaidInTheBaseAsset,
|
|
|
+ );
|
|
|
+
|
|
|
+ let mut total_number_of_updates = 0;
|
|
|
+
|
|
|
+ // let mut updated_price_feeds: Vec<PriceFeedId> = Vec::new(); // TODO: requires append for Vec
|
|
|
+ let mut i = 0;
|
|
|
+ while i < update_data.len() {
|
|
|
+ let data = update_data.get(i).unwrap();
|
|
|
+
|
|
|
+ match UpdateType::determine_type(data) {
|
|
|
+ UpdateType::Accumulator(accumulator_update) => {
|
|
|
+ let (number_of_updates, _updated_ids) = accumulator_update.update_price_feeds(
|
|
|
+ current_guardian_set_index(),
|
|
|
+ storage
|
|
|
+ .wormhole_guardian_sets,
|
|
|
+ storage
|
|
|
+ .latest_price_feed,
|
|
|
+ storage
|
|
|
+ .is_valid_data_source,
|
|
|
+ );
|
|
|
+ // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
+ total_number_of_updates += number_of_updates;
|
|
|
+ },
|
|
|
+ UpdateType::BatchAttestation(batch_attestation_update) => {
|
|
|
+ let _updated_ids = batch_attestation_update.update_price_feeds(
|
|
|
+ current_guardian_set_index(),
|
|
|
+ storage
|
|
|
+ .wormhole_guardian_sets,
|
|
|
+ storage
|
|
|
+ .latest_price_feed,
|
|
|
+ storage
|
|
|
+ .is_valid_data_source,
|
|
|
+ );
|
|
|
+ // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
+ total_number_of_updates += 1;
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ i += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ let required_fee = total_fee(total_number_of_updates, storage.single_update_fee);
|
|
|
+ require(msg_amount() >= required_fee, PythError::InsufficientFee);
|
|
|
+
|
|
|
+ // log(UpdatedPriceFeedsEvent { // TODO: requires append for Vec
|
|
|
+ // updated_price_feeds,
|
|
|
+ // })
|
|
|
}
|
|
|
|
|
|
#[storage(read, write), payable]
|
|
|
@@ -292,7 +341,56 @@ impl PythCore for Contract {
|
|
|
while i < price_feed_ids.len() {
|
|
|
if latest_publish_time(price_feed_ids.get(i).unwrap()) < publish_times.get(i).unwrap()
|
|
|
{
|
|
|
- update_price_feeds(update_data);
|
|
|
+ require(
|
|
|
+ msg_asset_id() == AssetId::base(),
|
|
|
+ PythError::FeesCanOnlyBePaidInTheBaseAsset,
|
|
|
+ );
|
|
|
+
|
|
|
+ let mut total_number_of_updates = 0;
|
|
|
+
|
|
|
+ // let mut updated_price_feeds: Vec<PriceFeedId> = Vec::new(); // TODO: requires append for Vec
|
|
|
+ let mut i = 0;
|
|
|
+ while i < update_data.len() {
|
|
|
+ let data = update_data.get(i).unwrap();
|
|
|
+
|
|
|
+ match UpdateType::determine_type(data) {
|
|
|
+ UpdateType::Accumulator(accumulator_update) => {
|
|
|
+ let (number_of_updates, _updated_ids) = accumulator_update.update_price_feeds(
|
|
|
+ current_guardian_set_index(),
|
|
|
+ storage
|
|
|
+ .wormhole_guardian_sets,
|
|
|
+ storage
|
|
|
+ .latest_price_feed,
|
|
|
+ storage
|
|
|
+ .is_valid_data_source,
|
|
|
+ );
|
|
|
+ // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
+ total_number_of_updates += number_of_updates;
|
|
|
+ },
|
|
|
+ UpdateType::BatchAttestation(batch_attestation_update) => {
|
|
|
+ let _updated_ids = batch_attestation_update.update_price_feeds(
|
|
|
+ current_guardian_set_index(),
|
|
|
+ storage
|
|
|
+ .wormhole_guardian_sets,
|
|
|
+ storage
|
|
|
+ .latest_price_feed,
|
|
|
+ storage
|
|
|
+ .is_valid_data_source,
|
|
|
+ );
|
|
|
+ // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
+ total_number_of_updates += 1;
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ i += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ let required_fee = total_fee(total_number_of_updates, storage.single_update_fee);
|
|
|
+ require(msg_amount() >= required_fee, PythError::InsufficientFee);
|
|
|
+
|
|
|
+ // log(UpdatedPriceFeedsEvent { // TODO: requires append for Vec
|
|
|
+ // updated_price_feeds,
|
|
|
+ // })
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -374,60 +472,6 @@ fn update_fee(update_data: Vec<Bytes>) -> u64 {
|
|
|
total_fee(total_number_of_updates, storage.single_update_fee)
|
|
|
}
|
|
|
|
|
|
-#[storage(read, write), payable]
|
|
|
-fn update_price_feeds(update_data: Vec<Bytes>) {
|
|
|
- require(
|
|
|
- msg_asset_id() == AssetId::base(),
|
|
|
- PythError::FeesCanOnlyBePaidInTheBaseAsset,
|
|
|
- );
|
|
|
-
|
|
|
- let mut total_number_of_updates = 0;
|
|
|
-
|
|
|
- // let mut updated_price_feeds: Vec<PriceFeedId> = Vec::new(); // TODO: requires append for Vec
|
|
|
- let mut i = 0;
|
|
|
- while i < update_data.len() {
|
|
|
- let data = update_data.get(i).unwrap();
|
|
|
-
|
|
|
- match UpdateType::determine_type(data) {
|
|
|
- UpdateType::Accumulator(accumulator_update) => {
|
|
|
- let (number_of_updates, _updated_ids) = accumulator_update.update_price_feeds(
|
|
|
- current_guardian_set_index(),
|
|
|
- storage
|
|
|
- .wormhole_guardian_sets,
|
|
|
- storage
|
|
|
- .latest_price_feed,
|
|
|
- storage
|
|
|
- .is_valid_data_source,
|
|
|
- );
|
|
|
- // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
- total_number_of_updates += number_of_updates;
|
|
|
- },
|
|
|
- UpdateType::BatchAttestation(batch_attestation_update) => {
|
|
|
- let _updated_ids = batch_attestation_update.update_price_feeds(
|
|
|
- current_guardian_set_index(),
|
|
|
- storage
|
|
|
- .wormhole_guardian_sets,
|
|
|
- storage
|
|
|
- .latest_price_feed,
|
|
|
- storage
|
|
|
- .is_valid_data_source,
|
|
|
- );
|
|
|
- // updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
|
|
|
- total_number_of_updates += 1;
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
- i += 1;
|
|
|
- }
|
|
|
-
|
|
|
- let required_fee = total_fee(total_number_of_updates, storage.single_update_fee);
|
|
|
- require(msg_amount() >= required_fee, PythError::InsufficientFee);
|
|
|
-
|
|
|
- // log(UpdatedPriceFeedsEvent { // TODO: requires append for Vec
|
|
|
- // updated_price_feeds,
|
|
|
- // })
|
|
|
-}
|
|
|
-
|
|
|
#[storage(read)]
|
|
|
fn valid_time_period() -> u64 {
|
|
|
storage.valid_time_period_seconds.read()
|