@drift-labs/sdk 2.29.0 → 2.30.0-beta.1

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.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
3
- import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams, PhoenixV1FulfillmentConfigAccount } from './types';
3
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy } from './types';
4
4
  import * as anchor from '@coral-xyz/anchor';
5
5
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
6
6
  import { TokenFaucet } from './tokenFaucet';
@@ -13,6 +13,7 @@ import { DriftClientConfig } from './driftClientConfig';
13
13
  import { User } from './user';
14
14
  import { UserSubscriptionConfig } from './userConfig';
15
15
  import { UserStats } from './userStats';
16
+ import { JupiterClient } from './jupiter/jupiterClient';
16
17
  type RemainingAccountParams = {
17
18
  userAccounts: UserAccount[];
18
19
  writablePerpMarketIndexes?: number[];
@@ -171,6 +172,7 @@ export declare class DriftClient {
171
172
  * @param useNative
172
173
  */
173
174
  getAssociatedTokenAccount(marketIndex: number, useNative?: boolean): Promise<PublicKey>;
175
+ createAssociatedTokenAccountIdempotentInstruction(account: PublicKey, payer: PublicKey, owner: PublicKey, mint: PublicKey): Promise<TransactionInstruction>;
174
176
  /**
175
177
  * Deposit funds into the given spot market
176
178
  *
@@ -274,6 +276,48 @@ export declare class DriftClient {
274
276
  addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
275
277
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
276
278
  addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
279
+ /**
280
+ * Swap tokens in drift account using jupiter
281
+ * @param jupiterClient jupiter client to find routes and jupiter instructions
282
+ * @param outMarketIndex the market index of the token you're buying
283
+ * @param inMarketIndex the market index of the token you're selling
284
+ * @param outAssociatedTokenAccount the token account to receive the token being sold on jupiter
285
+ * @param inAssociatedTokenAccount the token account to
286
+ * @param amount the amount of the token to sell
287
+ * @param slippageBps the max slippage passed to jupiter api
288
+ * @param txParams
289
+ */
290
+ swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, txParams, }: {
291
+ jupiterClient: JupiterClient;
292
+ outMarketIndex: number;
293
+ inMarketIndex: number;
294
+ outAssociatedTokenAccount: PublicKey;
295
+ inAssociatedTokenAccount: PublicKey;
296
+ amount: BN;
297
+ slippageBps: number;
298
+ txParams?: TxParams;
299
+ }): Promise<TransactionSignature>;
300
+ /**
301
+ * Get the drift begin_swap and end_swap instructions
302
+ *
303
+ * @param outMarketIndex the market index of the token you're buying
304
+ * @param inMarketIndex the market index of the token you're selling
305
+ * @param amountIn the amount of the token to sell
306
+ * @param inTokenAccount the token account to move the tokens being sold
307
+ * @param outTokenAccount the token account to receive the tokens being bought
308
+ * @param limitPrice the limit price of the swap
309
+ */
310
+ getSwapIx({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, }: {
311
+ outMarketIndex: number;
312
+ inMarketIndex: number;
313
+ amountIn: BN;
314
+ inTokenAccount: PublicKey;
315
+ outTokenAccount: PublicKey;
316
+ limitPrice?: BN;
317
+ }): Promise<{
318
+ beginSwapIx: TransactionInstruction;
319
+ endSwapIx: TransactionInstruction;
320
+ }>;
277
321
  triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
278
322
  getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
279
323
  forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
@@ -345,7 +389,7 @@ export declare class DriftClient {
345
389
  postOnly?: boolean;
346
390
  immediateOrCancel?: boolean;
347
391
  maxTs?: BN;
348
- policy?: ModifyOrderParams;
392
+ policy?: ModifyOrderPolicy;
349
393
  }, txParams?: TxParams): Promise<TransactionSignature>;
350
394
  getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }: {
351
395
  orderId: number;
@@ -362,7 +406,7 @@ export declare class DriftClient {
362
406
  postOnly?: boolean;
363
407
  immediateOrCancel?: boolean;
364
408
  maxTs?: BN;
365
- policy?: ModifyOrderParams;
409
+ policy?: ModifyOrderPolicy;
366
410
  }): Promise<TransactionInstruction>;
