@drift-labs/sdk 2.93.0-beta.6 → 2.93.0-beta.8
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/driftClient.d.ts +2 -0
- package/lib/driftClient.js +17 -0
- package/lib/idl/drift.json +18 -2
- 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/driftClient.ts +34 -0
- package/src/idl/drift.json +18 -2
- package/src/orderSubscriber/OrderSubscriber.ts +10 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.93.0-beta.
|
|
1
|
+
2.93.0-beta.8
|
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>;
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -640,6 +640,8 @@ export declare class DriftClient {
|
|
|
640
640
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
641
641
|
settleMultiplePNLs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature>;
|
|
642
642
|
settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
|
|
643
|
+
getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
|
|
644
|
+
setUserStatusToBeingLiquidated(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionSignature>;
|
|
643
645
|
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
|
644
646
|
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
|
|
645
647
|
liquidatePerpWithFill(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
package/lib/driftClient.js
CHANGED
|
@@ -3210,6 +3210,23 @@ class DriftClient {
|
|
|
3210
3210
|
remainingAccounts: remainingAccounts,
|
|
3211
3211
|
});
|
|
3212
3212
|
}
|
|
3213
|
+
async getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey, userAccount) {
|
|
3214
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
3215
|
+
userAccounts: [userAccount],
|
|
3216
|
+
});
|
|
3217
|
+
return await this.program.instruction.setUserStatusToBeingLiquidated({
|
|
3218
|
+
accounts: {
|
|
3219
|
+
state: await this.getStatePublicKey(),
|
|
3220
|
+
user: userAccountPublicKey,
|
|
3221
|
+
authority: this.wallet.publicKey,
|
|
3222
|
+
},
|
|
3223
|
+
remainingAccounts,
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
async setUserStatusToBeingLiquidated(userAccountPublicKey, userAccount) {
|
|
3227
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey, userAccount)), [], this.opts);
|
|
3228
|
+
return txSig;
|
|
3229
|
+
}
|
|
3213
3230
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams, liquidatorSubAccountId) {
|
|
3214
3231
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
3215
3232
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
package/lib/idl/drift.json
CHANGED
|
@@ -1881,6 +1881,22 @@
|
|
|
1881
1881
|
}
|
|
1882
1882
|
]
|
|
1883
1883
|
},
|
|
1884
|
+
{
|
|
1885
|
+
"name": "setUserStatusToBeingLiquidated",
|
|
1886
|
+
"accounts": [
|
|
1887
|
+
{
|
|
1888
|
+
"name": "state",
|
|
1889
|
+
"isMut": false,
|
|
1890
|
+
"isSigner": false
|
|
1891
|
+
},
|
|
1892
|
+
{
|
|
1893
|
+
"name": "user",
|
|
1894
|
+
"isMut": true,
|
|
1895
|
+
"isSigner": false
|
|
1896
|
+
}
|
|
1897
|
+
],
|
|
1898
|
+
"args": []
|
|
1899
|
+
},
|
|
1884
1900
|
{
|
|
1885
1901
|
"name": "resolvePerpPnlDeficit",
|
|
1886
1902
|
"accounts": [
|
|
@@ -2259,7 +2275,7 @@
|
|
|
2259
2275
|
},
|
|
2260
2276
|
{
|
|
2261
2277
|
"name": "spotMarket",
|
|
2262
|
-
"isMut":
|
|
2278
|
+
"isMut": true,
|
|
2263
2279
|
"isSigner": false
|
|
2264
2280
|
},
|
|
2265
2281
|
{
|
|
@@ -2295,7 +2311,7 @@
|
|
|
2295
2311
|
},
|
|
2296
2312
|
{
|
|
2297
2313
|
"name": "spotMarket",
|
|
2298
|
-
"isMut":
|
|
2314
|
+
"isMut": true,
|
|
2299
2315
|
"isSigner": false
|
|
2300
2316
|
},
|
|
2301
2317
|
{
|
|
@@ -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
package/src/driftClient.ts
CHANGED
|
@@ -5946,6 +5946,40 @@ export class DriftClient {
|
|
|
5946
5946
|
);
|
|
5947
5947
|
}
|
|
5948
5948
|
|
|
5949
|
+
public async getSetUserStatusToBeingLiquidatedIx(
|
|
5950
|
+
userAccountPublicKey: PublicKey,
|
|
5951
|
+
userAccount: UserAccount
|
|
5952
|
+
): Promise<TransactionInstruction> {
|
|
5953
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
5954
|
+
userAccounts: [userAccount],
|
|
5955
|
+
});
|
|
5956
|
+
return await this.program.instruction.setUserStatusToBeingLiquidated({
|
|
5957
|
+
accounts: {
|
|
5958
|
+
state: await this.getStatePublicKey(),
|
|
5959
|
+
user: userAccountPublicKey,
|
|
5960
|
+
authority: this.wallet.publicKey,
|
|
5961
|
+
},
|
|
5962
|
+
remainingAccounts,
|
|
5963
|
+
});
|
|
5964
|
+
}
|
|
5965
|
+
|
|
5966
|
+
public async setUserStatusToBeingLiquidated(
|
|
5967
|
+
userAccountPublicKey: PublicKey,
|
|
5968
|
+
userAccount: UserAccount
|
|
5969
|
+
): Promise<TransactionSignature> {
|
|
5970
|
+
const { txSig } = await this.sendTransaction(
|
|
5971
|
+
await this.buildTransaction(
|
|
5972
|
+
await this.getSetUserStatusToBeingLiquidatedIx(
|
|
5973
|
+
userAccountPublicKey,
|
|
5974
|
+
userAccount
|
|
5975
|
+
)
|
|
5976
|
+
),
|
|
5977
|
+
[],
|
|
5978
|
+
this.opts
|
|
5979
|
+
);
|
|
5980
|
+
return txSig;
|
|
5981
|
+
}
|
|
5982
|
+
|
|
5949
5983
|
public async liquidatePerp(
|
|
5950
5984
|
userAccountPublicKey: PublicKey,
|
|
5951
5985
|
userAccount: UserAccount,
|
package/src/idl/drift.json
CHANGED
|
@@ -1881,6 +1881,22 @@
|
|
|
1881
1881
|
}
|
|
1882
1882
|
]
|
|
1883
1883
|
},
|
|
1884
|
+
{
|
|
1885
|
+
"name": "setUserStatusToBeingLiquidated",
|
|
1886
|
+
"accounts": [
|
|
1887
|
+
{
|
|
1888
|
+
"name": "state",
|
|
1889
|
+
"isMut": false,
|
|
1890
|
+
"isSigner": false
|
|
1891
|
+
},
|
|
1892
|
+
{
|
|
1893
|
+
"name": "user",
|
|
1894
|
+
"isMut": true,
|
|
1895
|
+
"isSigner": false
|
|
1896
|
+
}
|
|
1897
|
+
],
|
|
1898
|
+
"args": []
|
|
1899
|
+
},
|
|
1884
1900
|
{
|
|
1885
1901
|
"name": "resolvePerpPnlDeficit",
|
|
1886
1902
|
"accounts": [
|
|
@@ -2259,7 +2275,7 @@
|
|
|
2259
2275
|
},
|
|
2260
2276
|
{
|
|
2261
2277
|
"name": "spotMarket",
|
|
2262
|
-
"isMut":
|
|
2278
|
+
"isMut": true,
|
|
2263
2279
|
"isSigner": false
|
|
2264
2280
|
},
|
|
2265
2281
|
{
|
|
@@ -2295,7 +2311,7 @@
|
|
|
2295
2311
|
},
|
|
2296
2312
|
{
|
|
2297
2313
|
"name": "spotMarket",
|
|
2298
|
-
"isMut":
|
|
2314
|
+
"isMut": true,
|
|
2299
2315
|
"isSigner": false
|
|
2300
2316
|
},
|
|
2301
2317
|
{
|
|
@@ -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);
|