@drift-labs/sdk-browser 2.104.0-beta.25 → 2.104.0-beta.26

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 CHANGED
@@ -1 +1 @@
1
- 2.104.0-beta.25
1
+ 2.104.0-beta.26
@@ -25,8 +25,6 @@ type DriftConfig = {
25
25
  export type DriftEnv = 'devnet' | 'mainnet-beta';
26
26
  export declare const DRIFT_PROGRAM_ID = "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH";
27
27
  export declare const DRIFT_ORACLE_RECEIVER_ID = "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha";
28
- export declare const SWIFT_ID = "SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS";
29
- export declare const ANCHOR_TEST_SWIFT_ID = "DpaEdAPW3ZX67fnczT14AoX12Lx9VMkxvtT81nCHy3Nv";
30
28
  export declare const PTYH_LAZER_PROGRAM_ID = "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt";
31
29
  export declare const PYTH_LAZER_STORAGE_ACCOUNT_KEY: PublicKey;
32
30
  export declare const DEFAULT_CONFIRMATION_OPTS: ConfirmOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DEFAULT_CONFIRMATION_OPTS = exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = exports.PTYH_LAZER_PROGRAM_ID = exports.ANCHOR_TEST_SWIFT_ID = exports.SWIFT_ID = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
3
+ exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DEFAULT_CONFIRMATION_OPTS = exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = exports.PTYH_LAZER_PROGRAM_ID = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
4
4
  const _1 = require(".");
5
5
  const perpMarkets_1 = require("./constants/perpMarkets");
6
6
  const spotMarkets_1 = require("./constants/spotMarkets");
@@ -8,8 +8,6 @@ const on_demand_1 = require("@switchboard-xyz/on-demand");
8
8
  const oracleId_1 = require("./oracles/oracleId");
9
9
  exports.DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
10
10
  exports.DRIFT_ORACLE_RECEIVER_ID = 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha';
11
- exports.SWIFT_ID = 'SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS';
12
- exports.ANCHOR_TEST_SWIFT_ID = 'DpaEdAPW3ZX67fnczT14AoX12Lx9VMkxvtT81nCHy3Nv';
13
11
  exports.PTYH_LAZER_PROGRAM_ID = 'pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt';
14
12
  exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = new _1.PublicKey('3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL');
15
13
  exports.DEFAULT_CONFIRMATION_OPTS = {
@@ -5,7 +5,7 @@
5
5
  import * as anchor from '@coral-xyz/anchor';
6
6
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
7
7
  import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
8
- import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, RFQMakerOrderParams, RFQMatch, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, SwiftServerMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
8
+ import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, RFQMakerOrderParams, RFQMatch, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
9
9
  import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
10
10
  import { TokenFaucet } from './tokenFaucet';
11
11
  import { EventEmitter } from 'events';
@@ -40,7 +40,6 @@ export declare class DriftClient {
40
40
  connection: Connection;
41
41
  wallet: IWallet;
42
42
  program: Program;
43
- swiftID: PublicKey;
44
43
  provider: AnchorProvider;
45
44
  opts?: ConfirmOptions;
46
45
  users: Map<string, User>;
@@ -531,29 +530,26 @@ export declare class DriftClient {
531
530
  getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number): Promise<TransactionInstruction>;
532
531
  placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
533
532
  getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
534
- encodeSwiftServerMessage(message: SwiftServerMessage): Buffer;
535
- decodeSwiftServerMessage(encodedMessage: Buffer): SwiftServerMessage;
536
- signSwiftServerMessage(message: SwiftServerMessage): Buffer;
537
533
  signSwiftOrderParamsMessage(orderParamsMessage: SwiftOrderParamsMessage): Buffer;
538
534
  encodeSwiftOrderParamsMessage(orderParamsMessage: SwiftOrderParamsMessage): Buffer;
539
535
  decodeSwiftOrderParamsMessage(encodedMessage: Buffer): SwiftOrderParamsMessage;
540
536
  signMessage(message: Uint8Array, keypair?: Keypair): Buffer;
541
- placeSwiftTakerOrder(swiftServerMessage: Buffer, swiftSignature: Buffer, swiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
537
+ placeSwiftTakerOrder(swiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
542
538
  taker: PublicKey;
543
539
  takerStats: PublicKey;
544
540
  takerUserAccount: UserAccount;
545
541
  }, txParams?: TxParams): Promise<TransactionSignature>;
546
- getPlaceSwiftTakerPerpOrderIxs(encodedSwiftServerMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
542
+ getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
547
543
  taker: PublicKey;
548
544
  takerStats: PublicKey;
549
545
  takerUserAccount: UserAccount;
550
546
  }, authority?: PublicKey): Promise<TransactionInstruction[]>;
551
- placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
547
+ placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
552
548
  taker: PublicKey;
553
549
  takerStats: PublicKey;
554
550
  takerUserAccount: UserAccount;
555
551
  }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
556
- getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
552
+ getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
557
553
  taker: PublicKey;
558
554
  takerStats: PublicKey;
559
555
  takerUserAccount: UserAccount;
@@ -83,7 +83,7 @@ class DriftClient {
83
83
  this._isSubscribed = val;
84
84
  }
85
85
  constructor(config) {
86
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20;
86
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
87
87
  this.users = new Map();
88
88
  this._isSubscribed = false;
89
89
  this.perpMarketLastSlotCache = new Map();
@@ -104,17 +104,16 @@ class DriftClient {
104
104
  // @ts-ignore
105
105
  config.wallet, this.opts);
106
106
  this.program = new anchor_1.Program(drift_json_1.default, (_b = config.programID) !== null && _b !== void 0 ? _b : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
107
- this.swiftID = (_c = config.swiftID) !== null && _c !== void 0 ? _c : new web3_js_1.PublicKey(config_1.SWIFT_ID);
108
- this.authority = (_d = config.authority) !== null && _d !== void 0 ? _d : this.wallet.publicKey;
109
- this.activeSubAccountId = (_e = config.activeSubAccountId) !== null && _e !== void 0 ? _e : 0;
110
- this.skipLoadUsers = (_f = config.skipLoadUsers) !== null && _f !== void 0 ? _f : false;
111
- this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 'legacy';
107
+ this.authority = (_c = config.authority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
108
+ this.activeSubAccountId = (_d = config.activeSubAccountId) !== null && _d !== void 0 ? _d : 0;
109
+ this.skipLoadUsers = (_e = config.skipLoadUsers) !== null && _e !== void 0 ? _e : false;
110
+ this.txVersion = (_f = config.txVersion) !== null && _f !== void 0 ? _f : 'legacy';
112
111
  this.txParams = {
113
- computeUnits: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnits) !== null && _j !== void 0 ? _j : 600000,
114
- computeUnitsPrice: (_l = (_k = config.txParams) === null || _k === void 0 ? void 0 : _k.computeUnitsPrice) !== null && _l !== void 0 ? _l : 0,
112
+ computeUnits: (_h = (_g = config.txParams) === null || _g === void 0 ? void 0 : _g.computeUnits) !== null && _h !== void 0 ? _h : 600000,
113
+ computeUnitsPrice: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnitsPrice) !== null && _k !== void 0 ? _k : 0,
115
114
  };
116
115
  this.txHandler =
117
- (_m = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _m !== void 0 ? _m : new txHandler_1.TxHandler({
116
+ (_l = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _l !== void 0 ? _l : new txHandler_1.TxHandler({
118
117
  connection: this.connection,
119
118
  // @ts-ignore
120
119
  wallet: this.provider.wallet,
@@ -140,8 +139,8 @@ class DriftClient {
140
139
  : config.subAccountIds
141
140
  ? new Map([[this.authority.toString(), config.subAccountIds]])
142
141
  : new Map();
143
- this.includeDelegates = (_o = config.includeDelegates) !== null && _o !== void 0 ? _o : false;
144
- if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'polling') {
142
+ this.includeDelegates = (_m = config.includeDelegates) !== null && _m !== void 0 ? _m : false;
143
+ if (((_o = config.accountSubscription) === null || _o === void 0 ? void 0 : _o.type) === 'polling') {
145
144
  this.userAccountSubscriptionConfig = {
146
145
  type: 'polling',
147
146
  accountLoader: config.accountSubscription.accountLoader,
@@ -151,32 +150,32 @@ class DriftClient {
151
150
  accountLoader: config.accountSubscription.accountLoader,
152
151
  };
153
152
  }
154
- else if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'grpc') {
153
+ else if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'grpc') {
155
154
  this.userAccountSubscriptionConfig = {
156
155
  type: 'grpc',
157
- resubTimeoutMs: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.resubTimeoutMs,
158
- logResubMessages: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.logResubMessages,
159
- grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
156
+ resubTimeoutMs: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.resubTimeoutMs,
157
+ logResubMessages: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.logResubMessages,
158
+ grpcConfigs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.grpcConfigs,
160
159
  };
161
160
  this.userStatsAccountSubscriptionConfig = {
162
161
  type: 'grpc',
163
- grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
164
- resubTimeoutMs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.resubTimeoutMs,
165
- logResubMessages: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.logResubMessages,
162
+ grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
163
+ resubTimeoutMs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.resubTimeoutMs,
164
+ logResubMessages: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.logResubMessages,
166
165
  };
167
166
  }
168
167
  else {
169
168
  this.userAccountSubscriptionConfig = {
170
169
  type: 'websocket',
171
- resubTimeoutMs: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.resubTimeoutMs,
172
- logResubMessages: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.logResubMessages,
173
- commitment: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.commitment,
170
+ resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
171
+ logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
172
+ commitment: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.commitment,
174
173
  };
175
174
  this.userStatsAccountSubscriptionConfig = {
176
175
  type: 'websocket',
177
- resubTimeoutMs: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.resubTimeoutMs,
178
- logResubMessages: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.logResubMessages,
179
- commitment: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.commitment,
176
+ resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
177
+ logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
178
+ commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
180
179
  };
181
180
  }
182
181
  if (config.userStats) {
@@ -194,20 +193,20 @@ class DriftClient {
194
193
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
195
194
  config.spotMarketIndexes === undefined &&
196
195
  config.oracleInfos === undefined;
197
- if (((_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.type) === 'polling') {
198
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_4 = config.perpMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.spotMarketIndexes) !== null && _5 !== void 0 ? _5 : [], (_6 = config.oracleInfos) !== null && _6 !== void 0 ? _6 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
196
+ if (((_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.type) === 'polling') {
197
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_3 = config.perpMarketIndexes) !== null && _3 !== void 0 ? _3 : [], (_4 = config.spotMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.oracleInfos) !== null && _5 !== void 0 ? _5 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
199
198
  }
200
- else if (((_7 = config.accountSubscription) === null || _7 === void 0 ? void 0 : _7.type) === 'grpc') {
201
- this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_8 = config.perpMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.spotMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.oracleInfos) !== null && _10 !== void 0 ? _10 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
202
- resubTimeoutMs: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.resubTimeoutMs,
203
- logResubMessages: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.logResubMessages,
199
+ else if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'grpc') {
200
+ this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_7 = config.perpMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.spotMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.oracleInfos) !== null && _9 !== void 0 ? _9 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
201
+ resubTimeoutMs: (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.resubTimeoutMs,
202
+ logResubMessages: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.logResubMessages,
204
203
  });
205
204
  }
206
205
  else {
207
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_13 = config.perpMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.spotMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.oracleInfos) !== null && _15 !== void 0 ? _15 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
208
- resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
209
- logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
210
- }, (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.commitment);
206
+ this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
207
+ resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
208
+ logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
209
+ }, (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.commitment);
211
210
  }
212
211
  this.eventEmitter = this.accountSubscriber.eventEmitter;
213
212
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -215,14 +214,14 @@ class DriftClient {
215
214
  this.enableMetricsEvents = true;
216
215
  }
217
216
  this.txSender =
218
- (_19 = config.txSender) !== null && _19 !== void 0 ? _19 : new retryTxSender_1.RetryTxSender({
217
+ (_18 = config.txSender) !== null && _18 !== void 0 ? _18 : new retryTxSender_1.RetryTxSender({
219
218
  connection: this.connection,
220
219
  wallet: this.wallet,
221
220
  opts: this.opts,
222
221
  txHandler: this.txHandler,
223
222
  });
224
223
  this.sbOnDemandProgramdId =
225
- config_1.configs[(_20 = config.env) !== null && _20 !== void 0 ? _20 : 'mainnet-beta'].SB_ON_DEMAND_PID;
224
+ config_1.configs[(_19 = config.env) !== null && _19 !== void 0 ? _19 : 'mainnet-beta'].SB_ON_DEMAND_PID;
226
225
  }
227
226
  getUserMapKey(subAccountId, authority) {
228
227
  return `${subAccountId}_${authority.toString()}`;
@@ -3165,21 +3164,6 @@ class DriftClient {
3165
3164
  remainingAccounts,
3166
3165
  });
3167
3166
  }
3168
- encodeSwiftServerMessage(message) {
3169
- return this.program.coder.types.encode('SwiftServerMessage', message);
3170
- }
3171
- decodeSwiftServerMessage(encodedMessage) {
3172
- const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3173
- return {
3174
- uuid: decodedSwiftMessage.uuid,
3175
- slot: decodedSwiftMessage.slot,
3176
- swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3177
- };
3178
- }
3179
- signSwiftServerMessage(message) {
3180
- const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
3181
- return this.signMessage(swiftServerMessage);
3182
- }
3183
3167
  signSwiftOrderParamsMessage(orderParamsMessage) {
3184
3168
  const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage);
3185
3169
  return this.signMessage(new TextEncoder().encode((0, digest_1.digest)(takerOrderParamsMessage).toString('hex')));
@@ -3193,12 +3177,12 @@ class DriftClient {
3193
3177
  signMessage(message, keypair = this.wallet.payer) {
3194
3178
  return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
3195
3179
  }
3196
- async placeSwiftTakerOrder(swiftServerMessage, swiftSignature, swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
3197
- const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftServerMessage, swiftSignature, swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
3180
+ async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
3181
+ const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
3198
3182
  const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3199
3183
  return txSig;
3200
3184
  }
3201
- async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftServerMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
3185
+ async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
3202
3186
  if (!authority && !takerInfo.takerUserAccount) {
3203
3187
  throw new Error('authority or takerUserAccount must be provided');
3204
3188
  }
@@ -3207,18 +3191,13 @@ class DriftClient {
3207
3191
  useMarketLastSlotCache: true,
3208
3192
  readablePerpMarketIndex: marketIndex,
3209
3193
  });
3210
- const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3211
- publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
3212
- signature: Uint8Array.from(swiftSignature),
3213
- message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
3214
- });
3215
3194
  const authorityToUse = authority || takerInfo.takerUserAccount.authority;
3216
3195
  const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3217
3196
  publicKey: authorityToUse.toBytes(),
3218
3197
  signature: Uint8Array.from(swiftOrderParamsSignature),
3219
3198
  message: new TextEncoder().encode((0, digest_1.digest)(encodedSwiftOrderParamsMessage).toString('hex')),
3220
3199
  });
3221
- const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
3200
+ const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftOrderParamsMessage, {
3222
3201
  accounts: {
3223
3202
  state: await this.getStatePublicKey(),
3224
3203
  user: takerInfo.taker,
@@ -3229,20 +3208,16 @@ class DriftClient {
3229
3208
  },
3230
3209
  remainingAccounts,
3231
3210
  });
3232
- return [
3233
- swiftServerSignatureIx,
3234
- swiftOrderParamsSignatureIx,
3235
- placeTakerSwiftPerpOrderIx,
3236
- ];
3211
+ return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
3237
3212
  }
3238
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3239
- const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3213
+ async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3214
+ const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3240
3215
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3241
3216
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3242
3217
  return txSig;
3243
3218
  }
