@drift-labs/sdk-browser 2.155.0-beta.2 → 2.155.0-beta.4

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.
Files changed (71) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +0 -1
  3. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +0 -1
  4. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +0 -1
  5. package/lib/browser/accounts/laserProgramAccountSubscriber.d.ts +0 -1
  6. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +0 -1
  7. package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +0 -1
  8. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +0 -1
  9. package/lib/browser/driftClient.d.ts +1 -2
  10. package/lib/browser/driftClient.js +5 -6
  11. package/lib/browser/oracles/pythPullClient.d.ts +2 -2
  12. package/lib/browser/oracles/pythPullClient.js +5 -2
  13. package/lib/browser/pyth/constants.d.ts +3 -0
  14. package/lib/browser/pyth/constants.js +6 -0
  15. package/lib/browser/pyth/index.d.ts +3 -0
  16. package/lib/browser/pyth/index.js +10 -0
  17. package/lib/browser/pyth/types.d.ts +2226 -0
  18. package/lib/browser/pyth/types.js +2224 -0
  19. package/lib/browser/pyth/utils.d.ts +2 -0
  20. package/lib/browser/pyth/utils.js +10 -0
  21. package/lib/browser/swap/UnifiedSwapClient.js +1 -10
  22. package/lib/browser/titan/titanClient.d.ts +4 -5
  23. package/lib/browser/titan/titanClient.js +2 -16
  24. package/lib/node/accounts/grpcAccountSubscriber.d.ts +0 -1
  25. package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
  26. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +0 -1
  27. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  28. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +0 -1
  29. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
  30. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +0 -1
  31. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
  32. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +0 -1
  33. package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  34. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +0 -1
  35. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts.map +1 -1
  36. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +0 -1
  37. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
  38. package/lib/node/driftClient.d.ts +1 -2
  39. package/lib/node/driftClient.d.ts.map +1 -1
  40. package/lib/node/driftClient.js +5 -6
  41. package/lib/node/oracles/pythPullClient.d.ts +2 -2
  42. package/lib/node/oracles/pythPullClient.d.ts.map +1 -1
  43. package/lib/node/oracles/pythPullClient.js +5 -2
  44. package/lib/node/pyth/constants.d.ts +4 -0
  45. package/lib/node/pyth/constants.d.ts.map +1 -0
  46. package/lib/node/pyth/constants.js +6 -0
  47. package/lib/node/pyth/index.d.ts +4 -0
  48. package/lib/node/pyth/index.d.ts.map +1 -0
  49. package/lib/node/pyth/index.js +10 -0
  50. package/lib/node/pyth/types.d.ts +2227 -0
  51. package/lib/node/pyth/types.d.ts.map +1 -0
  52. package/lib/node/pyth/types.js +2224 -0
  53. package/lib/node/pyth/utils.d.ts +3 -0
  54. package/lib/node/pyth/utils.d.ts.map +1 -0
  55. package/lib/node/pyth/utils.js +10 -0
  56. package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
  57. package/lib/node/swap/UnifiedSwapClient.js +1 -10
  58. package/lib/node/titan/titanClient.d.ts +4 -5
  59. package/lib/node/titan/titanClient.d.ts.map +1 -1
  60. package/lib/node/titan/titanClient.js +2 -16
  61. package/package.json +3 -4
  62. package/src/driftClient.ts +9 -11
  63. package/src/oracles/pythPullClient.ts +4 -5
  64. package/src/pyth/constants.ts +9 -0
  65. package/src/pyth/index.ts +11 -0
  66. package/src/pyth/types.ts +4453 -0
  67. package/src/pyth/utils.ts +13 -0
  68. package/src/swap/UnifiedSwapClient.ts +2 -13
  69. package/src/titan/titanClient.ts +4 -28
  70. package/tests/decode/test.ts +2 -1
  71. package/tests/dlob/helpers.ts +0 -1
@@ -0,0 +1,13 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+
3
+ export const getGuardianSetPda = (
4
+ guardianSetIndex: number,
5
+ wormholeProgramId: PublicKey
6
+ ) => {
7
+ const guardianSetIndexBuf = Buffer.alloc(4);
8
+ guardianSetIndexBuf.writeUInt32BE(guardianSetIndex, 0);
9
+ return PublicKey.findProgramAddressSync(
10
+ [Buffer.from('GuardianSet'), guardianSetIndexBuf],
11
+ wormholeProgramId
12
+ )[0];
13
+ };
@@ -11,11 +11,7 @@ import {
11
11
  JupiterClient,
12
12
  QuoteResponse as JupiterQuoteResponse,
13
13
  } from '../jupiter/jupiterClient';
