@drift-labs/sdk 2.69.0-beta.0 → 2.70.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.
- package/VERSION +1 -1
- package/lib/driftClient.d.ts +6 -5
- package/lib/driftClient.js +23 -17
- package/lib/factory/oracleClient.js +3 -4
- package/lib/idl/drift.json +1 -1
- package/lib/tx/baseTxSender.d.ts +1 -0
- package/lib/tx/baseTxSender.js +15 -0
- package/lib/tx/types.d.ts +1 -0
- package/lib/types.d.ts +0 -3
- package/lib/types.js +1 -1
- package/package.json +1 -1
- package/src/driftClient.ts +44 -29
- package/src/factory/oracleClient.ts +3 -4
- package/src/idl/drift.json +1 -1
- package/src/tx/baseTxSender.ts +15 -0
- package/src/tx/types.ts +2 -0
- package/src/types.ts +1 -1
- package/lib/idl/switchboard.json +0 -8354
- package/lib/oracles/switchboardClient.d.ts +0 -11
- package/lib/oracles/switchboardClient.js +0 -40
- package/src/idl/switchboard.json +0 -8354
- package/src/oracles/switchboardClient.ts +0 -77
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.70.0-beta.1
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -435,7 +435,7 @@ export declare class DriftClient {
|
|
|
435
435
|
updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
436
436
|
getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
437
437
|
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
438
|
-
placeAndTakePerpWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean): Promise<{
|
|
438
|
+
placeAndTakePerpWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, simulateFirst?: boolean): Promise<{
|
|
439
439
|
txSig: TransactionSignature;
|
|
440
440
|
signedCancelExistingOrdersTx?: Transaction;
|
|
441
441
|
signedSettlePnlTx?: Transaction;
|
|
@@ -613,7 +613,7 @@ export declare class DriftClient {
|
|
|
613
613
|
/**
|
|
614
614
|
* Add to an insurance fund stake and optionally initialize the account
|
|
615
615
|
*/
|
|
616
|
-
addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }: {
|
|
616
|
+
addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, txParams, }: {
|
|
617
617
|
/**
|
|
618
618
|
* Spot market index
|
|
619
619
|
*/
|
|
@@ -631,10 +631,11 @@ export declare class DriftClient {
|
|
|
631
631
|
* Optional -- withdraw from current subaccount to fund stake amount, instead of wallet balance
|
|
632
632
|
*/
|
|
633
633
|
fromSubaccount?: boolean;
|
|
634
|
+
txParams?: TxParams;
|
|
634
635
|
}): Promise<TransactionSignature>;
|
|
635
|
-
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
636
|
-
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
637
|
-
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
636
|
+
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
637
|
+
cancelRequestRemoveInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
638
|
+
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
638
639
|
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
639
640
|
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
640
641
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -2492,7 +2492,21 @@ class DriftClient {
|
|
|
2492
2492
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2493
2493
|
return txSig;
|
|
2494
2494
|
}
|
|
2495
|
-
async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl) {
|
|
2495
|
+
async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, simulateFirst) {
|
|
2496
|
+
const ixs = [];
|
|
2497
|
+
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId);
|
|
2498
|
+
ixs.push(placeAndTakeIx);
|
|
2499
|
+
if (bracketOrdersParams.length > 0) {
|
|
2500
|
+
const bracketOrdersIx = await this.getPlaceOrdersIx(bracketOrdersParams, subAccountId);
|
|
2501
|
+
ixs.push(bracketOrdersIx);
|
|
2502
|
+
}
|
|
2503
|
+
const placeAndTakeTx = (await this.buildTransaction(ixs, txParams));
|
|
2504
|
+
// if param is passed, return early before the tx fails so ui can fallback to placeOrder
|
|
2505
|
+
if (simulateFirst) {
|
|
2506
|
+
const success = await this.txSender.simulateTransaction(placeAndTakeTx);
|
|
2507
|
+
if (!success)
|
|
2508
|
+
return;
|
|
2509
|
+
}
|
|
2496
2510
|
let cancelExistingOrdersTx;
|
|
2497
2511
|
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
2498
2512
|
const cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, subAccountId);
|
|
@@ -2507,14 +2521,6 @@ class DriftClient {
|
|
|
2507
2521
|
//@ts-ignore
|
|
2508
2522
|
settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion);
|
|
2509
2523
|
}
|
|
2510
|
-
const ixs = [];
|
|
2511
|
-
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId);
|
|
2512
|
-
ixs.push(placeAndTakeIx);
|
|
2513
|
-
if (bracketOrdersParams.length > 0) {
|
|
2514
|
-
const bracketOrdersIx = await this.getPlaceOrdersIx(bracketOrdersParams, subAccountId);
|
|
2515
|
-
ixs.push(bracketOrdersIx);
|
|
2516
|
-
}
|
|
2517
|
-
const placeAndTakeTx = await this.buildTransaction(ixs, txParams);
|
|
2518
2524
|
const allPossibleTxs = [
|
|
2519
2525
|
placeAndTakeTx,
|
|
2520
2526
|
cancelExistingOrdersTx,
|
|
@@ -3221,7 +3227,7 @@ class DriftClient {
|
|
|
3221
3227
|
/**
|
|
3222
3228
|
* Add to an insurance fund stake and optionally initialize the account
|
|
3223
3229
|
*/
|
|
3224
|
-
async addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }) {
|
|
3230
|
+
async addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, txParams, }) {
|
|
3225
3231
|
const addIfStakeIxs = [];
|
|
3226
3232
|
const additionalSigners = [];
|
|
3227
3233
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -3251,11 +3257,11 @@ class DriftClient {
|
|
|
3251
3257
|
if (createWSOLTokenAccount) {
|
|
3252
3258
|
addIfStakeIxs.push((0, spl_token_1.createCloseAccountInstruction)(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
|
|
3253
3259
|
}
|
|
3254
|
-
const tx = await this.buildTransaction(addIfStakeIxs);
|
|
3260
|
+
const tx = await this.buildTransaction(addIfStakeIxs, txParams);
|
|
3255
3261
|
const { txSig } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
3256
3262
|
return txSig;
|
|
3257
3263
|
}
|
|
3258
|
-
async requestRemoveInsuranceFundStake(marketIndex, amount) {
|
|
3264
|
+
async requestRemoveInsuranceFundStake(marketIndex, amount, txParams) {
|
|
3259
3265
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
3260
3266
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
3261
3267
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -3274,11 +3280,11 @@ class DriftClient {
|
|
|
3274
3280
|
},
|
|
3275
3281
|
remainingAccounts,
|
|
3276
3282
|
});
|
|
3277
|
-
const tx = await this.buildTransaction(ix);
|
|
3283
|
+
const tx = await this.buildTransaction(ix, txParams);
|
|
3278
3284
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3279
3285
|
return txSig;
|
|
3280
3286
|
}
|
|
3281
|
-
async cancelRequestRemoveInsuranceFundStake(marketIndex) {
|
|
3287
|
+
async cancelRequestRemoveInsuranceFundStake(marketIndex, txParams) {
|
|
3282
3288
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
3283
3289
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
3284
3290
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -3297,11 +3303,11 @@ class DriftClient {
|
|
|
3297
3303
|
},
|
|
3298
3304
|
remainingAccounts,
|
|
3299
3305
|
});
|
|
3300
|
-
const tx = await this.buildTransaction(ix);
|
|
3306
|
+
const tx = await this.buildTransaction(ix, txParams);
|
|
3301
3307
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3302
3308
|
return txSig;
|
|
3303
3309
|
}
|
|
3304
|
-
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
3310
|
+
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey, txParams) {
|
|
3305
3311
|
var _a, _b;
|
|
3306
3312
|
const removeIfStakeIxs = [];
|
|
3307
3313
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -3351,7 +3357,7 @@ class DriftClient {
|
|
|
3351
3357
|
if (createWSOLTokenAccount) {
|
|
3352
3358
|
removeIfStakeIxs.push((0, spl_token_1.createCloseAccountInstruction)(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
|
|
3353
3359
|
}
|
|
3354
|
-
const tx = await this.buildTransaction(removeIfStakeIxs);
|
|
3360
|
+
const tx = await this.buildTransaction(removeIfStakeIxs, txParams);
|
|
3355
3361
|
const { txSig } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
3356
3362
|
return txSig;
|
|
3357
3363
|
}
|
|
@@ -6,7 +6,6 @@ const pythClient_1 = require("../oracles/pythClient");
|
|
|
6
6
|
// import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
7
7
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
8
8
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
|
-
const switchboardClient_1 = require("../oracles/switchboardClient");
|
|
10
9
|
function getOracleClient(oracleSource, connection) {
|
|
11
10
|
if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
|
|
12
11
|
return new pythClient_1.PythClient(connection);
|
|
@@ -20,9 +19,9 @@ function getOracleClient(oracleSource, connection) {
|
|
|
20
19
|
if ((0, types_1.isVariant)(oracleSource, 'pythStableCoin')) {
|
|
21
20
|
return new pythClient_1.PythClient(connection, undefined, true);
|
|
22
21
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
}
|
|
22
|
+
// if (isVariant(oracleSource, 'switchboard')) {
|
|
23
|
+
// return new SwitchboardClient(connection);
|
|
24
|
+
// }
|
|
26
25
|
if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) {
|
|
27
26
|
return new quoteAssetOracleClient_1.QuoteAssetOracleClient();
|
|
28
27
|
}
|
package/lib/idl/drift.json
CHANGED
package/lib/tx/baseTxSender.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare abstract class BaseTxSender implements TxSender {
|
|
|
25
25
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): 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
|
+
simulateTransaction(tx: VersionedTransaction): Promise<boolean>;
|
|
28
29
|
confirmTransactionWebSocket(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
29
30
|
confirmTransactionPolling(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult> | undefined>;
|
|
30
31
|
confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
package/lib/tx/baseTxSender.js
CHANGED
|
@@ -95,6 +95,21 @@ class BaseTxSender {
|
|
|
95
95
|
opts) {
|
|
96
96
|
throw new Error('Must be implemented by subclass');
|
|
97
97
|
}
|
|
98
|
+
/* Simulate the tx and return a boolean for success value */
|
|
99
|
+
async simulateTransaction(tx) {
|
|
100
|
+
try {
|
|
101
|
+
const result = await this.connection.simulateTransaction(tx);
|
|
102
|
+
if (result.value.err != null) {
|
|
103
|
+
console.error('Error in transaction simulation: ', result.value.err);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error('Error calling simulateTransaction: ', e);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
98
113
|
async confirmTransactionWebSocket(signature, commitment) {
|
|
99
114
|
var _a;
|
|
100
115
|
let decodedSignature;
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -19,5 +19,6 @@ export interface TxSender {
|
|
|
19
19
|
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
20
20
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
21
21
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
22
|
+
simulateTransaction(tx: VersionedTransaction): Promise<boolean>;
|
|
22
23
|
getTimeoutCount(): number;
|
|
23
24
|
}
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
|
@@ -95,7 +95,7 @@ exports.OracleSource = OracleSource;
|
|
|
95
95
|
OracleSource.PYTH = { pyth: {} };
|
|
96
96
|
OracleSource.PYTH_1K = { pyth1K: {} };
|
|
97
97
|
OracleSource.PYTH_1M = { pyth1M: {} };
|
|
98
|
-
|
|
98
|
+
// static readonly SWITCHBOARD = { switchboard: {} };
|
|
99
99
|
OracleSource.QUOTE_ASSET = { quoteAsset: {} };
|
|
100
100
|
OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
|
|
101
101
|
class OrderType {
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -4476,12 +4476,43 @@ export class DriftClient {
|
|
|
4476
4476
|
txParams?: TxParams,
|
|
4477
4477
|
subAccountId?: number,
|
|
4478
4478
|
cancelExistingOrders?: boolean,
|
|
4479
|
-
settlePnl?: boolean
|
|
4479
|
+
settlePnl?: boolean,
|
|
4480
|
+
simulateFirst?: boolean
|
|
4480
4481
|
): Promise<{
|
|
4481
4482
|
txSig: TransactionSignature;
|
|
4482
4483
|
signedCancelExistingOrdersTx?: Transaction;
|
|
4483
4484
|
signedSettlePnlTx?: Transaction;
|
|
4484
4485
|
}> {
|
|
4486
|
+
const ixs = [];
|
|
4487
|
+
|
|
4488
|
+
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(
|
|
4489
|
+
orderParams,
|
|
4490
|
+
makerInfo,
|
|
4491
|
+
referrerInfo,
|
|
4492
|
+
subAccountId
|
|
4493
|
+
);
|
|
4494
|
+
|
|
4495
|
+
ixs.push(placeAndTakeIx);
|
|
4496
|
+
|
|
4497
|
+
if (bracketOrdersParams.length > 0) {
|
|
4498
|
+
const bracketOrdersIx = await this.getPlaceOrdersIx(
|
|
4499
|
+
bracketOrdersParams,
|
|
4500
|
+
subAccountId
|
|
4501
|
+
);
|
|
4502
|
+
ixs.push(bracketOrdersIx);
|
|
4503
|
+
}
|
|
4504
|
+
|
|
4505
|
+
const placeAndTakeTx = (await this.buildTransaction(
|
|
4506
|
+
ixs,
|
|
4507
|
+
txParams
|
|
4508
|
+
)) as VersionedTransaction;
|
|
4509
|
+
|
|
4510
|
+
// if param is passed, return early before the tx fails so ui can fallback to placeOrder
|
|
4511
|
+
if (simulateFirst) {
|
|
4512
|
+
const success = await this.txSender.simulateTransaction(placeAndTakeTx);
|
|
4513
|
+
if (!success) return;
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4485
4516
|
let cancelExistingOrdersTx: Transaction;
|
|
4486
4517
|
if (cancelExistingOrders && isVariant(orderParams.marketType, 'perp')) {
|
|
4487
4518
|
const cancelOrdersIx = await this.getCancelOrdersIx(
|
|
@@ -4520,27 +4551,6 @@ export class DriftClient {
|
|
|
4520
4551
|
);
|
|
4521
4552
|
}
|
|
4522
4553
|
|
|
4523
|
-
const ixs = [];
|
|
4524
|
-
|
|
4525
|
-
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(
|
|
4526
|
-
orderParams,
|
|
4527
|
-
makerInfo,
|
|
4528
|
-
referrerInfo,
|
|
4529
|
-
subAccountId
|
|
4530
|
-
);
|
|
4531
|
-
|
|
4532
|
-
ixs.push(placeAndTakeIx);
|
|
4533
|
-
|
|
4534
|
-
if (bracketOrdersParams.length > 0) {
|
|
4535
|
-
const bracketOrdersIx = await this.getPlaceOrdersIx(
|
|
4536
|
-
bracketOrdersParams,
|
|
4537
|
-
subAccountId
|
|
4538
|
-
);
|
|
4539
|
-
ixs.push(bracketOrdersIx);
|
|
4540
|
-
}
|
|
4541
|
-
|
|
4542
|
-
const placeAndTakeTx = await this.buildTransaction(ixs, txParams);
|
|
4543
|
-
|
|
4544
4554
|
const allPossibleTxs = [
|
|
4545
4555
|
placeAndTakeTx,
|
|
4546
4556
|
cancelExistingOrdersTx,
|
|
@@ -5975,6 +5985,7 @@ export class DriftClient {
|
|
|
5975
5985
|
collateralAccountPublicKey,
|
|
5976
5986
|
initializeStakeAccount,
|
|
5977
5987
|
fromSubaccount,
|
|
5988
|
+
txParams,
|
|
5978
5989
|
}: {
|
|
5979
5990
|
/**
|
|
5980
5991
|
* Spot market index
|
|
@@ -5993,6 +6004,7 @@ export class DriftClient {
|
|
|
5993
6004
|
* Optional -- withdraw from current subaccount to fund stake amount, instead of wallet balance
|
|
5994
6005
|
*/
|
|
5995
6006
|
fromSubaccount?: boolean;
|
|
6007
|
+
txParams?: TxParams;
|
|
5996
6008
|
}): Promise<TransactionSignature> {
|
|
5997
6009
|
const addIfStakeIxs = [];
|
|
5998
6010
|
|
|
@@ -6052,7 +6064,7 @@ export class DriftClient {
|
|
|
6052
6064
|
);
|
|
6053
6065
|
}
|
|
6054
6066
|
|
|
6055
|
-
const tx = await this.buildTransaction(addIfStakeIxs);
|
|
6067
|
+
const tx = await this.buildTransaction(addIfStakeIxs, txParams);
|
|
6056
6068
|
|
|
6057
6069
|
const { txSig } = await this.sendTransaction(
|
|
6058
6070
|
tx,
|
|
@@ -6065,7 +6077,8 @@ export class DriftClient {
|
|
|
6065
6077
|
|
|
6066
6078
|
public async requestRemoveInsuranceFundStake(
|
|
6067
6079
|
marketIndex: number,
|
|
6068
|
-
amount: BN
|
|
6080
|
+
amount: BN,
|
|
6081
|
+
txParams?: TxParams
|
|
6069
6082
|
): Promise<TransactionSignature> {
|
|
6070
6083
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
6071
6084
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
@@ -6096,14 +6109,15 @@ export class DriftClient {
|
|
|
6096
6109
|
}
|
|
6097
6110
|
);
|
|
6098
6111
|
|
|
6099
|
-
const tx = await this.buildTransaction(ix);
|
|
6112
|
+
const tx = await this.buildTransaction(ix, txParams);
|
|
6100
6113
|
|
|
6101
6114
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6102
6115
|
return txSig;
|
|
6103
6116
|
}
|
|
6104
6117
|
|
|
6105
6118
|
public async cancelRequestRemoveInsuranceFundStake(
|
|
6106
|
-
marketIndex: number
|
|
6119
|
+
marketIndex: number,
|
|
6120
|
+
txParams?: TxParams
|
|
6107
6121
|
): Promise<TransactionSignature> {
|
|
6108
6122
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
6109
6123
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
@@ -6134,7 +6148,7 @@ export class DriftClient {
|
|
|
6134
6148
|
}
|
|
6135
6149
|
);
|
|
6136
6150
|
|
|
6137
|
-
const tx = await this.buildTransaction(ix);
|
|
6151
|
+
const tx = await this.buildTransaction(ix, txParams);
|
|
6138
6152
|
|
|
6139
6153
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6140
6154
|
return txSig;
|
|
@@ -6142,7 +6156,8 @@ export class DriftClient {
|
|
|
6142
6156
|
|
|
6143
6157
|
public async removeInsuranceFundStake(
|
|
6144
6158
|
marketIndex: number,
|
|
6145
|
-
collateralAccountPublicKey: PublicKey
|
|
6159
|
+
collateralAccountPublicKey: PublicKey,
|
|
6160
|
+
txParams?: TxParams
|
|
6146
6161
|
): Promise<TransactionSignature> {
|
|
6147
6162
|
const removeIfStakeIxs = [];
|
|
6148
6163
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -6223,7 +6238,7 @@ export class DriftClient {
|
|
|
6223
6238
|
);
|
|
6224
6239
|
}
|
|
6225
6240
|
|
|
6226
|
-
const tx = await this.buildTransaction(removeIfStakeIxs);
|
|
6241
|
+
const tx = await this.buildTransaction(removeIfStakeIxs, txParams);
|
|
6227
6242
|
|
|
6228
6243
|
const { txSig } = await this.sendTransaction(
|
|
6229
6244
|
tx,
|
|
@@ -5,7 +5,6 @@ import { PythClient } from '../oracles/pythClient';
|
|
|
5
5
|
// import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
6
6
|
import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
|
|
7
7
|
import { BN } from '@coral-xyz/anchor';
|
|
8
|
-
import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
9
8
|
|
|
10
9
|
export function getOracleClient(
|
|
11
10
|
oracleSource: OracleSource,
|
|
@@ -27,9 +26,9 @@ export function getOracleClient(
|
|
|
27
26
|
return new PythClient(connection, undefined, true);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
if (isVariant(oracleSource, 'switchboard')) {
|
|
31
|
-
|
|
32
|
-
}
|
|
29
|
+
// if (isVariant(oracleSource, 'switchboard')) {
|
|
30
|
+
// return new SwitchboardClient(connection);
|
|
31
|
+
// }
|
|
33
32
|
|
|
34
33
|
if (isVariant(oracleSource, 'quoteAsset')) {
|
|
35
34
|
return new QuoteAssetOracleClient();
|
package/src/idl/drift.json
CHANGED
package/src/tx/baseTxSender.ts
CHANGED
|
@@ -179,6 +179,21 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
179
179
|
throw new Error('Must be implemented by subclass');
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/* Simulate the tx and return a boolean for success value */
|
|
183
|
+
async simulateTransaction(tx: VersionedTransaction): Promise<boolean> {
|
|
184
|
+
try {
|
|
185
|
+
const result = await this.connection.simulateTransaction(tx);
|
|
186
|
+
if (result.value.err != null) {
|
|
187
|
+
console.error('Error in transaction simulation: ', result.value.err);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
} catch (e) {
|
|
192
|
+
console.error('Error calling simulateTransaction: ', e);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
182
197
|
async confirmTransactionWebSocket(
|
|
183
198
|
signature: TransactionSignature,
|
|
184
199
|
commitment?: Commitment
|
package/src/tx/types.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -93,7 +93,7 @@ export class OracleSource {
|
|
|
93
93
|
static readonly PYTH = { pyth: {} };
|
|
94
94
|
static readonly PYTH_1K = { pyth1K: {} };
|
|
95
95
|
static readonly PYTH_1M = { pyth1M: {} };
|
|
96
|
-
static readonly SWITCHBOARD = { switchboard: {} };
|
|
96
|
+
// static readonly SWITCHBOARD = { switchboard: {} };
|
|
97
97
|
static readonly QUOTE_ASSET = { quoteAsset: {} };
|
|
98
98
|
static readonly PYTH_STABLE_COIN = { pythStableCoin: {} };
|
|
99
99
|
}
|