3244
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3245
- const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3219
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3220
+ const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3246
3221
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3247
3222
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
3248
3223
  const user = await this.getUserAccountPublicKey(subAccountId);
@@ -3278,12 +3253,7 @@ class DriftClient {
3278
3253
  },
3279
3254
  remainingAccounts,
3280
3255
  });
3281
- return [
3282
- swiftServerSignatureIx,
3283
- swiftOrderSignatureIx,
3284
- placeTakerSwiftPerpOrderIx,
3285
- placeAndMakeIx,
3286
- ];
3256
+ return [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx, placeAndMakeIx];
3287
3257
  }
3288
3258
  encodeRFQMakerOrderParams(message) {
3289
3259
  return this.program.coder.types.encode('RFQMakerOrderParams', message);
@@ -11,7 +11,6 @@ export type DriftClientConfig = {
11
11
  wallet: IWallet;
12
12
  env?: DriftEnv;
13
13
  programID?: PublicKey;
14
- swiftID?: PublicKey;
15
14
  accountSubscription?: DriftClientSubscriptionConfig;
16
15
  opts?: ConfirmOptions;
17
16
  txSender?: TxSender;
@@ -813,10 +813,6 @@
813
813
  }
814
814
  ],
815
815
  "args": [
816
- {
817
- "name": "swiftMessageBytes",
818
- "type": "bytes"
819
- },
820
816
  {
821
817
  "name": "swiftOrderParamsMessageBytes",
822
818
  "type": "bytes"
@@ -9002,50 +8998,33 @@
9002
8998
  }
9003
8999
  },
