@velocity-exchange/sdk 0.0.1 → 0.0.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/README.md +5 -6
- package/bunfig.toml +3 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/browser/auctionSubscriber/types.d.ts +4 -2
- package/lib/browser/config.d.ts +3 -8
- package/lib/browser/config.js +14 -22
- package/lib/browser/constituentMap/constituentMap.d.ts +4 -2
- package/lib/browser/constituentMap/constituentMap.js +14 -10
- package/lib/browser/core/VelocityCore.d.ts +4 -0
- package/lib/browser/core/VelocityCore.js +3 -1
- package/lib/browser/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/browser/dlob/DLOBSubscriber.js +19 -10
- package/lib/browser/dlob/types.d.ts +3 -1
- package/lib/browser/idl/drift.d.ts +54 -1
- package/lib/browser/idl/drift.json +6046 -803
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/browser/orderSubscriber/types.d.ts +3 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/browser/priorityFee/types.d.ts +9 -5
- package/lib/browser/priorityFee/types.js +1 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/browser/swift/swiftOrderSubscriber.js +19 -11
- package/lib/browser/user.d.ts +3 -1
- package/lib/browser/user.js +93 -86
- package/lib/browser/userConfig.d.ts +4 -2
- package/lib/browser/userMap/referrerMap.d.ts +5 -3
- package/lib/browser/userMap/referrerMap.js +18 -14
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/browser/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/browser/userMap/userMap.d.ts +3 -1
- package/lib/browser/userMap/userMap.js +24 -19
- package/lib/browser/userMap/userMapConfig.d.ts +4 -2
- package/lib/browser/userMap/userStatsMap.d.ts +5 -3
- package/lib/browser/userMap/userStatsMap.js +15 -11
- package/lib/browser/userStats.d.ts +3 -1
- package/lib/browser/userStats.js +21 -15
- package/lib/browser/userStatsConfig.d.ts +4 -2
- package/lib/browser/util/deprecatedAlias.d.ts +26 -0
- package/lib/browser/util/deprecatedAlias.js +10 -0
- package/lib/browser/velocityClient.js +5 -5
- package/lib/browser/velocityClientConfig.d.ts +7 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/node/auctionSubscriber/types.d.ts +4 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/config.d.ts +3 -8
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +14 -22
- package/lib/node/constituentMap/constituentMap.d.ts +4 -2
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +14 -10
- package/lib/node/core/VelocityCore.d.ts +4 -0
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +3 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +19 -10
- package/lib/node/dlob/types.d.ts +3 -1
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/idl/drift.d.ts +54 -1
- package/lib/node/idl/drift.d.ts.map +1 -1
- package/lib/node/idl/drift.json +6046 -803
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/node/orderSubscriber/types.d.ts +3 -1
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/node/priorityFee/types.d.ts +9 -5
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/types.js +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +19 -11
- package/lib/node/user.d.ts +3 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +93 -86
- package/lib/node/userConfig.d.ts +4 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.d.ts +5 -3
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +18 -14
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/node/userMap/userMap.d.ts +3 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +24 -19
- package/lib/node/userMap/userMapConfig.d.ts +4 -2
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +5 -3
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +15 -11
- package/lib/node/userStats.d.ts +3 -1
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +21 -15
- package/lib/node/userStatsConfig.d.ts +4 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- package/lib/node/util/deprecatedAlias.d.ts +27 -0
- package/lib/node/util/deprecatedAlias.d.ts.map +1 -0
- package/lib/node/util/deprecatedAlias.js +10 -0
- package/lib/node/velocityClient.js +5 -5
- package/lib/node/velocityClientConfig.d.ts +7 -4
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/auctionSubscriber/auctionSubscriber.ts +12 -6
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -6
- package/src/auctionSubscriber/types.ts +5 -2
- package/src/config.ts +35 -27
- package/src/constituentMap/constituentMap.ts +17 -9
- package/src/core/VelocityCore.ts +6 -0
- package/src/dlob/DLOBSubscriber.ts +21 -11
- package/src/dlob/types.ts +3 -1
- package/src/idl/drift.json +23940 -18697
- package/src/idl/drift.ts +54 -1
- package/src/orderSubscriber/OrderSubscriber.ts +17 -7
- package/src/orderSubscriber/types.ts +3 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +13 -9
- package/src/priorityFee/priorityFeeSubscriberMap.ts +23 -25
- package/src/priorityFee/types.ts +14 -9
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
- package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
- package/src/swift/swiftOrderSubscriber.ts +24 -16
- package/src/user.ts +93 -82
- package/src/userConfig.ts +5 -2
- package/src/userMap/referrerMap.ts +19 -15
- package/src/userMap/revenueShareEscrowMap.ts +20 -16
- package/src/userMap/userMap.ts +20 -15
- package/src/userMap/userMapConfig.ts +6 -3
- package/src/userMap/userStatsMap.ts +19 -15
- package/src/userStats.ts +13 -7
- package/src/userStatsConfig.ts +5 -2
- package/src/util/deprecatedAlias.ts +25 -0
- package/src/velocityClient.ts +6 -6
- package/src/velocityClientConfig.ts +25 -42
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userStatsConfig.d.ts","sourceRoot":"","sources":["../../src/userStatsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"userStatsConfig.d.ts","sourceRoot":"","sources":["../../src/userStatsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,KAAK,mBAAmB,GAAG;IAC1B,mBAAmB,CAAC,EAAE,2BAA2B,CAAC;IAClD,yBAAyB,EAAE,SAAS,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAChD,UAAU,CAAC,gBAAgB,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;AAE7D,MAAM,MAAM,2BAA2B,GACpC;IACA,IAAI,EAAE,WAAW,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;CACvB,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,EAAE,iBAAiB,CAAC;CAChC,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,0BAA0B,EAAE,0BAA0B,CAAC;CACtD,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,WAAW,CAAC;CACxB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type helpers for expressing the Drift → Velocity rename surface.
|
|
3
|
+
*
|
|
4
|
+
* The SDK exposes paired keys (`velocityX` canonical, `driftX` deprecated) on
|
|
5
|
+
* several config objects. {@link AtLeastOne} captures the "callers must supply
|
|
6
|
+
* one of the two" contract at the type level so the runtime fallback in the
|
|
7
|
+
* consuming class can rely on the value being present.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `AtLeastOne<A, B, T>` requires the caller to set at least one of two keys
|
|
11
|
+
* (`A` canonical, `B` deprecated) to a value of type `T`. Whichever the caller
|
|
12
|
+
* omits remains optional.
|
|
13
|
+
*
|
|
14
|
+
* Use this to express "rename `B` to `A`, but keep `B` accepted until the next
|
|
15
|
+
* major" on a config object without dropping back to "both optional + runtime
|
|
16
|
+
* throw".
|
|
17
|
+
*/
|
|
18
|
+
export type AtLeastOne<A extends string, B extends string, T> = ({
|
|
19
|
+
[K in A]: T;
|
|
20
|
+
} & {
|
|
21
|
+
[K in B]?: T;
|
|
22
|
+
}) | ({
|
|
23
|
+
[K in A]?: T;
|
|
24
|
+
} & {
|
|
25
|
+
[K in B]: T;
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=deprecatedAlias.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecatedAlias.d.ts","sourceRoot":"","sources":["../../../src/util/deprecatedAlias.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CACrB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,EAChB,CAAC,IAEC,CAAC;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAAE,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;CAAE,CAAC,GACpC,CAAC;KAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;CAAE,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type helpers for expressing the Drift → Velocity rename surface.
|
|
4
|
+
*
|
|
5
|
+
* The SDK exposes paired keys (`velocityX` canonical, `driftX` deprecated) on
|
|
6
|
+
* several config objects. {@link AtLeastOne} captures the "callers must supply
|
|
7
|
+
* one of the two" contract at the type level so the runtime fallback in the
|
|
8
|
+
* consuming class can rely on the value being present.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -192,7 +192,7 @@ class VelocityClient {
|
|
|
192
192
|
}
|
|
193
193
|
if (config.userStats) {
|
|
194
194
|
this.userStats = new userStats_1.UserStats({
|
|
195
|
-
|
|
195
|
+
velocityClient: this,
|
|
196
196
|
userStatsAccountPublicKey: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority),
|
|
197
197
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
198
198
|
});
|
|
@@ -245,7 +245,7 @@ class VelocityClient {
|
|
|
245
245
|
createUser(subAccountId, accountSubscriptionConfig, authority) {
|
|
246
246
|
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, authority !== null && authority !== void 0 ? authority : this.authority, subAccountId);
|
|
247
247
|
return new user_1.User({
|
|
248
|
-
|
|
248
|
+
velocityClient: this,
|
|
249
249
|
userAccountPublicKey,
|
|
250
250
|
accountSubscription: accountSubscriptionConfig,
|
|
251
251
|
});
|
|
@@ -437,7 +437,7 @@ class VelocityClient {
|
|
|
437
437
|
}
|
|
438
438
|
this.userStats = undefined;
|
|
439
439
|
this.userStats = new userStats_1.UserStats({
|
|
440
|
-
|
|
440
|
+
velocityClient: this,
|
|
441
441
|
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
442
442
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
443
443
|
});
|
|
@@ -475,7 +475,7 @@ class VelocityClient {
|
|
|
475
475
|
}
|
|
476
476
|
this.userStats = undefined;
|
|
477
477
|
this.userStats = new userStats_1.UserStats({
|
|
478
|
-
|
|
478
|
+
velocityClient: this,
|
|
479
479
|
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
480
480
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
481
481
|
});
|
|
@@ -500,7 +500,7 @@ class VelocityClient {
|
|
|
500
500
|
await this.userStats.unsubscribe();
|
|
501
501
|
}
|
|
502
502
|
this.userStats = new userStats_1.UserStats({
|
|
503
|
-
|
|
503
|
+
velocityClient: this,
|
|
504
504
|
userStatsAccountPublicKey: this.userStatsAccountPublicKey,
|
|
505
505
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
506
506
|
});
|
|
@@ -56,14 +56,16 @@ export type VelocityClientConfig = {
|
|
|
56
56
|
};
|
|
57
57
|
/** @deprecated Use `VelocityClientConfig` instead. `DriftClientConfig` will be removed in a future major. */
|
|
58
58
|
export type DriftClientConfig = VelocityClientConfig;
|
|
59
|
+
type GrpcVelocityClientAccountSubscriberCtor = new (grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => grpcVelocityClientAccountSubscriberV2 | grpcVelocityClientAccountSubscriber;
|
|
60
|
+
type WsVelocityClientAccountSubscriberCtor = new (program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => WebSocketVelocityClientAccountSubscriber | WebSocketVelocityClientAccountSubscriberV2;
|
|
59
61
|
export type VelocityClientSubscriptionConfig = {
|
|
60
62
|
type: 'grpc';
|
|
61
63
|
grpcConfigs: GrpcConfigs;
|
|
62
64
|
resubTimeoutMs?: number;
|
|
63
65
|
logResubMessages?: boolean;
|
|
64
|
-
velocityClientAccountSubscriber?:
|
|
66
|
+
velocityClientAccountSubscriber?: GrpcVelocityClientAccountSubscriberCtor;
|
|
65
67
|
/** @deprecated Use `velocityClientAccountSubscriber` instead. `driftClientAccountSubscriber` will be removed in a future major. */
|
|
66
|
-
driftClientAccountSubscriber?:
|
|
68
|
+
driftClientAccountSubscriber?: GrpcVelocityClientAccountSubscriberCtor;
|
|
67
69
|
grpcMultiUserAccountSubscriber?: grpcMultiUserAccountSubscriber;
|
|
68
70
|
} | {
|
|
69
71
|
type: 'websocket';
|
|
@@ -73,13 +75,14 @@ export type VelocityClientSubscriptionConfig = {
|
|
|
73
75
|
programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
74
76
|
perpMarketAccountSubscriber?: new (accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, commitment?: Commitment) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
75
77
|
/** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
|
|
76
|
-
velocityClientAccountSubscriber?:
|
|
78
|
+
velocityClientAccountSubscriber?: WsVelocityClientAccountSubscriberCtor;
|
|
77
79
|
/** @deprecated Use `velocityClientAccountSubscriber` instead. `driftClientAccountSubscriber` will be removed in a future major. */
|
|
78
|
-
driftClientAccountSubscriber?:
|
|
80
|
+
driftClientAccountSubscriber?: WsVelocityClientAccountSubscriberCtor;
|
|
79
81
|
} | {
|
|
80
82
|
type: 'polling';
|
|
81
83
|
accountLoader: BulkAccountLoader;
|
|
82
84
|
};
|
|
83
85
|
/** @deprecated Use `VelocityClientSubscriptionConfig` instead. `DriftClientSubscriptionConfig` will be removed in a future major. */
|
|
84
86
|
export type DriftClientSubscriptionConfig = VelocityClientSubscriptionConfig;
|
|
87
|
+
export {};
|
|
85
88
|
//# sourceMappingURL=velocityClientConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"velocityClientConfig.d.ts","sourceRoot":"","sources":["../../src/velocityClientConfig.ts"],"names":[],"mappings":";;AAAA;;;;;;GAMG;AACH,OAAO,EACN,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE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C,EAAE,OAAO,CAAC;IAC3B,+BAA+B,CAAC,EAAE,uCAAuC,CAAC;IAC1E,mIAAmI;IACnI,4BAA4B,CAAC,EAAE,uCAAuC,CAAC;IACvE,8BAA8B,CAAC,EAAE,8BAA8B,CAAC;CAC/D,GACD;IACA,IAAI,EAAE,WAAW,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,4BAA4B,CAAC,EAAE,iCAAiC,CAAC,WAAW,CAAC,CAAC;IAC9E,2BAA2B,CAAC,EAAE,KAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,SAAS,EAC3B,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,EACtC,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,UAAU,KACnB,4BAA4B,CAAC,GAAG,CAAC,GAAG,0BAA0B,CAAC,GAAG,CAAC,CAAC;IACzE,yIAAyI;IACzI,+BAA+B,CAAC,EAAE,qCAAqC,CAAC;IACxE,mIAAmI;IACnI,4BAA4B,CAAC,EAAE,qCAAqC,CAAC;CACpE,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAEL,qIAAqI;AACrI,MAAM,MAAM,6BAA6B,GAAG,gCAAgC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velocity-exchange/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "lib/node/index.js",
|
|
5
5
|
"types": "lib/node/index.d.ts",
|
|
6
6
|
"module": "./lib/browser/index.js",
|
|
7
|
-
"author": "crispheaney",
|
|
8
7
|
"homepage": "https://www.drift.trade/",
|
|
9
8
|
"repository": {
|
|
10
9
|
"type": "git",
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
},
|
|
104
103
|
"description": "SDK for Drift Protocol",
|
|
105
104
|
"engines": {
|
|
106
|
-
"node": "24.
|
|
105
|
+
"node": "^24.0.0"
|
|
107
106
|
},
|
|
108
107
|
"resolutions": {
|
|
109
108
|
"@solana/web3.js": "1.98.0",
|
|
@@ -9,7 +9,11 @@ import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramA
|
|
|
9
9
|
import { ResubOpts } from '../accounts/types';
|
|
10
10
|
|
|
11
11
|
export class AuctionSubscriber {
|
|
12
|
-
private
|
|
12
|
+
private velocityClient: VelocityClient;
|
|
13
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
14
|
+
private get driftClient(): VelocityClient {
|
|
15
|
+
return this.velocityClient;
|
|
16
|
+
}
|
|
13
17
|
private opts: ConfirmOptions;
|
|
14
18
|
private resubOpts?: ResubOpts;
|
|
15
19
|
|
|
@@ -17,13 +21,15 @@ export class AuctionSubscriber {
|
|
|
17
21
|
private subscriber: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
18
22
|
|
|
19
23
|
constructor({
|
|
24
|
+
velocityClient,
|
|
20
25
|
driftClient,
|
|
21
26
|
opts,
|
|
22
27
|
resubTimeoutMs,
|
|
23
28
|
logResubMessages,
|
|
24
29
|
}: AuctionSubscriberConfig) {
|
|
25
|
-
|
|
26
|
-
this.
|
|
30
|
+
// Type-system guarantees at least one of the two is supplied.
|
|
31
|
+
this.velocityClient = (velocityClient ?? driftClient)!;
|
|
32
|
+
this.opts = opts || this.velocityClient.opts;
|
|
27
33
|
this.eventEmitter = new EventEmitter();
|
|
28
34
|
this.resubOpts = { resubTimeoutMs, logResubMessages };
|
|
29
35
|
}
|
|
@@ -33,11 +39,11 @@ export class AuctionSubscriber {
|
|
|
33
39
|
this.subscriber = new WebSocketProgramAccountSubscriber<UserAccount>(
|
|
34
40
|
'AuctionSubscriber',
|
|
35
41
|
'user',
|
|
36
|
-
this.
|
|
42
|
+
this.velocityClient.program,
|
|
37
43
|
(
|
|
38
|
-
this.
|
|
44
|
+
this.velocityClient.program.account as any
|
|
39
45
|
).user.coder.accounts.decode.bind(
|
|
40
|
-
(this.
|
|
46
|
+
(this.velocityClient.program.account as any).user.coder.accounts
|
|
41
47
|
),
|
|
42
48
|
{
|
|
43
49
|
filters: [getUserFilter(), getUserWithAuctionFilter()],
|
|
@@ -10,7 +10,11 @@ import { GrpcConfigs, ResubOpts } from '../accounts/types';
|
|
|
10
10
|
import { grpcProgramAccountSubscriber } from '../accounts/grpcProgramAccountSubscriber';
|
|
11
11
|
|
|
12
12
|
export class AuctionSubscriberGrpc {
|
|
13
|
-
private
|
|
13
|
+
private velocityClient: VelocityClient;
|
|
14
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
15
|
+
private get driftClient(): VelocityClient {
|
|
16
|
+
return this.velocityClient;
|
|
17
|
+
}
|
|
14
18
|
private opts: ConfirmOptions;
|
|
15
19
|
private resubOpts?: ResubOpts;
|
|
16
20
|
private grpcConfigs?: GrpcConfigs;
|
|
@@ -19,14 +23,16 @@ export class AuctionSubscriberGrpc {
|
|
|
19
23
|
private subscriber: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
20
24
|
|
|
21
25
|
constructor({
|
|
26
|
+
velocityClient,
|
|
22
27
|
driftClient,
|
|
23
28
|
opts,
|
|
24
29
|
grpcConfigs,
|
|
25
30
|
resubTimeoutMs,
|
|
26
31
|
logResubMessages,
|
|
27
32
|
}: AuctionSubscriberConfig) {
|
|
28
|
-
|
|
29
|
-
this.
|
|
33
|
+
// Type-system guarantees at least one of the two is supplied.
|
|
34
|
+
this.velocityClient = (velocityClient ?? driftClient)!;
|
|
35
|
+
this.opts = opts || this.velocityClient.opts;
|
|
30
36
|
this.eventEmitter = new EventEmitter();
|
|
31
37
|
this.resubOpts = { resubTimeoutMs, logResubMessages };
|
|
32
38
|
this.grpcConfigs = grpcConfigs;
|
|
@@ -38,11 +44,11 @@ export class AuctionSubscriberGrpc {
|
|
|
38
44
|
this.grpcConfigs,
|
|
39
45
|
'AuctionSubscriber',
|
|
40
46
|
'user',
|
|
41
|
-
this.
|
|
47
|
+
this.velocityClient.program,
|
|
42
48
|
(
|
|
43
|
-
this.
|
|
49
|
+
this.velocityClient.program.account as any
|
|
44
50
|
).user.coder.accounts.decode.bind(
|
|
45
|
-
(this.
|
|
51
|
+
(this.velocityClient.program.account as any).user.coder.accounts
|
|
46
52
|
),
|
|
47
53
|
{
|
|
48
54
|
filters: [getUserFilter(), getUserWithAuctionFilter()],
|
|
@@ -2,15 +2,18 @@ import { GrpcConfigs } from '../accounts/types';
|
|
|
2
2
|
import { VelocityClient } from '../velocityClient';
|
|
3
3
|
import { UserAccount } from '../types';
|
|
4
4
|
import { ConfirmOptions, PublicKey } from '@solana/web3.js';
|
|
5
|
+
import { AtLeastOne } from '../util/deprecatedAlias';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
driftClient: VelocityClient;
|
|
7
|
+
type AuctionSubscriberConfigBase = {
|
|
8
8
|
opts?: ConfirmOptions;
|
|
9
9
|
resubTimeoutMs?: number;
|
|
10
10
|
logResubMessages?: boolean;
|
|
11
11
|
grpcConfigs?: GrpcConfigs;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
export type AuctionSubscriberConfig = AuctionSubscriberConfigBase &
|
|
15
|
+
AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
|
|
16
|
+
|
|
14
17
|
export interface AuctionSubscriberEvents {
|
|
15
18
|
onAccountUpdate: (
|
|
16
19
|
account: UserAccount,
|
package/src/config.ts
CHANGED
|
@@ -27,6 +27,9 @@ export type VelocityEnv = 'devnet' | 'mainnet-beta';
|
|
|
27
27
|
/** @deprecated Use `VelocityEnv` instead. `DriftEnv` will be removed in a future major. */
|
|
28
28
|
export type DriftEnv = VelocityEnv;
|
|
29
29
|
|
|
30
|
+
/** Widened env type accepted by `initialize()`; `'master'` is a legacy alias for `'devnet'`. */
|
|
31
|
+
export type LegacyVelocityEnv = VelocityEnv | 'master';
|
|
32
|
+
|
|
30
33
|
export interface VelocityConfig {
|
|
31
34
|
ENV: VelocityEnv;
|
|
32
35
|
PYTH_ORACLE_MAPPING_ADDRESS: string;
|
|
@@ -50,7 +53,8 @@ export interface VelocityConfig {
|
|
|
50
53
|
/** @deprecated Use `VelocityConfig` instead. `DriftConfig` will be removed in a future major. */
|
|
51
54
|
export type DriftConfig = VelocityConfig;
|
|
52
55
|
|
|
53
|
-
export const VELOCITY_PROGRAM_ID =
|
|
56
|
+
export const VELOCITY_PROGRAM_ID =
|
|
57
|
+
'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
|
|
54
58
|
|
|
55
59
|
/** @deprecated Use `VELOCITY_PROGRAM_ID` instead. `DRIFT_PROGRAM_ID` will be removed in a future major. */
|
|
56
60
|
export const DRIFT_PROGRAM_ID = VELOCITY_PROGRAM_ID;
|
|
@@ -140,35 +144,37 @@ export const getConfig = (): VelocityConfig => currentConfig;
|
|
|
140
144
|
* @param props
|
|
141
145
|
* @returns
|
|
142
146
|
*/
|
|
147
|
+
/**
|
|
148
|
+
* Mirror a canonical/deprecated alias pair so the resolved config carries the
|
|
149
|
+
* same value under both keys regardless of which one the caller overrode.
|
|
150
|
+
*/
|
|
151
|
+
const mirrorAlias = <K1 extends keyof VelocityConfig, K2 extends keyof VelocityConfig>(
|
|
152
|
+
merged: VelocityConfig,
|
|
153
|
+
override: Partial<VelocityConfig>,
|
|
154
|
+
canon: K1,
|
|
155
|
+
deprecated: K2
|
|
156
|
+
): void => {
|
|
157
|
+
const value = override[canon] ?? override[deprecated] ?? merged[canon];
|
|
158
|
+
(merged[canon] as VelocityConfig[K1]) = value as VelocityConfig[K1];
|
|
159
|
+
(merged[deprecated] as VelocityConfig[K2]) = value as VelocityConfig[K2];
|
|
160
|
+
};
|
|
161
|
+
|
|
143
162
|
export const initialize = (props: {
|
|
144
|
-
env:
|
|
163
|
+
env: LegacyVelocityEnv;
|
|
145
164
|
overrideEnv?: Partial<VelocityConfig>;
|
|
146
165
|
}): VelocityConfig => {
|
|
147
166
|
const override = props.overrideEnv ?? {};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const overrodeVelocityOracleReceiver =
|
|
162
|
-
'VELOCITY_ORACLE_RECEIVER_ID' in override;
|
|
163
|
-
const overrodeDriftOracleReceiver = 'DRIFT_ORACLE_RECEIVER_ID' in override;
|
|
164
|
-
if (overrodeVelocityOracleReceiver && !overrodeDriftOracleReceiver) {
|
|
165
|
-
merged.DRIFT_ORACLE_RECEIVER_ID = merged.VELOCITY_ORACLE_RECEIVER_ID;
|
|
166
|
-
} else if (overrodeDriftOracleReceiver && !overrodeVelocityOracleReceiver) {
|
|
167
|
-
merged.VELOCITY_ORACLE_RECEIVER_ID = merged.DRIFT_ORACLE_RECEIVER_ID;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//@ts-ignore
|
|
171
|
-
if (props.env === 'master') return merged;
|
|
167
|
+
const normalizedEnv: VelocityEnv =
|
|
168
|
+
props.env === 'master' ? 'devnet' : props.env;
|
|
169
|
+
const merged: VelocityConfig = { ...configs[normalizedEnv], ...override };
|
|
170
|
+
|
|
171
|
+
mirrorAlias(merged, override, 'VELOCITY_PROGRAM_ID', 'DRIFT_PROGRAM_ID');
|
|
172
|
+
mirrorAlias(
|
|
173
|
+
merged,
|
|
174
|
+
override,
|
|
175
|
+
'VELOCITY_ORACLE_RECEIVER_ID',
|
|
176
|
+
'DRIFT_ORACLE_RECEIVER_ID'
|
|
177
|
+
);
|
|
172
178
|
|
|
173
179
|
currentConfig = merged;
|
|
174
180
|
return currentConfig;
|
|
@@ -215,7 +221,9 @@ export function getMarketsAndOraclesForSubscription(
|
|
|
215
221
|
};
|
|
216
222
|
}
|
|
217
223
|
|
|
218
|
-
export async function findAllMarketAndOracles(
|
|
224
|
+
export async function findAllMarketAndOracles(
|
|
225
|
+
program: VelocityProgram
|
|
226
|
+
): Promise<{
|
|
219
227
|
perpMarketIndexes: number[];
|
|
220
228
|
perpMarketAccounts: PerpMarketAccount[];
|
|
221
229
|
spotMarketIndexes: number[];
|
|
@@ -17,7 +17,9 @@ import { getLpPoolPublicKey } from '../addresses/pda';
|
|
|
17
17
|
const MAX_CONSTITUENT_SIZE_BYTES = 480; // TODO: update this when account is finalized
|
|
18
18
|
|
|
19
19
|
export type ConstituentMapConfig = {
|
|
20
|
-
|
|
20
|
+
velocityClient?: VelocityClient;
|
|
21
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
22
|
+
driftClient?: VelocityClient;
|
|
21
23
|
connection?: Connection;
|
|
22
24
|
subscriptionConfig:
|
|
23
25
|
| {
|
|
@@ -55,7 +57,7 @@ export interface ConstituentMapInterface {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export class ConstituentMap implements ConstituentMapInterface {
|
|
58
|
-
private
|
|
60
|
+
private velocityClient: VelocityClient;
|
|
59
61
|
private constituentMap = new Map<string, DataAndSlot<ConstituentAccount>>();
|
|
60
62
|
private constituentAccountSubscriber: ConstituentAccountSubscriber;
|
|
61
63
|
private additionalFilters?: MemcmpFilter[];
|
|
@@ -69,10 +71,16 @@ export class ConstituentMap implements ConstituentMapInterface {
|
|
|
69
71
|
private decoder: 'base64' | 'base64+zstd';
|
|
70
72
|
|
|
71
73
|
constructor(config: ConstituentMapConfig) {
|
|
72
|
-
|
|
74
|
+
const velocityClient = config.velocityClient ?? config.driftClient;
|
|
75
|
+
if (!velocityClient) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'ConstituentMap: velocityClient (or deprecated driftClient) must be provided'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
this.velocityClient = velocityClient;
|
|
73
81
|
this.additionalFilters = config.additionalFilters;
|
|
74
82
|
this.commitment = config.subscriptionConfig.commitment;
|
|
75
|
-
this.connection = config.connection || this.
|
|
83
|
+
this.connection = config.connection || this.velocityClient.connection;
|
|
76
84
|
this.lpPoolId = config.lpPoolId ?? 0;
|
|
77
85
|
this.decoder = config.decoder ?? 'base64+zstd';
|
|
78
86
|
|
|
@@ -80,7 +88,7 @@ export class ConstituentMap implements ConstituentMapInterface {
|
|
|
80
88
|
this.constituentAccountSubscriber =
|
|
81
89
|
new PollingConstituentAccountSubscriber(
|
|
82
90
|
this,
|
|
83
|
-
this.
|
|
91
|
+
this.velocityClient.program,
|
|
84
92
|
config.subscriptionConfig.frequency,
|
|
85
93
|
config.subscriptionConfig.commitment,
|
|
86
94
|
this.getFilters()
|
|
@@ -89,7 +97,7 @@ export class ConstituentMap implements ConstituentMapInterface {
|
|
|
89
97
|
this.constituentAccountSubscriber =
|
|
90
98
|
new WebSocketConstituentAccountSubscriber(
|
|
91
99
|
this,
|
|
92
|
-
this.
|
|
100
|
+
this.velocityClient.program,
|
|
93
101
|
config.subscriptionConfig.resubTimeoutMs,
|
|
94
102
|
config.subscriptionConfig.commitment,
|
|
95
103
|
this.getFilters()
|
|
@@ -109,7 +117,7 @@ export class ConstituentMap implements ConstituentMapInterface {
|
|
|
109
117
|
const filters = [
|
|
110
118
|
getConstituentFilter(),
|
|
111
119
|
getConstituentLpPoolFilter(
|
|
112
|
-
getLpPoolPublicKey(this.
|
|
120
|
+
getLpPoolPublicKey(this.velocityClient.program.programId, this.lpPoolId)
|
|
113
121
|
),
|
|
114
122
|
];
|
|
115
123
|
if (this.additionalFilters) {
|
|
@@ -120,14 +128,14 @@ export class ConstituentMap implements ConstituentMapInterface {
|
|
|
120
128
|
|
|
121
129
|
private decode(name: string, buffer: Buffer): ConstituentAccount {
|
|
122
130
|
return (
|
|
123
|
-
this.
|
|
131
|
+
this.velocityClient.program.account as any
|
|
124
132
|
).constituent.coder.accounts.decodeUnchecked(name, buffer);
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
public async sync(): Promise<void> {
|
|
128
136
|
try {
|
|
129
137
|
const rpcRequestArgs = [
|
|
130
|
-
this.
|
|
138
|
+
this.velocityClient.program.programId.toBase58(),
|
|
131
139
|
{
|
|
132
140
|
commitment: this.commitment,
|
|
133
141
|
filters: this.getFilters(),
|
package/src/core/VelocityCore.ts
CHANGED
|
@@ -329,3 +329,9 @@ export class VelocityCore {
|
|
|
329
329
|
return [];
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
+
|
|
333
|
+
/** @deprecated Use `VelocityCore` instead. `DriftCore` will be removed in a future major. */
|
|
334
|
+
export const DriftCore = VelocityCore;
|
|
335
|
+
|
|
336
|
+
/** @deprecated Use `VelocityCore` instead. `DriftCore` will be removed in a future major. */
|
|
337
|
+
export type DriftCore = VelocityCore;
|
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
import { BN } from '../isomorphic/anchor';
|
|
21
21
|
|
|
22
22
|
export class DLOBSubscriber {
|
|
23
|
-
|
|
23
|
+
velocityClient: VelocityClient;
|
|
24
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
25
|
+
public get driftClient(): VelocityClient {
|
|
26
|
+
return this.velocityClient;
|
|
27
|
+
}
|
|
24
28
|
dlobSource: DLOBSource;
|
|
25
29
|
slotSource: SlotSource;
|
|
26
30
|
updateFrequency: number;
|
|
@@ -28,7 +32,13 @@ export class DLOBSubscriber {
|
|
|
28
32
|
dlob: DLOB;
|
|
29
33
|
public eventEmitter: StrictEventEmitter<EventEmitter, DLOBSubscriberEvents>;
|
|
30
34
|
constructor(config: DLOBSubscriptionConfig) {
|
|
31
|
-
|
|
35
|
+
const velocityClient = config.velocityClient ?? config.driftClient;
|
|
36
|
+
if (!velocityClient) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'DLOBSubscriber: velocityClient (or deprecated driftClient) must be provided'
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
this.velocityClient = velocityClient;
|
|
32
42
|
this.dlobSource = config.dlobSource;
|
|
33
43
|
this.slotSource = config.slotSource;
|
|
34
44
|
this.updateFrequency = config.updateFrequency;
|
|
@@ -93,7 +103,7 @@ export class DLOBSubscriber {
|
|
|
93
103
|
}): L2OrderBook {
|
|
94
104
|
if (marketName) {
|
|
95
105
|
const derivedMarketInfo =
|
|
96
|
-
this.
|
|
106
|
+
this.velocityClient.getMarketIndexAndType(marketName);
|
|
97
107
|
if (!derivedMarketInfo) {
|
|
98
108
|
throw new Error(`Market ${marketName} not found`);
|
|
99
109
|
}
|
|
@@ -111,13 +121,13 @@ export class DLOBSubscriber {
|
|
|
111
121
|
const isPerp = isVariant(marketType, 'perp');
|
|
112
122
|
if (isPerp) {
|
|
113
123
|
const perpMarketAccount =
|
|
114
|
-
this.
|
|
115
|
-
oraclePriceData = this.
|
|
124
|
+
this.velocityClient.getPerpMarketAccount(marketIndex);
|
|
125
|
+
oraclePriceData = this.velocityClient.getOracleDataForPerpMarket(
|
|
116
126
|
perpMarketAccount.marketIndex
|
|
117
127
|
);
|
|
118
128
|
} else {
|
|
119
129
|
oraclePriceData =
|
|
120
|
-
this.
|
|
130
|
+
this.velocityClient.getOracleDataForSpotMarket(marketIndex);
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
if (isPerp && includeVamm) {
|
|
@@ -129,9 +139,9 @@ export class DLOBSubscriber {
|
|
|
129
139
|
|
|
130
140
|
fallbackL2Generators = [
|
|
131
141
|
getVammL2Generator({
|
|
132
|
-
marketAccount: this.
|
|
142
|
+
marketAccount: this.velocityClient.getPerpMarketAccount(marketIndex),
|
|
133
143
|
mmOraclePriceData:
|
|
134
|
-
this.
|
|
144
|
+
this.velocityClient.getMMOracleDataForPerpMarket(marketIndex),
|
|
135
145
|
numOrders: numVammOrders ?? depth,
|
|
136
146
|
topOfBookQuoteAmounts:
|
|
137
147
|
marketIndex < 3
|
|
@@ -170,7 +180,7 @@ export class DLOBSubscriber {
|
|
|
170
180
|
}): L3OrderBook {
|
|
171
181
|
if (marketName) {
|
|
172
182
|
const derivedMarketInfo =
|
|
173
|
-
this.
|
|
183
|
+
this.velocityClient.getMarketIndexAndType(marketName);
|
|
174
184
|
if (!derivedMarketInfo) {
|
|
175
185
|
throw new Error(`Market ${marketName} not found`);
|
|
176
186
|
}
|
|
@@ -188,10 +198,10 @@ export class DLOBSubscriber {
|
|
|
188
198
|
const isPerp = isVariant(marketType, 'perp');
|
|
189
199
|
if (isPerp) {
|
|
190
200
|
oraclePriceData =
|
|
191
|
-
this.
|
|
201
|
+
this.velocityClient.getOracleDataForPerpMarket(marketIndex);
|
|
192
202
|
} else {
|
|
193
203
|
oraclePriceData =
|
|
194
|
-
this.
|
|
204
|
+
this.velocityClient.getOracleDataForSpotMarket(marketIndex);
|
|
195
205
|
}
|
|
196
206
|
|
|
197
207
|
return this.dlob.getL3({
|
package/src/dlob/types.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { DLOB } from './DLOB';
|
|
|
2
2
|
import { VelocityClient } from '../velocityClient';
|
|
3
3
|
|
|
4
4
|
export type DLOBSubscriptionConfig = {
|
|
5
|
-
|
|
5
|
+
velocityClient?: VelocityClient;
|
|
6
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
7
|
+
driftClient?: VelocityClient;
|
|
6
8
|
dlobSource: DLOBSource;
|
|
7
9
|
slotSource: SlotSource;
|
|
8
10
|
updateFrequency: number;
|