@drift-labs/sdk 2.94.0-beta.6 → 2.94.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.94.0-beta.6
1
+ 2.94.0-beta.7
@@ -20,7 +20,7 @@ export declare class BankrunContextWrapper {
20
20
  readonly provider: BankrunProvider;
21
21
  readonly commitment: Commitment;
22
22
  constructor(context: ProgramTestContext, verifySignatures?: boolean);
23
- sendTransaction(tx: Transaction, additionalSigners?: Keypair[]): Promise<TransactionSignature>;
23
+ sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Keypair[]): Promise<TransactionSignature>;
24
24
  getMinimumBalanceForRentExemption(_: number): Promise<number>;
25
25
  fundKeypair(keypair: Keypair | Wallet, lamports: number | bigint): Promise<TransactionSignature>;
26
26
  getLatestBlockhash(): Promise<Blockhash>;
@@ -45,7 +45,7 @@ export declare class BankrunConnection {
45
45
  getAccountInfo(publicKey: PublicKey): Promise<null | AccountInfo<Buffer>>;
46
46
  getAccountInfoAndContext(publicKey: PublicKey, _commitment?: Commitment): Promise<RpcResponseAndContext<null | AccountInfo<Buffer>>>;
47
47
  sendRawTransaction(rawTransaction: Buffer | Uint8Array | Array<number>, _options?: any): Promise<TransactionSignature>;
48
- sendTransaction(tx: Transaction): Promise<TransactionSignature>;
48
+ sendTransaction(tx: Transaction | VersionedTransaction): Promise<TransactionSignature>;
49
49
  private updateSlotAndClock;
50
50
  getTime(): number;
51
51
  getParsedAccountInfo(publicKey: PublicKey): Promise<RpcResponseAndContext<AccountInfo<Buffer>>>;
@@ -10,6 +10,7 @@ const anchor_bankrun_1 = require("anchor-bankrun");
10
10
  const bs58_1 = __importDefault(require("bs58"));
11
11
  const anchor_1 = require("@coral-xyz/anchor");
12
12
  const spl_token_1 = require("@solana/spl-token");
13
+ const utils_1 = require("../tx/utils");
13
14
  class BankrunContextWrapper {
14
15
  constructor(context, verifySignatures = true) {
15
16
  this.commitment = 'confirmed';
@@ -18,12 +19,24 @@ class BankrunContextWrapper {
18
19
  this.connection = new BankrunConnection(this.context.banksClient, this.context, verifySignatures);
19
20
  }
20
21
  async sendTransaction(tx, additionalSigners) {
21
- tx.recentBlockhash = (await this.getLatestBlockhash()).toString();
22
- tx.feePayer = this.context.payer.publicKey;
22
+ const isVersioned = (0, utils_1.isVersionedTransaction)(tx);
23
23
  if (!additionalSigners) {
24
24
  additionalSigners = [];
25
25
  }
26
- tx.sign(this.context.payer, ...additionalSigners);
26
+ if (isVersioned) {
27
+ tx = tx;
28
+ tx.message.recentBlockhash = await this.getLatestBlockhash();
29
+ if (!additionalSigners) {
30
+ additionalSigners = [];
31
+ }
32
+ tx.sign([this.context.payer, ...additionalSigners]);
33
+ }
34
+ else {
35
+ tx = tx;
36
+ tx.recentBlockhash = await this.getLatestBlockhash();
37
+ tx.feePayer = this.context.payer.publicKey;
38
+ tx.sign(this.context.payer, ...additionalSigners);
39
+ }
27
40
  return await this.connection.sendTransaction(tx);
28
41
  }
29
42
  async getMinimumBalanceForRentExemption(_) {
@@ -104,19 +117,24 @@ class BankrunConnection {
104
117
  return signature;
105
118
  }
106
119
  async sendTransaction(tx) {
107
- const serialized = tx.serialize({
108
- verifySignatures: this.verifySignatures,
109
- });
120
+ const isVersioned = (0, utils_1.isVersionedTransaction)(tx);
121
+ const serialized = isVersioned
122
+ ? tx.serialize()
123
+ : tx.serialize({
124
+ verifySignatures: this.verifySignatures,
125
+ });
110
126
  // @ts-ignore
111
127
  const internal = this._banksClient.inner;
112
- const inner = tx instanceof web3_js_1.Transaction
113
- ? await internal.tryProcessLegacyTransaction(serialized)
114
- : await internal.tryProcessVersionedTransaction(serialized);
128
+ const inner = isVersioned
129
+ ? await internal.tryProcessVersionedTransaction(serialized)
130
+ : await internal.tryProcessLegacyTransaction(serialized);
115
131
  const banksTransactionMeta = new solana_bankrun_1.BanksTransactionResultWithMeta(inner);
116
132
  if (banksTransactionMeta.result) {
117
133
  throw new Error(banksTransactionMeta.result);
118
134
  }
119
- const signature = bs58_1.default.encode(tx.signatures[0].signature);
135
+ const signature = isVersioned
136
+ ? bs58_1.default.encode(tx.signatures[0])
137
+ : bs58_1.default.encode(tx.signatures[0].signature);
120
138
  this.transactionToMeta.set(signature, banksTransactionMeta);
121
139
  let finalizedCount = 0;
122
140
  while (finalizedCount < 10) {
@@ -1893,6 +1893,11 @@
1893
1893
  "name": "user",
1894
1894
  "isMut": true,
1895
1895
  "isSigner": false
1896
+ },
1897
+ {
1898
+ "name": "authority",
1899
+ "isMut": false,
1900
+ "isSigner": true
1896
1901
  }
1897
1902
  ],
1898
1903
  "args": []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.94.0-beta.6",
3
+ "version": "2.94.0-beta.7",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -36,6 +36,7 @@ import { BankrunProvider } from 'anchor-bankrun';
36
36
  import bs58 from 'bs58';
37
37
  import { BN, Wallet } from '@coral-xyz/anchor';
38
38
  import { Account, unpackAccount } from '@solana/spl-token';
39
+ import { isVersionedTransaction } from '../tx/utils';
39
40
 
40
41
  export type Connection = SolanaConnection | BankrunConnection;
41
42
 
@@ -66,15 +67,26 @@ export class BankrunContextWrapper {
66
67
  }
67
68
 
68
69
  async sendTransaction(
69
- tx: Transaction,
70
+ tx: Transaction | VersionedTransaction,
70
71
  additionalSigners?: Keypair[]
71
72
  ): Promise<TransactionSignature> {
72
- tx.recentBlockhash = (await this.getLatestBlockhash()).toString();
73
- tx.feePayer = this.context.payer.publicKey;
73
+ const isVersioned = isVersionedTransaction(tx);
74
74
  if (!additionalSigners) {
75
75
  additionalSigners = [];
76
76
  }
77
- tx.sign(this.context.payer, ...additionalSigners);
77
+ if (isVersioned) {
78
+ tx = tx as VersionedTransaction;
79
+ tx.message.recentBlockhash = await this.getLatestBlockhash();
80
+ if (!additionalSigners) {
81
+ additionalSigners = [];
82
+ }
83
+ tx.sign([this.context.payer, ...additionalSigners]);
84
+ } else {
85
+ tx = tx as Transaction;
86
+ tx.recentBlockhash = await this.getLatestBlockhash();
87
+ tx.feePayer = this.context.payer.publicKey;
88
+ tx.sign(this.context.payer, ...additionalSigners);
89
+ }
78
90
  return await this.connection.sendTransaction(tx);
79
91
  }
80
92
 
@@ -212,22 +224,28 @@ export class BankrunConnection {
212
224
  return signature;
213
225
  }
214
226
 
215
- async sendTransaction(tx: Transaction): Promise<TransactionSignature> {
216
- const serialized = tx.serialize({
217
- verifySignatures: this.verifySignatures,
218
- });
227
+ async sendTransaction(
228
+ tx: Transaction | VersionedTransaction
229
+ ): Promise<TransactionSignature> {
230
+ const isVersioned = isVersionedTransaction(tx);
231
+ const serialized = isVersioned
232
+ ? tx.serialize()
233
+ : tx.serialize({
234
+ verifySignatures: this.verifySignatures,
235
+ });
219
236
  // @ts-ignore
220
237
  const internal = this._banksClient.inner;
221
- const inner =
222
- tx instanceof Transaction
223
- ? await internal.tryProcessLegacyTransaction(serialized)
224
- : await internal.tryProcessVersionedTransaction(serialized);
238
+ const inner = isVersioned
239
+ ? await internal.tryProcessVersionedTransaction(serialized)
240
+ : await internal.tryProcessLegacyTransaction(serialized);
225
241
  const banksTransactionMeta = new BanksTransactionResultWithMeta(inner);
226
242
 
227
243
  if (banksTransactionMeta.result) {
228
244
  throw new Error(banksTransactionMeta.result);
229
245
  }
230
- const signature = bs58.encode(tx.signatures[0].signature);
246
+ const signature = isVersioned
247
+ ? bs58.encode((tx as VersionedTransaction).signatures[0])
248
+ : bs58.encode((tx as Transaction).signatures[0].signature);
231
249
  this.transactionToMeta.set(signature, banksTransactionMeta);
232
250
  let finalizedCount = 0;
233
251
  while (finalizedCount < 10) {
@@ -1893,6 +1893,11 @@
1893
1893
  "name": "user",
1894
1894
  "isMut": true,
1895
1895
  "isSigner": false
1896
+ },
1897
+ {
1898
+ "name": "authority",
1899
+ "isMut": false,
1900
+ "isSigner": true
1896
1901
  }
1897
1902
  ],
1898
1903
  "args": []