367
411
  /**
368
412
  * Modifies an open order by closing it and replacing it with a new order.
@@ -396,7 +440,7 @@ export declare class DriftClient {
396
440
  reduceOnly?: boolean;
397
441
  postOnly?: boolean;
398
442
  immediateOrCancel?: boolean;
399
- policy?: ModifyOrderParams;
443
+ policy?: ModifyOrderPolicy;
400
444
  maxTs?: BN;
401
445
  }, txParams?: TxParams): Promise<TransactionSignature>;
402
446
  getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }: {
@@ -413,7 +457,7 @@ export declare class DriftClient {
413
457
  reduceOnly?: boolean;
414
458
  postOnly?: boolean;
415
459
  immediateOrCancel?: boolean;
416
- policy?: ModifyOrderParams;
460
+ policy?: ModifyOrderPolicy;
417
461
  maxTs?: BN;
418
462
  txParams?: TxParams;
419
463
  }): Promise<TransactionInstruction>;
@@ -485,6 +529,6 @@ export declare class DriftClient {
485
529
  marketType: MarketType;
486
530
  } | undefined;
487
531
  sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
488
- buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams): Promise<Transaction | VersionedTransaction>;
532
+ buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[]): Promise<Transaction | VersionedTransaction>;
489
533
  }
490
534
  export {};
@@ -957,6 +957,24 @@ class DriftClient {
957
957
  const mint = spotMarket.mint;
958
958
  return await spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, this.wallet.publicKey);
959
959
  }
960
+ async createAssociatedTokenAccountIdempotentInstruction(account, payer, owner, mint) {
961
+ return new web3_js_1.TransactionInstruction({
962
+ keys: [
963
+ { pubkey: payer, isSigner: true, isWritable: true },
964
+ { pubkey: account, isSigner: false, isWritable: true },
965
+ { pubkey: owner, isSigner: false, isWritable: false },
966
+ { pubkey: mint, isSigner: false, isWritable: false },
967
+ {
968
+ pubkey: web3_js_1.SystemProgram.programId,
969
+ isSigner: false,
970
+ isWritable: false,
971
+ },
972
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
973
+ ],
974
+ programId: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
975
+ data: Buffer.from([0x1]),
976
+ });
977
+ }
960
978
  /**
961
979
  * Deposit funds into the given spot market
962
980
  *
@@ -1947,6 +1965,129 @@ class DriftClient {
1947
1965
  isSigner: false,
1948
1966
  });
1949
1967
  }
1968
+ /**
1969
+ * Swap tokens in drift account using jupiter
1970
+ * @param jupiterClient jupiter client to find routes and jupiter instructions
1971
+ * @param outMarketIndex the market index of the token you're buying
1972
+ * @param inMarketIndex the market index of the token you're selling
1973
+ * @param outAssociatedTokenAccount the token account to receive the token being sold on jupiter
1974
+ * @param inAssociatedTokenAccount the token account to
1975
+ * @param amount the amount of the token to sell
1976
+ * @param slippageBps the max slippage passed to jupiter api
1977
+ * @param txParams
1978
+ */
1979
+ async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, txParams, }) {
1980
+ const outMarket = this.getSpotMarketAccount(outMarketIndex);
1981
+ const inMarket = this.getSpotMarketAccount(inMarketIndex);
1982
+ const routes = await jupiterClient.getRoutes({
1983
+ inputMint: inMarket.mint,
1984
+ outputMint: outMarket.mint,
1985
+ amount,
1986
+ slippageBps,
1987
+ });
1988
+ if (!routes || routes.length === 0) {
1989
+ throw new Error('No jupiter routes found');
1990
+ }
1991
+ const route = routes[0];
1992
+ const transaction = await jupiterClient.getSwapTransaction({
1993
+ route,
1994
+ userPublicKey: this.provider.wallet.publicKey,
1995
+ slippageBps,
1996
+ });
1997
+ const { transactionMessage, lookupTables } = await jupiterClient.getTransactionMessageAndLookupTables({
1998
+ transaction,
1999
+ });
2000
+ const jupiterInstructions = jupiterClient.getJupiterInstructions({
2001
+ transactionMessage,
2002
+ inputMint: inMarket.mint,
2003
+ outputMint: outMarket.mint,
2004
+ });
2005
+ const preInstructions = [];
2006
+ if (!outAssociatedTokenAccount) {
2007
+ outAssociatedTokenAccount = await this.getAssociatedTokenAccount(outMarket.marketIndex);
2008
+ const accountInfo = await this.connection.getAccountInfo(outAssociatedTokenAccount);
2009
+ if (!accountInfo) {
2010
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(outAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, outMarket.mint));
2011
+ }
2012
+ }
2013
+ if (!inAssociatedTokenAccount) {
2014
+ inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex);
2015
+ const accountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
2016
+ if (!accountInfo) {
2017
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint));
2018
+ }
2019
+ }
2020
+ const { beginSwapIx, endSwapIx } = await this.getSwapIx({
2021
+ outMarketIndex,
2022
+ inMarketIndex,
2023
+ amountIn: amount,
2024
+ inTokenAccount: inAssociatedTokenAccount,
2025
+ outTokenAccount: outAssociatedTokenAccount,
2026
+ });
2027
+ const instructions = [
2028
+ ...preInstructions,
2029
+ beginSwapIx,
2030
+ ...jupiterInstructions,
2031
+ endSwapIx,
2032
+ ];
2033
+ const tx = await this.buildTransaction(instructions, txParams, 0, lookupTables);
2034
+ const { txSig, slot } = await this.sendTransaction(tx);
2035
+ this.spotMarketLastSlotCache.set(outMarketIndex, slot);
2036
+ this.spotMarketLastSlotCache.set(inMarketIndex, slot);
2037
+ return txSig;
2038
+ }
2039
+ /**
2040
+ * Get the drift begin_swap and end_swap instructions
2041
+ *
2042
+ * @param outMarketIndex the market index of the token you're buying
2043
+ * @param inMarketIndex the market index of the token you're selling
2044
+ * @param amountIn the amount of the token to sell
2045
+ * @param inTokenAccount the token account to move the tokens being sold
2046
+ * @param outTokenAccount the token account to receive the tokens being bought
2047
+ * @param limitPrice the limit price of the swap
2048
+ */
2049
+ async getSwapIx({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, }) {
2050
+ const userAccountPublicKey = await this.getUserAccountPublicKey();
2051
+ const remainingAccounts = this.getRemainingAccounts({
2052
+ userAccounts: [this.getUserAccount()],
2053
+ writableSpotMarketIndexes: [outMarketIndex, inMarketIndex],
2054
+ });
2055
+ const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
2056
+ const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
2057
+ const beginSwapIx = await this.program.instruction.beginSwap(inMarketIndex, outMarketIndex, amountIn, {
2058
+ accounts: {
2059
+ state: await this.getStatePublicKey(),
2060
+ user: userAccountPublicKey,
2061
+ userStats: this.getUserStatsAccountPublicKey(),
2062
+ authority: this.authority,
2063
+ outSpotMarketVault: outSpotMarket.vault,
2064
+ inSpotMarketVault: inSpotMarket.vault,
2065
+ inTokenAccount,
2066
+ outTokenAccount,
2067
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2068
+ driftSigner: this.getStateAccount().signer,
2069
+ instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2070
+ },
2071
+ remainingAccounts,
2072
+ });
2073
+ const endSwapIx = await this.program.instruction.endSwap(inMarketIndex, outMarketIndex, limitPrice !== null && limitPrice !== void 0 ? limitPrice : null, {
2074
+ accounts: {
2075
+ state: await this.getStatePublicKey(),
2076
+ user: userAccountPublicKey,
2077
+ userStats: this.getUserStatsAccountPublicKey(),
2078
+ authority: this.authority,
2079
+ outSpotMarketVault: outSpotMarket.vault,
2080
+ inSpotMarketVault: inSpotMarket.vault,
2081
+ inTokenAccount,
2082
+ outTokenAccount,
2083
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2084
+ driftSigner: this.getStateAccount().signer,
2085
+ instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2086
+ },
2087
+ remainingAccounts,
2088
+ });
2089
+ return { beginSwapIx, endSwapIx };
2090
+ }
1950
2091
  async triggerOrder(userAccountPublicKey, user, order, txParams) {
1951
2092
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams), [], this.opts);
1952
2093
  return txSig;
