Post
Share your knowledge.
what is pyth oracle?
I know Pyth is an a oracle that gives price feeds. but does anybody here worked with Pyth in Move contracts?
- Sui
- Architecture
Answers
8pyth hasn't deployed the contract to sui testnet/devnet yet. omnibtc's omnilending is a omnichain lending product with sui as the settlement center. Only Oracle on sui can be used to clear debts, and as many Oracle as possible is needed to avoid single point risk. omnibtc's omnilending has already been developed, except for the Oracle integration piece. Oracle deployed in sui test network has not been found. Therefore, Oracle that can be used on devnet is sought to debug the lending business of omnibtc
But if you want reference:
#[test_only]
module protocol_test::oracle_t {
use sui::math;
use sui::test_scenario::{Self, Scenario};
use x_oracle::x_oracle::{Self, XOracle, XOraclePolicyCap};
public fun init_t(scenario: &mut Scenario): (XOracle, XOraclePolicyCap) {
x_oracle::init_t(test_scenario::ctx(scenario));
let sender = test_scenario::sender(scenario);
test_scenario::next_tx(scenario, sender);
(test_scenario::take_shared<XOracle>(scenario), test_scenario::take_from_address<XOraclePolicyCap>(scenario, sender))
}
public fun calc_scaled_price(scaled_price: u64, decimals: u8): u64 {
assert!(decimals <= 9, 1);
// the oracle price_feed need a scaled price with 9 decimals
scaled_price * math::pow(10, 9 - decimals)
}
}
Pyth Oracle is a decentralized system that delivers real-time, accurate price data for assets like cryptocurrencies, stocks, forex, and commodities to smart contracts across over 100 blockchains. You can think of it as a bridge connecting real-world market data from trusted sources, like major exchanges and financial firms, to blockchain applications. It uses a pull-based model, meaning you request the latest price when needed, which keeps costs low and data fresh. This makes it ideal for DeFi apps needing reliable, up-to-date pricing for trading, lending, or other financial operations. Read more
Yeah, definitely! Pyth has a native integration for Sui, which is great. You'd work with the pyth Move package to fetch and verify price feeds directly in your contracts, usually by consuming PriceFeed objects. It's pretty well-supported.
Pyth is a blockchain oracle that delivers real-time price feeds, especially for assets like cryptocurrencies, stocks, and commodities. When using Pyth in Sui Move contracts, you're accessing externally sourced pricing data that has been aggregated and verified before being pushed on-chain. If you're building a DeFi protocol or any application that relies on external asset prices, you can use Pyth's price feed module to fetch values during your transaction execution. While Pyth isn't deeply integrated into Move by default, Sui provides support for Pyth through custom modules published to mainnet/testnet, like 0x2::pyth, and you’ll often need to interact with those by referencing the price feed’s object ID and ensuring proper module imports. You should be cautious of stale data or missing updates if you're not verifying the freshness of the feed during execution. To explore how to integrate Pyth in your Move contracts and access sample code, check out the docs: https://docs.pyth.network/documentation/pythnet-price-feeds/consuming-price-feeds/using-pyth-on-sui.
Pyth Oracle is a decentralized price oracle that delivers real-time market data (like crypto, stocks, FX, commodities) directly on-chain from first-party sources (exchanges, market makers). It's known for high-frequency, low-latency updates and is widely used in DeFi protocols for price accuracy and reliability.
On Sui, Pyth is integrated via its own smart contract modules, allowing developers to fetch verified price data directly in Move. Unlike off-chain oracles like Chainlink (which rely on pushing data into chains), Pyth typically follows a "pull + attest" model, where:
-
Price publishers submit prices to a Pythnet off-chain.
-
Consumers (e.g., a front end or keeper) submit those updates to the chain using a price update payload.
-
Your Move contract verifies the payload using the on-chain Pyth contract module.
Key Concepts When Working with Pyth in Move:
-
Price Feed IDs: Each asset has a unique ID (a hex identifier) used to fetch its price.
-
Update Price Data: Clients post price updates (payloads) to the Sui blockchain.
-
Verification Logic: The Pyth module verifies signatures and validity inside your contract call.
-
Pull-and-Verify Flow:
Off-chain service fetches the latest price data and sends a signed update.
The update is included in the transaction calling your contract.
Your Move contract uses the pyth::price_feed module to verify and extract the price.
Example Integration Steps:
- Import Pyth module in your Move package:
use 0xYourPythAddress::price_feed;
- Use a function to read a verified price:
public fun get_price(update: &PythPriceUpdate, clock: &Clock): u64 { let price = price_feed::read_price(update, clock); price.price }
Where PythPriceUpdate is the verified payload passed during the transaction.
CLI Use
You often use the Pyth SDK (Python/TS) to generate the update payload:
pyth-client get-update --price-id 0x... --output update.json
Then use Sui CLI to call your smart contract with the update.
Common Pitfalls
Outdated Prices: Always check the timestamp and confidence interval.
Missing Publisher Signatures: Payloads must be signed by quorum of data publishers.
Clock Object: You need to pass a Sui Clock object to verify freshness.
Storage Costs: Large payloads might inflate gas if not optimized.
Use Cases
Liquidations in Perp DEXs
NFT floor price feeds
Governance-controlled rebalancing
On-chain margining and LP pricing
Let me know if you want a template contract that integrates Pyth on Sui or need testnet Price Feed IDs.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410