@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 +3 -2
- package/VERSION +1 -0
- package/lib/auctionSubscriber/auctionSubscriber.js +2 -0
- package/lib/driftClient.js +3 -4
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -1
- package/package.json +3 -2
- package/scripts/updateVersion.js +28 -0
- package/src/auctionSubscriber/auctionSubscriber.ts +1 -0
- package/src/driftClient.ts +9 -14
- package/src/idl/drift.json +1 -1
- package/src/index.ts +4 -1
- package/src/assert/assert.js +0 -9
- package/src/token/index.js +0 -38
- package/src/util/computeUnits.js +0 -27
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
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-
|
|
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
|
|
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) => {
|
package/lib/driftClient.js
CHANGED
|
@@ -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 &&
|
|
1398
|
-
const versionedMarketOrderTx = await this.
|
|
1399
|
-
const versionedFillTx = await this.
|
|
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,
|
package/lib/idl/drift.json
CHANGED
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.
|
|
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("");
|
package/src/driftClient.ts
CHANGED
|
@@ -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 &&
|
|
2380
|
-
const versionedMarketOrderTx =
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
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
|
-
|
|
2390
|
-
|
|
2391
|
-
this.opts
|
|
2385
|
+
txParams,
|
|
2386
|
+
0
|
|
2392
2387
|
);
|
|
2393
2388
|
const [signedVersionedMarketOrderTx, signedVersionedFillTx] =
|
|
2394
2389
|
await this.provider.wallet.signAllTransactions([
|
package/src/idl/drift.json
CHANGED
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 };
|
package/src/assert/assert.js
DELETED
package/src/token/index.js
DELETED
|
@@ -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;
|
package/src/util/computeUnits.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.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;
|