@drift-labs/sdk 2.32.1-beta.8 → 2.33.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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.32.1-beta.8
1
+ 2.32.1-beta.13
@@ -111,7 +111,7 @@ exports.DevnetPerpMarkets = [
111
111
  baseAssetSymbol: '1MPEPE',
112
112
  marketIndex: 10,
113
113
  oracle: new web3_js_1.PublicKey('Gz9RfgDeAFSsH7BHDGyNTgCik74rjNwsodJpsCizzmkj'),
114
- launchTs: 1683125906000,
114
+ launchTs: 1683781239000,
115
115
  oracleSource: __1.OracleSource.PYTH_1M,
116
116
  },
117
117
  {
@@ -121,7 +121,7 @@ exports.DevnetPerpMarkets = [
121
121
  baseAssetSymbol: 'OP',
122
122
  marketIndex: 11,
123
123
  oracle: new web3_js_1.PublicKey('8ctSiDhA7eJoii4TkKV8Rx4KFdz3ycsA1FXy9wq56quG'),
124
- launchTs: 1683125906000,
124
+ launchTs: 1686091480000,
125
125
  oracleSource: __1.OracleSource.PYTH,
126
126
  },
127
127
  {
@@ -131,7 +131,7 @@ exports.DevnetPerpMarkets = [
131
131
  baseAssetSymbol: 'RNDR',
132
132
  marketIndex: 12,
133
133
  oracle: new web3_js_1.PublicKey('C2QvUPBiU3fViSyqA4nZgGyYqLgYf9PRpd8B8oLoo48w'),
134
- launchTs: 1683125906000,
134
+ launchTs: 1687201081000,
135
135
  oracleSource: __1.OracleSource.PYTH,
136
136
  },
137
137
  ];
@@ -243,7 +243,7 @@ exports.MainnetPerpMarkets = [
243
243
  baseAssetSymbol: '1MPEPE',
244
244
  marketIndex: 10,
245
245
  oracle: new web3_js_1.PublicKey('FSfxunDmjjbDV2QxpyxFCAPKmYJHSLnLuvQXDLkMzLBm'),
246
- launchTs: 1683125906000,
246
+ launchTs: 1683781239000,
247
247
  oracleSource: __1.OracleSource.PYTH_1M,
248
248
  },
249
249
  {
@@ -253,7 +253,7 @@ exports.MainnetPerpMarkets = [
253
253
  baseAssetSymbol: 'OP',
254
254
  marketIndex: 11,
255
255
  oracle: new web3_js_1.PublicKey('4o4CUwzFwLqCvmA5x1G4VzoZkAhAcbiuiYyjWX1CVbY2'),
256
- launchTs: 1683125906000,
256
+ launchTs: 1686091480000,
257
257
  oracleSource: __1.OracleSource.PYTH,
258
258
  },
259
259
  {
@@ -263,7 +263,7 @@ exports.MainnetPerpMarkets = [
263
263
  baseAssetSymbol: 'RNDR',
264
264
  marketIndex: 12,
265
265
  oracle: new web3_js_1.PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
266
- launchTs: 1683125906000,
266
+ launchTs: 1687201081000,
267
267
  oracleSource: __1.OracleSource.PYTH,
268
268
  },
269
269
  ];
@@ -2053,7 +2053,7 @@ class DriftClient {
2053
2053
  state: await this.getStatePublicKey(),
2054
2054
  user: userAccountPublicKeyToUse,
2055
2055
  userStats: this.getUserStatsAccountPublicKey(),
2056
- authority: this.authority,
2056
+ authority: this.wallet.publicKey,
2057
2057
  outSpotMarketVault: outSpotMarket.vault,
2058
2058
  inSpotMarketVault: inSpotMarket.vault,
2059
2059
  inTokenAccount,
@@ -2069,7 +2069,7 @@ class DriftClient {
2069
2069
  state: await this.getStatePublicKey(),
2070
2070
  user: userAccountPublicKeyToUse,
2071
2071
  userStats: this.getUserStatsAccountPublicKey(),
2072
- authority: this.authority,
2072
+ authority: this.wallet.publicKey,
2073
2073
  outSpotMarketVault: outSpotMarket.vault,
2074
2074
  inSpotMarketVault: inSpotMarket.vault,
2075
2075
  inTokenAccount,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.32.0",
2
+ "version": "2.33.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -4,12 +4,13 @@ import { DriftClient } from '../driftClient';
4
4
  import { BN } from '@coral-xyz/anchor';
5
5
  import { User } from '../user';
6
6
  import { DepositRecord } from '../types';
7
- export declare function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, }: {
7
+ export declare function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, forceMarinade, }: {
8
8
  amount: BN;
9
9
  jupiterClient: JupiterClient;
10
10
  driftClient: DriftClient;
11
11
  marinadePrice?: number;
12
12
  userAccountPublicKey?: PublicKey;
13
+ forceMarinade?: boolean;
13
14
  }): Promise<{
14
15
  ixs: TransactionInstruction[];
15
16
  lookupTables: AddressLookupTableAccount[];
@@ -10,7 +10,7 @@ const anchor_1 = require("@coral-xyz/anchor");
10
10
  const types_1 = require("../types");
11
11
  const numericConstants_1 = require("../constants/numericConstants");
12
12
  const node_fetch_1 = __importDefault(require("node-fetch"));
13
- async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, }) {
13
+ async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, marinadePrice, forceMarinade, }) {
14
14
  if (!marinadePrice) {
15
15
  const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(driftClient.provider);
16
16
  marinadePrice = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
@@ -31,8 +31,11 @@ async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userA
31
31
  catch (e) {
32
32
  console.error('Error getting jupiter price', e);
33
33
  }
34
- if (!jupiterPrice || marinadePrice <= jupiterPrice) {
35
- const ixs = await driftClient.getStakeForMSOLIx({ amount });
34
+ if (!jupiterPrice || marinadePrice <= jupiterPrice || forceMarinade) {
35
+ const ixs = await driftClient.getStakeForMSOLIx({
36
+ amount,
37
+ userAccountPublicKey,
38
+ });
36
39
  return {
37
40
  method: 'marinade',
38
41
  ixs,
package/lib/types.d.ts CHANGED
@@ -725,6 +725,8 @@ export type SpotMarketAccount = {
725
725
  nextDepositRecordId: BN;
726
726
  orderStepSize: BN;
727
727
  orderTickSize: BN;
728
+ minOrderSize: BN;
729
+ maxPositionSize: BN;
728
730
  nextFillRecordId: BN;
729
731
  spotFeePool: PoolBalance;
730
732
  totalSpotFee: BN;
package/lib/user.js CHANGED
@@ -1172,7 +1172,8 @@ class User {
1172
1172
  inSwap = minSwap.add(maxSwap).div(numericConstants_1.TWO);
1173
1173
  }
1174
1174
  if (i++ > iterationLimit) {
1175
- throw new Error('getMaxSwapAmount iteration limit reached');
1175
+ console.log('getMaxSwapAmount iteration limit reached');
1176
+ break;
1176
1177
  }
1177
1178
  }
1178
1179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.32.1-beta.8",
3
+ "version": "2.33.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assert = void 0;
4
+ function assert(condition, error) {
5
+ if (!condition) {
6
+ throw new Error(error || 'Unspecified AssertionError');
7
+ }
8
+ }
9
+ exports.assert = assert;
@@ -121,7 +121,7 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
121
121
  baseAssetSymbol: '1MPEPE',
122
122
  marketIndex: 10,
123
123
  oracle: new PublicKey('Gz9RfgDeAFSsH7BHDGyNTgCik74rjNwsodJpsCizzmkj'),
124
- launchTs: 1683125906000,
124
+ launchTs: 1683781239000,
125
125
  oracleSource: OracleSource.PYTH_1M,
126
126
  },
127
127
  {
@@ -131,7 +131,7 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
131
131
  baseAssetSymbol: 'OP',
132
132
  marketIndex: 11,
133
133
  oracle: new PublicKey('8ctSiDhA7eJoii4TkKV8Rx4KFdz3ycsA1FXy9wq56quG'),
134
- launchTs: 1683125906000,
134
+ launchTs: 1686091480000,
135
135
  oracleSource: OracleSource.PYTH,
136
136
  },
137
137
  {
@@ -141,7 +141,7 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
141
141
  baseAssetSymbol: 'RNDR',
142
142
  marketIndex: 12,
143
143
  oracle: new PublicKey('C2QvUPBiU3fViSyqA4nZgGyYqLgYf9PRpd8B8oLoo48w'),
144
- launchTs: 1683125906000,
144
+ launchTs: 1687201081000,
145
145
  oracleSource: OracleSource.PYTH,
146
146
  },
147
147
  ];
@@ -254,7 +254,7 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
254
254
  baseAssetSymbol: '1MPEPE',
255
255
  marketIndex: 10,
256
256
  oracle: new PublicKey('FSfxunDmjjbDV2QxpyxFCAPKmYJHSLnLuvQXDLkMzLBm'),
257
- launchTs: 1683125906000,
257
+ launchTs: 1683781239000,
258
258
  oracleSource: OracleSource.PYTH_1M,
259
259
  },
260
260
  {
@@ -264,7 +264,7 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
264
264
  baseAssetSymbol: 'OP',
265
265
  marketIndex: 11,
266
266
  oracle: new PublicKey('4o4CUwzFwLqCvmA5x1G4VzoZkAhAcbiuiYyjWX1CVbY2'),
267
- launchTs: 1683125906000,
267
+ launchTs: 1686091480000,
268
268
  oracleSource: OracleSource.PYTH,
269
269
  },
270
270
  {
@@ -274,7 +274,7 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
274
274
  baseAssetSymbol: 'RNDR',
275
275
  marketIndex: 12,
276
276
  oracle: new PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
277
- launchTs: 1683125906000,
277
+ launchTs: 1687201081000,
278
278
  oracleSource: OracleSource.PYTH,
279
279
  },
280
280
  ];
@@ -3594,7 +3594,7 @@ export class DriftClient {
3594
3594
  state: await this.getStatePublicKey(),
3595
3595
  user: userAccountPublicKeyToUse,
3596
3596
  userStats: this.getUserStatsAccountPublicKey(),
3597
- authority: this.authority,
3597
+ authority: this.wallet.publicKey,
3598
3598
  outSpotMarketVault: outSpotMarket.vault,
3599
3599
  inSpotMarketVault: inSpotMarket.vault,
3600
3600
  inTokenAccount,
@@ -3617,7 +3617,7 @@ export class DriftClient {
3617
3617
  state: await this.getStatePublicKey(),
3618
3618
  user: userAccountPublicKeyToUse,
3619
3619
  userStats: this.getUserStatsAccountPublicKey(),
3620
- authority: this.authority,
3620
+ authority: this.wallet.publicKey,
3621
3621
  outSpotMarketVault: outSpotMarket.vault,
3622
3622
  inSpotMarketVault: inSpotMarket.vault,
3623
3623
  inTokenAccount,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.32.0",
2
+ "version": "2.33.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -19,12 +19,14 @@ export async function findBestSuperStakeIxs({
19
19
  driftClient,
20
20
  userAccountPublicKey,
21
21
  marinadePrice,
22
+ forceMarinade,
22
23
  }: {
23
24
  amount: BN;
24
25
  jupiterClient: JupiterClient;
25
26
  driftClient: DriftClient;
26
27
  marinadePrice?: number;
27
28
  userAccountPublicKey?: PublicKey;
29
+ forceMarinade?: boolean;
28
30
  }): Promise<{
29
31
  ixs: TransactionInstruction[];
30
32
  lookupTables: AddressLookupTableAccount[];
@@ -54,8 +56,11 @@ export async function findBestSuperStakeIxs({
54
56
  console.error('Error getting jupiter price', e);
55
57
  }
56
58
 
57
- if (!jupiterPrice || marinadePrice <= jupiterPrice) {
58
- const ixs = await driftClient.getStakeForMSOLIx({ amount });
59
+ if (!jupiterPrice || marinadePrice <= jupiterPrice || forceMarinade) {
60
+ const ixs = await driftClient.getStakeForMSOLIx({
61
+ amount,
62
+ userAccountPublicKey,
63
+ });
59
64
  return {
60
65
  method: 'marinade',
61
66
  ixs,
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTokenAccount = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ function parseTokenAccount(data) {
7
+ const accountInfo = spl_token_1.AccountLayout.decode(data);
8
+ accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
9
+ accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
10
+ accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
11
+ if (accountInfo.delegateOption === 0) {
12
+ accountInfo.delegate = null;
13
+ // eslint-disable-next-line new-cap
14
+ accountInfo.delegatedAmount = new spl_token_1.u64(0);
15
+ }
16
+ else {
17
+ accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
18
+ accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
19
+ }
20
+ accountInfo.isInitialized = accountInfo.state !== 0;
21
+ accountInfo.isFrozen = accountInfo.state === 2;
22
+ if (accountInfo.isNativeOption === 1) {
23
+ accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
24
+ accountInfo.isNative = true;
25
+ }
26
+ else {
27
+ accountInfo.rentExemptReserve = null;
28
+ accountInfo.isNative = false;
29
+ }
30
+ if (accountInfo.closeAuthorityOption === 0) {
31
+ accountInfo.closeAuthority = null;
32
+ }
33
+ else {
34
+ accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
35
+ }
36
+ return accountInfo;
37
+ }
38
+ exports.parseTokenAccount = parseTokenAccount;
package/src/types.ts CHANGED
@@ -660,6 +660,8 @@ export type SpotMarketAccount = {
660
660
 
661
661
  orderStepSize: BN;
662
662
  orderTickSize: BN;
663
+ minOrderSize: BN;
664
+ maxPositionSize: BN;
663
665
  nextFillRecordId: BN;
664
666
  spotFeePool: PoolBalance;
665
667
  totalSpotFee: BN;
package/src/user.ts CHANGED
@@ -2106,7 +2106,8 @@ export class User {
2106
2106
  }
2107
2107
 
2108
2108
  if (i++ > iterationLimit) {
2109
- throw new Error('getMaxSwapAmount iteration limit reached');
2109
+ console.log('getMaxSwapAmount iteration limit reached');
2110
+ break;
2110
2111
  }
2111
2112
  }
2112
2113
  }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findComputeUnitConsumption = void 0;
13
+ function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const tx = yield connection.getTransaction(txSignature, { commitment });
16
+ const computeUnits = [];
17
+ const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
18
+ tx.meta.logMessages.forEach((logMessage) => {
19
+ const match = logMessage.match(regex);
20
+ if (match && match[1]) {
21
+ computeUnits.push(match[1]);
22
+ }
23
+ });
24
+ return computeUnits;
25
+ });
26
+ }
27
+ exports.findComputeUnitConsumption = findComputeUnitConsumption;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promiseTimeout = void 0;
4
+ function promiseTimeout(promise, timeoutMs) {
5
+ let timeoutId;
6
+ const timeoutPromise = new Promise((resolve) => {
7
+ timeoutId = setTimeout(() => resolve(null), timeoutMs);
8
+ });
9
+ return Promise.race([promise, timeoutPromise]).then((result) => {
10
+ clearTimeout(timeoutId);
11
+ return result;
12
+ });
13
+ }
14
+ exports.promiseTimeout = promiseTimeout;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.estimateTps = void 0;
13
+ function estimateTps(programId, connection, failed) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
16
+ if (failed) {
17
+ signatures = signatures.filter((signature) => signature.err);
18
+ }
19
+ const numberOfSignatures = signatures.length;
20
+ if (numberOfSignatures === 0) {
21
+ return 0;
22
+ }
23
+ return (numberOfSignatures /
24
+ (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
25
+ });
26
+ }
27
+ exports.estimateTps = estimateTps;
@@ -261,6 +261,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
261
261
  pubkey: PublicKey.default,
262
262
  mint: DevnetSpotMarkets[0].mint,
263
263
  vault: PublicKey.default,
264
+ minOrderSize: ZERO,
265
+ maxPositionSize: ZERO,
264
266
  revenuePool: {
265
267
  scaledBalance: new BN(0),
266
268
  marketIndex: 0,
@@ -343,6 +345,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
343
345
  scaledBalance: new BN(0),
344
346
  marketIndex: 0,
345
347
  },
348
+ minOrderSize: ZERO,
349
+ maxPositionSize: ZERO,
346
350
  insuranceFund: {
347
351
  vault: PublicKey.default,
348
352
  totalShares: new BN(0),
@@ -421,6 +425,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
421
425
  scaledBalance: new BN(0),
422
426
  marketIndex: 0,
423
427
  },
428
+ minOrderSize: ZERO,
429
+ maxPositionSize: ZERO,
424
430
  insuranceFund: {
425
431
  vault: PublicKey.default,
426
432
  totalShares: new BN(0),