@drift-labs/sdk 2.87.0-beta.1 → 2.87.0-beta.10

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.
Files changed (54) hide show
  1. package/VERSION +1 -1
  2. package/lib/addresses/pda.d.ts +2 -0
  3. package/lib/addresses/pda.js +9 -1
  4. package/lib/adminClient.d.ts +2 -0
  5. package/lib/adminClient.js +27 -4
  6. package/lib/bankrun/bankrunConnection.js +1 -1
  7. package/lib/config.d.ts +1 -0
  8. package/lib/config.js +2 -0
  9. package/lib/constants/perpMarkets.js +7 -7
  10. package/lib/constants/spotMarkets.d.ts +1 -0
  11. package/lib/constants/spotMarkets.js +10 -0
  12. package/lib/dlob/orderBookLevels.d.ts +1 -1
  13. package/lib/driftClient.d.ts +15 -5
  14. package/lib/driftClient.js +155 -41
  15. package/lib/events/types.d.ts +3 -2
  16. package/lib/events/types.js +1 -0
  17. package/lib/factory/oracleClient.js +4 -0
  18. package/lib/idl/drift.json +147 -5
  19. package/lib/idl/openbook.json +3854 -0
  20. package/lib/idl/switchboard_on_demand_30.json +4383 -0
  21. package/lib/index.d.ts +2 -0
  22. package/lib/index.js +2 -0
  23. package/lib/math/spotMarket.d.ts +6 -0
  24. package/lib/math/spotMarket.js +16 -1
  25. package/lib/math/superStake.d.ts +3 -2
  26. package/lib/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
  27. package/lib/openbook/openbookV2FulfillmentConfigMap.js +17 -0
  28. package/lib/openbook/openbookV2Subscriber.d.ts +36 -0
  29. package/lib/openbook/openbookV2Subscriber.js +102 -0
  30. package/lib/oracles/switchboardOnDemandClient.d.ts +11 -0
  31. package/lib/oracles/switchboardOnDemandClient.js +32 -0
  32. package/lib/types.d.ts +13 -0
  33. package/lib/types.js +1 -0
  34. package/package.json +6 -2
  35. package/src/addresses/pda.ts +10 -0
  36. package/src/adminClient.ts +47 -4
  37. package/src/bankrun/bankrunConnection.ts +2 -2
  38. package/src/config.ts +3 -0
  39. package/src/constants/perpMarkets.ts +7 -7
  40. package/src/constants/spotMarkets.ts +12 -0
  41. package/src/dlob/orderBookLevels.ts +1 -1
  42. package/src/driftClient.ts +229 -52
  43. package/src/events/types.ts +5 -1
  44. package/src/factory/oracleClient.ts +5 -0
  45. package/src/idl/drift.json +147 -5
  46. package/src/idl/switchboard_on_demand_30.json +4383 -0
  47. package/src/index.ts +2 -0
  48. package/src/math/spotMarket.ts +28 -2
  49. package/src/openbook/openbookV2FulfillmentConfigMap.ts +29 -0
  50. package/src/openbook/openbookV2Subscriber.ts +165 -0
  51. package/src/oracles/switchboardOnDemandClient.ts +56 -0
  52. package/src/types.ts +13 -0
  53. package/tests/ci/verifyConstants.ts +3 -6
  54. package/tests/subscriber/openbook.ts +58 -0
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.DriftClient = void 0;
30
30
  const anchor_1 = require("@coral-xyz/anchor");
31
+ const anchor_30_1 = require("@coral-xyz/anchor-30");
31
32
  const bs58_1 = __importDefault(require("bs58"));
32
33
  const spl_token_1 = require("@solana/spl-token");
33
34
  const types_1 = require("./types");
@@ -65,6 +66,8 @@ const config_2 = require("./config");
65
66
  const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
66
67
  const utils_2 = require("./tx/utils");
67
68
  const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
