Jayant Krishnamurthy 2 anos atrás
pai
commit
d0bf466cfe

+ 0 - 2
cosmwasm/Cargo.lock

@@ -1272,7 +1272,6 @@ dependencies = [
  "hex",
  "k256 0.9.6",
  "lazy_static",
- "p2w-sdk",
  "pyth-sdk-cw",
  "schemars",
  "serde",
@@ -1281,7 +1280,6 @@ dependencies = [
  "sha3",
  "terraswap",
  "thiserror",
- "wormhole-bridge-terra-2",
 ]
 
 [[package]]

+ 0 - 2
cosmwasm/example/contract/Cargo.toml

@@ -20,7 +20,6 @@ schemars = "0.8.1"
 serde = { version = "1.0.103", default-features = false, features = ["derive"] }
 serde_derive = { version = "1.0.103"}
 terraswap = "2.4.0"
-wormhole-bridge-terra-2 = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.8.9", features = ["library"] }
 thiserror = { version = "1.0.20" }
 k256 = { version = "0.9.4", default-features = false, features = ["ecdsa"] }
 sha3 = { version = "0.9.1", default-features = false }
@@ -28,7 +27,6 @@ generic-array = { version = "0.14.4" }
 hex = "0.4.2"
 lazy_static = "1.4.0"
 bigint = "4"
-p2w-sdk = { path = "../../../third_party/pyth/p2w-sdk/rust" }
 pyth-sdk-cw = "0.2.0"
 byteorder = "1.4.3"
 

+ 16 - 11
cosmwasm/example/contract/src/contract.rs

@@ -47,10 +47,14 @@ pub fn instantiate(
     _info: MessageInfo,
     msg: InstantiateMsg,
 ) -> StdResult<Response> {
-    // Save general wormhole and pyth info
     let state = ConfigInfo {
-        pyth_contract:   msg.pyth_contract,
-        price_feed_id:   msg.price_feed_id,
+        // Store the pyth contract address and the id of the desired price feed in the config.
+        // These fields will be used to query the pyth contract when we need the price.
+        pyth_contract: msg.pyth_contract,
+        price_feed_id: msg.price_feed_id,
+
+        // TODO: fix the docs
+        // Store the price of the token in usd.
         price_in_usd:    msg.price_in_usd,
         target_exponent: msg.target_exponent,
     };
@@ -71,7 +75,7 @@ pub fn execute(
 }
 
 #[cfg_attr(not(feature = "library"), entry_point)]
-pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
+pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
     match msg {
         // user wants to purchase `quantity` of the token. They need to pay
         QueryMsg::GetPrice { quantity } => {
@@ -82,7 +86,13 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
                 expo:  0,
             };
 
-            let feed = read_pyth_price(&deps, &env)?;
+            // Call the query_price_feed function from the Pyth SDK to get the current value of the
+            // configured price feed.
+            // FIXME: this function on the sdk needs some &'s to prevent copying
+            let feed =
+                query_price_feed(&deps.querier, cfg.pyth_contract.clone(), cfg.price_feed_id)?
+                    .price_feed;
+
             // Value of token in USD, e.g, 1BTC = $10k
             let current_token_price = feed
                 .get_current_price()
@@ -102,11 +112,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
     }
 }
 
-pub fn read_pyth_price(deps: &Deps, _env: &Env) -> StdResult<PriceFeed> {
-    let cfg = config_read(deps.storage).load()?;
-    query_price_feed(&deps.querier, cfg.pyth_contract, cfg.price_feed_id).map(|r| r.price_feed)
-}
-
 #[cfg(test)]
 mod test {
     use {
@@ -127,7 +132,7 @@ mod test {
             SystemError,
             SystemResult,
         },
-        p2w_sdk::PriceStatus,
+        pyth_sdk_cw::PriceStatus,
     };
 
     // TODO: point to documentation

+ 0 - 55
cosmwasm/example/contract/src/error.rs

@@ -1,55 +0,0 @@
-use {
-    cosmwasm_std::StdError,
-    thiserror::Error,
-};
-
-#[derive(Error, Debug)]
-pub enum PythContractError {
-    /// Message sender not permitted to execute this operation
-    #[error("PermissionDenied")]
-    PermissionDenied,
-
-    /// Wrapped asset not found in the registry
-    #[error("PriceFeedNotFound")]
-    PriceFeedNotFound,
-
-    /// Message emitter is not an accepted data source.
-    #[error("InvalidUpdateMessageEmitter")]
-    InvalidUpdateEmitter,
-
-    /// Message payload cannot be deserialized to a batch attestation
-    #[error("InvalidUpdatePayload")]
-    InvalidUpdatePayload,
-
-    /// Data source does not exists error (on removing data source)
-    #[error("DataSourceDoesNotExists")]
-    DataSourceDoesNotExists,
-
-    /// Data source already exists error (on adding data source)
-    #[error("DataSourceAlreadyExists")]
-    DataSourceAlreadyExists,
-
-    /// Message emitter is not an accepted source of governance instructions.
-    #[error("InvalidGovernanceEmitter")]
-    InvalidGovernanceEmitter,
-
-    /// Message payload cannot be deserialized as a valid governance instruction.
-    #[error("InvalidGovernancePayload")]
-    InvalidGovernancePayload,
-
-    /// The sequence number of the governance message is too old.
-    #[error("OldGovernanceMessage")]
-    OldGovernanceMessage,
-
-    /// The message did not include a sufficient fee.
-    #[error("InsufficientFee")]
-    InsufficientFee,
-}
-
-impl From<PythContractError> for StdError {
-    fn from(other: PythContractError) -> StdError {
-        StdError::GenericErr {
-            msg: format!("{other}"),
-        }
-    }
-}

+ 0 - 1
cosmwasm/example/contract/src/lib.rs

@@ -2,6 +2,5 @@
 extern crate lazy_static;
 
 pub mod contract;
-pub mod error;
 pub mod msg;
 pub mod state;