@@ -2895,7 +3036,7 @@ class DriftClient {
2895
3036
  return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts);
2896
3037
  }
2897
3038
  }
2898
- async buildTransaction(instructions, txParams) {
3039
+ async buildTransaction(instructions, txParams, txVersion, lookupTables) {
2899
3040
  var _a, _b;
2900
3041
  const allIx = [];
2901
3042
  const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000;
@@ -2921,11 +3062,14 @@ class DriftClient {
2921
3062
  }
2922
3063
  else {
2923
3064
  const marketLookupTable = await this.fetchMarketLookupTableAccount();
3065
+ lookupTables = lookupTables
3066
+ ? [...lookupTables, marketLookupTable]
3067
+ : [marketLookupTable];
2924
3068
  const message = new web3_js_1.TransactionMessage({
2925
3069
  payerKey: this.provider.wallet.publicKey,
2926
3070
  recentBlockhash: (await this.provider.connection.getRecentBlockhash(this.opts.preflightCommitment)).blockhash,
2927
3071
  instructions: allIx,
2928
- }).compileToV0Message([marketLookupTable]);
3072
+ }).compileToV0Message(lookupTables);
2929
3073
  return new web3_js_1.VersionedTransaction(message);
2930
3074
  }
2931
3075
  }
@@ -1,5 +1,5 @@
1
1
  import { Commitment, TransactionSignature } from '@solana/web3.js';
