@velocity-exchange/sdk 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- 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/decode/user.js +5 -5
- package/lib/browser/dlob/DLOB.js +1 -1
- package/lib/browser/dlob/DLOBNode.js +1 -2
- 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 +59 -6
- package/lib/browser/idl/drift.json +6049 -806
- package/lib/browser/math/auction.d.ts +1 -1
- package/lib/browser/math/auction.js +2 -9
- package/lib/browser/math/orders.js +3 -3
- 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/types.d.ts +2 -2
- 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.d.ts +6 -6
- package/lib/browser/velocityClient.js +6 -6
- 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/decode/user.js +5 -5
- package/lib/node/dlob/DLOB.js +1 -1
- package/lib/node/dlob/DLOBNode.js +1 -2
- 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 +59 -6
- package/lib/node/idl/drift.d.ts.map +1 -1
- package/lib/node/idl/drift.json +6049 -806
- package/lib/node/math/auction.d.ts +1 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +2 -9
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +3 -3
- 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/types.d.ts +2 -2
- package/lib/node/types.d.ts.map +1 -1
- 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.d.ts +6 -6
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +6 -6
- package/lib/node/velocityClientConfig.d.ts +7 -4
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +1 -1
- 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 +38 -27
- package/src/constituentMap/constituentMap.ts +17 -9
- package/src/core/VelocityCore.ts +6 -0
- package/src/decode/user.ts +5 -5
- package/src/dlob/DLOB.ts +1 -1
- package/src/dlob/DLOBNode.ts +1 -1
- 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 +59 -6
- package/src/math/auction.ts +3 -10
- package/src/math/orders.ts +3 -6
- 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 +19 -9
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
- package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
- package/src/swift/swiftOrderSubscriber.ts +24 -16
- package/src/types.ts +2 -2
- 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 +21 -0
- package/src/velocityClient.ts +12 -12
- package/src/velocityClientConfig.ts +27 -42
- package/tests/auctions/test.ts +4 -4
- package/tests/decode/test.ts +1 -1
- package/tests/dlob/test.ts +5 -5
- package/tests/user/helpers.ts +1 -1
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,40 @@ 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 = <
|
|
152
|
+
K1 extends keyof VelocityConfig,
|
|
153
|
+
K2 extends keyof VelocityConfig,
|
|
154
|
+
>(
|
|
155
|
+
merged: VelocityConfig,
|
|
156
|
+
override: Partial<VelocityConfig>,
|
|
157
|
+
canon: K1,
|
|
158
|
+
deprecated: K2
|
|
159
|
+
): void => {
|
|
160
|
+
const value = override[canon] ?? override[deprecated] ?? merged[canon];
|
|
161
|
+
(merged[canon] as VelocityConfig[K1]) = value as VelocityConfig[K1];
|
|
162
|
+
(merged[deprecated] as VelocityConfig[K2]) = value as VelocityConfig[K2];
|
|
163
|
+
};
|
|
164
|
+
|
|
143
165
|
export const initialize = (props: {
|
|
144
|
-
env:
|
|
166
|
+
env: LegacyVelocityEnv;
|
|
145
167
|
overrideEnv?: Partial<VelocityConfig>;
|
|
146
168
|
}): VelocityConfig => {
|
|
147
169
|
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;
|
|
170
|
+
const normalizedEnv: VelocityEnv =
|
|
171
|
+
props.env === 'master' ? 'devnet' : props.env;
|
|
172
|
+
const merged: VelocityConfig = { ...configs[normalizedEnv], ...override };
|
|
173
|
+
|
|
174
|
+
mirrorAlias(merged, override, 'VELOCITY_PROGRAM_ID', 'DRIFT_PROGRAM_ID');
|
|
175
|
+
mirrorAlias(
|
|
176
|
+
merged,
|
|
177
|
+
override,
|
|
178
|
+
'VELOCITY_ORACLE_RECEIVER_ID',
|
|
179
|
+
'DRIFT_ORACLE_RECEIVER_ID'
|
|
180
|
+
);
|
|
172
181
|
|
|
173
182
|
currentConfig = merged;
|
|
174
183
|
return currentConfig;
|
|
@@ -215,7 +224,9 @@ export function getMarketsAndOraclesForSubscription(
|
|
|
215
224
|
};
|
|
216
225
|
}
|
|
217
226
|
|
|
218
|
-
export async function findAllMarketAndOracles(
|
|
227
|
+
export async function findAllMarketAndOracles(
|
|
228
|
+
program: VelocityProgram
|
|
229
|
+
): Promise<{
|
|
219
230
|
perpMarketIndexes: number[];
|
|
220
231
|
perpMarketAccounts: PerpMarketAccount[];
|
|
221
232
|
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;
|
package/src/decode/user.ts
CHANGED
|
@@ -143,8 +143,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
143
143
|
const orders: Order[] = [];
|
|
144
144
|
for (let i = 0; i < 32; i++) {
|
|
145
145
|
// skip order if it's not open
|
|
146
|
-
if (buffer.readUint8(offset +
|
|
147
|
-
offset +=
|
|
146
|
+
if (buffer.readUint8(offset + 86) !== 1) {
|
|
147
|
+
offset += 104;
|
|
148
148
|
continue;
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -166,8 +166,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
166
166
|
offset += 8;
|
|
167
167
|
const maxTs = readSignedBigInt64LE(buffer, offset);
|
|
168
168
|
offset += 8;
|
|
169
|
-
const oraclePriceOffset = buffer
|
|
170
|
-
offset +=
|
|
169
|
+
const oraclePriceOffset = readSignedBigInt64LE(buffer, offset);
|
|
170
|
+
offset += 8;
|
|
171
171
|
const orderId = buffer.readUInt32LE(offset);
|
|
172
172
|
offset += 4;
|
|
173
173
|
const marketIndex = buffer.readUInt16LE(offset);
|
|
@@ -245,7 +245,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
245
245
|
offset += 1;
|
|
246
246
|
const bitFlags = buffer.readUint8(offset);
|
|
247
247
|
offset += 1;
|
|
248
|
-
offset +=
|
|
248
|
+
offset += 5; // padding
|
|
249
249
|
orders.push({
|
|
250
250
|
slot,
|
|
251
251
|
price,
|
package/src/dlob/DLOB.ts
CHANGED
|
@@ -333,7 +333,7 @@ export class DLOB {
|
|
|
333
333
|
isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])
|
|
334
334
|
) {
|
|
335
335
|
type = 'market';
|
|
336
|
-
} else if (order.oraclePriceOffset
|
|
336
|
+
} else if (!order.oraclePriceOffset.eq(ZERO)) {
|
|
337
337
|
type = 'floatingLimit';
|
|
338
338
|
} else {
|
|
339
339
|
const isResting = isRestingLimitOrder(order, slot);
|
package/src/dlob/DLOBNode.ts
CHANGED
|
@@ -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;
|