@drift-labs/sdk 2.31.0-beta.7 → 2.31.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  <p>
7
7
  <a href="https://www.npmjs.com/package/@drift-labs/sdk"><img alt="SDK npm package" src="https://img.shields.io/npm/v/@drift-labs/sdk" /></a>
8
- <a href="https://drift-labs.github.io/protocol-v1/sdk/"><img alt="Docs" src="https://img.shields.io/badge/docs-tutorials-blueviolet" /></a>
8
+ <a href="https://drift-labs.github.io/protocol-v2/sdk/"><img alt="Docs" src="https://img.shields.io/badge/docs-tutorials-blueviolet" /></a>
9
9
  <a href="https://discord.com/channels/849494028176588802/878700556904980500"><img alt="Discord Chat" src="https://img.shields.io/discord/889577356681945098?color=blueviolet" /></a>
10
10
  <a href="https://opensource.org/licenses/Apache-2.0"><img alt="License" src="https://img.shields.io/github/license/project-serum/anchor?color=blueviolet" /></a>
11
11
  </p>
@@ -53,6 +53,7 @@ The Drift SDK uses some common precisions, which are available as constants to i
53
53
  | PEG_PRECISION | 10^6 |
54
54
  | PRICE_PRECISION | 10^6 |
55
55
  | AMM_RESERVE_PRECISION | 10^9 |
56
+ | BASE_PRECISION | 10^9 |
56
57
 
57
58
  **Important Note for BigNum division**
58
59
 
@@ -238,7 +239,7 @@ main();
238
239
 
239
240
  ## License
240
241
 
241
- Drift Protocol v1 is licensed under [Apache 2.0](./LICENSE).
242
+ Drift Protocol v2 is licensed under [Apache 2.0](./LICENSE).
242
243
 
243
244
  Unless you explicitly state otherwise, any contribution intentionally submitted
244
245
  for inclusion in Drift SDK by you, as defined in the Apache-2.0 license, shall be
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.31.1-beta.0
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuctionSubscriber = void 0;
4
4
  const memcmp_1 = require("../memcmp");