2
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord } from '../index';
2
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord } from '../index';
3
3
  export type EventSubscriptionOptions = {
4
4
  eventTypes?: EventType[];
5
5
  maxEventsPerType?: number;
@@ -35,9 +35,10 @@ export type EventMap = {
35
35
  SpotInterestRecord: Event<SpotInterestRecord>;
36
36
  InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>;
37
37
  CurveRecord: Event<CurveRecord>;
38
+ SwapRecord: Event<SwapRecord>;
38
39
  };
39
40
  export type EventType = keyof EventMap;
40
- 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>;
41
+ 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>;
41
42
  export interface EventSubscriberEvents {
42
43
  newEvent: (event: WrappedEvent<EventType>) => void;
43
44
  }
@@ -16,6 +16,7 @@ exports.DefaultEventSubscriptionOptions = {
16
16
  'SpotInterestRecord',
17
17
  'InsuranceFundStakeRecord',
18
18
  'CurveRecord',
19
+ 'SwapRecord',
19
20
  ],
20
21
  maxEventsPerType: 4096,
21
22
  orderBy: 'blockchain',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.29.0",
2
+ "version": "2.30.0-beta.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -710,6 +710,162 @@
710
710
  }
711
711
  ]
712
712
  },
713
+ {
714
+ "name": "beginSwap",
715
+ "accounts": [
716
+ {
717
+ "name": "state",
718
+ "isMut": false,
719
+ "isSigner": false
720
+ },
721
+ {
722
+ "name": "user",
723
+ "isMut": true,
724
+ "isSigner": false
725
+ },
726
+ {
727
+ "name": "userStats",
728
+ "isMut": true,
729
+ "isSigner": false
730
+ },
731
+ {
732
+ "name": "authority",
733
+ "isMut": false,
734
+ "isSigner": true
735
+ },
736
+ {
737
+ "name": "outSpotMarketVault",
738
+ "isMut": true,
739
+ "isSigner": false
740
+ },
741
+ {
742
+ "name": "inSpotMarketVault",
743
+ "isMut": true,
744
+ "isSigner": false
745
+ },
746
+ {
747
+ "name": "outTokenAccount",
748
+ "isMut": true,
749
+ "isSigner": false
750
+ },
751
+ {
752
+ "name": "inTokenAccount",
753
+ "isMut": true,
754
+ "isSigner": false
755
+ },
756
+ {
757
+ "name": "tokenProgram",
758
+ "isMut": false,
759
+ "isSigner": false
760
+ },
761
+ {
762
+ "name": "driftSigner",
763
+ "isMut": false,
764
+ "isSigner": false
765
+ },
766
+ {
767
+ "name": "instructions",
768
+ "isMut": false,
769
+ "isSigner": false,
770
+ "docs": [
771
+ "Instructions Sysvar for instruction introspection"
772
+ ]
773
+ }
774
+ ],
775
+ "args": [
776
+ {
777
+ "name": "inMarketIndex",
778
+ "type": "u16"
779
+ },
780
+ {
781
+ "name": "outMarketIndex",
782
+ "type": "u16"
783
+ },
784
+ {
785
+ "name": "amountIn",
786
+ "type": "u64"
787
+ }
788
+ ]
789
+ },
790
+ {
791
+ "name": "endSwap",
792
+ "accounts": [
793
+ {
794
+ "name": "state",
795
+ "isMut": false,
796
+ "isSigner": false
797
+ },
798
+ {
799
+ "name": "user",
800
+ "isMut": true,
801
+ "isSigner": false
802
+ },
803
+ {
804
+ "name": "userStats",
805
+ "isMut": true,
806
+ "isSigner": false
807
+ },
808
+ {
809
+ "name": "authority",
810
+ "isMut": false,
811
+ "isSigner": true
812
+ },
813
+ {
814
+ "name": "outSpotMarketVault",
815
+ "isMut": true,
816
+ "isSigner": false
817
+ },
818
+ {
819
+ "name": "inSpotMarketVault",
820
+ "isMut": true,
821
+ "isSigner": false
822
+ },
823
+ {
824
+ "name": "outTokenAccount",
825
+ "isMut": true,
826
+ "isSigner": false
827
+ },
828
+ {
829
+ "name": "inTokenAccount",
830
+ "isMut": true,
831
+ "isSigner": false
832
+ },
833
+ {
834
+ "name": "tokenProgram",
835
+ "isMut": false,
836
+ "isSigner": false
837
+ },
838
+ {
839
+ "name": "driftSigner",
840
+ "isMut": false,
841
+ "isSigner": false
842
+ },
843
+ {
844
+ "name": "instructions",
845
+ "isMut": false,
846
+ "isSigner": false,
847
+ "docs": [
848
+ "Instructions Sysvar for instruction introspection"
849
+ ]
850
+ }
851
+ ],
852
+ "args": [
853
+ {
854
+ "name": "inMarketIndex",
855
+ "type": "u16"
856
+ },
857
+ {
858
+ "name": "outMarketIndex",
859
+ "type": "u16"
860
+ },
861
+ {
862
+ "name": "limitPrice",
863
+ "type": {
864
+ "option": "u64"
865
+ }
866
+ }
867
+ ]
868
+ },
713
869
  {
714
870
  "name": "addPerpLpShares",
715
871
  "accounts": [
@@ -4895,12 +5051,46 @@
4895
5051
  "defined": "AssetTier"
4896
5052
  }
4897
5053
  },
