@drift-labs/sdk 2.98.0-beta.8 → 2.99.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
  3. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
  4. package/lib/browser/accounts/types.d.ts +14 -1
  5. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
  6. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
  7. package/lib/browser/addresses/pda.d.ts +1 -0
  8. package/lib/browser/addresses/pda.js +8 -1
  9. package/lib/browser/constants/perpMarkets.js +11 -0
  10. package/lib/browser/constants/spotMarkets.js +2 -2
  11. package/lib/browser/driftClient.d.ts +14 -4
  12. package/lib/browser/driftClient.js +64 -21
  13. package/lib/browser/idl/drift.json +199 -17
  14. package/lib/browser/index.d.ts +4 -0
  15. package/lib/browser/index.js +4 -0
  16. package/lib/browser/jupiter/jupiterClient.d.ts +6 -0
  17. package/lib/browser/memcmp.d.ts +3 -0
  18. package/lib/browser/memcmp.js +28 -1
  19. package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
  20. package/lib/browser/slot/SlothashSubscriber.js +85 -0
  21. package/lib/browser/types.d.ts +4 -3
  22. package/lib/browser/user.js +3 -0
  23. package/lib/browser/userMap/referrerMap.d.ts +45 -0
  24. package/lib/browser/userMap/referrerMap.js +180 -0
  25. package/lib/browser/util/digest.d.ts +4 -0
  26. package/lib/browser/util/digest.js +14 -0
  27. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
  28. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
  29. package/lib/node/accounts/types.d.ts +14 -1
  30. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
  31. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
  32. package/lib/node/addresses/pda.d.ts +1 -0
  33. package/lib/node/addresses/pda.js +8 -1
  34. package/lib/node/constants/perpMarkets.js +11 -0
  35. package/lib/node/constants/spotMarkets.js +2 -2
  36. package/lib/node/driftClient.d.ts +14 -4
  37. package/lib/node/driftClient.js +64 -21
  38. package/lib/node/idl/drift.json +199 -17
  39. package/lib/node/index.d.ts +4 -0
  40. package/lib/node/index.js +4 -0
  41. package/lib/node/jupiter/jupiterClient.d.ts +6 -0
  42. package/lib/node/memcmp.d.ts +3 -0
  43. package/lib/node/memcmp.js +28 -1
  44. package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
  45. package/lib/node/slot/SlothashSubscriber.js +85 -0
  46. package/lib/node/types.d.ts +4 -3
  47. package/lib/node/user.js +3 -0
  48. package/lib/node/userMap/referrerMap.d.ts +45 -0
  49. package/lib/node/userMap/referrerMap.js +180 -0
  50. package/lib/node/util/digest.d.ts +4 -0
  51. package/lib/node/util/digest.js +14 -0
  52. package/package.json +1 -1
  53. package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
  54. package/src/accounts/types.ts +25 -1
  55. package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
  56. package/src/addresses/pda.ts +13 -0
  57. package/src/constants/perpMarkets.ts +12 -0
  58. package/src/constants/spotMarkets.ts +2 -2
  59. package/src/driftClient.ts +127 -38
  60. package/src/idl/drift.json +199 -17
  61. package/src/index.ts +4 -0
  62. package/src/jupiter/jupiterClient.ts +6 -0
  63. package/src/memcmp.ts +27 -0
  64. package/src/slot/SlothashSubscriber.ts +126 -0
  65. package/src/types.ts +4 -3
  66. package/src/user.ts +4 -0
  67. package/src/userMap/referrerMap.ts +283 -0
  68. package/src/util/digest.ts +11 -0
  69. package/tests/ci/verifyConstants.ts +16 -2
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.98.0-beta.8
1
+ 2.99.0-beta.0
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { DataAndSlot, HighLeverageModeConfigAccountEvents, HighLeverageModeConfigAccountSubscriber } from './types';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import StrictEventEmitter from 'strict-event-emitter-types';
5
+ import { EventEmitter } from 'events';
6
+ import { PublicKey } from '@solana/web3.js';
7
+ import { BulkAccountLoader } from './bulkAccountLoader';
8
+ import { HighLeverageModeConfig } from '../types';
9
+ export declare class PollingHighLeverageModeConfigAccountSubscriber implements HighLeverageModeConfigAccountSubscriber {
10
+ isSubscribed: boolean;
11
+ program: Program;
12
+ eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
13
+ highLeverageModeConfigAccountPublicKey: PublicKey;
14
+ accountLoader: BulkAccountLoader;
15
+ callbackId?: string;
16
+ errorCallbackId?: string;
17
+ highLeverageModeConfigAccountAndSlot?: DataAndSlot<HighLeverageModeConfig>;
18
+ constructor(program: Program, publicKey: PublicKey, accountLoader: BulkAccountLoader);
19
+ subscribe(highLeverageModeConfig?: HighLeverageModeConfig): Promise<boolean>;
20
+ addToAccountLoader(): Promise<void>;
21
+ fetchIfUnloaded(): Promise<void>;
22
+ fetch(): Promise<void>;
23
+ doesAccountExist(): boolean;
24
+ unsubscribe(): Promise<void>;
25
+ assertIsSubscribed(): void;
26
+ getHighLeverageModeConfigAccountAndSlot(): DataAndSlot<HighLeverageModeConfig>;
27
+ didSubscriptionSucceed(): boolean;
28
+ updateData(highLeverageModeConfig: HighLeverageModeConfig, slot: number): void;
29
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PollingHighLeverageModeConfigAccountSubscriber = void 0;
4
+ const types_1 = require("./types");
5
+ const events_1 = require("events");
6
+ class PollingHighLeverageModeConfigAccountSubscriber {
7
+ constructor(program, publicKey, accountLoader) {
8
+ this.isSubscribed = false;
9
+ this.program = program;
10
+ this.highLeverageModeConfigAccountPublicKey = publicKey;
11
+ this.accountLoader = accountLoader;
12
+ this.eventEmitter = new events_1.EventEmitter();
13
+ }
14
+ async subscribe(highLeverageModeConfig) {
15
+ if (this.isSubscribed) {
16
+ return true;
17
+ }
18
+ if (highLeverageModeConfig) {
19
+ this.highLeverageModeConfigAccountAndSlot = {
20
+ data: highLeverageModeConfig,
21
+ slot: undefined,
22
+ };
23
+ }
24
+ await this.addToAccountLoader();
25
+ await this.fetchIfUnloaded();
26
+ if (this.doesAccountExist()) {
27
+ this.eventEmitter.emit('update');
28
+ }
29
+ this.isSubscribed = true;
30
+ return true;
31
+ }
32
+ async addToAccountLoader() {
33
+ if (this.callbackId) {
34
+ return;
35
+ }
36
+ this.callbackId = await this.accountLoader.addAccount(this.highLeverageModeConfigAccountPublicKey, (buffer, slot) => {
37
+ if (!buffer) {
38
+ return;
39
+ }
40
+ if (this.highLeverageModeConfigAccountAndSlot &&
41
+ this.highLeverageModeConfigAccountAndSlot.slot > slot) {
42
+ return;
43
+ }
44
+ const account = this.program.account.user.coder.accounts.decode('HighLeverageModeConfig', buffer);
45
+ this.highLeverageModeConfigAccountAndSlot = { data: account, slot };
46
+ this.eventEmitter.emit('highLeverageModeConfigAccountUpdate', account);
47
+ this.eventEmitter.emit('update');
48
+ });
49
+ this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
50
+ this.eventEmitter.emit('error', error);
51
+ });
52
+ }
53
+ async fetchIfUnloaded() {
54
+ if (this.highLeverageModeConfigAccountAndSlot === undefined) {
55
+ await this.fetch();
56
+ }
57
+ }
58
+ async fetch() {
59
+ var _a, _b;
60
+ try {
61
+ const dataAndContext = await this.program.account.highLeverageModeConfig.fetchAndContext(this.highLeverageModeConfigAccountPublicKey, this.accountLoader.commitment);
62
+ if (dataAndContext.context.slot >
63
+ ((_b = (_a = this.highLeverageModeConfigAccountAndSlot) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0)) {
64
+ this.highLeverageModeConfigAccountAndSlot = {
65
+ data: dataAndContext.data,
66
+ slot: dataAndContext.context.slot,
67
+ };
68
+ }
69
+ }
70
+ catch (e) {
71
+ console.log(`PollingHighLeverageModeConfigAccountSubscriber.fetch() HighLeverageModeConfig does not exist: ${e.message}`);
72
+ }
73
+ }
74
+ doesAccountExist() {
75
+ return this.highLeverageModeConfigAccountAndSlot !== undefined;
76
+ }
77
+ async unsubscribe() {
78
+ if (!this.isSubscribed) {
79
+ return;
80
+ }
81
+ this.accountLoader.removeAccount(this.highLeverageModeConfigAccountPublicKey, this.callbackId);
82
+ this.callbackId = undefined;
83
+ this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
84
+ this.errorCallbackId = undefined;
85
+ this.isSubscribed = false;
86
+ }
87
+ assertIsSubscribed() {
88
+ if (!this.isSubscribed) {
89
+ throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
90
+ }
91
+ }
92
+ getHighLeverageModeConfigAccountAndSlot() {
93
+ this.assertIsSubscribed();
94
+ return this.highLeverageModeConfigAccountAndSlot;
95
+ }
96
+ didSubscriptionSucceed() {
97
+ return !!this.highLeverageModeConfigAccountAndSlot;
98
+ }
99
+ updateData(highLeverageModeConfig, slot) {
100
+ if (!this.highLeverageModeConfigAccountAndSlot ||
101
+ this.highLeverageModeConfigAccountAndSlot.slot < slot) {
102
+ this.highLeverageModeConfigAccountAndSlot = {
103
+ data: highLeverageModeConfig,
104
+ slot,
105
+ };
106
+ this.eventEmitter.emit('highLeverageModeConfigAccountUpdate', highLeverageModeConfig);
107
+ this.eventEmitter.emit('update');
108
+ }
109
+ }
110
+ }
111
+ exports.PollingHighLeverageModeConfigAccountSubscriber = PollingHighLeverageModeConfigAccountSubscriber;
@@ -6,7 +6,7 @@ import StrictEventEmitter from 'strict-event-emitter-types';
6
6
  import { EventEmitter } from 'events';
