@drift-labs/sdk 2.87.0-beta.7 → 2.87.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 CHANGED
@@ -1 +1 @@
1
- 2.87.0-beta.7
1
+ 2.87.0-beta.8
@@ -640,6 +640,8 @@ export declare class DriftClient {
640
640
  settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
641
641
  liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
642
642
  getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
643
+ liquidatePerpWithFill(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
644
+ getLiquidatePerpWithFillIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
643
645
  liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
644
646
  getLiquidateSpotIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
645
647
  liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
@@ -3228,6 +3228,44 @@ class DriftClient {
3228
3228
  remainingAccounts: remainingAccounts,
3229
3229
  });
3230
3230
  }
3231
+ async liquidatePerpWithFill(userAccountPublicKey, userAccount, marketIndex, makerInfos, txParams, liquidatorSubAccountId) {
3232
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId), txParams), [], this.opts);
3233
+ this.perpMarketLastSlotCache.set(marketIndex, slot);
3234
+ return txSig;
3235
+ }
3236
+ async getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId) {
3237
+ const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
3238
+ const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
3239
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
3240
+ const remainingAccounts = this.getRemainingAccounts({
3241
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
3242
+ useMarketLastSlotCache: true,
3243
+ writablePerpMarketIndexes: [marketIndex],
3244
+ });
3245
+ for (const makerInfo of makerInfos) {
3246
+ remainingAccounts.push({
3247
+ pubkey: makerInfo.maker,
3248
+ isSigner: false,
3249
+ isWritable: true,
3250
+ });
3251
+ remainingAccounts.push({
3252
+ pubkey: makerInfo.makerStats,
3253
+ isSigner: false,
3254
+ isWritable: true,
3255
+ });
3256
+ }
3257
+ return await this.program.instruction.liquidatePerpWithFill(marketIndex, {
3258
+ accounts: {
3259
+ state: await this.getStatePublicKey(),
3260
+ authority: this.wallet.publicKey,
3261
+ user: userAccountPublicKey,
3262
+ userStats: userStatsPublicKey,
3263
+ liquidator,
3264
+ liquidatorStats: liquidatorStatsPublicKey,
3265
+ },
3266
+ remainingAccounts: remainingAccounts,
3267
+ });
3268
+ }
3231
3269
  async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
3232
3270
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
3233
3271
  this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
@@ -1675,6 +1675,47 @@
1675
1675
  }
1676
1676
  ]
1677
1677
  },
1678
+ {
1679
+ "name": "liquidatePerpWithFill",
1680
+ "accounts": [
1681
+ {
1682
+ "name": "state",
1683
+ "isMut": false,
1684
+ "isSigner": false
1685
+ },
1686
+ {
1687
+ "name": "authority",
1688
+ "isMut": false,
1689
+ "isSigner": true
1690
+ },
1691
+ {
1692
+ "name": "liquidator",
1693
+ "isMut": true,
1694
+ "isSigner": false
1695
+ },
1696
+ {
1697
+ "name": "liquidatorStats",
1698
+ "isMut": true,
1699
+ "isSigner": false
1700
+ },
1701
+ {
1702
+ "name": "user",
1703
+ "isMut": true,
1704
+ "isSigner": false
1705
+ },
1706
+ {
1707
+ "name": "userStats",
1708
+ "isMut": true,
1709
+ "isSigner": false
1710
+ }
1711
+ ],
1712
+ "args": [
1713
+ {
1714
+ "name": "marketIndex",
1715
+ "type": "u16"
1716
+ }
1717
+ ]
1718
+ },
1678
1719
  {
1679
1720
  "name": "liquidateSpot",
1680
1721
  "accounts": [
@@ -3362,27 +3403,6 @@
3362
3403
  }
3363
3404
  ]
3364
3405
  },
