@pythnetwork/pyth-solana-receiver 0.11.0 → 0.13.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/dist/PythSolanaReceiver.cjs +581 -0
- package/{lib → dist}/PythSolanaReceiver.d.ts +10 -10
- package/dist/address.cjs +61 -0
- package/{lib → dist}/address.d.ts +0 -1
- package/dist/compute_budget.cjs +46 -0
- package/{lib → dist}/compute_budget.d.ts +0 -1
- package/{lib/idl/pyth_push_oracle.js → dist/idl/pyth_push_oracle.cjs} +50 -37
- package/{lib → dist}/idl/pyth_push_oracle.d.ts +0 -1
- package/{lib/idl/pyth_solana_receiver.js → dist/idl/pyth_solana_receiver.cjs} +309 -236
- package/{lib → dist}/idl/pyth_solana_receiver.d.ts +79 -23
- package/{lib/idl/wormhole_core_bridge_solana.js → dist/idl/wormhole_core_bridge_solana.cjs} +607 -464
- package/{lib → dist}/idl/wormhole_core_bridge_solana.d.ts +0 -1
- package/dist/index.cjs +44 -0
- package/dist/index.d.ts +5 -0
- package/dist/package.json +1 -0
- package/dist/vaa.cjs +221 -0
- package/{lib → dist}/vaa.d.ts +6 -7
- package/package.json +52 -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/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
|
@@ -1,633 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PythSolanaReceiver = exports.PythTransactionBuilder = exports.DEFAULT_TREASURY_ID = void 0;
|
|
4
|
-
exports.getPriceFeedAccountForProgram = getPriceFeedAccountForProgram;
|
|
5
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
|
-
const pyth_solana_receiver_1 = require("./idl/pyth_solana_receiver");
|
|
7
|
-
const wormhole_core_bridge_solana_1 = require("./idl/wormhole_core_bridge_solana");
|
|
8
|
-
const address_1 = require("./address");
|
|
9
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
-
const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
|
|
11
|
-
const compute_budget_1 = require("./compute_budget");
|
|
12
|
-
const vaa_1 = require("./vaa");
|
|
13
|
-
const solana_utils_1 = require("@pythnetwork/solana-utils");
|
|
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;
|
|
20
|
-
/**
|
|
21
|
-
* A builder class to build transactions that:
|
|
22
|
-
* - Post price updates (fully or partially verified) or update price feed accounts
|
|
23
|
-
* - Consume price updates in a consumer program
|
|
24
|
-
* - (Optionally) Close price update and encoded vaa accounts to recover the rent (`closeUpdateAccounts` in `PythTransactionBuilderConfig`)
|
|
25
|
-
*
|
|
26
|
-
* This class provides methods for working with both price update accounts and price feed accounts.
|
|
27
|
-
* Price update accounts are ephemeral accounts containing a single price update, whereas price feed accounts are long-lived
|
|
28
|
-
* accounts that always hold price data for a specific feed id. Price feed accounts can be updated to advance the current price.
|
|
29
|
-
* Applications should choose which type of account to work with based on their needs. In general, applications that
|
|
30
|
-
* want the price at a specific time (e.g., to settle a trade) should use price update accounts, while applications that want
|
|
31
|
-
* any recent price should use price feed accounts.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
*
|
|
36
|
-
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
37
|
-
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
38
|
-
* SOL_PRICE_FEED_ID,
|
|
39
|
-
* ETH_PRICE_FEED_ID,
|
|
40
|
-
* ]);
|
|
41
|
-
*
|
|
42
|
-
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
43
|
-
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
44
|
-
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
45
|
-
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
46
|
-
*
|
|
47
|
-
* await pythSolanaReceiver.provider.sendAll(await transactionBuilder.buildVersionedTransactions({computeUnitPriceMicroLamports:100000, tightComputeBudget: true}))
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
class PythTransactionBuilder extends solana_utils_1.TransactionBuilder {
|
|
51
|
-
pythSolanaReceiver;
|
|
52
|
-
closeInstructions;
|
|
53
|
-
priceFeedIdToPriceUpdateAccount;
|
|
54
|
-
priceFeedIdToTwapUpdateAccount;
|
|
55
|
-
closeUpdateAccounts;
|
|
56
|
-
constructor(pythSolanaReceiver, config, addressLookupTable) {
|
|
57
|
-
super(pythSolanaReceiver.wallet.publicKey, pythSolanaReceiver.connection, addressLookupTable);
|
|
58
|
-
this.pythSolanaReceiver = pythSolanaReceiver;
|
|
59
|
-
this.closeInstructions = [];
|
|
60
|
-
this.priceFeedIdToPriceUpdateAccount = {};
|
|
61
|
-
this.priceFeedIdToTwapUpdateAccount = {};
|
|
62
|
-
this.closeUpdateAccounts = config.closeUpdateAccounts ?? true;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Add instructions to post price updates to the builder.
|
|
66
|
-
* Use this function to post fully verified price updates from the present or from the past for your program to consume.
|
|
67
|
-
*
|
|
68
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
73
|
-
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
74
|
-
* SOL_PRICE_FEED_ID,
|
|
75
|
-
* ETH_PRICE_FEED_ID,
|
|
76
|
-
* ]);
|
|
77
|
-
*
|
|
78
|
-
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
79
|
-
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
80
|
-
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
81
|
-
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
async addPostPriceUpdates(priceUpdateDataArray) {
|
|
85
|
-
const { postInstructions, priceFeedIdToPriceUpdateAccount, closeInstructions, } = await this.pythSolanaReceiver.buildPostPriceUpdateInstructions(priceUpdateDataArray);
|
|
86
|
-
this.closeInstructions.push(...closeInstructions);
|
|
87
|
-
Object.assign(this.priceFeedIdToPriceUpdateAccount, priceFeedIdToPriceUpdateAccount);
|
|
88
|
-
this.addInstructions(postInstructions);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Add instructions to post partially verified price updates to the builder.
|
|
92
|
-
* Use this function to post partially verified price updates from the present or from the past for your program to consume.
|
|
93
|
-
*
|
|
94
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
95
|
-
*
|
|
96
|
-
* 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.
|
|
97
|
-
* 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}.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
102
|
-
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
103
|
-
* SOL_PRICE_FEED_ID,
|
|
104
|
-
* ETH_PRICE_FEED_ID,
|
|
105
|
-
* ]);
|
|
106
|
-
*
|
|
107
|
-
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
108
|
-
* await transactionBuilder.addPostPartiallyVerifiedPriceUpdates(priceUpdateData);
|
|
109
|
-
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
110
|
-
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
111
|
-
* ...
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
async addPostPartiallyVerifiedPriceUpdates(priceUpdateDataArray) {
|
|
115
|
-
const { postInstructions, priceFeedIdToPriceUpdateAccount, closeInstructions, } = await this.pythSolanaReceiver.buildPostPriceUpdateAtomicInstructions(priceUpdateDataArray);
|
|
116
|
-
this.closeInstructions.push(...closeInstructions);
|
|
117
|
-
Object.assign(this.priceFeedIdToPriceUpdateAccount, priceFeedIdToPriceUpdateAccount);
|
|
118
|
-
this.addInstructions(postInstructions);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Add instructions to post TWAP updates to the builder.
|
|
122
|
-
* Use this function to post fully verified TWAP updates from the present or from the past for your program to consume.
|
|
123
|
-
*
|
|
124
|
-
* @param twapUpdateDataArray the output of the `@pythnetwork/hermes-client`'s `getLatestTwaps`. This is an array of verifiable price updates.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
129
|
-
* const twapUpdateData = await hermesClient.getLatestTwaps([
|
|
130
|
-
* SOL_PRICE_FEED_ID,
|
|
131
|
-
* ETH_PRICE_FEED_ID,
|
|
132
|
-
* ]);
|
|
133
|
-
*
|
|
134
|
-
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
135
|
-
* await transactionBuilder.addPostTwapUpdates(priceUpdateData);
|
|
136
|
-
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getTwapUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
|
|
137
|
-
* await transactionBuilder.addTwapConsumerInstructions(...)
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
async addPostTwapUpdates(twapUpdateDataArray) {
|
|
141
|
-
const { postInstructions, priceFeedIdToTwapUpdateAccount, closeInstructions, } = await this.pythSolanaReceiver.buildPostTwapUpdateInstructions(twapUpdateDataArray);
|
|
142
|
-
this.closeInstructions.push(...closeInstructions);
|
|
143
|
-
Object.assign(this.priceFeedIdToTwapUpdateAccount, priceFeedIdToTwapUpdateAccount);
|
|
144
|
-
this.addInstructions(postInstructions);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Add instructions to update price feed accounts to the builder.
|
|
148
|
-
* Price feed accounts are fixed accounts per price feed id that can only be updated with a more recent price.
|
|
149
|
-
*
|
|
150
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
151
|
-
* @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.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* // Get the price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
|
|
156
|
-
* const priceUpdateData = await priceServiceConnection.getLatestVaas([
|
|
157
|
-
* SOL_PRICE_FEED_ID,
|
|
158
|
-
* ETH_PRICE_FEED_ID,
|
|
159
|
-
* ]);
|
|
160
|
-
*
|
|
161
|
-
* const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({});
|
|
162
|
-
* await transactionBuilder.addUpdatePriceFeed(priceUpdateData);
|
|
163
|
-
* await transactionBuilder.addPriceConsumerInstructions(...)
|
|
164
|
-
* ...
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
async addUpdatePriceFeed(priceUpdateDataArray, shardId) {
|
|
168
|
-
const { postInstructions, priceFeedIdToPriceUpdateAccount, closeInstructions, } = await this.pythSolanaReceiver.buildUpdatePriceFeedInstructions(priceUpdateDataArray, shardId);
|
|
169
|
-
this.closeInstructions.push(...closeInstructions);
|
|
170
|
-
Object.assign(this.priceFeedIdToPriceUpdateAccount, priceFeedIdToPriceUpdateAccount);
|
|
171
|
-
this.addInstructions(postInstructions);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Add instructions that consume price updates to the builder.
|
|
175
|
-
*
|
|
176
|
-
* @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.
|
|
177
|
-
* 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.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* ...
|
|
182
|
-
* await transactionBuilder.addPostPriceUpdates(priceUpdateData);
|
|
183
|
-
* await transactionBuilder.addPriceConsumerInstructions(
|
|
184
|
-
* async (
|
|
185
|
-
* getPriceUpdateAccount: ( priceFeedId: string) => PublicKey
|
|
186
|
-
* ): Promise<InstructionWithEphemeralSigners[]> => {
|
|
187
|
-
* return [
|
|
188
|
-
* {
|
|
189
|
-
* instruction: await myFirstPythApp.methods
|
|
190
|
-
* .consume()
|
|
191
|
-
* .accounts({
|
|
192
|
-
* solPriceUpdate: getPriceUpdateAccount(SOL_PRICE_FEED_ID),
|
|
193
|
-
* ethPriceUpdate: getPriceUpdateAccount(ETH_PRICE_FEED_ID),
|
|
194
|
-
* })
|
|
195
|
-
* .instruction(),
|
|
196
|
-
* signers: [],
|
|
197
|
-
* },
|
|
198
|
-
* ];
|
|
199
|
-
* }
|
|
200
|
-
* );
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
async addPriceConsumerInstructions(getInstructions) {
|
|
204
|
-
this.addInstructions(await getInstructions(this.getPriceUpdateAccount.bind(this)));
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Add instructions that consume TWAP updates to the builder.
|
|
208
|
-
*
|
|
209
|
-
* @param getInstructions a function that given a mapping of price feed IDs to TWAP update accounts, generates a series of instructions. TWAP updates get posted to ephemeral accounts and this function allows the user to indicate which accounts in their instruction need to be "replaced" with each price update account.
|
|
210
|
-
* If multiple TWAP updates for the same price feed ID are posted with the same builder, the account corresponding to the last update to get posted will be used.
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```typescript
|
|
214
|
-
* ...
|
|
215
|
-
* await transactionBuilder.addPostTwapUpdates(twapUpdateData);
|
|
216
|
-
* await transactionBuilder.addTwapConsumerInstructions(
|
|
217
|
-
* async (
|
|
218
|
-
* getTwapUpdateAccount: ( priceFeedId: string) => PublicKey
|
|
219
|
-
* ): Promise<InstructionWithEphemeralSigners[]> => {
|
|
220
|
-
* return [
|
|
221
|
-
* {
|
|
222
|
-
* instruction: await myFirstPythApp.methods
|
|
223
|
-
* .consume()
|
|
224
|
-
* .accounts({
|
|
225
|
-
* solTwapUpdate: getTwapUpdateAccount(SOL_PRICE_FEED_ID),
|
|
226
|
-
* ethTwapUpdate: getTwapUpdateAccount(ETH_PRICE_FEED_ID),
|
|
227
|
-
* })
|
|
228
|
-
* .instruction(),
|
|
229
|
-
* signers: [],
|
|
230
|
-
* },
|
|
231
|
-
* ];
|
|
232
|
-
* }
|
|
233
|
-
* );
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
async addTwapConsumerInstructions(getInstructions) {
|
|
237
|
-
this.addInstructions(await getInstructions(this.getTwapUpdateAccount.bind(this)));
|
|
238
|
-
}
|
|
239
|
-
/** Add instructions to close encoded VAA accounts from previous actions.
|
|
240
|
-
* 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.
|
|
241
|
-
* 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.
|
|
242
|
-
*/
|
|
243
|
-
async addClosePreviousEncodedVaasInstructions(maxInstructions = 40) {
|
|
244
|
-
this.addInstructions(await this.pythSolanaReceiver.buildClosePreviousEncodedVaasInstructions(maxInstructions));
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Returns all the added instructions batched into versioned transactions, plus for each transaction the ephemeral signers that need to sign it
|
|
248
|
-
*/
|
|
249
|
-
async buildVersionedTransactions(args) {
|
|
250
|
-
if (this.closeUpdateAccounts) {
|
|
251
|
-
this.addInstructions(this.closeInstructions);
|
|
252
|
-
}
|
|
253
|
-
return super.buildVersionedTransactions(args);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Returns all the added instructions batched into transactions, plus for each transaction the ephemeral signers that need to sign it
|
|
257
|
-
*/
|
|
258
|
-
buildLegacyTransactions(args) {
|
|
259
|
-
if (this.closeUpdateAccounts) {
|
|
260
|
-
this.addInstructions(this.closeInstructions);
|
|
261
|
-
}
|
|
262
|
-
return super.buildLegacyTransactions(args);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* 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.
|
|
266
|
-
* 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.
|
|
267
|
-
* */
|
|
268
|
-
getPriceUpdateAccount(priceFeedId) {
|
|
269
|
-
const priceUpdateAccount = this.priceFeedIdToPriceUpdateAccount[priceFeedId];
|
|
270
|
-
if (!priceUpdateAccount) {
|
|
271
|
-
throw new Error(`No price update account found for the price feed ID ${priceFeedId}. Make sure to call addPostPriceUpdates or addPostPartiallyVerifiedPriceUpdates before calling this function.`);
|
|
272
|
-
}
|
|
273
|
-
return priceUpdateAccount;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* This method is used to retrieve the address of the TWAP update account where the TWAP update for a given price feed ID will be posted.
|
|
277
|
-
* If multiple updates for the same price feed ID will be posted with the same builder, the address of the account corresponding to the last update to get posted will be returned.
|
|
278
|
-
* */
|
|
279
|
-
getTwapUpdateAccount(priceFeedId) {
|
|
280
|
-
const twapUpdateAccount = this.priceFeedIdToTwapUpdateAccount[priceFeedId];
|
|
281
|
-
if (!twapUpdateAccount) {
|
|
282
|
-
throw new Error(`No TWAP update account found for the price feed ID ${priceFeedId}. Make sure to call addPostTwapUpdates before calling this function.`);
|
|
283
|
-
}
|
|
284
|
-
return twapUpdateAccount;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
exports.PythTransactionBuilder = PythTransactionBuilder;
|
|
288
|
-
/**
|
|
289
|
-
* A class to interact with the Pyth Solana Receiver program.
|
|
290
|
-
*
|
|
291
|
-
* This class provides helpful methods to build instructions to interact with the Pyth Solana Receiver program:
|
|
292
|
-
* - Post price updates (fully or partially verified)
|
|
293
|
-
* - Close price update and encoded vaa accounts to recover rent
|
|
294
|
-
*/
|
|
295
|
-
class PythSolanaReceiver {
|
|
296
|
-
connection;
|
|
297
|
-
wallet;
|
|
298
|
-
provider;
|
|
299
|
-
receiver;
|
|
300
|
-
wormhole;
|
|
301
|
-
pushOracle;
|
|
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
|
-
}
|
|
307
|
-
this.connection = connection;
|
|
308
|
-
this.wallet = wallet;
|
|
309
|
-
this.provider = new anchor_1.AnchorProvider(this.connection, this.wallet, {
|
|
310
|
-
commitment: connection.commitment,
|
|
311
|
-
});
|
|
312
|
-
this.receiver = new anchor_1.Program(pyth_solana_receiver_1.IDL, receiverProgramId, this.provider);
|
|
313
|
-
this.wormhole = new anchor_1.Program(wormhole_core_bridge_solana_1.IDL, wormholeProgramId, this.provider);
|
|
314
|
-
this.pushOracle = new anchor_1.Program(pyth_push_oracle_1.IDL, pushOracleProgramId, this.provider);
|
|
315
|
-
this.treasuryId = treasuryId;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Get a new transaction builder to build transactions that interact with the Pyth Solana Receiver program and consume price updates
|
|
319
|
-
*/
|
|
320
|
-
newTransactionBuilder(config, addressLookupAccount) {
|
|
321
|
-
return new PythTransactionBuilder(this, config, addressLookupAccount);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
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.
|
|
325
|
-
*
|
|
326
|
-
* 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.
|
|
327
|
-
* 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}.
|
|
328
|
-
*
|
|
329
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
330
|
-
* @returns `postInstructions`: the instructions to post the price updates, these should be called before consuming the price updates
|
|
331
|
-
* @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.
|
|
332
|
-
* @returns `closeInstructions`: the instructions to close the price update accounts, these should be called after consuming the price updates
|
|
333
|
-
*/
|
|
334
|
-
async buildPostPriceUpdateAtomicInstructions(priceUpdateDataArray) {
|
|
335
|
-
const postInstructions = [];
|
|
336
|
-
const priceFeedIdToPriceUpdateAccount = {};
|
|
337
|
-
const closeInstructions = [];
|
|
338
|
-
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
339
|
-
for (const priceUpdateData of priceUpdateDataArray) {
|
|
340
|
-
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
341
|
-
const guardianSetIndex = (0, vaa_1.getGuardianSetIndex)(accumulatorUpdateData.vaa);
|
|
342
|
-
const trimmedVaa = (0, vaa_1.trimSignatures)(accumulatorUpdateData.vaa);
|
|
343
|
-
for (const update of accumulatorUpdateData.updates) {
|
|
344
|
-
const priceUpdateKeypair = new web3_js_1.Keypair();
|
|
345
|
-
postInstructions.push({
|
|
346
|
-
instruction: await this.receiver.methods
|
|
347
|
-
.postUpdateAtomic({
|
|
348
|
-
vaa: trimmedVaa,
|
|
349
|
-
merklePriceUpdate: update,
|
|
350
|
-
treasuryId,
|
|
351
|
-
})
|
|
352
|
-
.accounts({
|
|
353
|
-
priceUpdateAccount: priceUpdateKeypair.publicKey,
|
|
354
|
-
treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
|
|
355
|
-
config: (0, address_1.getConfigPda)(this.receiver.programId),
|
|
356
|
-
guardianSet: (0, address_1.getGuardianSetPda)(guardianSetIndex, this.wormhole.programId),
|
|
357
|
-
})
|
|
358
|
-
.instruction(),
|
|
359
|
-
signers: [priceUpdateKeypair],
|
|
360
|
-
computeUnits: compute_budget_1.POST_UPDATE_ATOMIC_COMPUTE_BUDGET,
|
|
361
|
-
});
|
|
362
|
-
priceFeedIdToPriceUpdateAccount["0x" + (0, price_service_sdk_1.parsePriceFeedMessage)(update.message).feedId.toString("hex")] = priceUpdateKeypair.publicKey;
|
|
363
|
-
closeInstructions.push(await this.buildClosePriceUpdateInstruction(priceUpdateKeypair.publicKey));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
postInstructions,
|
|
368
|
-
priceFeedIdToPriceUpdateAccount,
|
|
369
|
-
closeInstructions,
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* 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.
|
|
374
|
-
*
|
|
375
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
376
|
-
* @returns `postInstructions`: the instructions to post the price updates, these should be called before consuming the price updates
|
|
377
|
-
* @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.
|
|
378
|
-
* @returns `closeInstructions`: the instructions to close the price update accounts, these should be called after consuming the price updates
|
|
379
|
-
*/
|
|
380
|
-
async buildPostPriceUpdateInstructions(priceUpdateDataArray) {
|
|
381
|
-
const postInstructions = [];
|
|
382
|
-
const priceFeedIdToPriceUpdateAccount = {};
|
|
383
|
-
const closeInstructions = [];
|
|
384
|
-
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
385
|
-
for (const priceUpdateData of priceUpdateDataArray) {
|
|
386
|
-
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
387
|
-
const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
|
|
388
|
-
postInstructions.push(...postEncodedVaaInstructions);
|
|
389
|
-
closeInstructions.push(...postEncodedVaacloseInstructions);
|
|
390
|
-
for (const update of accumulatorUpdateData.updates) {
|
|
391
|
-
const priceUpdateKeypair = new web3_js_1.Keypair();
|
|
392
|
-
postInstructions.push({
|
|
393
|
-
instruction: await this.receiver.methods
|
|
394
|
-
.postUpdate({
|
|
395
|
-
merklePriceUpdate: update,
|
|
396
|
-
treasuryId,
|
|
397
|
-
})
|
|
398
|
-
.accounts({
|
|
399
|
-
encodedVaa,
|
|
400
|
-
priceUpdateAccount: priceUpdateKeypair.publicKey,
|
|
401
|
-
treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
|
|
402
|
-
config: (0, address_1.getConfigPda)(this.receiver.programId),
|
|
403
|
-
})
|
|
404
|
-
.instruction(),
|
|
405
|
-
signers: [priceUpdateKeypair],
|
|
406
|
-
computeUnits: compute_budget_1.POST_UPDATE_COMPUTE_BUDGET,
|
|
407
|
-
});
|
|
408
|
-
priceFeedIdToPriceUpdateAccount["0x" + (0, price_service_sdk_1.parsePriceFeedMessage)(update.message).feedId.toString("hex")] = priceUpdateKeypair.publicKey;
|
|
409
|
-
closeInstructions.push(await this.buildClosePriceUpdateInstruction(priceUpdateKeypair.publicKey));
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return {
|
|
413
|
-
postInstructions,
|
|
414
|
-
priceFeedIdToPriceUpdateAccount,
|
|
415
|
-
closeInstructions,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Build a series of helper instructions that post TWAP updates to the Pyth Solana Receiver program and another series to close the encoded vaa accounts and the TWAP update accounts.
|
|
420
|
-
*
|
|
421
|
-
* @param twapUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestTwaps`. This is an array of verifiable price updates.
|
|
422
|
-
* @returns `postInstructions`: the instructions to post the TWAP updates, these should be called before consuming the price updates
|
|
423
|
-
* @returns `priceFeedIdToTwapUpdateAccount`: 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 TWAP update.
|
|
424
|
-
* @returns `closeInstructions`: the instructions to close the TWAP update accounts, these should be called after consuming the TWAP updates
|
|
425
|
-
*/
|
|
426
|
-
async buildPostTwapUpdateInstructions(twapUpdateDataArray) {
|
|
427
|
-
const postInstructions = [];
|
|
428
|
-
const priceFeedIdToTwapUpdateAccount = {};
|
|
429
|
-
const closeInstructions = [];
|
|
430
|
-
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
431
|
-
if (twapUpdateDataArray.length !== 2) {
|
|
432
|
-
throw new Error("twapUpdateDataArray must contain exactly two updates (start and end)");
|
|
433
|
-
}
|
|
434
|
-
const [startUpdateData, endUpdateData] = twapUpdateDataArray.map((data) => (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(data, "base64")));
|
|
435
|
-
// Validate that the start and end updates contain the same number of price feeds
|
|
436
|
-
if (startUpdateData.updates.length !== endUpdateData.updates.length) {
|
|
437
|
-
throw new Error("Start and end updates must contain the same number of price feeds");
|
|
438
|
-
}
|
|
439
|
-
// Post encoded VAAs
|
|
440
|
-
const { postInstructions: buildVaasInstructions, closeInstructions: closeVaasInstructions, startEncodedVaaAddress, endEncodedVaaAddress, } = await (0, vaa_1.buildPostEncodedVaasForTwapInstructions)(this.wormhole, startUpdateData, endUpdateData);
|
|
441
|
-
postInstructions.push(...buildVaasInstructions);
|
|
442
|
-
closeInstructions.push(...closeVaasInstructions);
|
|
443
|
-
// Post a TWAP update to the receiver contract for each price feed
|
|
444
|
-
for (let i = 0; i < startUpdateData.updates.length; i++) {
|
|
445
|
-
const startUpdate = startUpdateData.updates[i];
|
|
446
|
-
const endUpdate = endUpdateData.updates[i];
|
|
447
|
-
const twapUpdateKeypair = new web3_js_1.Keypair();
|
|
448
|
-
postInstructions.push({
|
|
449
|
-
instruction: await this.receiver.methods
|
|
450
|
-
.postTwapUpdate({
|
|
451
|
-
startMerklePriceUpdate: startUpdate,
|
|
452
|
-
endMerklePriceUpdate: endUpdate,
|
|
453
|
-
treasuryId,
|
|
454
|
-
})
|
|
455
|
-
.accounts({
|
|
456
|
-
startEncodedVaa: startEncodedVaaAddress,
|
|
457
|
-
endEncodedVaa: endEncodedVaaAddress,
|
|
458
|
-
twapUpdateAccount: twapUpdateKeypair.publicKey,
|
|
459
|
-
treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
|
|
460
|
-
config: (0, address_1.getConfigPda)(this.receiver.programId),
|
|
461
|
-
})
|
|
462
|
-
.instruction(),
|
|
463
|
-
signers: [twapUpdateKeypair],
|
|
464
|
-
computeUnits: compute_budget_1.POST_TWAP_UPDATE_COMPUTE_BUDGET,
|
|
465
|
-
});
|
|
466
|
-
priceFeedIdToTwapUpdateAccount["0x" + (0, price_service_sdk_1.parseTwapMessage)(startUpdate.message).feedId.toString("hex")] = twapUpdateKeypair.publicKey;
|
|
467
|
-
closeInstructions.push(await this.buildCloseTwapUpdateInstruction(twapUpdateKeypair.publicKey));
|
|
468
|
-
}
|
|
469
|
-
return {
|
|
470
|
-
postInstructions,
|
|
471
|
-
priceFeedIdToTwapUpdateAccount,
|
|
472
|
-
closeInstructions,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* 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.
|
|
477
|
-
*
|
|
478
|
-
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
|
|
479
|
-
* @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.
|
|
480
|
-
* @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.
|
|
481
|
-
* @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`.
|
|
482
|
-
* @returns `closeInstructions`: the instructions to close the encoded VAA accounts that were used to update the price feed accounts.
|
|
483
|
-
*/
|
|
484
|
-
async buildUpdatePriceFeedInstructions(priceUpdateDataArray, shardId) {
|
|
485
|
-
const postInstructions = [];
|
|
486
|
-
const priceFeedIdToPriceUpdateAccount = {};
|
|
487
|
-
const closeInstructions = [];
|
|
488
|
-
const treasuryId = this.treasuryId ?? (0, address_1.getRandomTreasuryId)();
|
|
489
|
-
for (const priceUpdateData of priceUpdateDataArray) {
|
|
490
|
-
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(priceUpdateData, "base64"));
|
|
491
|
-
const { postInstructions: postEncodedVaaInstructions, encodedVaaAddress: encodedVaa, closeInstructions: postEncodedVaacloseInstructions, } = await this.buildPostEncodedVaaInstructions(accumulatorUpdateData.vaa);
|
|
492
|
-
postInstructions.push(...postEncodedVaaInstructions);
|
|
493
|
-
closeInstructions.push(...postEncodedVaacloseInstructions);
|
|
494
|
-
for (const update of accumulatorUpdateData.updates) {
|
|
495
|
-
const feedId = (0, price_service_sdk_1.parsePriceFeedMessage)(update.message).feedId;
|
|
496
|
-
postInstructions.push({
|
|
497
|
-
instruction: await this.pushOracle.methods
|
|
498
|
-
.updatePriceFeed({
|
|
499
|
-
merklePriceUpdate: update,
|
|
500
|
-
treasuryId,
|
|
501
|
-
}, shardId, Array.from(feedId))
|
|
502
|
-
.accounts({
|
|
503
|
-
pythSolanaReceiver: this.receiver.programId,
|
|
504
|
-
encodedVaa,
|
|
505
|
-
priceFeedAccount: this.getPriceFeedAccountAddress(shardId, feedId),
|
|
506
|
-
treasury: (0, address_1.getTreasuryPda)(treasuryId, this.receiver.programId),
|
|
507
|
-
config: (0, address_1.getConfigPda)(this.receiver.programId),
|
|
508
|
-
})
|
|
509
|
-
.instruction(),
|
|
510
|
-
signers: [],
|
|
511
|
-
computeUnits: compute_budget_1.UPDATE_PRICE_FEED_COMPUTE_BUDGET,
|
|
512
|
-
});
|
|
513
|
-
priceFeedIdToPriceUpdateAccount["0x" + (0, price_service_sdk_1.parsePriceFeedMessage)(update.message).feedId.toString("hex")] = this.getPriceFeedAccountAddress(shardId, feedId);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return {
|
|
517
|
-
postInstructions,
|
|
518
|
-
priceFeedIdToPriceUpdateAccount,
|
|
519
|
-
closeInstructions,
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* 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.
|
|
524
|
-
*
|
|
525
|
-
* @param vaa a Wormhole VAA
|
|
526
|
-
* @returns `encodedVaaAddress`: the address of the encoded VAA account where the VAA will be posted
|
|
527
|
-
* @returns `postInstructions`: the instructions to post the VAA
|
|
528
|
-
* @returns `closeInstructions`: the instructions to close the encoded VAA account
|
|
529
|
-
*/
|
|
530
|
-
async buildPostEncodedVaaInstructions(vaa) {
|
|
531
|
-
return (0, vaa_1.buildPostEncodedVaaInstructions)(this.wormhole, vaa);
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Build an instruction to close an encoded VAA account, recovering the rent.
|
|
535
|
-
*/
|
|
536
|
-
async buildCloseEncodedVaaInstruction(encodedVaa) {
|
|
537
|
-
return (0, vaa_1.buildCloseEncodedVaaInstruction)(this.wormhole, encodedVaa);
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Build aset of instructions to close all the existing encoded VAA accounts owned by this PythSolanaReceiver's wallet
|
|
541
|
-
*/
|
|
542
|
-
async buildClosePreviousEncodedVaasInstructions(maxInstructions) {
|
|
543
|
-
const encodedVaas = await this.findOwnedEncodedVaaAccounts();
|
|
544
|
-
const instructions = [];
|
|
545
|
-
for (const encodedVaa of encodedVaas) {
|
|
546
|
-
instructions.push(await this.buildCloseEncodedVaaInstruction(encodedVaa));
|
|
547
|
-
}
|
|
548
|
-
return instructions.slice(0, maxInstructions);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Build an instruction to close a price update account, recovering the rent.
|
|
552
|
-
*/
|
|
553
|
-
async buildClosePriceUpdateInstruction(priceUpdateAccount) {
|
|
554
|
-
const instruction = await this.receiver.methods
|
|
555
|
-
.reclaimRent()
|
|
556
|
-
.accounts({ priceUpdateAccount })
|
|
557
|
-
.instruction();
|
|
558
|
-
return { instruction, signers: [] };
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Build an instruction to close a TWAP update account, recovering the rent.
|
|
562
|
-
*/
|
|
563
|
-
async buildCloseTwapUpdateInstruction(twapUpdateAccount) {
|
|
564
|
-
const instruction = await this.receiver.methods
|
|
565
|
-
.reclaimTwapRent()
|
|
566
|
-
.accounts({ twapUpdateAccount })
|
|
567
|
-
.instruction();
|
|
568
|
-
return { instruction, signers: [] };
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Returns a set of versioned transactions that contain the provided instructions in the same order and with efficient batching
|
|
572
|
-
*/
|
|
573
|
-
async batchIntoVersionedTransactions(instructions, priorityFeeConfig, addressLookupTable) {
|
|
574
|
-
return solana_utils_1.TransactionBuilder.batchIntoVersionedTransactions(this.wallet.publicKey, this.connection, instructions, priorityFeeConfig, addressLookupTable);
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Fetch the contents of a price update account
|
|
578
|
-
* @param priceUpdateAccount The address of the price update account
|
|
579
|
-
* @returns The contents of the deserialized price update account or `null` if the account doesn't exist
|
|
580
|
-
*/
|
|
581
|
-
async fetchPriceUpdateAccount(priceUpdateAccount) {
|
|
582
|
-
return this.receiver.account.priceUpdateV2.fetchNullable(priceUpdateAccount);
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Fetch the contents of a price feed account
|
|
586
|
-
* @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.
|
|
587
|
-
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
588
|
-
* @returns The contents of the deserialized price feed account or `null` if the account doesn't exist
|
|
589
|
-
*/
|
|
590
|
-
async fetchPriceFeedAccount(shardId, priceFeedId) {
|
|
591
|
-
return this.receiver.account.priceUpdateV2.fetchNullable(this.getPriceFeedAccountAddress(shardId, priceFeedId));
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Derive the address of a price feed account
|
|
595
|
-
* @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.
|
|
596
|
-
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
597
|
-
* @returns The address of the price feed account
|
|
598
|
-
*/
|
|
599
|
-
getPriceFeedAccountAddress(shardId, priceFeedId) {
|
|
600
|
-
return getPriceFeedAccountForProgram(shardId, priceFeedId, this.pushOracle.programId);
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Find all the encoded VAA accounts owned by this PythSolanaReceiver's wallet
|
|
604
|
-
* @returns a list of the public keys of the encoded VAA accounts
|
|
605
|
-
*/
|
|
606
|
-
async findOwnedEncodedVaaAccounts() {
|
|
607
|
-
return await (0, vaa_1.findEncodedVaaAccountsByWriteAuthority)(this.receiver.provider.connection, this.wallet.publicKey, this.wormhole.programId);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
exports.PythSolanaReceiver = PythSolanaReceiver;
|
|
611
|
-
/**
|
|
612
|
-
* Derive the address of a price feed account
|
|
613
|
-
* @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.
|
|
614
|
-
* @param priceFeedId The price feed ID, as either a 32-byte buffer or hexadecimal string with or without a leading "0x" prefix.
|
|
615
|
-
* @param pushOracleProgramId The program ID of the Pyth Push Oracle program. If not provided, the default deployment will be used.
|
|
616
|
-
* @returns The address of the price feed account
|
|
617
|
-
*/
|
|
618
|
-
function getPriceFeedAccountForProgram(shardId, priceFeedId, pushOracleProgramId) {
|
|
619
|
-
if (typeof priceFeedId == "string") {
|
|
620
|
-
if (priceFeedId.startsWith("0x")) {
|
|
621
|
-
priceFeedId = Buffer.from(priceFeedId.slice(2), "hex");
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
priceFeedId = Buffer.from(priceFeedId, "hex");
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (priceFeedId.length != 32) {
|
|
628
|
-
throw new Error("Feed ID should be 32 bytes long");
|
|
629
|
-
}
|
|
630
|
-
const shardBuffer = Buffer.alloc(2);
|
|
631
|
-
shardBuffer.writeUint16LE(shardId, 0);
|
|
632
|
-
return web3_js_1.PublicKey.findProgramAddressSync([shardBuffer, priceFeedId], pushOracleProgramId ?? address_1.DEFAULT_PUSH_ORACLE_PROGRAM_ID)[0];
|
|
633
|
-
}
|
package/lib/address.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|