@pythnetwork/pyth-solana-receiver 0.12.0 → 0.14.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 +0 -44
- package/dist/cjs/PythSolanaReceiver.cjs +442 -0
- package/{lib → dist/cjs}/PythSolanaReceiver.d.ts +10 -86
- package/dist/cjs/address.cjs +63 -0
- package/{lib → dist/cjs}/address.d.ts +0 -1
- package/dist/cjs/compute_budget.cjs +42 -0
- package/{lib → dist/cjs}/compute_budget.d.ts +0 -5
- package/dist/cjs/idl/pyth_push_oracle.cjs +132 -0
- package/{lib → dist/cjs}/idl/pyth_push_oracle.d.ts +0 -1
- package/dist/cjs/idl/pyth_solana_receiver.cjs +858 -0
- package/{lib → dist/cjs}/idl/pyth_solana_receiver.d.ts +0 -1
- package/dist/cjs/idl/wormhole_core_bridge_solana.cjs +1751 -0
- package/{lib → dist/cjs}/idl/wormhole_core_bridge_solana.d.ts +0 -1
- package/dist/cjs/index.cjs +44 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/vaa.cjs +192 -0
- package/{lib → dist/cjs}/vaa.d.ts +4 -30
- package/dist/esm/PythSolanaReceiver.d.ts +318 -0
- package/dist/esm/PythSolanaReceiver.mjs +462 -0
- package/dist/esm/address.d.ts +29 -0
- package/dist/esm/address.mjs +45 -0
- package/dist/esm/compute_budget.d.ts +28 -0
- package/dist/esm/compute_budget.mjs +21 -0
- package/dist/esm/idl/pyth_push_oracle.d.ts +117 -0
- package/{lib/idl/pyth_push_oracle.js → dist/esm/idl/pyth_push_oracle.mjs} +41 -38
- package/dist/esm/idl/pyth_solana_receiver.d.ts +840 -0
- package/{lib/idl/pyth_solana_receiver.js → dist/esm/idl/pyth_solana_receiver.mjs} +237 -231
- package/dist/esm/idl/wormhole_core_bridge_solana.d.ts +1606 -0
- package/{lib/idl/wormhole_core_bridge_solana.js → dist/esm/idl/wormhole_core_bridge_solana.mjs} +598 -465
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/vaa.d.ts +75 -0
- package/dist/esm/vaa.mjs +197 -0
- package/package.json +101 -13
- package/lib/PythSolanaReceiver.d.ts.map +0 -1
- package/lib/PythSolanaReceiver.js +0 -633
- package/lib/address.d.ts.map +0 -1
- package/lib/address.js +0 -46
- package/lib/compute_budget.d.ts.map +0 -1
- package/lib/compute_budget.js +0 -35
- package/lib/idl/pyth_push_oracle.d.ts.map +0 -1
- package/lib/idl/pyth_solana_receiver.d.ts.map +0 -1
- package/lib/idl/pyth_solana_receiver.json +0 -839
- package/lib/idl/wormhole_core_bridge_solana.d.ts.map +0 -1
- package/lib/index.d.ts +0 -6
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -17
- package/lib/vaa.d.ts.map +0 -1
- package/lib/vaa.js +0 -270
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get DEFAULT_RECEIVER_PROGRAM_ID () {
|
|
13
|
+
return _address.DEFAULT_RECEIVER_PROGRAM_ID;
|
|
14
|
+
},
|
|
15
|
+
get DEFAULT_WORMHOLE_PROGRAM_ID () {
|
|
16
|
+
return _address.DEFAULT_WORMHOLE_PROGRAM_ID;
|
|
17
|
+
},
|
|
18
|
+
get PythSolanaReceiver () {
|
|
19
|
+
return _PythSolanaReceiver.PythSolanaReceiver;
|
|
20
|
+
},
|
|
21
|
+
get PythTransactionBuilder () {
|
|
22
|
+
return _PythSolanaReceiver.PythTransactionBuilder;
|
|
23
|
+
},
|
|
24
|
+
get TransactionBuilder () {
|
|
25
|
+
return _solanautils.TransactionBuilder;
|
|
26
|
+
},
|
|
27
|
+
get getConfigPda () {
|
|
28
|
+
return _address.getConfigPda;
|
|
29
|
+
},
|
|
30
|
+
get getPriceFeedAccountForProgram () {
|
|
31
|
+
return _PythSolanaReceiver.getPriceFeedAccountForProgram;
|
|
32
|
+
},
|
|
33
|
+
get pythSolanaReceiverIdl () {
|
|
34
|
+
return _pyth_solana_receiver.IDL;
|
|
35
|
+
},
|
|
36
|
+
get wormholeCoreBridgeIdl () {
|
|
37
|
+
return _wormhole_core_bridge_solana.IDL;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const _PythSolanaReceiver = require("./PythSolanaReceiver.cjs");
|
|
41
|
+
const _solanautils = require("@pythnetwork/solana-utils");
|
|
42
|
+
const _address = require("./address.cjs");
|
|
43
|
+
const _pyth_solana_receiver = require("./idl/pyth_solana_receiver.cjs");
|
|
44
|
+
const _wormhole_core_bridge_solana = require("./idl/wormhole_core_bridge_solana.cjs");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PythSolanaReceiver, PythTransactionBuilder, getPriceFeedAccountForProgram, } from "./PythSolanaReceiver";
|
|
2
|
+
export { TransactionBuilder, type InstructionWithEphemeralSigners, } from "@pythnetwork/solana-utils";
|
|
3
|
+
export { getConfigPda, DEFAULT_RECEIVER_PROGRAM_ID, DEFAULT_WORMHOLE_PROGRAM_ID, } from "./address";
|
|
4
|
+
export { IDL as pythSolanaReceiverIdl, type PythSolanaReceiver as PythSolanaReceiverProgram, } from "./idl/pyth_solana_receiver";
|
|
5
|
+
export { IDL as wormholeCoreBridgeIdl, type WormholeCoreBridgeSolana as WormholeCoreBridgeProgram, } from "./idl/wormhole_core_bridge_solana";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/dist/cjs/vaa.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
get DEFAULT_REDUCED_GUARDIAN_SET_SIZE () {
|
|
14
|
+
return DEFAULT_REDUCED_GUARDIAN_SET_SIZE;
|
|
15
|
+
},
|
|
16
|
+
get VAA_SIGNATURE_SIZE () {
|
|
17
|
+
return VAA_SIGNATURE_SIZE;
|
|
18
|
+
},
|
|
19
|
+
get VAA_SPLIT_INDEX () {
|
|
20
|
+
return VAA_SPLIT_INDEX;
|
|
21
|
+
},
|
|
22
|
+
get VAA_START () {
|
|
23
|
+
return VAA_START;
|
|
24
|
+
},
|
|
25
|
+
get buildCloseEncodedVaaInstruction () {
|
|
26
|
+
return buildCloseEncodedVaaInstruction;
|
|
27
|
+
},
|
|
28
|
+
get buildEncodedVaaCreateInstruction () {
|
|
29
|
+
return buildEncodedVaaCreateInstruction;
|
|
30
|
+
},
|
|
31
|
+
get buildPostEncodedVaaInstructions () {
|
|
32
|
+
return buildPostEncodedVaaInstructions;
|
|
33
|
+
},
|
|
34
|
+
get findEncodedVaaAccountsByWriteAuthority () {
|
|
35
|
+
return findEncodedVaaAccountsByWriteAuthority;
|
|
36
|
+
},
|
|
37
|
+
get getGuardianSetIndex () {
|
|
38
|
+
return getGuardianSetIndex;
|
|
39
|
+
},
|
|
40
|
+
get trimSignatures () {
|
|
41
|
+
return trimSignatures;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const _buffer = require("buffer");
|
|
45
|
+
const _bytes = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
46
|
+
const _sha256 = require("@noble/hashes/sha256");
|
|
47
|
+
const _web3 = require("@solana/web3.js");
|
|
48
|
+
const _address = require("./address.cjs");
|
|
49
|
+
const _compute_budget = require("./compute_budget.cjs");
|
|
50
|
+
function getGuardianSetIndex(vaa) {
|
|
51
|
+
return vaa.readUInt32BE(1);
|
|
52
|
+
}
|
|
53
|
+
const DEFAULT_REDUCED_GUARDIAN_SET_SIZE = 5;
|
|
54
|
+
const VAA_SIGNATURE_SIZE = 66;
|
|
55
|
+
const VAA_START = 46;
|
|
56
|
+
const VAA_SPLIT_INDEX = 721;
|
|
57
|
+
function trimSignatures(vaa, n = DEFAULT_REDUCED_GUARDIAN_SET_SIZE) {
|
|
58
|
+
const currentNumSignatures = vaa[5];
|
|
59
|
+
if (currentNumSignatures === undefined) {
|
|
60
|
+
throw new Error("vaa[5] is undefined");
|
|
61
|
+
}
|
|
62
|
+
if (n > currentNumSignatures) {
|
|
63
|
+
throw new Error("Resulting VAA can't have more signatures than the original VAA");
|
|
64
|
+
}
|
|
65
|
+
const trimmedVaa = _buffer.Buffer.concat([
|
|
66
|
+
vaa.subarray(0, 6 + n * VAA_SIGNATURE_SIZE),
|
|
67
|
+
vaa.subarray(6 + currentNumSignatures * VAA_SIGNATURE_SIZE)
|
|
68
|
+
]);
|
|
69
|
+
trimmedVaa[5] = n;
|
|
70
|
+
return trimmedVaa;
|
|
71
|
+
}
|
|
72
|
+
// Core function to generate VAA instruction groups
|
|
73
|
+
async function generateVaaInstructionGroups(wormhole, vaa) {
|
|
74
|
+
const encodedVaaKeypair = new _web3.Keypair();
|
|
75
|
+
// Create and init instructions
|
|
76
|
+
const initInstructions = [
|
|
77
|
+
await buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair),
|
|
78
|
+
{
|
|
79
|
+
instruction: await wormhole.methods.initEncodedVaa().accounts({
|
|
80
|
+
encodedVaa: encodedVaaKeypair.publicKey
|
|
81
|
+
}).instruction(),
|
|
82
|
+
signers: [],
|
|
83
|
+
computeUnits: _compute_budget.INIT_ENCODED_VAA_COMPUTE_BUDGET
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
// First write instruction
|
|
87
|
+
const writeFirstPartInstructions = [
|
|
88
|
+
{
|
|
89
|
+
instruction: await wormhole.methods.writeEncodedVaa({
|
|
90
|
+
index: 0,
|
|
91
|
+
data: vaa.subarray(0, VAA_SPLIT_INDEX)
|
|
92
|
+
}).accounts({
|
|
93
|
+
draftVaa: encodedVaaKeypair.publicKey
|
|
94
|
+
}).instruction(),
|
|
95
|
+
signers: [],
|
|
96
|
+
computeUnits: _compute_budget.WRITE_ENCODED_VAA_COMPUTE_BUDGET
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
// Second write and verify instructions
|
|
100
|
+
const writeSecondPartAndVerifyInstructions = [];
|
|
101
|
+
// The second write instruction is only needed if there are more bytes past the split index in the VAA
|
|
102
|
+
if (vaa.length > VAA_SPLIT_INDEX) {
|
|
103
|
+
writeSecondPartAndVerifyInstructions.push({
|
|
104
|
+
instruction: await wormhole.methods.writeEncodedVaa({
|
|
105
|
+
index: VAA_SPLIT_INDEX,
|
|
106
|
+
data: vaa.subarray(VAA_SPLIT_INDEX)
|
|
107
|
+
}).accounts({
|
|
108
|
+
draftVaa: encodedVaaKeypair.publicKey
|
|
109
|
+
}).instruction(),
|
|
110
|
+
signers: [],
|
|
111
|
+
computeUnits: _compute_budget.WRITE_ENCODED_VAA_COMPUTE_BUDGET
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
writeSecondPartAndVerifyInstructions.push({
|
|
115
|
+
instruction: await wormhole.methods.verifyEncodedVaaV1().accounts({
|
|
116
|
+
guardianSet: (0, _address.getGuardianSetPda)(getGuardianSetIndex(vaa), wormhole.programId),
|
|
117
|
+
draftVaa: encodedVaaKeypair.publicKey
|
|
118
|
+
}).instruction(),
|
|
119
|
+
signers: [],
|
|
120
|
+
computeUnits: _compute_budget.VERIFY_ENCODED_VAA_COMPUTE_BUDGET
|
|
121
|
+
});
|
|
122
|
+
// Close instructions
|
|
123
|
+
const closeInstructions = [
|
|
124
|
+
{
|
|
125
|
+
instruction: await wormhole.methods.closeEncodedVaa().accounts({
|
|
126
|
+
encodedVaa: encodedVaaKeypair.publicKey
|
|
127
|
+
}).instruction(),
|
|
128
|
+
signers: [],
|
|
129
|
+
computeUnits: _compute_budget.CLOSE_ENCODED_VAA_COMPUTE_BUDGET
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
return {
|
|
133
|
+
initInstructions,
|
|
134
|
+
writeFirstPartInstructions,
|
|
135
|
+
writeSecondPartAndVerifyInstructions,
|
|
136
|
+
closeInstructions,
|
|
137
|
+
encodedVaaAddress: encodedVaaKeypair.publicKey
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async function buildPostEncodedVaaInstructions(wormhole, vaa) {
|
|
141
|
+
const groups = await generateVaaInstructionGroups(wormhole, vaa);
|
|
142
|
+
// Pack instructions for optimal 2-transaction pattern:
|
|
143
|
+
// TX1: init + first write
|
|
144
|
+
// TX2: second write + verify
|
|
145
|
+
return {
|
|
146
|
+
encodedVaaAddress: groups.encodedVaaAddress,
|
|
147
|
+
postInstructions: [
|
|
148
|
+
...groups.initInstructions,
|
|
149
|
+
...groups.writeFirstPartInstructions,
|
|
150
|
+
...groups.writeSecondPartAndVerifyInstructions
|
|
151
|
+
],
|
|
152
|
+
closeInstructions: groups.closeInstructions
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async function buildCloseEncodedVaaInstruction(wormhole, encodedVaa) {
|
|
156
|
+
const instruction = await wormhole.methods.closeEncodedVaa().accounts({
|
|
157
|
+
encodedVaa
|
|
158
|
+
}).instruction();
|
|
159
|
+
return {
|
|
160
|
+
instruction,
|
|
161
|
+
signers: [],
|
|
162
|
+
computeUnits: _compute_budget.CLOSE_ENCODED_VAA_COMPUTE_BUDGET
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async function buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair) {
|
|
166
|
+
const encodedVaaSize = vaa.length + VAA_START;
|
|
167
|
+
return {
|
|
168
|
+
instruction: await wormhole.account.encodedVaa.createInstruction(encodedVaaKeypair, encodedVaaSize),
|
|
169
|
+
signers: [
|
|
170
|
+
encodedVaaKeypair
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function findEncodedVaaAccountsByWriteAuthority(connection, writeAuthority, wormholeProgramId) {
|
|
175
|
+
const result = await connection.getProgramAccounts(wormholeProgramId, {
|
|
176
|
+
filters: [
|
|
177
|
+
{
|
|
178
|
+
memcmp: {
|
|
179
|
+
offset: 0,
|
|
180
|
+
bytes: _bytes.bs58.encode(_buffer.Buffer.from((0, _sha256.sha256)("account:EncodedVaa").slice(0, 8)))
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
memcmp: {
|
|
185
|
+
offset: 8 + 1,
|
|
186
|
+
bytes: _bytes.bs58.encode(writeAuthority.toBuffer())
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
return result.map((account)=>new _web3.PublicKey(account.pubkey));
|
|
192
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
|
|
3
1
|
import { Program } from "@coral-xyz/anchor";
|
|
4
|
-
import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
|
|
5
|
-
import {
|
|
2
|
+
import type { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
|
|
3
|
+
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
4
|
+
import type { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
|
|
6
5
|
/**
|
|
7
6
|
* Get the index of the guardian set that signed a VAA
|
|
8
7
|
*/
|
|
@@ -49,7 +48,7 @@ export declare function trimSignatures(vaa: Buffer, n?: number): Buffer;
|
|
|
49
48
|
*
|
|
50
49
|
* @param wormhole - The Wormhole program instance
|
|
51
50
|
* @param vaa - The VAA buffer to post
|
|
52
|
-
* @returns
|
|
51
|
+
* @returns Result containing:
|
|
53
52
|
* - encodedVaaAddress: Public key of the encoded VAA account
|
|
54
53
|
* - postInstructions: Instructions to post and verify the VAA
|
|
55
54
|
* - closeInstructions: Instructions to close the encoded VAA account and recover rent
|
|
@@ -59,30 +58,6 @@ export declare function buildPostEncodedVaaInstructions(wormhole: Program<Wormho
|
|
|
59
58
|
postInstructions: InstructionWithEphemeralSigners[];
|
|
60
59
|
closeInstructions: InstructionWithEphemeralSigners[];
|
|
61
60
|
}>;
|
|
62
|
-
/**
|
|
63
|
-
* Build instructions to post two VAAs for TWAP (Time-Weighted Average Price) calculations,
|
|
64
|
-
* optimized for 3 transactions. This is specifically designed for posting start and end
|
|
65
|
-
* accumulator update VAAs efficiently.
|
|
66
|
-
* The instructions are packed into 3 transactions:
|
|
67
|
-
* - TX1: Initialize and write first part of start VAA
|
|
68
|
-
* - TX2: Initialize and write first part of end VAA
|
|
69
|
-
* - TX3: Write second part and verify both VAAs
|
|
70
|
-
*
|
|
71
|
-
* @param wormhole - The Wormhole program instance
|
|
72
|
-
* @param startUpdateData - Accumulator update data containing the start VAA
|
|
73
|
-
* @param endUpdateData - Accumulator update data containing the end VAA
|
|
74
|
-
* @returns {Object} Result containing:
|
|
75
|
-
* - startEncodedVaaAddress: Public key of the start VAA account
|
|
76
|
-
* - endEncodedVaaAddress: Public key of the end VAA account
|
|
77
|
-
* - postInstructions: Instructions to post and verify both VAAs
|
|
78
|
-
* - closeInstructions: Instructions to close both encoded VAA accounts
|
|
79
|
-
*/
|
|
80
|
-
export declare function buildPostEncodedVaasForTwapInstructions(wormhole: Program<WormholeCoreBridgeSolana>, startUpdateData: AccumulatorUpdateData, endUpdateData: AccumulatorUpdateData): Promise<{
|
|
81
|
-
startEncodedVaaAddress: PublicKey;
|
|
82
|
-
endEncodedVaaAddress: PublicKey;
|
|
83
|
-
postInstructions: InstructionWithEphemeralSigners[];
|
|
84
|
-
closeInstructions: InstructionWithEphemeralSigners[];
|
|
85
|
-
}>;
|
|
86
61
|
/**
|
|
87
62
|
* Build an instruction to close an encoded VAA account, recovering the rent.
|
|
88
63
|
*/
|
|
@@ -98,4 +73,3 @@ export declare function buildEncodedVaaCreateInstruction(wormhole: Program<Wormh
|
|
|
98
73
|
* @returns a list of the public keys of the encoded VAA accounts
|
|
99
74
|
*/
|
|
100
75
|
export declare function findEncodedVaaAccountsByWriteAuthority(connection: Connection, writeAuthority: PublicKey, wormholeProgramId: PublicKey): Promise<PublicKey[]>;
|
|
101
|
-
//# sourceMappingURL=vaa.d.ts.map
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { IdlAccounts } from "@coral-xyz/anchor";
|
|
2
|
+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
|
|
3
|
+
import type { InstructionWithEphemeralSigners, PriorityFeeConfig } from "@pythnetwork/solana-utils";
|
|
4
|
+
import { TransactionBuilder } from "@pythnetwork/solana-utils";
|
|
5
|
+
import type { Signer } from "@solana/web3.js";
|
|
6
|
+
import { AddressLookupTableAccount, Connection, Transaction, VersionedTransaction, PublicKey } from "@solana/web3.js";
|
|
7
|
+
import type { PythPushOracle } from "./idl/pyth_push_oracle";
|
|
8
|
+
import type { PythSolanaReceiver as PythSolanaReceiverProgram } from "./idl/pyth_solana_receiver";
|
|
9
|
+
import type { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
|
|
10
|
+
export type PriceUpdateAccount = IdlAccounts<PythSolanaReceiverProgram>["priceUpdateV2"];
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the PythTransactionBuilder
|
|
13
|
+
* @property closeUpdateAccounts (default: true) if true, the builder will add instructions to close the price update accounts and the encoded vaa accounts to recover the rent
|
|
14
|
+
*/
|
|
15
|
+
export type PythTransactionBuilderConfig = {
|
|
16
|
+
closeUpdateAccounts?: boolean;
|
|
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;
|
|
23
|
+
/**
|
|
24
|
+
* A builder class to build transactions that:
|
|
25
|
+
* - Post price updates (fully or partially verified) or update price feed accounts
|
|
26
|
+
* - Consume price updates in a consumer program
|
|
27
|
+
* - (Optionally) Close price update and encoded vaa accounts to recover the rent (`closeUpdateAccounts` in `PythTransactionBuilderConfig`)
|
|
28
|
+
*
|
|
29
|
+
* This class provides methods for working with both price update accounts and price feed accounts.
|
|
30
|
+
* Price update accounts are ephemeral accounts containing a single price update, whereas price feed accounts are long-lived
|
|
31
|
+
* accounts that always hold price data for a specific feed id. Price feed accounts can be updated to advance the current price.
|
|
32
|
+
* Applications should choose which type of account to work with based on their needs. In general, applications that
|
|
33
|
+
* want the price at a specific time (e.g., to settle a trade) should use price update accounts, while applications that want
|
|
34
|
+
* any recent price should use price feed accounts.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
*
|
|
39
|
+
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
40
|
+
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
41
|
+
* SOL_PRICE_FEED_ID,
|
|
42
|
+
* ETH_PRICE_FEED_ID,
|
|
43
|
+
* ]);
|
|
44
|
+
*
|
|
45
|
+
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
46
|
+
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
47
|
+
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
48
|
+
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
49
|
+
*
|
|
50
|
+
* await pythSolanaReceiver.provider.sendAll(await transactionBuilder.buildVersionedTransactions({computeUnitPriceMicroLamports:100000, tightComputeBudget: true}))
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class PythTransactionBuilder extends TransactionBuilder {
|
|
54
|
+
readonly pythSolanaReceiver: PythSolanaReceiver;
|
|
55
|
+
readonly closeInstructions: InstructionWithEphemeralSigners[];
|
|
56
|
+
readonly priceFeedIdToPriceUpdateAccount: Record<string, PublicKey>;
|
|
57
|
+
readonly closeUpdateAccounts: boolean;
|
|
58
|
+
constructor(pythSolanaReceiver: PythSolanaReceiver, config: PythTransactionBuilderConfig, addressLookupTable?: AddressLookupTableAccount);
|
|
59
|
+
/**
|
|
60
|
+
* Add instructions to post price updates to the builder.
|
|
61
|
+
* Use this function to post fully verified price updates from the present or from the past for your program to consume.
|
|
62
|
+
*
|
|
63
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
68
|
+
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
69
|
+
* SOL_PRICE_FEED_ID,
|
|
70
|
+
* ETH_PRICE_FEED_ID,
|
|
71
|
+
* ]);
|
|
72
|
+
*
|
|
73
|
+
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
74
|
+
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
75
|
+
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
76
|
+
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
addPostPriceUpdates(priceUpdateDataArray: string[]): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Add instructions to post partially verified price updates to the builder.
|
|
82
|
+
* Use this function to post partially verified price updates from the present or from the past for your program to consume.
|
|
83
|
+
*
|
|
84
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
85
|
+
*
|
|
86
|
+
* Partially verified price updates are price updates where not all the guardian signatures have been verified. By default this methods checks `DEFAULT_REDUCED_GUARDIAN_SET_SIZE` signatures when posting the VAA.
|
|
87
|
+
* If you are a on-chain program developer, make sure you understand the risks of consuming partially verified price updates here: {@link https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/solana/pyth_solana_receiver_sdk/src/price_update.rs}.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
92
|
+
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
93
|
+
* SOL_PRICE_FEED_ID,
|
|
94
|
+
* ETH_PRICE_FEED_ID,
|
|
95
|
+
* ]);
|
|
96
|
+
*
|
|
97
|
+
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
98
|
+
* await transactionBuilder.addPostPartiallyVerifiedPriceUpdates(priceUpdateData);
|
|
99
|
+
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
100
|
+
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
101
|
+
* ...
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
addPostPartiallyVerifiedPriceUpdates(priceUpdateDataArray: string[]): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Add instructions to update price feed accounts to the builder.
|
|
107
|
+
* Price feed accounts are fixed accounts per price feed id that can only be updated with a more recent price.
|
|
108
|
+
*
|
|
109
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
110
|
+
* @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.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
115
|
+
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
116
|
+
* SOL_PRICE_FEED_ID,
|
|
117
|
+
* ETH_PRICE_FEED_ID,
|
|
118
|
+
* ]);
|
|
119
|
+
*
|
|
120
|
+
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
121
|
+
* await transactionBuilder.addUpdatePriceFeed(priceUpdateData);
|
|
122
|
+
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
123
|
+
* ...
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
addUpdatePriceFeed(priceUpdateDataArray: string[], shardId: number): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Add instructions that consume price updates to the builder.
|
|
129
|
+
*
|
|
130
|
+
* @param getInstructions a function that given a mapping of price feed IDs to price update accounts, generates a series of instructions. Price 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.
|
|
131
|
+
* If multiple price 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.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* ...
|
|
136
|
+
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
137
|
+
* await transactionBuilder.addPriceConsumerInstructions(
|
|
138
|
+
* async (
|
|
139
|
+
* getPriceUpdateAccount: ( priceFeedId: string) => PublicKey
|
|
140
|
+
* ): Promise<InstructionWithEphemeralSigners[]> => {
|
|
141
|
+
* return [
|
|
142
|
+
* {
|
|
143
|
+
* instruction: await myFirstPythApp.methods
|
|
144
|
+
* .consume()
|
|
145
|
+
* .accounts({
|
|
146
|
+
* solPriceUpdate: getPriceUpdateAccount(SOL_PRICE_FEED_ID),
|
|
147
|
+
* ethPriceUpdate: getPriceUpdateAccount(ETH_PRICE_FEED_ID),
|
|
148
|
+
* })
|
|
149
|
+
* .instruction(),
|
|
150
|
+
* signers: [],
|
|
151
|
+
* },
|
|
152
|
+
* ];
|
|
153
|
+
* }
|
|
154
|
+
* );
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
addPriceConsumerInstructions(getInstructions: (getPriceUpdateAccount: (priceFeedId: string) => PublicKey) => Promise<InstructionWithEphemeralSigners[]>): Promise<void>;
|
|
158
|
+
/** Add instructions to close encoded VAA accounts from previous actions.
|
|
159
|
+
* 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.
|
|
160
|
+
* 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.
|
|
161
|
+
*/
|
|
162
|
+
addClosePreviousEncodedVaasInstructions(maxInstructions?: number): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Returns all the added instructions batched into versioned transactions, plus for each transaction the ephemeral signers that need to sign it
|
|
165
|
+
*/
|
|
166
|
+
buildVersionedTransactions(args: PriorityFeeConfig): Promise<{
|
|
167
|
+
tx: VersionedTransaction;
|
|
168
|
+
signers: Signer[];
|
|
169
|
+
}[]>;
|
|
170
|
+
/**
|
|
171
|
+
* Returns all the added instructions batched into transactions, plus for each transaction the ephemeral signers that need to sign it
|
|
172
|
+
*/
|
|
173
|
+
buildLegacyTransactions(args: PriorityFeeConfig): {
|
|
174
|
+
tx: Transaction;
|
|
175
|
+
signers: Signer[];
|
|
176
|
+
}[];
|
|
177
|
+
/**
|
|
178
|
+
* This method is used to retrieve the address of the price update account where the price update for a given price feed ID will be posted.
|
|
179
|
+
* If multiple price 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.
|
|
180
|
+
* */
|
|
181
|
+
getPriceUpdateAccount(priceFeedId: string): PublicKey;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A class to interact with the Pyth Solana Receiver program.
|
|
185
|
+
*
|
|
186
|
+
* This class provides helpful methods to build instructions to interact with the Pyth Solana Receiver program:
|
|
187
|
+
* - Post price updates (fully or partially verified)
|
|
188
|
+
* - Close price update and encoded vaa accounts to recover rent
|
|
189
|
+
*/
|
|
190
|
+
export declare class PythSolanaReceiver {
|
|
191
|
+
readonly connection: Connection;
|
|
192
|
+
readonly wallet: Wallet;
|
|
193
|
+
readonly provider: AnchorProvider;
|
|
194
|
+
readonly receiver: Program<PythSolanaReceiverProgram>;
|
|
195
|
+
readonly wormhole: Program<WormholeCoreBridgeSolana>;
|
|
196
|
+
readonly pushOracle: Program<PythPushOracle>;
|
|
197
|
+
readonly treasuryId?: number | undefined;
|
|
198
|
+
constructor({ connection, wallet, wormholeProgramId, receiverProgramId, pushOracleProgramId, treasuryId, }: {
|
|
199
|
+
connection: Connection;
|
|
200
|
+
wallet: Wallet;
|
|
201
|
+
wormholeProgramId?: PublicKey;
|
|
202
|
+
receiverProgramId?: PublicKey;
|
|
203
|
+
pushOracleProgramId?: PublicKey;
|
|
204
|
+
treasuryId?: number;
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* Get a new transaction builder to build transactions that interact with the Pyth Solana Receiver program and consume price updates
|
|
208
|
+
*/
|
|
209
|
+
newTransactionBuilder(config: PythTransactionBuilderConfig, addressLookupAccount?: AddressLookupTableAccount): PythTransactionBuilder;
|
|
210
|
+
/**
|
|
211
|
+
* 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.
|
|
212
|
+
*
|
|
213
|
+
* This function uses partially verified price updates. Partially verified price updates are price updates where not all the guardian signatures have been verified. By default this methods checks `DEFAULT_REDUCED_GUARDIAN_SET_SIZE` signatures when posting the VAA.
|
|
214
|
+
* If you are a on-chain program developer, make sure you understand the risks of consuming partially verified price updates here: {@link https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/solana/pyth_solana_receiver_sdk/src/price_update.rs}.
|
|
215
|
+
*
|
|
216
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
217
|
+
* @returns `postInstructions`: the instructions to post the price updates, these should be called before consuming the price updates
|
|
218
|
+
* @returns `priceFeedIdToPriceUpdateAccount`: this is a map of price feed IDs to Solana address. Given a price feed ID, you can use this map to find the account where `postInstructions` will post the price update.
|
|
219
|
+
* @returns `closeInstructions`: the instructions to close the price update accounts, these should be called after consuming the price updates
|
|
220
|
+
*/
|
|
221
|
+
buildPostPriceUpdateAtomicInstructions(priceUpdateDataArray: string[]): Promise<{
|
|
222
|
+
postInstructions: InstructionWithEphemeralSigners[];
|
|
223
|
+
priceFeedIdToPriceUpdateAccount: Record<string, PublicKey>;
|
|
224
|
+
closeInstructions: InstructionWithEphemeralSigners[];
|
|
225
|
+
}>;
|
|
226
|
+
/**
|
|
227
|
+
* Build a series of helper instructions that post price updates to the Pyth Solana Receiver program and another series to close the encoded vaa accounts and the price update accounts.
|
|
228
|
+
*
|
|
229
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
230
|
+
* @returns `postInstructions`: the instructions to post the price updates, these should be called before consuming the price updates
|
|
231
|
+
* @returns `priceFeedIdToPriceUpdateAccount`: this is a map of price feed IDs to Solana address. Given a price feed ID, you can use this map to find the account where `postInstructions` will post the price update.
|
|
232
|
+
* @returns `closeInstructions`: the instructions to close the price update accounts, these should be called after consuming the price updates
|
|
233
|
+
*/
|
|
234
|
+
buildPostPriceUpdateInstructions(priceUpdateDataArray: string[]): Promise<{
|
|
235
|
+
postInstructions: InstructionWithEphemeralSigners[];
|
|
236
|
+
priceFeedIdToPriceUpdateAccount: Record<string, PublicKey>;
|
|
237
|
+
closeInstructions: InstructionWithEphemeralSigners[];
|
|
238
|
+
}>;
|
|
239
|
+
/**
|
|
240
|
+
* Build a series of helper instructions that update one or many price feed accounts and another series to close the encoded vaa accounts used to update the price feed accounts.
|
|
241
|
+
*
|
|
242
|
+
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
243
|
+
* @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.
|
|
244
|
+
* @returns `postInstructions`: the instructions to update the price feed accounts. If the price feed accounts don't contain a recent update, these should be called before consuming the price updates.
|
|
245
|
+
* @returns `priceFeedIdToPriceUpdateAccount`: this is a map of price feed IDs to Solana address. Given a price feed ID, you can use this map to find the account where `postInstructions` will post the price update. Note that since price feed accounts are PDAs, the address of the account can also be found with `getPriceFeedAccountAddress`.
|
|
246
|
+
* @returns `closeInstructions`: the instructions to close the encoded VAA accounts that were used to update the price feed accounts.
|
|
247
|
+
*/
|
|
248
|
+
buildUpdatePriceFeedInstructions(priceUpdateDataArray: string[], shardId: number): Promise<{
|
|
249
|
+
postInstructions: InstructionWithEphemeralSigners[];
|
|
250
|
+
priceFeedIdToPriceUpdateAccount: Record<string, PublicKey>;
|
|
251
|
+
closeInstructions: InstructionWithEphemeralSigners[];
|
|
252
|
+
}>;
|
|
253
|
+
/**
|
|
254
|
+
* Build a series of helper instructions that post a VAA in an encoded VAA account. This function is bespoke for posting Pyth VAAs and might not work for other usecases.
|
|
255
|
+
*
|
|
256
|
+
* @param vaa a Wormhole VAA
|
|
257
|
+
* @returns `encodedVaaAddress`: the address of the encoded VAA account where the VAA will be posted
|
|
258
|
+
* @returns `postInstructions`: the instructions to post the VAA
|
|
259
|
+
* @returns `closeInstructions`: the instructions to close the encoded VAA account
|
|
260
|
+
*/
|
|
261
|
+
buildPostEncodedVaaInstructions(vaa: Buffer): Promise<{
|
|
262
|
+
encodedVaaAddress: PublicKey;
|
|
263
|
+
postInstructions: InstructionWithEphemeralSigners[];
|
|
264
|
+
closeInstructions: InstructionWithEphemeralSigners[];
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Build an instruction to close an encoded VAA account, recovering the rent.
|
|
268
|
+
*/
|
|
269
|
+
buildCloseEncodedVaaInstruction(encodedVaa: PublicKey): Promise<InstructionWithEphemeralSigners>;
|
|
270
|
+
/**
|
|
271
|
+
* Build aset of instructions to close all the existing encoded VAA accounts owned by this PythSolanaReceiver's wallet
|
|
272
|
+
*/
|
|
273
|
+
buildClosePreviousEncodedVaasInstructions(maxInstructions: number): Promise<InstructionWithEphemeralSigners[]>;
|
|
274
|
+
/**
|
|
275
|
+
* Build an instruction to close a price update account, recovering the rent.
|
|
276
|
+
*/
|
|
277
|
+
buildClosePriceUpdateInstruction(priceUpdateAccount: PublicKey): Promise<InstructionWithEphemeralSigners>;
|
|
278
|
+
/**
|
|
279
|
+
* Returns a set of versioned transactions that contain the provided instructions in the same order and with efficient batching
|
|
280
|
+
*/
|
|
281
|
+
batchIntoVersionedTransactions(instructions: InstructionWithEphemeralSigners[], priorityFeeConfig: PriorityFeeConfig, addressLookupTable?: AddressLookupTableAccount): Promise<{
|
|
282
|
+
tx: VersionedTransaction;
|
|
283
|
+
signers: Signer[];
|
|
284
|
+
}[]>;
|
|
285
|
+
/**
|
|
286
|
+
* Fetch the contents of a price update account
|
|
287
|
+
* @param priceUpdateAccount The address of the price update account
|
|
288
|
+
* @returns The contents of the deserialized price update account or `null` if the account doesn't exist
|
|
289
|
+
*/
|
|
290
|
+
fetchPriceUpdateAccount(priceUpdateAccount: PublicKey): Promise<PriceUpdateAccount | null>;
|
|
291
|
+
/**
|
|
292
|
+
* Fetch the contents of a price feed account
|
|
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.
|
|
294
|
+
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
295
|
+
* @returns The contents of the deserialized price feed account or `null` if the account doesn't exist
|
|
296
|
+
*/
|
|
297
|
+
fetchPriceFeedAccount(shardId: number, priceFeedId: Buffer | string): Promise<PriceUpdateAccount | null>;
|
|
298
|
+
/**
|
|
299
|
+
* Derive the address of a price feed account
|
|
300
|
+
* @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.
|
|
301
|
+
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
302
|
+
* @returns The address of the price feed account
|
|
303
|
+
*/
|
|
304
|
+
getPriceFeedAccountAddress(shardId: number, priceFeedId: Buffer | string): PublicKey;
|
|
305
|
+
/**
|
|
306
|
+
* Find all the encoded VAA accounts owned by this PythSolanaReceiver's wallet
|
|
307
|
+
* @returns a list of the public keys of the encoded VAA accounts
|
|
308
|
+
*/
|
|
309
|
+
findOwnedEncodedVaaAccounts(): Promise<PublicKey[]>;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Derive the address of a price feed account
|
|
313
|
+
* @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.
|
|
314
|
+
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
315
|
+
* @param pushOracleProgramId The program ID of the Pyth Push Oracle program. If not provided, the default deployment will be used.
|
|
316
|
+
* @returns The address of the price feed account
|
|
317
|
+
*/
|
|
318
|
+
export declare function getPriceFeedAccountForProgram(shardId: number, priceFeedId: Buffer | string, pushOracleProgramId?: PublicKey): PublicKey;
|