Skip to content

Commit

Permalink
Merge branch 'master' into nick/dlp-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lowkeynicc committed Jan 16, 2024
2 parents 9725446 + bc18f93 commit 94cf40b
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Features

### Fixes

### Breaking

## [2.54.0] - 2023-01-15

### Features
- sdk: move bracket orders into single instruction
- sdk: add ability to do placeAndTake order with bracket orders attached
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/drift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drift"
version = "2.53.0"
version = "2.54.0"
description = "Created with Anchor"
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.54.0-beta.12
2.55.0-beta.1
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@drift-labs/sdk",
"version": "2.54.0-beta.12",
"version": "2.55.0-beta.1",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "crispheaney",
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/accounts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export interface DriftClientAccountEvents {
error: (e: Error) => void;
}

export interface DriftClientMetricsEvents {
txSigned: void;
}

export interface DriftClientAccountSubscriber {
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
isSubscribed: boolean;
Expand Down
31 changes: 28 additions & 3 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ import {
DriftClientAccountSubscriber,
DriftClientAccountEvents,
DataAndSlot,
DriftClientMetricsEvents,
} from './accounts/types';
import { TxSender, TxSigAndSlot } from './tx/types';
import { ExtraConfirmationOptions, TxSender, TxSigAndSlot } from './tx/types';
import { getSignedTransactionMap, wrapInTx } from './tx/utils';
import {
BASE_PRECISION,
Expand Down Expand Up @@ -150,6 +151,10 @@ export class DriftClient {
userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig;
accountSubscriber: DriftClientAccountSubscriber;
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
metricsEventEmitter: StrictEventEmitter<
EventEmitter,
DriftClientMetricsEvents
>;
_isSubscribed = false;
txSender: TxSender;
perpMarketLastSlotCache = new Map<number, number>();
Expand All @@ -164,6 +169,7 @@ export class DriftClient {
skipLoadUsers?: boolean;
txVersion: TransactionVersion;
txParams: TxParams;
enableMetricsEvents?: boolean;

public get isSubscribed() {
return this._isSubscribed && this.accountSubscriber.isSubscribed;
Expand Down Expand Up @@ -288,6 +294,12 @@ export class DriftClient {
);
}
this.eventEmitter = this.accountSubscriber.eventEmitter;

if (config.enableMetricsEvents) {
this.enableMetricsEvents = true;
this.metricsEventEmitter = new EventEmitter();
}

this.txSender =
config.txSender ??
new RetryTxSender({
Expand Down Expand Up @@ -6330,25 +6342,38 @@ export class DriftClient {
return undefined;
}

private handleSignedTransaction() {
this.metricsEventEmitter.emit('txSigned');
}

sendTransaction(
tx: Transaction | VersionedTransaction,
additionalSigners?: Array<Signer>,
opts?: ConfirmOptions,
preSigned?: boolean
): Promise<TxSigAndSlot> {
const extraConfirmationOptions: ExtraConfirmationOptions = this
.enableMetricsEvents
? {
onSignedCb: this.handleSignedTransaction.bind(this),
}
: undefined;

if (tx instanceof VersionedTransaction) {
return this.txSender.sendVersionedTransaction(
tx as VersionedTransaction,
additionalSigners,
opts,
preSigned
preSigned,
extraConfirmationOptions
);
} else {
return this.txSender.send(
tx as Transaction,
additionalSigners,
opts,
preSigned
preSigned,
extraConfirmationOptions
);
}
}
Expand Down
1 change: 1 addition & 0 deletions sdk/src/driftClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type DriftClientConfig = {
skipLoadUsers?: boolean; // if passed to constructor, no user accounts will be loaded. they will load if updateWallet is called afterwards.
txVersion?: TransactionVersion; // which tx version to use
txParams?: TxParams; // default tx params to use
enableMetricsEvents?: boolean;
};

export type DriftClientSubscriptionConfig =
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.53.0",
"version": "2.54.0",
"name": "drift",
"instructions": [
{
Expand Down
21 changes: 18 additions & 3 deletions sdk/src/tx/baseTxSender.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ConfirmationStrategy, TxSender, TxSigAndSlot } from './types';
import {
ConfirmationStrategy,
ExtraConfirmationOptions,
TxSender,
TxSigAndSlot,
} from './types';
import {
Commitment,
ConfirmOptions,
Expand Down Expand Up @@ -57,7 +62,8 @@ export abstract class BaseTxSender implements TxSender {
tx: Transaction,
additionalSigners?: Array<Signer>,
opts?: ConfirmOptions,
preSigned?: boolean
preSigned?: boolean,
extraConfirmationOptions?: ExtraConfirmationOptions
): Promise<TxSigAndSlot> {
if (additionalSigners === undefined) {
additionalSigners = [];
Expand All @@ -70,6 +76,10 @@ export abstract class BaseTxSender implements TxSender {
? tx
: await this.prepareTx(tx, additionalSigners, opts);

if (extraConfirmationOptions?.onSignedCb) {
extraConfirmationOptions.onSignedCb();
}

return this.sendRawTransaction(signedTx.serialize(), opts);
}

Expand Down Expand Up @@ -124,7 +134,8 @@ export abstract class BaseTxSender implements TxSender {
tx: VersionedTransaction,
additionalSigners?: Array<Signer>,
opts?: ConfirmOptions,
preSigned?: boolean
preSigned?: boolean,
extraConfirmationOptions?: ExtraConfirmationOptions
): Promise<TxSigAndSlot> {
let signedTx;
if (preSigned) {
Expand All @@ -144,6 +155,10 @@ export abstract class BaseTxSender implements TxSender {
signedTx = await this.wallet.signTransaction(tx);
}

if (extraConfirmationOptions?.onSignedCb) {
extraConfirmationOptions.onSignedCb();
}

if (opts === undefined) {
opts = this.opts;
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/src/tx/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@ export type TxSigAndSlot = {
slot: number;
};

export type ExtraConfirmationOptions = {
onSignedCb: () => void;
};

export interface TxSender {
wallet: IWallet;

send(
tx: Transaction,
additionalSigners?: Array<Signer>,
opts?: ConfirmOptions,
preSigned?: boolean
preSigned?: boolean,
extraConfirmationOptions?: ExtraConfirmationOptions
): Promise<TxSigAndSlot>;

sendVersionedTransaction(
tx: VersionedTransaction,
additionalSigners?: Array<Signer>,
opts?: ConfirmOptions,
preSigned?: boolean
preSigned?: boolean,
extraConfirmationOptions?: ExtraConfirmationOptions
): Promise<TxSigAndSlot>;

getVersionedTransaction(
Expand Down

0 comments on commit 94cf40b

Please sign in to comment.