@pythnetwork/pyth-solana-receiver 0.9.1 → 0.10.1
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/LICENSE +1 -1
- package/lib/PythSolanaReceiver.d.ts +9 -3
- package/lib/PythSolanaReceiver.d.ts.map +1 -1
- package/lib/PythSolanaReceiver.js +19 -9
- package/lib/address.d.ts.map +1 -1
- package/lib/address.js +2 -2
- package/lib/vaa.d.ts +3 -3
- package/lib/vaa.d.ts.map +1 -1
- package/lib/vaa.js +11 -10
- package/package.json +16 -16
package/LICENSE
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AnchorProvider, IdlAccounts, Program } from "@coral-xyz/anchor";
|
|
3
2
|
import { AddressLookupTableAccount, Connection, Signer, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
4
3
|
import { PythSolanaReceiver as PythSolanaReceiverProgram } from "./idl/pyth_solana_receiver";
|
|
@@ -16,6 +15,11 @@ export type TwapUpdateAccount = IdlAccounts<PythSolanaReceiverProgram>["twapUpda
|
|
|
16
15
|
export type PythTransactionBuilderConfig = {
|
|
17
16
|
closeUpdateAccounts?: boolean;
|
|
18
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* A stable treasury ID. This ID's corresponding treasury address
|
|
20
|
+
* can be cached in an account lookup table in order to reduce the overall txn size.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_TREASURY_ID = 0;
|
|
19
23
|
/**
|
|
20
24
|
* A builder class to build transactions that:
|
|
21
25
|
* - Post price updates (fully or partially verified) or update price feed accounts
|
|
@@ -248,17 +252,19 @@ export declare class PythSolanaReceiver {
|
|
|
248
252
|
readonly receiver: Program<PythSolanaReceiverProgram>;
|
|
249
253
|
readonly wormhole: Program<WormholeCoreBridgeSolana>;
|
|
250
254
|
readonly pushOracle: Program<PythPushOracle>;
|
|
251
|
-
|
|
255
|
+
readonly treasuryId?: number;
|
|
256
|
+
constructor({ connection, wallet, wormholeProgramId, receiverProgramId, pushOracleProgramId, treasuryId, }: {
|
|
252
257
|
connection: Connection;
|
|
253
258
|
wallet: Wallet;
|
|
254
259
|
wormholeProgramId?: PublicKey;
|
|
255
260
|
receiverProgramId?: PublicKey;
|
|
256
261
|
pushOracleProgramId?: PublicKey;
|
|
262
|
+
treasuryId?: number;
|
|
257
263
|
});
|
|
258
264
|
/**
|
|
259
265
|
* Get a new transaction builder to build transactions that interact with the Pyth Solana Receiver program and consume price updates
|
|
260
266
|
*/
|
|
261
|
-
newTransactionBuilder(config: PythTransactionBuilderConfig): PythTransactionBuilder;
|
|
267
|
+
newTransactionBuilder(config: PythTransactionBuilderConfig, addressLookupAccount?: AddressLookupTableAccount): PythTransactionBuilder;
|
|
262
268
|
/**
|
|
263
269
|
* Build a series of helper instructions that post price updates to the Pyth Solana Receiver program and another series to close the price update accounts.
|
|
264
270
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PythSolanaReceiver.d.ts","sourceRoot":"","sources":["../src/PythSolanaReceiver.ts"],"names":[],"mappings":"
|
|
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,yBAAyB,EACzB,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;AAS3C,OAAO,EACL,kBAAkB,EAClB,+BAA+B,EAC/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AC;IAMrC;;;;;OAKG;IACH,0BAA0B,CACxB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,SAAS;IAQZ;;;OAGG;IACG,2BAA2B;CAOlC;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,mBAAmB,CAAC,EAAE,SAAS,GAC9B,SAAS,CAmBX"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PythSolanaReceiver = exports.PythTransactionBuilder = exports.DEFAULT_TREASURY_ID = void 0;
|
|
4
|
+
exports.getPriceFeedAccountForProgram = getPriceFeedAccountForProgram;
|
|
4
5
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
6
|
const pyth_solana_receiver_1 = require("./idl/pyth_solana_receiver");
|
|
6
7
|
const wormhole_core_bridge_solana_1 = require("./idl/wormhole_core_bridge_solana");
|
|
@@ -11,6 +12,11 @@ const compute_budget_1 = require("./compute_budget");
|
|
|
11
12
|
const vaa_1 = require("./vaa");
|
|
12
13
|
const solana_utils_1 = require("@pythnetwork/solana-utils");
|
|
13
14
|
const pyth_push_oracle_1 = require("./idl/pyth_push_oracle");
|
|
15
|
+
/**
|
|
16
|
+
* A stable treasury ID. This ID's corresponding treasury address
|
|
17
|
+
* can be cached in an account lookup table in order to reduce the overall txn size.
|
|
18
|
+
*/
|
|
19
|
+
exports.DEFAULT_TREASURY_ID = 0;
|
|
14
20
|
/**
|
|
15
21
|
* A builder class to build transactions that:
|
|
16
22
|
* - Post price updates (fully or partially verified) or update price feed accounts
|
|
@@ -293,7 +299,11 @@ class PythSolanaReceiver {
|
|
|
293
299
|
receiver;
|
|
294
300
|
wormhole;
|
|
295
301
|
pushOracle;
|
|
296
|
-
|
|
302
|
+
treasuryId;
|
|
303
|
+
constructor({ connection, wallet, wormholeProgramId = address_1.DEFAULT_WORMHOLE_PROGRAM_ID, receiverProgramId = address_1.DEFAULT_RECEIVER_PROGRAM_ID, pushOracleProgramId = address_1.DEFAULT_PUSH_ORACLE_PROGRAM_ID, treasuryId = undefined, }) {
|
|
304
|
+
if (treasuryId !== undefined && (treasuryId < 0 || treasuryId > 255)) {
|
|
305
|
+
throw new Error("treasuryId must be between 0 and 255");
|
|
306
|
+
}
|
|
297
307
|
this.connection = connection;
|
|
298
308
|
this.wallet = wallet;
|
|
299
309
|
this.provider = new anchor_1.AnchorProvider(this.connection, this.wallet, {
|
|
@@ -302,12 +312,13 @@ class PythSolanaReceiver {
|
|
|
302
312
|
this.receiver = new anchor_1.Program(pyth_solana_receiver_1.IDL, receiverProgramId, this.provider);
|
|
303
313
|
this.wormhole = new anchor_1.Program(wormhole_core_bridge_solana_1.IDL, wormholeProgramId, this.provider);
|
|
304
314
|
this.pushOracle = new anchor_1.Program(pyth_push_oracle_1.IDL, pushOracleProgramId, this.provider);
|
|
315
|
+
this.treasuryId = treasuryId;
|
|
305
316
|
}
|
|
306
317
|
/**
|
|
307
318
|
* Get a new transaction builder to build transactions that interact with the Pyth Solana Receiver program and consume price updates
|
|
308
319
|
*/
|
|
309
|
-
newTransactionBuilder(config) {
|
|
310
|
-
return new PythTransactionBuilder(this, config);
|
|
320
|
+
newTransactionBuilder(config, addressLookupAccount) {
|
|
321
|
+
return new PythTransactionBuilder(this, config, addressLookupAccount);
|
|
311
322
|
}
|
|
312
323
|
/**
|
|
313
324
|
* Build a series of helper instructions that post price updates to the Pyth Solana Receiver program and another series to close the price update accounts.
|
|
@@ -324,7 +335,7 @@ class PythSolanaReceiver {
|
|
|
324
335
|
const postInstructions = [];
|
|
325
336
|
const priceFeedIdToPriceUpdateAccount = {};
|
|
326
337
|
const closeInstructions = [];
|
|
327
|
-
const treasuryId = (0, address_1.getRandomTreasuryId)();
|
|
338
|
+
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
328
339
|
for (const priceUpdateData of priceUpdateDataArray) {
|
|
329
340
|
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
330
341
|
const guardianSetIndex = (0, vaa_1.getGuardianSetIndex)(accumulatorUpdateData.vaa);
|
|
@@ -370,7 +381,7 @@ class PythSolanaReceiver {
|
|
|
370
381
|
const postInstructions = [];
|
|
371
382
|
const priceFeedIdToPriceUpdateAccount = {};
|
|
372
383
|
const closeInstructions = [];
|
|
373
|
-
const treasuryId = (0, address_1.getRandomTreasuryId)();
|
|
384
|
+
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
374
385
|
for (const priceUpdateData of priceUpdateDataArray) {
|
|
375
386
|
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
376
387
|
const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
|
|
@@ -416,7 +427,7 @@ class PythSolanaReceiver {
|
|
|
416
427
|
const postInstructions = [];
|
|
417
428
|
const priceFeedIdToTwapUpdateAccount = {};
|
|
418
429
|
const closeInstructions = [];
|
|
419
|
-
const treasuryId = (0, address_1.getRandomTreasuryId)();
|
|
430
|
+
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
420
431
|
if (twapUpdateDataArray.length !== 2) {
|
|
421
432
|
throw new Error("twapUpdateDataArray must contain exactly two updates (start and end)");
|
|
422
433
|
}
|
|
@@ -474,7 +485,7 @@ class PythSolanaReceiver {
|
|
|
474
485
|
const postInstructions = [];
|
|
475
486
|
const priceFeedIdToPriceUpdateAccount = {};
|
|
476
487
|
const closeInstructions = [];
|
|
477
|
-
const treasuryId = (0, address_1.getRandomTreasuryId)();
|
|
488
|
+
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
478
489
|
for (const priceUpdateData of priceUpdateDataArray) {
|
|
479
490
|
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
480
491
|
const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
|
|
@@ -620,4 +631,3 @@ function getPriceFeedAccountForProgram(shardId, priceFeedId, pushOracleProgramId
|
|
|
620
631
|
shardBuffer.writeUint16LE(shardId, 0);
|
|
621
632
|
return web3_js_1.PublicKey.findProgramAddressSync([shardBuffer, priceFeedId], pushOracleProgramId ?? address_1.DEFAULT_PUSH_ORACLE_PROGRAM_ID)[0];
|
|
622
633
|
}
|
|
623
|
-
exports.getPriceFeedAccountForProgram = getPriceFeedAccountForProgram;
|
package/lib/address.d.ts.map
CHANGED
|
@@ -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,
|
|
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,GAC5B,kBAAkB,MAAM,EACxB,mBAAmB,SAAS,cAQ7B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,WAElC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,MAAM,EAClB,mBAAmB,SAAS,cAM7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,mBAAmB,SAAS,cAKxD,CAAC"}
|
package/lib/address.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfigPda = exports.getTreasuryPda = exports.
|
|
3
|
+
exports.getConfigPda = exports.getTreasuryPda = exports.getGuardianSetPda = exports.DEFAULT_PUSH_ORACLE_PROGRAM_ID = exports.DEFAULT_WORMHOLE_PROGRAM_ID = exports.DEFAULT_RECEIVER_PROGRAM_ID = void 0;
|
|
4
|
+
exports.getRandomTreasuryId = getRandomTreasuryId;
|
|
4
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
6
|
/**
|
|
6
7
|
* The default Pyth Solana Receiver program ID.
|
|
@@ -29,7 +30,6 @@ exports.getGuardianSetPda = getGuardianSetPda;
|
|
|
29
30
|
function getRandomTreasuryId() {
|
|
30
31
|
return Math.floor(Math.random() * 256);
|
|
31
32
|
}
|
|
32
|
-
exports.getRandomTreasuryId = getRandomTreasuryId;
|
|
33
33
|
/**
|
|
34
34
|
* Returns the address of a treasury account from the Pyth Solana Receiver program.
|
|
35
35
|
*/
|
package/lib/vaa.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
3
2
|
import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
|
|
4
3
|
import { Program } from "@coral-xyz/anchor";
|
|
@@ -28,10 +27,11 @@ export declare const VAA_START = 46;
|
|
|
28
27
|
*
|
|
29
28
|
* The first one writes the first `VAA_SPLIT_INDEX` bytes and the second one writes the rest.
|
|
30
29
|
*
|
|
31
|
-
* This number was chosen as the biggest number such that one can still call `createInstruction`,
|
|
30
|
+
* This number was chosen as the biggest number such that one can still call `createInstruction`,
|
|
31
|
+
* `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction, while using an address lookup table.
|
|
32
32
|
* This way, the packing of the instructions to post an encoded vaa is more efficient.
|
|
33
33
|
*/
|
|
34
|
-
export declare const VAA_SPLIT_INDEX =
|
|
34
|
+
export declare const VAA_SPLIT_INDEX = 721;
|
|
35
35
|
/**
|
|
36
36
|
* Trim the number of signatures of a VAA.
|
|
37
37
|
*
|
package/lib/vaa.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vaa.d.ts","sourceRoot":"","sources":["../src/vaa.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vaa.d.ts","sourceRoot":"","sources":["../src/vaa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAS5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;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;;GAEG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,wBAA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.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.VAA_SPLIT_INDEX = exports.VAA_START = exports.VAA_SIGNATURE_SIZE = exports.DEFAULT_REDUCED_GUARDIAN_SET_SIZE = void 0;
|
|
4
|
+
exports.getGuardianSetIndex = getGuardianSetIndex;
|
|
5
|
+
exports.trimSignatures = trimSignatures;
|
|
6
|
+
exports.buildPostEncodedVaaInstructions = buildPostEncodedVaaInstructions;
|
|
7
|
+
exports.buildPostEncodedVaasForTwapInstructions = buildPostEncodedVaasForTwapInstructions;
|
|
8
|
+
exports.buildCloseEncodedVaaInstruction = buildCloseEncodedVaaInstruction;
|
|
9
|
+
exports.buildEncodedVaaCreateInstruction = buildEncodedVaaCreateInstruction;
|
|
10
|
+
exports.findEncodedVaaAccountsByWriteAuthority = findEncodedVaaAccountsByWriteAuthority;
|
|
4
11
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
12
|
const compute_budget_1 = require("./compute_budget");
|
|
6
13
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
@@ -12,7 +19,6 @@ const address_1 = require("./address");
|
|
|
12
19
|
function getGuardianSetIndex(vaa) {
|
|
13
20
|
return vaa.readUInt32BE(1);
|
|
14
21
|
}
|
|
15
|
-
exports.getGuardianSetIndex = getGuardianSetIndex;
|
|
16
22
|
/**
|
|
17
23
|
* The default number of signatures to keep in a VAA when using `trimSignatures`.
|
|
18
24
|
* This number was chosen as the maximum number of signatures so that the VAA's contents can be posted in a single Solana transaction.
|
|
@@ -33,10 +39,11 @@ exports.VAA_START = 46;
|
|
|
33
39
|
*
|
|
34
40
|
* The first one writes the first `VAA_SPLIT_INDEX` bytes and the second one writes the rest.
|
|
35
41
|
*
|
|
36
|
-
* This number was chosen as the biggest number such that one can still call `createInstruction`,
|
|
42
|
+
* This number was chosen as the biggest number such that one can still call `createInstruction`,
|
|
43
|
+
* `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction, while using an address lookup table.
|
|
37
44
|
* This way, the packing of the instructions to post an encoded vaa is more efficient.
|
|
38
45
|
*/
|
|
39
|
-
exports.VAA_SPLIT_INDEX =
|
|
46
|
+
exports.VAA_SPLIT_INDEX = 721;
|
|
40
47
|
/**
|
|
41
48
|
* Trim the number of signatures of a VAA.
|
|
42
49
|
*
|
|
@@ -57,7 +64,6 @@ function trimSignatures(vaa, n = exports.DEFAULT_REDUCED_GUARDIAN_SET_SIZE) {
|
|
|
57
64
|
trimmedVaa[5] = n;
|
|
58
65
|
return trimmedVaa;
|
|
59
66
|
}
|
|
60
|
-
exports.trimSignatures = trimSignatures;
|
|
61
67
|
// Core function to generate VAA instruction groups
|
|
62
68
|
async function generateVaaInstructionGroups(wormhole, vaa) {
|
|
63
69
|
const encodedVaaKeypair = new web3_js_1.Keypair();
|
|
@@ -165,7 +171,6 @@ async function buildPostEncodedVaaInstructions(wormhole, vaa) {
|
|
|
165
171
|
closeInstructions: groups.closeInstructions,
|
|
166
172
|
};
|
|
167
173
|
}
|
|
168
|
-
exports.buildPostEncodedVaaInstructions = buildPostEncodedVaaInstructions;
|
|
169
174
|
/**
|
|
170
175
|
* Build instructions to post two VAAs for TWAP (Time-Weighted Average Price) calculations,
|
|
171
176
|
* optimized for 3 transactions. This is specifically designed for posting start and end
|
|
@@ -212,7 +217,6 @@ async function buildPostEncodedVaasForTwapInstructions(wormhole, startUpdateData
|
|
|
212
217
|
],
|
|
213
218
|
};
|
|
214
219
|
}
|
|
215
|
-
exports.buildPostEncodedVaasForTwapInstructions = buildPostEncodedVaasForTwapInstructions;
|
|
216
220
|
/**
|
|
217
221
|
* Build an instruction to close an encoded VAA account, recovering the rent.
|
|
218
222
|
*/
|
|
@@ -227,7 +231,6 @@ async function buildCloseEncodedVaaInstruction(wormhole, encodedVaa) {
|
|
|
227
231
|
computeUnits: compute_budget_1.CLOSE_ENCODED_VAA_COMPUTE_BUDGET,
|
|
228
232
|
};
|
|
229
233
|
}
|
|
230
|
-
exports.buildCloseEncodedVaaInstruction = buildCloseEncodedVaaInstruction;
|
|
231
234
|
/**
|
|
232
235
|
* Build an instruction to create an encoded VAA account.
|
|
233
236
|
*
|
|
@@ -240,7 +243,6 @@ async function buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair
|
|
|
240
243
|
signers: [encodedVaaKeypair],
|
|
241
244
|
};
|
|
242
245
|
}
|
|
243
|
-
exports.buildEncodedVaaCreateInstruction = buildEncodedVaaCreateInstruction;
|
|
244
246
|
/**
|
|
245
247
|
* Find all the encoded VAA accounts that have a given write authority
|
|
246
248
|
* @returns a list of the public keys of the encoded VAA accounts
|
|
@@ -264,4 +266,3 @@ async function findEncodedVaaAccountsByWriteAuthority(connection, writeAuthority
|
|
|
264
266
|
});
|
|
265
267
|
return result.map((account) => new web3_js_1.PublicKey(account.pubkey));
|
|
266
268
|
}
|
|
267
|
-
exports.findEncodedVaaAccountsByWriteAuthority = findEncodedVaaAccountsByWriteAuthority;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-solana-receiver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Pyth solana receiver SDK",
|
|
5
5
|
"homepage": "https://pyth.network",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,38 +16,38 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc",
|
|
21
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
22
|
-
"test:lint": "eslint src/",
|
|
23
|
-
"prepublishOnly": "pnpm run build && pnpm test:lint",
|
|
24
|
-
"preversion": "pnpm run test:lint",
|
|
25
|
-
"version": "pnpm run format && git add -A src"
|
|
26
|
-
},
|
|
27
19
|
"keywords": [
|
|
28
20
|
"pyth",
|
|
29
21
|
"oracle"
|
|
30
22
|
],
|
|
31
23
|
"license": "Apache-2.0",
|
|
32
24
|
"devDependencies": {
|
|
33
|
-
"@pythnetwork/hermes-client": "1.3.0",
|
|
34
25
|
"@types/jest": "^29.4.0",
|
|
35
26
|
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
36
27
|
"@typescript-eslint/parser": "^5.20.0",
|
|
37
28
|
"eslint": "^8.13.0",
|
|
38
29
|
"jest": "^29.4.0",
|
|
39
|
-
"prettier": "^
|
|
30
|
+
"prettier": "^3.5.3",
|
|
40
31
|
"quicktype": "^23.0.76",
|
|
41
32
|
"ts-jest": "^29.0.5",
|
|
42
33
|
"ts-node": "^10.9.2",
|
|
43
|
-
"typescript": "^
|
|
34
|
+
"typescript": "^5.8.2",
|
|
35
|
+
"@pythnetwork/hermes-client": "2.0.0"
|
|
44
36
|
},
|
|
45
37
|
"dependencies": {
|
|
46
38
|
"@coral-xyz/anchor": "^0.29.0",
|
|
47
39
|
"@noble/hashes": "^1.4.0",
|
|
40
|
+
"@solana/web3.js": "^1.90.0",
|
|
48
41
|
"@pythnetwork/price-service-sdk": "1.8.0",
|
|
49
|
-
"@pythnetwork/solana-utils": "0.4.
|
|
50
|
-
"@solana/web3.js": "^1.90.0"
|
|
42
|
+
"@pythnetwork/solana-utils": "0.4.4"
|
|
51
43
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"test:lint": "eslint src/ --max-warnings 0",
|
|
47
|
+
"test:format": "prettier --check \"src/**/*.ts\"",
|
|
48
|
+
"fix:lint": "eslint src/ --fix --max-warnings 0",
|
|
49
|
+
"fix:format": "prettier --write \"src/**/*.ts\"",
|
|
50
|
+
"preversion": "pnpm run test:lint",
|
|
51
|
+
"version": "pnpm run format && git add -A src"
|
|
52
|
+
}
|
|
53
|
+
}
|