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: target_chains/solana/sdk/js/pyth_solana_receiver/README.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,6 +175,50 @@ Price updates are relatively large and can take multiple transactions to post on
175
175
You can reduce the size of the transaction payload by using `addPostPartiallyVerifiedPriceUpdates` instead of `addPostPriceUpdates`.
176
176
This method does sacrifice some security however -- please see the method documentation for more details.
177
177
178
+
### Post a TWAP price update
179
+
180
+
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.
181
+
182
+
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.
183
+
184
+
```typescript
185
+
// Fetch the binary TWAP data from hermes or benchmarks. See Preliminaries section above for more info.
See `examples/post_twap_update.ts` for a runnable example of posting a TWAP price update.
221
+
178
222
### Get Instructions
179
223
180
224
The `PythTransactionBuilder` class used in the examples above helps craft transactions that update prices and then use them in successive instructions.
@@ -311,6 +313,46 @@ export class PythTransactionBuilder extends TransactionBuilder {
311
313
);
312
314
}
313
315
316
+
/**
317
+
* Add instructions that consume TWAP updates to the builder.
318
+
*
319
+
* @param getInstructions a function that given a mapping of price feed IDs to TWAP update accounts, generates a series of instructions. TWAP updates get posted to ephemeral accounts and this function allows the user to indicate which accounts in their instruction need to be "replaced" with each price update account.
320
+
* If multiple TWAP updates for the same price feed ID are posted with the same builder, the account corresponding to the last update to get posted will be used.
/** Add instructions to close encoded VAA accounts from previous actions.
315
357
* If you have previously used the PythTransactionBuilder with closeUpdateAccounts set to false or if you posted encoded VAAs but the transaction to close them did not land on-chain, your wallet might own many encoded VAA accounts.
316
358
* The rent cost for these accounts is 0.008 SOL per encoded VAA account. You can recover this rent calling this function when building a set of transactions.
@@ -356,11 +398,25 @@ export class PythTransactionBuilder extends TransactionBuilder {
`No price update account found for the price feed ID ${priceFeedId}. Make sure to call addPostPriceUpdates or addPostPartiallyVerifiedPriceUpdates or postTwapUpdates before calling this function.`
401
+
`No price update account found for the price feed ID ${priceFeedId}. Make sure to call addPostPriceUpdates or addPostPartiallyVerifiedPriceUpdates before calling this function.`
360
402
);
361
403
}
362
404
returnpriceUpdateAccount;
363
405
}
406
+
407
+
/**
408
+
* This method is used to retrieve the address of the TWAP update account where the TWAP update for a given price feed ID will be posted.
409
+
* If multiple updates for the same price feed ID will be posted with the same builder, the address of the account corresponding to the last update to get posted will be returned.
0 commit comments