Skip to content

fix: fuel example #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pages/price-feeds/use-real-time-data/fuel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,34 @@ abi UpdatePrice {
fn update_price_feeds(update_fee: u64, update_data: Vec<Bytes>);
}

const PYTH_CONTRACT_ID = 0x1ab91bc1402a187055d3e827017ace566a103ce2a4126517da5d656d6a436aea; // Testnet Contract
const PYTH_MAINNET_CONTRACT_ID = 0x1c86fdd9e0e7bc0d2ae1bf6817ef4834ffa7247655701ee1b031b52a24c523da; // Mainnet Contract
const PYTH_TESTNET_CONTRACT_ID = 0x25146735b29d4216639f7f8b1d7b921ff87a1d3051de62d6cceaacabeb33b8e7; // Testnet Contract
const FUEL_ETH_BASE_ASSET_ID = 0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07;

impl UpdatePrice for Contract {
fn valid_time_period() -> u64 {
let pyth_contract = abi(PythCore, PYTH_CONTRACT_ID);
let pyth_contract = abi(PythCore, PYTH_MAINNET_CONTRACT_ID);
let period = pyth_contract.valid_time_period();
period
}
fn get_price(price_feed_id: PriceFeedId) -> Price {
let pyth_contract = abi(PythCore, PYTH_CONTRACT_ID);
let pyth_contract = abi(PythCore, PYTH_MAINNET_CONTRACT_ID);
let price = pyth_contract.price(price_feed_id);
price
}
fn get_price_unsafe(price_feed_id: PriceFeedId) -> Price {
let pyth_contract = abi(PythCore, PYTH_CONTRACT_ID);
let pyth_contract = abi(PythCore, PYTH_MAINNET_CONTRACT_ID);
let price = pyth_contract.price_unsafe(price_feed_id);
price
}
fn update_fee(update_data: Vec<Bytes>) -> u64 {
let pyth_contract = abi(PythCore, PYTH_CONTRACT_ID);
let pyth_contract = abi(PythCore, PYTH_MAINNET_CONTRACT_ID);
let fee = pyth_contract.update_fee(update_data);
fee
}
#[payable]
fn update_price_feeds(update_fee: u64, update_data: Vec<Bytes>) {
let pyth_contract = abi(PythCore, PYTH_CONTRACT_ID);
let pyth_contract = abi(PythCore, PYTH_MAINNET_CONTRACT_ID);
pyth_contract
.update_price_feeds {
asset_id: FUEL_ETH_BASE_ASSET_ID,
Expand Down Expand Up @@ -101,7 +102,7 @@ The code snippet above does the following things:
- `update_fee(update_data)`: Calculates the fee required to update the price feeds.
- `update_price_feeds(update_fee, update_data)`: Updates the price feeds with the provided data and fee.

3. Uses the `PYTH_CONTRACT_ID` constant to interact with the Pyth contract on testnet.
3. Uses the `PYTH_MAINNET_CONTRACT_ID` constant to interact with the Pyth contract on testnet.
4. Uses the `FUEL_ETH_BASE_ASSET_ID` constant as the asset ID for paying update fees.

To use this contract, you would typically:
Expand Down
Loading