@drift-labs/common 1.0.18 → 1.0.20
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/lib/actions/actionHelpers/actionHelpers.d.ts +9 -9
- package/lib/common-ui-utils/commonUiUtils.d.ts +4 -1
- package/lib/common-ui-utils/commonUiUtils.js.map +1 -1
- package/lib/common-ui-utils/user.js +3 -1
- package/lib/common-ui-utils/user.js.map +1 -1
- package/lib/constants/predictionMarket.d.ts +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.d.ts +10 -10
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +4 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +2 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift/index.d.ts +5 -0
- package/lib/drift/Drift/clients/CentralServerDrift/index.js +9 -3
- package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/index.d.ts +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.d.ts +34 -0
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js +45 -0
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +8 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +8 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +8 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +6 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +5 -3
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/types.d.ts +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/types.js.map +1 -1
- package/lib/drift/base/actions/user/create.d.ts +9 -2
- package/lib/drift/base/actions/user/create.js +10 -6
- package/lib/drift/base/actions/user/create.js.map +1 -1
- package/lib/drift/base/details/user/balances.d.ts +1 -1
- package/lib/drift/base/details/user/positions.d.ts +1 -1
- package/lib/drift/cli.js +28 -6
- package/lib/drift/cli.js.map +1 -1
- package/lib/drift/utils/funding.d.ts +0 -1
- package/lib/serializableTypes.d.ts +10 -0
- package/lib/serializableTypes.js +317 -217
- package/lib/serializableTypes.js.map +1 -1
- package/lib/types/UIMarket.d.ts +2 -2
- package/lib/utils/NumLib.d.ts +4 -4
- package/lib/utils/ResultSlotIncrementer.d.ts +4 -0
- package/lib/utils/ResultSlotIncrementer.js +8 -0
- package/lib/utils/ResultSlotIncrementer.js.map +1 -1
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/math.d.ts +3 -3
- package/package.json +8 -5
package/lib/types/UIMarket.d.ts
CHANGED
|
@@ -81,8 +81,8 @@ export declare class UIMarket {
|
|
|
81
81
|
get isUsdcMarket(): boolean;
|
|
82
82
|
get isStableCoinMarket(): boolean;
|
|
83
83
|
get isPredictionMarket(): boolean;
|
|
84
|
-
get precision():
|
|
85
|
-
get precisionExp():
|
|
84
|
+
get precision(): BN;
|
|
85
|
+
get precisionExp(): BN;
|
|
86
86
|
equals(other: UIMarket): boolean;
|
|
87
87
|
baseAssetSymbol(removePrefix?: boolean): string;
|
|
88
88
|
protected setUiSymbols(): void;
|
package/lib/utils/NumLib.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNum } from '@drift-labs/sdk';
|
|
2
2
|
/**
|
|
3
3
|
* Utilities to convert numbers and BigNumbers (BN) to different formats for the UI.
|
|
4
4
|
*/
|
|
@@ -77,9 +77,9 @@ export declare class NumLib {
|
|
|
77
77
|
toDecimalPlaces: (num: number, decimalPlaces: number, noPadding?: boolean) => string;
|
|
78
78
|
};
|
|
79
79
|
static formatBn: {
|
|
80
|
-
toRawNum: (bn: BN, precision: BN, fixedAccuracity?: number) =>
|
|
81
|
-
fromQuote: (bn: BN) =>
|
|
82
|
-
fromBase: (bn: BN) =>
|
|
80
|
+
toRawNum: (bn: BN, precision: BN, fixedAccuracity?: number) => any;
|
|
81
|
+
fromQuote: (bn: BN) => any;
|
|
82
|
+
fromBase: (bn: BN) => any;
|
|
83
83
|
};
|
|
84
84
|
/**
|
|
85
85
|
* Outputs information and formatted string for UI based on its log10 value
|
|
@@ -24,6 +24,10 @@ export declare class ResultSlotIncrementer {
|
|
|
24
24
|
* Reset slot tracking for a specific key (useful when reestablishing connections)
|
|
25
25
|
*/
|
|
26
26
|
resetKey(key: string | symbol): void;
|
|
27
|
+
/**
|
|
28
|
+
* Reset all tracking (useful on full reconnection)
|
|
29
|
+
*/
|
|
30
|
+
resetAll(): void;
|
|
27
31
|
/**
|
|
28
32
|
* Configure the tab return behavior
|
|
29
33
|
*/
|
|
@@ -71,6 +71,14 @@ class ResultSlotIncrementer {
|
|
|
71
71
|
resetKey(key) {
|
|
72
72
|
this.resultIncrements.delete(key);
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Reset all tracking (useful on full reconnection)
|
|
76
|
+
*/
|
|
77
|
+
resetAll() {
|
|
78
|
+
this.resultIncrements.clear();
|
|
79
|
+
this.isInTabReturnMode = false;
|
|
80
|
+
this.tabReturnTimestamp = null;
|
|
81
|
+
}
|
|
74
82
|
/**
|
|
75
83
|
* Configure the tab return behavior
|
|
76
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResultSlotIncrementer.js","sourceRoot":"","sources":["../../src/utils/ResultSlotIncrementer.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,qBAAqB;IAAlC;QACS,qBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;QACtD,uBAAkB,GAAkB,IAAI,CAAC;QACzC,sBAAiB,GAAG,KAAK,CAAC;QAC1B,wBAAmB,GAAG,IAAI,CAAC,CAAC,oDAAoD;QAChF,yBAAoB,GAAG,GAAG,CAAC,CAAC,sEAAsE;
|
|
1
|
+
{"version":3,"file":"ResultSlotIncrementer.js","sourceRoot":"","sources":["../../src/utils/ResultSlotIncrementer.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,qBAAqB;IAAlC;QACS,qBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;QACtD,uBAAkB,GAAkB,IAAI,CAAC;QACzC,sBAAiB,GAAG,KAAK,CAAC;QAC1B,wBAAmB,GAAG,IAAI,CAAC,CAAC,oDAAoD;QAChF,yBAAoB,GAAG,GAAG,CAAC,CAAC,sEAAsE;IAuF3G,CAAC;IArFA;;OAEG;IACH,eAAe;QACd,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAE9B,qDAAqD;QACrD,UAAU,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;YAC/B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAChC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,wBAAwB,CAC/B,GAAoB,EACpB,IAAY;QAEZ,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ;YAAE,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,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAC/B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,UAAkB,EAAE,iBAAyB;QAC/D,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC;QACtC,IAAI,CAAC,oBAAoB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;CACD;AA5FD,sDA4FC","sourcesContent":["/**\n * Utility class which makes sure that all results with a slot are only accepted if the slot is higher than the previous result\n * Enhanced to handle tab return scenarios and prevent \"speed run\" through queued messages\n */\nexport class ResultSlotIncrementer {\n\tprivate resultIncrements = new Map<string | symbol, number>();\n\tprivate tabReturnTimestamp: number | null = null;\n\tprivate isInTabReturnMode = false;\n\tprivate tabReturnDebounceMs = 2000; // 2 seconds to filter old messages after tab return\n\tprivate maxSlotJumpThreshold = 100; // If slot jumps by more than this, consider it a \"speed run\" scenario\n\n\t/**\n\t * Call this when the tab returns from being inactive to enable enhanced filtering\n\t */\n\thandleTabReturn() {\n\t\tthis.tabReturnTimestamp = Date.now();\n\t\tthis.isInTabReturnMode = true;\n\n\t\t// Auto-disable tab return mode after debounce period\n\t\tsetTimeout(() => {\n\t\t\tthis.isInTabReturnMode = false;\n\t\t\tthis.tabReturnTimestamp = null;\n\t\t}, this.tabReturnDebounceMs);\n\t}\n\n\t/**\n\t * Check if we should reset state due to a large slot jump (indicating queued messages)\n\t */\n\tprivate shouldResetDueToSlotJump(\n\t\tkey: string | symbol,\n\t\tslot: number\n\t): boolean {\n\t\tconst previous = this.resultIncrements.get(key);\n\t\tif (!previous) return false;\n\n\t\tconst slotJump = slot - previous;\n\t\treturn slotJump > this.maxSlotJumpThreshold;\n\t}\n\n\t/**\n\t * Enhanced result handler that deals with tab return scenarios\n\t */\n\thandleResult(key: string | symbol, slot: number, messageTimestamp?: number) {\n\t\tif (slot === undefined) {\n\t\t\tconsole.warn('Caught undefined slot in ResultSlotIncrementer');\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're in tab return mode, be more aggressive about filtering\n\t\tif (this.isInTabReturnMode && this.tabReturnTimestamp) {\n\t\t\t// If message timestamp is available and it's older than when tab returned, skip it\n\t\t\tif (messageTimestamp && messageTimestamp < this.tabReturnTimestamp) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Check for large slot jumps that indicate queued messages\n\t\t\tif (this.shouldResetDueToSlotJump(key, slot)) {\n\t\t\t\t// Reset the previous slot to current - 1 so this message passes\n\t\t\t\t// This effectively \"jumps\" to the latest state\n\t\t\t\tthis.resultIncrements.set(key, slot - 1);\n\t\t\t}\n\t\t}\n\n\t\tconst previous = this.resultIncrements.get(key);\n\n\t\tif (!previous || slot >= previous) {\n\t\t\tthis.resultIncrements.set(key, slot);\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Reset slot tracking for a specific key (useful when reestablishing connections)\n\t */\n\tresetKey(key: string | symbol) {\n\t\tthis.resultIncrements.delete(key);\n\t}\n\n\t/**\n\t * Reset all tracking (useful on full reconnection)\n\t */\n\tresetAll() {\n\t\tthis.resultIncrements.clear();\n\t\tthis.isInTabReturnMode = false;\n\t\tthis.tabReturnTimestamp = null;\n\t}\n\n\t/**\n\t * Configure the tab return behavior\n\t */\n\tconfigureTabReturn(debounceMs: number, slotJumpThreshold: number) {\n\t\tthis.tabReturnDebounceMs = debounceMs;\n\t\tthis.maxSlotJumpThreshold = slotJumpThreshold;\n\t}\n}\n"]}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -95,8 +95,8 @@ export declare const filterTradeRecordsFromUIOrderRecords: (orderRecords: UISeri
|
|
|
95
95
|
* @param baseAmount
|
|
96
96
|
* @returns PRICE_PRECISION
|
|
97
97
|
*/
|
|
98
|
-
export declare const getPriceForBaseAndQuoteAmount: (quoteAmount: BN, baseAmount: BN) =>
|
|
99
|
-
export declare const getPriceForOrderRecord: (orderRecord: Pick<OrderActionRecord, 'quoteAssetAmountFilled' | 'baseAssetAmountFilled'>) =>
|
|
98
|
+
export declare const getPriceForBaseAndQuoteAmount: (quoteAmount: BN, baseAmount: BN) => any;
|
|
99
|
+
export declare const getPriceForOrderRecord: (orderRecord: Pick<OrderActionRecord, 'quoteAssetAmountFilled' | 'baseAssetAmountFilled'>) => any;
|
|
100
100
|
export declare const getPriceForUIOrderRecord: (orderRecord: Pick<UISerializableOrderActionRecord, 'quoteAssetAmountFilled' | 'baseAssetAmountFilled'>) => BigNum;
|
|
101
101
|
export declare const orderIsNull: (order: UISerializableOrderActionRecord | Event<OrderActionRecord>, side: 'taker' | 'maker') => boolean;
|
|
102
102
|
export declare const getAnchorEnumString: (enumVal: Record<string, unknown>) => string;
|
package/lib/utils/math.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L2OrderBook } from '@drift-labs/sdk';
|
|
2
2
|
export declare const COMMON_MATH: {
|
|
3
3
|
calculateSpreadBidAskMark: (l2: Pick<L2OrderBook, 'bids' | 'asks'>, oraclePrice?: BN) => {
|
|
4
4
|
bestBidPrice: BN;
|
|
5
5
|
bestAskPrice: BN;
|
|
6
6
|
markPrice: BN;
|
|
7
|
-
spreadPct:
|
|
8
|
-
spreadQuote:
|
|
7
|
+
spreadPct: any;
|
|
8
|
+
spreadQuote: any;
|
|
9
9
|
};
|
|
10
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Common functions for Drift",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"author": "Drift Labs",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@drift-labs/sdk": "^2.
|
|
20
|
+
"@drift-labs/sdk": "^2.155.0-beta.5",
|
|
21
21
|
"@slack/web-api": "6.4.0",
|
|
22
22
|
"@solana/spl-token": "0.3.8",
|
|
23
23
|
"@solana/web3.js": "1.98.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"winston-slack-webhook-transport": "2.3.5"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@drift-labs/sdk": "^2.
|
|
38
|
+
"@drift-labs/sdk": "^2.155.0-beta.6",
|
|
39
39
|
"@solana/web3.js": "1.98.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
"update-jup-errors": "node src/scripts/update-jup-error-codes.js",
|
|
56
56
|
"update-drift-errors": "node src/scripts/update-drift-error-codes.js",
|
|
57
57
|
"circular-deps": "bunx madge --circular --circular --extensions ts,tsx src",
|
|
58
|
-
"build-and-pack": "bun run build && npm pack"
|
|
58
|
+
"build-and-pack": "bun run build && npm pack",
|
|
59
|
+
"update-sdk": "node scripts/update-sdk.js"
|
|
59
60
|
},
|
|
60
61
|
"directories": {
|
|
61
62
|
"lib": "lib"
|
|
@@ -96,6 +97,8 @@
|
|
|
96
97
|
"access": "public"
|
|
97
98
|
},
|
|
98
99
|
"resolutions": {
|
|
99
|
-
"@solana/
|
|
100
|
+
"@solana/web3.js": "1.98.0",
|
|
101
|
+
"@solana/errors": "2.0.0-preview.4",
|
|
102
|
+
"@solana/codecs-data-structures": "2.0.0-preview.4"
|
|
100
103
|
}
|
|
101
104
|
}
|