@drift-labs/sdk 2.25.4 → 2.26.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 (90) hide show
  1. package/lib/accounts/pollingUserAccountSubscriber.d.ts +5 -4
  2. package/lib/accounts/pollingUserAccountSubscriber.js +35 -48
  3. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -4
  4. package/lib/accounts/pollingUserStatsAccountSubscriber.js +30 -47
  5. package/lib/accounts/types.d.ts +2 -1
  6. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
  7. package/lib/accounts/webSocketAccountSubscriber.js +4 -3
  8. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -0
  9. package/lib/accounts/webSocketUserAccountSubscriber.js +9 -0
  10. package/lib/addresses/pda.d.ts +2 -0
  11. package/lib/addresses/pda.js +8 -1
  12. package/lib/adminClient.d.ts +2 -0
  13. package/lib/adminClient.js +20 -0
  14. package/lib/constants/numericConstants.d.ts +61 -59
  15. package/lib/constants/spotMarkets.d.ts +1 -0
  16. package/lib/dlob/DLOB.d.ts +1 -0
  17. package/lib/dlob/DLOBApiClient.d.ts +14 -0
  18. package/lib/dlob/DLOBApiClient.js +34 -0
  19. package/lib/dlob/DLOBNode.d.ts +1 -0
  20. package/lib/dlob/DLOBSubscriber.d.ts +19 -0
  21. package/lib/dlob/DLOBSubscriber.js +42 -0
  22. package/lib/dlob/NodeList.d.ts +1 -0
  23. package/lib/dlob/types.d.ts +16 -0
  24. package/lib/dlob/types.js +2 -0
  25. package/lib/driftClient.d.ts +14 -10
  26. package/lib/driftClient.js +124 -28
  27. package/lib/examples/loadDlob.js +2 -4
  28. package/lib/factory/bigNum.d.ts +8 -7
  29. package/lib/idl/drift.json +264 -82
  30. package/lib/index.d.ts +2 -0
  31. package/lib/index.js +2 -0
  32. package/lib/math/amm.d.ts +2 -1
  33. package/lib/math/auction.d.ts +1 -0
  34. package/lib/math/conversion.d.ts +2 -1
  35. package/lib/math/funding.d.ts +1 -0
  36. package/lib/math/insurance.d.ts +1 -0
  37. package/lib/math/margin.d.ts +1 -0
  38. package/lib/math/market.d.ts +1 -0
  39. package/lib/math/oracles.d.ts +1 -0
  40. package/lib/math/orders.d.ts +1 -0
  41. package/lib/math/position.d.ts +1 -0
  42. package/lib/math/repeg.d.ts +1 -0
  43. package/lib/math/spotBalance.d.ts +1 -0
  44. package/lib/math/spotMarket.d.ts +1 -0
  45. package/lib/math/spotPosition.d.ts +1 -0
  46. package/lib/math/trade.d.ts +1 -0
  47. package/lib/math/utils.d.ts +1 -0
  48. package/lib/oracles/pythClient.d.ts +2 -1
  49. package/lib/oracles/types.d.ts +1 -0
  50. package/lib/orderParams.d.ts +1 -0
  51. package/lib/serum/serumSubscriber.d.ts +1 -0
  52. package/lib/slot/SlotSubscriber.js +3 -0
  53. package/lib/tokenFaucet.d.ts +1 -0
  54. package/lib/tx/retryTxSender.d.ts +2 -1
  55. package/lib/tx/retryTxSender.js +5 -1
  56. package/lib/tx/types.d.ts +4 -1
  57. package/lib/types.d.ts +12 -0
  58. package/lib/user.d.ts +1 -0
  59. package/lib/userMap/userMap.d.ts +17 -6
  60. package/lib/userMap/userMap.js +74 -46
  61. package/lib/userMap/userStatsMap.d.ts +6 -3
  62. package/lib/userMap/userStatsMap.js +30 -30
  63. package/package.json +2 -1
  64. package/src/accounts/pollingUserAccountSubscriber.ts +51 -63
  65. package/src/accounts/pollingUserStatsAccountSubscriber.ts +46 -62
  66. package/src/accounts/types.ts +2 -1
  67. package/src/accounts/webSocketAccountSubscriber.ts +4 -3
  68. package/src/accounts/webSocketUserAccountSubscriber.ts +10 -0
  69. package/src/addresses/pda.ts +13 -0
  70. package/src/adminClient.ts +34 -0
  71. package/src/dlob/DLOBApiClient.ts +37 -0
  72. package/src/dlob/DLOBSubscriber.ts +57 -0
  73. package/src/dlob/types.ts +20 -0
  74. package/src/driftClient.ts +216 -59
  75. package/src/examples/loadDlob.ts +2 -4
  76. package/src/idl/drift.json +264 -82
  77. package/src/index.ts +2 -0
  78. package/src/slot/SlotSubscriber.ts +4 -0
  79. package/src/tx/retryTxSender.ts +19 -2
  80. package/src/tx/types.ts +13 -0
  81. package/src/types.ts +12 -0
  82. package/src/userMap/userMap.ts +111 -60
  83. package/src/userMap/userStatsMap.ts +43 -44
  84. package/tests/dlob/helpers.ts +3 -1
  85. package/src/assert/assert.js +0 -9
  86. package/src/token/index.js +0 -38
  87. package/src/util/computeUnits.js +0 -27
  88. package/src/util/getTokenAddress.js +0 -9
  89. package/src/util/promiseTimeout.js +0 -14
  90. package/src/util/tps.js +0 -27
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { DataAndSlot, AccountToPoll, UserAccountEvents, UserAccountSubscriber } from './types';
2
+ import { DataAndSlot, UserAccountEvents, UserAccountSubscriber } from './types';
3
3
  import { Program } from '@coral-xyz/anchor';
