Skip to content

Commit

Permalink
Merge branch 'tb/solana-receiver-js-sdk/post-twap-updates' of github.…
Browse files Browse the repository at this point in the history
…com:pyth-network/pyth-crosschain into tb/solana-receiver-js-sdk/post-twap-updates
  • Loading branch information
tejasbadadare committed Dec 17, 2024
2 parents faf0407 + 920aa9c commit 82dbaba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions target_chains/solana/sdk/js/pyth_solana_receiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ This method does sacrifice some security however -- please see the method docume

TWAP prices updates are calculated using a pair of verifiable cumulative price updates per price feed (the "start" and "end" updates for the given time window), and then performing an averaging calculation on-chain to create the time-weighted average price.

The flow of using verifying, posting, and consuming these prices are the same as standard price updates. Get the binary update data from Hermes or Benchmarks, verify the VAAs via the Wormhole contract, and post the VAAs to the Pyth receiver contract. After this, you can consume the calculated TWAP posted to the TwapUpdate account. You can also optionally close these ephemeral accounts after the TWAP has been consumed to save on rent.
The flow of using, verifying, posting, and consuming these prices are the same as standard price updates. Get the binary update data from Hermes or Benchmarks, post and verify the VAAs via the Wormhole contract, and verify the updates against the VAAs via Pyth receiver contract. After this, you can consume the calculated TWAP posted to the TwapUpdate account. You can also optionally close these ephemeral accounts after the TWAP has been consumed to save on rent.

```typescript
// Fetch the binary TWAP data from hermes or benchmarks. See Preliminaries section above for more info.
Expand All @@ -200,7 +200,7 @@ await transactionBuilder.addTwapConsumerInstructions(
getTwapUpdateAccount: (priceFeedId: string) => PublicKey
): Promise<InstructionWithEphemeralSigners[]> => {
// Generate instructions here that use the TWAP updates posted above.
// getTwaoUpdateAccount(<price feed id>) will give you the account for each TWAP update.
// getTwapUpdateAccount(<price feed id>) will give you the account for each TWAP update.
return [];
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export class PythTransactionBuilder extends TransactionBuilder {
*
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
* await transactionBuilder.addPostTwapUpdates(priceUpdateData);
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
* await transactionBuilder.addPriceConsumerInstructions(...)
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getTwapUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
* await transactionBuilder.addTwapConsumerInstructions(...)
* ```
*/
async addPostTwapUpdates(twapUpdateDataArray: string[]) {
Expand Down

0 comments on commit 82dbaba

Please sign in to comment.