7
7
  import { Context, PublicKey } from '@solana/web3.js';
8
8
  import { Account } from '@solana/spl-token';
9
- import { OracleInfo, OraclePriceData } from '..';
9
+ import { HighLeverageModeConfig, OracleInfo, OraclePriceData } from '..';
10
10
  import { ChannelOptions, CommitmentLevel } from '../isomorphic/grpc';
11
11
  export interface AccountSubscriber<T> {
12
12
  dataAndSlot?: DataAndSlot<T>;
@@ -153,3 +153,16 @@ export type GrpcConfigs = {
153
153
  commitmentLevel?: CommitmentLevel;
154
154
  channelOptions?: ChannelOptions;
155
155
  };
156
+ export interface HighLeverageModeConfigAccountSubscriber {
157
+ eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
158
+ isSubscribed: boolean;
159
+ subscribe(highLeverageModeConfigAccount?: HighLeverageModeConfig): Promise<boolean>;
160
+ fetch(): Promise<void>;
161
+ unsubscribe(): Promise<void>;
162
+ getHighLeverageModeConfigAccountAndSlot(): DataAndSlot<HighLeverageModeConfig>;
163
+ }
164
+ export interface HighLeverageModeConfigAccountEvents {
165
+ highLeverageModeConfigAccountUpdate: (payload: HighLeverageModeConfig) => void;
166
+ update: void;
167
+ error: (e: Error) => void;
168
+ }
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { DataAndSlot, AccountSubscriber, HighLeverageModeConfigAccountEvents, HighLeverageModeConfigAccountSubscriber } from './types';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import StrictEventEmitter from 'strict-event-emitter-types';
5
+ import { EventEmitter } from 'events';
6
+ import { Commitment, PublicKey } from '@solana/web3.js';
7
+ import { HighLeverageModeConfig } from '../types';
8
+ export declare class WebSocketHighLeverageModeConfigAccountSubscriber implements HighLeverageModeConfigAccountSubscriber {
9
+ isSubscribed: boolean;
10
+ resubTimeoutMs?: number;
11
+ commitment?: Commitment;
12
+ program: Program;
13
+ eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
14
+ highLeverageModeConfigAccountPublicKey: PublicKey;
15
+ highLeverageModeConfigDataAccountSubscriber: AccountSubscriber<HighLeverageModeConfig>;
16
+ constructor(program: Program, highLeverageModeConfigAccountPublicKey: PublicKey, resubTimeoutMs?: number, commitment?: Commitment);
17
+ subscribe(highLeverageModeConfigAccount?: HighLeverageModeConfig): Promise<boolean>;
18
+ fetch(): Promise<void>;
19
+ unsubscribe(): Promise<void>;
20
+ assertIsSubscribed(): void;
21
+ getHighLeverageModeConfigAccountAndSlot(): DataAndSlot<HighLeverageModeConfig>;
22
+ updateData(highLeverageModeConfig: HighLeverageModeConfig, slot: number): void;
23
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketHighLeverageModeConfigAccountSubscriber = void 0;
4
+ const types_1 = require("./types");
5
+ const events_1 = require("events");
6
+ const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
7
+ class WebSocketHighLeverageModeConfigAccountSubscriber {
8
+ constructor(program, highLeverageModeConfigAccountPublicKey, resubTimeoutMs, commitment) {
9
+ this.isSubscribed = false;
10
+ this.program = program;
11
+ this.highLeverageModeConfigAccountPublicKey =
12
+ highLeverageModeConfigAccountPublicKey;
13
+ this.eventEmitter = new events_1.EventEmitter();
14
+ this.resubTimeoutMs = resubTimeoutMs;
15
+ this.commitment = commitment;
16
+ }
17
+ async subscribe(highLeverageModeConfigAccount) {
18
+ if (this.isSubscribed) {
19
+ return true;
20
+ }
21
+ this.highLeverageModeConfigDataAccountSubscriber =
22
+ new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('highLeverageModeConfig', this.program, this.highLeverageModeConfigAccountPublicKey, undefined, {
23
+ resubTimeoutMs: this.resubTimeoutMs,
24
+ }, this.commitment);
25
+ if (highLeverageModeConfigAccount) {
26
+ this.highLeverageModeConfigDataAccountSubscriber.setData(highLeverageModeConfigAccount);
27
+ }
28
+ await this.highLeverageModeConfigDataAccountSubscriber.subscribe((data) => {
29
+ this.eventEmitter.emit('highLeverageModeConfigAccountUpdate', data);
30
+ this.eventEmitter.emit('update');
31
+ });
32
+ this.eventEmitter.emit('update');
33
+ this.isSubscribed = true;
34
+ return true;
35
+ }
36
+ async fetch() {
37
+ await Promise.all([
38
+ this.highLeverageModeConfigDataAccountSubscriber.fetch(),
39
+ ]);
40
+ }
41
+ async unsubscribe() {
42
+ if (!this.isSubscribed) {
43
+ return;
44
+ }
45
+ await Promise.all([
46
+ this.highLeverageModeConfigDataAccountSubscriber.unsubscribe(),
47
+ ]);
48
+ this.isSubscribed = false;
49
+ }
50
+ assertIsSubscribed() {
51
+ if (!this.isSubscribed) {
52
+ throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
53
+ }
54
+ }
55
+ getHighLeverageModeConfigAccountAndSlot() {
56
+ this.assertIsSubscribed();
57
+ return this.highLeverageModeConfigDataAccountSubscriber.dataAndSlot;
58
+ }
59
+ updateData(highLeverageModeConfig, slot) {
60
+ var _a;
61
+ const currentDataSlot = ((_a = this.highLeverageModeConfigDataAccountSubscriber.dataAndSlot) === null || _a === void 0 ? void 0 : _a.slot) || 0;
62
+ if (currentDataSlot <= slot) {
63
+ this.highLeverageModeConfigDataAccountSubscriber.setData(highLeverageModeConfig, slot);
64
+ this.eventEmitter.emit('highLeverageModeConfigAccountUpdate', highLeverageModeConfig);
65
+ this.eventEmitter.emit('update');
66
+ }
67
+ }
68
+ }
69
+ exports.WebSocketHighLeverageModeConfigAccountSubscriber = WebSocketHighLeverageModeConfigAccountSubscriber;
@@ -9,6 +9,7 @@ export declare function getUserAccountPublicKey(programId: PublicKey, authority:
9
9
  export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
10
10
  export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
11
11
  export declare function getRFQUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
+ export declare function getSwiftUserAccountPublicKey(programId: PublicKey, userAccountPublicKey: PublicKey): PublicKey;
12
13
  export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
13
14
  export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
14
15
  export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  const spl_token_1 = require("@solana/spl-token");
@@ -69,6 +69,13 @@ function getRFQUserAccountPublicKey(programId, userAccountPublicKey) {
69
69
  ], programId)[0];
70
70
  }
71
71
  exports.getRFQUserAccountPublicKey = getRFQUserAccountPublicKey;
72
+ function getSwiftUserAccountPublicKey(programId, userAccountPublicKey) {
73
+ return web3_js_1.PublicKey.findProgramAddressSync([
74
+ Buffer.from(anchor.utils.bytes.utf8.encode('SWIFT')),
75
+ userAccountPublicKey.toBuffer(),
76
+ ], programId)[0];
77
+ }
78
+ exports.getSwiftUserAccountPublicKey = getSwiftUserAccountPublicKey;
72
79
  async function getPerpMarketPublicKey(programId, marketIndex) {
73
80
  return (await web3_js_1.PublicKey.findProgramAddress([
74
81
  Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
@@ -872,6 +872,17 @@ exports.MainnetPerpMarkets = [
872
872
  oracleSource: __1.OracleSource.PYTH_1K_PULL,
873
873
  pythFeedId: '0x514aed52ca5294177f20187ae883cec4a018619772ddce41efcc36a6448f5d5d',
874
874
  },
875
+ {
876
+ fullName: 'MICHI',
877
+ category: ['Meme'],
878
+ symbol: 'MICHI-PERP',
879
+ baseAssetSymbol: 'MICHI',
880
+ marketIndex: 52,
881
+ oracle: new web3_js_1.PublicKey('GHzvsMDMSiuyZoWhEAuM27MKFdN2Y4fA4wSDuSd6dLMA'),
882
+ launchTs: 1730402722000,
883
+ oracleSource: __1.OracleSource.PYTH_PULL,
884
+ pythFeedId: '0x63a45218d6b13ffd28ca04748615511bf70eff80a3411c97d96b8ed74a6decab',
885
+ },
875
886
  ];
876
887
  exports.PerpMarkets = {
877
888
  devnet: exports.DevnetPerpMarkets,
@@ -337,12 +337,12 @@ exports.MainnetSpotMarkets = [
337
337
  {
338
338
  symbol: 'BNSOL',
339
339
  marketIndex: 25,
340
- oracle: new web3_js_1.PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
340
+ oracle: new web3_js_1.PublicKey('8DmXTfhhtb9kTcpTVfb6Ygx8WhZ8wexGqcpxfn23zooe'),
341
341
  oracleSource: __1.OracleSource.PYTH_PULL,
342
342
  mint: new web3_js_1.PublicKey('BNso1VUJnh4zcfpZa6986Ea66P6TCp59hvtNJ8b1X85'),
343
343
  precision: numericConstants_1.LAMPORTS_PRECISION,
344
344
  precisionExp: numericConstants_1.LAMPORTS_EXP,
345
- pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
345
+ pythFeedId: '0x55f8289be7450f1ae564dd9798e49e7d797d89adbc54fe4f8c906b1fcb94b0c3',
346
346
  },
347
347
  {
348
348
  symbol: 'MOTHER',
@@ -22,6 +22,7 @@ import { UserStatsSubscriptionConfig } from './userStatsConfig';
22
22
  import { TxHandler } from './tx/txHandler';
23
23
  import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
24
24
  import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
25
+ import { Slothash } from './slot/SlothashSubscriber';
25
26
  type RemainingAccountParams = {
26
27
  userAccounts: UserAccount[];
27
28
  writablePerpMarketIndexes?: number[];
@@ -140,6 +141,8 @@ export declare class DriftClient {
140
141
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
141
142
  initializeRFQUser(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
142
143
  getInitializeRFQUserInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
144
+ initializeSwiftUserOrdersAccount(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
145
+ getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
143
146
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
144
147
  getNextSubAccountId(): Promise<number>;
145
148
  initializeReferrerName(name: string): Promise<TransactionSignature>;
@@ -531,12 +534,12 @@ export declare class DriftClient {
531
534
  takerStats: PublicKey;
532
535
  takerUserAccount: UserAccount;
533
536
  }): Promise<TransactionInstruction[]>;
534
- placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
537
+ placeAndMakeSwiftPerpOrder(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
535
538
  taker: PublicKey;
536
539
  takerStats: PublicKey;
537
540
  takerUserAccount: UserAccount;
538
541
  }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
539
- getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, takerExpectedOrderId: number, takerInfo: {
542
+ getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage: Buffer, swiftSignature: Buffer, encodedSwiftOrderParamsMessage: Buffer, swiftOrderParamsSignature: Buffer, swiftOrderUuid: Uint8Array, takerInfo: {
540
543
  taker: PublicKey;
541
544
  takerStats: PublicKey;
542
545
  takerUserAccount: UserAccount;
@@ -759,6 +762,13 @@ export declare class DriftClient {
759
762
  resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
760
763
  getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
761
764
  getDepositIntoSpotMarketRevenuePoolIx(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
765
+ /**
766
+ * This ix will donate your funds to drift revenue pool. It does not deposit into your user account
767
+ * @param marketIndex
768
+ * @param amount
769
+ * @param userTokenAccountPublicKey
770
+ * @returns
771
+ */
762
772
  depositIntoSpotMarketRevenuePool(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionSignature>;
763
773
  getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo;
764
774
  /**
@@ -794,8 +804,8 @@ export declare class DriftClient {
794
804
  proof: number[][];
795
805
  };
796
806
  }, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
797
- getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, numSignatures?: number): Promise<TransactionInstruction | undefined>;
798
- postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
807
+ getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionInstruction | undefined>;
808
+ postSwitchboardOnDemandUpdate(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionSignature>;
799
809
  private getBuildEncodedVaaIxs;
800
810
  enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
801
811
  getEnableHighLeverageModeIx(subAccountId: number, depositToTradeArgs?: {
@@ -69,6 +69,7 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
69
69
  const on_demand_1 = require("@switchboard-xyz/on-demand");
70
70
  const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
71
71
  const tweetnacl_1 = __importDefault(require("tweetnacl"));
72
+ const digest_1 = require("./util/digest");
72
73
  /**
73
74
  * # DriftClient
74
75
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -185,7 +186,7 @@ class DriftClient {
185
186
  if (config.env && !this.marketLookupTable) {
186
187
  this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
187
188
  }
188
- const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Subscribe;
189
+ const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
189
190
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
190
191
  config.spotMarketIndexes === undefined &&
191
192
  config.oracleInfos === undefined;
@@ -599,6 +600,28 @@ class DriftClient {
599
600
  });
600
601
  return [rfqUserAccountPublicKey, initializeUserAccountIx];
601
602
  }
603
+ async initializeSwiftUserOrdersAccount(userAccountPublicKey, txParams) {
604
+ const initializeIxs = [];
605
+ const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey);
606
+ initializeIxs.push(initializeUserAccountIx);
607
+ const tx = await this.buildTransaction(initializeIxs, txParams);
608
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
609
+ return [txSig, swiftUserAccountPublicKey];
610
+ }
611
+ async getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey) {
612
+ const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
613
+ const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders({
614
+ accounts: {
615
+ swiftUserOrders: swiftUserAccountPublicKey,
616
+ authority: this.wallet.publicKey,
617
+ user: userAccountPublicKey,
618
+ payer: this.wallet.publicKey,
619
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
620
+ systemProgram: anchor.web3.SystemProgram.programId,
621
+ },
622
+ });
623
+ return [swiftUserAccountPublicKey, initializeUserAccountIx];
624
+ }
602
625
  async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
603
626
  const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
604
627
  const remainingAccounts = new Array();
@@ -2992,25 +3015,22 @@ class DriftClient {
2992
3015
  });
2993
3016
  }
2994
3017
  encodeSwiftServerMessage(message) {
2995
- const messageWithBuffer = {
2996
- slot: message.slot,
2997
- swiftOrderSignature: message.swiftOrderSignature,
2998
- };
2999
- return this.program.coder.types.encode('SwiftServerMessage', messageWithBuffer);
3018
+ return this.program.coder.types.encode('SwiftServerMessage', message);
3000
3019
  }
3001
3020
  decodeSwiftServerMessage(encodedMessage) {
3002
3021
  const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3003
3022
  return {
3023
+ uuid: decodedSwiftMessage.uuid,
3004
3024
  slot: decodedSwiftMessage.slot,
3005
3025
  swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3006
3026
  };
3007
3027
  }
3008
3028
  signSwiftServerMessage(message) {
3009
- const swiftServerMessage = Uint8Array.from(this.encodeSwiftServerMessage(message));
3029
+ const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
3010
3030
  return this.signMessage(swiftServerMessage);
3011
3031
  }
3012
3032
  signSwiftOrderParamsMessage(orderParamsMessage) {
3013
- const takerOrderParamsMessage = Uint8Array.from(this.encodeSwiftOrderParamsMessage(orderParamsMessage));
3033
+ const takerOrderParamsMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftOrderParamsMessage(orderParamsMessage)));
3014
3034
  return this.signMessage(takerOrderParamsMessage);
3015
3035
  }
3016
3036
  encodeSwiftOrderParamsMessage(orderParamsMessage) {
@@ -3036,18 +3056,19 @@ class DriftClient {
3036
3056
  const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3037
3057
  publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
3038
3058
  signature: Uint8Array.from(swiftSignature),
3039
- message: Uint8Array.from(encodedSwiftServerMessage),
3059
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
3040
3060
  });
3041
3061
  const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3042
3062
  publicKey: takerInfo.takerUserAccount.authority.toBytes(),
3043
3063
  signature: Uint8Array.from(swiftOrderParamsSignature),
3044
- message: Uint8Array.from(encodedSwiftOrderParamsMessage),
3064
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftOrderParamsMessage)),
3045
3065
  });
3046
- const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, swiftSignature, {
3066
+ const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
3047
3067
  accounts: {
3048
3068
  state: await this.getStatePublicKey(),
3049
3069
  user: takerInfo.taker,
3050
3070
  userStats: takerInfo.takerStats,
3071
+ swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3051
3072
  authority: this.wallet.publicKey,
3052
3073
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3053
3074
  },
@@ -3059,13 +3080,13 @@ class DriftClient {
3059
3080
  placeTakerSwiftPerpOrderIx,
3060
3081
  ];
3061
3082
  }
3062
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3063
- const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId);
3083
+ async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3084
+ const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
3064
3085
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3065
3086
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3066
3087
  return txSig;
3067
3088
  }
3068
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId) {
3089
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3069
3090
  const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3070
3091
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3071
3092
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -3090,7 +3111,7 @@ class DriftClient {
3090
3111
  isSigner: false,
3091
3112
  });
3092
3113
  }
3093
- const placeAndMakeIx = await this.program.instruction.placeAndMakePerpOrder(orderParams, takerExpectedOrderId, {
3114
+ const placeAndMakeIx = await this.program.instruction.placeAndMakeSwiftPerpOrder(orderParams, swiftOrderUuid, {
3094
3115
  accounts: {
3095
3116
  state: await this.getStatePublicKey(),
3096
3117
  user,
@@ -3098,6 +3119,7 @@ class DriftClient {
3098
3119
  taker: takerInfo.taker,
3099
3120
  takerStats: takerInfo.takerStats,
3100
3121
  authority: this.wallet.publicKey,
3122
+ takerSwiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3101
3123
  },
3102
3124
  remainingAccounts,
3103
3125
  });
@@ -3879,6 +3901,10 @@ class DriftClient {
3879
3901
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
3880
3902
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
3881
3903
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
3904
+ const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
3905
+ // create associated token account because it may not exist
3906
+ const associatedTokenAccountPublicKey = (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarketAccount.mint, this.wallet.publicKey, true, tokenProgramId);
3907
+ addIfStakeIxs.push(await (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, associatedTokenAccountPublicKey, this.wallet.publicKey, spotMarketAccount.mint, tokenProgramId));
3882
3908
  let tokenAccount;
3883
3909
  if (!(await this.checkIfAccountExists(this.getUserStatsAccountPublicKey()))) {
3884
3910
  addIfStakeIxs.push(await this.getInitializeUserStatsIx());
@@ -3951,6 +3977,7 @@ class DriftClient {
3951
3977
  const additionalSigners = [];
3952
3978
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
3953
3979
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
3980
+ const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
3954
3981
  let tokenAccount;
3955
3982
  if (createWSOLTokenAccount) {
3956
3983
  const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
@@ -3963,7 +3990,7 @@ class DriftClient {
3963
3990
  tokenAccount = collateralAccountPublicKey;
3964
3991
  const tokenAccountExists = await this.checkIfAccountExists(tokenAccount);
3965
3992
  if (!tokenAccountExists) {
3966
- const createTokenAccountIx = await this.createAssociatedTokenAccountIdempotentInstruction(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, spotMarketAccount.mint);
3993
+ const createTokenAccountIx = await this.createAssociatedTokenAccountIdempotentInstruction(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, spotMarketAccount.mint, tokenProgramId);
3967
3994
  removeIfStakeIxs.push(createTokenAccountIx);
3968
3995
  }
3969
3996
  }
@@ -4100,6 +4127,13 @@ class DriftClient {
4100
4127
  });
4101
4128
  return ix;
4102
4129
  }
4130
+ /**
4131
+ * This ix will donate your funds to drift revenue pool. It does not deposit into your user account
4132
+ * @param marketIndex
4133
+ * @param amount
4134
+ * @param userTokenAccountPublicKey
4135
+ * @returns
4136
+ */
4103
4137
  async depositIntoSpotMarketRevenuePool(marketIndex, amount, userTokenAccountPublicKey) {
4104
4138
  const ix = await this.getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey);
4105
4139
  const tx = await this.buildTransaction([ix]);
@@ -4147,7 +4181,14 @@ class DriftClient {
4147
4181
  else {
4148
4182
  marketAccount = this.getSpotMarketAccount(marketIndex);
4149
4183
  }
4150
- takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
4184
+ let takeFeeAdjustment;
4185
+ if (user && user.isHighLeverageMode()) {
4186
+ takeFeeAdjustment = 100;
4187
+ }
4188
+ else {
4189
+ takeFeeAdjustment = marketAccount.feeAdjustment;
4190
+ }
4191
+ takerFee += (takerFee * takeFeeAdjustment) / 100;
4151
4192
  makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
4152
4193
  }
4153
4194
  return {
@@ -4288,7 +4329,7 @@ class DriftClient {
4288
4329
  },
4289
4330
  });
4290
4331
  }
4291
- async getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures = 3) {
4332
+ async getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures = 3) {
4292
4333
  const program = await this.getSwitchboardOnDemandProgram();
4293
4334
  const feedAccount = new on_demand_1.PullFeed(program, feed);
4294
4335
  if (!this.sbProgramFeedConfigs) {
@@ -4300,14 +4341,16 @@ class DriftClient {
4300
4341
  }
4301
4342
  const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
4302
4343
  numSignatures,
4303
- });
4344
+ }, recentSlothash
4345
+ ? [[new anchor_1.BN(recentSlothash.slot), recentSlothash.hash]]
4346
+ : undefined);
4304
4347
  if (!success) {
4305
4348
  return undefined;
4306
4349
  }
4307
4350
  return pullIx;
4308
4351
  }
4309
- async postSwitchboardOnDemandUpdate(feed, numSignatures = 3) {
4310
- const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures);
4352
+ async postSwitchboardOnDemandUpdate(feed, recentSlothash, numSignatures = 3) {
4353
+ const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures);
4311
4354
  if (!pullIx) {
4312
4355
  return undefined;
4313
4356
  }