#cosmwasm #oracle #pyth

pyth-sdk-cw

Data structures and utilites for the Pyth price oracle

5 releases (2 stable)

1.2.0 May 18, 2023
1.0.0 Feb 14, 2023
0.3.0 Dec 7, 2022
0.2.0 Aug 18, 2022
0.1.0 Jul 14, 2022

#7 in #pyth

Download history 157/week @ 2024-03-13 110/week @ 2024-03-20 78/week @ 2024-03-27 104/week @ 2024-04-03 147/week @ 2024-04-10 196/week @ 2024-04-17 145/week @ 2024-04-24 110/week @ 2024-05-01 78/week @ 2024-05-08 80/week @ 2024-05-15 118/week @ 2024-05-22 155/week @ 2024-05-29 192/week @ 2024-06-05 136/week @ 2024-06-12 178/week @ 2024-06-19 106/week @ 2024-06-26

655 downloads per month
Used in 9 crates (2 directly)

Apache-2.0

12KB
214 lines

Pyth SDK CW

This crate exposes utilities to interact with the contract on the CosmWasm ecosystem. You can also look at the example contract which demonstrates how to read price feeds from on-chain CosmWasm applications.

Installation

Add this crate to the dependencies section of your CosmWasm contract's Cargo.toml file:

[dependencies]
pyth-sdk-cw = "1.0.0"

Usage

Simply import the structs exposed by the crate and use them while interacting with the pyth contract. For example:

// to query Pyth contract
use pyth_sdk_cw::{
    PriceFeedResponse,
    query_price_feed,
};

... {
    let price_feed_response: PriceFeedResponse = query_price_feed(&deps.querier, state.pyth_contract_addr, state.price_feed_id)?;
    let price_feed = price_feed_response.price_feed;
}
....

This snippet returns a PriceFeed struct which exposes methods for reading the current price along with other useful functionality. See the Pyth common SDK documentation for more information about this struct. The common SDK also provides methods for combining price feeds in several useful ways. These methods allow you to derive prices for alternative quote currencies -- for example, to derive the BTC/ETH price from the BTC/USD and ETH/USD price feeds -- and to price baskets of currencies.

Contracts and Price Feeds

Pyth is currently available on the following cosmwasm chains:

Testnet

Network Contract address
Injective inj1z60tg0tekdzcasenhuuwq3htjcd5slmgf7gpez

Available price feeds on these networks can be find below:

Price Feeds

Network Available Price Feeds
Injective Testnet https://pyth.network/developers/price-feed-ids#injective-testnet

Dependencies

~4.5–6.5MB
~130K SLoC