@drift-labs/sdk 2.94.0-beta.5 → 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 +1 -1
- package/lib/bankrun/bankrunConnection.d.ts +2 -2
- package/lib/bankrun/bankrunConnection.js +28 -10
- package/lib/driftClient.js +4 -21
- package/lib/idl/drift.json +5 -0
- package/package.json +1 -1
- package/src/bankrun/bankrunConnection.ts +31 -13
- package/src/driftClient.ts +4 -23
- package/src/idl/drift.json +5 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.94.0-beta.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
108
|
-
|
|
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 =
|
|
113
|
-
? await internal.
|
|
114
|
-
: await internal.
|
|
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 =
|
|
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) {
|
package/lib/driftClient.js
CHANGED
|
@@ -1720,28 +1720,11 @@ class DriftClient {
|
|
|
1720
1720
|
return txSig;
|
|
1721
1721
|
}
|
|
1722
1722
|
async getSettleExpiredMarketIx(marketIndex) {
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
marketAccountInfos.push({
|
|
1728
|
-
pubkey: market.pubkey,
|
|
1729
|
-
isWritable: true,
|
|
1730
|
-
isSigner: false,
|
|
1731
|
-
});
|
|
1732
|
-
oracleAccountInfos.push({
|
|
1733
|
-
pubkey: market.amm.oracle,
|
|
1734
|
-
isWritable: false,
|
|
1735
|
-
isSigner: false,
|
|
1736
|
-
});
|
|
1737
|
-
spotMarketAccountInfos.push({
|
|
1738
|
-
pubkey: this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX).pubkey,
|
|
1739
|
-
isSigner: false,
|
|
1740
|
-
isWritable: true,
|
|
1723
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
1724
|
+
userAccounts: [],
|
|
1725
|
+
writablePerpMarketIndexes: [marketIndex],
|
|
1726
|
+
writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
1741
1727
|
});
|
|
1742
|
-
const remainingAccounts = oracleAccountInfos
|
|
1743
|
-
.concat(spotMarketAccountInfos)
|
|
1744
|
-
.concat(marketAccountInfos);
|
|
1745
1728
|
return await this.program.instruction.settleExpiredMarket(marketIndex, {
|
|
1746
1729
|
accounts: {
|
|
1747
1730
|
state: await this.getStatePublicKey(),
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
|
@@ -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
|
-
|
|
73
|
-
tx.feePayer = this.context.payer.publicKey;
|
|
73
|
+
const isVersioned = isVersionedTransaction(tx);
|
|
74
74
|
if (!additionalSigners) {
|
|
75
75
|
additionalSigners = [];
|
|
76
76
|
}
|
|
77
|
-
|
|
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(
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
223
|
-
|
|
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 =
|
|
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) {
|
package/src/driftClient.ts
CHANGED
|
@@ -3216,31 +3216,12 @@ export class DriftClient {
|
|
|
3216
3216
|
public async getSettleExpiredMarketIx(
|
|
3217
3217
|
marketIndex: number
|
|
3218
3218
|
): Promise<TransactionInstruction> {
|
|
3219
|
-
const
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
marketAccountInfos.push({
|
|
3224
|
-
pubkey: market.pubkey,
|
|
3225
|
-
isWritable: true,
|
|
3226
|
-
isSigner: false,
|
|
3227
|
-
});
|
|
3228
|
-
oracleAccountInfos.push({
|
|
3229
|
-
pubkey: market.amm.oracle,
|
|
3230
|
-
isWritable: false,
|
|
3231
|
-
isSigner: false,
|
|
3232
|
-
});
|
|
3233
|
-
|
|
3234
|
-
spotMarketAccountInfos.push({
|
|
3235
|
-
pubkey: this.getSpotMarketAccount(QUOTE_SPOT_MARKET_INDEX).pubkey,
|
|
3236
|
-
isSigner: false,
|
|
3237
|
-
isWritable: true,
|
|
3219
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
3220
|
+
userAccounts: [],
|
|
3221
|
+
writablePerpMarketIndexes: [marketIndex],
|
|
3222
|
+
writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
3238
3223
|
});
|
|
3239
3224
|
|
|
3240
|
-
const remainingAccounts = oracleAccountInfos
|
|
3241
|
-
.concat(spotMarketAccountInfos)
|
|
3242
|
-
.concat(marketAccountInfos);
|
|
3243
|
-
|
|
3244
3225
|
return await this.program.instruction.settleExpiredMarket(marketIndex, {
|
|
3245
3226
|
accounts: {
|
|
3246
3227
|
state: await this.getStatePublicKey(),
|