@drift-labs/sdk 2.75.0-beta.0 → 2.75.0-beta.2

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.
@@ -244,6 +244,16 @@ exports.DevnetPerpMarkets = [
244
244
  launchTs: 1709852537000,
245
245
  oracleSource: __1.OracleSource.Prelaunch,
246
246
  },
247
+ {
248
+ fullName: 'Kamino',
249
+ category: ['Lending'],
250
+ symbol: 'KMNO-PERP',
251
+ baseAssetSymbol: 'KMNO',
252
+ marketIndex: 24,
253
+ oracle: new web3_js_1.PublicKey('FkAaa46aYdHn8QxxwmiUnJt3th8radB2GFXDMtyLALCY'),
254
+ launchTs: 1711475936000,
255
+ oracleSource: __1.OracleSource.Prelaunch,
256
+ },
247
257
  ];
248
258
  exports.MainnetPerpMarkets = [
249
259
  {
@@ -329,8 +329,8 @@ export declare class DriftClient {
329
329
  getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
330
330
  placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
331
331
  getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
332
- fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
333
- getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
332
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
333
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
334
334
  addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
335
335
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
336
336
  addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
@@ -1934,22 +1934,27 @@ class DriftClient {
1934
1934
  const marketIndex = order
1935
1935
  ? order.marketIndex
1936
1936
  : userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
1937
+ makerInfo = Array.isArray(makerInfo)
1938
+ ? makerInfo
1939
+ : makerInfo
1940
+ ? [makerInfo]
1941
+ : [];
1937
1942
  const userAccounts = [userAccount];
1938
- if (makerInfo !== undefined) {
1939
- userAccounts.push(makerInfo.makerUserAccount);
1943
+ for (const maker of makerInfo) {
1944
+ userAccounts.push(maker.makerUserAccount);
1940
1945
  }
1941
1946
  const remainingAccounts = this.getRemainingAccounts({
1942
1947
  userAccounts,
1943
1948
  writableSpotMarketIndexes: [marketIndex, numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
1944
1949
  });
1945
- if (makerInfo) {
1950
+ for (const maker of makerInfo) {
1946
1951
  remainingAccounts.push({
1947
- pubkey: makerInfo.maker,
1952
+ pubkey: maker.maker,
1948
1953
  isWritable: true,
1949
1954
  isSigner: false,
1950
1955
  });
1951
1956
  remainingAccounts.push({
1952
- pubkey: makerInfo.makerStats,
1957
+ pubkey: maker.makerStats,
1953
1958
  isWritable: true,
1954
1959
  isSigner: false,
1955
1960
  });
@@ -1967,9 +1972,8 @@ class DriftClient {
1967
1972
  });
1968
1973
  }
1969
1974
  const orderId = order.orderId;
1970
- const makerOrderId = makerInfo ? makerInfo.order.orderId : null;
1971
1975
  this.addSpotFulfillmentAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
1972
- return await this.program.instruction.fillSpotOrder(orderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, makerOrderId, {
1976
+ return await this.program.instruction.fillSpotOrder(orderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, null, {
1973
1977
  accounts: {
1974
1978
  state: await this.getStatePublicKey(),
1975
1979
  filler,
@@ -8997,7 +8997,11 @@
8997
8997
  "name": "ExternalMarket"
8998
8998
  },
8999
8999
  {
9000
- "name": "Match"
9000
+ "name": "Match",
9001
+ "fields": [
9002
+ "publicKey",
9003
+ "u16"
9004
+ ]
9001
9005
  }
9002
9006
  ]
9003
9007
  }
package/lib/index.d.ts CHANGED
@@ -73,6 +73,7 @@ export * from './priorityFee';
73
73
  export * from './phoenix/phoenixFulfillmentConfigMap';
74
74
  export * from './tx/fastSingleTxSender';
75
75
  export * from './tx/retryTxSender';
76
+ export * from './tx/whileValidTxSender';
76
77
  export * from './tx/priorityFeeCalculator';
77
78
  export * from './tx/types';
78
79
  export * from './util/computeUnits';
package/lib/index.js CHANGED
@@ -96,6 +96,7 @@ __exportStar(require("./priorityFee"), exports);
96
96
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
97
97
  __exportStar(require("./tx/fastSingleTxSender"), exports);
98
98
  __exportStar(require("./tx/retryTxSender"), exports);
99
+ __exportStar(require("./tx/whileValidTxSender"), exports);
99
100
  __exportStar(require("./tx/priorityFeeCalculator"), exports);
100
101
  __exportStar(require("./tx/types"), exports);
101
102
  __exportStar(require("./util/computeUnits"), exports);
@@ -21,7 +21,7 @@ export declare abstract class BaseTxSender implements TxSender {
21
21
  additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
22
22
  });
23
23
  send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
24
- prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
24
+ prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
25
25
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions, blockhash?: string): Promise<VersionedTransaction>;
26
26
  sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
27
27
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
@@ -28,15 +28,16 @@ class BaseTxSender {
28
28
  if (opts === undefined) {
29
29
  opts = this.opts;
30
30
  }
31
- const signedTx = preSigned
32
- ? tx
33
- : await this.prepareTx(tx, additionalSigners, opts);
31
+ const signedTx = await this.prepareTx(tx, additionalSigners, opts, preSigned);
34
32
  if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
35
33
  extraConfirmationOptions.onSignedCb();
36
34
  }
37
35
  return this.sendRawTransaction(signedTx.serialize(), opts);
38
36
  }
39
- async prepareTx(tx, additionalSigners, opts) {
37
+ async prepareTx(tx, additionalSigners, opts, preSigned) {
38
+ if (preSigned) {
39
+ return tx;
40
+ }
40
41
  tx.feePayer = this.wallet.publicKey;
41
42
  tx.recentBlockhash = (await this.connection.getLatestBlockhash(opts.preflightCommitment)).blockhash;
42
43
  additionalSigners
@@ -26,7 +26,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
26
26
  confirmationStrategy?: ConfirmationStrategy;
27
27
  });
28
28
  startBlockhashRefreshLoop(): void;
29
- prepareTx(tx: Transaction, additionalSigners: Array<Signer>, _opts: ConfirmOptions): Promise<Transaction>;
29
+ prepareTx(tx: Transaction, additionalSigners: Array<Signer>, _opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
30
30
  getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions, blockhash?: string): Promise<VersionedTransaction>;
31
31
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
32
32
  }
@@ -38,19 +38,8 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
38
38
  }
39
39
  }, this.blockhashRefreshInterval);
40
40
  }