5054
+ {
5055
+ "name": "padding1",
5056
+ "type": {
5057
+ "array": [
5058
+ "u8",
5059
+ 6
5060
+ ]
5061
+ }
5062
+ },
5063
+ {
5064
+ "name": "flashLoanAmount",
5065
+ "docs": [
5066
+ "For swaps, the amount of token loaned out in the begin_swap ix",
5067
+ "precision: token mint precision"
5068
+ ],
5069
+ "type": "u64"
5070
+ },
5071
+ {
5072
+ "name": "flashLoanInitialTokenAmount",
5073
+ "docs": [
5074
+ "For swaps, the amount in the users token account in the begin_swap ix",
5075
+ "Used to calculate how much of the token left the system in end_swap ix",
5076
+ "precision: token mint precision"
5077
+ ],
5078
+ "type": "u64"
5079
+ },
5080
+ {
5081
+ "name": "totalSwapFee",
5082
+ "docs": [
5083
+ "The total fees received from swaps",
5084
+ "precision: token mint precision"
5085
+ ],
5086
+ "type": "u64"
5087
+ },
4898
5088
  {
4899
5089
  "name": "padding",
4900
5090
  "type": {
4901
5091
  "array": [
4902
5092
  "u8",
4903
- 86
5093
+ 56
4904
5094
  ]
4905
5095
  }
4906
5096
  }