3365
- {
3366
- "name": "initializePredictionMarket",
3367
- "accounts": [
3368
- {
3369
- "name": "admin",
3370
- "isMut": false,
3371
- "isSigner": true
3372
- },
3373
- {
3374
- "name": "state",
3375
- "isMut": false,
3376
- "isSigner": false
3377
- },
3378
- {
3379
- "name": "perpMarket",
3380
- "isMut": true,
3381
- "isSigner": false
3382
- }
3383
- ],
3384
- "args": []
3385
- },
3386
3406
  {
3387
3407
  "name": "deleteInitializedPerpMarket",
3388
3408
  "accounts": [
@@ -9858,6 +9878,9 @@
9858
9878
  },
9859
9879
  {
9860
9880
  "name": "PlaceAndTake"
9881
+ },
9882
+ {
9883
+ "name": "Liquidation"
9861
9884
  }
9862
9885
  ]
9863
9886
  }
@@ -10125,9 +10148,6 @@
10125
10148
  },
10126
10149
  {
10127
10150
  "name": "Future"
10128
- },
10129
- {
10130
- "name": "Prediction"
10131
10151
  }
10132
10152
  ]
10133
10153
  }
@@ -12797,6 +12817,11 @@
12797
12817
  "code": 6282,
12798
12818
  "name": "NonZeroTransferFee",
12799
12819
  "msg": "Non zero transfer fee"
12820
+ },
12821
+ {
12822
+ "code": 6283,
12823
+ "name": "LiquidationOrderFailedToFill",
12824
+ "msg": "Liquidation order failed to fill"
12800
12825
  }
12801
12826
  ],
12802
12827
  "metadata": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.87.0-beta.7",
3
+ "version": "2.87.0-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -5990,6 +5990,81 @@ export class DriftClient {
5990
5990
  );
5991
5991
  }
5992
5992
 
5993
+ public async liquidatePerpWithFill(
5994
+ userAccountPublicKey: PublicKey,
5995
+ userAccount: UserAccount,
5996
+ marketIndex: number,
5997
+ makerInfos: MakerInfo[],
5998
+ txParams?: TxParams,
5999
+ liquidatorSubAccountId?: number
6000
+ ): Promise<TransactionSignature> {
6001
+ const { txSig, slot } = await this.sendTransaction(
6002
+ await this.buildTransaction(
6003
+ await this.getLiquidatePerpWithFillIx(
6004
+ userAccountPublicKey,
6005
+ userAccount,
6006
+ marketIndex,
6007
+ makerInfos,
6008
+ liquidatorSubAccountId
6009
+ ),
6010
+ txParams
6011
+ ),
6012
+ [],
6013
+ this.opts
6014
+ );
6015
+ this.perpMarketLastSlotCache.set(marketIndex, slot);
6016
+ return txSig;
6017
+ }
6018
+
6019
+ public async getLiquidatePerpWithFillIx(
6020
+ userAccountPublicKey: PublicKey,
6021
+ userAccount: UserAccount,
6022
+ marketIndex: number,
6023
+ makerInfos: MakerInfo[],
6024
+ liquidatorSubAccountId?: number
6025
+ ): Promise<TransactionInstruction> {
6026
+ const userStatsPublicKey = getUserStatsAccountPublicKey(
6027
+ this.program.programId,
6028
+ userAccount.authority
6029
+ );
6030
+
6031
+ const liquidator = await this.getUserAccountPublicKey(
6032
+ liquidatorSubAccountId
6033
+ );
6034
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
6035
+
6036
+ const remainingAccounts = this.getRemainingAccounts({
6037
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
6038
+ useMarketLastSlotCache: true,
6039
+ writablePerpMarketIndexes: [marketIndex],
6040
+ });
6041
+
6042
+ for (const makerInfo of makerInfos) {
6043
+ remainingAccounts.push({
6044
+ pubkey: makerInfo.maker,
6045
+ isSigner: false,
6046
+ isWritable: true,
6047
+ });
6048
+ remainingAccounts.push({
6049
+ pubkey: makerInfo.makerStats,
6050
+ isSigner: false,
6051
+ isWritable: true,
6052
+ });
6053
+ }
6054
+
6055
+ return await this.program.instruction.liquidatePerpWithFill(marketIndex, {
6056
+ accounts: {
6057
+ state: await this.getStatePublicKey(),
6058
+ authority: this.wallet.publicKey,
6059
+ user: userAccountPublicKey,
6060
+ userStats: userStatsPublicKey,
6061
+ liquidator,
6062
+ liquidatorStats: liquidatorStatsPublicKey,
6063
+ },
6064
+ remainingAccounts: remainingAccounts,
6065
+ });
6066
+ }
6067
+
5993
6068
  public async liquidateSpot(
5994
6069
  userAccountPublicKey: PublicKey,
5995
6070
  userAccount: UserAccount,
@@ -1675,6 +1675,47 @@
1675
1675
  }
