@pythnetwork/pyth-solana-receiver 0.5.0 → 0.7.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.
@@ -4,7 +4,7 @@ import { Connection, Signer, Transaction, VersionedTransaction } from "@solana/w
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";
7
- import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
7
+ import { Wallet } from "@coral-xyz/anchor";
8
8
  import { TransactionBuilder, InstructionWithEphemeralSigners, PriorityFeeConfig } from "@pythnetwork/solana-utils";
9
9
  import { PythPushOracle } from "./idl/pyth_push_oracle";
10
10
  export type PriceUpdateAccount = IdlAccounts<PythSolanaReceiverProgram>["priceUpdateV2"];
@@ -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
  */
@@ -275,16 +284,21 @@ export declare class PythSolanaReceiver {
275
284
  /**
276
285
  * Fetch the contents of a price feed account
277
286
  * @param shardId The shard ID of the set of price feed accounts. This shard ID allows for multiple price feed accounts for the same price feed id to exist.
278
- * @param priceFeedId The price feed ID.
287
+ * @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
279
288
  * @returns The contents of the deserialized price feed account or `null` if the account doesn't exist
280
289
  */
281
- fetchPriceFeedAccount(shardId: number, priceFeedId: Buffer): Promise<PriceUpdateAccount | null>;
290
+ fetchPriceFeedAccount(shardId: number, priceFeedId: Buffer | string): Promise<PriceUpdateAccount | null>;
282
291
  /**
283
292
  * Derive the address of a price feed account
284
293
  * @param shardId The shard ID of the set of price feed accounts. This shard ID allows for multiple price feed accounts for the same price feed id to exist.
285
- * @param priceFeedId The price feed ID.
294
+ * @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
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,OA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GAAG,MAAM,GAC3B,SAAS;IAQZ;;;OAGG;IACG,2BAA2B;CAOlC"}
@@ -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
  })
@@ -300,6 +308,7 @@ class PythSolanaReceiver {
300
308
  })
301
309
  .instruction(),
302
310
  signers: [],
311
+ computeUnits: compute_budget_1.INIT_ENCODED_VAA_COMPUTE_BUDGET,
303
312
  });
304
313
  postInstructions.push(...(await (0, vaa_1.buildWriteEncodedVaaWithSplitInstructions)(this.wormhole, vaa, encodedVaaKeypair.publicKey)));
305
314
  postInstructions.push({
@@ -332,6 +341,7 @@ class PythSolanaReceiver {
332
341
  const postInstructions = [];
333
342
  const priceFeedIdToPriceUpdateAccount = {};
334
343
  const closeInstructions = [];
344
+ const treasuryId = (0, address_1.getRandomTreasuryId)();
335
345
  for (const priceUpdateData of priceUpdateDataArray) {
336
346
  const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
337
347
  const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
@@ -343,12 +353,12 @@ class PythSolanaReceiver {
343
353
  instruction: await this.receiver.methods
344
354
  .postUpdate({
345
355
  merklePriceUpdate: update,
346
- treasuryId: address_1.DEFAULT_TREASURY_ID,
356
+ treasuryId,
347
357
  })
348
358
  .accounts({
349
359
  encodedVaa,
350
360
  priceUpdateAccount: priceUpdateKeypair.publicKey,
351
- treasury: (0, address_1.getTreasuryPda)(address_1.DEFAULT_TREASURY_ID, this.receiver.programId),
361
+ treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
352
362
  config: (0, address_1.getConfigPda)(this.receiver.programId),
353
363
  })
354
364
  .instruction(),
@@ -378,6 +388,7 @@ class PythSolanaReceiver {
378
388
  const postInstructions = [];
379
389
  const priceFeedIdToPriceUpdateAccount = {};
380
390
  const closeInstructions = [];
391
+ const treasuryId = (0, address_1.getRandomTreasuryId)();
381
392
  for (const priceUpdateData of priceUpdateDataArray) {
382
393
  const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
383
394
  const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
@@ -389,18 +400,18 @@ class PythSolanaReceiver {
389
400
  instruction: await this.pushOracle.methods
390
401
  .updatePriceFeed({
391
402
  merklePriceUpdate: update,
392
- treasuryId: address_1.DEFAULT_TREASURY_ID,
403
+ treasuryId,
393
404
  }, shardId, Array.from(feedId))
394
405
  .accounts({
395
406
  pythSolanaReceiver: this.receiver.programId,
396
407
  encodedVaa,
397
408
  priceFeedAccount: this.getPriceFeedAccountAddress(shardId, feedId),
398
- treasury: (0, address_1.getTreasuryPda)(address_1.DEFAULT_TREASURY_ID, this.receiver.programId),
409
+ treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
399
410
  config: (0, address_1.getConfigPda)(this.receiver.programId),
400
411
  })
401
412
  .instruction(),
402
413
  signers: [],
403
- computeUnits: compute_budget_1.POST_UPDATE_COMPUTE_BUDGET,
414
+ computeUnits: compute_budget_1.UPDATE_PRICE_FEED_COMPUTE_BUDGET,
404
415
  });
405
416
  priceFeedIdToPriceUpdateAccount["0x" + (0, price_service_sdk_1.parsePriceFeedMessage)(update.message).feedId.toString("hex")] = this.getPriceFeedAccountAddress(shardId, feedId);
406
417
  }
@@ -419,7 +430,22 @@ class PythSolanaReceiver {
419
430
  .closeEncodedVaa()
420
431
  .accounts({ encodedVaa })
421
432
  .instruction();
422
- 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);
423
449
  }
424
450
  /**
425
451
  * Build an instruction to close a price update account, recovering the rent.
@@ -448,7 +474,7 @@ class PythSolanaReceiver {
448
474
  /**
449
475
  * Fetch the contents of a price feed account
450
476
  * @param shardId The shard ID of the set of price feed accounts. This shard ID allows for multiple price feed accounts for the same price feed id to exist.
451
- * @param priceFeedId The price feed ID.
477
+ * @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
452
478
  * @returns The contents of the deserialized price feed account or `null` if the account doesn't exist
453
479
  */
454
480
  async fetchPriceFeedAccount(shardId, priceFeedId) {
@@ -457,18 +483,25 @@ class PythSolanaReceiver {
457
483
  /**
458
484
  * Derive the address of a price feed account
459
485
  * @param shardId The shard ID of the set of price feed accounts. This shard ID allows for multiple price feed accounts for the same price feed id to exist.
460
- * @param priceFeedId The price feed ID.
486
+ * @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
461
487
  * @returns The address of the price feed account
462
488
  */
463
489
  getPriceFeedAccountAddress(shardId, priceFeedId) {
464
490
  return getPriceFeedAccountForProgram(shardId, priceFeedId, this.pushOracle.programId);
465
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
+ }
466
499
  }
467
500
  exports.PythSolanaReceiver = PythSolanaReceiver;
468
501
  /**
469
502
  * Derive the address of a price feed account
470
503
  * @param shardId The shard ID of the set of price feed accounts. This shard ID allows for multiple price feed accounts for the same price feed id to exist.
471
- * @param priceFeedId The price feed ID.
504
+ * @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
472
505
  * @param pushOracleProgramId The program ID of the Pyth Push Oracle program. If not provided, the default deployment will be used.
473
506
  * @returns The address of the price feed account
474
507
  */
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
  */
@@ -10,4 +10,20 @@ export declare const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 170000;
10
10
  * A hard-coded budget for the compute units required for the `postUpdate` instruction in the Pyth Solana Receiver program.
11
11
  */
12
12
  export declare const POST_UPDATE_COMPUTE_BUDGET = 35000;
13
+ /**
14
+ * A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
15
+ */
16
+ export declare const UPDATE_PRICE_FEED_COMPUTE_BUDGET = 55000;
17
+ /**
18
+ * A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
19
+ */
20
+ export declare const INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
21
+ /**
22
+ * A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
23
+ */
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;
13
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"}
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.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
  */
@@ -13,3 +13,19 @@ exports.POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 170000;
13
13
  * A hard-coded budget for the compute units required for the `postUpdate` instruction in the Pyth Solana Receiver program.
14
14
  */
15
15
  exports.POST_UPDATE_COMPUTE_BUDGET = 35000;
16
+ /**
17
+ * A hard-coded budget for the compute units required for the `updatePriceFeed` instruction in the Pyth Push Oracle program.
18
+ */
19
+ exports.UPDATE_PRICE_FEED_COMPUTE_BUDGET = 55000;
20
+ /**
21
+ * A hard-coded budget for the compute units required for the `initEncodedVaa` instruction in the Wormhole program.
22
+ */
23
+ exports.INIT_ENCODED_VAA_COMPUTE_BUDGET = 3000;
24
+ /**
25
+ * A hard-coded budget for the compute units required for the `writeEncodedVaa` instruction in the Wormhole program.
26
+ */
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";
@@ -45,7 +45,7 @@ export declare function buildEncodedVaaCreateInstruction(wormhole: Program<Wormh
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;AAE5E;;GAEG;AACH,wBAAgB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G,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;AAED;;;GAGG;AACH,wBAAsB,sCAAsC,CAC1D,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,SAAS,EACzB,iBAAiB,EAAE,SAAS,GAC3B,OAAO,CAAC,SAAS,EAAE,CAAC,CAoBtB"}
package/lib/vaa.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
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");
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");
4
8
  /**
5
9
  * Get the index of the guardian set that signed a VAA
6
10
  */
@@ -65,7 +69,7 @@ exports.buildEncodedVaaCreateInstruction = buildEncodedVaaCreateInstruction;
65
69
  * This number was chosen as the biggest number such that one can still call `createInstruction`, `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction.
66
70
  * This way, the packing of the instructions to post an encoded vaa is more efficient.
67
71
  */
68
- exports.VAA_SPLIT_INDEX = 792;
72
+ exports.VAA_SPLIT_INDEX = 755;
69
73
  /**
70
74
  * Build a set of instructions to write a VAA to an encoded VAA account
71
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:
@@ -87,6 +91,7 @@ async function buildWriteEncodedVaaWithSplitInstructions(wormhole, vaa, draftVaa
87
91
  })
88
92
  .instruction(),
89
93
  signers: [],
94
+ computeUnits: compute_budget_1.WRITE_ENCODED_VAA_COMPUTE_BUDGET,
90
95
  },
91
96
  {
92
97
  instruction: await wormhole.methods
@@ -99,7 +104,32 @@ async function buildWriteEncodedVaaWithSplitInstructions(wormhole, vaa, draftVaa
99
104
  })
100
105
  .instruction(),
101
106
  signers: [],
107
+ computeUnits: compute_budget_1.WRITE_ENCODED_VAA_COMPUTE_BUDGET,
102
108
  },
103
109
  ];
104
110
  }
105
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.5.0",
3
+ "version": "0.7.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": "62d189e3b5e3cdbbfba04c1ebd677b28f4a6f693"
51
+ "gitHead": "56cbace282dcdce0099a188a637493ce6bf2312c"
51
52
  }