@@ -8845,6 +9035,56 @@
8845
9035
  "index": false
8846
9036
  }
8847
9037
  ]
9038
+ },
9039
+ {
9040
+ "name": "SwapRecord",
9041
+ "fields": [
9042
+ {
9043
+ "name": "ts",
9044
+ "type": "i64",
9045
+ "index": false
9046
+ },
9047
+ {
9048
+ "name": "user",
9049
+ "type": "publicKey",
9050
+ "index": false
9051
+ },
9052
+ {
9053
+ "name": "amountOut",
9054
+ "type": "u64",
9055
+ "index": false
9056
+ },
9057
+ {
9058
+ "name": "amountIn",
9059
+ "type": "u64",
9060
+ "index": false
9061
+ },
9062
+ {
9063
+ "name": "outMarketIndex",
9064
+ "type": "u16",
9065
+ "index": false
9066
+ },
9067
+ {
9068
+ "name": "inMarketIndex",
9069
+ "type": "u16",
9070
+ "index": false
9071
+ },
9072
+ {
9073
+ "name": "outOraclePrice",
9074
+ "type": "i64",
9075
+ "index": false
9076
+ },
9077
+ {
9078
+ "name": "inOraclePrice",
9079
+ "type": "i64",
9080
+ "index": false
9081
+ },
9082
+ {
9083
+ "name": "fee",
9084
+ "type": "u64",
9085
+ "index": false
9086
+ }
9087
+ ]
8848
9088
  }
8849
9089
  ],
8850
9090
  "errors": [
@@ -10087,6 +10327,21 @@
10087
10327
  "code": 6247,
10088
10328
  "name": "InvalidPhoenixMarket",
10089
10329
  "msg": "InvalidPhoenixMarket"
10330
+ },
10331
+ {
10332
+ "code": 6248,
10333
+ "name": "InvalidSwap",
10334
+ "msg": "InvalidSwap"
10335
+ },
10336
+ {
10337
+ "code": 6249,
10338
+ "name": "SwapLimitPriceBreached",
10339
+ "msg": "SwapLimitPriceBreached"
10340
+ },
10341
+ {
10342
+ "code": 6250,
10343
+ "name": "SpotMarketReduceOnly",
10344
+ "msg": "SpotMarketReduceOnly"
10090
10345
  }
10091
10346
  ]
10092
10347
  }
package/lib/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export * from './factory/bigNum';
30
30
  export * from './events/types';
31
31
  export * from './events/eventSubscriber';
32
32
  export * from './events/fetchLogs';
33
+ export * from './jupiter/jupiterClient';
33
34
  export * from './math/auction';
34
35
  export * from './math/spotMarket';
35
36
  export * from './math/conversion';
package/lib/index.js CHANGED
@@ -54,6 +54,7 @@ __exportStar(require("./factory/bigNum"), exports);
54
54
  __exportStar(require("./events/types"), exports);
55
55
  __exportStar(require("./events/eventSubscriber"), exports);
56
56
  __exportStar(require("./events/fetchLogs"), exports);
57
+ __exportStar(require("./jupiter/jupiterClient"), exports);
57
58
  __exportStar(require("./math/auction"), exports);
58
59
  __exportStar(require("./math/spotMarket"), exports);
59
60
  __exportStar(require("./math/conversion"), exports);