1676
1676
  ]
1677
1677
  },
1678
+ {
1679
+ "name": "liquidatePerpWithFill",
1680
+ "accounts": [
1681
+ {
1682
+ "name": "state",
1683
+ "isMut": false,
1684
+ "isSigner": false
1685
+ },
1686
+ {
1687
+ "name": "authority",
1688
+ "isMut": false,
1689
+ "isSigner": true
1690
+ },
1691
+ {
1692
+ "name": "liquidator",
1693
+ "isMut": true,
1694
+ "isSigner": false
1695
+ },
1696
+ {
1697
+ "name": "liquidatorStats",
1698
+ "isMut": true,
1699
+ "isSigner": false
1700
+ },
1701
+ {
1702
+ "name": "user",
1703
+ "isMut": true,
1704
+ "isSigner": false
1705
+ },
1706
+ {
1707
+ "name": "userStats",
1708
+ "isMut": true,
1709
+ "isSigner": false
1710
+ }
1711
+ ],
1712
+ "args": [
1713
+ {
1714
+ "name": "marketIndex",
1715
+ "type": "u16"
1716
+ }
1717
+ ]
1718
+ },
1678
1719
  {
1679
1720
  "name": "liquidateSpot",
1680
1721
  "accounts": [
@@ -3362,27 +3403,6 @@
3362
3403
  }
3363
3404
  ]
3364
3405
  },
3365
- {
3366
- "name": "initializePredictionMarket",
3367
- "accounts": [
3368
- {
3369
- "name": "admin",
3370
- "isMut": false,
3371
- "isSigner": true
3372
- },
3373
- {
3374
- "name": "state",
3375
- "isMut": false,
3376
- "isSigner": false
3377
- },
3378
- {
3379
- "name": "perpMarket",
3380
- "isMut": true,
3381
- "isSigner": false
3382
- }
3383
- ],
3384
- "args": []
3385
- },
3386
3406
  {
3387
3407
  "name": "deleteInitializedPerpMarket",
3388
3408
  "accounts": [
@@ -9858,6 +9878,9 @@
9858
9878
  },
9859
9879
  {
9860
9880
  "name": "PlaceAndTake"
9881
+ },
9882
+ {
9883
+ "name": "Liquidation"
9861
9884
  }
9862
9885
  ]
9863
9886
  }
@@ -10125,9 +10148,6 @@
10125
10148
  },
10126
10149
  {
10127
10150
  "name": "Future"
10128
- },
10129
- {
10130
- "name": "Prediction"
10131
10151
  }
10132
10152
  ]
10133
10153
  }
@@ -12797,9 +12817,14 @@
12797
12817
  "code": 6282,
12798
12818
  "name": "NonZeroTransferFee",
12799
12819
  "msg": "Non zero transfer fee"
12820
+ },
12821
+ {
12822
+ "code": 6283,
12823
+ "name": "LiquidationOrderFailedToFill",
12824
+ "msg": "Liquidation order failed to fill"
12800
12825
  }
12801
12826
  ],
12802
12827
  "metadata": {
12803
12828
  "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
12804
12829
  }
12805
- }
12830
+ }