@drift-labs/sdk 2.55.0-beta.0 → 2.55.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.
- package/VERSION +1 -1
- package/lib/accounts/types.d.ts +3 -0
- package/lib/driftClient.d.ts +4 -1
- package/lib/driftClient.js +16 -2
- package/lib/driftClientConfig.d.ts +1 -0
- package/lib/tx/baseTxSender.d.ts +3 -3
- package/lib/tx/baseTxSender.js +8 -2
- package/lib/tx/retryTxSender.js +1 -0
- package/lib/tx/types.d.ts +5 -2
- package/lib/user.js +1 -1
- package/package.json +1 -1
- package/src/accounts/types.ts +4 -0
- package/src/driftClient.ts +28 -3
- package/src/driftClientConfig.ts +1 -0
- package/src/tx/baseTxSender.ts +18 -3
- package/src/tx/retryTxSender.ts +1 -0
- package/src/tx/types.ts +8 -2
- package/src/user.ts +3 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.55.0-beta.
|
|
1
|
+
2.55.0-beta.2
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export interface DriftClientAccountEvents {
|
|
|
29
29
|
update: void;
|
|
30
30
|
error: (e: Error) => void;
|
|
31
31
|
}
|
|
32
|
+
export interface DriftClientMetricsEvents {
|
|
33
|
+
txSigned: void;
|
|
34
|
+
}
|
|
32
35
|
export interface DriftClientAccountSubscriber {
|
|
33
36
|
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
34
37
|
isSubscribed: boolean;
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transactio
|
|
|
7
7
|
import { TokenFaucet } from './tokenFaucet';
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
|
-
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './accounts/types';
|
|
10
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot, DriftClientMetricsEvents } from './accounts/types';
|
|
11
11
|
import { TxSender, TxSigAndSlot } from './tx/types';
|
|
12
12
|
import { OraclePriceData } from './oracles/types';
|
|
13
13
|
import { DriftClientConfig } from './driftClientConfig';
|
|
@@ -41,6 +41,7 @@ export declare class DriftClient {
|
|
|
41
41
|
userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig;
|
|
42
42
|
accountSubscriber: DriftClientAccountSubscriber;
|
|
43
43
|
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
44
|
+
metricsEventEmitter: StrictEventEmitter<EventEmitter, DriftClientMetricsEvents>;
|
|
44
45
|
_isSubscribed: boolean;
|
|
45
46
|
txSender: TxSender;
|
|
46
47
|
perpMarketLastSlotCache: Map<number, number>;
|
|
@@ -55,6 +56,7 @@ export declare class DriftClient {
|
|
|
55
56
|
skipLoadUsers?: boolean;
|
|
56
57
|
txVersion: TransactionVersion;
|
|
57
58
|
txParams: TxParams;
|
|
59
|
+
enableMetricsEvents?: boolean;
|
|
58
60
|
get isSubscribed(): boolean;
|
|
59
61
|
set isSubscribed(val: boolean);
|
|
60
62
|
constructor(config: DriftClientConfig);
|
|
@@ -644,6 +646,7 @@ export declare class DriftClient {
|
|
|
644
646
|
marketIndex: number;
|
|
645
647
|
marketType: MarketType;
|
|
646
648
|
} | undefined;
|
|
649
|
+
private handleSignedTransaction;
|
|
647
650
|
sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
648
651
|
buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[]): Promise<Transaction | VersionedTransaction>;
|
|
649
652
|
}
|
package/lib/driftClient.js
CHANGED
|
@@ -34,6 +34,7 @@ const types_1 = require("./types");
|
|
|
34
34
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
35
35
|
const drift_json_1 = __importDefault(require("./idl/drift.json"));
|
|
36
36
|
const web3_js_1 = require("@solana/web3.js");
|
|
37
|
+
const events_1 = require("events");
|
|
37
38
|
const pda_1 = require("./addresses/pda");
|
|
38
39
|
const utils_1 = require("./tx/utils");
|
|
39
40
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
@@ -146,6 +147,10 @@ class DriftClient {
|
|
|
146
147
|
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_v = config.perpMarketIndexes) !== null && _v !== void 0 ? _v : [], (_w = config.spotMarketIndexes) !== null && _w !== void 0 ? _w : [], (_x = config.oracleInfos) !== null && _x !== void 0 ? _x : [], noMarketsAndOraclesSpecified, (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs, (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.commitment);
|
|
147
148
|
}
|
|
148
149
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
150
|
+
if (config.enableMetricsEvents) {
|
|
151
|
+
this.enableMetricsEvents = true;
|
|
152
|
+
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
153
|
+
}
|
|
149
154
|
this.txSender =
|
|
150
155
|
(_0 = config.txSender) !== null && _0 !== void 0 ? _0 : new retryTxSender_1.RetryTxSender({
|
|
151
156
|
connection: this.connection,
|
|
@@ -3416,12 +3421,21 @@ class DriftClient {
|
|
|
3416
3421
|
}
|
|
3417
3422
|
return undefined;
|
|
3418
3423
|
}
|
|
3424
|
+
handleSignedTransaction() {
|
|
3425
|
+
this.metricsEventEmitter.emit('txSigned');
|
|
3426
|
+
}
|
|
3419
3427
|
sendTransaction(tx, additionalSigners, opts, preSigned) {
|
|
3428
|
+
const extraConfirmationOptions = this
|
|
3429
|
+
.enableMetricsEvents
|
|
3430
|
+
? {
|
|
3431
|
+
onSignedCb: this.handleSignedTransaction.bind(this),
|
|
3432
|
+
}
|
|
3433
|
+
: undefined;
|
|
3420
3434
|
if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
3421
|
-
return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned);
|
|
3435
|
+
return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions);
|
|
3422
3436
|
}
|
|
3423
3437
|
else {
|
|
3424
|
-
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
3438
|
+
return this.txSender.send(tx, additionalSigners, opts, preSigned, extraConfirmationOptions);
|
|
3425
3439
|
}
|
|
3426
3440
|
}
|
|
3427
3441
|
async buildTransaction(instructions, txParams, txVersion, lookupTables) {
|
package/lib/tx/baseTxSender.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ConfirmationStrategy, TxSender, TxSigAndSlot } from './types';
|
|
2
|
+
import { ConfirmationStrategy, ExtraConfirmationOptions, TxSender, TxSigAndSlot } from './types';
|
|
3
3
|
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, VersionedTransaction, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
4
4
|
import { IWallet } from '../types';
|
|
5
5
|
export declare abstract class BaseTxSender implements TxSender {
|
|
@@ -18,10 +18,10 @@ export declare abstract class BaseTxSender implements TxSender {
|
|
|
18
18
|
additionalConnections?: any;
|
|
19
19
|
confirmationStrategy?: ConfirmationStrategy;
|
|
20
20
|
});
|
|
21
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
21
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
22
22
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
23
23
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
24
|
-
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
24
|
+
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
25
25
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
26
26
|
confirmTransactionWebSocket(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
27
27
|
confirmTransactionPolling(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult> | undefined>;
|
package/lib/tx/baseTxSender.js
CHANGED
|
@@ -20,7 +20,7 @@ class BaseTxSender {
|
|
|
20
20
|
this.additionalConnections = additionalConnections;
|
|
21
21
|
this.confirmationStrategy = confirmationStrategy;
|
|
22
22
|
}
|
|
23
|
-
async send(tx, additionalSigners, opts, preSigned) {
|
|
23
|
+
async send(tx, additionalSigners, opts, preSigned, extraConfirmationOptions) {
|
|
24
24
|
if (additionalSigners === undefined) {
|
|
25
25
|
additionalSigners = [];
|
|
26
26
|
}
|
|
@@ -30,6 +30,9 @@ class BaseTxSender {
|
|
|
30
30
|
const signedTx = preSigned
|
|
31
31
|
? tx
|
|
32
32
|
: await this.prepareTx(tx, additionalSigners, opts);
|
|
33
|
+
if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
|
|
34
|
+
extraConfirmationOptions.onSignedCb();
|
|
35
|
+
}
|
|
33
36
|
return this.sendRawTransaction(signedTx.serialize(), opts);
|
|
34
37
|
}
|
|
35
38
|
async prepareTx(tx, additionalSigners, opts) {
|
|
@@ -58,7 +61,7 @@ class BaseTxSender {
|
|
|
58
61
|
const tx = new web3_js_1.VersionedTransaction(message);
|
|
59
62
|
return tx;
|
|
60
63
|
}
|
|
61
|
-
async sendVersionedTransaction(tx, additionalSigners, opts, preSigned) {
|
|
64
|
+
async sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions) {
|
|
62
65
|
let signedTx;
|
|
63
66
|
if (preSigned) {
|
|
64
67
|
signedTx = tx;
|
|
@@ -76,6 +79,9 @@ class BaseTxSender {
|
|
|
76
79
|
// @ts-ignore
|
|
77
80
|
signedTx = await this.wallet.signTransaction(tx);
|
|
78
81
|
}
|
|
82
|
+
if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
|
|
83
|
+
extraConfirmationOptions.onSignedCb();
|
|
84
|
+
}
|
|
79
85
|
if (opts === undefined) {
|
|
80
86
|
opts = this.opts;
|
|
81
87
|
}
|
package/lib/tx/retryTxSender.js
CHANGED
package/lib/tx/types.d.ts
CHANGED
|
@@ -10,10 +10,13 @@ export type TxSigAndSlot = {
|
|
|
10
10
|
txSig: TransactionSignature;
|
|
11
11
|
slot: number;
|
|
12
12
|
};
|
|
13
|
+
export type ExtraConfirmationOptions = {
|
|
14
|
+
onSignedCb: () => void;
|
|
15
|
+
};
|
|
13
16
|
export interface TxSender {
|
|
14
17
|
wallet: IWallet;
|
|
15
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
16
|
-
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
18
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
19
|
+
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
17
20
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
18
21
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
19
22
|
getTimeoutCount(): number;
|
package/lib/user.js
CHANGED
|
@@ -488,7 +488,7 @@ class User {
|
|
|
488
488
|
*/
|
|
489
489
|
getUnrealizedPNL(withFunding, marketIndex, withWeightMarginCategory, strict = false) {
|
|
490
490
|
return this.getActivePerpPositions()
|
|
491
|
-
.filter((pos) =>
|
|
491
|
+
.filter((pos) => marketIndex !== undefined ? pos.marketIndex === marketIndex : true)
|
|
492
492
|
.reduce((unrealizedPnl, perpPosition) => {
|
|
493
493
|
const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
|
|
494
494
|
const oraclePriceData = this.getOracleDataForPerpMarket(market.marketIndex);
|
package/package.json
CHANGED
package/src/accounts/types.ts
CHANGED
|
@@ -43,6 +43,10 @@ export interface DriftClientAccountEvents {
|
|
|
43
43
|
error: (e: Error) => void;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
export interface DriftClientMetricsEvents {
|
|
47
|
+
txSigned: void;
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
export interface DriftClientAccountSubscriber {
|
|
47
51
|
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
48
52
|
isSubscribed: boolean;
|
package/src/driftClient.ts
CHANGED
|
@@ -86,8 +86,9 @@ import {
|
|
|
86
86
|
DriftClientAccountSubscriber,
|
|
87
87
|
DriftClientAccountEvents,
|
|
88
88
|
DataAndSlot,
|
|
89
|
+
DriftClientMetricsEvents,
|
|
89
90
|
} from './accounts/types';
|
|
90
|
-
import { TxSender, TxSigAndSlot } from './tx/types';
|
|
91
|
+
import { ExtraConfirmationOptions, TxSender, TxSigAndSlot } from './tx/types';
|
|
91
92
|
import { getSignedTransactionMap, wrapInTx } from './tx/utils';
|
|
92
93
|
import {
|
|
93
94
|
BASE_PRECISION,
|
|
@@ -150,6 +151,10 @@ export class DriftClient {
|
|
|
150
151
|
userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig;
|
|
151
152
|
accountSubscriber: DriftClientAccountSubscriber;
|
|
152
153
|
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
154
|
+
metricsEventEmitter: StrictEventEmitter<
|
|
155
|
+
EventEmitter,
|
|
156
|
+
DriftClientMetricsEvents
|
|
157
|
+
>;
|
|
153
158
|
_isSubscribed = false;
|
|
154
159
|
txSender: TxSender;
|
|
155
160
|
perpMarketLastSlotCache = new Map<number, number>();
|
|
@@ -164,6 +169,7 @@ export class DriftClient {
|
|
|
164
169
|
skipLoadUsers?: boolean;
|
|
165
170
|
txVersion: TransactionVersion;
|
|
166
171
|
txParams: TxParams;
|
|
172
|
+
enableMetricsEvents?: boolean;
|
|
167
173
|
|
|
168
174
|
public get isSubscribed() {
|
|
169
175
|
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
@@ -288,6 +294,12 @@ export class DriftClient {
|
|
|
288
294
|
);
|
|
289
295
|
}
|
|
290
296
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
297
|
+
|
|
298
|
+
if (config.enableMetricsEvents) {
|
|
299
|
+
this.enableMetricsEvents = true;
|
|
300
|
+
this.metricsEventEmitter = new EventEmitter();
|
|
301
|
+
}
|
|
302
|
+
|
|
291
303
|
this.txSender =
|
|
292
304
|
config.txSender ??
|
|
293
305
|
new RetryTxSender({
|
|
@@ -6322,25 +6334,38 @@ export class DriftClient {
|
|
|
6322
6334
|
return undefined;
|
|
6323
6335
|
}
|
|
6324
6336
|
|
|
6337
|
+
private handleSignedTransaction() {
|
|
6338
|
+
this.metricsEventEmitter.emit('txSigned');
|
|
6339
|
+
}
|
|
6340
|
+
|
|
6325
6341
|
sendTransaction(
|
|
6326
6342
|
tx: Transaction | VersionedTransaction,
|
|
6327
6343
|
additionalSigners?: Array<Signer>,
|
|
6328
6344
|
opts?: ConfirmOptions,
|
|
6329
6345
|
preSigned?: boolean
|
|
6330
6346
|
): Promise<TxSigAndSlot> {
|
|
6347
|
+
const extraConfirmationOptions: ExtraConfirmationOptions = this
|
|
6348
|
+
.enableMetricsEvents
|
|
6349
|
+
? {
|
|
6350
|
+
onSignedCb: this.handleSignedTransaction.bind(this),
|
|
6351
|
+
}
|
|
6352
|
+
: undefined;
|
|
6353
|
+
|
|
6331
6354
|
if (tx instanceof VersionedTransaction) {
|
|
6332
6355
|
return this.txSender.sendVersionedTransaction(
|
|
6333
6356
|
tx as VersionedTransaction,
|
|
6334
6357
|
additionalSigners,
|
|
6335
6358
|
opts,
|
|
6336
|
-
preSigned
|
|
6359
|
+
preSigned,
|
|
6360
|
+
extraConfirmationOptions
|
|
6337
6361
|
);
|
|
6338
6362
|
} else {
|
|
6339
6363
|
return this.txSender.send(
|
|
6340
6364
|
tx as Transaction,
|
|
6341
6365
|
additionalSigners,
|
|
6342
6366
|
opts,
|
|
6343
|
-
preSigned
|
|
6367
|
+
preSigned,
|
|
6368
|
+
extraConfirmationOptions
|
|
6344
6369
|
);
|
|
6345
6370
|
}
|
|
6346
6371
|
}
|
package/src/driftClientConfig.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type DriftClientConfig = {
|
|
|
32
32
|
skipLoadUsers?: boolean; // if passed to constructor, no user accounts will be loaded. they will load if updateWallet is called afterwards.
|
|
33
33
|
txVersion?: TransactionVersion; // which tx version to use
|
|
34
34
|
txParams?: TxParams; // default tx params to use
|
|
35
|
+
enableMetricsEvents?: boolean;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export type DriftClientSubscriptionConfig =
|
package/src/tx/baseTxSender.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ConfirmationStrategy,
|
|
3
|
+
ExtraConfirmationOptions,
|
|
4
|
+
TxSender,
|
|
5
|
+
TxSigAndSlot,
|
|
6
|
+
} from './types';
|
|
2
7
|
import {
|
|
3
8
|
Commitment,
|
|
4
9
|
ConfirmOptions,
|
|
@@ -57,7 +62,8 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
57
62
|
tx: Transaction,
|
|
58
63
|
additionalSigners?: Array<Signer>,
|
|
59
64
|
opts?: ConfirmOptions,
|
|
60
|
-
preSigned?: boolean
|
|
65
|
+
preSigned?: boolean,
|
|
66
|
+
extraConfirmationOptions?: ExtraConfirmationOptions
|
|
61
67
|
): Promise<TxSigAndSlot> {
|
|
62
68
|
if (additionalSigners === undefined) {
|
|
63
69
|
additionalSigners = [];
|
|
@@ -70,6 +76,10 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
70
76
|
? tx
|
|
71
77
|
: await this.prepareTx(tx, additionalSigners, opts);
|
|
72
78
|
|
|
79
|
+
if (extraConfirmationOptions?.onSignedCb) {
|
|
80
|
+
extraConfirmationOptions.onSignedCb();
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
return this.sendRawTransaction(signedTx.serialize(), opts);
|
|
74
84
|
}
|
|
75
85
|
|
|
@@ -124,7 +134,8 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
124
134
|
tx: VersionedTransaction,
|
|
125
135
|
additionalSigners?: Array<Signer>,
|
|
126
136
|
opts?: ConfirmOptions,
|
|
127
|
-
preSigned?: boolean
|
|
137
|
+
preSigned?: boolean,
|
|
138
|
+
extraConfirmationOptions?: ExtraConfirmationOptions
|
|
128
139
|
): Promise<TxSigAndSlot> {
|
|
129
140
|
let signedTx;
|
|
130
141
|
if (preSigned) {
|
|
@@ -144,6 +155,10 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
144
155
|
signedTx = await this.wallet.signTransaction(tx);
|
|
145
156
|
}
|
|
146
157
|
|
|
158
|
+
if (extraConfirmationOptions?.onSignedCb) {
|
|
159
|
+
extraConfirmationOptions.onSignedCb();
|
|
160
|
+
}
|
|
161
|
+
|
|
147
162
|
if (opts === undefined) {
|
|
148
163
|
opts = this.opts;
|
|
149
164
|
}
|
package/src/tx/retryTxSender.ts
CHANGED
package/src/tx/types.ts
CHANGED
|
@@ -20,6 +20,10 @@ export type TxSigAndSlot = {
|
|
|
20
20
|
slot: number;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
export type ExtraConfirmationOptions = {
|
|
24
|
+
onSignedCb: () => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
23
27
|
export interface TxSender {
|
|
24
28
|
wallet: IWallet;
|
|
25
29
|
|
|
@@ -27,14 +31,16 @@ export interface TxSender {
|
|
|
27
31
|
tx: Transaction,
|
|
28
32
|
additionalSigners?: Array<Signer>,
|
|
29
33
|
opts?: ConfirmOptions,
|
|
30
|
-
preSigned?: boolean
|
|
34
|
+
preSigned?: boolean,
|
|
35
|
+
extraConfirmationOptions?: ExtraConfirmationOptions
|
|
31
36
|
): Promise<TxSigAndSlot>;
|
|
32
37
|
|
|
33
38
|
sendVersionedTransaction(
|
|
34
39
|
tx: VersionedTransaction,
|
|
35
40
|
additionalSigners?: Array<Signer>,
|
|
36
41
|
opts?: ConfirmOptions,
|
|
37
|
-
preSigned?: boolean
|
|
42
|
+
preSigned?: boolean,
|
|
43
|
+
extraConfirmationOptions?: ExtraConfirmationOptions
|
|
38
44
|
): Promise<TxSigAndSlot>;
|
|
39
45
|
|
|
40
46
|
getVersionedTransaction(
|
package/src/user.ts
CHANGED
|
@@ -766,7 +766,9 @@ export class User {
|
|
|
766
766
|
strict = false
|
|
767
767
|
): BN {
|
|
768
768
|
return this.getActivePerpPositions()
|
|
769
|
-
.filter((pos) =>
|
|
769
|
+
.filter((pos) =>
|
|
770
|
+
marketIndex !== undefined ? pos.marketIndex === marketIndex : true
|
|
771
|
+
)
|
|
770
772
|
.reduce((unrealizedPnl, perpPosition) => {
|
|
771
773
|
const market = this.driftClient.getPerpMarketAccount(
|
|
772
774
|
perpPosition.marketIndex
|