diff --git a/content/docs/resources/guides/using-pyth-price-feeds.mdx b/content/docs/resources/guides/using-pyth-price-feeds.mdx index 7144b9fe8..26f02e0c0 100644 --- a/content/docs/resources/guides/using-pyth-price-feeds.mdx +++ b/content/docs/resources/guides/using-pyth-price-feeds.mdx @@ -28,7 +28,7 @@ graph LR D -->|Submit VAA + TX| E[Stacks Chain] E -->|Verify & Update| F[Pyth Oracle Contract] F -->|Fresh Price| G[Your Contract] - + style A fill:#FF7733,stroke:#0d0c0c,stroke-width:2px,color:#0d0c0c style C fill:#B3D9FF,stroke:#0d0c0c,stroke-width:2px,color:#0d0c0c style D fill:#F5F5F5,stroke:#0d0c0c,stroke-width:2px,color:#0d0c0c @@ -72,7 +72,7 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth ### Write the smart contract - + First, implement the Clarity contract that reads Pyth price data: ```clarity contracts/benjamin-club.clar @@ -105,32 +105,32 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth pyth-decoder-contract: PYTH-DECODER, wormhole-core-contract: WORMHOLE-CORE }))) - + ;; Get the updated BTC price (price-data (try! (contract-call? PYTH-ORACLE get-price BTC-USD-FEED-ID PYTH-STORAGE))) - + ;; Process the price data (btc-price (process-price-data price-data)) - + ;; Calculate required sBTC amount for $100 (required-sbtc (calculate-sbtc-amount btc-price)) - + ;; Get user's sBTC balance - (user-balance (unwrap! + (user-balance (unwrap! (contract-call? .sbtc-token get-balance tx-sender) ERR-INSUFFICIENT-FUNDS)) ) ;; Verify price is fresh (less than 5 minutes old) (try! (verify-price-freshness price-data)) - + ;; Verify user has enough sBTC (asserts! (>= user-balance required-sbtc) ERR-INSUFFICIENT-FUNDS) - + ;; Transfer sBTC from user - (try! (contract-call? .sbtc-token transfer + (try! (contract-call? .sbtc-token transfer required-sbtc tx-sender (as-contract tx-sender) none)) - + ;; Mint the NFT (let ((token-id (+ (var-get last-token-id) u1))) (try! (nft-mint? benjamin-nft token-id tx-sender)) @@ -182,7 +182,7 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth ### Build the frontend integration - + Create a service to fetch price data from Pyth: ```typescript frontend/pyth-service.ts @@ -201,7 +201,7 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth const vaas = await pythClient.getLatestVaas([PRICE_FEEDS.BTC_USD]); const messageBuffer = Buffer.from(vaas[0], 'base64'); - + return `0x${messageBuffer.toString('hex')}`; } ``` @@ -222,7 +222,7 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth try { // Fetch fresh price data const priceVAA = await fetchBTCPriceVAA(); - + // Create post-conditions for safety const postConditions = [ // Oracle fee (1 uSTX max) @@ -249,8 +249,8 @@ We'll create a "Benjamin Club" - an exclusive NFT that costs exactly $100 worth }; return ( -