@drift-labs/sdk 2.98.0-beta.9 → 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 +58 -16
  13. package/lib/browser/idl/drift.json +199 -8
  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 +1 -0
  26. package/lib/browser/util/digest.js +5 -1
  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 +58 -16
  38. package/lib/node/idl/drift.json +199 -8
  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 +1 -0
  51. package/lib/node/util/digest.js +5 -1
  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 +122 -33
  60. package/src/idl/drift.json +199 -8
  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 +4 -0
  69. package/tests/ci/verifyConstants.ts +16 -2
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.98.0-beta.9
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?: {
@@ -186,7 +186,7 @@ class DriftClient {
186
186
  if (config.env && !this.marketLookupTable) {
187
187
  this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
188
188
  }
189
- const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Subscribe;
189
+ const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
190
190
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
191
191
  config.spotMarketIndexes === undefined &&
192
192
  config.oracleInfos === undefined;
@@ -600,6 +600,28 @@ class DriftClient {
600
600
  });
601
601
  return [rfqUserAccountPublicKey, initializeUserAccountIx];
602
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
+ }
603
625
  async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
604
626
  const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
605
627
  const remainingAccounts = new Array();
@@ -2993,15 +3015,12 @@ class DriftClient {
2993
3015
  });
2994
3016
  }
2995
3017
  encodeSwiftServerMessage(message) {
2996
- const messageWithBuffer = {
2997
- slot: message.slot,
2998
- swiftOrderSignature: message.swiftOrderSignature,
2999
- };
3000
- return this.program.coder.types.encode('SwiftServerMessage', messageWithBuffer);
3018
+ return this.program.coder.types.encode('SwiftServerMessage', message);
3001
3019
  }
3002
3020
  decodeSwiftServerMessage(encodedMessage) {
3003
3021
  const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
3004
3022
  return {
3023
+ uuid: decodedSwiftMessage.uuid,
3005
3024
  slot: decodedSwiftMessage.slot,
3006
3025
  swiftOrderSignature: decodedSwiftMessage.swiftSignature,
3007
3026
  };
@@ -3049,6 +3068,7 @@ class DriftClient {
3049
3068
  state: await this.getStatePublicKey(),
3050
3069
  user: takerInfo.taker,
3051
3070
  userStats: takerInfo.takerStats,
3071
+ swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3052
3072
  authority: this.wallet.publicKey,
3053
3073
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3054
3074
  },
@@ -3060,13 +3080,13 @@ class DriftClient {
3060
3080
  placeTakerSwiftPerpOrderIx,
3061
3081
  ];
3062
3082
  }
3063
- async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
3064
- 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);
3065
3085
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3066
3086
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3067
3087
  return txSig;
3068
3088
  }
3069
- async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, takerExpectedOrderId, takerInfo, orderParams, referrerInfo, subAccountId) {
3089
+ async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
3070
3090
  const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
3071
3091
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3072
3092
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -3091,7 +3111,7 @@ class DriftClient {
3091
3111
  isSigner: false,
3092
3112
  });
3093
3113
  }
3094
- const placeAndMakeIx = await this.program.instruction.placeAndMakePerpOrder(orderParams, takerExpectedOrderId, {
3114
+ const placeAndMakeIx = await this.program.instruction.placeAndMakeSwiftPerpOrder(orderParams, swiftOrderUuid, {
3095
3115
  accounts: {
3096
3116
  state: await this.getStatePublicKey(),
3097
3117
  user,
@@ -3099,6 +3119,7 @@ class DriftClient {
3099
3119
  taker: takerInfo.taker,
3100
3120
  takerStats: takerInfo.takerStats,
3101
3121
  authority: this.wallet.publicKey,
3122
+ takerSwiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
3102
3123
  },
3103
3124
  remainingAccounts,
3104
3125
  });
@@ -3880,6 +3901,10 @@ class DriftClient {
3880
3901
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
3881
3902
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
3882
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));
3883
3908
  let tokenAccount;
3884
3909
  if (!(await this.checkIfAccountExists(this.getUserStatsAccountPublicKey()))) {
3885
3910
  addIfStakeIxs.push(await this.getInitializeUserStatsIx());
@@ -3952,6 +3977,7 @@ class DriftClient {
3952
3977
  const additionalSigners = [];
3953
3978
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
3954
3979
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
3980
+ const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
3955
3981
  let tokenAccount;
3956
3982
  if (createWSOLTokenAccount) {
3957
3983
  const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
@@ -3964,7 +3990,7 @@ class DriftClient {
3964
3990
  tokenAccount = collateralAccountPublicKey;
3965
3991
  const tokenAccountExists = await this.checkIfAccountExists(tokenAccount);
3966
3992
  if (!tokenAccountExists) {
3967
- 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);
3968
3994
  removeIfStakeIxs.push(createTokenAccountIx);
3969
3995
  }
3970
3996
  }
@@ -4101,6 +4127,13 @@ class DriftClient {
4101
4127
  });
4102
4128
  return ix;
4103
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
+ */
4104
4137
  async depositIntoSpotMarketRevenuePool(marketIndex, amount, userTokenAccountPublicKey) {
4105
4138
  const ix = await this.getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey);
4106
4139
  const tx = await this.buildTransaction([ix]);
@@ -4148,7 +4181,14 @@ class DriftClient {
4148
4181
  else {
4149
4182
  marketAccount = this.getSpotMarketAccount(marketIndex);
4150
4183
  }
4151
- 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;
4152
4192
  makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
4153
4193
  }
4154
4194
  return {
@@ -4289,7 +4329,7 @@ class DriftClient {
4289
4329
  },
4290
4330
  });
4291
4331
  }
4292
- async getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures = 3) {
4332
+ async getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures = 3) {
4293
4333
  const program = await this.getSwitchboardOnDemandProgram();
4294
4334
  const feedAccount = new on_demand_1.PullFeed(program, feed);
4295
4335
  if (!this.sbProgramFeedConfigs) {
@@ -4301,14 +4341,16 @@ class DriftClient {
4301
4341
  }
4302
4342
  const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
4303
4343
  numSignatures,
4304
- });
4344
+ }, recentSlothash
4345
+ ? [[new anchor_1.BN(recentSlothash.slot), recentSlothash.hash]]
4346
+ : undefined);
4305
4347
  if (!success) {
4306
4348
  return undefined;
4307
4349
  }
4308
4350
  return pullIx;
4309
4351
  }
4310
- async postSwitchboardOnDemandUpdate(feed, numSignatures = 3) {
4311
- const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures);
4352
+ async postSwitchboardOnDemandUpdate(feed, recentSlothash, numSignatures = 3) {
4353
+ const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures);
4312
4354
  if (!pullIx) {
4313
4355
  return undefined;
4314
4356
  }