9004
9000
  {
9005
- "name": "SwiftServerMessage",
9001
+ "name": "SwiftOrderParamsMessage",
9006
9002
  "type": {
9007
9003
  "kind": "struct",
9008
9004
  "fields": [
9009
9005
  {
9010
- "name": "uuid",
9006
+ "name": "swiftOrderParams",
9011
9007
  "type": {
9012
- "array": [
9013
- "u8",
9014
- 8
9015
- ]
9008
+ "defined": "OrderParams"
9016
9009
  }
9017
9010
  },
9018
9011
  {
9019
- "name": "swiftOrderSignature",
9020
- "type": {
9021
- "array": [
9022
- "u8",
9023
- 64
9024
- ]
9025
- }
9012
+ "name": "subAccountId",
9013
+ "type": "u16"
9026
9014
  },
9027
9015
  {
9028
9016
  "name": "slot",
9029
9017
  "type": "u64"
9030
- }
9031
- ]
9032
- }
9033
- },
9034
- {
9035
- "name": "SwiftOrderParamsMessage",
9036
- "type": {
9037
- "kind": "struct",
9038
- "fields": [
9018
+ },
9039
9019
  {
9040
- "name": "swiftOrderParams",
9020
+ "name": "uuid",
9041
9021
  "type": {
9042
- "defined": "OrderParams"
9022
+ "array": [
9023
+ "u8",
9024
+ 8
9025
+ ]
9043
9026
  }
9044
9027
  },
9045
- {
9046
- "name": "subAccountId",
9047
- "type": "u16"
9048
- },
9049
9028
  {
9050
9029
  "name": "takeProfitOrderParams",
9051
9030
  "type": {
@@ -1141,14 +1141,11 @@ export declare enum ModifyOrderPolicy {
1141
1141
  ExcludePreviousFill = 2
1142
1142
  }
1143
1143
  export declare const DefaultOrderParams: OrderParams;
1144
- export type SwiftServerMessage = {
1145
- slot: BN;
1146
- swiftOrderSignature: Uint8Array;
1147
- uuid: Uint8Array;
1148
- };
1149
1144
  export type SwiftOrderParamsMessage = {
1150
1145
  swiftOrderParams: OptionalOrderParams;
1151
1146
  subAccountId: number;
1147
+ uuid: Uint8Array;
1148
+ slot: BN;
1152
1149
  takeProfitOrderParams: SwiftTriggerOrderParams | null;
1153
1150
  stopLossOrderParams: SwiftTriggerOrderParams | null;
1154
1151
  };
@@ -2,3 +2,4 @@
2
2
  /// <reference types="node" />
3
3
  export declare function digest(data: Buffer): Buffer;
4
4
  export declare function digestSignature(signature: Uint8Array): string;
5
+ export declare function generateSwiftUuid(): Uint8Array;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.digestSignature = exports.digest = void 0;
3
+ exports.generateSwiftUuid = exports.digestSignature = exports.digest = void 0;
4
4
  const crypto_1 = require("crypto");
5
+ const nanoid_1 = require("nanoid");
5
6
  function digest(data) {
6
7
  const hash = (0, crypto_1.createHash)('sha256');
7
8
  hash.update(data);
@@ -12,3 +13,7 @@ function digestSignature(signature) {
12
13
  return (0, crypto_1.createHash)('sha256').update(signature).digest('base64');
13
14
  }
14
15
  exports.digestSignature = digestSignature;
16
+ function generateSwiftUuid() {
17
+ return Uint8Array.from(Buffer.from((0, nanoid_1.nanoid)(8)));
18
+ }
19
+ exports.generateSwiftUuid = generateSwiftUuid;
@@ -25,8 +25,6 @@ type DriftConfig = {
25
25
  export type DriftEnv = 'devnet' | 'mainnet-beta';
26
26
  export declare const DRIFT_PROGRAM_ID = "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH";
27
27
  export declare const DRIFT_ORACLE_RECEIVER_ID = "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha";
28
- export declare const SWIFT_ID = "SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS";
29
- export declare const ANCHOR_TEST_SWIFT_ID = "DpaEdAPW3ZX67fnczT14AoX12Lx9VMkxvtT81nCHy3Nv";
30
28
  export declare const PTYH_LAZER_PROGRAM_ID = "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt";
31
29
  export declare const PYTH_LAZER_STORAGE_ACCOUNT_KEY: PublicKey;
32
30
  export declare const DEFAULT_CONFIRMATION_OPTS: ConfirmOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DEFAULT_CONFIRMATION_OPTS = exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = exports.PTYH_LAZER_PROGRAM_ID = exports.ANCHOR_TEST_SWIFT_ID = exports.SWIFT_ID = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
3
+ exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DEFAULT_CONFIRMATION_OPTS = exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = exports.PTYH_LAZER_PROGRAM_ID = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
4
4
  const _1 = require(".");
5
5
  const perpMarkets_1 = require("./constants/perpMarkets");
6
6
  const spotMarkets_1 = require("./constants/spotMarkets");
@@ -8,8 +8,6 @@ const on_demand_1 = require("@switchboard-xyz/on-demand");
8
8
  const oracleId_1 = require("./oracles/oracleId");
9
9
  exports.DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
10
10
  exports.DRIFT_ORACLE_RECEIVER_ID = 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha';
11
- exports.SWIFT_ID = 'SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS';
12
- exports.ANCHOR_TEST_SWIFT_ID = 'DpaEdAPW3ZX67fnczT14AoX12Lx9VMkxvtT81nCHy3Nv';
13
11
  exports.PTYH_LAZER_PROGRAM_ID = 'pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt';
14
12
  exports.PYTH_LAZER_STORAGE_ACCOUNT_KEY = new _1.PublicKey('3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL');
15
13
  exports.DEFAULT_CONFIRMATION_OPTS = {
@@ -5,7 +5,7 @@
5
5
  import * as anchor from '@coral-xyz/anchor';
6
6
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
7
7
  import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
8
- import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, RFQMakerOrderParams, RFQMatch, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, SwiftServerMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
8
+ import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, RFQMakerOrderParams, RFQMatch, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
9
9
  import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
10
10
  import { TokenFaucet } from './tokenFaucet';
11
11
  import { EventEmitter } from 'events';
@@ -40,7 +40,6 @@ export declare class DriftClient {
40
40
  connection: Connection;
41
41
  wallet: IWallet;
42
42
  program: Program;
43
- swiftID: PublicKey;
44
43
  provider: AnchorProvider;
45
44
  opts?: ConfirmOptions;
46
45
  users: Map<string, User>;
@@ -531,29 +530,26 @@ export declare class DriftClient {
531
530
  getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number): Promise<TransactionInstruction>;
532
531
  placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
533
532
  getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
534
- encodeSwiftServerMessage(message: SwiftServerMessage): Buffer;
535
- decodeSwiftServerMessage(encodedMessage: Buffer): SwiftServerMessage;
536
- signSwiftServerMessage(message: SwiftServerMessage): Buffer;
537
533
  signSwiftOrderParamsMessage(orderParamsMessage: SwiftOrderParamsMessage): Buffer;
538
534
  encodeSwiftOrderParamsMessage(orderParamsMessage: SwiftOrderParamsMessage): Buffer;
539
535
  decodeSwiftOrderParamsMessage(encodedMessage: Buffer): SwiftOrderParamsMessage;
540
536
  signMessage(message: Uint8Array, keypair?: Keypair): Buffer;
541
- placeSwiftTakerOrder(swiftServerMessage: Buffer, swiftSignature: Buffer, swiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
537
+ placeSwiftTakerOrder(swiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
542
538
  taker: PublicKey;
543
539
  takerStats: PublicKey;
544
540
  takerUserAccount: UserAccount;
545
541
  }, txParams?: TxParams): Promise<TransactionSignature>;
546
- getPlaceSwiftTakerPerpOrderIxs(encodedSwiftServerMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
542
+ getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, marketIndex: number, takerInfo: {
547
543
  taker: PublicKey;
548
544
  takerStats: PublicKey;
549
545
  takerUserAccount: UserAccount;
550
546
  }, authority?: PublicKey): Promise<TransactionInstruction[]>;
551
- placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
547
+ placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
552
548
  taker: PublicKey;
553
549
  takerStats: PublicKey;
554
550
  takerUserAccount: UserAccount;
555
551
  }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
556
- getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
552
+ getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
557
553
  taker: PublicKey;
558
554
  takerStats: PublicKey;
559
555
  takerUserAccount: UserAccount;
@@ -83,7 +83,7 @@ class DriftClient {
83
83
  this._isSubscribed = val;
84
84
  }
85
85
  constructor(config) {
86
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20;
86
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
87
87
  this.users = new Map();
88
88
  this._isSubscribed = false;
89
89
  this.perpMarketLastSlotCache = new Map();
@@ -104,17 +104,16 @@ class DriftClient {
104
104
  // @ts-ignore
105
105
  config.wallet, this.opts);
106
106
  this.program = new anchor_1.Program(drift_json_1.default, (_b = config.programID) !== null && _b !== void 0 ? _b : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
107
- this.swiftID = (_c = config.swiftID) !== null && _c !== void 0 ? _c : new web3_js_1.PublicKey(config_1.SWIFT_ID);
108
- this.authority = (_d = config.authority) !== null && _d !== void 0 ? _d : this.wallet.publicKey;
109
- this.activeSubAccountId = (_e = config.activeSubAccountId) !== null && _e !== void 0 ? _e : 0;
110
- this.skipLoadUsers = (_f = config.skipLoadUsers) !== null && _f !== void 0 ? _f : false;
111
- this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 'legacy';
107
+ this.authority = (_c = config.authority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
108
+ this.activeSubAccountId = (_d = config.activeSubAccountId) !== null && _d !== void 0 ? _d : 0;
109
+ this.skipLoadUsers = (_e = config.skipLoadUsers) !== null && _e !== void 0 ? _e : false;
110
+ this.txVersion = (_f = config.txVersion) !== null && _f !== void 0 ? _f : 'legacy';
112
111
  this.txParams = {
113
- computeUnits: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnits) !== null && _j !== void 0 ? _j : 600000,
114
- computeUnitsPrice: (_l = (_k = config.txParams) === null || _k === void 0 ? void 0 : _k.computeUnitsPrice) !== null && _l !== void 0 ? _l : 0,
112
+ computeUnits: (_h = (_g = config.txParams) === null || _g === void 0 ? void 0 : _g.computeUnits) !== null && _h !== void 0 ? _h : 600000,
113
+ computeUnitsPrice: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnitsPrice) !== null && _k !== void 0 ? _k : 0,
115
114
  };
116
115
  this.txHandler =
117
- (_m = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _m !== void 0 ? _m : new txHandler_1.TxHandler({
116
+ (_l = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _l !== void 0 ? _l : new txHandler_1.TxHandler({
118
117
  connection: this.connection,
119
118
  // @ts-ignore
120
119
  wallet: this.provider.wallet,
@@ -140,8 +139,8 @@ class DriftClient {
140
139
  : config.subAccountIds
141
140
  ? new Map([[this.authority.toString(), config.subAccountIds]])
142
141
  : new Map();
143
- this.includeDelegates = (_o = config.includeDelegates) !== null && _o !== void 0 ? _o : false;
144
- if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'polling') {
142
+ this.includeDelegates = (_m = config.includeDelegates) !== null && _m !== void 0 ? _m : false;
143
+ if (((_o = config.accountSubscription) === null || _o === void 0 ? void 0 : _o.type) === 'polling') {
145
144
  this.userAccountSubscriptionConfig = {
146
145
  type: 'polling',
147
146
  accountLoader: config.accountSubscription.accountLoader,
@@ -151,32 +150,32 @@ class DriftClient {
151
150
  accountLoader: config.accountSubscription.accountLoader,
152
151
  };
153
152
  }
154
- else if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'grpc') {
153
+ else if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'grpc') {
155
154
  this.userAccountSubscriptionConfig = {
156
155
  type: 'grpc',
157
- resubTimeoutMs: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.resubTimeoutMs,
158
- logResubMessages: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.logResubMessages,
159
- grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
156
+ resubTimeoutMs: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.resubTimeoutMs,
157
+ logResubMessages: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.logResubMessages,
158
+ grpcConfigs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.grpcConfigs,
160
159
  };
161
160
  this.userStatsAccountSubscriptionConfig = {
162
161
  type: 'grpc',
163
- grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
164
- resubTimeoutMs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.resubTimeoutMs,
165
- logResubMessages: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.logResubMessages,
162
+ grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
163
+ resubTimeoutMs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.resubTimeoutMs,
164
+ logResubMessages: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.logResubMessages,
166
165
  };
167
166
  }
168
167
  else {
169
168
  this.userAccountSubscriptionConfig = {
170
169
  type: 'websocket',
171
- resubTimeoutMs: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.resubTimeoutMs,
172
- logResubMessages: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.logResubMessages,
173
- commitment: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.commitment,
170
+ resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
171
+ logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
172
+ commitment: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.commitment,
174
173
  };
175
174
  this.userStatsAccountSubscriptionConfig = {
176
175
  type: 'websocket',
177
- resubTimeoutMs: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.resubTimeoutMs,
178
- logResubMessages: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.logResubMessages,
179
- commitment: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.commitment,
176
+ resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
177
+ logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
178
+ commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
180
179
  };
181
180
  }
182
181
  if (config.userStats) {
@@ -194,20 +193,20 @@ class DriftClient {
194
193
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
195
194
  config.spotMarketIndexes === undefined &&
196
195
  config.oracleInfos === undefined;
197
- if (((_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.type) === 'polling') {
198
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_4 = config.perpMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.spotMarketIndexes) !== null && _5 !== void 0 ? _5 : [], (_6 = config.oracleInfos) !== null && _6 !== void 0 ? _6 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
196
+ if (((_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.type) === 'polling') {
197
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_3 = config.perpMarketIndexes) !== null && _3 !== void 0 ? _3 : [], (_4 = config.spotMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.oracleInfos) !== null && _5 !== void 0 ? _5 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
199
198
  }
200
- else if (((_7 = config.accountSubscription) === null || _7 === void 0 ? void 0 : _7.type) === 'grpc') {
201
- this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_8 = config.perpMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.spotMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.oracleInfos) !== null && _10 !== void 0 ? _10 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
202
- resubTimeoutMs: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.resubTimeoutMs,
203
- logResubMessages: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.logResubMessages,
199
+ else if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'grpc') {
200
+ this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_7 = config.perpMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.spotMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.oracleInfos) !== null && _9 !== void 0 ? _9 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
201
+ resubTimeoutMs: (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.resubTimeoutMs,
202
+ logResubMessages: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.logResubMessages,
204
203
  });
205
204
  }
206
205
  else {
207
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_13 = config.perpMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.spotMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.oracleInfos) !== null && _15 !== void 0 ? _15 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
208
- resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
209
- logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
210
- }, (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.commitment);
206
+ this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
207
+ resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
208
+ logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
209
+ }, (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.commitment);
211
210
  }
212
211
  this.eventEmitter = this.accountSubscriber.eventEmitter;
213
212
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -215,14 +214,14 @@ class DriftClient {
215
214
  this.enableMetricsEvents = true;
216
215
  }
217
216
  this.txSender =
218
- (_19 = config.txSender) !== null && _19 !== void 0 ? _19 : new retryTxSender_1.RetryTxSender({
217
+ (_18 = config.txSender) !== null && _18 !== void 0 ? _18 : new retryTxSender_1.RetryTxSender({
219
218
  connection: this.connection,
220
219
  wallet: this.wallet,
221
220
  opts: this.opts,
222
221
  txHandler: this.txHandler,
223
222
  });
224
223
  this.sbOnDemandProgramdId =
225
- config_1.configs[(_20 = config.env) !== null && _20 !== void 0 ? _20 : 'mainnet-beta'].SB_ON_DEMAND_PID;
224
+ config_1.configs[(_19 = config.env) !== null && _19 !== void 0 ? _19 : 'mainnet-beta'].SB_ON_DEMAND_PID;
226
225
  }
227
226
  getUserMapKey(subAccountId, authority) {
228
227
  return `${subAccountId}_${authority.toString()}`;
@@ -3165,21 +3164,6 @@ class DriftClient {
3165
3164
  remainingAccounts,
3166
3165
  });
3167
3166
  }
3168
- encodeSwiftServerMessage(message) {
3169
- return this.program.coder.types.encode('SwiftServerMessage', message);
3170
- }
3171
- decodeSwiftServerMessage(encodedMessage) {
3172
- const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3173
- return {
3174
- uuid: decodedSwiftMessage.uuid,
3175
- slot: decodedSwiftMessage.slot,
3176
- swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3177
- };
3178
- }
3179
- signSwiftServerMessage(message) {
3180
- const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
3181
- return this.signMessage(swiftServerMessage);
3182
- }
3183
3167
  signSwiftOrderParamsMessage(orderParamsMessage) {
3184
3168
  const takerOrderParamsMessage = this.encodeSwiftOrderParamsMessage(orderParamsMessage);
3185
3169
  return this.signMessage(new TextEncoder().encode((0, digest_1.digest)(takerOrderParamsMessage).toString('hex')));
@@ -3193,12 +3177,12 @@ class DriftClient {
3193
3177
  signMessage(message, keypair = this.wallet.payer) {
3194
3178
  return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
3195
3179
  }
3196
- async placeSwiftTakerOrder(swiftServerMessage, swiftSignature, swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
3197
- const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftServerMessage, swiftSignature, swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
3180
+ async placeSwiftTakerOrder(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, txParams) {
3181
+ const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(swiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo);
3198
3182
  const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3199
3183
  return txSig;
3200
3184
  }
3201
- async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftServerMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
3185
+ async getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, marketIndex, takerInfo, authority) {
3202
3186
  if (!authority && !takerInfo.takerUserAccount) {
3203
3187
  throw new Error('authority or takerUserAccount must be provided');
3204
3188
  }
@@ -3207,18 +3191,13 @@ class DriftClient {
3207
3191
  useMarketLastSlotCache: true,
3208
3192
  readablePerpMarketIndex: marketIndex,
3209
3193
  });
3210
- const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3211
- publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
3212
- signature: Uint8Array.from(swiftSignature),
3213
- message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
3214
- });
3215
3194
  const authorityToUse = authority || takerInfo.takerUserAccount.authority;
3216
3195
  const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3217
3196
  publicKey: authorityToUse.toBytes(),
3218
3197
  signature: Uint8Array.from(swiftOrderParamsSignature),
3219
3198
  message: new TextEncoder().encode((0, digest_1.digest)(encodedSwiftOrderParamsMessage).toString('hex')),
3220
3199
  });
3221
- const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
3200
+ const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftOrderParamsMessage, {
3222
3201
  accounts: {
3223
3202
  state: await this.getStatePublicKey(),
3224
3203
  user: takerInfo.taker,
@@ -3229,20 +3208,16 @@ class DriftClient {
3229
3208
  },
3230
3209
  remainingAccounts,
3231
3210
  });
3232
- return [
3233
- swiftServerSignatureIx,
3234
- swiftOrderParamsSignatureIx,
3235
- placeTakerSwiftPerpOrderIx,
3236
- ];
3211
+ return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
3237
3212
  }
3238
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3239
- const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3213
+ async placeAndMakeSwiftPerpOrder(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3214
+ const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3240
3215
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3241
3216
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3242
3217
  return txSig;
3243
3218
  }
3244
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3245
- const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3219
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3220
+ const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3246
3221
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3247
3222
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
3248
3223
  const user = await this.getUserAccountPublicKey(subAccountId);
@@ -3278,12 +3253,7 @@ class DriftClient {
3278
3253
  },
3279
3254
  remainingAccounts,
3280
3255
  });
3281
- return [
3282
- swiftServerSignatureIx,
3283
- swiftOrderSignatureIx,
3284
- placeTakerSwiftPerpOrderIx,
3285
- placeAndMakeIx,
3286
- ];
3256
+ return [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx, placeAndMakeIx];
3287
3257
  }
3288
3258
  encodeRFQMakerOrderParams(message) {
3289
3259
  return this.program.coder.types.encode('RFQMakerOrderParams', message);
@@ -11,7 +11,6 @@ export type DriftClientConfig = {
11
11
  wallet: IWallet;
12
12
  env?: DriftEnv;
13
13
  programID?: PublicKey;
14
- swiftID?: PublicKey;
15
14
  accountSubscription?: DriftClientSubscriptionConfig;
16
15
  opts?: ConfirmOptions;
17
16
  txSender?: TxSender;
@@ -813,10 +813,6 @@
813
813
  }
814
814
  ],
815
815
  "args": [
816
- {
817
- "name": "swiftMessageBytes",
818
- "type": "bytes"
819
- },
820
816
  {
821
817
  "name": "swiftOrderParamsMessageBytes",
822
818
  "type": "bytes"
@@ -9002,50 +8998,33 @@
9002
8998
  }
9003
8999
  },
9004
9000
  {
9005
- "name": "SwiftServerMessage",
9001
+ "name": "SwiftOrderParamsMessage",
9006
9002
  "type": {
9007
9003
  "kind": "struct",
9008
9004
  "fields": [
9009
9005
  {
9010
- "name": "uuid",
9006
+ "name": "swiftOrderParams",
9011
9007
  "type": {
9012
- "array": [
9013
- "u8",
9014
- 8
9015
- ]
9008
+ "defined": "OrderParams"
9016
9009
  }
9017
9010
  },
9018
9011
  {
9019
- "name": "swiftOrderSignature",
9020
- "type": {
9021
- "array": [
9022
- "u8",
9023
- 64
9024
- ]
9025
- }
9012
+ "name": "subAccountId",
9013
+ "type": "u16"
9026
9014
  },
9027
9015
  {
9028
9016
  "name": "slot",
9029
9017
  "type": "u64"
9030
- }
9031
- ]
9032
- }
9033
- },
9034
- {
9035
- "name": "SwiftOrderParamsMessage",
9036
- "type": {
9037
- "kind": "struct",
9038
- "fields": [
9018
+ },
9039
9019
  {
9040
- "name": "swiftOrderParams",
9020
+ "name": "uuid",
9041
9021
  "type": {
9042
- "defined": "OrderParams"
9022
+ "array": [
9023
+ "u8",
9024
+ 8
9025
+ ]
9043
9026
  }
9044
9027
  },
9045
- {
9046
- "name": "subAccountId",
9047
- "type": "u16"
9048
- },
9049
9028
  {
9050
9029
  "name": "takeProfitOrderParams",
9051
9030
  "type": {
@@ -1141,14 +1141,11 @@ export declare enum ModifyOrderPolicy {
1141
1141
  ExcludePreviousFill = 2
1142
1142
  }
1143
1143
  export declare const DefaultOrderParams: OrderParams;
1144
- export type SwiftServerMessage = {
1145
- slot: BN;
1146
- swiftOrderSignature: Uint8Array;
1147
- uuid: Uint8Array;
1148
- };
1149
1144
  export type SwiftOrderParamsMessage = {
1150
1145
  swiftOrderParams: OptionalOrderParams;
1151
1146
  subAccountId: number;
1147
+ uuid: Uint8Array;
1148
+ slot: BN;
1152
1149
  takeProfitOrderParams: SwiftTriggerOrderParams | null;
1153
1150
  stopLossOrderParams: SwiftTriggerOrderParams | null;
1154
1151
  };
@@ -2,3 +2,4 @@
2
2
  /// <reference types="node" />
3
3
  export declare function digest(data: Buffer): Buffer;
4
4
  export declare function digestSignature(signature: Uint8Array): string;
5
+ export declare function generateSwiftUuid(): Uint8Array;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.digestSignature = exports.digest = void 0;
3
+ exports.generateSwiftUuid = exports.digestSignature = exports.digest = void 0;
4
4
  const crypto_1 = require("crypto");
5
+ const nanoid_1 = require("nanoid");
5
6
  function digest(data) {
6
7
  const hash = (0, crypto_1.createHash)('sha256');
7
8
  hash.update(data);
@@ -12,3 +13,7 @@ function digestSignature(signature) {
12
13
  return (0, crypto_1.createHash)('sha256').update(signature).digest('base64');
13
14
  }
14
15
  exports.digestSignature = digestSignature;
16
+ function generateSwiftUuid() {
17
+ return Uint8Array.from(Buffer.from((0, nanoid_1.nanoid)(8)));
18
+ }
19
+ exports.generateSwiftUuid = generateSwiftUuid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk-browser",
3
- "version": "2.104.0-beta.25",
3
+ "version": "2.104.0-beta.26",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -50,6 +50,7 @@
50
50
  "@switchboard-xyz/on-demand": "1.2.42",
51
51
  "@triton-one/yellowstone-grpc": "1.3.0",
52
52
  "anchor-bankrun": "0.3.0",
53
+ "nanoid": "3.3.4",
53
54
  "node-cache": "5.1.2",
54
55
  "rpc-websockets": "7.5.1",
55
56
  "solana-bankrun": "0.3.1",
package/src/config.ts CHANGED
@@ -44,9 +44,6 @@ export type DriftEnv = 'devnet' | 'mainnet-beta';
44
44
  export const DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
45
45
  export const DRIFT_ORACLE_RECEIVER_ID =
46
46
  'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha';
47
- export const SWIFT_ID = 'SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS';
48
- export const ANCHOR_TEST_SWIFT_ID =
49
- 'DpaEdAPW3ZX67fnczT14AoX12Lx9VMkxvtT81nCHy3Nv';
50
47
  export const PTYH_LAZER_PROGRAM_ID =
51
48
  'pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt';
52
49
  export const PYTH_LAZER_STORAGE_ACCOUNT_KEY = new PublicKey(
@@ -54,7 +54,6 @@ import {
54
54
  StateAccount,
55
55
  SwapReduceOnly,
56
56
  SwiftOrderParamsMessage,
57
- SwiftServerMessage,
58
57
  TakerInfo,
59
58
  TxParams,
60
59
  UserAccount,
@@ -136,7 +135,6 @@ import {
136
135
  DRIFT_ORACLE_RECEIVER_ID,
137
136
  DEFAULT_CONFIRMATION_OPTS,
138
137
  DRIFT_PROGRAM_ID,
139
- SWIFT_ID,
140
138
  DriftEnv,
141
139
  PYTH_LAZER_STORAGE_ACCOUNT_KEY,
142
140
  } from './config';
@@ -202,7 +200,6 @@ export class DriftClient {
202
200
  connection: Connection;
203
201
  wallet: IWallet;
204
202
  public program: Program;
205
- public swiftID: PublicKey;
206
203
  provider: AnchorProvider;
207
204
  opts?: ConfirmOptions;
208
205
  users = new Map<string, User>();
@@ -270,7 +267,6 @@ export class DriftClient {
270
267
  config.programID ?? new PublicKey(DRIFT_PROGRAM_ID),
271
268
  this.provider
272
269
  );
273
- this.swiftID = config.swiftID ?? new PublicKey(SWIFT_ID);
274
270
 
275
271
  this.authority = config.authority ?? this.wallet.publicKey;
276
272
  this.activeSubAccountId = config.activeSubAccountId ?? 0;
@@ -5847,29 +5843,6 @@ export class DriftClient {
5847
5843
  );
5848
5844
  }
5849
5845
 
5850
- public encodeSwiftServerMessage(message: SwiftServerMessage): Buffer {
5851
- return this.program.coder.types.encode('SwiftServerMessage', message);
5852
- }
5853
-
5854
- public decodeSwiftServerMessage(encodedMessage: Buffer): SwiftServerMessage {
5855
- const decodedSwiftMessage = this.program.coder.types.decode(
5856
- 'SwiftServerMessage',
5857
- encodedMessage
5858
- );
5859
- return {
5860
- uuid: decodedSwiftMessage.uuid,
5861
- slot: decodedSwiftMessage.slot,
5862
- swiftOrderSignature: decodedSwiftMessage.swiftSignature,
5863
- };
5864
- }
5865
-
5866
- public signSwiftServerMessage(message: SwiftServerMessage): Buffer {
5867
- const swiftServerMessage = Uint8Array.from(
5868
- digest(this.encodeSwiftServerMessage(message))
5869
- );
5870
- return this.signMessage(swiftServerMessage);
5871
- }
5872
-
5873
5846
  public signSwiftOrderParamsMessage(
5874
5847
  orderParamsMessage: SwiftOrderParamsMessage
5875
5848
  ): Buffer {
@@ -5906,8 +5879,6 @@ export class DriftClient {
5906
5879
  }
5907
5880
 
5908
5881
  public async placeSwiftTakerOrder(
5909
- swiftServerMessage: Buffer,
5910
- swiftSignature: Buffer,
5911
5882
  swiftOrderParamsMessage: Buffer,
5912
5883
  swiftOrderParamsSignature: Buffer,
5913
5884
  marketIndex: number,
@@ -5919,8 +5890,6 @@ export class DriftClient {
5919
5890
  txParams?: TxParams
5920
5891
  ): Promise<TransactionSignature> {
5921
5892
  const ixs = await this.getPlaceSwiftTakerPerpOrderIxs(
5922
- swiftServerMessage,
5923
- swiftSignature,
5924
5893
  swiftOrderParamsMessage,
5925
5894
  swiftOrderParamsSignature,
5926
5895
  marketIndex,
@@ -5935,8 +5904,6 @@ export class DriftClient {
5935
5904
  }
5936
5905
 
5937
5906
  public async getPlaceSwiftTakerPerpOrderIxs(
5938
- encodedSwiftServerMessage: Buffer,
5939
- swiftSignature: Buffer,
5940
5907
  encodedSwiftOrderParamsMessage: Buffer,
5941
5908
  swiftOrderParamsSignature: Buffer,
5942
5909
  marketIndex: number,
@@ -5957,13 +5924,6 @@ export class DriftClient {
5957
5924
  readablePerpMarketIndex: marketIndex,
5958
5925
  });
5959
5926
 
5960
- const swiftServerSignatureIx =
5961
- Ed25519Program.createInstructionWithPublicKey({
5962
- publicKey: new PublicKey(this.swiftID).toBytes(),
5963
- signature: Uint8Array.from(swiftSignature),
5964
- message: Uint8Array.from(digest(encodedSwiftServerMessage)),
5965
- });
5966
-
5967
5927
  const authorityToUse = authority || takerInfo.takerUserAccount.authority;
5968
5928
  const swiftOrderParamsSignatureIx =
5969
5929
  Ed25519Program.createInstructionWithPublicKey({
@@ -5976,7 +5936,6 @@ export class DriftClient {
5976
5936
 
5977
5937
  const placeTakerSwiftPerpOrderIx =
5978
5938
  await this.program.instruction.placeSwiftTakerOrder(
5979
- encodedSwiftServerMessage,
5980
5939
  encodedSwiftOrderParamsMessage,
5981
5940
  {
5982
5941
  accounts: {
@@ -5994,16 +5953,10 @@ export class DriftClient {
5994
5953
  }
5995
5954
  );
5996
5955
 
5997
- return [
5998
- swiftServerSignatureIx,
5999
- swiftOrderParamsSignatureIx,
6000
- placeTakerSwiftPerpOrderIx,
6001
- ];
5956
+ return [swiftOrderParamsSignatureIx, placeTakerSwiftPerpOrderIx];
6002
5957
  }
6003
5958
 
6004
5959
  public async placeAndMakeSwiftPerpOrder(
6005
- encodedSwiftMessage: Buffer,
6006
- swiftSignature: Buffer,
6007
5960
  encodedSwiftOrderParamsMessage: Buffer,
6008
5961
  swiftOrderParamsSignature: Buffer,
6009
5962
  swiftOrderUuid: Uint8Array,
@@ -6018,8 +5971,6 @@ export class DriftClient {
6018
5971
  subAccountId?: number
6019
5972
  ): Promise<TransactionSignature> {
6020
5973
  const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(
6021
- encodedSwiftMessage,
6022
- swiftSignature,
6023
5974
  encodedSwiftOrderParamsMessage,
6024
5975
  swiftOrderParamsSignature,
6025
5976
  swiftOrderUuid,
@@ -6039,8 +5990,6 @@ export class DriftClient {
6039
5990
  }
6040
5991
 
6041
5992
  public async getPlaceAndMakeSwiftPerpOrderIxs(
6042
- encodedSwiftMessage: Buffer,
6043
- swiftSignature: Buffer,
6044
5993
  encodedSwiftOrderParamsMessage: Buffer,
6045
5994
  swiftOrderParamsSignature: Buffer,
6046
5995
  swiftOrderUuid: Uint8Array,
@@ -6053,18 +6002,13 @@ export class DriftClient {
6053
6002
  referrerInfo?: ReferrerInfo,
6054
6003
  subAccountId?: number
6055
6004
  ): Promise<TransactionInstruction[]> {
6056
- const [
6057
- swiftServerSignatureIx,
6058
- swiftOrderSignatureIx,
6059
- placeTakerSwiftPerpOrderIx,
6060
- ] = await this.getPlaceSwiftTakerPerpOrderIxs(
6061
- encodedSwiftMessage,
6062
- swiftSignature,
6063
- encodedSwiftOrderParamsMessage,
6064
- swiftOrderParamsSignature,
6065
- orderParams.marketIndex,
6066
- takerInfo
6067
- );
6005
+ const [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx] =
6006
+ await this.getPlaceSwiftTakerPerpOrderIxs(
6007
+ encodedSwiftOrderParamsMessage,
6008
+ swiftOrderParamsSignature,
6009
+ orderParams.marketIndex,
6010
+ takerInfo
6011
+ );
6068
6012
 
6069
6013
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
6070
6014
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -6113,12 +6057,7 @@ export class DriftClient {
6113
6057
  }
6114
6058
  );
6115
6059
 
6116
- return [
6117
- swiftServerSignatureIx,
6118
- swiftOrderSignatureIx,
6119
- placeTakerSwiftPerpOrderIx,
6120
- placeAndMakeIx,
6121
- ];
6060
+ return [swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx, placeAndMakeIx];
6122
6061
  }
6123
6062
 
6124
6063
  public encodeRFQMakerOrderParams(message: RFQMakerOrderParams): Buffer {
@@ -18,7 +18,6 @@ export type DriftClientConfig = {
18
18
  wallet: IWallet;
19
19
  env?: DriftEnv;
20
20
  programID?: PublicKey;
21
- swiftID?: PublicKey;
22
21
  accountSubscription?: DriftClientSubscriptionConfig;
23
22
  opts?: ConfirmOptions;
24
23
  txSender?: TxSender;
@@ -813,10 +813,6 @@
813
813
  }
814
814
  ],
815
815
  "args": [
816
- {
817
- "name": "swiftMessageBytes",
818
- "type": "bytes"
819
- },
820
816
  {
821
817
  "name": "swiftOrderParamsMessageBytes",
822
818
  "type": "bytes"
@@ -9002,50 +8998,33 @@
9002
8998
  }
9003
8999
  },
9004
9000
  {
9005
- "name": "SwiftServerMessage",
9001
+ "name": "SwiftOrderParamsMessage",
9006
9002
  "type": {
9007
9003
  "kind": "struct",
9008
9004
  "fields": [
9009
9005
  {
9010
- "name": "uuid",
9006
+ "name": "swiftOrderParams",
9011
9007
  "type": {
9012
- "array": [
9013
- "u8",
9014
- 8
9015
- ]
9008
+ "defined": "OrderParams"
9016
9009
  }
9017
9010
  },
9018
9011
  {
9019
- "name": "swiftOrderSignature",
9020
- "type": {
9021
- "array": [
9022
- "u8",
9023
- 64
9024
- ]
9025
- }
9012
+ "name": "subAccountId",
9013
+ "type": "u16"
9026
9014
  },
9027
9015
  {
9028
9016
  "name": "slot",
9029
9017
  "type": "u64"
9030
- }
9031
- ]
9032
- }
9033
- },
9034
- {
9035
- "name": "SwiftOrderParamsMessage",
9036
- "type": {
9037
- "kind": "struct",
9038
- "fields": [
9018
+ },
9039
9019
  {
9040
- "name": "swiftOrderParams",
9020
+ "name": "uuid",
9041
9021
  "type": {
9042
- "defined": "OrderParams"
9022
+ "array": [
9023
+ "u8",
9024
+ 8
9025
+ ]
9043
9026
  }
9044
9027
  },
9045
- {
9046
- "name": "subAccountId",
9047
- "type": "u16"
9048
- },
9049
9028
  {
9050
9029
  "name": "takeProfitOrderParams",
9051
9030
  "type": {
package/src/types.ts CHANGED
@@ -1105,15 +1105,11 @@ export const DefaultOrderParams: OrderParams = {
1105
1105
  auctionEndPrice: null,
1106
1106
  };
1107
1107
 
1108
- export type SwiftServerMessage = {
1109
- slot: BN;
1110
- swiftOrderSignature: Uint8Array;
1111
- uuid: Uint8Array; // From buffer of standard UUID string
1112
- };
1113
-
1114
1108
  export type SwiftOrderParamsMessage = {
1115
1109
  swiftOrderParams: OptionalOrderParams;
1116
1110
  subAccountId: number;
1111
+ uuid: Uint8Array;
1112
+ slot: BN;
1117
1113
  takeProfitOrderParams: SwiftTriggerOrderParams | null;
1118
1114
  stopLossOrderParams: SwiftTriggerOrderParams | null;
1119
1115
  };
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'crypto';
2
+ import { nanoid } from 'nanoid';
2
3
 
3
4
  export function digest(data: Buffer): Buffer {
4
5
  const hash = createHash('sha256');
@@ -9,3 +10,7 @@ export function digest(data: Buffer): Buffer {
9
10
  export function digestSignature(signature: Uint8Array): string {
10
11
  return createHash('sha256').update(signature).digest('base64');
11
12
  }
13
+
14
+ export function generateSwiftUuid(): Uint8Array {
15
+ return Uint8Array.from(Buffer.from(nanoid(8)));
16
+ }