@drift-labs/sdk-browser 2.115.0-beta.16 → 2.115.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/browser/constants/perpMarkets.js +10 -14
- package/lib/browser/constants/spotMarkets.js +4 -6
- package/lib/browser/dlob/DLOB.d.ts +3 -3
- package/lib/browser/dlob/DLOB.js +5 -8
- package/lib/browser/dlob/DLOBNode.d.ts +5 -5
- package/lib/browser/dlob/DLOBNode.js +13 -12
- package/lib/browser/dlob/DLOBSubscriber.d.ts +1 -2
- package/lib/browser/dlob/DLOBSubscriber.js +2 -8
- package/lib/browser/dlob/NodeList.d.ts +2 -2
- package/lib/browser/dlob/NodeList.js +2 -2
- package/lib/browser/dlob/types.d.ts +1 -6
- package/lib/browser/driftClient.d.ts +7 -7
- package/lib/browser/driftClient.js +22 -25
- package/lib/browser/fastlane/fastlaneOrderSubscriber.d.ts +33 -0
- package/lib/browser/fastlane/fastlaneOrderSubscriber.js +137 -0
- package/lib/browser/fastlane/grpcSignedMsgUserAccountSubscriber.d.ts +22 -0
- package/lib/browser/fastlane/grpcSignedMsgUserAccountSubscriber.js +57 -0
- package/lib/browser/fastlane/index.d.ts +3 -0
- package/lib/browser/fastlane/index.js +19 -0
- package/lib/browser/fastlane/signedMsgUserAccountSubscriber.d.ts +43 -0
- package/lib/browser/fastlane/signedMsgUserAccountSubscriber.js +116 -0
- package/lib/browser/idl/drift.json +2 -72
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/math/orders.d.ts +2 -3
- package/lib/browser/math/orders.js +10 -22
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +0 -2
- package/lib/browser/openbook/openbookV2Subscriber.js +6 -16
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +2 -3
- package/lib/browser/orderSubscriber/OrderSubscriber.js +4 -4
- package/lib/browser/phoenix/phoenixSubscriber.d.ts +0 -2
- package/lib/browser/phoenix/phoenixSubscriber.js +10 -19
- package/lib/browser/swift/swiftOrderSubscriber.js +0 -16
- package/lib/browser/types.d.ts +1 -16
- package/lib/browser/userMap/userMap.d.ts +2 -2
- package/lib/browser/userMap/userMap.js +2 -2
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +10 -14
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constants/spotMarkets.js +4 -6
- package/lib/node/dlob/DLOB.d.ts +3 -3
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +5 -8
- package/lib/node/dlob/DLOBNode.d.ts +5 -5
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.js +13 -12
- package/lib/node/dlob/DLOBSubscriber.d.ts +1 -2
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +2 -8
- package/lib/node/dlob/NodeList.d.ts +2 -2
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.js +2 -2
- package/lib/node/dlob/types.d.ts +1 -6
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/driftClient.d.ts +7 -7
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +22 -25
- package/lib/node/fastlane/fastlaneOrderSubscriber.d.ts +34 -0
- package/lib/node/fastlane/fastlaneOrderSubscriber.d.ts.map +1 -0
- package/lib/node/fastlane/fastlaneOrderSubscriber.js +137 -0
- package/lib/node/fastlane/grpcSignedMsgUserAccountSubscriber.d.ts +23 -0
- package/lib/node/fastlane/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -0
- package/lib/node/fastlane/grpcSignedMsgUserAccountSubscriber.js +57 -0
- package/lib/node/fastlane/index.d.ts +4 -0
- package/lib/node/fastlane/index.d.ts.map +1 -0
- package/lib/node/fastlane/index.js +19 -0
- package/lib/node/fastlane/signedMsgUserAccountSubscriber.d.ts +44 -0
- package/lib/node/fastlane/signedMsgUserAccountSubscriber.d.ts.map +1 -0
- package/lib/node/fastlane/signedMsgUserAccountSubscriber.js +116 -0
- package/lib/node/idl/drift.json +2 -72
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/math/orders.d.ts +2 -3
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +10 -22
- package/lib/node/openbook/openbookV2Subscriber.d.ts +0 -2
- package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
- package/lib/node/openbook/openbookV2Subscriber.js +6 -16
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +2 -3
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +4 -4
- package/lib/node/phoenix/phoenixSubscriber.d.ts +0 -2
- package/lib/node/phoenix/phoenixSubscriber.d.ts.map +1 -1
- package/lib/node/phoenix/phoenixSubscriber.js +10 -19
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +0 -16
- package/lib/node/types.d.ts +1 -16
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/userMap/userMap.d.ts +2 -2
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +2 -2
- package/package.json +1 -1
- package/src/constants/perpMarkets.ts +10 -14
- package/src/constants/spotMarkets.ts +4 -6
- package/src/dlob/DLOB.ts +6 -14
- package/src/dlob/DLOBNode.ts +15 -25
- package/src/dlob/DLOBSubscriber.ts +2 -10
- package/src/dlob/NodeList.ts +3 -3
- package/src/dlob/types.ts +1 -10
- package/src/driftClient.ts +24 -53
- package/src/fastlane/fastlaneOrderSubscriber.ts +230 -0
- package/src/fastlane/grpcSignedMsgUserAccountSubscriber.ts +95 -0
- package/src/fastlane/index.ts +3 -0
- package/src/fastlane/signedMsgUserAccountSubscriber.ts +234 -0
- package/src/idl/drift.json +2 -72
- package/src/index.ts +1 -0
- package/src/math/orders.ts +9 -39
- package/src/openbook/openbookV2Subscriber.ts +10 -20
- package/src/orderSubscriber/OrderSubscriber.ts +5 -5
- package/src/phoenix/phoenixSubscriber.ts +16 -28
- package/src/swift/swiftOrderSubscriber.ts +0 -22
- package/src/types.ts +1 -18
- package/src/userMap/userMap.ts +2 -3
- package/tests/dlob/helpers.ts +0 -6
- package/tests/dlob/test.ts +0 -4
- package/lib/browser/math/protectedMakerParams.d.ts +0 -4
- package/lib/browser/math/protectedMakerParams.js +0 -32
- package/lib/node/math/protectedMakerParams.d.ts +0 -5
- package/lib/node/math/protectedMakerParams.d.ts.map +0 -1
- package/lib/node/math/protectedMakerParams.js +0 -32
- package/src/math/protectedMakerParams.ts +0 -37
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.115.0-beta.
|
|
1
|
+
2.115.0-beta.3
|
|
@@ -58,9 +58,9 @@ exports.DevnetPerpMarkets = [
|
|
|
58
58
|
symbol: '1MBONK-PERP',
|
|
59
59
|
baseAssetSymbol: '1MBONK',
|
|
60
60
|
marketIndex: 4,
|
|
61
|
-
oracle: new web3_js_1.PublicKey('
|
|
61
|
+
oracle: new web3_js_1.PublicKey('GojbSnJuPdKDT1ZuHuAM5t9oz6bxTo1xhUKpTua2F72p'),
|
|
62
62
|
launchTs: 1677068931000,
|
|
63
|
-
oracleSource: __1.OracleSource.
|
|
63
|
+
oracleSource: __1.OracleSource.PYTH_1M_PULL,
|
|
64
64
|
pythFeedId: '0x72b021217ca3fe68922a19aaf990109cb9d84e9ad004b4d2025ad6f529314419',
|
|
65
65
|
pythLazerId: 9,
|
|
66
66
|
},
|
|
@@ -708,11 +708,10 @@ exports.MainnetPerpMarkets = [
|
|
|
708
708
|
symbol: 'DRIFT-PERP',
|
|
709
709
|
baseAssetSymbol: 'DRIFT',
|
|
710
710
|
marketIndex: 30,
|
|
711
|
-
oracle: new web3_js_1.PublicKey('
|
|
711
|
+
oracle: new web3_js_1.PublicKey('23KmX7SNikmUr2axSCy6Zer7XPBnvmVcASALnDGqBVRR'),
|
|
712
712
|
launchTs: 1716595200000,
|
|
713
|
-
oracleSource: __1.OracleSource.
|
|
713
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
714
714
|
pythFeedId: '0x5c1690b27bb02446db17cdda13ccc2c1d609ad6d2ef5bf4983a85ea8b6f19d07',
|
|
715
|
-
pythLazerId: 249,
|
|
716
715
|
},
|
|
717
716
|
{
|
|
718
717
|
fullName: 'Sanctum',
|
|
@@ -1104,11 +1103,10 @@ exports.MainnetPerpMarkets = [
|
|
|
1104
1103
|
symbol: 'BERA-PERP',
|
|
1105
1104
|
baseAssetSymbol: 'BERA',
|
|
1106
1105
|
marketIndex: 66,
|
|
1107
|
-
oracle: new web3_js_1.PublicKey('
|
|
1106
|
+
oracle: new web3_js_1.PublicKey('53Ae7ArP9yCnjqL2CqxJ1zdv3ba64NoVTqRcwjrCg181'),
|
|
1108
1107
|
launchTs: 1738850177000,
|
|
1109
|
-
oracleSource: __1.OracleSource.
|
|
1108
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
1110
1109
|
pythFeedId: '0x962088abcfdbdb6e30db2e340c8cf887d9efb311b1f2f17b155a63dbb6d40265',
|
|
1111
|
-
pythLazerId: 308,
|
|
1112
1110
|
},
|
|
1113
1111
|
{
|
|
1114
1112
|
fullName: 'NBAFINALS25-OKC',
|
|
@@ -1136,11 +1134,10 @@ exports.MainnetPerpMarkets = [
|
|
|
1136
1134
|
symbol: 'KAITO-PERP',
|
|
1137
1135
|
baseAssetSymbol: 'KAITO',
|
|
1138
1136
|
marketIndex: 69,
|
|
1139
|
-
oracle: new web3_js_1.PublicKey('
|
|
1137
|
+
oracle: new web3_js_1.PublicKey('DRCNnwxET1URxGMvpCPncBkZsWf1Xh26TMxXNSGTrGpU'),
|
|
1140
1138
|
launchTs: 1739545901000,
|
|
1141
|
-
oracleSource: __1.OracleSource.
|
|
1139
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
1142
1140
|
pythFeedId: '0x7302dee641a08507c297a7b0c8b3efa74a48a3baa6c040acab1e5209692b7e59',
|
|
1143
|
-
pythLazerId: 306,
|
|
1144
1141
|
},
|
|
1145
1142
|
{
|
|
1146
1143
|
fullName: 'Story Protocol',
|
|
@@ -1148,11 +1145,10 @@ exports.MainnetPerpMarkets = [
|
|
|
1148
1145
|
symbol: 'IP-PERP',
|
|
1149
1146
|
baseAssetSymbol: 'IP',
|
|
1150
1147
|
marketIndex: 70,
|
|
1151
|
-
oracle: new web3_js_1.PublicKey('
|
|
1148
|
+
oracle: new web3_js_1.PublicKey('E8A2iky96tzM8YuNNcJateE8S4e5N8FYspg17XHLp2aY'),
|
|
1152
1149
|
launchTs: 1740150623000,
|
|
1153
|
-
oracleSource: __1.OracleSource.
|
|
1150
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
1154
1151
|
pythFeedId: '0xb620ba83044577029da7e4ded7a2abccf8e6afc2a0d4d26d89ccdd39ec109025',
|
|
1155
|
-
pythLazerId: 309,
|
|
1156
1152
|
},
|
|
1157
1153
|
];
|
|
1158
1154
|
exports.PerpMarkets = {
|
|
@@ -300,15 +300,14 @@ exports.MainnetSpotMarkets = [
|
|
|
300
300
|
symbol: 'DRIFT',
|
|
301
301
|
marketIndex: 15,
|
|
302
302
|
poolId: 0,
|
|
303
|
-
oracle: new web3_js_1.PublicKey('
|
|
304
|
-
oracleSource: __1.OracleSource.
|
|
303
|
+
oracle: new web3_js_1.PublicKey('23KmX7SNikmUr2axSCy6Zer7XPBnvmVcASALnDGqBVRR'),
|
|
304
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
305
305
|
mint: new web3_js_1.PublicKey('DriFtupJYLTosbwoN8koMbEYSx54aFAVLddWsbksjwg7'),
|
|
306
306
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
307
307
|
precisionExp: numericConstants_1.SIX,
|
|
308
308
|
phoenixMarket: new web3_js_1.PublicKey('8BV6rrWsUabnTDA3dE6A69oUDJAj3hMhtBHTJyXB7czp'),
|
|
309
309
|
launchTs: 1715860800000,
|
|
310
310
|
pythFeedId: '0x5c1690b27bb02446db17cdda13ccc2c1d609ad6d2ef5bf4983a85ea8b6f19d07',
|
|
311
|
-
pythLazerId: 249,
|
|
312
311
|
},
|
|
313
312
|
{
|
|
314
313
|
symbol: 'INF',
|
|
@@ -338,14 +337,13 @@ exports.MainnetSpotMarkets = [
|
|
|
338
337
|
symbol: 'USDY',
|
|
339
338
|
marketIndex: 18,
|
|
340
339
|
poolId: 0,
|
|
341
|
-
oracle: new web3_js_1.PublicKey('
|
|
342
|
-
oracleSource: __1.OracleSource.
|
|
340
|
+
oracle: new web3_js_1.PublicKey('BPTQgHV4y2x4jvKPPkkd9aS8jY7L3DGZBwjEZC8Vm27o'),
|
|
341
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
343
342
|
mint: new web3_js_1.PublicKey('A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6'),
|
|
344
343
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
345
344
|
precisionExp: numericConstants_1.SIX,
|
|
346
345
|
launchTs: 1718811089000,
|
|
347
346
|
pythFeedId: '0xe393449f6aff8a4b6d3e1165a7c9ebec103685f3b41e60db4277b5b6d10e7326',
|
|
348
|
-
pythLazerId: 276,
|
|
349
347
|
},
|
|
350
348
|
{
|
|
351
349
|
symbol: 'JLP',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { NodeList } from './NodeList';
|
|
3
|
-
import { BN, DLOBNode, DLOBNodeType, DriftClient, MarketType, MarketTypeStr, OraclePriceData, Order, PerpMarketAccount, PositionDirection,
|
|
3
|
+
import { BN, DLOBNode, DLOBNodeType, DriftClient, MarketType, MarketTypeStr, OraclePriceData, Order, PerpMarketAccount, PositionDirection, SlotSubscriber, SpotMarketAccount, StateAccount, TriggerOrderNode, UserMap } from '..';
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { L2OrderBook, L2OrderBookGenerator, L3OrderBook } from './orderBookLevels';
|
|
6
6
|
export type DLOBOrder = {
|
|
@@ -58,8 +58,8 @@ export declare class DLOB {
|
|
|
58
58
|
orderLists: Map<MarketTypeStr, Map<number, MarketNodeLists>>;
|
|
59
59
|
maxSlotForRestingLimitOrders: number;
|
|
60
60
|
initialized: boolean;
|
|
61
|
-
|
|
62
|
-
constructor(
|
|
61
|
+
protectedMakerView: boolean;
|
|
62
|
+
constructor(protectedMakerView?: boolean);
|
|
63
63
|
private init;
|
|
64
64
|
clear(): void;
|
|
65
65
|
/**
|
package/lib/browser/dlob/DLOB.js
CHANGED
|
@@ -14,15 +14,12 @@ const SUPPORTED_ORDER_TYPES = [
|
|
|
14
14
|
'oracle',
|
|
15
15
|
];
|
|
16
16
|
class DLOB {
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(protectedMakerView) {
|
|
18
18
|
this.openOrders = new Map();
|
|
19
19
|
this.orderLists = new Map();
|
|
20
20
|
this.maxSlotForRestingLimitOrders = 0;
|
|
21
21
|
this.initialized = false;
|
|
22
|
-
this.
|
|
23
|
-
perp: new Map(),
|
|
24
|
-
spot: new Map(),
|
|
25
|
-
};
|
|
22
|
+
this.protectedMakerView = protectedMakerView || false;
|
|
26
23
|
this.init();
|
|
27
24
|
}
|
|
28
25
|
init() {
|
|
@@ -91,7 +88,7 @@ class DLOB {
|
|
|
91
88
|
.get(marketType)
|
|
92
89
|
.add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
93
90
|
}
|
|
94
|
-
(_a = this.getListForOnChainOrder(order, slot, isUserProtectedMaker)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, isUserProtectedMaker, this.
|
|
91
|
+
(_a = this.getListForOnChainOrder(order, slot, isUserProtectedMaker)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerView);
|
|
95
92
|
if (onInsert) {
|
|
96
93
|
onInsert();
|
|
97
94
|
}
|
|
@@ -109,7 +106,7 @@ class DLOB {
|
|
|
109
106
|
this.orderLists
|
|
110
107
|
.get(marketType)
|
|
111
108
|
.get(marketIndex)
|
|
112
|
-
.signedMsg[bidOrAsk].insert(order, marketType, userAccount, isUserProtectedMaker, this.
|
|
109
|
+
.signedMsg[bidOrAsk].insert(order, marketType, userAccount, isUserProtectedMaker, this.protectedMakerView);
|
|
113
110
|
if (onInsert) {
|
|
114
111
|
onInsert();
|
|
115
112
|
}
|
|
@@ -218,7 +215,7 @@ class DLOB {
|
|
|
218
215
|
for (const nodeToUpdate of nodesToUpdate) {
|
|
219
216
|
const { side, node } = nodeToUpdate;
|
|
220
217
|
nodeLists.takingLimit[side].remove(node.order, node.userAccount);
|
|
221
|
-
nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount, node.isProtectedMaker, this.
|
|
218
|
+
nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount, node.isProtectedMaker, this.protectedMakerView);
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
221
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { BN, OraclePriceData, Order
|
|
2
|
+
import { BN, OraclePriceData, Order } from '..';
|
|
3
3
|
export interface DLOBNode {
|
|
4
4
|
getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
|
|
5
5
|
isVammNode(): boolean;
|
|
@@ -8,7 +8,7 @@ export interface DLOBNode {
|
|
|
8
8
|
haveFilled: boolean;
|
|
9
9
|
userAccount: string | undefined;
|
|
10
10
|
isProtectedMaker: boolean;
|
|
11
|
-
|
|
11
|
+
applyProtectedMakerOffset: boolean;
|
|
12
12
|
isSignedMsg: boolean | undefined;
|
|
13
13
|
}
|
|
14
14
|
export declare abstract class OrderNode implements DLOBNode {
|
|
@@ -18,9 +18,9 @@ export declare abstract class OrderNode implements DLOBNode {
|
|
|
18
18
|
haveFilled: boolean;
|
|
19
19
|
haveTrigger: boolean;
|
|
20
20
|
isProtectedMaker: boolean;
|
|
21
|
-
|
|
21
|
+
applyProtectedMakerOffset: boolean;
|
|
22
22
|
isSignedMsg: boolean;
|
|
23
|
-
constructor(order: Order, userAccount: string, isProtectedMaker: boolean,
|
|
23
|
+
constructor(order: Order, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean, isSignedMsg?: boolean);
|
|
24
24
|
abstract getSortValue(order: Order): BN;
|
|
25
25
|
getLabel(): string;
|
|
26
26
|
getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
|
|
@@ -68,4 +68,4 @@ export type DLOBNodeMap = {
|
|
|
68
68
|
signedMsg: SignedMsgOrderNode;
|
|
69
69
|
};
|
|
70
70
|
export type DLOBNodeType = 'signedMsg' | 'restingLimit' | 'takingLimit' | 'floatingLimit' | 'protectedFloatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
|
|
71
|
-
export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, userAccount: string, isProtectedMaker: boolean,
|
|
71
|
+
export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean): DLOBNodeMap[T];
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNode = exports.SignedMsgOrderNode = exports.TriggerOrderNode = exports.MarketOrderNode = exports.FloatingLimitOrderNode = exports.RestingLimitOrderNode = exports.TakingLimitOrderNode = exports.OrderNode = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
|
+
// import { PublicKey } from '@solana/web3.js';
|
|
5
6
|
const NodeList_1 = require("./NodeList");
|
|
6
7
|
class OrderNode {
|
|
7
|
-
constructor(order, userAccount, isProtectedMaker,
|
|
8
|
+
constructor(order, userAccount, isProtectedMaker, applyProtectedMakerOffset, isSignedMsg = false) {
|
|
8
9
|
this.haveFilled = false;
|
|
9
10
|
this.haveTrigger = false;
|
|
10
11
|
// Copy the order over to the node
|
|
@@ -12,7 +13,7 @@ class OrderNode {
|
|
|
12
13
|
this.userAccount = userAccount;
|
|
13
14
|
this.sortValue = this.getSortValue(order);
|
|
14
15
|
this.isProtectedMaker = isProtectedMaker;
|
|
15
|
-
this.
|
|
16
|
+
this.applyProtectedMakerOffset = applyProtectedMakerOffset;
|
|
16
17
|
this.isSignedMsg = isSignedMsg;
|
|
17
18
|
}
|
|
18
19
|
getLabel() {
|
|
@@ -29,7 +30,7 @@ class OrderNode {
|
|
|
29
30
|
return msg;
|
|
30
31
|
}
|
|
31
32
|
getPrice(oraclePriceData, slot) {
|
|
32
|
-
return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot, undefined, this.
|
|
33
|
+
return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot, undefined, this.applyProtectedMakerOffset && this.isProtectedMaker);
|
|
33
34
|
}
|
|
34
35
|
isBaseFilled() {
|
|
35
36
|
return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
|
|
@@ -48,7 +49,7 @@ exports.TakingLimitOrderNode = TakingLimitOrderNode;
|
|
|
48
49
|
class RestingLimitOrderNode extends OrderNode {
|
|
49
50
|
getSortValue(order) {
|
|
50
51
|
let sortValue = order.price;
|
|
51
|
-
if (this.
|
|
52
|
+
if (this.applyProtectedMakerOffset && this.isProtectedMaker) {
|
|
52
53
|
const offset = sortValue.divn(1000);
|
|
53
54
|
if ((0, __1.isVariant)(order.direction, 'long')) {
|
|
54
55
|
sortValue = sortValue.sub(offset);
|
|
@@ -82,27 +83,27 @@ exports.TriggerOrderNode = TriggerOrderNode;
|
|
|
82
83
|
// We'll use the signedMsg uuid for the order id since it's not yet on-chain
|
|
83
84
|
class SignedMsgOrderNode extends OrderNode {
|
|
84
85
|
constructor(order, userAccount) {
|
|
85
|
-
super(order, userAccount, false,
|
|
86
|
+
super(order, userAccount, false, false, true);
|
|
86
87
|
}
|
|
87
88
|
getSortValue(order) {
|
|
88
89
|
return order.slot;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
exports.SignedMsgOrderNode = SignedMsgOrderNode;
|
|
92
|
-
function createNode(nodeType, order, userAccount, isProtectedMaker,
|
|
93
|
+
function createNode(nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
|
|
93
94
|
switch (nodeType) {
|
|
94
95
|
case 'floatingLimit':
|
|
95
|
-
return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker,
|
|
96
|
+
return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
96
97
|
case 'protectedFloatingLimit':
|
|
97
|
-
return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker,
|
|
98
|
+
return new FloatingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
98
99
|
case 'restingLimit':
|
|
99
|
-
return new RestingLimitOrderNode(order, userAccount, isProtectedMaker,
|
|
100
|
+
return new RestingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
100
101
|
case 'takingLimit':
|
|
101
|
-
return new TakingLimitOrderNode(order, userAccount, isProtectedMaker,
|
|
102
|
+
return new TakingLimitOrderNode(order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
102
103
|
case 'market':
|
|
103
|
-
return new MarketOrderNode(order, userAccount, isProtectedMaker,
|
|
104
|
+
return new MarketOrderNode(order, userAccount, isProtectedMaker, false);
|
|
104
105
|
case 'trigger':
|
|
105
|
-
return new TriggerOrderNode(order, userAccount, isProtectedMaker,
|
|
106
|
+
return new TriggerOrderNode(order, userAccount, isProtectedMaker, false);
|
|
106
107
|
case 'signedMsg':
|
|
107
108
|
return new SignedMsgOrderNode(order, userAccount);
|
|
108
109
|
default:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { DLOB } from './DLOB';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
|
-
import { DLOBSource, DLOBSubscriberEvents, DLOBSubscriptionConfig,
|
|
6
|
+
import { DLOBSource, DLOBSubscriberEvents, DLOBSubscriptionConfig, SlotSource } from './types';
|
|
7
7
|
import { DriftClient } from '../driftClient';
|
|
8
8
|
import { MarketType } from '../types';
|
|
9
9
|
import { L2OrderBook, L2OrderBookGenerator, L3OrderBook } from './orderBookLevels';
|
|
@@ -18,7 +18,6 @@ export declare class DLOBSubscriber {
|
|
|
18
18
|
protectedMakerView: boolean;
|
|
19
19
|
constructor(config: DLOBSubscriptionConfig);
|
|
20
20
|
subscribe(): Promise<void>;
|
|
21
|
-
getProtectedMakerParamsMap(): ProtectMakerParamsMap | undefined;
|
|
22
21
|
updateDLOB(): Promise<void>;
|
|
23
22
|
getDLOB(): DLOB;
|
|
24
23
|
/**
|
|
@@ -5,7 +5,6 @@ const DLOB_1 = require("./DLOB");
|
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
const orderBookLevels_1 = require("./orderBookLevels");
|
|
8
|
-
const protectedMakerParams_1 = require("../math/protectedMakerParams");
|
|
9
8
|
class DLOBSubscriber {
|
|
10
9
|
constructor(config) {
|
|
11
10
|
this.driftClient = config.driftClient;
|
|
@@ -13,7 +12,7 @@ class DLOBSubscriber {
|
|
|
13
12
|
this.slotSource = config.slotSource;
|
|
14
13
|
this.updateFrequency = config.updateFrequency;
|
|
15
14
|
this.protectedMakerView = config.protectedMakerView || false;
|
|
16
|
-
this.dlob = new DLOB_1.DLOB(this.
|
|
15
|
+
this.dlob = new DLOB_1.DLOB(this.protectedMakerView);
|
|
17
16
|
this.eventEmitter = new events_1.EventEmitter();
|
|
18
17
|
}
|
|
19
18
|
async subscribe() {
|
|
@@ -31,13 +30,8 @@ class DLOBSubscriber {
|
|
|
31
30
|
}
|
|
32
31
|
}, this.updateFrequency);
|
|
33
32
|
}
|
|
34
|
-
getProtectedMakerParamsMap() {
|
|
35
|
-
return this.protectedMakerView
|
|
36
|
-
? (0, protectedMakerParams_1.getProtectedMakerParamsMap)(this.driftClient.getPerpMarketAccounts())
|
|
37
|
-
: undefined;
|
|
38
|
-
}
|
|
39
33
|
async updateDLOB() {
|
|
40
|
-
this.dlob = await this.dlobSource.getDLOB(this.slotSource.getSlot(), this.
|
|
34
|
+
this.dlob = await this.dlobSource.getDLOB(this.slotSource.getSlot(), this.protectedMakerView);
|
|
41
35
|
}
|
|
42
36
|
getDLOB() {
|
|
43
37
|
return this.dlob;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarketTypeStr, Order
|
|
1
|
+
import { MarketTypeStr, Order } from '..';
|
|
2
2
|
import { DLOBNode, DLOBNodeMap } from './DLOBNode';
|
|
3
3
|
export type SortDirection = 'asc' | 'desc';
|
|
4
4
|
export declare function getOrderSignature(orderId: number, userAccount: string): string;
|
|
@@ -13,7 +13,7 @@ export declare class NodeList<NodeType extends keyof DLOBNodeMap> implements DLO
|
|
|
13
13
|
nodeMap: Map<string, DLOBNodeMap[NodeType]>;
|
|
14
14
|
constructor(nodeType: NodeType, sortDirection: SortDirection);
|
|
15
15
|
clear(): void;
|
|
16
|
-
insert(order: Order, marketType: MarketTypeStr, userAccount: string, isProtectedMaker: boolean,
|
|
16
|
+
insert(order: Order, marketType: MarketTypeStr, userAccount: string, isProtectedMaker: boolean, applyProtectedMakerOffset: boolean): void;
|
|
17
17
|
prependNode(currentNode: DLOBNodeMap[NodeType], newNode: DLOBNodeMap[NodeType]): boolean;
|
|
18
18
|
update(order: Order, userAccount: string): void;
|
|
19
19
|
remove(order: Order, userAccount: string): void;
|
|
@@ -19,11 +19,11 @@ class NodeList {
|
|
|
19
19
|
this.length = 0;
|
|
20
20
|
this.nodeMap.clear();
|
|
21
21
|
}
|
|
22
|
-
insert(order, marketType, userAccount, isProtectedMaker,
|
|
22
|
+
insert(order, marketType, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
|
|
23
23
|
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker,
|
|
26
|
+
const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
27
27
|
const orderSignature = getOrderSignature(order.orderId, userAccount);
|
|
28
28
|
if (this.nodeMap.has(orderSignature)) {
|
|
29
29
|
return;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DLOB } from './DLOB';
|
|
2
2
|
import { DriftClient } from '../driftClient';
|
|
3
|
-
import { ProtectedMakerParams } from '../types';
|
|
4
|
-
import { MarketTypeStr } from '../types';
|
|
5
3
|
export type DLOBSubscriptionConfig = {
|
|
6
4
|
driftClient: DriftClient;
|
|
7
5
|
dlobSource: DLOBSource;
|
|
@@ -14,11 +12,8 @@ export interface DLOBSubscriberEvents {
|
|
|
14
12
|
error: (e: Error) => void;
|
|
15
13
|
}
|
|
16
14
|
export interface DLOBSource {
|
|
17
|
-
getDLOB(slot: number,
|
|
15
|
+
getDLOB(slot: number, protectedMakerView?: boolean): Promise<DLOB>;
|
|
18
16
|
}
|
|
19
17
|
export interface SlotSource {
|
|
20
18
|
getSlot(): number;
|
|
21
19
|
}
|
|
22
|
-
export type ProtectMakerParamsMap = {
|
|
23
|
-
[marketType in MarketTypeStr]: Map<number, ProtectedMakerParams>;
|
|
24
|
-
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as anchor from '@coral-xyz/anchor';
|
|
6
6
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
7
7
|
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
8
|
-
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SignedMsgOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount, ProtectedMakerModeConfig
|
|
8
|
+
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SignedMsgOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount, ProtectedMakerModeConfig } from './types';
|
|
9
9
|
import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
10
10
|
import { TokenFaucet } from './tokenFaucet';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
@@ -167,8 +167,8 @@ export declare class DriftClient {
|
|
|
167
167
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
168
168
|
initializeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
169
169
|
getInitializeSignedMsgUserOrdersAccountIx(authority: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
|
|
170
|
-
resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number,
|
|
171
|
-
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number
|
|
170
|
+
resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
171
|
+
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
|
|
172
172
|
initializeSignedMsgWsDelegatesAccount(authority: PublicKey, delegates?: PublicKey[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
173
173
|
getInitializeSignedMsgWsDelegatesAccountIx(authority: PublicKey, delegates?: PublicKey[]): Promise<TransactionInstruction>;
|
|
174
174
|
addSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
@@ -245,8 +245,8 @@ export declare class DriftClient {
|
|
|
245
245
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
246
246
|
* @param subAccountId
|
|
247
247
|
*/
|
|
248
|
-
forceGetUserAccount(subAccountId?: number
|
|
249
|
-
getUserAccountAndSlot(subAccountId?: number
|
|
248
|
+
forceGetUserAccount(subAccountId?: number): Promise<UserAccount | undefined>;
|
|
249
|
+
getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
|
|
250
250
|
getSpotPosition(marketIndex: number, subAccountId?: number): SpotPosition | undefined;
|
|
251
251
|
getQuoteAssetTokenAmount(): BN;
|
|
252
252
|
/**
|
|
@@ -577,8 +577,8 @@ export declare class DriftClient {
|
|
|
577
577
|
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
578
578
|
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
579
579
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
580
|
-
signSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage
|
|
581
|
-
encodeSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage
|
|
580
|
+
signSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage): SignedMsgOrderParams;
|
|
581
|
+
encodeSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage): Buffer;
|
|
582
582
|
decodeSignedMsgOrderParamsMessage(encodedMessage: Buffer): SignedMsgOrderParamsMessage;
|
|
583
583
|
signMessage(message: Uint8Array, keypair?: Keypair): Buffer;
|
|
584
584
|
placeSignedMsgTakerOrder(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: {
|
|
@@ -642,7 +642,7 @@ class DriftClient {
|
|
|
642
642
|
const initializeUserAccountIx = await this.program.instruction.initializeSignedMsgUserOrders(numOrders, {
|
|
643
643
|
accounts: {
|
|
644
644
|
signedMsgUserOrders: signedMsgUserAccountPublicKey,
|
|
645
|
-
authority,
|
|
645
|
+
authority: this.wallet.publicKey,
|
|
646
646
|
payer: this.wallet.publicKey,
|
|
647
647
|
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
648
648
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -650,21 +650,19 @@ class DriftClient {
|
|
|
650
650
|
});
|
|
651
651
|
return [signedMsgUserAccountPublicKey, initializeUserAccountIx];
|
|
652
652
|
}
|
|
653
|
-
async resizeSignedMsgUserOrders(authority, numOrders,
|
|
654
|
-
const resizeUserAccountIx = await this.getResizeSignedMsgUserOrdersInstruction(authority, numOrders
|
|
653
|
+
async resizeSignedMsgUserOrders(authority, numOrders, txParams) {
|
|
654
|
+
const resizeUserAccountIx = await this.getResizeSignedMsgUserOrdersInstruction(authority, numOrders);
|
|
655
655
|
const tx = await this.buildTransaction([resizeUserAccountIx], txParams);
|
|
656
656
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
657
657
|
return txSig;
|
|
658
658
|
}
|
|
659
|
-
async getResizeSignedMsgUserOrdersInstruction(authority, numOrders
|
|
659
|
+
async getResizeSignedMsgUserOrdersInstruction(authority, numOrders) {
|
|
660
660
|
const signedMsgUserAccountPublicKey = (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority);
|
|
661
661
|
const resizeUserAccountIx = await this.program.instruction.resizeSignedMsgUserOrders(numOrders, {
|
|
662
662
|
accounts: {
|
|
663
663
|
signedMsgUserOrders: signedMsgUserAccountPublicKey,
|
|
664
|
-
authority,
|
|
665
|
-
payer: this.wallet.publicKey,
|
|
664
|
+
authority: this.wallet.publicKey,
|
|
666
665
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
667
|
-
user: await (0, pda_1.getUserAccountPublicKey)(this.program.programId, authority, userSubaccountId),
|
|
668
666
|
},
|
|
669
667
|
});
|
|
670
668
|
return resizeUserAccountIx;
|
|
@@ -1195,12 +1193,12 @@ class DriftClient {
|
|
|
1195
1193
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
1196
1194
|
* @param subAccountId
|
|
1197
1195
|
*/
|
|
1198
|
-
async forceGetUserAccount(subAccountId
|
|
1199
|
-
await this.getUser(subAccountId
|
|
1200
|
-
return this.getUser(subAccountId
|
|
1196
|
+
async forceGetUserAccount(subAccountId) {
|
|
1197
|
+
await this.getUser(subAccountId).fetchAccounts();
|
|
1198
|
+
return this.getUser(subAccountId).getUserAccount();
|
|
1201
1199
|
}
|
|
1202
|
-
getUserAccountAndSlot(subAccountId
|
|
1203
|
-
return this.getUser(subAccountId
|
|
1200
|
+
getUserAccountAndSlot(subAccountId) {
|
|
1201
|
+
return this.getUser(subAccountId).getUserAccountAndSlot();
|
|
1204
1202
|
}
|
|
1205
1203
|
getSpotPosition(marketIndex, subAccountId) {
|
|
1206
1204
|
return this.getUserAccount(subAccountId).spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
|
|
@@ -1275,9 +1273,7 @@ class DriftClient {
|
|
|
1275
1273
|
if (params.useMarketLastSlotCache) {
|
|
1276
1274
|
const lastUserSlot = (_a = this.getUserAccountAndSlot(params.userAccounts.length > 0
|
|
1277
1275
|
? params.userAccounts[0].subAccountId
|
|
1278
|
-
: this.activeSubAccountId
|
|
1279
|
-
? params.userAccounts[0].authority
|
|
1280
|
-
: this.authority)) === null || _a === void 0 ? void 0 : _a.slot;
|
|
1276
|
+
: this.activeSubAccountId)) === null || _a === void 0 ? void 0 : _a.slot;
|
|
1281
1277
|
for (const [marketIndex, slot,] of this.perpMarketLastSlotCache.entries()) {
|
|
1282
1278
|
// if cache has more recent slot than user positions account slot, add market to remaining accounts
|
|
1283
1279
|
// otherwise remove from slot
|
|
@@ -1860,8 +1856,8 @@ class DriftClient {
|
|
|
1860
1856
|
return txSig;
|
|
1861
1857
|
}
|
|
1862
1858
|
async getTransferPerpPositionIx(fromSubAccountId, toSubAccountId, marketIndex, amount) {
|
|
1863
|
-
const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.
|
|
1864
|
-
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.
|
|
1859
|
+
const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, fromSubAccountId);
|
|
1860
|
+
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
1865
1861
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1866
1862
|
userAccounts: [
|
|
1867
1863
|
this.getUserAccount(fromSubAccountId),
|
|
@@ -1926,6 +1922,7 @@ class DriftClient {
|
|
|
1926
1922
|
const userAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
1927
1923
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1928
1924
|
userAccounts: [userAccount],
|
|
1925
|
+
useMarketLastSlotCache: true,
|
|
1929
1926
|
writablePerpMarketIndexes: [marketIndex],
|
|
1930
1927
|
});
|
|
1931
1928
|
if (sharesToBurn == undefined) {
|
|
@@ -3381,8 +3378,8 @@ class DriftClient {
|
|
|
3381
3378
|
remainingAccounts,
|
|
3382
3379
|
});
|
|
3383
3380
|
}
|
|
3384
|
-
signSignedMsgOrderParamsMessage(orderParamsMessage
|
|
3385
|
-
const borshBuf = this.encodeSignedMsgOrderParamsMessage(orderParamsMessage
|
|
3381
|
+
signSignedMsgOrderParamsMessage(orderParamsMessage) {
|
|
3382
|
+
const borshBuf = this.encodeSignedMsgOrderParamsMessage(orderParamsMessage);
|
|
3386
3383
|
const orderParams = Buffer.from(borshBuf.toString('hex'));
|
|
3387
3384
|
return {
|
|
3388
3385
|
orderParams,
|
|
@@ -3392,14 +3389,12 @@ class DriftClient {
|
|
|
3392
3389
|
/*
|
|
3393
3390
|
* Borsh encode signedMsg taker order params
|
|
3394
3391
|
*/
|
|
3395
|
-
encodeSignedMsgOrderParamsMessage(orderParamsMessage
|
|
3392
|
+
encodeSignedMsgOrderParamsMessage(orderParamsMessage) {
|
|
3396
3393
|
const anchorIxName = 'global' + ':' + 'SignedMsgOrderParamsMessage';
|
|
3397
3394
|
const prefix = Buffer.from((0, sha256_1.sha256)(anchorIxName).slice(0, 8));
|
|
3398
3395
|
const buf = Buffer.concat([
|
|
3399
3396
|
prefix,
|
|
3400
|
-
|
|
3401
|
-
? this.program.coder.types.encode('SignedMsgOrderParamsDelegateMessage', orderParamsMessage)
|
|
3402
|
-
: this.program.coder.types.encode('SignedMsgOrderParamsMessage', orderParamsMessage),
|
|
3397
|
+
this.program.coder.types.encode('SignedMsgOrderParamsMessage', orderParamsMessage),
|
|
3403
3398
|
]);
|
|
3404
3399
|
return buf;
|
|
3405
3400
|
}
|
|
@@ -3421,7 +3416,7 @@ class DriftClient {
|
|
|
3421
3416
|
async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex) {
|
|
3422
3417
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3423
3418
|
userAccounts: [takerInfo.takerUserAccount],
|
|
3424
|
-
useMarketLastSlotCache:
|
|
3419
|
+
useMarketLastSlotCache: true,
|
|
3425
3420
|
readablePerpMarketIndex: marketIndex,
|
|
3426
3421
|
});
|
|
3427
3422
|
const messageLengthBuffer = Buffer.alloc(2);
|
|
@@ -3463,7 +3458,7 @@ class DriftClient {
|
|
|
3463
3458
|
this.getUserAccount(subAccountId),
|
|
3464
3459
|
takerInfo.takerUserAccount,
|
|
3465
3460
|
],
|
|
3466
|
-
useMarketLastSlotCache:
|
|
3461
|
+
useMarketLastSlotCache: true,
|
|
3467
3462
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
3468
3463
|
});
|
|
3469
3464
|
if (referrerInfo) {
|
|
@@ -3931,6 +3926,7 @@ class DriftClient {
|
|
|
3931
3926
|
userAccount,
|
|
3932
3927
|
...makerInfos.map((makerInfo) => makerInfo.makerUserAccount),
|
|
3933
3928
|
],
|
|
3929
|
+
useMarketLastSlotCache: true,
|
|
3934
3930
|
writablePerpMarketIndexes: [marketIndex],
|
|
3935
3931
|
});
|
|
3936
3932
|
for (const makerInfo of makerInfos) {
|
|
@@ -4595,6 +4591,7 @@ class DriftClient {
|
|
|
4595
4591
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|
|
4596
4592
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4597
4593
|
userAccounts: [this.getUserAccount()],
|
|
4594
|
+
useMarketLastSlotCache: true,
|
|
4598
4595
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
4599
4596
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
4600
4597
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DriftClient, DriftEnv, OptionalOrderParams, SignedMsgOrderParamsMessage, UserMap } from '..';
|
|
2
|
+
import { Keypair, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
+
export type FastlaneOrderSubscriberConfig = {
|
|
4
|
+
driftClient: DriftClient;
|
|
5
|
+
userMap: UserMap;
|
|
6
|
+
driftEnv: DriftEnv;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
marketIndexes: number[];
|
|
9
|
+
/**
|
|
10
|
+
In the future, this will be used for verifying $DRIFT stake as we add
|
|
11
|
+
authentication for delegate signers
|
|
12
|
+
For now, pass a new keypair or a keypair to an empty wallet
|
|
13
|
+
*/
|
|
14
|
+
keypair: Keypair;
|
|
15
|
+
};
|
|
16
|
+
export declare class FastlaneOrderSubscriber {
|
|
17
|
+
private config;
|
|
18
|
+
private heartbeatTimeout;
|
|
19
|
+
private readonly heartbeatIntervalMs;
|
|
20
|
+
private ws;
|
|
21
|
+
private driftClient;
|
|
22
|
+
userMap: UserMap;
|
|
23
|
+
onOrder: (orderMessageRaw: any, signedMsgOrderParamsMessage: SignedMsgOrderParamsMessage) => Promise<void>;
|
|
24
|
+
subscribed: boolean;
|
|
25
|
+
constructor(config: FastlaneOrderSubscriberConfig);
|
|
26
|
+
getSymbolForMarketIndex(marketIndex: number): string;
|
|
27
|
+
generateChallengeResponse(nonce: string): string;
|
|
28
|
+
handleAuthMessage(message: any): void;
|
|
29
|
+
subscribe(onOrder: (orderMessageRaw: any, signedMsgOrderParamsMessage: SignedMsgOrderParamsMessage) => Promise<void>): Promise<void>;
|
|
30
|
+
getPlaceAndMakeSignedMsgOrderIxs(orderMessageRaw: any, signedMsgOrderParamsMessage: SignedMsgOrderParamsMessage, makerOrderParams: OptionalOrderParams): Promise<TransactionInstruction[]>;
|
|
31
|
+
private startHeartbeatTimer;
|
|
32
|
+
private reconnect;
|
|
33
|
+
}
|