From ada0ce5adda80b68556e9cc85024c6b930e6f79b Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Mon, 10 Jun 2024 14:15:42 -0400 Subject: [PATCH 1/9] Initial commit --- .../price-feeds/use-real-time-data/_meta.json | 1 + .../use-real-time-data/starknet.mdx | 210 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 pages/price-feeds/use-real-time-data/starknet.mdx diff --git a/pages/price-feeds/use-real-time-data/_meta.json b/pages/price-feeds/use-real-time-data/_meta.json index 6d05fb8c..7b8848f7 100644 --- a/pages/price-feeds/use-real-time-data/_meta.json +++ b/pages/price-feeds/use-real-time-data/_meta.json @@ -1,6 +1,7 @@ { "evm": "in EVM Contracts", "solana": "in Solana and SVM Programs", + "starknet": "in Starknet Contracts", "aptos": "in Aptos Contracts", "sui": "in Sui Contracts", "cosmwasm": "in CosmWasm Contracts", diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx new file mode 100644 index 00000000..f1686470 --- /dev/null +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -0,0 +1,210 @@ +--- +description: Consume Pyth Network prices in Starknet applications +--- + +import { Callout, Tabs } from "nextra/components"; + +# How to Use Real-Time Data in Starknet Contracts + +This guide explains how to use real-time Pyth data in Starknet contracts. + +## Install the Pyth SDK + +Use the following dependency in your `Scarb.toml` file to use the latest Pyth Starkenet package: + +```toml copy +[dependencies] +pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", tag = "pyth-starknet-contract-v0.1.0"} +``` + +Pyth also provides a javascript SDK to interact with the Pyth contract on Starknet. You can install it using the following command: + + + + ```sh copy $ npm install --save @pythnetwork/pyth-starknet-js ``` + + ```sh copy $ yarn add @pythnetwork/pyth-starknet-js ``` + + +## Write Contract Code + +The code snippet below provides an example module fetching the ETH/USD price from Pyth price feeds: + +```rust {12,17,49,57,62-64} copy +#[starknet::interface] +pub trait IFetchPrice { + fn example_method( + ref self: T, destination: ContractAddress, amount_in_usd: u256, price_update: ByteBuffer + ); +} + +#[starknet::contract] +mod example_method { + use core::panic_with_felt252; + use starknet::{ContractAddress, get_caller_address, get_contract_address}; + use pyth::{ByteBuffer, IPythDispatcher, IPythDispatcherTrait, UnwrapWithFelt252}; + use openzeppelin::token::erc20::interface::{IERC20CamelDispatcherTrait, IERC20CamelDispatcher}; + + #[storage] + struct Storage { + pyth_address: ContractAddress, + eth_erc20_address: ContractAddress, + eth_usd_price_feed_id: u256, + } + + #[constructor] + fn constructor( + ref self: ContractState, + pyth_address: ContractAddress, + eth_erc20_address: ContractAddress, + eth_usd_price_feed_id: u256, + ) { + self.pyth_address.write(pyth_address); + self.eth_erc20_address.write(eth_erc20_address); + self.eth_usd_price_feed_id.write(eth_usd_price_feed_id); + } + + #[abi(embed_v0)] + impl FetchPrice of super::IFetchPrice { + fn example_method( + ref self: ContractState, + destination: ContractAddress, + amount_in_usd: u256, + pyth_price_update: ByteBuffer + ) { + let pyth = IPythDispatcher { contract_address: self.pyth_address.read() }; + let eth_erc20 = IERC20CamelDispatcher { + contract_address: self.eth_erc20_address.read() + }; + let caller = get_caller_address(); + let contract = get_contract_address(); + + let pyth_fee = pyth.get_update_fee(pyth_price_update.clone(), eth_erc20.contract_address); + if !eth_erc20.transferFrom(caller, contract, pyth_fee) { + panic_with_felt252("insufficient allowance for fee"); + } + if !eth_erc20.approve(pyth.contract_address, pyth_fee) { + panic_with_felt252("approve failed"); + } + + pyth.update_price_feeds(pyth_price_update); + + // ETH/USD price feed ID + // The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids + let price = pyth + .get_price_no_older_than(self.eth_usd_price_feed_id.read(), MAX_PRICE_AGE) + .unwrap_with_felt252(); + let price_u64: u64 = price.price.try_into().unwrap(); + } + } +} +``` + + + Unlike Ethereum, there is no native token on Starknet. You cannot pass tokens + implicitly when calling functions. Moreover, there is no concept of a + designated payer account, unlike Solana. In Starknet, all token transfers must + be performed explicitly by calling functions on the token's ERC20 contract. In + the case of the Pyth contract on Starknet, the caller must approve the fee + transfer before calling `update_price_feeds` or using similar methods. You can + use **STRK** or **ETH** to pay the fee, but STRK is preferred. The fee is + currently set to the minimum possible value (1e-18 STRK, 1 WEI). + + +The code snippet above does the following things: + +1. Call `pyth.get_update_fee` to get the fee required to update the Pyth price feeds. +1. Call `pyth.update_price_feeds` and pass `pyth_price_update` to update the Pyth price feeds. +1. Call `pyth.get_price_no_older_than` to read the price, providing the [price feed ID](https://pyth.network/developers/price-feed-ids) you wish to read. + +The code snippet below provides an example of how to update the Pyth price feeds on Starknet using the `pyth-starknet-js` in JavaScript: + +```ts {52} copy +// `pyth-starknet-js` is intended to be combined with `price-service-client` and `starknet-js`. +import { Account, Contract, RpcProvider, shortString } from "starknet"; +import { PriceServiceConnection } from "@pythnetwork/price-service-client"; +import { + ByteBuffer, + ERC20_ABI, + ETH_TOKEN_ADDRESS, + PYTH_ABI, + PYTH_CONTRACT_ADDRESS_SEPOLIA, +} from "@pythnetwork/pyth-starknet-js"; + +// Create a `RpcProvider` instance to interact with Starknet RPC. +const provider = new RpcProvider({ + nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_6", +}); + +// Create a `Contract` instance to interact with a fee token contract on Starknet +// You can use STRK or ETH to pay fees, but using STRK is recommended. +const strkErc0Contract = new Contract(ERC20_ABI, STRK_TOKEN_ADDRESS, provider); + +// Create a `Contract` instance to interact with the Pyth contract on Starknet. +const pythContract = new Contract( + PYTH_ABI, + PYTH_CONTRACT_ADDRESS_SEPOLIA, + provider +); + +// Import your account data from environment variables. +// You'll need to set them before running the code. +const privateKey0 = process.env.ACCOUNT_PRIVATE_KEY; +if (privateKey0 === undefined) { + throw new Error("missing ACCOUNT_PRIVATE_KEY"); +} +const account0Address = process.env.ACCOUNT_ADDRESS; +if (account0Address === undefined) { + throw new Error("missing ACCOUNT_ADDRESS"); +} +const account0 = new Account(provider, account0Address, privateKey0); + +// Note: Get the Stable Hermes service URL from https://docs.pyth.network/price-feeds/api-instances-and-providers/hermes +const connection = new PriceServiceConnection("https://hermes.pyth.network", { + priceFeedRequestConfig: { + binary: true, + }, +}); + +// You can find the IDs of prices at https://pyth.network/developers/price-feed-ids +const priceFeedId = + "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"; // ETH/USD + +// Convert the price update to Starknet format. +const pythUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); + +// Query the fee required by Pyth to update the price on-chain. +const fee = await pythContract.get_update_fee( + pythUpdate, + strkErc0Contract.address +); + +// Approve fee withdrawal. +strkErc0Contract.connect(account0); +let tx = await strkErc0Contract.approve(pythContract.address, fee); +await provider.waitForTransaction(tx.transaction_hash); + +// Submit a transaction to your contract using the price update data. +pythContract.connect(account0); +tx = await pythContract.update_price_feeds(pythUpdate); +await provider.waitForTransaction(tx.transaction_hash); +console.log("transaction confirmed:", tx.transaction_hash); +``` + + + Price updates must be converted to `ByteBuffer` before being passed on to the + Pyth contract on Starknet. Use the `ByteBuffer` type from + "@pythnetwork/pyth-starknet-js" package as shown above. + + +## Additional Resources + +You may find these additional resources helpful for developing your Starknet application. + +### Interface + +The [Starknet Interface](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/starknet/contracts/src/pyth/interface.cairo#L9) provides a list of functions that can be called on the Pyth contract deployed on Starknet. + +### Example Applications + +- [Send-USD](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/starknet), which updates and consumes ETH/USD price feeds on Starknet to send USD to a recipient. From ccbf11d938d9e34c4e9a3cb2c4c5b51dd1b1c225 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Mon, 10 Jun 2024 15:16:30 -0400 Subject: [PATCH 2/9] tiny change --- pages/price-feeds/use-real-time-data/starknet.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index f1686470..15a243fd 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -171,11 +171,11 @@ const priceFeedId = "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"; // ETH/USD // Convert the price update to Starknet format. -const pythUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); +const priceUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); // Query the fee required by Pyth to update the price on-chain. const fee = await pythContract.get_update_fee( - pythUpdate, + priceUpdate, strkErc0Contract.address ); @@ -186,7 +186,7 @@ await provider.waitForTransaction(tx.transaction_hash); // Submit a transaction to your contract using the price update data. pythContract.connect(account0); -tx = await pythContract.update_price_feeds(pythUpdate); +tx = await pythContract.update_price_feeds(priceUpdate); await provider.waitForTransaction(tx.transaction_hash); console.log("transaction confirmed:", tx.transaction_hash); ``` From 7471c8d7bc9b871a95eabaa1268022734b176f02 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 11 Jun 2024 12:52:46 -0400 Subject: [PATCH 3/9] tiny change --- .../use-real-time-data/starknet.mdx | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index 15a243fd..31eda9bd 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -21,9 +21,15 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn - ```sh copy $ npm install --save @pythnetwork/pyth-starknet-js ``` + ```sh copy + npm install --save @pythnetwork/pyth-starknet-js + ``` + + + ```sh copy + yarn add @pythnetwork/pyth-starknet-js + ``` - ```sh copy $ yarn add @pythnetwork/pyth-starknet-js ``` ## Write Contract Code @@ -45,23 +51,28 @@ mod example_method { use pyth::{ByteBuffer, IPythDispatcher, IPythDispatcherTrait, UnwrapWithFelt252}; use openzeppelin::token::erc20::interface::{IERC20CamelDispatcherTrait, IERC20CamelDispatcher}; + /* + * Storage to store the Pyth contract address, the ERC20 contract address representing ETH, and the ETH/USD price feed ID. + */ #[storage] struct Storage { pyth_address: ContractAddress, - eth_erc20_address: ContractAddress, - eth_usd_price_feed_id: u256, + strk_erc20_address: ContractAddress, } + /* + * Constructor to initialize the contract storage. + * @param pyth_address: The address of the Pyth contract on Starknet. + * @param strk_erc20_address: The address of the ERC20 contract representing STRK on Starknet. + */ #[constructor] fn constructor( ref self: ContractState, pyth_address: ContractAddress, - eth_erc20_address: ContractAddress, - eth_usd_price_feed_id: u256, + strk_erc20_address: ContractAddress, ) { self.pyth_address.write(pyth_address); - self.eth_erc20_address.write(eth_erc20_address); - self.eth_usd_price_feed_id.write(eth_usd_price_feed_id); + self.strk_erc20_address.write(strk_erc20_address); } #[abi(embed_v0)] @@ -73,24 +84,22 @@ mod example_method { pyth_price_update: ByteBuffer ) { let pyth = IPythDispatcher { contract_address: self.pyth_address.read() }; - let eth_erc20 = IERC20CamelDispatcher { - contract_address: self.eth_erc20_address.read() + let strk_erc20 = IERC20CamelDispatcher { + contract_address: self.strk_erc20_address.read() }; let caller = get_caller_address(); let contract = get_contract_address(); - let pyth_fee = pyth.get_update_fee(pyth_price_update.clone(), eth_erc20.contract_address); - if !eth_erc20.transferFrom(caller, contract, pyth_fee) { + let pyth_fee = pyth.get_update_fee(pyth_price_update.clone(), strk_erc20.contract_address); + if !strk_erc20.transferFrom(caller, contract, pyth_fee) { panic_with_felt252("insufficient allowance for fee"); } - if !eth_erc20.approve(pyth.contract_address, pyth_fee) { + if !strk_erc20.approve(pyth.contract_address, pyth_fee) { panic_with_felt252("approve failed"); } pyth.update_price_feeds(pyth_price_update); - // ETH/USD price feed ID - // The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids let price = pyth .get_price_no_older_than(self.eth_usd_price_feed_id.read(), MAX_PRICE_AGE) .unwrap_with_felt252(); From 2514864b00398c29681b2c024e261ed2754dd8a3 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 11 Jun 2024 17:34:47 -0400 Subject: [PATCH 4/9] requested changes --- .../use-real-time-data/starknet.mdx | 127 +++++++----------- 1 file changed, 45 insertions(+), 82 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index 31eda9bd..1655b0bf 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -37,10 +37,15 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn The code snippet below provides an example module fetching the ETH/USD price from Pyth price feeds: ```rust {12,17,49,57,62-64} copy +use starknet::ContractAddress; +use pyth::ByteBuffer; + #[starknet::interface] -pub trait IFetchPrice { +pub trait IExampleMethod { + // pyth_price_update is the price update data from Pyth to update the price feeds. + // It should be passed as a ByteBuffer. fn example_method( - ref self: T, destination: ContractAddress, amount_in_usd: u256, price_update: ByteBuffer + ref self: T, pyth_price_update: ByteBuffer ); } @@ -51,20 +56,17 @@ mod example_method { use pyth::{ByteBuffer, IPythDispatcher, IPythDispatcherTrait, UnwrapWithFelt252}; use openzeppelin::token::erc20::interface::{IERC20CamelDispatcherTrait, IERC20CamelDispatcher}; - /* - * Storage to store the Pyth contract address, the ERC20 contract address representing ETH, and the ETH/USD price feed ID. - */ + const MAX_PRICE_AGE: u64 = 3600; // 1 hour + // Storage to store the Pyth contract address, the ERC20 contract address representing ETH, and the ETH/USD price feed ID. #[storage] struct Storage { pyth_address: ContractAddress, strk_erc20_address: ContractAddress, } - /* - * Constructor to initialize the contract storage. - * @param pyth_address: The address of the Pyth contract on Starknet. - * @param strk_erc20_address: The address of the ERC20 contract representing STRK on Starknet. - */ + // Constructor to initialize the contract storage. + // * @param pyth_address: The address of the Pyth contract on Starknet. + // * @param strk_erc20_address: The address of the ERC20 contract representing STRK on Starknet. #[constructor] fn constructor( ref self: ContractState, @@ -76,11 +78,9 @@ mod example_method { } #[abi(embed_v0)] - impl FetchPrice of super::IFetchPrice { + impl ExampleMethod of super::IExampleMethod { fn example_method( ref self: ContractState, - destination: ContractAddress, - amount_in_usd: u256, pyth_price_update: ByteBuffer ) { let pyth = IPythDispatcher { contract_address: self.pyth_address.read() }; @@ -90,31 +90,42 @@ mod example_method { let caller = get_caller_address(); let contract = get_contract_address(); + // Get the fee required to update the Pyth price feeds. let pyth_fee = pyth.get_update_fee(pyth_price_update.clone(), strk_erc20.contract_address); if !strk_erc20.transferFrom(caller, contract, pyth_fee) { - panic_with_felt252("insufficient allowance for fee"); + panic_with_felt252('insufficient allowance for fee'); } if !strk_erc20.approve(pyth.contract_address, pyth_fee) { - panic_with_felt252("approve failed"); + panic_with_felt252('approve failed'); } + // Submit a pyth_price_update to the Pyth contract to update the on-chain price. pyth.update_price_feeds(pyth_price_update); + // Read the current price from a price feed. + // STRK/USD price feed ID + // The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids + let strk_usd_price_id = + 0x6a182399ff70ccf3e06024898942028204125a819e519a335ffa4579e66cd870; let price = pyth - .get_price_no_older_than(self.eth_usd_price_feed_id.read(), MAX_PRICE_AGE) + .get_price_no_older_than(strk_usd_price_id, MAX_PRICE_AGE) .unwrap_with_felt252(); - let price_u64: u64 = price.price.try_into().unwrap(); + let _: u64 = price.price.try_into().unwrap(); // Price in u64 } } } ``` +The pyth_price_update argument contains verified prices from Pyth. +Calling pyth.update_price_feeds with this value updates the on-chain Pyth price and ensures your application has recent price data. +The pyth_price_update can be fetched from Hermes; Consult [Fetch Price Updates](https://docs.pyth.network/price-feeds/fetch-price-updates) for more information on how to fetch the pyth_price_update. + Unlike Ethereum, there is no native token on Starknet. You cannot pass tokens implicitly when calling functions. Moreover, there is no concept of a designated payer account, unlike Solana. In Starknet, all token transfers must - be performed explicitly by calling functions on the token's ERC20 contract. In - the case of the Pyth contract on Starknet, the caller must approve the fee + be performed explicitly by calling functions on the token's ERC20 contract. + Regarding the Pyth contract on Starknet, the caller must approve the fee transfer before calling `update_price_feeds` or using similar methods. You can use **STRK** or **ETH** to pay the fee, but STRK is preferred. The fee is currently set to the minimum possible value (1e-18 STRK, 1 WEI). @@ -126,84 +137,36 @@ The code snippet above does the following things: 1. Call `pyth.update_price_feeds` and pass `pyth_price_update` to update the Pyth price feeds. 1. Call `pyth.get_price_no_older_than` to read the price, providing the [price feed ID](https://pyth.network/developers/price-feed-ids) you wish to read. -The code snippet below provides an example of how to update the Pyth price feeds on Starknet using the `pyth-starknet-js` in JavaScript: +### Write Client Code -```ts {52} copy -// `pyth-starknet-js` is intended to be combined with `price-service-client` and `starknet-js`. -import { Account, Contract, RpcProvider, shortString } from "starknet"; -import { PriceServiceConnection } from "@pythnetwork/price-service-client"; -import { - ByteBuffer, - ERC20_ABI, - ETH_TOKEN_ADDRESS, - PYTH_ABI, - PYTH_CONTRACT_ADDRESS_SEPOLIA, -} from "@pythnetwork/pyth-starknet-js"; - -// Create a `RpcProvider` instance to interact with Starknet RPC. -const provider = new RpcProvider({ - nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_6", -}); +The code snippet below provides an example of how to fetch price updates and convert to `ByteBuffer` for Starknet using the `pyth-starknet-js` in JavaScript: -// Create a `Contract` instance to interact with a fee token contract on Starknet -// You can use STRK or ETH to pay fees, but using STRK is recommended. -const strkErc0Contract = new Contract(ERC20_ABI, STRK_TOKEN_ADDRESS, provider); - -// Create a `Contract` instance to interact with the Pyth contract on Starknet. -const pythContract = new Contract( - PYTH_ABI, - PYTH_CONTRACT_ADDRESS_SEPOLIA, - provider -); - -// Import your account data from environment variables. -// You'll need to set them before running the code. -const privateKey0 = process.env.ACCOUNT_PRIVATE_KEY; -if (privateKey0 === undefined) { - throw new Error("missing ACCOUNT_PRIVATE_KEY"); -} -const account0Address = process.env.ACCOUNT_ADDRESS; -if (account0Address === undefined) { - throw new Error("missing ACCOUNT_ADDRESS"); -} -const account0 = new Account(provider, account0Address, privateKey0); - -// Note: Get the Stable Hermes service URL from https://docs.pyth.network/price-feeds/api-instances-and-providers/hermes +```ts copy +import { PriceServiceConnection } from "@pythnetwork/price-service-client"; +import { ByteBuffer } from "@pythnetwork/pyth-starknet-js"; +// The URL below is a public Hermes instance operated by the Pyth Data Association. +// Hermes is also available from several third-party providers listed here: +// https://docs.pyth.network/price-feeds/api-instances-and-providers/hermes const connection = new PriceServiceConnection("https://hermes.pyth.network", { priceFeedRequestConfig: { binary: true, }, }); -// You can find the IDs of prices at https://pyth.network/developers/price-feed-ids -const priceFeedId = - "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"; // ETH/USD +const priceId = + "0x6a182399ff70ccf3e06024898942028204125a819e519a335ffa4579e66cd870"; // STRK/USD + +// Get the latest values of the price feeds as json objects. +const currentPrices = await connection.getLatestPriceFeeds([priceId]); // Convert the price update to Starknet format. -const priceUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); - -// Query the fee required by Pyth to update the price on-chain. -const fee = await pythContract.get_update_fee( - priceUpdate, - strkErc0Contract.address -); - -// Approve fee withdrawal. -strkErc0Contract.connect(account0); -let tx = await strkErc0Contract.approve(pythContract.address, fee); -await provider.waitForTransaction(tx.transaction_hash); - -// Submit a transaction to your contract using the price update data. -pythContract.connect(account0); -tx = await pythContract.update_price_feeds(priceUpdate); -await provider.waitForTransaction(tx.transaction_hash); -console.log("transaction confirmed:", tx.transaction_hash); +const pythUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); ``` Price updates must be converted to `ByteBuffer` before being passed on to the Pyth contract on Starknet. Use the `ByteBuffer` type from - "@pythnetwork/pyth-starknet-js" package as shown above. + `@pythnetwork/pyth-starknet-js` package as shown above. ## Additional Resources From d272eee880d8060ce189eaabfd0c4296db667dc5 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 11 Jun 2024 17:41:16 -0400 Subject: [PATCH 5/9] requested changes --- pages/price-feeds/use-real-time-data/starknet.mdx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index 1655b0bf..583e489c 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -21,22 +21,16 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn - ```sh copy - npm install --save @pythnetwork/pyth-starknet-js - ``` - - - ```sh copy - yarn add @pythnetwork/pyth-starknet-js - ``` + ```sh copy npm install --save @pythnetwork/pyth-starknet-js ``` + ```sh copy yarn add @pythnetwork/pyth-starknet-js ``` ## Write Contract Code The code snippet below provides an example module fetching the ETH/USD price from Pyth price feeds: -```rust {12,17,49,57,62-64} copy +```rust {2,17,47,55,64,71-73} copy use starknet::ContractAddress; use pyth::ByteBuffer; @@ -141,7 +135,7 @@ The code snippet above does the following things: The code snippet below provides an example of how to fetch price updates and convert to `ByteBuffer` for Starknet using the `pyth-starknet-js` in JavaScript: -```ts copy +```ts {16} copy import { PriceServiceConnection } from "@pythnetwork/price-service-client"; import { ByteBuffer } from "@pythnetwork/pyth-starknet-js"; // The URL below is a public Hermes instance operated by the Pyth Data Association. From 2b35b66dadf6bde431e5d52e5a3363ad7af2d469 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Wed, 12 Jun 2024 09:05:22 -0400 Subject: [PATCH 6/9] requested chages --- pages/price-feeds/use-real-time-data/starknet.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index 583e489c..e24b502e 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -28,14 +28,14 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn ## Write Contract Code -The code snippet below provides an example module fetching the ETH/USD price from Pyth price feeds: +The code snippet below provides an example module fetching the STRK/USD price from Pyth price feeds: ```rust {2,17,47,55,64,71-73} copy use starknet::ContractAddress; use pyth::ByteBuffer; #[starknet::interface] -pub trait IExampleMethod { +pub trait IExampleContract { // pyth_price_update is the price update data from Pyth to update the price feeds. // It should be passed as a ByteBuffer. fn example_method( @@ -44,7 +44,7 @@ pub trait IExampleMethod { } #[starknet::contract] -mod example_method { +mod example_contract { use core::panic_with_felt252; use starknet::{ContractAddress, get_caller_address, get_contract_address}; use pyth::{ByteBuffer, IPythDispatcher, IPythDispatcherTrait, UnwrapWithFelt252}; @@ -72,7 +72,7 @@ mod example_method { } #[abi(embed_v0)] - impl ExampleMethod of super::IExampleMethod { + impl ExampleContract of super::IExampleContract { fn example_method( ref self: ContractState, pyth_price_update: ByteBuffer @@ -173,4 +173,4 @@ The [Starknet Interface](https://github.com/pyth-network/pyth-crosschain/blob/ma ### Example Applications -- [Send-USD](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/starknet), which updates and consumes ETH/USD price feeds on Starknet to send USD to a recipient. +- [Send-USD](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/starknet), which updates and consumes STRK/USD price feeds on Starknet to send USD to a recipient. From 2a65932741a9d354d2fb61f9444f264560f6a9c7 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Wed, 12 Jun 2024 17:44:00 -0400 Subject: [PATCH 7/9] pre-commit issue --- pages/price-feeds/use-real-time-data/starknet.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index e24b502e..1192a89b 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -21,9 +21,15 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn - ```sh copy npm install --save @pythnetwork/pyth-starknet-js ``` + ```sh copy + npm install --save @pythnetwork/pyth-starknet-js + ``` + + + ```sh copy + yarn add @pythnetwork/pyth-starknet-js + ``` - ```sh copy yarn add @pythnetwork/pyth-starknet-js ``` ## Write Contract Code From 33a47610be5052fe584d175db84fb9156c707d7b Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 13 Jun 2024 10:15:54 -0400 Subject: [PATCH 8/9] pre-commit issue --- .prettierignore | 3 +++ pages/price-feeds/use-real-time-data/starknet.mdx | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..2d344686 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +# Starknet Guide + +pages/price-feeds/use-real-time-data/starknet.mdx \ No newline at end of file diff --git a/pages/price-feeds/use-real-time-data/starknet.mdx b/pages/price-feeds/use-real-time-data/starknet.mdx index 1192a89b..0ec28b30 100644 --- a/pages/price-feeds/use-real-time-data/starknet.mdx +++ b/pages/price-feeds/use-real-time-data/starknet.mdx @@ -21,13 +21,13 @@ Pyth also provides a javascript SDK to interact with the Pyth contract on Starkn - ```sh copy - npm install --save @pythnetwork/pyth-starknet-js + ```sh copy + npm install --save @pythnetwork/pyth-starknet-js ``` ```sh copy - yarn add @pythnetwork/pyth-starknet-js + yarn add @pythnetwork/pyth-starknet-js ``` From 1ebcc4d5c9f9d8f9b3ac07e0f71256427d4d3235 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 13 Jun 2024 10:17:45 -0400 Subject: [PATCH 9/9] uh --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index 2d344686..71896c65 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,3 @@ # Starknet Guide -pages/price-feeds/use-real-time-data/starknet.mdx \ No newline at end of file +pages/price-feeds/use-real-time-data/starknet.mdx