@drift-labs/sdk 2.68.0-beta.0 → 2.70.0-beta.0
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 +1 -1
- package/lib/driftClient.js +15 -9
- 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 +32 -22
- 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.0
|
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;
|
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,
|
|
@@ -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,
|
|
@@ -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
|
}
|