14
- import {
15
- TitanClient,
16
- QuoteResponse as TitanQuoteResponse,
17
- SwapMode as TitanSwapMode,
18
- } from '../titan/titanClient';
14
+ import { TitanClient, SwapMode as TitanSwapMode } from '../titan/titanClient';
19
15
 
20
16
  export type SwapMode = 'ExactIn' | 'ExactOut';
21
17
  export type SwapClientType = 'jupiter' | 'titan';
@@ -167,18 +163,11 @@ export class UnifiedSwapClient {
167
163
  return { transaction };
168
164
  } else {
169
165
  const titanClient = this.client as TitanClient;
170
- const { quote, userPublicKey, slippageBps } = params;
166
+ const { userPublicKey } = params;
171
167
 
172
168
  // For Titan, we need to reconstruct the parameters from the quote
173
- const titanQuote = quote as TitanQuoteResponse;
174
169
  const result = await titanClient.getSwap({
175
- inputMint: new PublicKey(titanQuote.inputMint),
176
- outputMint: new PublicKey(titanQuote.outputMint),
177
- amount: new BN(titanQuote.inAmount),
178
170
  userPublicKey,
179
- slippageBps: slippageBps || titanQuote.slippageBps,
180
- swapMode: titanQuote.swapMode,
181
- sizeConstraint: 1280 - 375, // MAX_TX_BYTE_SIZE - buffer for drift instructions
182
171
  });
183
172
 
184
173
  return {
@@ -287,21 +287,11 @@ export class TitanClient {
287
287
  * Get a swap transaction for quote
288
288
  */
289
289
  public async getSwap({
290
- inputMint,
291
- outputMint,
292
- amount,
293
290
  userPublicKey,
294
- maxAccounts = 50, // 50 is an estimated amount with buffer
295
- slippageBps,
296
- swapMode,
297
- onlyDirectRoutes,
298
- excludeDexes,
299
- sizeConstraint,
300
- accountsLimitWritable,
301
291
  }: {
302
- inputMint: PublicKey;
303
- outputMint: PublicKey;
304
- amount: BN;
292
+ inputMint?: PublicKey;
293
+ outputMint?: PublicKey;
294
+ amount?: BN;
305
295
  userPublicKey: PublicKey;
306
296
  maxAccounts?: number;
307
297
  slippageBps?: number;
@@ -314,22 +304,8 @@ export class TitanClient {
314
304
  transactionMessage: TransactionMessage;
315
305
  lookupTables: AddressLookupTableAccount[];
316
306
  }> {
317
- const params = this.buildParams({
318
- inputMint,
319
- outputMint,
320
- amount,
321
- userPublicKey,
322
- maxAccounts,
323
- slippageBps,
324
- swapMode,
325
- onlyDirectRoutes,
326
- excludeDexes,
327
- sizeConstraint,
328
- accountsLimitWritable,
329
- });
330
-
331
307
  // Check if we have cached quote data that matches the current parameters
332
- if (!this.lastQuoteData || this.lastQuoteParams !== params.toString()) {
308
+ if (!this.lastQuoteData) {
333
309
  throw new Error(
334
310
  'No matching quote data found. Please get a fresh quote before attempting to swap.'
335
311
  );
@@ -187,10 +187,11 @@ function testPerpPosition(anchor: PerpPosition, custom: PerpPosition) {
187
187
  assert(anchor.openAsks.eq(custom.openAsks));
188
188
  assert(anchor.settledPnl.eq(custom.settledPnl));
189
189
  assert(anchor.lpShares.eq(custom.lpShares));
190
- assert(anchor.lastBaseAssetAmountPerLp.eq(custom.lastBaseAssetAmountPerLp));
191
190
  assert(anchor.lastQuoteAssetAmountPerLp.eq(custom.lastQuoteAssetAmountPerLp));
192
191
  assert(anchor.openOrders === custom.openOrders);
193
192
  assert(anchor.perLpBase === custom.perLpBase);
193
+ assert(anchor.isolatedPositionScaledBalance.eq(custom.isolatedPositionScaledBalance));
194
+ assert(anchor.positionFlag === custom.positionFlag);
194
195
  }
195
196
 
196
197
  function* getOrders(orders: Order[]) {
@@ -41,7 +41,6 @@ export const mockPerpPosition: PerpPosition = {
41
41
  settledPnl: new BN(0),
42
42
  lpShares: new BN(0),
43
43
  remainderBaseAssetAmount: 0,
44
- lastBaseAssetAmountPerLp: new BN(0),
45
44
  lastQuoteAssetAmountPerLp: new BN(0),
46
45
  perLpBase: 0,
47
46
  maxMarginRatio: 1,