@drift-labs/sdk 2.93.0-beta.7 → 2.93.0-beta.9
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/dlob/DLOB.d.ts +1 -1
- package/lib/orderSubscriber/OrderSubscriber.d.ts +6 -0
- package/lib/orderSubscriber/OrderSubscriber.js +9 -1
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +1 -1
- package/src/orderSubscriber/OrderSubscriber.ts +10 -1
- package/tests/dlob/helpers.ts +3 -0
- package/tests/dlob/test.ts +2 -7
- package/tests/subscriber/openbook.ts +4 -0
- package/tests/user/test.ts +12 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.93.0-beta.
|
|
1
|
+
2.93.0-beta.9
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare class DLOB {
|
|
|
81
81
|
findJitAuctionNodesToFill(marketIndex: number, slot: number, oraclePriceData: OraclePriceData, marketType: MarketType): NodeToFill[];
|
|
82
82
|
getTakingBids(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
83
83
|
getTakingAsks(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
84
|
-
|
|
84
|
+
protected getBestNode(generatorList: Array<Generator<DLOBNode>>, oraclePriceData: OraclePriceData, slot: number, compareFcn: (bestDLOBNode: DLOBNode, currentDLOBNode: DLOBNode, slot: number, oraclePriceData: OraclePriceData) => boolean, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
85
85
|
getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
86
86
|
getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
87
87
|
getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
@@ -28,6 +28,12 @@ export declare class OrderSubscriber {
|
|
|
28
28
|
subscribe(): Promise<void>;
|
|
29
29
|
fetch(): Promise<void>;
|
|
30
30
|
tryUpdateUserAccount(key: string, dataType: 'raw' | 'decoded' | 'buffer', data: string[] | UserAccount | Buffer, slot: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new DLOB for the order subscriber to fill. This will allow a
|
|
33
|
+
* caller to extend the DLOB Subscriber with a custom DLOB type.
|
|
34
|
+
* @returns New, empty DLOB object.
|
|
35
|
+
*/
|
|
36
|
+
protected createDLOB(): DLOB;
|
|
31
37
|
getDLOB(slot: number): Promise<DLOB>;
|
|
32
38
|
getSlot(): number;
|
|
33
39
|
unsubscribe(): Promise<void>;
|
|
@@ -141,8 +141,16 @@ class OrderSubscriber {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a new DLOB for the order subscriber to fill. This will allow a
|
|
146
|
+
* caller to extend the DLOB Subscriber with a custom DLOB type.
|
|
147
|
+
* @returns New, empty DLOB object.
|
|
148
|
+
*/
|
|
149
|
+
createDLOB() {
|
|
150
|
+
return new DLOB_1.DLOB();
|
|
151
|
+
}
|
|
144
152
|
async getDLOB(slot) {
|
|
145
|
-
const dlob =
|
|
153
|
+
const dlob = this.createDLOB();
|
|
146
154
|
for (const [key, { userAccount }] of this.usersAccounts.entries()) {
|
|
147
155
|
for (const order of userAccount.orders) {
|
|
148
156
|
dlob.insertOrder(order, key, slot);
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -217,8 +217,17 @@ export class OrderSubscriber {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Creates a new DLOB for the order subscriber to fill. This will allow a
|
|
222
|
+
* caller to extend the DLOB Subscriber with a custom DLOB type.
|
|
223
|
+
* @returns New, empty DLOB object.
|
|
224
|
+
*/
|
|
225
|
+
protected createDLOB(): DLOB {
|
|
226
|
+
return new DLOB();
|
|
227
|
+
}
|
|
228
|
+
|
|
220
229
|
public async getDLOB(slot: number): Promise<DLOB> {
|
|
221
|
-
const dlob =
|
|
230
|
+
const dlob = this.createDLOB();
|
|
222
231
|
for (const [key, { userAccount }] of this.usersAccounts.entries()) {
|
|
223
232
|
for (const order of userAccount.orders) {
|
|
224
233
|
dlob.insertOrder(order, key, slot);
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -367,6 +367,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
367
367
|
fuelBoostTaker: 0,
|
|
368
368
|
fuelBoostMaker: 0,
|
|
369
369
|
fuelBoostInsurance: 0,
|
|
370
|
+
tokenProgram: 0,
|
|
370
371
|
},
|
|
371
372
|
{
|
|
372
373
|
status: MarketStatus.ACTIVE,
|
|
@@ -457,6 +458,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
457
458
|
fuelBoostTaker: 0,
|
|
458
459
|
fuelBoostMaker: 0,
|
|
459
460
|
fuelBoostInsurance: 0,
|
|
461
|
+
tokenProgram: 0,
|
|
460
462
|
},
|
|
461
463
|
{
|
|
462
464
|
status: MarketStatus.ACTIVE,
|
|
@@ -547,6 +549,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
547
549
|
fuelBoostTaker: 0,
|
|
548
550
|
fuelBoostMaker: 0,
|
|
549
551
|
fuelBoostInsurance: 0,
|
|
552
|
+
tokenProgram: 0,
|
|
550
553
|
},
|
|
551
554
|
];
|
|
552
555
|
|
package/tests/dlob/test.ts
CHANGED
|
@@ -4931,15 +4931,10 @@ describe('DLOB Spot Tests', () => {
|
|
|
4931
4931
|
`cross found: taker orderId: ${n.node.order?.orderId.toString()}: BAA: ${n.node.order?.baseAssetAmountFilled.toString()}/${n.node.order?.baseAssetAmount.toString()}, maker orderId: ${n.makerNodes[0]?.order?.orderId.toString()}: BAA: ${n.makerNodes[0]?.order?.baseAssetAmountFilled.toString()}/${n.makerNodes[0]?.order?.baseAssetAmount.toString()}`
|
|
4932
4932
|
);
|
|
4933
4933
|
}
|
|
4934
|
-
expect(nodesToFillAfter.length).to.equal(
|
|
4934
|
+
expect(nodesToFillAfter.length).to.equal(1);
|
|
4935
4935
|
|
|
4936
4936
|
// taker should fill completely with best maker
|
|
4937
|
-
expect(nodesToFillAfter[0].
|
|
4938
|
-
expect(nodesToFillAfter[0].makerNodes[0]?.order?.orderId).to.equal(3);
|
|
4939
|
-
|
|
4940
|
-
// taker should fill completely with second best maker
|
|
4941
|
-
expect(nodesToFillAfter[1].node.order?.orderId).to.equal(4);
|
|
4942
|
-
expect(nodesToFillAfter[1].makerNodes[0]?.order?.orderId).to.equal(2);
|
|
4937
|
+
expect(nodesToFillAfter[0].makerNodes.length).to.equal(2);
|
|
4943
4938
|
});
|
|
4944
4939
|
|
|
4945
4940
|
it('Test two market orders to fill one limit order', () => {
|
package/tests/user/test.ts
CHANGED
|
@@ -82,10 +82,22 @@ async function makeMockUser(
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
function getOracleDataForPerpMarket(marketIndex) {
|
|
86
|
+
const oracle = getMockPerpMarket(marketIndex).amm.oracle;
|
|
87
|
+
return getMockOracle(oracle).data;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getOracleDataForSpotMarket(marketIndex) {
|
|
91
|
+
const oracle = getMockSpotMarket(marketIndex).oracle;
|
|
92
|
+
return getMockOracle(oracle).data;
|
|
93
|
+
}
|
|
94
|
+
|
|
85
95
|
mockUser.getUserAccount = getMockUserAccount;
|
|
86
96
|
mockUser.driftClient.getPerpMarketAccount = getMockPerpMarket;
|
|
87
97
|
mockUser.driftClient.getSpotMarketAccount = getMockSpotMarket;
|
|
88
98
|
mockUser.driftClient.getOraclePriceDataAndSlot = getMockOracle;
|
|
99
|
+
mockUser.driftClient.getOracleDataForPerpMarket = getOracleDataForPerpMarket;
|
|
100
|
+
mockUser.driftClient.getOracleDataForSpotMarket = getOracleDataForSpotMarket;
|
|
89
101
|
return mockUser;
|
|
90
102
|
}
|
|
91
103
|
|