69
+ const on_demand_1 = require("@switchboard-xyz/on-demand");
70
+ const switchboard_on_demand_30_json_1 = __importDefault(require("./idl/switchboard_on_demand_30.json"));
68
71
  /**
69
72
  * # DriftClient
70
73
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -1059,7 +1062,7 @@ class DriftClient {
1059
1062
  const mint = spotMarket.mint;
1060
1063
  return await (0, spl_token_1.getAssociatedTokenAddress)(mint, this.wallet.publicKey);
1061
1064
  }
1062
- createAssociatedTokenAccountIdempotentInstruction(account, payer, owner, mint) {
1065
+ createAssociatedTokenAccountIdempotentInstruction(account, payer, owner, mint, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
1063
1066
  return new web3_js_1.TransactionInstruction({
1064
1067
  keys: [
1065
1068
  { pubkey: payer, isSigner: true, isWritable: true },
@@ -1071,7 +1074,7 @@ class DriftClient {
1071
1074
  isSigner: false,
1072
1075
  isWritable: false,
1073
1076
  },
1074
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
1077
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
1075
1078
  ],
1076
1079
  programId: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
1077
1080
  data: Buffer.from([0x1]),
@@ -1130,6 +1133,8 @@ class DriftClient {
1130
1133
  });
1131
1134
  }
1132
1135
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
1136
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
1137
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
1133
1138
  return await this.program.instruction.deposit(marketIndex, amount, reduceOnly, {
1134
1139
  accounts: {
1135
1140
  state: await this.getStatePublicKey(),
@@ -1139,7 +1144,7 @@ class DriftClient {
1139
1144
  userStats: this.getUserStatsAccountPublicKey(),
1140
1145
  userTokenAccount: userTokenAccount,
1141
1146
  authority: this.wallet.publicKey,
1142
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1147
+ tokenProgram,
1143
1148
  },
1144
1149
  remainingAccounts,
1145
1150
  });
@@ -1181,6 +1186,21 @@ class DriftClient {
1181
1186
  result.ixs.push((0, spl_token_1.createInitializeAccountInstruction)(wrappedSolAccount, spotMarkets_1.WRAPPED_SOL_MINT, authority));
1182
1187
  return result;
1183
1188
  }
1189
+ getTokenProgramForSpotMarket(spotMarketAccount) {
1190
+ if (spotMarketAccount.tokenProgram === 1) {
1191
+ return spl_token_1.TOKEN_2022_PROGRAM_ID;
1192
+ }
1193
+ return spl_token_1.TOKEN_PROGRAM_ID;
1194
+ }
1195
+ addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts) {
1196
+ if (spotMarketAccount.tokenProgram === 1) {
1197
+ remainingAccounts.push({
1198
+ pubkey: spotMarketAccount.mint,
1199
+ isSigner: false,
1200
+ isWritable: false,
1201
+ });
1202
+ }
1203
+ }
1184
1204
  getAssociatedTokenAccountCreationIx(tokenMintAddress, associatedTokenAddress) {
1185
1205
  return (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, associatedTokenAddress, this.wallet.publicKey, tokenMintAddress);
1186
1206
  }
@@ -1344,6 +1364,8 @@ class DriftClient {
1344
1364
  readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
1345
1365
  });
1346
1366
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
1367
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
1368
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
1347
1369
  return await this.program.instruction.withdraw(marketIndex, amount, reduceOnly, {
1348
1370
  accounts: {
1349
1371
  state: await this.getStatePublicKey(),
@@ -1354,7 +1376,7 @@ class DriftClient {
1354
1376
  userStats: this.getUserStatsAccountPublicKey(),
1355
1377
  userTokenAccount: userTokenAccount,
1356
1378
  authority: this.wallet.publicKey,
1357
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1379
+ tokenProgram,
1358
1380
  },
1359
1381
  remainingAccounts,
1360
1382
  });
@@ -2354,14 +2376,16 @@ class DriftClient {
2354
2376
  outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex, false);
2355
2377
  const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2356
2378
  if (!accountInfo) {
2357
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint));
2379
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2380
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint, tokenProgram));
2358
2381
  }
2359
2382
  }
2360
2383
  if (!inAssociatedTokenAccount) {
2361
2384
  inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false);
2362
2385
  const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2363
2386
  if (!accountInfo) {
2364
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint));
2387
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
2388
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
2365
2389
  }
2366
2390
  }
2367
2391
  const { beginSwapIx, endSwapIx } = await this.getSwapIx({
@@ -2476,6 +2500,27 @@ class DriftClient {
2476
2500
  });
2477
2501
  const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
2478
2502
  const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
2503
+ const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
2504
+ const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
2505
+ if (!outTokenProgram.equals(inTokenProgram)) {
2506
+ remainingAccounts.push({
2507
+ pubkey: outTokenProgram,
2508
+ isWritable: false,
2509
+ isSigner: false,
2510
+ });
2511
+ }
2512
+ if (outSpotMarket.tokenProgram === 1 || inSpotMarket.tokenProgram === 1) {
2513
+ remainingAccounts.push({
2514
+ pubkey: inSpotMarket.mint,
2515
+ isWritable: false,
2516
+ isSigner: false,
2517
+ });
2518
+ remainingAccounts.push({
2519
+ pubkey: outSpotMarket.mint,
2520
+ isWritable: false,
2521
+ isSigner: false,
2522
+ });
2523
+ }
2479
2524
  const beginSwapIx = await this.program.instruction.beginSwap(inMarketIndex, outMarketIndex, amountIn, {
2480
2525
  accounts: {
2481
2526
  state: await this.getStatePublicKey(),
@@ -2486,7 +2531,7 @@ class DriftClient {
2486
2531
  inSpotMarketVault: inSpotMarket.vault,
2487
2532
  inTokenAccount,
2488
2533
  outTokenAccount,
2489
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2534
+ tokenProgram: inTokenProgram,
2490
2535
  driftSigner: this.getStateAccount().signer,
2491
2536
  instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2492
2537
  },
@@ -2502,7 +2547,7 @@ class DriftClient {
2502
2547
  inSpotMarketVault: inSpotMarket.vault,
2503
2548
  inTokenAccount,
2504
2549
  outTokenAccount,
2505
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2550
+ tokenProgram: inTokenProgram,
2506
2551
  driftSigner: this.getStateAccount().signer,
2507
2552
  instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2508
2553
  },
@@ -3188,6 +3233,44 @@ class DriftClient {
3188
3233
  remainingAccounts: remainingAccounts,
3189
3234
  });
3190
3235
  }
3236
+ async liquidatePerpWithFill(userAccountPublicKey, userAccount, marketIndex, makerInfos, txParams, liquidatorSubAccountId) {
3237
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId), txParams), [], this.opts);
3238
+ this.perpMarketLastSlotCache.set(marketIndex, slot);
3239
+ return txSig;
3240
+ }
3241
+ async getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId) {
3242
+ const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
3243
+ const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
3244
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
3245
+ const remainingAccounts = this.getRemainingAccounts({
3246
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
3247
+ useMarketLastSlotCache: true,
3248
+ writablePerpMarketIndexes: [marketIndex],
3249
+ });
3250
+ for (const makerInfo of makerInfos) {
3251
+ remainingAccounts.push({
3252
+ pubkey: makerInfo.maker,
3253
+ isSigner: false,
3254
+ isWritable: true,
3255
+ });
3256
+ remainingAccounts.push({
3257
+ pubkey: makerInfo.makerStats,
3258
+ isSigner: false,
3259
+ isWritable: true,
3260
+ });
3261
+ }
3262
+ return await this.program.instruction.liquidatePerpWithFill(marketIndex, {
3263
+ accounts: {
3264
+ state: await this.getStatePublicKey(),
3265
+ authority: this.wallet.publicKey,
3266
+ user: userAccountPublicKey,
3267
+ userStats: userStatsPublicKey,
3268
+ liquidator,
3269
+ liquidatorStats: liquidatorStatsPublicKey,
3270
+ },
3271
+ remainingAccounts: remainingAccounts,
3272
+ });
3273
+ }
3191
3274
  async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
3192
3275
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
3193
3276
  this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
@@ -3312,6 +3395,7 @@ class DriftClient {
3312
3395
  writableSpotMarketIndexes: [marketIndex],
3313
3396
  });
3314
3397
  const spotMarket = this.getSpotMarketAccount(marketIndex);
3398
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
3315
3399
  return await this.program.instruction.resolveSpotBankruptcy(marketIndex, {
3316
3400
  accounts: {
3317
3401
  state: await this.getStatePublicKey(),
@@ -3441,14 +3525,12 @@ class DriftClient {
3441
3525
  },
3442
3526
  });
3443
3527
  }
3444
- async getAddInsuranceFundStakeIx(marketIndex, amount, collateralAccountPublicKey, fromSubAccount) {
3528
+ async getAddInsuranceFundStakeIx(marketIndex, amount, collateralAccountPublicKey) {
3445
3529
  const spotMarket = this.getSpotMarketAccount(marketIndex);
3446
3530
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
3447
- const remainingAccounts = this.getRemainingAccounts({
3448
- userAccounts: fromSubAccount ? [this.getUserAccount()] : [],
3449
- useMarketLastSlotCache: fromSubAccount ? true : false,
3450
- writableSpotMarketIndexes: [marketIndex],
3451
- });
3531
+ const remainingAccounts = [];
3532
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
3533
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
3452
3534
  const ix = this.program.instruction.addInsuranceFundStake(marketIndex, amount, {
3453
3535
  accounts: {
3454
3536
  state: await this.getStatePublicKey(),
@@ -3460,7 +3542,7 @@ class DriftClient {
3460
3542
  insuranceFundVault: spotMarket.insuranceFund.vault,
3461
3543
  driftSigner: this.getSignerPublicKey(),
3462
3544
  userTokenAccount: collateralAccountPublicKey,
3463
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3545
+ tokenProgram,
3464
3546
  },
3465
3547
  remainingAccounts,
3466
3548
  });
@@ -3497,7 +3579,7 @@ class DriftClient {
3497
3579
  const initializeIx = await this.getInitializeInsuranceFundStakeIx(marketIndex);
3498
3580
  addIfStakeIxs.push(initializeIx);
3499
3581
  }
3500
- const addFundsIx = await this.getAddInsuranceFundStakeIx(marketIndex, amount, tokenAccount, fromSubaccount);
3582
+ const addFundsIx = await this.getAddInsuranceFundStakeIx(marketIndex, amount, tokenAccount);
3501
3583
  addIfStakeIxs.push(addFundsIx);
3502
3584
  if (createWSOLTokenAccount) {
3503
3585
  addIfStakeIxs.push((0, spl_token_1.createCloseAccountInstruction)(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
@@ -3509,10 +3591,6 @@ class DriftClient {
3509
3591
  async requestRemoveInsuranceFundStake(marketIndex, amount, txParams) {
3510
3592
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
3511
3593
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
3512
- const remainingAccounts = this.getRemainingAccounts({
3513
- userAccounts: [],
3514
- writableSpotMarketIndexes: [marketIndex],
3515
- });
3516
3594
  const ix = await this.program.instruction.requestRemoveInsuranceFundStake(marketIndex, amount, {
3517
3595
  accounts: {
3518
3596
  state: await this.getStatePublicKey(),
@@ -3522,7 +3600,6 @@ class DriftClient {
3522
3600
  authority: this.wallet.publicKey,
3523
3601
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
3524
3602
  },
3525
- remainingAccounts,
3526
3603
  });
3527
3604
  const tx = await this.buildTransaction(ix, txParams);
3528
3605
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -3531,11 +3608,6 @@ class DriftClient {
3531
3608
  async cancelRequestRemoveInsuranceFundStake(marketIndex, txParams) {
3532
3609
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
3533
3610
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
3534
- const remainingAccounts = this.getRemainingAccounts({
3535
- userAccounts: [this.getUserAccount()],
3536
- useMarketLastSlotCache: true,
3537
- writableSpotMarketIndexes: [marketIndex],
3538
- });
3539
3611
  const ix = await this.program.instruction.cancelRequestRemoveInsuranceFundStake(marketIndex, {
3540
3612
  accounts: {
3541
3613
  state: await this.getStatePublicKey(),
@@ -3545,7 +3617,6 @@ class DriftClient {
3545
3617
  authority: this.wallet.publicKey,
3546
3618
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
3547
3619
  },
3548
- remainingAccounts,
3549
3620
  });
3550
3621
  const tx = await this.buildTransaction(ix, txParams);
3551
3622
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -3574,10 +3645,9 @@ class DriftClient {
3574
3645
  removeIfStakeIxs.push(createTokenAccountIx);
3575
3646
  }
3576
3647
  }
3577
- const remainingAccounts = this.getRemainingAccounts({
3578
- userAccounts: [],
3579
- writableSpotMarketIndexes: [marketIndex],
3580
- });
3648
+ const remainingAccounts = [];
3649
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
3650
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
3581
3651
  const removeStakeIx = await this.program.instruction.removeInsuranceFundStake(marketIndex, {
3582
3652
  accounts: {
3583
3653
  state: await this.getStatePublicKey(),
@@ -3588,7 +3658,7 @@ class DriftClient {
3588
3658
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
3589
3659
  driftSigner: this.getSignerPublicKey(),
3590
3660
  userTokenAccount: tokenAccount,
3591
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3661
+ tokenProgram,
3592
3662
  },
3593
3663
  remainingAccounts,
3594
3664
  });
@@ -3601,18 +3671,15 @@ class DriftClient {
3601
3671
  const { txSig } = await this.sendTransaction(tx, additionalSigners, this.opts);
3602
3672
  return txSig;
3603
3673
  }
3604
- async settleRevenueToInsuranceFund(spotMarketIndex, subAccountId, txParams) {
3605
- const tx = await this.buildTransaction(await this.getSettleRevenueToInsuranceFundIx(spotMarketIndex, subAccountId), txParams);
3674
+ async settleRevenueToInsuranceFund(spotMarketIndex, txParams) {
3675
+ const tx = await this.buildTransaction(await this.getSettleRevenueToInsuranceFundIx(spotMarketIndex), txParams);
3606
3676
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
3607
3677
  return txSig;
3608
3678
  }
3609
- async getSettleRevenueToInsuranceFundIx(spotMarketIndex, subAccountId) {
3679
+ async getSettleRevenueToInsuranceFundIx(spotMarketIndex) {
3610
3680
  const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
3611
- const remainingAccounts = this.getRemainingAccounts({
3612
- userAccounts: [this.getUserAccount(subAccountId)],
3613
- useMarketLastSlotCache: true,
3614
- writableSpotMarketIndexes: [spotMarketIndex],
3615
- });
3681
+ const remainingAccounts = [];
3682
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
3616
3683
  const ix = await this.program.instruction.settleRevenueToInsuranceFund(spotMarketIndex, {
3617
3684
  accounts: {
3618
3685
  state: await this.getStatePublicKey(),
@@ -3652,6 +3719,9 @@ class DriftClient {
3652
3719
  }
3653
3720
  async getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey) {
3654
3721
  const spotMarket = await this.getSpotMarketAccount(marketIndex);
3722
+ const remainingAccounts = [];
3723
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
3724
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
3655
3725
  const ix = await this.program.instruction.depositIntoSpotMarketRevenuePool(amount, {
3656
3726
  accounts: {
3657
3727
  state: await this.getStatePublicKey(),
@@ -3659,7 +3729,7 @@ class DriftClient {
3659
3729
  authority: this.wallet.publicKey,
3660
3730
  spotMarketVault: spotMarket.vault,
3661
3731
  userTokenAccount: userTokenAccountPublicKey,
3662
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3732
+ tokenProgram,
3663
3733
  },
3664
3734
  });
3665
3735
  return ix;
@@ -3751,6 +3821,12 @@ class DriftClient {
3751
3821
  }
3752
3822
  return this.receiverProgram;
3753
3823
  }
3824
+ getSwitchboardOnDemandProgram() {
3825
+ if (this.sbOnDemandProgram === undefined) {
3826
+ this.sbOnDemandProgram = new anchor_30_1.Program(switchboard_on_demand_30_json_1.default, this.provider);
3827
+ }
3828
+ return this.sbOnDemandProgram;
3829
+ }
3754
3830
  async postPythPullOracleUpdateAtomic(vaaString, feedId) {
3755
3831
  const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(vaaString, feedId);
3756
3832
  const tx = await this.buildTransaction(postIxs);
@@ -3845,6 +3921,44 @@ class DriftClient {
3845
3921
  },
3846
3922
  });
3847
3923
  }
3924
+ async getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures = 3) {
3925
+ const program = this.getSwitchboardOnDemandProgram();
3926
+ const feedAccount = new on_demand_1.PullFeed(program, feed);
3927
+ if (!this.sbProgramFeedConfigs) {
3928
+ this.sbProgramFeedConfigs = new Map();
3929
+ }
3930
+ if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
3931
+ const feedConfig = await feedAccount.loadConfigs();
3932
+ this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
3933
+ }
3934
+ const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
3935
+ numSignatures,
3936
+ feedConfigs: this.sbProgramFeedConfigs.get(feed.toString()),
3937
+ });
3938
+ if (!success) {
3939
+ return undefined;
3940
+ }
3941
+ return pullIx;
3942
+ }
3943
+ async postSwitchboardOnDemandUpdate(feed, numSignatures = 3) {
3944
+ const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures);
3945
+ if (!pullIx) {
3946
+ return undefined;
3947
+ }
3948
+ const tx = await (0, on_demand_1.asV0Tx)({
3949
+ connection: this.connection,
3950
+ ixs: [pullIx],
3951
+ payer: this.wallet.publicKey,
3952
+ computeUnitLimitMultiple: 1.3,
3953
+ lookupTables: [await this.fetchMarketLookupTableAccount()],
3954
+ });
3955
+ const { txSig } = await this.sendTransaction(tx, [], {
3956
+ commitment: 'processed',
3957
+ skipPreflight: true,
3958
+ maxRetries: 0,
3959
+ });
3960
+ return txSig;
3961
+ }
3848
3962
  async getBuildEncodedVaaIxs(vaa, guardianSet) {
3849
3963
  const postIxs = [];
3850
3964
  if (this.wormholeProgram === undefined) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -40,9 +40,10 @@ export type EventMap = {
40
40
  InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>;
41
41
  CurveRecord: Event<CurveRecord>;
42
42
  SwapRecord: Event<SwapRecord>;
43
+ SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
43
44
  };
44
45
  export type EventType = keyof EventMap;
45
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord>;
46
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord>;
46
47
  export interface EventSubscriberEvents {
47
48
  newEvent: (event: WrappedEvent<EventType>) => void;
48
49
  }
@@ -17,6 +17,7 @@ exports.DefaultEventSubscriptionOptions = {
17
17
  'InsuranceFundStakeRecord',
18
18
  'CurveRecord',
19
19
  'SwapRecord',
20
+ 'SpotMarketVaultDepositRecord',
20
21
  ],
21
22
  maxEventsPerType: 4096,
22
23
  orderBy: 'blockchain',
@@ -9,6 +9,7 @@ const anchor_1 = require("@coral-xyz/anchor");
9
9
  const prelaunchOracleClient_1 = require("../oracles/prelaunchOracleClient");
10
10
  const switchboardClient_1 = require("../oracles/switchboardClient");
11
11
  const pythPullClient_1 = require("../oracles/pythPullClient");
12
+ const switchboardOnDemandClient_1 = require("../oracles/switchboardOnDemandClient");
12
13
  function getOracleClient(oracleSource, connection, program) {
13
14
  if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
14
15
  return new pythClient_1.PythClient(connection);
@@ -43,6 +44,9 @@ function getOracleClient(oracleSource, connection, program) {
43
44
  if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) {
44
45
  return new quoteAssetOracleClient_1.QuoteAssetOracleClient();
45
46
  }
47
+ if ((0, types_1.isVariant)(oracleSource, 'switchboardOnDemand')) {
48
+ return new switchboardOnDemandClient_1.SwitchboardOnDemandClient(connection);
49
+ }
46
50
  throw new Error(`Unknown oracle source ${oracleSource}`);
47
51
  }
48
52
  exports.getOracleClient = getOracleClient;
@@ -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": [
@@ -2341,7 +2382,7 @@
2341
2382
  },
2342
2383
  {
2343
2384
  "name": "spotMarket",
2344
- "isMut": false,
2385
+ "isMut": true,
2345
2386
  "isSigner": false
2346
2387
  },
2347
2388
  {
@@ -2401,7 +2442,7 @@
2401
2442
  "accounts": [
2402
2443
  {
2403
2444
  "name": "spotMarket",
2404
- "isMut": false,
2445
+ "isMut": true,
2405
2446
  "isSigner": false
2406
2447
  },
2407
2448
  {
@@ -2441,7 +2482,7 @@
2441
2482
  "accounts": [
2442
2483
  {
2443
2484
  "name": "spotMarket",
2444
- "isMut": false,
2485
+ "isMut": true,
2445
2486
  "isSigner": false
2446
2487
  },
2447
2488
  {
@@ -2482,7 +2523,7 @@
2482
2523
  },
2483
2524
  {
2484
2525
  "name": "spotMarket",
2485
- "isMut": false,
2526
+ "isMut": true,
2486
2527
  "isSigner": false
2487
2528
  },
2488
2529
  {
@@ -3593,6 +3634,47 @@
3593
3634
  }
3594
3635
  ]
3595
3636
  },
3637
+ {
3638
+ "name": "depositIntoSpotMarketVault",
3639
+ "accounts": [
3640
+ {
3641
+ "name": "state",
3642
+ "isMut": false,
3643
+ "isSigner": false
3644
+ },
3645
+ {
3646
+ "name": "spotMarket",
3647
+ "isMut": true,
3648
+ "isSigner": false
3649
+ },
3650
+ {
3651
+ "name": "admin",
3652
+ "isMut": false,
3653
+ "isSigner": true
3654
+ },
3655
+ {
3656
+ "name": "sourceVault",
3657
+ "isMut": true,
3658
+ "isSigner": false
3659
+ },
3660
+ {
3661
+ "name": "spotMarketVault",
3662
+ "isMut": true,
3663
+ "isSigner": false
3664
+ },
3665
+ {
3666
+ "name": "tokenProgram",
3667
+ "isMut": false,
3668
+ "isSigner": false
3669
+ }
3670
+ ],
3671
+ "args": [
3672
+ {
3673
+ "name": "amount",
3674
+ "type": "u64"
3675
+ }
3676
+ ]
3677
+ },
3596
3678
  {
3597
3679
  "name": "depositIntoSpotMarketRevenuePool",
3598
3680
  "accounts": [
@@ -6835,12 +6917,16 @@
6835
6917
  ],
6836
6918
  "type": "u8"
6837
6919
  },
6920
+ {
6921
+ "name": "tokenProgram",
6922
+ "type": "u8"
6923
+ },
6838
6924
  {
6839
6925
  "name": "padding",
6840
6926
  "type": {
6841
6927
  "array": [
6842
6928
  "u8",
6843
- 42
6929
+ 41
6844
6930
  ]
6845
6931
  }
6846
6932
  }
@@ -9833,6 +9919,9 @@
9833
9919
  },
9834
9920
  {
9835
9921
  "name": "PlaceAndTake"
9922
+ },
9923
+ {
9924
+ "name": "Liquidation"
9836
9925
  }
9837
9926
  ]
9838
9927
  }
@@ -9945,6 +10034,9 @@
9945
10034
  },
9946
10035
  {
9947
10036
  "name": "PythStableCoinPull"
10037
+ },
10038
+ {
10039
+ "name": "SwitchboardOnDemand"
9948
10040
  }
9949
10041
  ]
9950
10042
  }
@@ -11349,6 +11441,46 @@
11349
11441
  "index": false
11350
11442
  }
11351
11443
  ]
11444
+ },
11445
+ {
11446
+ "name": "SpotMarketVaultDepositRecord",
11447
+ "fields": [
11448
+ {
11449
+ "name": "ts",
11450
+ "type": "i64",
11451
+ "index": false
11452
+ },
11453
+ {
11454
+ "name": "marketIndex",
11455
+ "type": "u16",
11456
+ "index": false
11457
+ },
11458
+ {
11459
+ "name": "depositBalance",
11460
+ "type": "u128",
11461
+ "index": false
11462
+ },
11463
+ {
11464
+ "name": "cumulativeDepositInterestBefore",
11465
+ "type": "u128",
11466
+ "index": false
11467
+ },
11468
+ {
11469
+ "name": "cumulativeDepositInterestAfter",
11470
+ "type": "u128",
11471
+ "index": false
11472
+ },
11473
+ {
11474
+ "name": "depositTokenAmountBefore",
11475
+ "type": "u64",
11476
+ "index": false
11477
+ },
11478
+ {
11479
+ "name": "amount",
11480
+ "type": "u64",
11481
+ "index": false
11482
+ }
11483
+ ]
11352
11484
  }
11353
11485
  ],
11354
11486
  "errors": [
@@ -12761,6 +12893,16 @@
12761
12893
  "code": 6281,
12762
12894
  "name": "InvalidOpenbookV2Market",
12763
12895
  "msg": "InvalidOpenbookV2Market"
12896
+ },
12897
+ {
12898
+ "code": 6282,
12899
+ "name": "NonZeroTransferFee",
12900
+ "msg": "Non zero transfer fee"
12901
+ },
12902
+ {
12903
+ "code": 6283,
12904
+ "name": "LiquidationOrderFailedToFill",
12905
+ "msg": "Liquidation order failed to fill"
12764
12906
  }
12765
12907
  ],
12766
12908
  "metadata": {