4
4
  import StrictEventEmitter from 'strict-event-emitter-types';
5
5
  import { EventEmitter } from 'events';
@@ -12,16 +12,17 @@ export declare class PollingUserAccountSubscriber implements UserAccountSubscrib
12
12
  eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
13
13
  userAccountPublicKey: PublicKey;
14
14
  accountLoader: BulkAccountLoader;
15
- accountsToPoll: Map<string, AccountToPoll>;
15
+ callbackId?: string;
16
16
  errorCallbackId?: string;
17
17
  user?: DataAndSlot<UserAccount>;
18
18
  constructor(program: Program, userAccountPublicKey: PublicKey, accountLoader: BulkAccountLoader);
19
- subscribe(): Promise<boolean>;
19
+ subscribe(userAccount?: UserAccount): Promise<boolean>;
20
20
  addToAccountLoader(): Promise<void>;
21
21
  fetchIfUnloaded(): Promise<void>;
22
22
  fetch(): Promise<void>;
23
- doAccountsExist(): boolean;
23
+ doesAccountExist(): boolean;
24
24
  unsubscribe(): Promise<void>;
25
25
  assertIsSubscribed(): void;
26
26
  getUserAccountAndSlot(): DataAndSlot<UserAccount>;
27
+ updateData(userAccount: UserAccount, slot: number): void;
27
28
  }
@@ -3,95 +3,75 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PollingUserAccountSubscriber = void 0;
4
4
  const types_1 = require("./types");
5
5
  const events_1 = require("events");
