|
|
@@ -1,22 +1,22 @@
|
|
|
use fuels::{
|
|
|
accounts::wallet::WalletUnlocked,
|
|
|
prelude::{Bytes, CallParameters, TxPolicies},
|
|
|
- programs::call_response::FuelCallResponse,
|
|
|
- types::errors::Error,
|
|
|
+ programs::responses::CallResponse,
|
|
|
types::Bits256,
|
|
|
};
|
|
|
|
|
|
-use pyth_sdk::pyth_utils::{Price, PriceFeed, PythOracleContract};
|
|
|
+use pyth_sdk::pyth_utils::{handle_error, Price, PriceFeed, PythOracleContract};
|
|
|
|
|
|
pub(crate) async fn ema_price(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.ema_price(price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
@@ -24,24 +24,26 @@ pub(crate) async fn ema_price_no_older_than(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
time_period: u64,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.ema_price_no_older_than(time_period, price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn ema_price_unsafe(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.ema_price_unsafe(price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
@@ -52,7 +54,7 @@ pub(crate) async fn parse_price_feed_updates(
|
|
|
min_publish_time: u64,
|
|
|
price_feed_ids: Vec<Bits256>,
|
|
|
update_data: Vec<Bytes>,
|
|
|
-) -> FuelCallResponse<Vec<PriceFeed>> {
|
|
|
+) -> CallResponse<Vec<PriceFeed>> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.parse_price_feed_updates(
|
|
|
@@ -66,18 +68,20 @@ pub(crate) async fn parse_price_feed_updates(
|
|
|
.unwrap()
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn price(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.price(price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
@@ -85,36 +89,39 @@ pub(crate) async fn price_no_older_than(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
time_period: u64,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.price_no_older_than(time_period, price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn price_unsafe(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
price_feed_id: Bits256,
|
|
|
-) -> FuelCallResponse<Price> {
|
|
|
+) -> CallResponse<Price> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.price_unsafe(price_feed_id)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn update_fee(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
update_data: Vec<Bytes>,
|
|
|
-) -> FuelCallResponse<u64> {
|
|
|
+) -> CallResponse<u64> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.update_fee(update_data)
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
@@ -122,7 +129,7 @@ pub(crate) async fn update_price_feeds(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
fee: u64,
|
|
|
update_data: Vec<Bytes>,
|
|
|
-) -> Result<FuelCallResponse<()>, Error> {
|
|
|
+) -> CallResponse<()> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.update_price_feeds(update_data)
|
|
|
@@ -130,6 +137,8 @@ pub(crate) async fn update_price_feeds(
|
|
|
.unwrap()
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
+ .unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn update_price_feeds_if_necessary(
|
|
|
@@ -138,7 +147,7 @@ pub(crate) async fn update_price_feeds_if_necessary(
|
|
|
price_feed_ids: Vec<Bits256>,
|
|
|
publish_times: Vec<u64>,
|
|
|
update_data: Vec<Bytes>,
|
|
|
-) -> FuelCallResponse<()> {
|
|
|
+) -> CallResponse<()> {
|
|
|
contract
|
|
|
.methods()
|
|
|
.update_price_feeds_if_necessary(price_feed_ids, publish_times, update_data)
|
|
|
@@ -146,11 +155,18 @@ pub(crate) async fn update_price_feeds_if_necessary(
|
|
|
.unwrap()
|
|
|
.call()
|
|
|
.await
|
|
|
+ .map_err(handle_error)
|
|
|
.unwrap()
|
|
|
}
|
|
|
|
|
|
pub(crate) async fn valid_time_period(
|
|
|
contract: &PythOracleContract<WalletUnlocked>,
|
|
|
-) -> FuelCallResponse<u64> {
|
|
|
- contract.methods().valid_time_period().call().await.unwrap()
|
|
|
+) -> CallResponse<u64> {
|
|
|
+ contract
|
|
|
+ .methods()
|
|
|
+ .valid_time_period()
|
|
|
+ .call()
|
|
|
+ .await
|
|
|
+ .map_err(handle_error)
|
|
|
+ .unwrap()
|
|
|
}
|