|
|
@@ -9,8 +9,8 @@ use cosmwasm_std::{
|
|
|
QueryRequest,
|
|
|
Response,
|
|
|
StdResult,
|
|
|
- WasmQuery,
|
|
|
Timestamp,
|
|
|
+ WasmQuery,
|
|
|
};
|
|
|
|
|
|
use pyth_sdk::{
|
|
|
@@ -23,8 +23,8 @@ use crate::{
|
|
|
ExecuteMsg,
|
|
|
InstantiateMsg,
|
|
|
MigrateMsg,
|
|
|
- QueryMsg,
|
|
|
PriceFeedResponse,
|
|
|
+ QueryMsg,
|
|
|
},
|
|
|
state::{
|
|
|
config,
|
|
|
@@ -37,16 +37,12 @@ use crate::{
|
|
|
},
|
|
|
};
|
|
|
|
|
|
-use p2w_sdk::{
|
|
|
- BatchPriceAttestation,
|
|
|
-};
|
|
|
+use p2w_sdk::BatchPriceAttestation;
|
|
|
|
|
|
use wormhole::{
|
|
|
error::ContractError,
|
|
|
msg::QueryMsg as WormholeQueryMsg,
|
|
|
- state::{
|
|
|
- ParsedVAA,
|
|
|
- },
|
|
|
+ state::ParsedVAA,
|
|
|
};
|
|
|
|
|
|
#[cfg_attr(not(feature = "library"), entry_point)]
|
|
|
@@ -130,18 +126,18 @@ fn process_batch_attestation(
|
|
|
let price_feed = PriceFeed::new(
|
|
|
price_attestation.price_id.to_bytes(),
|
|
|
price_attestation.status,
|
|
|
- price_attestation.publish_time,
|
|
|
+ price_attestation.publish_time,
|
|
|
price_attestation.expo,
|
|
|
- price_attestation.max_num_publishers, // max_num_publishers data is currently unavailable
|
|
|
- price_attestation.num_publishers, // num_publishers data is currently unavailable
|
|
|
+ price_attestation.max_num_publishers,
|
|
|
+ price_attestation.num_publishers,
|
|
|
price_attestation.product_id.to_bytes(),
|
|
|
price_attestation.price,
|
|
|
price_attestation.conf,
|
|
|
price_attestation.ema_price,
|
|
|
price_attestation.ema_conf,
|
|
|
- price_attestation.prev_price,
|
|
|
- price_attestation.prev_conf,
|
|
|
- price_attestation.prev_publish_time,
|
|
|
+ price_attestation.prev_price,
|
|
|
+ price_attestation.prev_conf,
|
|
|
+ price_attestation.prev_publish_time,
|
|
|
);
|
|
|
|
|
|
let attestation_time = Timestamp::from_seconds(price_attestation.attestation_time as u64);
|
|
|
@@ -161,8 +157,8 @@ fn process_batch_attestation(
|
|
|
}
|
|
|
|
|
|
/// Returns true if the price_feed is newer than the stored one.
|
|
|
-///
|
|
|
-/// This function returns error only if there be issues in ser/de when it reads from the bucket. Such an example would be
|
|
|
+///
|
|
|
+/// This function returns error only if there be issues in ser/de when it reads from the bucket. Such an example would be
|
|
|
/// upgrades which migration is not handled carefully so the binary stored in the bucket won't be parsed.
|
|
|
fn update_price_feed_if_new(
|
|
|
deps: &mut DepsMut,
|
|
|
@@ -205,9 +201,7 @@ fn update_price_feed_if_new(
|
|
|
#[cfg_attr(not(feature = "library"), entry_point)]
|
|
|
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
|
|
match msg {
|
|
|
- QueryMsg::PriceFeed { id } => {
|
|
|
- to_binary(&query_price_info(deps, env, id.as_ref())?)
|
|
|
- }
|
|
|
+ QueryMsg::PriceFeed { id } => to_binary(&query_price_info(deps, env, id.as_ref())?),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -222,21 +216,20 @@ pub fn query_price_info(deps: Deps, env: Env, address: &[u8]) -> StdResult<Price
|
|
|
// but more than that is set to unknown, the reason is huge clock difference means there exists a
|
|
|
// problem in a either Terra or Solana blockchain and if it is Solana we don't want to propagate
|
|
|
// Solana internal problems to Terra
|
|
|
- let time_abs_diff = if env.block.time.seconds() > terra_price_info.attestation_time.seconds() {
|
|
|
- env.block.time.seconds() - terra_price_info.attestation_time.seconds()
|
|
|
- } else {
|
|
|
- terra_price_info.attestation_time.seconds() - env.block.time.seconds()
|
|
|
- };
|
|
|
+ let time_abs_diff =
|
|
|
+ if env.block.time.seconds() > terra_price_info.attestation_time.seconds() {
|
|
|
+ env.block.time.seconds() - terra_price_info.attestation_time.seconds()
|
|
|
+ } else {
|
|
|
+ terra_price_info.attestation_time.seconds() - env.block.time.seconds()
|
|
|
+ };
|
|
|
|
|
|
if time_abs_diff > VALID_TIME_PERIOD.as_secs() {
|
|
|
terra_price_info.price_feed.status = PriceStatus::Unknown;
|
|
|
}
|
|
|
|
|
|
- Ok(
|
|
|
- PriceFeedResponse {
|
|
|
- price_feed: terra_price_info.price_feed,
|
|
|
- }
|
|
|
- )
|
|
|
+ Ok(PriceFeedResponse {
|
|
|
+ price_feed: terra_price_info.price_feed,
|
|
|
+ })
|
|
|
}
|
|
|
Err(_) => ContractError::AssetNotFound.std_err(),
|
|
|
}
|
|
|
@@ -283,7 +276,7 @@ mod test {
|
|
|
price_feed
|
|
|
}
|
|
|
|
|
|
- /// Updates the price feed with the given attestation time stamp and
|
|
|
+ /// Updates the price feed with the given attestation time stamp and
|
|
|
/// returns the update status (true means updated, false means ignored)
|
|
|
fn do_update_price_feed(
|
|
|
deps: &mut DepsMut,
|