6
- const utils_1 = require("./utils");
7
6
  class PollingUserAccountSubscriber {
8
7
  constructor(program, userAccountPublicKey, accountLoader) {
9
- this.accountsToPoll = new Map();
10
8
  this.isSubscribed = false;
11
9
  this.program = program;
12
10
  this.accountLoader = accountLoader;
13
11
  this.eventEmitter = new events_1.EventEmitter();
14
12
  this.userAccountPublicKey = userAccountPublicKey;
15
13
  }
16
- async subscribe() {
14
+ async subscribe(userAccount) {
17
15
  if (this.isSubscribed) {
18
16
  return true;
19
17
  }
18
+ if (userAccount) {
19
+ this.user = { data: userAccount, slot: undefined };
20
+ }
20
21
  await this.addToAccountLoader();
21
22
  await this.fetchIfUnloaded();
22
- if (this.doAccountsExist()) {
23
+ if (this.doesAccountExist()) {
23
24
  this.eventEmitter.emit('update');
24
25
  }
25
26
  this.isSubscribed = true;
26
27
  return true;
27
28
  }
28
29
  async addToAccountLoader() {
29
- if (this.accountsToPoll.size > 0) {
30
+ if (this.callbackId) {
30
31
  return;
31
32
  }
32
- this.accountsToPoll.set(this.userAccountPublicKey.toString(), {
33
- key: 'user',
34
- publicKey: this.userAccountPublicKey,
35
- eventType: 'userAccountUpdate',
33
+ this.callbackId = await this.accountLoader.addAccount(this.userAccountPublicKey, (buffer, slot) => {
34
+ if (!buffer) {
35
+ return;
36
+ }
37
+ if (this.user && this.user.slot > slot) {
38
+ return;
39
+ }
40
+ const account = this.program.account.user.coder.accounts.decode('User', buffer);
41
+ this.user = { data: account, slot };
42
+ this.eventEmitter.emit('userAccountUpdate', account);
43
+ this.eventEmitter.emit('update');
36
44
  });
37
- for (const [_, accountToPoll] of this.accountsToPoll) {
38
- accountToPoll.callbackId = await this.accountLoader.addAccount(accountToPoll.publicKey, (buffer, slot) => {
39
- if (!buffer) {
40
- return;
41
- }
42
- const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
43
- this[accountToPoll.key] = { data: account, slot };
44
- // @ts-ignore
45
- this.eventEmitter.emit(accountToPoll.eventType, account);
46
- this.eventEmitter.emit('update');
47
- });
48
- }
49
45
  this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
50
46
  this.eventEmitter.emit('error', error);
51
47
  });
52
48
  }
53
49
  async fetchIfUnloaded() {
54
- let shouldFetch = false;
55
- for (const [_, accountToPoll] of this.accountsToPoll) {
56
- if (this[accountToPoll.key] === undefined) {
57
- shouldFetch = true;
58
- break;
59
- }
60
- }
61
- if (shouldFetch) {
50
+ if (this.user === undefined) {
62
51
  await this.fetch();
63
52
  }
64
53
  }
65
54
  async fetch() {
55
+ var _a, _b;
66
56
  await this.accountLoader.load();
67
- for (const [_, accountToPoll] of this.accountsToPoll) {
68
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
69
- if (buffer) {
70
- const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
71
- this[accountToPoll.key] = { data: account, slot };
72
- }
57
+ const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userAccountPublicKey);
58
+ const currentSlot = (_b = (_a = this.user) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
59
+ if (buffer && slot > currentSlot) {
60
+ const account = this.program.account.user.coder.accounts.decode('User', buffer);
61
+ this.user = { data: account, slot };
73
62
  }
74
63
  }
75
- doAccountsExist() {
76
- let success = true;
77
- for (const [_, accountToPoll] of this.accountsToPoll) {
78
- if (!this[accountToPoll.key]) {
79
- success = false;
80
- break;
81
- }
82
- }
83
- return success;
64
+ doesAccountExist() {
65
+ return this.user !== undefined;
84
66
  }
85
67
  async unsubscribe() {
86
68
  if (!this.isSubscribed) {
87
69
  return;
88
70
  }
89
- for (const [_, accountToPoll] of this.accountsToPoll) {
90
- this.accountLoader.removeAccount(accountToPoll.publicKey, accountToPoll.callbackId);
91
- }
71
+ this.accountLoader.removeAccount(this.userAccountPublicKey, this.callbackId);
72
+ this.callbackId = undefined;
92
73
  this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
93
74
  this.errorCallbackId = undefined;
94
- this.accountsToPoll.clear();
95
75
  this.isSubscribed = false;
96
76
  }
97
77
  assertIsSubscribed() {
@@ -103,5 +83,12 @@ class PollingUserAccountSubscriber {
103
83
  this.assertIsSubscribed();
104
84
  return this.user;
105
85
  }
86
+ updateData(userAccount, slot) {
87
+ if (!this.user || this.user.slot < slot) {
88
+ this.user = { data: userAccount, slot };
89
+ this.eventEmitter.emit('userAccountUpdate', userAccount);
90
+ this.eventEmitter.emit('update');
91
+ }
92
+ }
106
93
  }
107
94
  exports.PollingUserAccountSubscriber = PollingUserAccountSubscriber;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { DataAndSlot, AccountToPoll, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
2
+ import { DataAndSlot, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
3
3
  import { Program } from '@coral-xyz/anchor';
4
4
  import StrictEventEmitter from 'strict-event-emitter-types';
5
5
  import { EventEmitter } from 'events';
@@ -12,15 +12,15 @@ export declare class PollingUserStatsAccountSubscriber implements UserStatsAccou
12
12
  eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
13
13
  userStatsAccountPublicKey: PublicKey;
14
14
  accountLoader: BulkAccountLoader;
15
- accountsToPoll: Map<string, AccountToPoll>;
15
+ callbackId?: string;
16
16
  errorCallbackId?: string;
17
17
  userStats?: DataAndSlot<UserStatsAccount>;
18
18
  constructor(program: Program, userStatsAccountPublicKey: PublicKey, accountLoader: BulkAccountLoader);
19
- subscribe(): Promise<boolean>;
19
+ subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
20
20
  addToAccountLoader(): Promise<void>;
21
21
  fetchIfUnloaded(): Promise<void>;
22
22
  fetch(): Promise<void>;
23
- doAccountsExist(): boolean;
23
+ doesAccountExist(): boolean;
24
24
  unsubscribe(): Promise<void>;
25
25
  assertIsSubscribed(): void;
26
26
  getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
@@ -3,92 +3,75 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PollingUserStatsAccountSubscriber = void 0;
4
4
  const types_1 = require("./types");
5
5
  const events_1 = require("events");
6
- const utils_1 = require("./utils");
7
6
  class PollingUserStatsAccountSubscriber {
8
7
  constructor(program, userStatsAccountPublicKey, accountLoader) {
9
- this.accountsToPoll = new Map();
10
8
  this.isSubscribed = false;
11
9
  this.program = program;
12
10
  this.accountLoader = accountLoader;
13
11
  this.eventEmitter = new events_1.EventEmitter();
14
12
  this.userStatsAccountPublicKey = userStatsAccountPublicKey;
15
13
  }
16
- async subscribe() {
14
+ async subscribe(userStatsAccount) {
17
15
  if (this.isSubscribed) {
18
16
  return true;
19
17
  }
18
+ if (userStatsAccount) {
19
+ this.userStats = { data: userStatsAccount, slot: undefined };
20
+ }
20
21
  await this.addToAccountLoader();
21
22
  await this.fetchIfUnloaded();
22
- if (this.doAccountsExist()) {
23
+ if (this.doesAccountExist()) {
23
24
  this.eventEmitter.emit('update');
24
25
  }
25
26
  this.isSubscribed = true;
26
27
  return true;
27
28
  }
28
29
  async addToAccountLoader() {
29
- if (this.accountsToPoll.size > 0) {
30
+ if (this.callbackId !== undefined) {
30
31
  return;
31
32
  }
32
- this.accountsToPoll.set(this.userStatsAccountPublicKey.toString(), {
33
- key: 'userStats',
34
- publicKey: this.userStatsAccountPublicKey,
35
- eventType: 'userStatsAccountUpdate',
33
+ this.callbackId = await this.accountLoader.addAccount(this.userStatsAccountPublicKey, (buffer, slot) => {
34
+ if (!buffer) {
35
+ return;
36
+ }
37
+ if (this.userStats && this.userStats.slot > slot) {
38
+ return;
39
+ }
40
+ const account = this.program.account.userStats.coder.accounts.decode('UserStats', buffer);
41
+ this.userStats = { data: account, slot };
42
+ this.eventEmitter.emit('userStatsAccountUpdate', account);
43
+ this.eventEmitter.emit('update');
36
44
  });
37
- for (const [_, accountToPoll] of this.accountsToPoll) {
38
- accountToPoll.callbackId = await this.accountLoader.addAccount(accountToPoll.publicKey, (buffer, slot) => {
39
- if (!buffer) {
40
- return;
41
- }
42
- const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
43
- this[accountToPoll.key] = { data: account, slot };
44
- // @ts-ignore
45
- this.eventEmitter.emit(accountToPoll.eventType, account);
46
- this.eventEmitter.emit('update');
47
- });
48
- }
49
45
  this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
50
46
  this.eventEmitter.emit('error', error);
51
47
  });
52
48
  }
53
49
  async fetchIfUnloaded() {
54
- let shouldFetch = false;
55
- for (const [_, accountToPoll] of this.accountsToPoll) {
56
- if (this[accountToPoll.key] === undefined) {
57
- shouldFetch = true;
58
- break;
59
- }
60
- }
61
- if (shouldFetch) {
50
+ if (this.userStats === undefined) {
62
51
  await this.fetch();
63
52
  }
64
53
  }
65
54
  async fetch() {
55
+ var _a, _b;
66
56
  await this.accountLoader.load();
67
- for (const [_, accountToPoll] of this.accountsToPoll) {
68
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
69
- if (buffer) {
70
- const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
71
- this[accountToPoll.key] = { data: account, slot };
72
- }
57
+ const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userStatsAccountPublicKey);
58
+ const currentSlot = (_b = (_a = this.userStats) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
59
+ if (buffer && slot > currentSlot) {
60
+ const account = this.program.account.userStats.coder.accounts.decode('UserStats', buffer);
61
+ this.userStats = { data: account, slot };
73
62
  }
74
63
  }
75
- doAccountsExist() {
76
- let success = true;
77
- for (const [_, accountToPoll] of this.accountsToPoll) {
78
- if (!this[accountToPoll.key]) {
79
- success = false;
80
- break;
81
- }
82
- }
83
- return success;
64
+ doesAccountExist() {
65
+ return this.userStats !== undefined;
84
66
  }
85
67
  async unsubscribe() {
86
- for (const [_, accountToPoll] of this.accountsToPoll) {
87
- this.accountLoader.removeAccount(accountToPoll.publicKey, accountToPoll.callbackId);
68
+ if (!this.isSubscribed) {
69
+ return;
88
70
  }
71
+ this.accountLoader.removeAccount(this.userStatsAccountPublicKey, this.callbackId);
72
+ this.callbackId = undefined;
89
73
  this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
90
74
  this.errorCallbackId = undefined;
91
- this.accountsToPoll.clear();
92
75
  this.isSubscribed = false;
93
76
  }
94
77
  assertIsSubscribed() {
@@ -11,7 +11,7 @@ export interface AccountSubscriber<T> {
11
11
  subscribe(onChange: (data: T) => void): Promise<void>;
12
12
  fetch(): Promise<void>;
13
13
  unsubscribe(): Promise<void>;
14
- setData(userAccount: T): void;
14
+ setData(userAccount: T, slot?: number): void;
15
15
  }
16
16
  export declare class NotSubscribedError extends Error {
17
17
  name: string;
@@ -51,6 +51,7 @@ export interface UserAccountSubscriber {
51
51
  isSubscribed: boolean;
52
52
  subscribe(userAccount?: UserAccount): Promise<boolean>;
53
53
  fetch(): Promise<void>;
54
+ updateData(userAccount: UserAccount, slot: number): void;
54
55
  unsubscribe(): Promise<void>;
55
56
  getUserAccountAndSlot(): DataAndSlot<UserAccount>;
56
57
  }
@@ -13,7 +13,7 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
13
13
  listenerId?: number;
14
14
  constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T);
15
15
  subscribe(onChange: (data: T) => void): Promise<void>;
16
- setData(data: T): void;
16
+ setData(data: T, slot?: number): void;
17
17
  fetch(): Promise<void>;
18
18
  handleRpcResponse(context: Context, accountInfo?: AccountInfo<Buffer>): void;
19
19
  decodeBuffer(buffer: Buffer): T;
@@ -21,13 +21,14 @@ class WebSocketAccountSubscriber {
21
21
  this.handleRpcResponse(context, accountInfo);
22
22
  }, this.program.provider.opts.commitment);
23
23
  }
24
- setData(data) {
25
- if (this.dataAndSlot) {
24
+ setData(data, slot) {
25
+ const newSlot = slot || 0;
26
+ if (this.dataAndSlot && this.dataAndSlot.slot > newSlot) {
26
27
  return;
27
28
  }
28
29
  this.dataAndSlot = {
29
30
  data,
30
- slot: undefined,
31
+ slot,
31
32
  };
32
33
  }
33
34
  async fetch() {
@@ -17,4 +17,5 @@ export declare class WebSocketUserAccountSubscriber implements UserAccountSubscr
17
17
  unsubscribe(): Promise<void>;
18
18
  assertIsSubscribed(): void;
19
19
  getUserAccountAndSlot(): DataAndSlot<UserAccount>;
20
+ updateData(userAccount: UserAccount, slot: number): void;
20
21
  }
@@ -46,5 +46,14 @@ class WebSocketUserAccountSubscriber {
46
46
  this.assertIsSubscribed();
47
47
  return this.userDataAccountSubscriber.dataAndSlot;
48
48
  }
49
+ updateData(userAccount, slot) {
50
+ var _a;
51
+ const currentDataSlot = ((_a = this.userDataAccountSubscriber.dataAndSlot) === null || _a === void 0 ? void 0 : _a.slot) || 0;
52
+ if (currentDataSlot < slot) {
53
+ this.userDataAccountSubscriber.setData(userAccount, slot);
54
+ this.eventEmitter.emit('userAccountUpdate', userAccount);
55
+ this.eventEmitter.emit('update');
56
+ }
57
+ }
49
58
  }
50
59
  exports.WebSocketUserAccountSubscriber = WebSocketUserAccountSubscriber;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
@@ -15,4 +16,5 @@ export declare function getDriftSignerPublicKey(programId: PublicKey): PublicKey
15
16
  export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
16
17
  export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
17
18
  export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
19
+ export declare function getPhoenixFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
18
20
  export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameBuffer: number[]): 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.getReferrerNamePublicKeySync = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getReferrerNamePublicKeySync = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = 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
  async function getDriftStateAccountPublicKeyAndNonce(programId) {
@@ -119,6 +119,13 @@ function getSerumFulfillmentConfigPublicKey(programId, market) {
119
119
  ], programId)[0];
120
120
  }
121
121
  exports.getSerumFulfillmentConfigPublicKey = getSerumFulfillmentConfigPublicKey;
122
+ function getPhoenixFulfillmentConfigPublicKey(programId, market) {
123
+ return web3_js_1.PublicKey.findProgramAddressSync([
124
+ Buffer.from(anchor.utils.bytes.utf8.encode('phoenix_fulfillment_config')),
125
+ market.toBuffer(),
126
+ ], programId)[0];
127
+ }
128
+ exports.getPhoenixFulfillmentConfigPublicKey = getPhoenixFulfillmentConfigPublicKey;
122
129
  function getReferrerNamePublicKeySync(programId, nameBuffer) {
123
130
  return web3_js_1.PublicKey.findProgramAddressSync([
124
131
  Buffer.from(anchor.utils.bytes.utf8.encode('referrer_name')),
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey, TransactionSignature } from '@solana/web3.js';
2
3
  import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
3
4
  import { BN } from '@coral-xyz/anchor';
@@ -6,6 +7,7 @@ export declare class AdminClient extends DriftClient {
6
7
  initialize(usdcMint: PublicKey, _adminControlsPrices: boolean): Promise<[TransactionSignature]>;
7
8
  initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
8
9
  initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
10
+ initializePhoenixFulfillmentConfig(marketIndex: number, phoenixMarket: PublicKey): Promise<TransactionSignature>;
9
11
  initializePerpMarket(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
10
12
  deleteInitializedPerpMarket(marketIndex: number): Promise<TransactionSignature>;
11
13
  moveAmmPrice(perpMarketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
@@ -36,6 +36,7 @@ const driftClient_1 = require("./driftClient");
36
36
  const numericConstants_1 = require("./constants/numericConstants");
37
37
  const trade_1 = require("./math/trade");
38
38
  const amm_1 = require("./math/amm");
39
+ const phoenix_sdk_1 = require("@ellipsis-labs/phoenix-sdk");
39
40
  class AdminClient extends driftClient_1.DriftClient {
40
41
  async initialize(usdcMint, _adminControlsPrices) {
41
42
  const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
@@ -107,6 +108,25 @@ class AdminClient extends driftClient_1.DriftClient {
107
108
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
108
109
  return txSig;
109
110
  }
111
+ async initializePhoenixFulfillmentConfig(marketIndex, phoenixMarket) {
112
+ const phoenixFulfillmentConfig = (0, pda_1.getPhoenixFulfillmentConfigPublicKey)(this.program.programId, phoenixMarket);
113
+ const tx = await this.program.transaction.initializePhoenixFulfillmentConfig(marketIndex, {
114
+ accounts: {
115
+ admin: this.wallet.publicKey,
116
+ state: await this.getStatePublicKey(),
117
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
118
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
119
+ driftSigner: this.getSignerPublicKey(),
120
+ phoenixMarket: phoenixMarket,
121
+ phoenixProgram: phoenix_sdk_1.PROGRAM_ID,
122
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
123
+ systemProgram: anchor.web3.SystemProgram.programId,
124
+ phoenixFulfillmentConfig,
125
+ },
126
+ });
127
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
128
+ return txSig;
129
+ }
110
130
  async initializePerpMarket(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
111
131
  const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
112
132
  const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, currentPerpMarketIndex);
@@ -1,60 +1,62 @@
1
- export declare const ZERO: any;
2
- export declare const ONE: any;
3
- export declare const TWO: any;
4
- export declare const THREE: any;
5
- export declare const FOUR: any;
6
- export declare const FIVE: any;
7
- export declare const SIX: any;
8
- export declare const SEVEN: any;
9
- export declare const EIGHT: any;
10
- export declare const NINE: any;
11
- export declare const TEN: any;
12
- export declare const TEN_THOUSAND: any;
13
- export declare const BN_MAX: any;
14
- export declare const TEN_MILLION: any;
15
- export declare const MAX_LEVERAGE: any;
16
- export declare const MAX_LEVERAGE_ORDER_SIZE: any;
17
- export declare const PERCENTAGE_PRECISION_EXP: any;
18
- export declare const PERCENTAGE_PRECISION: any;
19
- export declare const CONCENTRATION_PRECISION: any;
20
- export declare const QUOTE_PRECISION_EXP: any;
21
- export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: any;
22
- export declare const PRICE_PRECISION_EXP: any;
23
- export declare const FUNDING_RATE_PRECISION_EXP: any;
24
- export declare const PEG_PRECISION_EXP: any;
25
- export declare const AMM_RESERVE_PRECISION_EXP: any;
26
- export declare const SPOT_MARKET_RATE_PRECISION_EXP: any;
27
- export declare const SPOT_MARKET_RATE_PRECISION: any;
28
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: any;
29
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: any;
30
- export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: any;
31
- export declare const SPOT_MARKET_UTILIZATION_PRECISION: any;
32
- export declare const SPOT_MARKET_WEIGHT_PRECISION: any;
33
- export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: any;
34
- export declare const SPOT_MARKET_BALANCE_PRECISION: any;
35
- export declare const SPOT_MARKET_IMF_PRECISION_EXP: any;
36
- export declare const SPOT_MARKET_IMF_PRECISION: any;
37
- export declare const LIQUIDATION_FEE_PRECISION: any;
38
- export declare const QUOTE_PRECISION: any;
39
- export declare const PRICE_PRECISION: any;
40
- export declare const FUNDING_RATE_PRECISION: any;
41
- export declare const FUNDING_RATE_BUFFER_PRECISION: any;
42
- export declare const PEG_PRECISION: any;
43
- export declare const AMM_RESERVE_PRECISION: any;
44
- export declare const BASE_PRECISION: any;
45
- export declare const BASE_PRECISION_EXP: any;
46
- export declare const AMM_TO_QUOTE_PRECISION_RATIO: any;
47
- export declare const PRICE_DIV_PEG: any;
48
- export declare const PRICE_TO_QUOTE_PRECISION: any;
49
- export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: any;
50
- export declare const MARGIN_PRECISION: any;
51
- export declare const BID_ASK_SPREAD_PRECISION: any;
52
- export declare const LIQUIDATION_PCT_PRECISION: any;
53
- export declare const FIVE_MINUTE: any;
54
- export declare const ONE_HOUR: any;
55
- export declare const ONE_YEAR: any;
1
+ /// <reference types="bn.js" />
2
+ import { BN } from '../';
3
+ export declare const ZERO: BN;
4
+ export declare const ONE: BN;
5
+ export declare const TWO: BN;
6
+ export declare const THREE: BN;
7
+ export declare const FOUR: BN;
8
+ export declare const FIVE: BN;
9
+ export declare const SIX: BN;
10
+ export declare const SEVEN: BN;
11
+ export declare const EIGHT: BN;
12
+ export declare const NINE: BN;
13
+ export declare const TEN: BN;
14
+ export declare const TEN_THOUSAND: BN;
15
+ export declare const BN_MAX: BN;
16
+ export declare const TEN_MILLION: BN;
17
+ export declare const MAX_LEVERAGE: BN;
18
+ export declare const MAX_LEVERAGE_ORDER_SIZE: BN;
19
+ export declare const PERCENTAGE_PRECISION_EXP: BN;
20
+ export declare const PERCENTAGE_PRECISION: BN;
21
+ export declare const CONCENTRATION_PRECISION: BN;
22
+ export declare const QUOTE_PRECISION_EXP: BN;
23
+ export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
24
+ export declare const PRICE_PRECISION_EXP: BN;
25
+ export declare const FUNDING_RATE_PRECISION_EXP: BN;
26
+ export declare const PEG_PRECISION_EXP: BN;
27
+ export declare const AMM_RESERVE_PRECISION_EXP: BN;
28
+ export declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
29
+ export declare const SPOT_MARKET_RATE_PRECISION: BN;
30
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: BN;
31
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: BN;
32
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
33
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
34
+ export declare const SPOT_MARKET_WEIGHT_PRECISION: BN;
35
+ export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: BN;
36
+ export declare const SPOT_MARKET_BALANCE_PRECISION: BN;
37
+ export declare const SPOT_MARKET_IMF_PRECISION_EXP: BN;
38
+ export declare const SPOT_MARKET_IMF_PRECISION: BN;
39
+ export declare const LIQUIDATION_FEE_PRECISION: BN;
40
+ export declare const QUOTE_PRECISION: BN;
41
+ export declare const PRICE_PRECISION: BN;
42
+ export declare const FUNDING_RATE_PRECISION: BN;
43
+ export declare const FUNDING_RATE_BUFFER_PRECISION: BN;
44
+ export declare const PEG_PRECISION: BN;
45
+ export declare const AMM_RESERVE_PRECISION: BN;
46
+ export declare const BASE_PRECISION: BN;
47
+ export declare const BASE_PRECISION_EXP: BN;
48
+ export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
49
+ export declare const PRICE_DIV_PEG: BN;
50
+ export declare const PRICE_TO_QUOTE_PRECISION: BN;
51
+ export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
52
+ export declare const MARGIN_PRECISION: BN;
53
+ export declare const BID_ASK_SPREAD_PRECISION: BN;
54
+ export declare const LIQUIDATION_PCT_PRECISION: BN;
55
+ export declare const FIVE_MINUTE: BN;
56
+ export declare const ONE_HOUR: BN;
57
+ export declare const ONE_YEAR: BN;
56
58
  export declare const QUOTE_SPOT_MARKET_INDEX = 0;
57
- export declare const LAMPORTS_PRECISION: any;
58
- export declare const LAMPORTS_EXP: any;
59
- export declare const OPEN_ORDER_MARGIN_REQUIREMENT: any;
60
- export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: any;
59
+ export declare const LAMPORTS_PRECISION: BN;
60
+ export declare const LAMPORTS_EXP: BN;
61
+ export declare const OPEN_ORDER_MARGIN_REQUIREMENT: BN;
62
+ export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { BN, DriftEnv, OracleSource } from '../';
3
4
  export type SpotMarketConfig = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { NodeList } from './NodeList';
2
3
  import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, MarketTypeStr, StateAccount, UserMap, OrderRecord, OrderActionRecord } from '..';
3
4
  import { PublicKey } from '@solana/web3.js';
@@ -0,0 +1,14 @@
1
+ import { DLOBOrdersCoder } from './DLOBOrders';
2
+ import { DLOB } from './DLOB';
3
+ type DLOBApiClientConfig = {
4
+ url: string;
5
+ };
6
+ export declare class DLOBApiClient {
7
+ url: string;
8
+ dlobCoder: DLOBOrdersCoder;
9
+ lastSeenDLOB: DLOB;
10
+ lastSeenSlot: number;
11
+ constructor(config: DLOBApiClientConfig);
12
+ getDLOB(slot: number): Promise<DLOB>;
13
+ }
14
+ export {};