@pythnetwork/pyth-solana-receiver 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,7 @@ Applications can therefore store the address of a price feed account and read it
52
52
  Price feed accounts have a fixed address derived from the feed id and a shard id.
53
53
  The shard id allows different applications to use different accounts for the same feed, thereby reducing the impact of solana congestion.
54
54
  This method of using Pyth prices is a good fit for applications that always want to use the most recent price.
55
- Additionally, the [Price Scheduler](../../../../../../../price_pusher/) can be used to continuously write fresh updates to a price feed account, freeing applications from worrying about writing their own updates.
55
+ Additionally, the [Price Scheduler](../../../../../../../apps/price_pusher/) can be used to continuously write fresh updates to a price feed account, freeing applications from worrying about writing their own updates.
56
56
 
57
57
  This SDK provides methods for working with both types of accounts.
58
58
 
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { AnchorProvider, IdlAccounts, Program } from "@coral-xyz/anchor";
3
- import { Connection, Signer, Transaction, VersionedTransaction } from "@solana/web3.js";
3
+ import { AddressLookupTableAccount, Connection, Signer, Transaction, VersionedTransaction } from "@solana/web3.js";
4
4
  import { PythSolanaReceiver as PythSolanaReceiverProgram } from "./idl/pyth_solana_receiver";
5
5
  import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
6
6
  import { PublicKey } from "@solana/web3.js";