41
- async prepareTx(tx, additionalSigners, _opts) {
42
- var _a;
43
- tx.feePayer = this.wallet.publicKey;
44
- tx.recentBlockhash =
45
- (_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(this.blockhashCommitment))
46
- .blockhash;
47
- additionalSigners
48
- .filter((s) => s !== undefined)
49
- .forEach((kp) => {
50
- tx.partialSign(kp);
51
- });
52
- const signedTx = await this.wallet.signTransaction(tx);
53
- return signedTx;
41
+ async prepareTx(tx, additionalSigners, _opts, preSigned) {
42
+ return super.prepareTx(tx, additionalSigners, _opts, preSigned);
54
43
  }
55
44
  async getVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts, blockhash) {
56
45
  var _a;
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import { ExtraConfirmationOptions, TxSigAndSlot } from './types';
3
+ import { AddressLookupTableAccount, ConfirmOptions, Connection, Signer, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
4
+ import { IWallet } from '../types';
5
+ import { BaseTxSender } from './baseTxSender';
6
+ type ResolveReference = {
7
+ resolve?: () => void;
8
+ };
9
+ export declare class WhileValidTxSender extends BaseTxSender {
10
+ connection: Connection;
11
+ wallet: IWallet;
12
+ opts: ConfirmOptions;
13
+ timeout: number;
14
+ retrySleep: number;
15
+ additionalConnections: Connection[];
16
+ timoutCount: number;
17
+ untilValid: Map<string, {
18
+ blockhash: string;
19
+ lastValidBlockHeight: number;
20
+ }>;
21
+ constructor({ connection, wallet, opts, retrySleep, additionalConnections, additionalTxSenderCallbacks, }: {
22
+ connection: Connection;
23
+ wallet: IWallet;
24
+ opts?: ConfirmOptions;
25
+ retrySleep?: number;
26
+ additionalConnections?: any;
27
+ additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
28
+ });
29
+ sleep(reference: ResolveReference): Promise<void>;
30
+ prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
31
+ getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], _additionalSigners?: Array<Signer>, _opts?: ConfirmOptions): Promise<VersionedTransaction>;
32
+ sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
33
+ sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
34
+ }
35
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WhileValidTxSender = void 0;
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const anchor_1 = require("@coral-xyz/anchor");
9
+ const baseTxSender_1 = require("./baseTxSender");
10
+ const bs58_1 = __importDefault(require("bs58"));
11
+ const DEFAULT_RETRY = 8000;
12
+ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
13
+ constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], }) {
14
+ super({
15
+ connection,
16
+ wallet,
17
+ opts,
18
+ additionalConnections,
19
+ additionalTxSenderCallbacks,
20
+ });
21
+ this.timoutCount = 0;
22
+ this.untilValid = new Map();
23
+ this.retrySleep = retrySleep;
24
+ }
25
+ async sleep(reference) {
26
+ return new Promise((resolve) => {
27
+ reference.resolve = resolve;
28
+ setTimeout(resolve, this.retrySleep);
29
+ });
30
+ }
31
+ async prepareTx(tx, additionalSigners, opts, preSigned) {
32
+ var _a;
33
+ const latestBlockhash = await this.connection.getLatestBlockhash(opts.preflightCommitment);
34
+ // handle tx
35
+ let signedTx = tx;
36
+ if (!preSigned) {
37
+ tx.feePayer = this.wallet.publicKey;
38
+ tx.recentBlockhash = latestBlockhash.blockhash;
39
+ additionalSigners
40
+ .filter((s) => s !== undefined)
41
+ .forEach((kp) => {
42
+ tx.partialSign(kp);
43
+ });
44
+ signedTx = await this.wallet.signTransaction(tx);
45
+ }
46
+ // handle subclass-specific side effects
47
+ const txSig = bs58_1.default.encode(((_a = tx.signatures[0]) === null || _a === void 0 ? void 0 : _a.signature) || tx.signatures[0]);
48
+ this.untilValid.set(txSig, latestBlockhash);
49
+ return signedTx;
50
+ }
51
+ async getVersionedTransaction(ixs, lookupTableAccounts, _additionalSigners, _opts) {
52
+ const message = new web3_js_1.TransactionMessage({
53
+ payerKey: this.wallet.publicKey,
54
+ recentBlockhash: '',
55
+ instructions: ixs,
56
+ }).compileToV0Message(lookupTableAccounts);
57
+ const tx = new web3_js_1.VersionedTransaction(message);
58
+ return tx;
59
+ }
60
+ async sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions) {
61
+ const latestBlockhash = await this.connection.getLatestBlockhash();
62
+ tx.message.recentBlockhash = latestBlockhash.blockhash;
63
+ let signedTx;
64
+ if (preSigned) {
65
+ signedTx = tx;
66
+ // @ts-ignore
67
+ }
68
+ else if (this.wallet.payer) {
69
+ // @ts-ignore
70
+ tx.sign((additionalSigners !== null && additionalSigners !== void 0 ? additionalSigners : []).concat(this.wallet.payer));
71
+ signedTx = tx;
72
+ }
73
+ else {
74
+ additionalSigners === null || additionalSigners === void 0 ? void 0 : additionalSigners.filter((s) => s !== undefined).forEach((kp) => {
75
+ tx.sign([kp]);
76
+ });
77
+ // @ts-ignore
78
+ signedTx = await this.wallet.signTransaction(tx);
79
+ }
80
+ if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
81
+ extraConfirmationOptions.onSignedCb();
82
+ }
83
+ if (opts === undefined) {
84
+ opts = this.opts;
85
+ }
86
+ const txSig = bs58_1.default.encode(signedTx.signatures[0]);
87
+ this.untilValid.set(txSig, latestBlockhash);
88
+ return this.sendRawTransaction(signedTx.serialize(), opts);
89
+ }
90
+ async sendRawTransaction(rawTransaction, opts) {
91
+ const startTime = this.getTimestamp();
92
+ const txid = await this.connection.sendRawTransaction(rawTransaction, opts);
93
+ this.sendToAdditionalConnections(rawTransaction, opts);
94
+ let done = false;
95
+ const resolveReference = {
96
+ resolve: undefined,
97
+ };
98
+ const stopWaiting = () => {
99
+ done = true;
100
+ if (resolveReference.resolve) {
101
+ resolveReference.resolve();
102
+ }
103
+ };
104
+ (async () => {
105
+ while (!done && this.getTimestamp() - startTime < this.timeout) {
106
+ await this.sleep(resolveReference);
107
+ if (!done) {
108
+ this.connection
109
+ .sendRawTransaction(rawTransaction, opts)
110
+ .catch((e) => {
111
+ console.error(e);
112
+ stopWaiting();
113
+ });
114
+ this.sendToAdditionalConnections(rawTransaction, opts);
115
+ }
116
+ }
117
+ })();
118
+ let slot;
119
+ try {
120
+ const { blockhash, lastValidBlockHeight } = this.untilValid.get(txid);
121
+ const result = await this.connection.confirmTransaction({
122
+ signature: txid,
123
+ lastValidBlockHeight,
124
+ blockhash,
125
+ }, opts.commitment);
126
+ slot = result.context.slot;
127
+ // eslint-disable-next-line no-useless-catch
128
+ }
129
+ catch (e) {
130
+ throw e;
131
+ }
132
+ finally {
133
+ stopWaiting();
134
+ }
135
+ return { txSig: txid, slot };
136
+ }
137
+ }
138
+ exports.WhileValidTxSender = WhileValidTxSender;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.75.0-beta.0",
3
+ "version": "2.75.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",