@drift-labs/sdk 2.85.0-beta.11 → 2.85.0-beta.12

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.
@@ -14,6 +14,7 @@ exports.DevnetSpotMarkets = [
14
14
  mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
15
15
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
16
16
  precisionExp: numericConstants_1.SIX,
17
+ pythFeedId: '0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
17
18
  },
18
19
  {
19
20
  symbol: 'SOL',
@@ -25,6 +26,7 @@ exports.DevnetSpotMarkets = [
25
26
  precisionExp: numericConstants_1.LAMPORTS_EXP,
26
27
  serumMarket: new web3_js_1.PublicKey('8N37SsnTu8RYxtjrV9SStjkkwVhmU8aCWhLvwduAPEKW'),
27
28
  phoenixMarket: new web3_js_1.PublicKey('78ehDnHgbkFxqXZwdFxa8HK7saX58GymeX2wNGdkqYLp'),
29
+ pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
28
30
  },
29
31
  {
30
32
  symbol: 'BTC',
@@ -35,6 +37,7 @@ exports.DevnetSpotMarkets = [
35
37
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
36
38
  precisionExp: numericConstants_1.SIX,
37
39
  serumMarket: new web3_js_1.PublicKey('AGsmbVu3MS9u68GEYABWosQQCZwmLcBHu4pWEuBYH7Za'),
40
+ pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
38
41
  },
39
42
  ];
40
43
  exports.MainnetSpotMarkets = [
@@ -46,6 +49,7 @@ exports.MainnetSpotMarkets = [
46
49
  mint: new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
47
50
  precision: numericConstants_1.QUOTE_PRECISION,
48
51
  precisionExp: numericConstants_1.QUOTE_PRECISION_EXP,
52
+ pythFeedId: '0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
49
53
  },
50
54
  {
51
55
  symbol: 'SOL',
@@ -57,6 +61,7 @@ exports.MainnetSpotMarkets = [
57
61
  precisionExp: numericConstants_1.LAMPORTS_EXP,
58
62
  serumMarket: new web3_js_1.PublicKey('8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'),
59
63
  phoenixMarket: new web3_js_1.PublicKey('4DoNfFBfF7UokCC2FQzriy7yHK6DY6NVdYpuekQ5pRgg'),
64
+ pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
60
65
  },
61
66
  {
62
67
  symbol: 'mSOL',
@@ -67,6 +72,7 @@ exports.MainnetSpotMarkets = [
67
72
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
68
73
  precisionExp: numericConstants_1.NINE,
69
74
  serumMarket: new web3_js_1.PublicKey('9Lyhks5bQQxb9EyyX55NtgKQzpM4WK7JCmeaWuQ5MoXD'),
75
+ pythFeedId: '0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4',
70
76
  },
71
77
  {
72
78
  symbol: 'wBTC',
@@ -77,6 +83,7 @@ exports.MainnetSpotMarkets = [
77
83
  precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
78
84
  precisionExp: numericConstants_1.EIGHT,
79
85
  serumMarket: new web3_js_1.PublicKey('3BAKsQd3RuhZKES2DGysMhjBdwjZYKYmxRqnSMtZ4KSN'),
86
+ pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
80
87
  },
81
88
  {
82
89
  symbol: 'wETH',
@@ -88,6 +95,7 @@ exports.MainnetSpotMarkets = [
88
95
  precisionExp: numericConstants_1.EIGHT,
89
96
  serumMarket: new web3_js_1.PublicKey('BbJgE7HZMaDp5NTYvRh5jZSkQPVDTU8ubPFtpogUkEj4'),
90
97
  phoenixMarket: new web3_js_1.PublicKey('Ew3vFDdtdGrknJAVVfraxCA37uNJtimXYPY4QjnfhFHH'),
98
+ pythFeedId: '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
91
99
  },
92
100
  {
93
101
  symbol: 'USDT',
@@ -98,6 +106,7 @@ exports.MainnetSpotMarkets = [
98
106
  precision: numericConstants_1.QUOTE_PRECISION,
99
107
  precisionExp: numericConstants_1.QUOTE_PRECISION_EXP,
100
108
  serumMarket: new web3_js_1.PublicKey('B2na8Awyd7cpC59iEU43FagJAPLigr3AP3s38KM982bu'),
109
+ pythFeedId: '0x2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
101
110
  },
102
111
  {
103
112
  symbol: 'jitoSOL',
@@ -109,6 +118,7 @@ exports.MainnetSpotMarkets = [
109
118
  precisionExp: numericConstants_1.NINE,
110
119
  serumMarket: new web3_js_1.PublicKey('DkbVbMhFxswS32xnn1K2UY4aoBugXooBTxdzkWWDWRkH'),
111
120
  phoenixMarket: new web3_js_1.PublicKey('5LQLfGtqcC5rm2WuGxJf4tjqYmDjsQAbKo2AMLQ8KB7p'),
121
+ pythFeedId: '0x67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb',
112
122
  },
113
123
  {
114
124
  symbol: 'PYTH',
@@ -120,6 +130,7 @@ exports.MainnetSpotMarkets = [
120
130
  precisionExp: numericConstants_1.SIX,
121
131
  serumMarket: new web3_js_1.PublicKey('4E17F3BxtNVqzVsirxguuqkpYLtFgCR6NfTpccPh82WE'),
122
132
  phoenixMarket: new web3_js_1.PublicKey('2sTMN9A1D1qeZLF95XQgJCUPiKe5DiV52jLfZGqMP46m'),
133
+ pythFeedId: '0x0bbf28e9a841a1cc788f6a361b17ca072d0ea3098a1e5df1c3922d06719579ff',
123
134
  },
124
135
  {
125
136
  symbol: 'bSOL',
@@ -130,6 +141,7 @@ exports.MainnetSpotMarkets = [
130
141
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
131
142
  precisionExp: numericConstants_1.NINE,
132
143
  serumMarket: new web3_js_1.PublicKey('ARjaHVxGCQfTvvKjLd7U7srvk6orthZSE6uqWchCczZc'),
144
+ pythFeedId: '0x89875379e70f8fbadc17aef315adf3a8d5d160b811435537e03c97e8aac97d9c',
133
145
  },
134
146
  {
135
147
  symbol: 'JTO',
@@ -141,6 +153,7 @@ exports.MainnetSpotMarkets = [
141
153
  precisionExp: numericConstants_1.NINE,
142
154
  serumMarket: new web3_js_1.PublicKey('H87FfmHABiZLRGrDsXRZtqq25YpARzaokCzL1vMYGiep'),
143
155
  phoenixMarket: new web3_js_1.PublicKey('BRLLmdtPGuuFn3BU6orYw4KHaohAEptBToi3dwRUnHQZ'),
156
+ pythFeedId: '0xb43660a5f790c69354b0729a5ef9d50d68f1df92107540210b9cccba1f947cc2',
144
157
  },
145
158
  {
146
159
  symbol: 'WIF',
@@ -152,6 +165,7 @@ exports.MainnetSpotMarkets = [
152
165
  precisionExp: numericConstants_1.SIX,
153
166
  serumMarket: new web3_js_1.PublicKey('2BtDHBTCTUxvdur498ZEcMgimasaFrY5GzLv8wS8XgCb'),
154
167
  phoenixMarket: new web3_js_1.PublicKey('6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX'),
168
+ pythFeedId: '0x4ca4beeca86f0d164160323817a4e42b10010a724c2217c6ee41b54cd4cc61fc',
155
169
  },
156
170
  {
157
171
  symbol: 'JUP',
@@ -163,6 +177,7 @@ exports.MainnetSpotMarkets = [
163
177
  precisionExp: numericConstants_1.SIX,
164
178
  phoenixMarket: new web3_js_1.PublicKey('2pspvjWWaf3dNgt3jsgSzFCNvMGPb7t8FrEYvLGjvcCe'),
165
179
  launchTs: 1706731200000,
180
+ pythFeedId: '0x0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996',
166
181
  },
167
182
  {
168
183
  symbol: 'RNDR',
@@ -174,6 +189,7 @@ exports.MainnetSpotMarkets = [
174
189
  precisionExp: numericConstants_1.EIGHT,
175
190
  serumMarket: new web3_js_1.PublicKey('2m7ZLEKtxWF29727DSb5D91erpXPUY1bqhRWRC3wQX7u'),
176
191
  launchTs: 1708964021000,
192
+ pythFeedId: '0xab7347771135fc733f8f38db462ba085ed3309955f42554a14fa13e855ac0e2f',
177
193
  },
178
194
  {
179
195
  symbol: 'W',
@@ -185,6 +201,7 @@ exports.MainnetSpotMarkets = [
185
201
  precisionExp: numericConstants_1.SIX,
186
202
  phoenixMarket: new web3_js_1.PublicKey('8dFTCTAbtGuHsdDL8WEPrTU6pXFDrU1QSjBTutw8fwZk'),
187
203
  launchTs: 1712149014000,
204
+ pythFeedId: '0xeff7446475e218517566ea99e72a4abec2e1bd8498b43b7d8331e29dcb059389',
188
205
  },
189
206
  {
190
207
  symbol: 'TNSR',
@@ -196,6 +213,7 @@ exports.MainnetSpotMarkets = [
196
213
  precisionExp: numericConstants_1.NINE,
197
214
  phoenixMarket: new web3_js_1.PublicKey('AbJCZ9TAJiby5AY3cHcXS2gUdENC6mtsm6m7XpC2ZMvE'),
198
215
  launchTs: 1712593532000,
216
+ pythFeedId: '0x05ecd4597cd48fe13d6cc3596c62af4f9675aee06e2e0b94c06d8bee2b659e05',
199
217
  },
200
218
  {
201
219
  symbol: 'DRIFT',
@@ -207,6 +225,7 @@ exports.MainnetSpotMarkets = [
207
225
  precisionExp: numericConstants_1.SIX,
208
226
  phoenixMarket: new web3_js_1.PublicKey('8BV6rrWsUabnTDA3dE6A69oUDJAj3hMhtBHTJyXB7czp'),
209
227
  launchTs: 1715860800000,
228
+ pythFeedId: '0x5c1690b27bb02446db17cdda13ccc2c1d609ad6d2ef5bf4983a85ea8b6f19d07',
210
229
  },
211
230
  {
212
231
  symbol: 'INF',
@@ -217,6 +236,7 @@ exports.MainnetSpotMarkets = [
217
236
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
218
237
  precisionExp: numericConstants_1.NINE,
219
238
  launchTs: 1716595200000,
239
+ pythFeedId: '0xf51570985c642c49c2d6e50156390fdba80bb6d5f7fa389d2f012ced4f7d208f',
220
240
  },
221
241
  {
222
242
  symbol: 'dSOL',
@@ -1,9 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
+ /// <reference types="node" />
3
4
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
4
5
  import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord } from './types';
5
6
  import * as anchor from '@coral-xyz/anchor';
6
- import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
7
+ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Keypair, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
7
8
  import { TokenFaucet } from './tokenFaucet';
8
9
  import { EventEmitter } from 'events';
9
10
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -18,6 +19,8 @@ import { UserStats } from './userStats';
18
19
  import { JupiterClient, QuoteResponse, Route, SwapMode } from './jupiter/jupiterClient';
19
20
  import { UserStatsSubscriptionConfig } from './userStatsConfig';
20
21
  import { TxHandler } from './tx/txHandler';
22
+ import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
23
+ import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
21
24
  type RemainingAccountParams = {
22
25
  userAccounts: UserAccount[];
23
26
  writablePerpMarketIndexes?: number[];
@@ -60,6 +63,8 @@ export declare class DriftClient {
60
63
  txParams: TxParams;
61
64
  enableMetricsEvents?: boolean;
62
65
  txHandler: TxHandler;
66
+ receiverProgram?: Program<PythSolanaReceiver>;
67
+ wormholeProgram?: Program<WormholeCoreBridgeSolana>;
63
68
  get isSubscribed(): boolean;
64
69
  set isSubscribed(val: boolean);
65
70
  constructor(config: DriftClientConfig);
@@ -705,6 +710,24 @@ export declare class DriftClient {
705
710
  marketIndex: number;
706
711
  marketType: MarketType;
707
712
  } | undefined;
713
+ getReceiverProgram(): Program<PythSolanaReceiver>;
714
+ postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
715
+ getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedId: string, numSignatures?: number): Promise<TransactionInstruction[]>;
716
+ getSinglePostPythPullOracleAtomicIx(params: {
717
+ vaa: Buffer;
718
+ merklePriceUpdate: {
719
+ message: Buffer;
720
+ proof: number[][];
721
+ };
722
+ }, feedId: string, guardianSet: PublicKey): Promise<TransactionInstruction>;
723
+ updatePythPullOracle(vaaString: string, feedId: string): Promise<TransactionSignature>;
724
+ getUpdatePythPullOracleIxs(params: {
725
+ merklePriceUpdate: {
726
+ message: Buffer;
727
+ proof: number[][];
728
+ };
729
+ }, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
730
+ getBuildEncodedVaaIxs(vaa: Buffer, guardianSet: PublicKey): Promise<[TransactionInstruction[], Keypair]>;
708
731
  private handleSignedTransaction;
709
732
  private handlePreSignedTransaction;
710
733
  private isVersionedTransaction;
@@ -58,6 +58,11 @@ const utils_1 = require("./math/utils");
58
58
  const txParamProcessor_1 = require("./tx/txParamProcessor");
59
59
  const oracles_1 = require("./math/oracles");
60
60
  const txHandler_1 = require("./tx/txHandler");
61
+ const pyth_solana_receiver_1 = require("@pythnetwork/pyth-solana-receiver");
62
+ const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
63
+ const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
64
+ const config_2 = require("./config");
65
+ const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
61
66
  const utils_2 = require("./tx/utils");
62
67
  /**
63
68
  * # DriftClient
@@ -3634,6 +3639,117 @@ class DriftClient {
3634
3639
  }
3635
3640
  return undefined;
3636
3641
  }
3642
+ getReceiverProgram() {
3643
+ if (this.receiverProgram === undefined) {
3644
+ this.receiverProgram = new anchor_1.Program(pyth_solana_receiver_1.pythSolanaReceiverIdl, pyth_solana_receiver_1.DEFAULT_RECEIVER_PROGRAM_ID, this.provider);
3645
+ }
3646
+ return this.receiverProgram;
3647
+ }
3648
+ async postPythPullOracleUpdateAtomic(vaaString, feedId) {
3649
+ const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(vaaString, feedId);
3650
+ const tx = await this.buildTransaction(postIxs);
3651
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3652
+ return txSig;
3653
+ }
3654
+ async getPostPythPullOracleUpdateAtomicIxs(vaaString, feedId, numSignatures = 2) {
3655
+ feedId = (0, pythPullOracleUtils_1.trimFeedId)(feedId);
3656
+ const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(vaaString, 'base64'));
3657
+ const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
3658
+ const guardianSet = (0, address_1.getGuardianSetPda)(guardianSetIndex, address_1.DEFAULT_WORMHOLE_PROGRAM_ID);
3659
+ const trimmedVaa = (0, oracles_1.trimVaaSignatures)(accumulatorUpdateData.vaa, numSignatures);
3660
+ const postIxs = [];
3661
+ for (const update of accumulatorUpdateData.updates) {
3662
+ postIxs.push(await this.getSinglePostPythPullOracleAtomicIx({
3663
+ vaa: trimmedVaa,
3664
+ merklePriceUpdate: update,
3665
+ }, feedId, guardianSet));
3666
+ }
3667
+ return postIxs;
3668
+ }
3669
+ async getSinglePostPythPullOracleAtomicIx(params, feedId, guardianSet) {
3670
+ const feedIdBuffer = (0, pythPullOracleUtils_1.getFeedIdUint8Array)(feedId);
3671
+ const receiverProgram = this.getReceiverProgram();
3672
+ const encodedParams = receiverProgram.coder.types.encode('PostUpdateAtomicParams', params);
3673
+ return this.program.instruction.postPythPullOracleUpdateAtomic(feedIdBuffer, encodedParams, {
3674
+ accounts: {
3675
+ keeper: this.wallet.publicKey,
3676
+ pythSolanaReceiver: config_2.DRIFT_ORACLE_RECEIVER_ID,
3677
+ guardianSet,
3678
+ priceFeed: (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, feedIdBuffer),
3679
+ },
3680
+ });
3681
+ }
3682
+ async updatePythPullOracle(vaaString, feedId) {
3683
+ feedId = (0, pythPullOracleUtils_1.trimFeedId)(feedId);
3684
+ const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(vaaString, 'base64'));
3685
+ const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
3686
+ const guardianSet = (0, address_1.getGuardianSetPda)(guardianSetIndex, address_1.DEFAULT_WORMHOLE_PROGRAM_ID);
3687
+ const [postIxs, encodedVaaAddress] = await this.getBuildEncodedVaaIxs(accumulatorUpdateData.vaa, guardianSet);
3688
+ for (const update of accumulatorUpdateData.updates) {
3689
+ postIxs.push(await this.getUpdatePythPullOracleIxs({
3690
+ merklePriceUpdate: update,
3691
+ }, feedId, encodedVaaAddress.publicKey));
3692
+ }
3693
+ const tx = await this.buildTransaction(postIxs);
3694
+ const { txSig } = await this.sendTransaction(tx, [encodedVaaAddress], this.opts);
3695
+ return txSig;
3696
+ }
3697
+ async getUpdatePythPullOracleIxs(params, feedId, encodedVaaAddress) {
3698
+ const feedIdBuffer = (0, pythPullOracleUtils_1.getFeedIdUint8Array)(feedId);
3699
+ const receiverProgram = this.getReceiverProgram();
3700
+ const encodedParams = receiverProgram.coder.types.encode('PostUpdateParams', params);
3701
+ return this.program.instruction.updatePythPullOracle(feedIdBuffer, encodedParams, {
3702
+ accounts: {
3703
+ keeper: this.wallet.publicKey,
3704
+ pythSolanaReceiver: config_2.DRIFT_ORACLE_RECEIVER_ID,
3705
+ encodedVaa: encodedVaaAddress,
3706
+ priceFeed: (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, feedIdBuffer),
3707
+ },
3708
+ });
3709
+ }
3710
+ async getBuildEncodedVaaIxs(vaa, guardianSet) {
3711
+ const postIxs = [];
3712
+ if (this.wormholeProgram === undefined) {
3713
+ this.wormholeProgram = new anchor_1.Program(pyth_solana_receiver_1.wormholeCoreBridgeIdl, address_1.DEFAULT_WORMHOLE_PROGRAM_ID, this.provider);
3714
+ }
3715
+ const encodedVaaKeypair = new web3_js_1.Keypair();
3716
+ postIxs.push(await this.wormholeProgram.account.encodedVaa.createInstruction(encodedVaaKeypair, vaa.length + 46));
3717
+ // Why do we need this too?
3718
+ postIxs.push(await this.wormholeProgram.methods
3719
+ .initEncodedVaa()
3720
+ .accounts({
3721
+ encodedVaa: encodedVaaKeypair.publicKey,
3722
+ })
3723
+ .instruction());
3724
+ // Split the write into two ixs
3725
+ postIxs.push(await this.wormholeProgram.methods
3726
+ .writeEncodedVaa({
3727
+ index: 0,
3728
+ data: vaa.subarray(0, 755),
3729
+ })
3730
+ .accounts({
3731
+ draftVaa: encodedVaaKeypair.publicKey,
3732
+ })
3733
+ .instruction());
3734
+ postIxs.push(await this.wormholeProgram.methods
3735
+ .writeEncodedVaa({
3736
+ index: 755,
3737
+ data: vaa.subarray(755),
3738
+ })
3739
+ .accounts({
3740
+ draftVaa: encodedVaaKeypair.publicKey,
3741
+ })
3742
+ .instruction());
3743
+ // Verify
3744
+ postIxs.push(await this.wormholeProgram.methods
3745
+ .verifyEncodedVaaV1()
3746
+ .accounts({
3747
+ guardianSet,
3748
+ draftVaa: encodedVaaKeypair.publicKey,
3749
+ })
3750
+ .instruction());
3751
+ return [postIxs, encodedVaaKeypair];
3752
+ }
3637
3753
  handleSignedTransaction(signedTxs) {
3638
3754
  if (this.enableMetricsEvents && this.metricsEventEmitter) {
3639
3755
  this.metricsEventEmitter.emit('txSigned', signedTxs);
@@ -2547,6 +2547,86 @@
2547
2547
  }
2548
2548
  ]
2549
2549
  },
2550
+ {
2551
+ "name": "updatePythPullOracle",
2552
+ "accounts": [
2553
+ {
2554
+ "name": "keeper",
2555
+ "isMut": true,
2556
+ "isSigner": true
2557
+ },
2558
+ {
2559
+ "name": "pythSolanaReceiver",
2560
+ "isMut": false,
2561
+ "isSigner": false
2562
+ },
2563
+ {
2564
+ "name": "encodedVaa",
2565
+ "isMut": false,
2566
+ "isSigner": false
2567
+ },
2568
+ {
2569
+ "name": "priceFeed",
2570
+ "isMut": true,
2571
+ "isSigner": false
2572
+ }
2573
+ ],
2574
+ "args": [
2575
+ {
2576
+ "name": "feedId",
2577
+ "type": {
2578
+ "array": [
2579
+ "u8",
2580
+ 32
2581
+ ]
2582
+ }
2583
+ },
2584
+ {
2585
+ "name": "params",
2586
+ "type": "bytes"
2587
+ }
2588
+ ]
2589
+ },
2590
+ {
2591
+ "name": "postPythPullOracleUpdateAtomic",
2592
+ "accounts": [
2593
+ {
2594
+ "name": "keeper",
2595
+ "isMut": true,
2596
+ "isSigner": true
2597
+ },
2598
+ {
2599
+ "name": "pythSolanaReceiver",
2600
+ "isMut": false,
2601
+ "isSigner": false
2602
+ },
2603
+ {
2604
+ "name": "guardianSet",
2605
+ "isMut": false,
2606
+ "isSigner": false
2607
+ },
2608
+ {
2609
+ "name": "priceFeed",
2610
+ "isMut": true,
2611
+ "isSigner": false
2612
+ }
2613
+ ],
2614
+ "args": [
2615
+ {
2616
+ "name": "feedId",
2617
+ "type": {
2618
+ "array": [
2619
+ "u8",
2620
+ 32
2621
+ ]
2622
+ }
2623
+ },
2624
+ {
2625
+ "name": "params",
2626
+ "type": "bytes"
2627
+ }
2628
+ ]
2629
+ },
2550
2630
  {
2551
2631
  "name": "initialize",
2552
2632
  "accounts": [
@@ -5296,6 +5376,47 @@
5296
5376
  "type": "u16"
5297
5377
  }
5298
5378
  ]
5379
+ },
5380
+ {
5381
+ "name": "initializePythPullOracle",
5382
+ "accounts": [
5383
+ {
5384
+ "name": "admin",
5385
+ "isMut": true,
5386
+ "isSigner": true
5387
+ },
5388
+ {
5389
+ "name": "pythSolanaReceiver",
5390
+ "isMut": false,
5391
+ "isSigner": false
5392
+ },
5393
+ {
5394
+ "name": "priceFeed",
5395
+ "isMut": true,
5396
+ "isSigner": false
5397
+ },
5398
+ {
5399
+ "name": "systemProgram",
5400
+ "isMut": false,
5401
+ "isSigner": false
5402
+ },
5403
+ {
5404
+ "name": "state",
5405
+ "isMut": false,
5406
+ "isSigner": false
5407
+ }
5408
+ ],
5409
+ "args": [
5410
+ {
5411
+ "name": "feedId",
5412
+ "type": {
5413
+ "array": [
5414
+ "u8",
5415
+ 32
5416
+ ]
5417
+ }
5418
+ }
5419
+ ]
5299
5420
  }
5300
5421
  ],
5301
5422
  "accounts": [
@@ -12029,6 +12150,44 @@
12029
12150
  "code": 6268,
12030
12151
  "name": "MaxBorrows",
12031
12152
  "msg": "Can not borow more than max borrows"
12153
+ },
12154
+ {
12155
+ "code": 6269,
12156
+ "name": "OracleUpdatesNotMonotonic",
12157
+ "msg": "Updates must be monotonically increasing"
12158
+ },
12159
+ {
12160
+ "code": 6270,
12161
+ "name": "OraclePriceFeedMessageMismatch",
12162
+ "msg": "Trying to update price feed with the wrong feed id"
12163
+ },
12164
+ {
12165
+ "code": 6271,
12166
+ "name": "OracleUnsupportedMessageType",
12167
+ "msg": "The message in the update must be a PriceFeedMessage"
12168
+ },
12169
+ {
12170
+ "code": 6272,
12171
+ "name": "OracleDeserializeMessageFailed",
12172
+ "msg": "Could not deserialize the message in the update"
12173
+ },
12174
+ {
12175
+ "code": 6273,
12176
+ "name": "OracleWrongGuardianSetOwner",
12177
+ "msg": "Wrong guardian set owner in update price atomic"
12178
+ },
12179
+ {
12180
+ "code": 6274,
12181
+ "name": "OracleWrongWriteAuthority",
12182
+ "msg": "Oracle post update atomic price feed account must be drift program"
12183
+ },
12184
+ {
12185
+ "code": 6275,
12186
+ "name": "OracleWrongVaaOwner",
12187
+ "msg": "Oracle vaa owner must be wormhole program"
12032
12188
  }
12033
- ]
12189
+ ],
12190
+ "metadata": {
12191
+ "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
12192
+ }
12034
12193
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="bn.js" />
2
+ /// <reference types="node" />
2
3
  import { AMM, OracleGuardRails } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
4
5
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -9,3 +10,4 @@ export declare function isOracleTooDivergent(amm: AMM, oraclePriceData: OraclePr
9
10
  export declare function calculateLiveOracleTwap(histOracleData: HistoricalOracleData, oraclePriceData: OraclePriceData, now: BN, period: BN): BN;
10
11
  export declare function calculateLiveOracleStd(amm: AMM, oraclePriceData: OraclePriceData, now: BN): BN;
11
12
  export declare function getNewOracleConfPct(amm: AMM, oraclePriceData: OraclePriceData, reservePrice: BN, now: BN): BN;
13
+ export declare function trimVaaSignatures(vaa: Buffer, n?: number): Buffer;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNewOracleConfPct = exports.calculateLiveOracleStd = exports.calculateLiveOracleTwap = exports.isOracleTooDivergent = exports.isOracleValid = exports.getMaxConfidenceIntervalMultiplier = exports.oraclePriceBands = void 0;
3
+ exports.trimVaaSignatures = exports.getNewOracleConfPct = exports.calculateLiveOracleStd = exports.calculateLiveOracleTwap = exports.isOracleTooDivergent = exports.isOracleValid = exports.getMaxConfidenceIntervalMultiplier = exports.oraclePriceBands = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const index_1 = require("../index");
@@ -119,3 +119,16 @@ function getNewOracleConfPct(amm, oraclePriceData, reservePrice, now) {
119
119
  return confIntervalPctResult;
120
120
  }
121
121
  exports.getNewOracleConfPct = getNewOracleConfPct;
122
+ function trimVaaSignatures(vaa, n = 3) {
123
+ const currentNumSignatures = vaa[5];
124
+ if (n > currentNumSignatures) {
125
+ throw new Error("Resulting VAA can't have more signatures than the original VAA");
126
+ }
127
+ const trimmedVaa = Buffer.concat([
128
+ vaa.subarray(0, 6 + n * 66),
129
+ vaa.subarray(6 + currentNumSignatures * 66),
130
+ ]);
131
+ trimmedVaa[5] = n;
132
+ return trimmedVaa;
133
+ }
134
+ exports.trimVaaSignatures = trimVaaSignatures;
@@ -16,7 +16,7 @@ class PythPullClient {
16
16
  new __1.Wallet(new web3_js_1.Keypair()), {
17
17
  commitment: connection.commitment,
18
18
  });
19
- this.receiver = new anchor_1.Program(pyth_solana_receiver_1.pythSolanaReceiverIdl, pyth_solana_receiver_1.DEFAULT_RECEIVER_PROGRAM_ID, provider);
19
+ this.receiver = new anchor_1.Program(pyth_solana_receiver_1.pythSolanaReceiverIdl, __1.DRIFT_ORACLE_RECEIVER_ID, provider);
20
20
  this.decodeFunc =
21
21
  this.receiver.account.priceUpdateV2.coder.accounts.decodeUnchecked.bind(this.receiver.account.priceUpdateV2.coder.accounts);
22
22
  }
@@ -238,6 +238,7 @@ class BaseTxSender {
238
238
  const logs = transactionResult.meta.logMessages;
239
239
  const lastLog = logs[logs.length - 1];
240
240
  const friendlyMessage = (_b = lastLog === null || lastLog === void 0 ? void 0 : lastLog.match(/(failed:) (.+)/)) === null || _b === void 0 ? void 0 : _b[2];
241
+ // @ts-ignore
241
242
  throw new web3_js_1.SendTransactionError({
242
243
  action: 'send',
243
244
  signature: txSig,
@@ -0,0 +1,2 @@
1
+ export declare function trimFeedId(feedId: string): string;
2
+ export declare function getFeedIdUint8Array(feedId: string): Uint8Array;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
4
+ function trimFeedId(feedId) {
5
+ if (feedId.startsWith('0x')) {
6
+ return feedId.slice(2);
7
+ }
8
+ return feedId;
9
+ }
10
+ exports.trimFeedId = trimFeedId;
11
+ function getFeedIdUint8Array(feedId) {
12
+ const trimmedFeedId = trimFeedId(feedId);
13
+ return Uint8Array.from(Buffer.from(trimmedFeedId, 'hex'));
14
+ }
15
+ exports.getFeedIdUint8Array = getFeedIdUint8Array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.85.0-beta.11",
3
+ "version": "2.85.0-beta.12",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -38,6 +38,7 @@
38
38
  "@ellipsis-labs/phoenix-sdk": "^1.4.2",
39
39
  "@project-serum/serum": "^0.13.38",
40
40
  "@pythnetwork/client": "2.5.3",
41
+ "@pythnetwork/price-service-sdk": "^1.7.1",
41
42
  "@pythnetwork/pyth-solana-receiver": "^0.7.0",
42
43
  "@solana/spl-token": "0.3.7",
43
44
  "@solana/web3.js": "1.92.3",
@@ -236,3 +236,16 @@ export function getPrelaunchOraclePublicKey(
236
236
  programId
237
237
  )[0];
238
238
  }
239
+
240
+ export function getPythPullOraclePublicKey(
241
+ progarmId: PublicKey,
242
+ feedId: Uint8Array
243
+ ): PublicKey {
244
+ return PublicKey.findProgramAddressSync(
245
+ [
246
+ Buffer.from(anchor.utils.bytes.utf8.encode('pyth_pull')),
247
+ Buffer.from(feedId),
248
+ ],
249
+ progarmId
250
+ )[0];
251
+ }