@@ -50,7 +50,7 @@ export declare class PythTransactionBuilder extends TransactionBuilder {
50
50
  readonly closeInstructions: InstructionWithEphemeralSigners[];
51
51
  readonly priceFeedIdToPriceUpdateAccount: Record<string, PublicKey>;
52
52
  readonly closeUpdateAccounts: boolean;
53
- constructor(pythSolanaReceiver: PythSolanaReceiver, config: PythTransactionBuilderConfig);
53
+ constructor(pythSolanaReceiver: PythSolanaReceiver, config: PythTransactionBuilderConfig, addressLookupTable?: AddressLookupTableAccount);
54
54
  /**
55
55
  * Add instructions to post price updates to the builder.
56
56
  * Use this function to post fully verified price updates from the present or from the past for your program to consume.
@@ -150,6 +150,11 @@ export declare class PythTransactionBuilder extends TransactionBuilder {
150
150
  * ```
151
151
  */
152
152
  addPriceConsumerInstructions(getInstructions: (getPriceUpdateAccount: (priceFeedId: string) => PublicKey) => Promise<InstructionWithEphemeralSigners[]>): Promise<void>;
153
+ /** Add instructions to close encoded VAA accounts from previous actions.
154
+ * 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.
155
+ * 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.
156
+ */
157
+ addClosePreviousEncodedVaasInstructions(maxInstructions?: number): Promise<void>;
153
158
  /**
154
159
  * Returns all the added instructions batched into versioned transactions, plus for each transaction the ephemeral signers that need to sign it
155
160
  */
@@ -255,6 +260,10 @@ export declare class PythSolanaReceiver {
255
260
  * Build an instruction to close an encoded VAA account, recovering the rent.
256
261
  */
257
262
  buildCloseEncodedVaaInstruction(encodedVaa: PublicKey): Promise<InstructionWithEphemeralSigners>;
263
+ /**
264
+ * Build aset of instructions to close all the existing encoded VAA accounts owned by this PythSolanaReceiver's wallet
265
+ */
266
+ buildClosePreviousEncodedVaasInstructions(maxInstructions: number): Promise<InstructionWithEphemeralSigners[]>;
258
267
  /**
259
268
  * Build an instruction to close a price update account, recovering the rent.
260
269
  */
@@ -262,7 +271,7 @@ export declare class PythSolanaReceiver {
262
271
  /**
263
272
  * Returns a set of versioned transactions that contain the provided instructions in the same order and with efficient batching
264
273
  */
265
- batchIntoVersionedTransactions(instructions: InstructionWithEphemeralSigners[], priorityFeeConfig: PriorityFeeConfig): Promise<{
274
+ batchIntoVersionedTransactions(instructions: InstructionWithEphemeralSigners[], priorityFeeConfig: PriorityFeeConfig, addressLookupTable?: AddressLookupTableAccount): Promise<{
266
275
  tx: VersionedTransaction;
267
276
  signers: Signer[];
268
277
  }[]>;
@@ -286,5 +295,10 @@ export declare class PythSolanaReceiver {
286
295
  * @returns The address of the price feed account
287
296
  */
288
297
  getPriceFeedAccountAddress(shardId: number, priceFeedId: Buffer | string): PublicKey;
298
+ /**
299
+ * Find all the encoded VAA accounts owned by this PythSolanaReceiver's wallet
300
+ * @returns a list of the public keys of the encoded VAA accounts
301
+ */
302
+ findOwnedEncodedVaaAccounts(): Promise<PublicKey[]>;
289
303
  }
290
304
  //# sourceMappingURL=PythSolanaReceiver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PythSolanaReceiver.d.ts","sourceRoot":"","sources":["../src/PythSolanaReceiver.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,UAAU,EACV,MAAM,EACN,WAAW,EACX,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,IAAI,yBAAyB,EAEhD,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,wBAAwB,EAEzB,MAAM,mCAAmC,CAAC;AAU3C,OAAO,EAAE,SAAS,EAAW,MAAM,iBAAiB,CAAC;AAYrD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAO3C,OAAO,EACL,kBAAkB,EAClB,+BAA+B,EAC/B,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,kBAAkB,GAC5B,WAAW,CAAC,yBAAyB,CAAC,CAAC,eAAe,CAAC,CAAC;AAC1D;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,iBAAiB,E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AC;IAQ3C;;OAEG;IACG,8BAA8B,CAClC,YAAY,EAAE,+BAA+B,EAAE,EAC/C,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,CAAC,EAAE,yBAAyB,GAC7C,OAAO,CAAC;QAAE,EAAE,EAAE,oBAAoB,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAU7D;;;;OAIG;IACG,uBAAuB,CAC3B,kBAAkB,EAAE,SAAS,GAC5B,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAMrC;;;;;OAKG;IACG,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAMrC;;;;;OAKG;IACH,0BAA0B,CACxB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,SAAS;IAQZ;;;OAGG;IACG,2BAA2B;CAOlC"}
@@ -46,8 +46,8 @@ class PythTransactionBuilder extends solana_utils_1.TransactionBuilder {
46
46
  closeInstructions;
47
47
  priceFeedIdToPriceUpdateAccount;
48
48
  closeUpdateAccounts;
49
- constructor(pythSolanaReceiver, config) {
50
- super(pythSolanaReceiver.wallet.publicKey, pythSolanaReceiver.connection);
49
+ constructor(pythSolanaReceiver, config, addressLookupTable) {
50
+ super(pythSolanaReceiver.wallet.publicKey, pythSolanaReceiver.connection, addressLookupTable);
51
51
  this.pythSolanaReceiver = pythSolanaReceiver;
52
52
  this.closeInstructions = [];
53
53
  this.priceFeedIdToPriceUpdateAccount = {};
@@ -169,6 +169,13 @@ class PythTransactionBuilder extends solana_utils_1.TransactionBuilder {
169
169
  async addPriceConsumerInstructions(getInstructions) {
170
170
  this.addInstructions(await getInstructions(this.getPriceUpdateAccount.bind(this)));
171
171
  }
172
+ /** Add instructions to close encoded VAA accounts from previous actions.
173
+ * 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.
174
+ * 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.
175
+ */
176
+ async addClosePreviousEncodedVaasInstructions(maxInstructions = 40) {
177
+ this.addInstructions(await this.pythSolanaReceiver.buildClosePreviousEncodedVaasInstructions(maxInstructions));
178
+ }
172
179
  /**
173
180
  * Returns all the added instructions batched into versioned transactions, plus for each transaction the ephemeral signers that need to sign it
174
181
  */
@@ -245,6 +252,7 @@ class PythSolanaReceiver {
245
252
  const postInstructions = [];
246
253
  const priceFeedIdToPriceUpdateAccount = {};
247
254
  const closeInstructions = [];
255
+ const treasuryId = (0, address_1.getRandomTreasuryId)();
248
256
  for (const priceUpdateData of priceUpdateDataArray) {
249
257
  const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
250
258
  const guardianSetIndex = (0, vaa_1.getGuardianSetIndex)(accumulatorUpdateData.vaa);
@@ -256,11 +264,11 @@ class PythSolanaReceiver {
256
264
  .postUpdateAtomic({
257
265
  vaa: trimmedVaa,
258
266
  merklePriceUpdate: update,
259
- treasuryId: address_1.DEFAULT_TREASURY_ID,
267
+ treasuryId,
260
268
  })
261
269
  .accounts({
262
270
  priceUpdateAccount: priceUpdateKeypair.publicKey,
263
- treasury: (0, address_1.getTreasuryPda)(address_1.DEFAULT_TREASURY_ID, this.receiver.programId),
271
+ treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
264
272
  config: (0, address_1.getConfigPda)(this.receiver.programId),
265
273
  guardianSet: (0, address_1.getGuardianSetPda)(guardianSetIndex, this.wormhole.programId),
266
274
  })
@@ -333,6 +341,7 @@ class PythSolanaReceiver {
333
341
  const postInstructions = [];
334
342
  const priceFeedIdToPriceUpdateAccount = {};
335
343
  const closeInstructions = [];
344
+ const treasuryId = (0, address_1.getRandomTreasuryId)();
336
345
  for (const priceUpdateData of priceUpdateDataArray) {
337
346
  const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
338
347
  const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
@@ -344,12 +353,12 @@ class PythSolanaReceiver {
344
353
  instruction: await this.receiver.methods
345
354
  .postUpdate({
346
355
  merklePriceUpdate: update,
347
- treasuryId: address_1.DEFAULT_TREASURY_ID,
356
+ treasuryId,
348
357
  })
349
358
  .accounts({
350
359
  encodedVaa,
351
360
  priceUpdateAccount: priceUpdateKeypair.publicKey,
352
- treasury: (0, address_1.getTreasuryPda)(address_1.DEFAULT_TREASURY_ID, this.receiver.programId),
361
+ treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
353
362
  config: (0, address_1.getConfigPda)(this.receiver.programId),
354
363
  })
355
364
  .instruction(),
@@ -379,6 +388,7 @@ class PythSolanaReceiver {
379
388
  const postInstructions = [];
380
389
  const priceFeedIdToPriceUpdateAccount = {};
381
390
  const closeInstructions = [];
391
+ const treasuryId = (0, address_1.getRandomTreasuryId)();
382
392
  for (const priceUpdateData of priceUpdateDataArray) {
383
393
  const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
384
394
  const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
@@ -390,13 +400,13 @@ class PythSolanaReceiver {
390
400
  instruction: await this.pushOracle.methods
391
401
  .updatePriceFeed({
392
402
  merklePriceUpdate: update,
393
- treasuryId: address_1.DEFAULT_TREASURY_ID,
403
+ treasuryId,
394
404
  }, shardId, Array.from(feedId))
395
405
  .accounts({
396
406
  pythSolanaReceiver: this.receiver.programId,
397
407
  encodedVaa,
398
408
  priceFeedAccount: this.getPriceFeedAccountAddress(shardId, feedId),
399
- treasury: (0, address_1.getTreasuryPda)(address_1.DEFAULT_TREASURY_ID, this.receiver.programId),
409
+ treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
400
410
  config: (0, address_1.getConfigPda)(this.receiver.programId),
401
411
  })
402
412
  .instruction(),
@@ -420,7 +430,22 @@ class PythSolanaReceiver {
420
430
  .closeEncodedVaa()
421
431
  .accounts({ encodedVaa })
422
432
  .instruction();
423
- return { instruction, signers: [] };
433
+ return {
434
+ instruction,
435
+ signers: [],
436
+ computeUnits: compute_budget_1.CLOSE_ENCODED_VAA_COMPUTE_BUDGET,
437
+ };
438
+ }
439
+ /**
440
+ * Build aset of instructions to close all the existing encoded VAA accounts owned by this PythSolanaReceiver's wallet
441
+ */
442
+ async buildClosePreviousEncodedVaasInstructions(maxInstructions) {
443
+ const encodedVaas = await this.findOwnedEncodedVaaAccounts();
444
+ const instructions = [];
445
+ for (const encodedVaa of encodedVaas) {
446
+ instructions.push(await this.buildCloseEncodedVaaInstruction(encodedVaa));
447
+ }
448
+ return instructions.slice(0, maxInstructions);
424
449
  }
425
450
  /**
426
451
  * Build an instruction to close a price update account, recovering the rent.
@@ -435,8 +460,8 @@ class PythSolanaReceiver {
435
460
  /**
436
461
  * Returns a set of versioned transactions that contain the provided instructions in the same order and with efficient batching
437
462
  */
438
- async batchIntoVersionedTransactions(instructions, priorityFeeConfig) {
439
- return solana_utils_1.TransactionBuilder.batchIntoVersionedTransactions(this.wallet.publicKey, this.connection, instructions, priorityFeeConfig);
463
+ async batchIntoVersionedTransactions(instructions, priorityFeeConfig, addressLookupTable) {
464
+ return solana_utils_1.TransactionBuilder.batchIntoVersionedTransactions(this.wallet.publicKey, this.connection, instructions, priorityFeeConfig, addressLookupTable);
440
465
  }
441
466
  /**
442
467
  * Fetch the contents of a price update account
@@ -464,6 +489,13 @@ class PythSolanaReceiver {
464
489
  getPriceFeedAccountAddress(shardId, priceFeedId) {
465
490
  return getPriceFeedAccountForProgram(shardId, priceFeedId, this.pushOracle.programId);
466
491
  }
492
+ /**
493
+ * Find all the encoded VAA accounts owned by this PythSolanaReceiver's wallet
494
+ * @returns a list of the public keys of the encoded VAA accounts
495
+ */
496
+ async findOwnedEncodedVaaAccounts() {
497
+ return await (0, vaa_1.findEncodedVaaAccountsByWriteAuthority)(this.receiver.provider.connection, this.wallet.publicKey, this.wormhole.programId);
498
+ }
467
499
  }
468
500
  exports.PythSolanaReceiver = PythSolanaReceiver;
469
501
  /**
package/lib/address.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare const getGuardianSetPda: (guardianSetIndex: number, wormholeProgr
18
18
  * The Pyth Solana Receiver has one treasury account for each u8 `treasuryId`.
19
19
  * This is meant to avoid write-locks on the treasury account by load-balancing the writes across multiple accounts.
20
20
  */
21
- export declare const DEFAULT_TREASURY_ID = 0;
21
+ export declare function getRandomTreasuryId(): number;
22
22
  /**
23
23
  * Returns the address of a treasury account from the Pyth Solana Receiver program.
24
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,WAEvC,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,WAEvC,CAAC;AAEF,eAAO,MAAM,8BAA8B,WAE1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,qBACV,MAAM,qBACL,SAAS,cAQ7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,cAAc,eACb,MAAM,qBACC,SAAS,cAM7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,sBAAuB,SAAS,cAKxD,CAAC"}
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,WAEvC,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,WAEvC,CAAC;AAEF,eAAO,MAAM,8BAA8B,WAE1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,qBACV,MAAM,qBACL,SAAS,cAQ7B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,WAElC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,eACb,MAAM,qBACC,SAAS,cAM7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,sBAAuB,SAAS,cAKxD,CAAC"}
package/lib/address.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfigPda = exports.getTreasuryPda = exports.DEFAULT_TREASURY_ID = exports.getGuardianSetPda = exports.DEFAULT_PUSH_ORACLE_PROGRAM_ID = exports.DEFAULT_WORMHOLE_PROGRAM_ID = exports.DEFAULT_RECEIVER_PROGRAM_ID = void 0;
3
+ exports.getConfigPda = exports.getTreasuryPda = exports.getRandomTreasuryId = exports.getGuardianSetPda = exports.DEFAULT_PUSH_ORACLE_PROGRAM_ID = exports.DEFAULT_WORMHOLE_PROGRAM_ID = exports.DEFAULT_RECEIVER_PROGRAM_ID = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  /**
6
6
  * The default Pyth Solana Receiver program ID.
@@ -26,7 +26,10 @@ exports.getGuardianSetPda = getGuardianSetPda;
26
26
  * The Pyth Solana Receiver has one treasury account for each u8 `treasuryId`.
27
27
  * This is meant to avoid write-locks on the treasury account by load-balancing the writes across multiple accounts.
28
28
  */
29
- exports.DEFAULT_TREASURY_ID = 0;
29
+ function getRandomTreasuryId() {
30
+ return Math.floor(Math.random() * 256);
31
+ }
32
+ exports.getRandomTreasuryId = getRandomTreasuryId;
30
33
  /**
31
34
  * Returns the address of a treasury account from the Pyth Solana Receiver program.
32
35
  */
@@ -13,7 +13,7 @@ export declare const POST_UPDATE_COMPUTE_BUDGET = 35000;
13
13
  /**
14
14
  * A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
15
15
  */
16
- export declare const UPDATE_PRICE_FEED_COMPUTE_BUDGET = 190000;
16
+ export declare const UPDATE_PRICE_FEED_COMPUTE_BUDGET = 55000;
17
17
  /**
18
18
  * A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
19
19
  */
@@ -22,4 +22,8 @@ export declare const INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
22
22
  * A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
23
23
  */
24
24
  export declare const WRITE_ENCODED_VAA_COMPUTE_BUDGET = 3000;
25
+ /**
26
+ * A hard-coded budget for the compute units required for the `closeEncodedVaa` instruction in the Wormhole program.
27
+ */
28
+ export declare const CLOSE_ENCODED_VAA_COMPUTE_BUDGET = 30000;
25
29
  //# sourceMappingURL=compute_budget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute_budget.d.ts","sourceRoot":"","sources":["../src/compute_budget.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iCAAiC,SAAS,CAAC;AACxD;;GAEG;AACH,eAAO,MAAM,iCAAiC,SAAS,CAAC;AACxD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAQ,CAAC;AAChD;;GAEG;AACH,eAAO,MAAM,gCAAgC,SAAS,CAAC;AACvD;;GAEG;AACH,eAAO,MAAM,+BAA+B,OAAO,CAAC;AACpD;;GAEG;AACH,eAAO,MAAM,gCAAgC,OAAO,CAAC"}
1
+ {"version":3,"file":"compute_budget.d.ts","sourceRoot":"","sources":["../src/compute_budget.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iCAAiC,SAAS,CAAC;AACxD;;GAEG;AACH,eAAO,MAAM,iCAAiC,SAAS,CAAC;AACxD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAQ,CAAC;AAChD;;GAEG;AACH,eAAO,MAAM,gCAAgC,QAAQ,CAAC;AACtD;;GAEG;AACH,eAAO,MAAM,+BAA+B,OAAO,CAAC;AACpD;;GAEG;AACH,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD;;GAEG;AACH,eAAO,MAAM,gCAAgC,QAAQ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WRITE_ENCODED_VAA_COMPUTE_BUDGET = exports.INIT_ENCODED_VAA_COMPUTE_BUDGET = exports.UPDATE_PRICE_FEED_COMPUTE_BUDGET = exports.POST_UPDATE_COMPUTE_BUDGET = exports.POST_UPDATE_ATOMIC_COMPUTE_BUDGET = exports.VERIFY_ENCODED_VAA_COMPUTE_BUDGET = void 0;
3
+ exports.CLOSE_ENCODED_VAA_COMPUTE_BUDGET = exports.WRITE_ENCODED_VAA_COMPUTE_BUDGET = exports.INIT_ENCODED_VAA_COMPUTE_BUDGET = exports.UPDATE_PRICE_FEED_COMPUTE_BUDGET = exports.POST_UPDATE_COMPUTE_BUDGET = exports.POST_UPDATE_ATOMIC_COMPUTE_BUDGET = exports.VERIFY_ENCODED_VAA_COMPUTE_BUDGET = void 0;
4
4
  /**
5
5
  * A hard-coded budget for the compute units required for the `verifyEncodedVaa` instruction in the Wormhole program.
6
6
  */
@@ -16,7 +16,7 @@ exports.POST_UPDATE_COMPUTE_BUDGET = 35000;
16
16
  /**
17
17
  * A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
18
18
  */
19
- exports.UPDATE_PRICE_FEED_COMPUTE_BUDGET = 190000;
19
+ exports.UPDATE_PRICE_FEED_COMPUTE_BUDGET = 55000;
20
20
  /**
21
21
  * A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
22
22
  */
@@ -25,3 +25,7 @@ exports.INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
25
25
  * A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
26
26
  */
27
27
  exports.WRITE_ENCODED_VAA_COMPUTE_BUDGET = 3000;
28
+ /**
29
+ * A hard-coded budget for the compute units required for the `closeEncodedVaa` instruction in the Wormhole program.
30
+ */
31
+ exports.CLOSE_ENCODED_VAA_COMPUTE_BUDGET = 30000;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,GAAG,IAAI,qBAAqB,EAC5B,kBAAkB,IAAI,yBAAyB,GAChD,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,GAAG,IAAI,qBAAqB,EAC5B,wBAAwB,IAAI,yBAAyB,GACtD,MAAM,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,GAAG,IAAI,qBAAqB,EAC5B,kBAAkB,IAAI,yBAAyB,GAChD,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,GAAG,IAAI,qBAAqB,EAC5B,wBAAwB,IAAI,yBAAyB,GACtD,MAAM,mCAAmC,CAAC"}
package/lib/vaa.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Keypair, PublicKey } from "@solana/web3.js";
2
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
3
3
  import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
4
4
  import { Program } from "@coral-xyz/anchor";
5
5
  import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
@@ -38,14 +38,14 @@ export declare const VAA_START = 46;
38
38
  */
39
39
  export declare function buildEncodedVaaCreateInstruction(wormhole: Program<WormholeCoreBridgeSolana>, vaa: Buffer, encodedVaaKeypair: Keypair): Promise<InstructionWithEphemeralSigners>;
40
40
  /**
41
- * Writing the VAA to to an encoded VAA account is done in 2 instructions.
41
+ * Writing the VAA to an encoded VAA account is done in 2 instructions.
42
42
  *
43
43
  * The first one writes the first `VAA_SPLIT_INDEX` bytes and the second one writes the rest.
44
44
  *
45
45
  * This number was chosen as the biggest number such that one can still call `createInstruction`, `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction.
46
46
  * This way, the packing of the instructions to post an encoded vaa is more efficient.
47
47
  */
48
- export declare const VAA_SPLIT_INDEX = 792;
48
+ export declare const VAA_SPLIT_INDEX = 755;
49
49
  /**
50
50
  * Build a set of instructions to write a VAA to an encoded VAA account
51
51
  * This functions returns 2 instructions and splits the VAA in an opinionated way, so that the whole process of posting a VAA can be efficiently packed in the 2 transactions:
@@ -55,4 +55,9 @@ export declare const VAA_SPLIT_INDEX = 792;
55
55
  * TX 2 : `writeEncodedVaa_2` + `verifyEncodedVaaV1`
56
56
  */
57
57
  export declare function buildWriteEncodedVaaWithSplitInstructions(wormhole: Program<WormholeCoreBridgeSolana>, vaa: Buffer, draftVaa: PublicKey): Promise<InstructionWithEphemeralSigners[]>;
58
+ /**
59
+ * Find all the encoded VAA accounts that have a given write authority
60
+ * @returns a list of the public keys of the encoded VAA accounts
61
+ */
62
+ export declare function findEncodedVaaAccountsByWriteAuthority(connection: Connection, writeAuthority: PublicKey, wormholeProgramId: PublicKey): Promise<PublicKey[]>;
58
63
  //# sourceMappingURL=vaa.d.ts.map
package/lib/vaa.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vaa.d.ts","sourceRoot":"","sources":["../src/vaa.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAG5E;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,UAE9C;AAED;;;GAGG;AACH,eAAO,MAAM,iCAAiC,IAAI,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,CAAC,SAAoC,GACpC,MAAM,CAeR;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B;;;;GAIG;AACH,wBAAsB,gCAAgC,CACpD,QAAQ,EAAE,OAAO,CAAC,wBAAwB,CAAC,EAC3C,GAAG,EAAE,MAAM,EACX,iBAAiB,EAAE,OAAO,GACzB,OAAO,CAAC,+BAA+B,CAAC,CAS1C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,wBAAsB,yCAAyC,CAC7D,QAAQ,EAAE,OAAO,CAAC,wBAAwB,CAAC,EAC3C,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,GAClB,OAAO,CAAC,+BAA+B,EAAE,CAAC,CA6B5C"}
1
+ {"version":3,"file":"vaa.d.ts","sourceRoot":"","sources":["../src/vaa.ts"],"names":[],"mapp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VaaWithSplitInstructions = exports.VAA_SPLIT_INDEX = exports.buildEncodedVaaCreateInstruction = exports.VAA_START = exports.trimSignatures = exports.VAA_SIGNATURE_SIZE = exports.DEFAULT_REDUCED_GUARDIAN_SET_SIZE = exports.getGuardianSetIndex = void 0;
3
+ exports.findEncodedVaaAccountsByWriteAuthority = exports.buildWriteEncodedVaaWithSplitInstructions = exports.VAA_SPLIT_INDEX = exports.buildEncodedVaaCreateInstruction = exports.VAA_START = exports.trimSignatures = exports.VAA_SIGNATURE_SIZE = exports.DEFAULT_REDUCED_GUARDIAN_SET_SIZE = exports.getGuardianSetIndex = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
4
5
  const compute_budget_1 = require("./compute_budget");
6
+ const sha256_1 = require("@noble/hashes/sha256");
7
+ const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
5
8
  /**
6
9
  * Get the index of the guardian set that signed a VAA
7
10
  */
@@ -59,14 +62,14 @@ async function buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair
59
62
  }
60
63
  exports.buildEncodedVaaCreateInstruction = buildEncodedVaaCreateInstruction;
61
64
  /**
62
- * Writing the VAA to to an encoded VAA account is done in 2 instructions.
65
+ * Writing the VAA to an encoded VAA account is done in 2 instructions.
63
66
  *
64
67
  * The first one writes the first `VAA_SPLIT_INDEX` bytes and the second one writes the rest.
65
68
  *
66
69
  * This number was chosen as the biggest number such that one can still call `createInstruction`, `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction.
67
70
  * This way, the packing of the instructions to post an encoded vaa is more efficient.
68
71
  */
69
- exports.VAA_SPLIT_INDEX = 792;
72
+ exports.VAA_SPLIT_INDEX = 755;
70
73
  /**
71
74
  * Build a set of instructions to write a VAA to an encoded VAA account
72
75
  * This functions returns 2 instructions and splits the VAA in an opinionated way, so that the whole process of posting a VAA can be efficiently packed in the 2 transactions:
@@ -106,3 +109,27 @@ async function buildWriteEncodedVaaWithSplitInstructions(wormhole, vaa, draftVaa
106
109
  ];
107
110
  }
108
111
  exports.buildWriteEncodedVaaWithSplitInstructions = buildWriteEncodedVaaWithSplitInstructions;
112
+ /**
113
+ * Find all the encoded VAA accounts that have a given write authority
114
+ * @returns a list of the public keys of the encoded VAA accounts
115
+ */
116
+ async function findEncodedVaaAccountsByWriteAuthority(connection, writeAuthority, wormholeProgramId) {
117
+ const result = await connection.getProgramAccounts(wormholeProgramId, {
118
+ filters: [
119
+ {
120
+ memcmp: {
121
+ offset: 0,
122
+ bytes: bytes_1.bs58.encode(Buffer.from((0, sha256_1.sha256)("account:EncodedVaa").slice(0, 8))),
123
+ },
124
+ },
125
+ {
126
+ memcmp: {
127
+ offset: 8 + 1,
128
+ bytes: bytes_1.bs58.encode(writeAuthority.toBuffer()),
129
+ },
130
+ },
131
+ ],
132
+ });
133
+ return result.map((account) => new web3_js_1.PublicKey(account.pubkey));
134
+ }
135
+ exports.findEncodedVaaAccountsByWriteAuthority = findEncodedVaaAccountsByWriteAuthority;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/pyth-solana-receiver",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Pyth solana receiver SDK",
5
5
  "homepage": "https://pyth.network",
6
6
  "main": "lib/index.js",
@@ -43,9 +43,10 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@coral-xyz/anchor": "^0.29.0",
46
+ "@noble/hashes": "^1.4.0",
46
47
  "@pythnetwork/price-service-sdk": ">=1.6.0",
47
48
  "@pythnetwork/solana-utils": "*",
48
49
  "@solana/web3.js": "^1.90.0"
49
50
  },
50
- "gitHead": "70c2c8ec4b5092729791f642493072565d953439"
51
+ "gitHead": "6535e7fe613c560e21b872a584c888d066c8b5f6"
51
52
  }