Skip to content

Commit 24e1275

Browse files
ChesterSim0xbigz
authored andcommitted
Improve Circular Dependencies 2 (#1778)
1 parent 8b8b824 commit 24e1275

29 files changed

+4745
-219
lines changed

bun.lock

Lines changed: 1072 additions & 0 deletions
Large diffs are not rendered by default.

sdk/src/dlob/DLOB.ts

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ZERO,
1010
} from '../constants/numericConstants';
1111
import { decodeName } from '../userName';
12-
import { DLOBNode, DLOBNodeType, TriggerOrderNode } from './DLOBNode';
12+
import { DLOBNode, DLOBNodeType } from './DLOBNode';
1313
import { DriftClient } from '../driftClient';
1414
import {
1515
getLimitPrice,
@@ -33,9 +33,18 @@ import {
3333
} from '../types';
3434
import { isUserProtectedMaker } from '../math/userStatus';
3535
import { OraclePriceData } from '../oracles/types';
36-
import { ProtectMakerParamsMap } from './types';
36+
import {
37+
DLOBFilterFcn,
38+
DLOBOrders,
39+
IDLOB,
40+
MarketNodeLists,
41+
NodeToFill,
42+
NodeToTrigger,
43+
OrderBookCallback,
44+
ProtectMakerParamsMap,
45+
} from './types';
3746
import { SlotSubscriber } from '../slot/SlotSubscriber';
38-
import { UserMap } from '../userMap/userMap';
47+
import { IUserMap } from '../userMap/types';
3948
import { PublicKey } from '@solana/web3.js';
4049
import { ammPaused, exchangePaused, fillPaused } from '../math/exchangeStatus';
4150
import {
@@ -50,59 +59,6 @@ import {
5059
import { isFallbackAvailableLiquiditySource } from '../math/auction';
5160
import { convertToNumber } from '../math/conversion';
5261

53-
export type DLOBOrder = { user: PublicKey; order: Order };
54-
export type DLOBOrders = DLOBOrder[];
55-
56-
export type MarketNodeLists = {
57-
restingLimit: {
58-
ask: NodeList<'restingLimit'>;
59-
bid: NodeList<'restingLimit'>;
60-
};
61-
floatingLimit: {
62-
ask: NodeList<'floatingLimit'>;
63-
bid: NodeList<'floatingLimit'>;
64-
};
65-
protectedFloatingLimit: {
66-
ask: NodeList<'protectedFloatingLimit'>;
67-
bid: NodeList<'protectedFloatingLimit'>;
68-
};
69-
takingLimit: {
70-
ask: NodeList<'takingLimit'>;
71-
bid: NodeList<'takingLimit'>;
72-
};
73-
market: {
74-
ask: NodeList<'market'>;
75-
bid: NodeList<'market'>;
76-
};
77-
trigger: {
78-
above: NodeList<'trigger'>;
79-
below: NodeList<'trigger'>;
80-
};
81-
signedMsg: {
82-
ask: NodeList<'signedMsg'>;
83-
bid: NodeList<'signedMsg'>;
84-
};
85-
};
86-
87-
type OrderBookCallback = () => void;
88-
89-
/**
90-
* Receives a DLOBNode and is expected to return true if the node should
91-
* be taken into account when generating, or false otherwise.
92-
*
93-
* Currently used in functions that rely on getBestNode
94-
*/
95-
export type DLOBFilterFcn = (node: DLOBNode) => boolean;
96-
97-
export type NodeToFill = {
98-
node: DLOBNode;
99-
makerNodes: DLOBNode[];
100-
};
101-
102-
export type NodeToTrigger = {
103-
node: TriggerOrderNode;
104-
};
105-
10662
const SUPPORTED_ORDER_TYPES = [
10763
'market',
10864
'limit',
@@ -111,7 +67,7 @@ const SUPPORTED_ORDER_TYPES = [
11167
'oracle',
11268
];
11369

114-
export class DLOB {
70+
export class DLOB implements IDLOB {
11571
openOrders = new Map<MarketTypeStr, Set<string>>();
11672
orderLists = new Map<MarketTypeStr, Map<number, MarketNodeLists>>();
11773
maxSlotForRestingLimitOrders = 0;
@@ -166,7 +122,7 @@ export class DLOB {
166122
* @returns a promise that resolves when the DLOB is initialized
167123
*/
168124
public async initFromUserMap(
169-
userMap: UserMap,
125+
userMap: IUserMap,
170126
slot: number
171127
): Promise<boolean> {
172128
if (this.initialized) {

sdk/src/dlob/DLOBSubscriber.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
DLOBSource,
66
DLOBSubscriberEvents,
77
DLOBSubscriptionConfig,
8+
IDLOB,
89
ProtectMakerParamsMap,
910
SlotSource,
1011
} from './types';
11-
import { DriftClient } from '../driftClient';
1212
import { isVariant, MarketType } from '../types';
1313
import {
1414
DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS,
@@ -19,14 +19,15 @@ import {
1919
L3OrderBook,
2020
} from './orderBookLevels';
2121
import { getProtectedMakerParamsMap } from '../math/protectedMakerParams';
22+
import { IDriftClient } from '../driftClient/types';
2223

2324
export class DLOBSubscriber {
24-
driftClient: DriftClient;
25+
driftClient: IDriftClient;
2526
dlobSource: DLOBSource;
2627
slotSource: SlotSource;
2728
updateFrequency: number;
2829
intervalId?: ReturnType<typeof setTimeout>;
29-
dlob: DLOB;
30+
dlob: IDLOB;
3031
public eventEmitter: StrictEventEmitter<EventEmitter, DLOBSubscriberEvents>;
3132
protectedMakerView: boolean;
3233
constructor(config: DLOBSubscriptionConfig) {
@@ -69,7 +70,7 @@ export class DLOBSubscriber {
6970
);
7071
}
7172

72-
public getDLOB(): DLOB {
73+
public getDLOB(): IDLOB {
7374
return this.dlob;
7475
}
7576

sdk/src/dlob/orderBookLevels.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
} from '../types';
2525
import { OraclePriceData } from '../oracles/types';
2626
import { PublicKey } from '@solana/web3.js';
27-
import { standardizeBaseAssetAmount, standardizePrice } from '../math/orders';
27+
import { standardizePrice } from '../math/orders';
28+
import { standardizeBaseAssetAmount } from '../math/utils';
2829

2930
type liquiditySource =
3031
| 'serum'

0 commit comments

Comments
 (0)