5
+ const events_1 = require("events");
5
6
  class AuctionSubscriber {
6
7
  constructor({ driftClient, opts }) {
7
8
  this.driftClient = driftClient;
8
9
  this.opts = opts || this.driftClient.opts;
10
+ this.eventEmitter = new events_1.EventEmitter();
9
11
  }
10
12
  async subscribe() {
11
13
  this.websocketId = this.driftClient.connection.onProgramAccountChange(this.driftClient.program.programId, (keyAccountInfo, context) => {
@@ -1389,14 +1389,13 @@ class DriftClient {
1389
1389
  orderId,
1390
1390
  marketIndex,
1391
1391
  }, makerInfo, referrerInfo);
1392
- const lookupTableAccount = await this.fetchMarketLookupTableAccount();
1393
1392
  const walletSupportsVersionedTxns =
1394
1393
  //@ts-ignore
1395
1394
  (_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
1396
1395
  // use versioned transactions if there is a lookup table account and wallet is compatible
1397
- if (walletSupportsVersionedTxns && lookupTableAccount && useVersionedTx) {
1398
- const versionedMarketOrderTx = await this.txSender.getVersionedTransaction([placePerpOrderIx].concat(bracketOrderIxs), [lookupTableAccount], [], this.opts);
1399
- const versionedFillTx = await this.txSender.getVersionedTransaction([fillPerpOrderIx], [lookupTableAccount], [], this.opts);
1396
+ if (walletSupportsVersionedTxns && useVersionedTx) {
1397
+ const versionedMarketOrderTx = await this.buildTransaction([placePerpOrderIx].concat(bracketOrderIxs), txParams, 0);
1398
+ const versionedFillTx = await this.buildTransaction([fillPerpOrderIx], txParams, 0);
1400
1399
  const [signedVersionedMarketOrderTx, signedVersionedFillTx] = await this.provider.wallet.signAllTransactions([
1401
1400
  //@ts-ignore
1402
1401
  versionedMarketOrderTx,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.0-beta.7",
2
+ "version": "2.31.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/index.d.ts CHANGED
@@ -57,6 +57,7 @@ export * from './serum/serumFulfillmentConfigMap';
57
57
  export * from './phoenix/phoenixSubscriber';
58
58
  export * from './phoenix/phoenixFulfillmentConfigMap';
59
59
  export * from './tx/retryTxSender';
60
+ export * from './tx/types';
60
61
  export * from './util/computeUnits';
61
62
  export * from './util/tps';
62
63
  export * from './util/promiseTimeout';
@@ -75,4 +76,7 @@ export * from './userMap/userMap';
75
76
  export * from './userMap/userStatsMap';
76
77
  export * from './math/bankruptcy';
77
78
  export * from './orderSubscriber';
79
+ export * from './orderSubscriber/types';
80
+ export * from './auctionSubscriber';
81
+ export * from './auctionSubscriber/types';
78
82
  export { BN, PublicKey, pyth };
package/lib/index.js CHANGED
@@ -27,7 +27,6 @@ exports.pyth = client_1.default;
27
27
  __exportStar(require("./tokenFaucet"), exports);
28
28
  __exportStar(require("./oracles/types"), exports);
29
29
  __exportStar(require("./oracles/pythClient"), exports);
30
- // export * from './oracles/switchboardClient';
31
30
  __exportStar(require("./types"), exports);
32
31
  __exportStar(require("./constants/perpMarkets"), exports);
33
32
  __exportStar(require("./accounts/fetch"), exports);
@@ -81,6 +80,7 @@ __exportStar(require("./serum/serumFulfillmentConfigMap"), exports);
81
80
  __exportStar(require("./phoenix/phoenixSubscriber"), exports);
82
81
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
83
82
  __exportStar(require("./tx/retryTxSender"), exports);
83
+ __exportStar(require("./tx/types"), exports);
84
84
  __exportStar(require("./util/computeUnits"), exports);
85
85
  __exportStar(require("./util/tps"), exports);
86
86
  __exportStar(require("./util/promiseTimeout"), exports);
@@ -99,3 +99,6 @@ __exportStar(require("./userMap/userMap"), exports);
99
99
  __exportStar(require("./userMap/userStatsMap"), exports);
100
100
  __exportStar(require("./math/bankruptcy"), exports);
101
101
  __exportStar(require("./orderSubscriber"), exports);
102
+ __exportStar(require("./orderSubscriber/types"), exports);
103
+ __exportStar(require("./auctionSubscriber"), exports);
104
+ __exportStar(require("./auctionSubscriber/types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.0-beta.7",
3
+ "version": "2.31.1-beta.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -18,7 +18,8 @@
18
18
  "test:bignum": "mocha -r ts-node/register tests/bn/**/*.ts",
19
19
  "patch-and-pub": "npm version patch --force && npm publish",
20
20
  "prettify": "prettier --check './src/***/*.ts'",
21
- "prettify:fix": "prettier --write './{src,tests}/***/*.ts'"
21
+ "prettify:fix": "prettier --write './{src,tests}/***/*.ts'",
22
+ "version": "node ./scripts/updateVersion.js"
22
23
  },
23
24
  "keywords": [
24
25
  "drift-labs",
@@ -0,0 +1,28 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const packageJson = require('../package.json');
4
+
5
+ const versionFilePath = path.join(__dirname, '..', 'VERSION');
6
+
7
+ let version = fs.readFileSync(versionFilePath, 'utf8');
8
+ version = version.replace(/\n/g, '');
9
+
10
+ const filesToReplace = [
11
+ // sdk/src/idl/drift.json
12
+ path.join(__dirname, '..', 'src', 'idl', 'drift.json'),
13
+ // programs/drift/Cargo.toml
14
+ path.join(__dirname, '..', '..', 'programs', 'drift', 'Cargo.toml'),
15
+ // Cargo.lock
16
+ path.join(__dirname, '..', '..', 'Cargo.lock'),
17
+ ]
18
+
19
+ console.log(`Updating versions from ${version} to ${packageJson.version} in:`);
20
+ for (const file of filesToReplace) {
21
+ console.log(`* ${file}`);
22
+ const fileContents = fs.readFileSync(file, 'utf8');
23
+ const newFileContents = fileContents.replace(version, packageJson.version);
24
+ fs.writeFileSync(file, newFileContents);
25
+ }
26
+
27
+ fs.writeFileSync(versionFilePath, packageJson.version);
28
+ console.log("");
@@ -17,6 +17,7 @@ export class AuctionSubscriber {
17
17
  constructor({ driftClient, opts }: AuctionSubscriberConfig) {
18
18
  this.driftClient = driftClient;
19
19
  this.opts = opts || this.driftClient.opts;
20
+ this.eventEmitter = new EventEmitter();
20
21
  }
21
22
 
22
23
  public async subscribe() {
@@ -2369,26 +2369,21 @@ export class DriftClient {
2369
2369
  referrerInfo
2370
2370
  );
2371
2371
 
2372
- const lookupTableAccount = await this.fetchMarketLookupTableAccount();
2373
-
2374
2372
  const walletSupportsVersionedTxns =
2375
2373
  //@ts-ignore
2376
2374
  this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
2377
2375
 
2378
2376
  // use versioned transactions if there is a lookup table account and wallet is compatible
2379
- if (walletSupportsVersionedTxns && lookupTableAccount && useVersionedTx) {
2380
- const versionedMarketOrderTx =
2381
- await this.txSender.getVersionedTransaction(
2382
- [placePerpOrderIx].concat(bracketOrderIxs),
2383
- [lookupTableAccount],
2384
- [],
2385
- this.opts
2386
- );
2387
- const versionedFillTx = await this.txSender.getVersionedTransaction(
2377
+ if (walletSupportsVersionedTxns && useVersionedTx) {
2378
+ const versionedMarketOrderTx = await this.buildTransaction(
2379
+ [placePerpOrderIx].concat(bracketOrderIxs),
2380
+ txParams,
2381
+ 0
2382
+ );
2383
+ const versionedFillTx = await this.buildTransaction(
2388
2384
  [fillPerpOrderIx],
2389
- [lookupTableAccount],
2390
- [],
2391
- this.opts
2385
+ txParams,
2386
+ 0
2392
2387
  );
2393
2388
  const [signedVersionedMarketOrderTx, signedVersionedFillTx] =
2394
2389
  await this.provider.wallet.signAllTransactions([
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.0-beta.7",
2
+ "version": "2.31.1-beta.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/src/index.ts CHANGED
@@ -5,7 +5,6 @@ import pyth from '@pythnetwork/client';
5
5
  export * from './tokenFaucet';
6
6
  export * from './oracles/types';
7
7
  export * from './oracles/pythClient';
8
- // export * from './oracles/switchboardClient';
9
8
  export * from './types';
10
9
  export * from './constants/perpMarkets';
11
10
  export * from './accounts/fetch';
@@ -59,6 +58,7 @@ export * from './serum/serumFulfillmentConfigMap';
59
58
  export * from './phoenix/phoenixSubscriber';
60
59
  export * from './phoenix/phoenixFulfillmentConfigMap';
61
60
  export * from './tx/retryTxSender';
61
+ export * from './tx/types';
62
62
  export * from './util/computeUnits';
63
63
  export * from './util/tps';
64
64
  export * from './util/promiseTimeout';
@@ -77,5 +77,8 @@ export * from './userMap/userMap';
77
77
  export * from './userMap/userStatsMap';
78
78
  export * from './math/bankruptcy';
79
79
  export * from './orderSubscriber';
80
+ export * from './orderSubscriber/types';
81
+ export * from './auctionSubscriber';
82
+ export * from './auctionSubscriber/types';
80
83
 
81
84
  export { BN, PublicKey, pyth };
@@ -1,9 +0,0 @@
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;
@@ -1,38 +0,0 @@
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;
@@ -1,27 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
package/src/util/tps.js DELETED
@@ -1,27 +0,0 @@
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;