@drift-labs/sdk 2.112.0-beta.5 → 2.112.0-beta.7
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 +1 -1
- package/lib/browser/decode/user.js +4 -1
- package/lib/browser/driftClient.d.ts +1 -0
- package/lib/browser/driftClient.js +16 -13
- package/lib/browser/idl/drift.json +9 -1
- package/lib/browser/math/orders.d.ts +1 -0
- package/lib/browser/math/orders.js +6 -1
- package/lib/browser/types.d.ts +3 -1
- package/lib/node/decode/user.js +4 -1
- package/lib/node/driftClient.d.ts +1 -0
- package/lib/node/driftClient.js +16 -13
- package/lib/node/idl/drift.json +9 -1
- package/lib/node/math/orders.d.ts +1 -0
- package/lib/node/math/orders.js +6 -1
- package/lib/node/types.d.ts +3 -1
- package/package.json +1 -1
- package/src/decode/user.ts +4 -1
- package/src/driftClient.ts +14 -9
- package/src/idl/drift.json +9 -1
- package/src/math/orders.ts +5 -0
- package/src/types.ts +6 -0
- package/tests/user/helpers.ts +1 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.112.0-beta.
|
|
1
|
+
2.112.0-beta.7
|
|
@@ -230,7 +230,9 @@ function decodeUser(buffer) {
|
|
|
230
230
|
offset += 1;
|
|
231
231
|
const postedSlotTail = buffer.readUint8(offset);
|
|
232
232
|
offset += 1;
|
|
233
|
-
|
|
233
|
+
const bitFlags = buffer.readUint8(offset);
|
|
234
|
+
offset += 1;
|
|
235
|
+
offset += 1; // padding
|
|
234
236
|
orders.push({
|
|
235
237
|
slot,
|
|
236
238
|
price,
|
|
@@ -256,6 +258,7 @@ function decodeUser(buffer) {
|
|
|
256
258
|
immediateOrCancel,
|
|
257
259
|
triggerCondition,
|
|
258
260
|
auctionDuration,
|
|
261
|
+
bitFlags,
|
|
259
262
|
postedSlotTail,
|
|
260
263
|
});
|
|
261
264
|
}
|
|
@@ -125,6 +125,7 @@ export declare class DriftClient {
|
|
|
125
125
|
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
126
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
127
|
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
128
|
+
private getTxVersionForNewWallet;
|
|
128
129
|
/**
|
|
129
130
|
* Update the wallet to use for drift transactions and linked user account
|
|
130
131
|
* @param newWallet
|
|
@@ -110,7 +110,8 @@ class DriftClient {
|
|
|
110
110
|
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
111
111
|
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
112
112
|
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
113
|
-
this.txVersion =
|
|
113
|
+
this.txVersion =
|
|
114
|
+
(_h = config.txVersion) !== null && _h !== void 0 ? _h : this.getTxVersionForNewWallet(config.wallet);
|
|
114
115
|
this.txParams = {
|
|
115
116
|
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
116
117
|
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
@@ -395,6 +396,14 @@ class DriftClient {
|
|
|
395
396
|
this.lookupTableAccounts = lookupTableAccounts;
|
|
396
397
|
return lookupTableAccounts;
|
|
397
398
|
}
|
|
399
|
+
getTxVersionForNewWallet(newWallet) {
|
|
400
|
+
var _a, _b, _c;
|
|
401
|
+
if (!(newWallet === null || newWallet === void 0 ? void 0 : newWallet.supportedTransactionVersions))
|
|
402
|
+
return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
403
|
+
const walletSupportsVersionedTxns = ((_a = newWallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.has(0)) ||
|
|
404
|
+
((_c = (_b = newWallet.supportedTransactionVersions) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1;
|
|
405
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
406
|
+
}
|
|
398
407
|
/**
|
|
399
408
|
* Update the wallet to use for drift transactions and linked user account
|
|
400
409
|
* @param newWallet
|
|
@@ -403,7 +412,7 @@ class DriftClient {
|
|
|
403
412
|
* @param includeDelegates
|
|
404
413
|
*/
|
|
405
414
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
406
|
-
var _a
|
|
415
|
+
var _a;
|
|
407
416
|
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
408
417
|
// @ts-ignore
|
|
409
418
|
newWallet, this.opts);
|
|
@@ -419,10 +428,7 @@ class DriftClient {
|
|
|
419
428
|
this.activeSubAccountId = activeSubAccountId;
|
|
420
429
|
this.userStatsAccountPublicKey = undefined;
|
|
421
430
|
this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
|
|
422
|
-
|
|
423
|
-
//@ts-expect-error
|
|
424
|
-
((_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 1;
|
|
425
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
431
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
426
432
|
if (includeDelegates && subAccountIds) {
|
|
427
433
|
throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
|
|
428
434
|
}
|
|
@@ -438,7 +444,7 @@ class DriftClient {
|
|
|
438
444
|
? new Map([[this.authority.toString(), subAccountIds]])
|
|
439
445
|
: new Map();
|
|
440
446
|
/* Reset user stats account */
|
|
441
|
-
if ((
|
|
447
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
442
448
|
await this.userStats.unsubscribe();
|
|
443
449
|
}
|
|
444
450
|
this.userStats = undefined;
|
|
@@ -467,19 +473,16 @@ class DriftClient {
|
|
|
467
473
|
* @param emulateAuthority
|
|
468
474
|
*/
|
|
469
475
|
async emulateAccount(emulateAuthority) {
|
|
470
|
-
var _a
|
|
476
|
+
var _a;
|
|
471
477
|
this.skipLoadUsers = false;
|
|
472
478
|
// Update provider for txSender with new wallet details
|
|
473
479
|
this.authority = emulateAuthority;
|
|
474
480
|
this.userStatsAccountPublicKey = undefined;
|
|
475
481
|
this.includeDelegates = true;
|
|
476
|
-
|
|
477
|
-
//@ts-ignore
|
|
478
|
-
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
479
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
482
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
480
483
|
this.authoritySubAccountMap = new Map();
|
|
481
484
|
/* Reset user stats account */
|
|
482
|
-
if ((
|
|
485
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
483
486
|
await this.userStats.unsubscribe();
|
|
484
487
|
}
|
|
485
488
|
this.userStats = undefined;
|
|
@@ -10912,12 +10912,20 @@
|
|
|
10912
10912
|
],
|
|
10913
10913
|
"type": "u8"
|
|
10914
10914
|
},
|
|
10915
|
+
{
|
|
10916
|
+
"name": "bitFlags",
|
|
10917
|
+
"docs": [
|
|
10918
|
+
"Bitflags for further classification",
|
|
10919
|
+
"0: is_signed_message"
|
|
10920
|
+
],
|
|
10921
|
+
"type": "u8"
|
|
10922
|
+
},
|
|
10915
10923
|
{
|
|
10916
10924
|
"name": "padding",
|
|
10917
10925
|
"type": {
|
|
10918
10926
|
"array": [
|
|
10919
10927
|
"u8",
|
|
10920
|
-
|
|
10928
|
+
1
|
|
10921
10929
|
]
|
|
10922
10930
|
}
|
|
10923
10931
|
}
|
|
@@ -21,3 +21,4 @@ export declare function mustBeTriggered(order: Order): boolean;
|
|
|
21
21
|
export declare function isTriggered(order: Order): boolean;
|
|
22
22
|
export declare function isRestingLimitOrder(order: Order, slot: number): boolean;
|
|
23
23
|
export declare function isTakingOrder(order: Order, slot: number): boolean;
|
|
24
|
+
export declare function isSignedMsgOrder(order: Order): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
3
|
+
exports.isSignedMsgOrder = exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
@@ -223,3 +223,8 @@ function isTakingOrder(order, slot) {
|
|
|
223
223
|
return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
|
|
224
224
|
}
|
|
225
225
|
exports.isTakingOrder = isTakingOrder;
|
|
226
|
+
const FLAG_IS_SIGNED_MSG = 0x01;
|
|
227
|
+
function isSignedMsgOrder(order) {
|
|
228
|
+
return (order.bitFlags & FLAG_IS_SIGNED_MSG) !== 0;
|
|
229
|
+
}
|
|
230
|
+
exports.isSignedMsgOrder = isSignedMsgOrder;
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { Keypair, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { Keypair, PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
5
5
|
import { BN } from '.';
|
|
6
6
|
export type MappedRecord<A extends Record<string, unknown>, B> = {
|
|
7
7
|
[K in keyof A]: B;
|
|
@@ -1142,6 +1142,7 @@ export type Order = {
|
|
|
1142
1142
|
auctionStartPrice: BN;
|
|
1143
1143
|
auctionEndPrice: BN;
|
|
1144
1144
|
maxTs: BN;
|
|
1145
|
+
bitFlags: number;
|
|
1145
1146
|
postedSlotTail: number;
|
|
1146
1147
|
};
|
|
1147
1148
|
export type OrderParams = {
|
|
@@ -1261,6 +1262,7 @@ export interface IWallet {
|
|
|
1261
1262
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1262
1263
|
publicKey: PublicKey;
|
|
1263
1264
|
payer?: Keypair;
|
|
1265
|
+
supportedTransactionVersions?: ReadonlySet<TransactionVersion> | null | undefined;
|
|
1264
1266
|
}
|
|
1265
1267
|
export interface IVersionedWallet {
|
|
1266
1268
|
signVersionedTransaction(tx: VersionedTransaction): Promise<VersionedTransaction>;
|
package/lib/node/decode/user.js
CHANGED
|
@@ -230,7 +230,9 @@ function decodeUser(buffer) {
|
|
|
230
230
|
offset += 1;
|
|
231
231
|
const postedSlotTail = buffer.readUint8(offset);
|
|
232
232
|
offset += 1;
|
|
233
|
-
|
|
233
|
+
const bitFlags = buffer.readUint8(offset);
|
|
234
|
+
offset += 1;
|
|
235
|
+
offset += 1; // padding
|
|
234
236
|
orders.push({
|
|
235
237
|
slot,
|
|
236
238
|
price,
|
|
@@ -256,6 +258,7 @@ function decodeUser(buffer) {
|
|
|
256
258
|
immediateOrCancel,
|
|
257
259
|
triggerCondition,
|
|
258
260
|
auctionDuration,
|
|
261
|
+
bitFlags,
|
|
259
262
|
postedSlotTail,
|
|
260
263
|
});
|
|
261
264
|
}
|
|
@@ -125,6 +125,7 @@ export declare class DriftClient {
|
|
|
125
125
|
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
126
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
127
|
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
128
|
+
private getTxVersionForNewWallet;
|
|
128
129
|
/**
|
|
129
130
|
* Update the wallet to use for drift transactions and linked user account
|
|
130
131
|
* @param newWallet
|
package/lib/node/driftClient.js
CHANGED
|
@@ -110,7 +110,8 @@ class DriftClient {
|
|
|
110
110
|
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
111
111
|
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
112
112
|
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
113
|
-
this.txVersion =
|
|
113
|
+
this.txVersion =
|
|
114
|
+
(_h = config.txVersion) !== null && _h !== void 0 ? _h : this.getTxVersionForNewWallet(config.wallet);
|
|
114
115
|
this.txParams = {
|
|
115
116
|
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
116
117
|
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
@@ -395,6 +396,14 @@ class DriftClient {
|
|
|
395
396
|
this.lookupTableAccounts = lookupTableAccounts;
|
|
396
397
|
return lookupTableAccounts;
|
|
397
398
|
}
|
|
399
|
+
getTxVersionForNewWallet(newWallet) {
|
|
400
|
+
var _a, _b, _c;
|
|
401
|
+
if (!(newWallet === null || newWallet === void 0 ? void 0 : newWallet.supportedTransactionVersions))
|
|
402
|
+
return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
403
|
+
const walletSupportsVersionedTxns = ((_a = newWallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.has(0)) ||
|
|
404
|
+
((_c = (_b = newWallet.supportedTransactionVersions) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1;
|
|
405
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
406
|
+
}
|
|
398
407
|
/**
|
|
399
408
|
* Update the wallet to use for drift transactions and linked user account
|
|
400
409
|
* @param newWallet
|
|
@@ -403,7 +412,7 @@ class DriftClient {
|
|
|
403
412
|
* @param includeDelegates
|
|
404
413
|
*/
|
|
405
414
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
406
|
-
var _a
|
|
415
|
+
var _a;
|
|
407
416
|
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
408
417
|
// @ts-ignore
|
|
409
418
|
newWallet, this.opts);
|
|
@@ -419,10 +428,7 @@ class DriftClient {
|
|
|
419
428
|
this.activeSubAccountId = activeSubAccountId;
|
|
420
429
|
this.userStatsAccountPublicKey = undefined;
|
|
421
430
|
this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
|
|
422
|
-
|
|
423
|
-
//@ts-expect-error
|
|
424
|
-
((_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 1;
|
|
425
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
431
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
426
432
|
if (includeDelegates && subAccountIds) {
|
|
427
433
|
throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
|
|
428
434
|
}
|
|
@@ -438,7 +444,7 @@ class DriftClient {
|
|
|
438
444
|
? new Map([[this.authority.toString(), subAccountIds]])
|
|
439
445
|
: new Map();
|
|
440
446
|
/* Reset user stats account */
|
|
441
|
-
if ((
|
|
447
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
442
448
|
await this.userStats.unsubscribe();
|
|
443
449
|
}
|
|
444
450
|
this.userStats = undefined;
|
|
@@ -467,19 +473,16 @@ class DriftClient {
|
|
|
467
473
|
* @param emulateAuthority
|
|
468
474
|
*/
|
|
469
475
|
async emulateAccount(emulateAuthority) {
|
|
470
|
-
var _a
|
|
476
|
+
var _a;
|
|
471
477
|
this.skipLoadUsers = false;
|
|
472
478
|
// Update provider for txSender with new wallet details
|
|
473
479
|
this.authority = emulateAuthority;
|
|
474
480
|
this.userStatsAccountPublicKey = undefined;
|
|
475
481
|
this.includeDelegates = true;
|
|
476
|
-
|
|
477
|
-
//@ts-ignore
|
|
478
|
-
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
479
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
482
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
480
483
|
this.authoritySubAccountMap = new Map();
|
|
481
484
|
/* Reset user stats account */
|
|
482
|
-
if ((
|
|
485
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
483
486
|
await this.userStats.unsubscribe();
|
|
484
487
|
}
|
|
485
488
|
this.userStats = undefined;
|
package/lib/node/idl/drift.json
CHANGED
|
@@ -10912,12 +10912,20 @@
|
|
|
10912
10912
|
],
|
|
10913
10913
|
"type": "u8"
|
|
10914
10914
|
},
|
|
10915
|
+
{
|
|
10916
|
+
"name": "bitFlags",
|
|
10917
|
+
"docs": [
|
|
10918
|
+
"Bitflags for further classification",
|
|
10919
|
+
"0: is_signed_message"
|
|
10920
|
+
],
|
|
10921
|
+
"type": "u8"
|
|
10922
|
+
},
|
|
10915
10923
|
{
|
|
10916
10924
|
"name": "padding",
|
|
10917
10925
|
"type": {
|
|
10918
10926
|
"array": [
|
|
10919
10927
|
"u8",
|
|
10920
|
-
|
|
10928
|
+
1
|
|
10921
10929
|
]
|
|
10922
10930
|
}
|
|
10923
10931
|
}
|
|
@@ -21,3 +21,4 @@ export declare function mustBeTriggered(order: Order): boolean;
|
|
|
21
21
|
export declare function isTriggered(order: Order): boolean;
|
|
22
22
|
export declare function isRestingLimitOrder(order: Order, slot: number): boolean;
|
|
23
23
|
export declare function isTakingOrder(order: Order, slot: number): boolean;
|
|
24
|
+
export declare function isSignedMsgOrder(order: Order): boolean;
|
package/lib/node/math/orders.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
3
|
+
exports.isSignedMsgOrder = exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
@@ -223,3 +223,8 @@ function isTakingOrder(order, slot) {
|
|
|
223
223
|
return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
|
|
224
224
|
}
|
|
225
225
|
exports.isTakingOrder = isTakingOrder;
|
|
226
|
+
const FLAG_IS_SIGNED_MSG = 0x01;
|
|
227
|
+
function isSignedMsgOrder(order) {
|
|
228
|
+
return (order.bitFlags & FLAG_IS_SIGNED_MSG) !== 0;
|
|
229
|
+
}
|
|
230
|
+
exports.isSignedMsgOrder = isSignedMsgOrder;
|
package/lib/node/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { Keypair, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { Keypair, PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
5
5
|
import { BN } from '.';
|
|
6
6
|
export type MappedRecord<A extends Record<string, unknown>, B> = {
|
|
7
7
|
[K in keyof A]: B;
|
|
@@ -1142,6 +1142,7 @@ export type Order = {
|
|
|
1142
1142
|
auctionStartPrice: BN;
|
|
1143
1143
|
auctionEndPrice: BN;
|
|
1144
1144
|
maxTs: BN;
|
|
1145
|
+
bitFlags: number;
|
|
1145
1146
|
postedSlotTail: number;
|
|
1146
1147
|
};
|
|
1147
1148
|
export type OrderParams = {
|
|
@@ -1261,6 +1262,7 @@ export interface IWallet {
|
|
|
1261
1262
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1262
1263
|
publicKey: PublicKey;
|
|
1263
1264
|
payer?: Keypair;
|
|
1265
|
+
supportedTransactionVersions?: ReadonlySet<TransactionVersion> | null | undefined;
|
|
1264
1266
|
}
|
|
1265
1267
|
export interface IVersionedWallet {
|
|
1266
1268
|
signVersionedTransaction(tx: VersionedTransaction): Promise<VersionedTransaction>;
|
package/package.json
CHANGED
package/src/decode/user.ts
CHANGED
|
@@ -239,7 +239,9 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
239
239
|
offset += 1;
|
|
240
240
|
const postedSlotTail = buffer.readUint8(offset);
|
|
241
241
|
offset += 1;
|
|
242
|
-
|
|
242
|
+
const bitFlags = buffer.readUint8(offset);
|
|
243
|
+
offset += 1;
|
|
244
|
+
offset += 1; // padding
|
|
243
245
|
orders.push({
|
|
244
246
|
slot,
|
|
245
247
|
price,
|
|
@@ -265,6 +267,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
265
267
|
immediateOrCancel,
|
|
266
268
|
triggerCondition,
|
|
267
269
|
auctionDuration,
|
|
270
|
+
bitFlags,
|
|
268
271
|
postedSlotTail,
|
|
269
272
|
});
|
|
270
273
|
}
|
package/src/driftClient.ts
CHANGED
|
@@ -278,7 +278,8 @@ export class DriftClient {
|
|
|
278
278
|
this.authority = config.authority ?? this.wallet.publicKey;
|
|
279
279
|
this.activeSubAccountId = config.activeSubAccountId ?? 0;
|
|
280
280
|
this.skipLoadUsers = config.skipLoadUsers ?? false;
|
|
281
|
-
this.txVersion =
|
|
281
|
+
this.txVersion =
|
|
282
|
+
config.txVersion ?? this.getTxVersionForNewWallet(config.wallet);
|
|
282
283
|
this.txParams = {
|
|
283
284
|
computeUnits: config.txParams?.computeUnits ?? 600_000,
|
|
284
285
|
computeUnitsPrice: config.txParams?.computeUnitsPrice ?? 0,
|
|
@@ -732,6 +733,16 @@ export class DriftClient {
|
|
|
732
733
|
return lookupTableAccounts;
|
|
733
734
|
}
|
|
734
735
|
|
|
736
|
+
private getTxVersionForNewWallet(newWallet: IWallet) {
|
|
737
|
+
if (!newWallet?.supportedTransactionVersions) return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
738
|
+
|
|
739
|
+
const walletSupportsVersionedTxns =
|
|
740
|
+
newWallet.supportedTransactionVersions?.has(0) ||
|
|
741
|
+
(newWallet.supportedTransactionVersions?.size ?? 0) > 1;
|
|
742
|
+
|
|
743
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
744
|
+
}
|
|
745
|
+
|
|
735
746
|
/**
|
|
736
747
|
* Update the wallet to use for drift transactions and linked user account
|
|
737
748
|
* @param newWallet
|
|
@@ -769,10 +780,7 @@ export class DriftClient {
|
|
|
769
780
|
this.activeSubAccountId = activeSubAccountId;
|
|
770
781
|
this.userStatsAccountPublicKey = undefined;
|
|
771
782
|
this.includeDelegates = includeDelegates ?? false;
|
|
772
|
-
|
|
773
|
-
//@ts-expect-error
|
|
774
|
-
(this.wallet.supportedTransactionVersions?.size ?? 0) > 1;
|
|
775
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
783
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
776
784
|
|
|
777
785
|
if (includeDelegates && subAccountIds) {
|
|
778
786
|
throw new Error(
|
|
@@ -842,10 +850,7 @@ export class DriftClient {
|
|
|
842
850
|
this.authority = emulateAuthority;
|
|
843
851
|
this.userStatsAccountPublicKey = undefined;
|
|
844
852
|
this.includeDelegates = true;
|
|
845
|
-
|
|
846
|
-
//@ts-ignore
|
|
847
|
-
this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
|
|
848
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
853
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
849
854
|
|
|
850
855
|
this.authoritySubAccountMap = new Map<string, number[]>();
|
|
851
856
|
|
package/src/idl/drift.json
CHANGED
|
@@ -10912,12 +10912,20 @@
|
|
|
10912
10912
|
],
|
|
10913
10913
|
"type": "u8"
|
|
10914
10914
|
},
|
|
10915
|
+
{
|
|
10916
|
+
"name": "bitFlags",
|
|
10917
|
+
"docs": [
|
|
10918
|
+
"Bitflags for further classification",
|
|
10919
|
+
"0: is_signed_message"
|
|
10920
|
+
],
|
|
10921
|
+
"type": "u8"
|
|
10922
|
+
},
|
|
10915
10923
|
{
|
|
10916
10924
|
"name": "padding",
|
|
10917
10925
|
"type": {
|
|
10918
10926
|
"array": [
|
|
10919
10927
|
"u8",
|
|
10920
|
-
|
|
10928
|
+
1
|
|
10921
10929
|
]
|
|
10922
10930
|
}
|
|
10923
10931
|
}
|
package/src/math/orders.ts
CHANGED
|
@@ -352,3 +352,8 @@ export function isRestingLimitOrder(order: Order, slot: number): boolean {
|
|
|
352
352
|
export function isTakingOrder(order: Order, slot: number): boolean {
|
|
353
353
|
return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
|
|
354
354
|
}
|
|
355
|
+
|
|
356
|
+
const FLAG_IS_SIGNED_MSG = 0x01;
|
|
357
|
+
export function isSignedMsgOrder(order: Order): boolean {
|
|
358
|
+
return (order.bitFlags & FLAG_IS_SIGNED_MSG) !== 0;
|
|
359
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Keypair,
|
|
3
3
|
PublicKey,
|
|
4
4
|
Transaction,
|
|
5
|
+
TransactionVersion,
|
|
5
6
|
VersionedTransaction,
|
|
6
7
|
} from '@solana/web3.js';
|
|
7
8
|
import { BN, ZERO } from '.';
|
|
@@ -1086,6 +1087,7 @@ export type Order = {
|
|
|
1086
1087
|
auctionStartPrice: BN;
|
|
1087
1088
|
auctionEndPrice: BN;
|
|
1088
1089
|
maxTs: BN;
|
|
1090
|
+
bitFlags: number;
|
|
1089
1091
|
postedSlotTail: number;
|
|
1090
1092
|
};
|
|
1091
1093
|
|
|
@@ -1231,6 +1233,10 @@ export interface IWallet {
|
|
|
1231
1233
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1232
1234
|
publicKey: PublicKey;
|
|
1233
1235
|
payer?: Keypair;
|
|
1236
|
+
supportedTransactionVersions?:
|
|
1237
|
+
| ReadonlySet<TransactionVersion>
|
|
1238
|
+
| null
|
|
1239
|
+
| undefined;
|
|
1234
1240
|
}
|
|
1235
1241
|
export interface IVersionedWallet {
|
|
1236
1242
|
signVersionedTransaction(
|