You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/price-feeds/use-real-time-data/solana.mdx
+134Lines changed: 134 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -241,6 +241,140 @@ The [SDK documentation](https://github.com/pyth-network/pyth-crosschain/tree/mai
241
241
partially verified price updates.
242
242
</Callout>
243
243
244
+
## Time-Weighted Average Price (TWAP)
245
+
246
+
Pyth also provides Time-Weighted Average Price (TWAP) for Solana applications. TWAP represents the average price over a specified time window, which can be useful for reducing the impact of short-term price volatility.
247
+
248
+
<Callouttype="warning"emoji="⚠️">
249
+
The TWAP window is currently limited to a maximum of 10 minutes (600 seconds).
250
+
</Callout>
251
+
252
+
### Using TWAP in Solana Programs
253
+
254
+
To use TWAP in your Solana program, import the `TwapUpdate` struct from the Pyth Solana receiver SDK:
The [Solana TWAP example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/solana/send_usd) demonstrates how to fetch TWAP data from Hermes, post it to Solana, and consume it from a smart contract. The example includes:
371
+
372
+
- A React frontend for interacting with the contract
373
+
- A Solana program that consumes TWAP updates
374
+
- Complete transaction building for posting and consuming TWAP data
375
+
376
+
The example allows users to send a USD-denominated amount of SOL using either spot prices or TWAP prices, demonstrating how TWAP can be used to reduce the impact of price volatility.
377
+
244
378
## Additional Resources
245
379
246
380
You may find these additional resources helpful for developing your Solana application.
0 commit comments