@drift-labs/sdk 2.87.0-beta.0 → 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 +12 -12
  10. package/lib/constants/spotMarkets.d.ts +1 -0
  11. package/lib/constants/spotMarkets.js +13 -3
  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 +12 -12
  40. package/src/constants/spotMarkets.ts +15 -3
  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
@@ -5,6 +5,7 @@ import {
5
5
  Program,
6
6
  ProgramAccount,
7
7
  } from '@coral-xyz/anchor';
8
+ import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
8
9
  import bs58 from 'bs58';
9
10
  import {
10
11
  ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -13,6 +14,7 @@ import {
13
14
  createInitializeAccountInstruction,
14
15
  getAssociatedTokenAddress,
15
16
  TOKEN_PROGRAM_ID,
17
+ TOKEN_2022_PROGRAM_ID,
16
18
  } from '@solana/spl-token';
17
19
  import {
18
20
  StateAccount,
@@ -147,6 +149,8 @@ import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/py
147
149
  import { getFeedIdUint8Array, trimFeedId } from './util/pythPullOracleUtils';
148
150
  import { isVersionedTransaction } from './tx/utils';
149
151
  import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
152
+ import { asV0Tx, PullFeed } from '@switchboard-xyz/on-demand';
153
+ import switchboardOnDemandIdl from './idl/switchboard_on_demand_30.json';
150
154
 
151
155
  type RemainingAccountParams = {
152
156
  userAccounts: UserAccount[];
@@ -198,6 +202,8 @@ export class DriftClient {
198
202
 
199
203
  receiverProgram?: Program<PythSolanaReceiver>;
200
204
  wormholeProgram?: Program<WormholeCoreBridgeSolana>;
205
+ sbOnDemandProgram?: Program30<Idl30>;
206
+ sbProgramFeedConfigs?: Map<string, any>;
201
207
 
202
208
  public get isSubscribed() {
203
209
  return this._isSubscribed && this.accountSubscriber.isSubscribed;
@@ -1824,7 +1830,8 @@ export class DriftClient {
1824
1830
  account: PublicKey,
1825
1831
  payer: PublicKey,
1826
1832
  owner: PublicKey,
1827
- mint: PublicKey
1833
+ mint: PublicKey,
1834
+ tokenProgram = TOKEN_PROGRAM_ID
1828
1835
  ): TransactionInstruction {
1829
1836
  return new TransactionInstruction({
1830
1837
  keys: [
@@ -1837,7 +1844,7 @@ export class DriftClient {
1837
1844
  isSigner: false,
1838
1845
  isWritable: false,
1839
1846
  },
1840
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
1847
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
1841
1848
  ],
1842
1849
  programId: ASSOCIATED_TOKEN_PROGRAM_ID,
1843
1850
  data: Buffer.from([0x1]),
@@ -1851,7 +1858,7 @@ export class DriftClient {
1851
1858
  subAccountId?: number,
1852
1859
  reduceOnly = false,
1853
1860
  txParams?: TxParams
1854
- ): Promise<ReturnType<typeof this.buildTransaction>> {
1861
+ ): Promise<VersionedTransaction | Transaction> {
1855
1862
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
1856
1863
 
1857
1864
  const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
@@ -1965,6 +1972,8 @@ export class DriftClient {
1965
1972
 
1966
1973
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
1967
1974
 
1975
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
1976
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
1968
1977
  return await this.program.instruction.deposit(
1969
1978
  marketIndex,
1970
1979
  amount,
@@ -1978,7 +1987,7 @@ export class DriftClient {
1978
1987
  userStats: this.getUserStatsAccountPublicKey(),
1979
1988
  userTokenAccount: userTokenAccount,
1980
1989
  authority: this.wallet.publicKey,
1981
- tokenProgram: TOKEN_PROGRAM_ID,
1990
+ tokenProgram,
1982
1991
  },
1983
1992
  remainingAccounts,
1984
1993
  }
@@ -2051,6 +2060,28 @@ export class DriftClient {
2051
2060
  return result;
2052
2061
  }
2053
2062
 
2063
+ public getTokenProgramForSpotMarket(
2064
+ spotMarketAccount: SpotMarketAccount
2065
+ ): PublicKey {
2066
+ if (spotMarketAccount.tokenProgram === 1) {
2067
+ return TOKEN_2022_PROGRAM_ID;
2068
+ }
2069
+ return TOKEN_PROGRAM_ID;
2070
+ }
2071
+
2072
+ public addTokenMintToRemainingAccounts(
2073
+ spotMarketAccount: SpotMarketAccount,
2074
+ remainingAccounts: AccountMeta[]
2075
+ ) {
2076
+ if (spotMarketAccount.tokenProgram === 1) {
2077
+ remainingAccounts.push({
2078
+ pubkey: spotMarketAccount.mint,
2079
+ isSigner: false,
2080
+ isWritable: false,
2081
+ });
2082
+ }
2083
+ }
2084
+
2054
2085
  public getAssociatedTokenAccountCreationIx(
2055
2086
  tokenMintAddress: PublicKey,
2056
2087
  associatedTokenAddress: PublicKey
@@ -2463,6 +2494,9 @@ export class DriftClient {
2463
2494
 
2464
2495
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
2465
2496
 
2497
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
2498
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
2499
+
2466
2500
  return await this.program.instruction.withdraw(
2467
2501
  marketIndex,
2468
2502
  amount,
@@ -2477,7 +2511,7 @@ export class DriftClient {
2477
2511
  userStats: this.getUserStatsAccountPublicKey(),
2478
2512
  userTokenAccount: userTokenAccount,
2479
2513
  authority: this.wallet.publicKey,
2480
- tokenProgram: TOKEN_PROGRAM_ID,
2514
+ tokenProgram,
2481
2515
  },
2482
2516
  remainingAccounts,
2483
2517
  }
@@ -4225,12 +4259,15 @@ export class DriftClient {
4225
4259
  outAssociatedTokenAccount
4226
4260
  );
4227
4261
  if (!accountInfo) {
4262
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4263
+
4228
4264
  preInstructions.push(
4229
4265
  this.createAssociatedTokenAccountIdempotentInstruction(
4230
4266
  outAssociatedTokenAccount,
4231
4267
  this.provider.wallet.publicKey,
4232
4268
  this.provider.wallet.publicKey,
4233
- outMarket.mint
4269
+ outMarket.mint,
4270
+ tokenProgram
4234
4271
  )
4235
4272
  );
4236
4273
  }
@@ -4246,12 +4283,15 @@ export class DriftClient {
4246
4283
  inAssociatedTokenAccount
4247
4284
  );
4248
4285
  if (!accountInfo) {
4286
+ const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
4287
+
4249
4288
  preInstructions.push(
4250
4289
  this.createAssociatedTokenAccountIdempotentInstruction(
4251
4290
  inAssociatedTokenAccount,
4252
4291
  this.provider.wallet.publicKey,
4253
4292
  this.provider.wallet.publicKey,
4254
- inMarket.mint
4293
+ inMarket.mint,
4294
+ tokenProgram
4255
4295
  )
4256
4296
  );
4257
4297
  }
@@ -4466,6 +4506,30 @@ export class DriftClient {
4466
4506
  const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
4467
4507
  const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
4468
4508
 
4509
+ const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
4510
+ const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
4511
+
4512
+ if (!outTokenProgram.equals(inTokenProgram)) {
4513
+ remainingAccounts.push({
4514
+ pubkey: outTokenProgram,
4515
+ isWritable: false,
4516
+ isSigner: false,
4517
+ });
4518
+ }
4519
+
4520
+ if (outSpotMarket.tokenProgram === 1 || inSpotMarket.tokenProgram === 1) {
4521
+ remainingAccounts.push({
4522
+ pubkey: inSpotMarket.mint,
4523
+ isWritable: false,
4524
+ isSigner: false,
4525
+ });
4526
+ remainingAccounts.push({
4527
+ pubkey: outSpotMarket.mint,
4528
+ isWritable: false,
4529
+ isSigner: false,
4530
+ });
4531
+ }
4532
+
4469
4533
  const beginSwapIx = await this.program.instruction.beginSwap(
4470
4534
  inMarketIndex,
4471
4535
  outMarketIndex,
@@ -4480,7 +4544,7 @@ export class DriftClient {
4480
4544
  inSpotMarketVault: inSpotMarket.vault,
4481
4545
  inTokenAccount,
4482
4546
  outTokenAccount,
4483
- tokenProgram: TOKEN_PROGRAM_ID,
4547
+ tokenProgram: inTokenProgram,
4484
4548
  driftSigner: this.getStateAccount().signer,
4485
4549
  instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
4486
4550
  },
@@ -4503,7 +4567,7 @@ export class DriftClient {
4503
4567
  inSpotMarketVault: inSpotMarket.vault,
4504
4568
  inTokenAccount,
4505
4569
  outTokenAccount,
4506
- tokenProgram: TOKEN_PROGRAM_ID,
4570
+ tokenProgram: inTokenProgram,
4507
4571
  driftSigner: this.getStateAccount().signer,
4508
4572
  instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
4509
4573
  },
@@ -5935,6 +5999,81 @@ export class DriftClient {
5935
5999
  );
5936
6000
  }
5937
6001
 
6002
+ public async liquidatePerpWithFill(
6003
+ userAccountPublicKey: PublicKey,
6004
+ userAccount: UserAccount,
6005
+ marketIndex: number,
6006
+ makerInfos: MakerInfo[],
6007
+ txParams?: TxParams,
6008
+ liquidatorSubAccountId?: number
6009
+ ): Promise<TransactionSignature> {
6010
+ const { txSig, slot } = await this.sendTransaction(
6011
+ await this.buildTransaction(
6012
+ await this.getLiquidatePerpWithFillIx(
6013
+ userAccountPublicKey,
6014
+ userAccount,
6015
+ marketIndex,
6016
+ makerInfos,
6017
+ liquidatorSubAccountId
6018
+ ),
6019
+ txParams
6020
+ ),
6021
+ [],
6022
+ this.opts
6023
+ );
6024
+ this.perpMarketLastSlotCache.set(marketIndex, slot);
6025
+ return txSig;
6026
+ }
6027
+
6028
+ public async getLiquidatePerpWithFillIx(
6029
+ userAccountPublicKey: PublicKey,
6030
+ userAccount: UserAccount,
6031
+ marketIndex: number,
6032
+ makerInfos: MakerInfo[],
6033
+ liquidatorSubAccountId?: number
6034
+ ): Promise<TransactionInstruction> {
6035
+ const userStatsPublicKey = getUserStatsAccountPublicKey(
6036
+ this.program.programId,
6037
+ userAccount.authority
6038
+ );
6039
+
6040
+ const liquidator = await this.getUserAccountPublicKey(
6041
+ liquidatorSubAccountId
6042
+ );
6043
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
6044
+
6045
+ const remainingAccounts = this.getRemainingAccounts({
6046
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
6047
+ useMarketLastSlotCache: true,
6048
+ writablePerpMarketIndexes: [marketIndex],
6049
+ });
6050
+
6051
+ for (const makerInfo of makerInfos) {
6052
+ remainingAccounts.push({
6053
+ pubkey: makerInfo.maker,
6054
+ isSigner: false,
6055
+ isWritable: true,
6056
+ });
6057
+ remainingAccounts.push({
6058
+ pubkey: makerInfo.makerStats,
6059
+ isSigner: false,
6060
+ isWritable: true,
6061
+ });
6062
+ }
6063
+
6064
+ return await this.program.instruction.liquidatePerpWithFill(marketIndex, {
6065
+ accounts: {
6066
+ state: await this.getStatePublicKey(),
6067
+ authority: this.wallet.publicKey,
6068
+ user: userAccountPublicKey,
6069
+ userStats: userStatsPublicKey,
6070
+ liquidator,
6071
+ liquidatorStats: liquidatorStatsPublicKey,
6072
+ },
6073
+ remainingAccounts: remainingAccounts,
6074
+ });
6075
+ }
6076
+
5938
6077
  public async liquidateSpot(
5939
6078
  userAccountPublicKey: PublicKey,
5940
6079
  userAccount: UserAccount,
@@ -6274,6 +6413,8 @@ export class DriftClient {
6274
6413
 
6275
6414
  const spotMarket = this.getSpotMarketAccount(marketIndex);
6276
6415
 
6416
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
6417
+
6277
6418
  return await this.program.instruction.resolveSpotBankruptcy(marketIndex, {
6278
6419
  accounts: {
6279
6420
  state: await this.getStatePublicKey(),
@@ -6508,8 +6649,7 @@ export class DriftClient {
6508
6649
  public async getAddInsuranceFundStakeIx(
6509
6650
  marketIndex: number,
6510
6651
  amount: BN,
6511
- collateralAccountPublicKey: PublicKey,
6512
- fromSubAccount?: boolean
6652
+ collateralAccountPublicKey: PublicKey
6513
6653
  ): Promise<TransactionInstruction> {
6514
6654
  const spotMarket = this.getSpotMarketAccount(marketIndex);
6515
6655
  const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
@@ -6518,12 +6658,9 @@ export class DriftClient {
6518
6658
  marketIndex
6519
6659
  );
6520
6660
 
6521
- const remainingAccounts = this.getRemainingAccounts({
6522
- userAccounts: fromSubAccount ? [this.getUserAccount()] : [],
6523
- useMarketLastSlotCache: fromSubAccount ? true : false,
6524
- writableSpotMarketIndexes: [marketIndex],
6525
- });
6526
-
6661
+ const remainingAccounts = [];
6662
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
6663
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
6527
6664
  const ix = this.program.instruction.addInsuranceFundStake(
6528
6665
  marketIndex,
6529
6666
  amount,
@@ -6538,7 +6675,7 @@ export class DriftClient {
6538
6675
  insuranceFundVault: spotMarket.insuranceFund.vault,
6539
6676
  driftSigner: this.getSignerPublicKey(),
6540
6677
  userTokenAccount: collateralAccountPublicKey,
6541
- tokenProgram: TOKEN_PROGRAM_ID,
6678
+ tokenProgram,
6542
6679
  },
6543
6680
  remainingAccounts,
6544
6681
  }
@@ -6625,8 +6762,7 @@ export class DriftClient {
6625
6762
  const addFundsIx = await this.getAddInsuranceFundStakeIx(
6626
6763
  marketIndex,
6627
6764
  amount,
6628
- tokenAccount,
6629
- fromSubaccount
6765
+ tokenAccount
6630
6766
  );
6631
6767
 
6632
6768
  addIfStakeIxs.push(addFundsIx);
@@ -6665,11 +6801,6 @@ export class DriftClient {
6665
6801
  marketIndex
6666
6802
  );
6667
6803
 
6668
- const remainingAccounts = this.getRemainingAccounts({
6669
- userAccounts: [],
6670
- writableSpotMarketIndexes: [marketIndex],
6671
- });
6672
-
6673
6804
  const ix = await this.program.instruction.requestRemoveInsuranceFundStake(
6674
6805
  marketIndex,
6675
6806
  amount,
@@ -6682,7 +6813,6 @@ export class DriftClient {
6682
6813
  authority: this.wallet.publicKey,
6683
6814
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
6684
6815
  },
6685
- remainingAccounts,
6686
6816
  }
6687
6817
  );
6688
6818
 
@@ -6703,12 +6833,6 @@ export class DriftClient {
6703
6833
  marketIndex
6704
6834
  );
6705
6835
 
6706
- const remainingAccounts = this.getRemainingAccounts({
6707
- userAccounts: [this.getUserAccount()],
6708
- useMarketLastSlotCache: true,
6709
- writableSpotMarketIndexes: [marketIndex],
6710
- });
6711
-
6712
6836
  const ix =
6713
6837
  await this.program.instruction.cancelRequestRemoveInsuranceFundStake(
6714
6838
  marketIndex,
@@ -6721,7 +6845,6 @@ export class DriftClient {
6721
6845
  authority: this.wallet.publicKey,
6722
6846
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
6723
6847
  },
6724
- remainingAccounts,
6725
6848
  }
6726
6849
  );
6727
6850
 
@@ -6775,11 +6898,9 @@ export class DriftClient {
6775
6898
  }
6776
6899
  }
6777
6900
 
6778
- const remainingAccounts = this.getRemainingAccounts({
6779
- userAccounts: [],
6780
- writableSpotMarketIndexes: [marketIndex],
6781
- });
6782
-
6901
+ const remainingAccounts = [];
6902
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
6903
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
6783
6904
  const removeStakeIx =
6784
6905
  await this.program.instruction.removeInsuranceFundStake(marketIndex, {
6785
6906
  accounts: {
@@ -6791,7 +6912,7 @@ export class DriftClient {
6791
6912
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
6792
6913
  driftSigner: this.getSignerPublicKey(),
6793
6914
  userTokenAccount: tokenAccount,
6794
- tokenProgram: TOKEN_PROGRAM_ID,
6915
+ tokenProgram,
6795
6916
  },
6796
6917
  remainingAccounts,
6797
6918
  });
@@ -6822,14 +6943,10 @@ export class DriftClient {
6822
6943
 
6823
6944
  public async settleRevenueToInsuranceFund(
6824
6945
  spotMarketIndex: number,
6825
- subAccountId?: number,
6826
6946
  txParams?: TxParams
6827
6947
  ): Promise<TransactionSignature> {
6828
6948
  const tx = await this.buildTransaction(
6829
- await this.getSettleRevenueToInsuranceFundIx(
6830
- spotMarketIndex,
6831
- subAccountId
6832
- ),
6949
+ await this.getSettleRevenueToInsuranceFundIx(spotMarketIndex),
6833
6950
  txParams
6834
6951
  );
6835
6952
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -6837,15 +6954,11 @@ export class DriftClient {
6837
6954
  }
6838
6955
 
6839
6956
  public async getSettleRevenueToInsuranceFundIx(
6840
- spotMarketIndex: number,
6841
- subAccountId?: number
6957
+ spotMarketIndex: number
6842
6958
  ): Promise<TransactionInstruction> {
6843
6959
  const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
6844
- const remainingAccounts = this.getRemainingAccounts({
6845
- userAccounts: [this.getUserAccount(subAccountId)],
6846
- useMarketLastSlotCache: true,
6847
- writableSpotMarketIndexes: [spotMarketIndex],
6848
- });
6960
+ const remainingAccounts = [];
6961
+ this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
6849
6962
  const ix = await this.program.instruction.settleRevenueToInsuranceFund(
6850
6963
  spotMarketIndex,
6851
6964
  {
@@ -6915,6 +7028,10 @@ export class DriftClient {
6915
7028
  userTokenAccountPublicKey: PublicKey
6916
7029
  ): Promise<TransactionInstruction> {
6917
7030
  const spotMarket = await this.getSpotMarketAccount(marketIndex);
7031
+
7032
+ const remainingAccounts = [];
7033
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
7034
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
6918
7035
  const ix = await this.program.instruction.depositIntoSpotMarketRevenuePool(
6919
7036
  amount,
6920
7037
  {
@@ -6924,7 +7041,7 @@ export class DriftClient {
6924
7041
  authority: this.wallet.publicKey,
6925
7042
  spotMarketVault: spotMarket.vault,
6926
7043
  userTokenAccount: userTokenAccountPublicKey,
6927
- tokenProgram: TOKEN_PROGRAM_ID,
7044
+ tokenProgram,
6928
7045
  },
6929
7046
  }
6930
7047
  );
@@ -7057,6 +7174,16 @@ export class DriftClient {
7057
7174
  return this.receiverProgram;
7058
7175
  }
7059
7176
 
7177
+ public getSwitchboardOnDemandProgram(): Program30<Idl30> {
7178
+ if (this.sbOnDemandProgram === undefined) {
7179
+ this.sbOnDemandProgram = new Program30(
7180
+ switchboardOnDemandIdl as Idl30,
7181
+ this.provider
7182
+ );
7183
+ }
7184
+ return this.sbOnDemandProgram;
7185
+ }
7186
+
7060
7187
  public async postPythPullOracleUpdateAtomic(
7061
7188
  vaaString: string,
7062
7189
  feedId: string
@@ -7270,6 +7397,56 @@ export class DriftClient {
7270
7397
  );
7271
7398
  }
7272
7399
 
7400
+ public async getPostSwitchboardOnDemandUpdateAtomicIx(
7401
+ feed: PublicKey,
7402
+ numSignatures = 3
7403
+ ): Promise<TransactionInstruction | undefined> {
7404
+ const program = this.getSwitchboardOnDemandProgram();
7405
+ const feedAccount = new PullFeed(program, feed);
7406
+ if (!this.sbProgramFeedConfigs) {
7407
+ this.sbProgramFeedConfigs = new Map();
7408
+ }
7409
+ if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
7410
+ const feedConfig = await feedAccount.loadConfigs();
7411
+ this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
7412
+ }
7413
+
7414
+ const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
7415
+ numSignatures,
7416
+ feedConfigs: this.sbProgramFeedConfigs.get(feed.toString()),
7417
+ });
7418
+ if (!success) {
7419
+ return undefined;
7420
+ }
7421
+ return pullIx;
7422
+ }
7423
+
7424
+ public async postSwitchboardOnDemandUpdate(
7425
+ feed: PublicKey,
7426
+ numSignatures = 3
7427
+ ): Promise<TransactionSignature> {
7428
+ const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(
7429
+ feed,
7430
+ numSignatures
7431
+ );
7432
+ if (!pullIx) {
7433
+ return undefined;
7434
+ }
7435
+ const tx = await asV0Tx({
7436
+ connection: this.connection,
7437
+ ixs: [pullIx],
7438
+ payer: this.wallet.publicKey,
7439
+ computeUnitLimitMultiple: 1.3,
7440
+ lookupTables: [await this.fetchMarketLookupTableAccount()],
7441
+ });
7442
+ const { txSig } = await this.sendTransaction(tx, [], {
7443
+ commitment: 'processed',
7444
+ skipPreflight: true,
7445
+ maxRetries: 0,
7446
+ });
7447
+ return txSig;
7448
+ }
7449
+
7273
7450
  private async getBuildEncodedVaaIxs(
7274
7451
  vaa: Buffer,
7275
7452
  guardianSet: PublicKey
@@ -14,6 +14,7 @@ import {
14
14
  InsuranceFundStakeRecord,
15
15
  CurveRecord,
16
16
  SwapRecord,
17
+ SpotMarketVaultDepositRecord,
17
18
  } from '../index';
18
19
  import { EventEmitter } from 'events';
19
20
 
@@ -47,6 +48,7 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
47
48
  'InsuranceFundStakeRecord',
48
49
  'CurveRecord',
49
50
  'SwapRecord',
51
+ 'SpotMarketVaultDepositRecord',
50
52
  ],
51
53
  maxEventsPerType: 4096,
52
54
  orderBy: 'blockchain',
@@ -89,6 +91,7 @@ export type EventMap = {
89
91
  InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>;
90
92
  CurveRecord: Event<CurveRecord>;
91
93
  SwapRecord: Event<SwapRecord>;
94
+ SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
92
95
  };
93
96
 
94
97
  export type EventType = keyof EventMap;
@@ -107,7 +110,8 @@ export type DriftEvent =
107
110
  | Event<SpotInterestRecord>
108
111
  | Event<InsuranceFundStakeRecord>
109
112
  | Event<CurveRecord>
110
- | Event<SwapRecord>;
113
+ | Event<SwapRecord>
114
+ | Event<SpotMarketVaultDepositRecord>;
111
115
 
112
116
  export interface EventSubscriberEvents {
113
117
  newEvent: (event: WrappedEvent<EventType>) => void;
@@ -8,6 +8,7 @@ import { BN, Program } from '@coral-xyz/anchor';
8
8
  import { PrelaunchOracleClient } from '../oracles/prelaunchOracleClient';
9
9
  import { SwitchboardClient } from '../oracles/switchboardClient';
10
10
  import { PythPullClient } from '../oracles/pythPullClient';
11
+ import { SwitchboardOnDemandClient } from '../oracles/switchboardOnDemandClient';
11
12
 
12
13
  export function getOracleClient(
13
14
  oracleSource: OracleSource,
@@ -58,5 +59,9 @@ export function getOracleClient(
58
59
  return new QuoteAssetOracleClient();
59
60
  }
60
61
 
62
+ if (isVariant(oracleSource, 'switchboardOnDemand')) {
63
+ return new SwitchboardOnDemandClient(connection);
64
+ }
65
+
61
66
  throw new Error(`Unknown oracle source ${oracleSource}`);
62
67
  }