use near_sdk::serde_json::json; use near_workspaces::{Account, Contract}; use templar_common::oracle::pyth::{self, OracleResponse, PriceIdentifier}; use tokio::sync::OnceCell; use crate::{define, get_contract}; use super::ContractController; #[derive(Clone)] pub struct OracleController { pub contract: Contract, } impl ContractController for OracleController { fn contract(&self) -> &Contract { &self.contract } } impl OracleController { pub async fn deploy(account: Account) -> Self { static WASM_MOCK_ORACLE: OnceCell> = OnceCell::const_new(); let wasm = WASM_MOCK_ORACLE .get_or_init(|| get_contract("mock_oracle", "mock/oracle")) .await; let contract = account.deploy(wasm).await.unwrap().unwrap(); contract .call("new") .args_json(json!({})) .transact() .await .unwrap() .unwrap(); Self { contract } } define! { #[view] pub fn list_ema_prices_no_older_than(price_ids: Vec, age: u32) -> OracleResponse; #[call] pub fn set_price(price_identifier: PriceIdentifier, price: pyth::Price); } }