@drift-labs/sdk 2.74.0-beta.3 → 2.74.0-beta.5
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/blockhashSubscriber/BlockhashSubscriber.d.ts +3 -1
- package/lib/blockhashSubscriber/BlockhashSubscriber.js +4 -0
- package/lib/dlob/orderBookLevels.js +6 -0
- package/package.json +1 -1
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +7 -0
- package/src/dlob/orderBookLevels.ts +6 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.74.0-beta.
|
|
1
|
+
2.74.0-beta.5
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
1
|
+
import { BlockhashWithExpiryBlockHeight, Context } from '@solana/web3.js';
|
|
2
2
|
import { BlockhashSubscriberConfig } from './types';
|
|
3
3
|
export declare class BlockhashSubscriber {
|
|
4
4
|
private connection;
|
|
5
5
|
private isSubscribed;
|
|
6
6
|
private latestBlockHeight;
|
|
7
|
+
private latestBlockHeightContext;
|
|
7
8
|
private blockhashes;
|
|
8
9
|
private updateBlockhashIntervalId;
|
|
9
10
|
private commitment;
|
|
@@ -11,6 +12,7 @@ export declare class BlockhashSubscriber {
|
|
|
11
12
|
constructor(config: BlockhashSubscriberConfig);
|
|
12
13
|
getBlockhashCacheSize(): number;
|
|
13
14
|
getLatestBlockHeight(): number;
|
|
15
|
+
getLatestBlockHeightContext(): Context | undefined;
|
|
14
16
|
getLatestBlockhash(offset?: number): BlockhashWithExpiryBlockHeight | undefined;
|
|
15
17
|
pruneBlockhashes(): void;
|
|
16
18
|
updateBlockhash(): Promise<void>;
|
|
@@ -20,6 +20,9 @@ class BlockhashSubscriber {
|
|
|
20
20
|
getLatestBlockHeight() {
|
|
21
21
|
return this.latestBlockHeight;
|
|
22
22
|
}
|
|
23
|
+
getLatestBlockHeightContext() {
|
|
24
|
+
return this.latestBlockHeightContext;
|
|
25
|
+
}
|
|
23
26
|
getLatestBlockhash(offset) {
|
|
24
27
|
if (this.blockhashes.length === 0) {
|
|
25
28
|
return undefined;
|
|
@@ -40,6 +43,7 @@ class BlockhashSubscriber {
|
|
|
40
43
|
this.connection.getBlockHeight({ commitment: this.commitment }),
|
|
41
44
|
]);
|
|
42
45
|
this.latestBlockHeight = lastConfirmedBlockHeight;
|
|
46
|
+
this.latestBlockHeightContext = resp.context;
|
|
43
47
|
// avoid caching duplicate blockhashes
|
|
44
48
|
if (this.blockhashes.length > 0) {
|
|
45
49
|
if (resp.value.blockhash ===
|
|
@@ -122,6 +122,9 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
|
|
|
122
122
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
123
123
|
(0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'quote', quoteSwapped, __1.SwapDirection.REMOVE);
|
|
124
124
|
baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
125
|
+
if (baseSwapped.eq(__1.ZERO)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
125
128
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
126
129
|
baseSwapped = remainingBaseLiquidity;
|
|
127
130
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
@@ -170,6 +173,9 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
|
|
|
170
173
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
171
174
|
(0, __1.calculateAmmReservesAfterSwap)(askAmm, 'quote', quoteSwapped, __1.SwapDirection.ADD);
|
|
172
175
|
baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
176
|
+
if (baseSwapped.eq(__1.ZERO)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
173
179
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
174
180
|
baseSwapped = remainingBaseLiquidity;
|
|
175
181
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BlockhashWithExpiryBlockHeight,
|
|
3
3
|
Commitment,
|
|
4
4
|
Connection,
|
|
5
|
+
Context,
|
|
5
6
|
} from '@solana/web3.js';
|
|
6
7
|
import { BlockhashSubscriberConfig } from './types';
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ export class BlockhashSubscriber {
|
|
|
9
10
|
private connection: Connection;
|
|
10
11
|
private isSubscribed = false;
|
|
11
12
|
private latestBlockHeight: number;
|
|
13
|
+
private latestBlockHeightContext: Context | undefined;
|
|
12
14
|
private blockhashes: Array<BlockhashWithExpiryBlockHeight> = [];
|
|
13
15
|
private updateBlockhashIntervalId: NodeJS.Timeout | undefined;
|
|
14
16
|
private commitment: Commitment;
|
|
@@ -33,6 +35,10 @@ export class BlockhashSubscriber {
|
|
|
33
35
|
return this.latestBlockHeight;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
getLatestBlockHeightContext(): Context | undefined {
|
|
39
|
+
return this.latestBlockHeightContext;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
getLatestBlockhash(
|
|
37
43
|
offset?: number
|
|
38
44
|
): BlockhashWithExpiryBlockHeight | undefined {
|
|
@@ -63,6 +69,7 @@ export class BlockhashSubscriber {
|
|
|
63
69
|
this.connection.getBlockHeight({ commitment: this.commitment }),
|
|
64
70
|
]);
|
|
65
71
|
this.latestBlockHeight = lastConfirmedBlockHeight;
|
|
72
|
+
this.latestBlockHeightContext = resp.context;
|
|
66
73
|
|
|
67
74
|
// avoid caching duplicate blockhashes
|
|
68
75
|
if (this.blockhashes.length > 0) {
|
|
@@ -219,6 +219,9 @@ export function getVammL2Generator({
|
|
|
219
219
|
);
|
|
220
220
|
|
|
221
221
|
baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
222
|
+
if (baseSwapped.eq(ZERO)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
222
225
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
223
226
|
baseSwapped = remainingBaseLiquidity;
|
|
224
227
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
@@ -299,6 +302,9 @@ export function getVammL2Generator({
|
|
|
299
302
|
);
|
|
300
303
|
|
|
301
304
|
baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
305
|
+
if (baseSwapped.eq(ZERO)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
302
308
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
303
309
|
baseSwapped = remainingBaseLiquidity;
|
|
304
310
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|