@drift-labs/sdk 2.53.0-beta.1 → 2.53.0-beta.3
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/dlob/DLOB.d.ts +2 -2
- package/lib/dlob/DLOB.js +10 -6
- package/lib/tx/fastSingleTxSender.d.ts +2 -1
- package/lib/tx/fastSingleTxSender.js +17 -4
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +16 -10
- package/src/tx/fastSingleTxSender.ts +18 -7
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.53.0-beta.
|
|
1
|
+
2.53.0-beta.3
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -91,8 +91,8 @@ export declare class DLOB {
|
|
|
91
91
|
takerNode: DLOBNode;
|
|
92
92
|
makerNode: DLOBNode;
|
|
93
93
|
} | undefined;
|
|
94
|
-
getBestAsk(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
95
|
-
getBestBid(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
94
|
+
getBestAsk(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN | undefined;
|
|
95
|
+
getBestBid(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN | undefined;
|
|
96
96
|
getStopLosses(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
|
97
97
|
getStopLossMarkets(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
|
98
98
|
getStopLossLimits(marketIndex: number, marketType: MarketType, direction: PositionDirection): Generator<DLOBNode>;
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -822,14 +822,18 @@ class DLOB {
|
|
|
822
822
|
}
|
|
823
823
|
}
|
|
824
824
|
getBestAsk(marketIndex, slot, marketType, oraclePriceData) {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
.
|
|
825
|
+
const bestAsk = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
826
|
+
if (bestAsk) {
|
|
827
|
+
return bestAsk.getPrice(oraclePriceData, slot);
|
|
828
|
+
}
|
|
829
|
+
return undefined;
|
|
828
830
|
}
|
|
829
831
|
getBestBid(marketIndex, slot, marketType, oraclePriceData) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
.
|
|
832
|
+
const bestBid = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
833
|
+
if (bestBid) {
|
|
834
|
+
return bestBid.getPrice(oraclePriceData, slot);
|
|
835
|
+
}
|
|
836
|
+
return undefined;
|
|
833
837
|
}
|
|
834
838
|
*getStopLosses(marketIndex, marketType, direction) {
|
|
835
839
|
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
@@ -11,7 +11,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
|
|
|
11
11
|
blockhashRefreshInterval: number;
|
|
12
12
|
additionalConnections: Connection[];
|
|
13
13
|
timoutCount: number;
|
|
14
|
-
|
|
14
|
+
blockhashQueue: string[];
|
|
15
15
|
constructor({ connection, wallet, opts, timeout, blockhashRefreshInterval, additionalConnections, }: {
|
|
16
16
|
connection: Connection;
|
|
17
17
|
wallet: IWallet;
|
|
@@ -21,6 +21,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
|
|
|
21
21
|
additionalConnections?: any;
|
|
22
22
|
});
|
|
23
23
|
startBlockhashRefreshLoop(): void;
|
|
24
|
+
addBlockhashToQueue(blockhash: string): void;
|
|
24
25
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
25
26
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
26
27
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
@@ -5,11 +5,13 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
5
5
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
6
|
const baseTxSender_1 = require("./baseTxSender");
|
|
7
7
|
const DEFAULT_TIMEOUT = 35000;
|
|
8
|
-
const DEFAULT_BLOCKHASH_REFRESH =
|
|
8
|
+
const DEFAULT_BLOCKHASH_REFRESH = 500;
|
|
9
|
+
const MAX_BLOCKHASH_QUEUE_LENGTH = 100;
|
|
9
10
|
class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
10
11
|
constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), }) {
|
|
11
12
|
super({ connection, wallet, opts, timeout, additionalConnections });
|
|
12
13
|
this.timoutCount = 0;
|
|
14
|
+
this.blockhashQueue = [];
|
|
13
15
|
this.connection = connection;
|
|
14
16
|
this.wallet = wallet;
|
|
15
17
|
this.opts = opts;
|
|
@@ -21,18 +23,29 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
21
23
|
startBlockhashRefreshLoop() {
|
|
22
24
|
setInterval(async () => {
|
|
23
25
|
try {
|
|
24
|
-
|
|
26
|
+
const blockhash = (await this.connection.getLatestBlockhash(this.opts))
|
|
27
|
+
.blockhash;
|
|
28
|
+
this.addBlockhashToQueue(blockhash);
|
|
25
29
|
}
|
|
26
30
|
catch (e) {
|
|
27
31
|
console.error('Error in startBlockhashRefreshLoop: ', e);
|
|
28
32
|
}
|
|
29
33
|
}, this.blockhashRefreshInterval);
|
|
30
34
|
}
|
|
35
|
+
addBlockhashToQueue(blockhash) {
|
|
36
|
+
if (blockhash !== this.blockhashQueue[0]) {
|
|
37
|
+
this.blockhashQueue.push(blockhash);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (this.blockhashQueue.length > MAX_BLOCKHASH_QUEUE_LENGTH) {
|
|
41
|
+
this.blockhashQueue.shift();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
31
44
|
async prepareTx(tx, additionalSigners, opts) {
|
|
32
45
|
var _a;
|
|
33
46
|
tx.feePayer = this.wallet.publicKey;
|
|
34
47
|
tx.recentBlockhash =
|
|
35
|
-
(_a = this.
|
|
48
|
+
(_a = this.blockhashQueue.shift()) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
36
49
|
.blockhash;
|
|
37
50
|
additionalSigners
|
|
38
51
|
.filter((s) => s !== undefined)
|
|
@@ -52,7 +65,7 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
52
65
|
}
|
|
53
66
|
const message = new web3_js_1.TransactionMessage({
|
|
54
67
|
payerKey: this.wallet.publicKey,
|
|
55
|
-
recentBlockhash: (_a = this.
|
|
68
|
+
recentBlockhash: (_a = this.blockhashQueue.shift()) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
56
69
|
.blockhash,
|
|
57
70
|
instructions: ixs,
|
|
58
71
|
}).compileToV0Message(lookupTableAccounts);
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -1472,15 +1472,18 @@ export class DLOB {
|
|
|
1472
1472
|
slot: number,
|
|
1473
1473
|
marketType: MarketType,
|
|
1474
1474
|
oraclePriceData: OraclePriceData
|
|
1475
|
-
): BN {
|
|
1476
|
-
|
|
1475
|
+
): BN | undefined {
|
|
1476
|
+
const bestAsk = this.getRestingLimitAsks(
|
|
1477
1477
|
marketIndex,
|
|
1478
1478
|
slot,
|
|
1479
1479
|
marketType,
|
|
1480
1480
|
oraclePriceData
|
|
1481
|
-
)
|
|
1482
|
-
|
|
1483
|
-
|
|
1481
|
+
).next().value;
|
|
1482
|
+
|
|
1483
|
+
if (bestAsk) {
|
|
1484
|
+
return bestAsk.getPrice(oraclePriceData, slot);
|
|
1485
|
+
}
|
|
1486
|
+
return undefined;
|
|
1484
1487
|
}
|
|
1485
1488
|
|
|
1486
1489
|
public getBestBid(
|
|
@@ -1488,15 +1491,18 @@ export class DLOB {
|
|
|
1488
1491
|
slot: number,
|
|
1489
1492
|
marketType: MarketType,
|
|
1490
1493
|
oraclePriceData: OraclePriceData
|
|
1491
|
-
): BN {
|
|
1492
|
-
|
|
1494
|
+
): BN | undefined {
|
|
1495
|
+
const bestBid = this.getRestingLimitBids(
|
|
1493
1496
|
marketIndex,
|
|
1494
1497
|
slot,
|
|
1495
1498
|
marketType,
|
|
1496
1499
|
oraclePriceData
|
|
1497
|
-
)
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
+
).next().value;
|
|
1501
|
+
|
|
1502
|
+
if (bestBid) {
|
|
1503
|
+
return bestBid.getPrice(oraclePriceData, slot);
|
|
1504
|
+
}
|
|
1505
|
+
return undefined;
|
|
1500
1506
|
}
|
|
1501
1507
|
|
|
1502
1508
|
public *getStopLosses(
|
|
@@ -15,7 +15,8 @@ import { IWallet } from '../types';
|
|
|
15
15
|
import { BaseTxSender } from './baseTxSender';
|
|
16
16
|
|
|
17
17
|
const DEFAULT_TIMEOUT = 35000;
|
|
18
|
-
const DEFAULT_BLOCKHASH_REFRESH =
|
|
18
|
+
const DEFAULT_BLOCKHASH_REFRESH = 500;
|
|
19
|
+
const MAX_BLOCKHASH_QUEUE_LENGTH = 100;
|
|
19
20
|
|
|
20
21
|
export class FastSingleTxSender extends BaseTxSender {
|
|
21
22
|
connection: Connection;
|
|
@@ -25,7 +26,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
25
26
|
blockhashRefreshInterval: number;
|
|
26
27
|
additionalConnections: Connection[];
|
|
27
28
|
timoutCount = 0;
|
|
28
|
-
|
|
29
|
+
blockhashQueue: string[] = [];
|
|
29
30
|
|
|
30
31
|
public constructor({
|
|
31
32
|
connection,
|
|
@@ -55,15 +56,25 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
55
56
|
startBlockhashRefreshLoop(): void {
|
|
56
57
|
setInterval(async () => {
|
|
57
58
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const blockhash = (await this.connection.getLatestBlockhash(this.opts))
|
|
60
|
+
.blockhash;
|
|
61
|
+
this.addBlockhashToQueue(blockhash);
|
|
61
62
|
} catch (e) {
|
|
62
63
|
console.error('Error in startBlockhashRefreshLoop: ', e);
|
|
63
64
|
}
|
|
64
65
|
}, this.blockhashRefreshInterval);
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
addBlockhashToQueue(blockhash: string): void {
|
|
69
|
+
if (blockhash !== this.blockhashQueue[0]) {
|
|
70
|
+
this.blockhashQueue.push(blockhash);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (this.blockhashQueue.length > MAX_BLOCKHASH_QUEUE_LENGTH) {
|
|
74
|
+
this.blockhashQueue.shift();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
async prepareTx(
|
|
68
79
|
tx: Transaction,
|
|
69
80
|
additionalSigners: Array<Signer>,
|
|
@@ -72,7 +83,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
72
83
|
tx.feePayer = this.wallet.publicKey;
|
|
73
84
|
|
|
74
85
|
tx.recentBlockhash =
|
|
75
|
-
this.
|
|
86
|
+
this.blockhashQueue.shift() ??
|
|
76
87
|
(await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
77
88
|
.blockhash;
|
|
78
89
|
|
|
@@ -103,7 +114,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
103
114
|
const message = new TransactionMessage({
|
|
104
115
|
payerKey: this.wallet.publicKey,
|
|
105
116
|
recentBlockhash:
|
|
106
|
-
this.
|
|
117
|
+
this.blockhashQueue.shift() ??
|
|
107
118
|
(await this.connection.getLatestBlockhash(opts.preflightCommitment))
|
|
108
119
|
.blockhash,
|
|
109
120
|
instructions: ixs,
|