@drift-labs/sdk 0.2.0-master.37 → 0.2.0-master.39

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 (75) hide show
  1. package/README.md +14 -14
  2. package/lib/accounts/bulkUserStatsSubscription.d.ts +2 -2
  3. package/lib/accounts/bulkUserSubscription.d.ts +2 -2
  4. package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +3 -8
  5. package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +6 -13
  6. package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
  7. package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
  8. package/lib/accounts/types.d.ts +4 -4
  9. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.d.ts → webSocketDriftClientAccountSubscriber.d.ts} +3 -3
  10. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +4 -4
  11. package/lib/addresses/pda.d.ts +3 -3
  12. package/lib/addresses/pda.js +10 -10
  13. package/lib/{admin.d.ts → adminClient.d.ts} +12 -4
  14. package/lib/{admin.js → adminClient.js} +89 -15
  15. package/lib/config.js +1 -1
  16. package/lib/constants/numericConstants.d.ts +3 -0
  17. package/lib/constants/numericConstants.js +5 -2
  18. package/lib/dlob/DLOB.d.ts +2 -2
  19. package/lib/dlob/DLOB.js +4 -4
  20. package/lib/{clearingHouse.d.ts → driftClient.d.ts} +21 -20
  21. package/lib/{clearingHouse.js → driftClient.js} +48 -37
  22. package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +3 -3
  23. package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
  24. package/lib/examples/makeTradeExample.js +13 -13
  25. package/lib/idl/{clearing_house.json → drift.json} +717 -143
  26. package/lib/index.d.ts +10 -10
  27. package/lib/index.js +10 -10
  28. package/lib/math/orders.d.ts +4 -4
  29. package/lib/math/orders.js +3 -3
  30. package/lib/serum/serumFulfillmentConfigMap.d.ts +3 -3
  31. package/lib/serum/serumFulfillmentConfigMap.js +3 -3
  32. package/lib/types.d.ts +38 -2
  33. package/lib/types.js +2 -1
  34. package/lib/{clearingHouseUser.d.ts → user.d.ts} +16 -10
  35. package/lib/{clearingHouseUser.js → user.js} +54 -46
  36. package/lib/userConfig.d.ts +14 -0
  37. package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
  38. package/lib/userMap/userMap.d.ts +17 -17
  39. package/lib/userMap/userMap.js +15 -15
  40. package/lib/userMap/userStatsMap.d.ts +7 -7
  41. package/lib/userMap/userStatsMap.js +10 -10
  42. package/lib/{clearingHouseUserStats.d.ts → userStats.d.ts} +5 -5
  43. package/lib/{clearingHouseUserStats.js → userStats.js} +8 -8
  44. package/lib/userStatsConfig.d.ts +14 -0
  45. package/lib/{clearingHouseUserStatsConfig.js → userStatsConfig.js} +0 -0
  46. package/package.json +1 -1
  47. package/src/accounts/bulkUserStatsSubscription.ts +2 -2
  48. package/src/accounts/bulkUserSubscription.ts +2 -2
  49. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +11 -25
  50. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  51. package/src/accounts/types.ts +4 -4
  52. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +7 -7
  53. package/src/addresses/pda.ts +6 -8
  54. package/src/{admin.ts → adminClient.ts} +185 -18
  55. package/src/config.ts +1 -1
  56. package/src/constants/numericConstants.ts +4 -0
  57. package/src/dlob/DLOB.ts +5 -5
  58. package/src/{clearingHouse.ts → driftClient.ts} +85 -68
  59. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +3 -3
  60. package/src/examples/makeTradeExample.ts +15 -17
  61. package/src/idl/{clearing_house.json → drift.json} +717 -143
  62. package/src/index.ts +10 -10
  63. package/src/math/orders.ts +7 -13
  64. package/src/serum/serumFulfillmentConfigMap.ts +5 -5
  65. package/src/types.ts +41 -2
  66. package/src/{clearingHouseUser.ts → user.ts} +60 -54
  67. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  68. package/src/userMap/userMap.ts +29 -29
  69. package/src/userMap/userStatsMap.ts +21 -23
  70. package/src/{clearingHouseUserStats.ts → userStats.ts} +10 -10
  71. package/src/userStatsConfig.ts +18 -0
  72. package/tests/dlob/helpers.ts +55 -13
  73. package/lib/clearingHouseUserConfig.d.ts +0 -14
  74. package/lib/clearingHouseUserStatsConfig.d.ts +0 -14
  75. package/src/clearingHouseUserStatsConfig.ts +0 -18
@@ -1,10 +1,10 @@
1
1
  import {
2
- ClearingHouseUser,
3
- ClearingHouse,
2
+ User,
3
+ DriftClient,
4
4
  UserAccount,
5
5
  bulkPollingUserSubscribe,
6
6
  OrderRecord,
7
- ClearingHouseUserAccountSubscriptionConfig,
7
+ UserSubscriptionConfig,
8
8
  } from '..';
9
9
  import { ProgramAccount } from '@project-serum/anchor';
10
10
 
@@ -14,38 +14,38 @@ export interface UserMapInterface {
14
14
  fetchAllUsers(): Promise<void>;
15
15
  addPubkey(userAccountPublicKey: PublicKey): Promise<void>;
16
16
  has(key: string): boolean;
17
- get(key: string): ClearingHouseUser | undefined;
18
- mustGet(key: string): Promise<ClearingHouseUser>;
17
+ get(key: string): User | undefined;
18
+ mustGet(key: string): Promise<User>;
19
19
  getUserAuthority(key: string): PublicKey | undefined;
20
20
  updateWithOrderRecord(record: OrderRecord): Promise<void>;
21
- values(): IterableIterator<ClearingHouseUser>;
21
+ values(): IterableIterator<User>;
22
22
  }
23
23
 
24
24
  export class UserMap implements UserMapInterface {
25
- private userMap = new Map<string, ClearingHouseUser>();
26
- private clearingHouse: ClearingHouse;
27
- private accountSubscription: ClearingHouseUserAccountSubscriptionConfig;
25
+ private userMap = new Map<string, User>();
26
+ private driftClient: DriftClient;
27
+ private accountSubscription: UserSubscriptionConfig;
28
28
 
29
29
  constructor(
30
- clearingHouse: ClearingHouse,
31
- accountSubscription: ClearingHouseUserAccountSubscriptionConfig
30
+ driftClient: DriftClient,
31
+ accountSubscription: UserSubscriptionConfig
32
32
  ) {
33
- this.clearingHouse = clearingHouse;
33
+ this.driftClient = driftClient;
34
34
  this.accountSubscription = accountSubscription;
35
35
  }
36
36
 
37
37
  public async fetchAllUsers() {
38
- const userArray: ClearingHouseUser[] = [];
38
+ const userArray: User[] = [];
39
39
 
40
40
  const programUserAccounts =
41
- (await this.clearingHouse.program.account.user.all()) as ProgramAccount<UserAccount>[];
41
+ (await this.driftClient.program.account.user.all()) as ProgramAccount<UserAccount>[];
42
42
  for (const programUserAccount of programUserAccounts) {
43
43
  if (this.userMap.has(programUserAccount.publicKey.toString())) {
44
44
  continue;
45
45
  }
46
46
 
47
- const user = new ClearingHouseUser({
48
- clearingHouse: this.clearingHouse,
47
+ const user = new User({
48
+ driftClient: this.driftClient,
49
49
  userAccountPublicKey: programUserAccount.publicKey,
50
50
  accountSubscription: this.accountSubscription,
51
51
  });
@@ -65,8 +65,8 @@ export class UserMap implements UserMapInterface {
65
65
  }
66
66
 
67
67
  public async addPubkey(userAccountPublicKey: PublicKey) {
68
- const user = new ClearingHouseUser({
69
- clearingHouse: this.clearingHouse,
68
+ const user = new User({
69
+ driftClient: this.driftClient,
70
70
  userAccountPublicKey,
71
71
  accountSubscription: this.accountSubscription,
72
72
  });
@@ -79,20 +79,20 @@ export class UserMap implements UserMapInterface {
79
79
  }
80
80
 
81
81
  /**
82
- * gets the ClearingHouseUser for a particular userAccountPublicKey, if no ClearingHouseUser exists, undefined is returned
83
- * @param key userAccountPublicKey to get ClearngHouseUserFor
84
- * @returns user ClearingHouseUser | undefined
82
+ * gets the User for a particular userAccountPublicKey, if no User exists, undefined is returned
83
+ * @param key userAccountPublicKey to get User for
84
+ * @returns user User | undefined
85
85
  */
86
- public get(key: string): ClearingHouseUser | undefined {
86
+ public get(key: string): User | undefined {
87
87
  return this.userMap.get(key);
88
88
  }
89
89
 
90
90
  /**
91
- * gets the ClearingHouseUser for a particular userAccountPublicKey, if no ClearingHouseUser exists, new one is created
92
- * @param key userAccountPublicKey to get ClearngHouseUserFor
93
- * @returns ClearingHouseUser
91
+ * gets the User for a particular userAccountPublicKey, if no User exists, new one is created
92
+ * @param key userAccountPublicKey to get User for
93
+ * @returns User
94
94
  */
95
- public async mustGet(key: string): Promise<ClearingHouseUser> {
95
+ public async mustGet(key: string): Promise<User> {
96
96
  if (!this.has(key)) {
97
97
  await this.addPubkey(new PublicKey(key));
98
98
  }
@@ -102,8 +102,8 @@ export class UserMap implements UserMapInterface {
102
102
  }
103
103
 
104
104
  /**
105
- * gets the Authority for a particular userAccountPublicKey, if no ClearingHouseUser exists, undefined is returned
106
- * @param key userAccountPublicKey to get ClearngHouseUserFor
105
+ * gets the Authority for a particular userAccountPublicKey, if no User exists, undefined is returned
106
+ * @param key userAccountPublicKey to get User for
107
107
  * @returns authority PublicKey | undefined
108
108
  */
109
109
  public getUserAuthority(key: string): PublicKey | undefined {
@@ -118,7 +118,7 @@ export class UserMap implements UserMapInterface {
118
118
  await this.addPubkey(record.user);
119
119
  }
120
120
 
121
- public values(): IterableIterator<ClearingHouseUser> {
121
+ public values(): IterableIterator<User> {
122
122
  return this.userMap.values();
123
123
  }
124
124
  }
@@ -1,10 +1,10 @@
1
1
  import {
2
- ClearingHouse,
2
+ DriftClient,
3
3
  getUserStatsAccountPublicKey,
4
4
  OrderRecord,
5
5
  UserStatsAccount,
6
- ClearingHouseUserStats,
7
- ClearingHouseUserStatsAccountSubscriptionConfig,
6
+ UserStats,
7
+ UserStatsSubscriptionConfig,
8
8
  bulkPollingUserStatsSubscribe,
9
9
  } from '..';
10
10
  import { ProgramAccount } from '@project-serum/anchor';
@@ -14,25 +14,25 @@ import { UserMap } from './userMap';
14
14
 
15
15
  export class UserStatsMap {
16
16
  /**
17
- * map from authority pubkey to ClearingHouseUserStats
17
+ * map from authority pubkey to UserStats
18
18
  */
19
- private userStatsMap = new Map<string, ClearingHouseUserStats>();
20
- private clearingHouse: ClearingHouse;
21
- private accountSubscription: ClearingHouseUserStatsAccountSubscriptionConfig;
19
+ private userStatsMap = new Map<string, UserStats>();
20
+ private driftClient: DriftClient;
21
+ private accountSubscription: UserStatsSubscriptionConfig;
22
22
 
23
23
  constructor(
24
- clearingHouse: ClearingHouse,
25
- accountSubscription: ClearingHouseUserStatsAccountSubscriptionConfig
24
+ driftClient: DriftClient,
25
+ accountSubscription: UserStatsSubscriptionConfig
26
26
  ) {
27
- this.clearingHouse = clearingHouse;
27
+ this.driftClient = driftClient;
28
28
  this.accountSubscription = accountSubscription;
29
29
  }
30
30
 
31
31
  public async fetchAllUserStats() {
32
- const userStatArray: ClearingHouseUserStats[] = [];
32
+ const userStatArray: UserStats[] = [];
33
33
 
34
34
  const programUserAccounts =
35
- (await this.clearingHouse.program.account.userStats.all()) as ProgramAccount<UserStatsAccount>[];
35
+ (await this.driftClient.program.account.userStats.all()) as ProgramAccount<UserStatsAccount>[];
36
36
 
37
37
  for (const programUserAccount of programUserAccounts) {
38
38
  const userStat: UserStatsAccount = programUserAccount.account;
@@ -40,10 +40,10 @@ export class UserStatsMap {
40
40
  continue;
41
41
  }
42
42
 
43
- const chUserStat = new ClearingHouseUserStats({
44
- clearingHouse: this.clearingHouse,
43
+ const chUserStat = new UserStats({
44
+ driftClient: this.driftClient,
45
45
  userStatsAccountPublicKey: getUserStatsAccountPublicKey(
46
- this.clearingHouse.program.programId,
46
+ this.driftClient.program.programId,
47
47
  userStat.authority
48
48
  ),
49
49
  accountSubscription: this.accountSubscription,
@@ -67,10 +67,10 @@ export class UserStatsMap {
67
67
  }
68
68
 
69
69
  public async addUserStat(authority: PublicKey) {
70
- const userStat = new ClearingHouseUserStats({
71
- clearingHouse: this.clearingHouse,
70
+ const userStat = new UserStats({
71
+ driftClient: this.driftClient,
72
72
  userStatsAccountPublicKey: getUserStatsAccountPublicKey(
73
- this.clearingHouse.program.programId,
73
+ this.driftClient.program.programId,
74
74
  authority
75
75
  ),
76
76
  accountSubscription: this.accountSubscription,
@@ -91,20 +91,18 @@ export class UserStatsMap {
91
91
  return this.userStatsMap.has(authorityPublicKey);
92
92
  }
93
93
 
94
- public get(authorityPublicKey: string): ClearingHouseUserStats {
94
+ public get(authorityPublicKey: string): UserStats {
95
95
  return this.userStatsMap.get(authorityPublicKey);
96
96
  }
97
97
 
98
- public async mustGet(
99
- authorityPublicKey: string
100
- ): Promise<ClearingHouseUserStats> {
98
+ public async mustGet(authorityPublicKey: string): Promise<UserStats> {
101
99
  if (!this.has(authorityPublicKey)) {
102
100
  await this.addUserStat(new PublicKey(authorityPublicKey));
103
101
  }
104
102
  return this.get(authorityPublicKey);
105
103
  }
106
104
 
107
- public values(): IterableIterator<ClearingHouseUserStats> {
105
+ public values(): IterableIterator<UserStats> {
108
106
  return this.userStatsMap.values();
109
107
  }
110
108
  }
@@ -1,7 +1,7 @@
1
- import { ClearingHouse } from './clearingHouse';
1
+ import { DriftClient } from './driftClient';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { DataAndSlot, UserStatsAccountSubscriber } from './accounts/types';
4
- import { ClearingHouseUserStatsConfig } from './clearingHouseUserStatsConfig';
4
+ import { UserStatsConfig } from './userStatsConfig';
5
5
  import { PollingUserStatsAccountSubscriber } from './accounts/pollingUserStatsAccountSubscriber';
6
6
  import { WebSocketUserStatsAccountSubscriber } from './accounts/webSocketUserStatsAccountSubsriber';
7
7
  import { ReferrerInfo, UserStatsAccount } from './types';
@@ -10,24 +10,24 @@ import {
10
10
  getUserStatsAccountPublicKey,
11
11
  } from './addresses/pda';
12
12
 
13
- export class ClearingHouseUserStats {
14
- clearingHouse: ClearingHouse;
13
+ export class UserStats {
14
+ driftClient: DriftClient;
15
15
  userStatsAccountPublicKey: PublicKey;
16
16
  accountSubscriber: UserStatsAccountSubscriber;
17
17
  isSubscribed: boolean;
18
18
 
19
- public constructor(config: ClearingHouseUserStatsConfig) {
20
- this.clearingHouse = config.clearingHouse;
19
+ public constructor(config: UserStatsConfig) {
20
+ this.driftClient = config.driftClient;
21
21
  this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
22
22
  if (config.accountSubscription?.type === 'polling') {
23
23
  this.accountSubscriber = new PollingUserStatsAccountSubscriber(
24
- config.clearingHouse.program,
24
+ config.driftClient.program,
25
25
  config.userStatsAccountPublicKey,
26
26
  config.accountSubscription.accountLoader
27
27
  );
28
28
  } else {
29
29
  this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
30
- config.clearingHouse.program,
30
+ config.driftClient.program,
31
31
  config.userStatsAccountPublicKey
32
32
  );
33
33
  }
@@ -61,12 +61,12 @@ export class ClearingHouseUserStats {
61
61
  } else {
62
62
  return {
63
63
  referrer: getUserAccountPublicKeySync(
64
- this.clearingHouse.program.programId,
64
+ this.driftClient.program.programId,
65
65
  this.getAccount().referrer,
66
66
  0
67
67
  ),
68
68
  referrerStats: getUserStatsAccountPublicKey(
69
- this.clearingHouse.program.programId,
69
+ this.driftClient.program.programId,
70
70
  this.getAccount().referrer
71
71
  ),
72
72
  };
@@ -0,0 +1,18 @@
1
+ import { DriftClient } from './driftClient';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
+
5
+ export type UserStatsConfig = {
6
+ accountSubscription?: UserStatsSubscriptionConfig;
7
+ driftClient: DriftClient;
8
+ userStatsAccountPublicKey: PublicKey;
9
+ };
10
+
11
+ export type UserStatsSubscriptionConfig =
12
+ | {
13
+ type: 'websocket';
14
+ }
15
+ | {
16
+ type: 'polling';
17
+ accountLoader: BulkAccountLoader;
18
+ };
@@ -4,8 +4,8 @@ import {
4
4
  AssetTier,
5
5
  PerpPosition,
6
6
  BN,
7
- ClearingHouse,
8
- ClearingHouseUser,
7
+ DriftClient,
8
+ User,
9
9
  PerpMarketAccount,
10
10
  SpotMarketAccount,
11
11
  MarketStatus,
@@ -21,6 +21,7 @@ import {
21
21
  OrderRecord,
22
22
  ExchangeStatus,
23
23
  ZERO,
24
+ ContractTier,
24
25
  } from '../../src';
25
26
 
26
27
  export const mockPerpPosition: PerpPosition = {
@@ -71,7 +72,6 @@ export const mockAMM: AMM = {
71
72
  fundingPeriod: new BN(0),
72
73
  cumulativeFundingRateLong: new BN(0),
73
74
  cumulativeFundingRateShort: new BN(0),
74
- cumulativeFundingRateLp: new BN(0),
75
75
  totalFeeMinusDistributions: new BN(0),
76
76
  totalFeeWithdrawn: new BN(0),
77
77
  totalFee: new BN(0),
@@ -79,6 +79,14 @@ export const mockAMM: AMM = {
79
79
  baseAssetAmountWithUnsettledLp: new BN(0),
80
80
  orderStepSize: new BN(0),
81
81
  orderTickSize: new BN(1),
82
+ last24hAvgFundingRate: new BN(0),
83
+ lastFundingRateShort: new BN(0),
84
+ lastFundingRateLong: new BN(0),
85
+ concentrationCoef: new BN(0),
86
+ lastTradeTs: new BN(0),
87
+ lastOracleNormalisedPrice: new BN(0),
88
+ maxOpenInterest: new BN(0),
89
+ totalLiquidationFee: new BN(0),
82
90
  maxFillReserveFraction: 0,
83
91
  baseSpread: 0,
84
92
  curveUpdateIntensity: 0,
@@ -107,6 +115,25 @@ export const mockAMM: AMM = {
107
115
  cumulativeSocialLoss: new BN(0),
108
116
  baseAssetAmountPerLp: new BN(0),
109
117
  quoteAssetAmountPerLp: new BN(0),
118
+
119
+ quoteBreakEvenAmountLong: new BN(0),
120
+ quoteBreakEvenAmountShort: new BN(0),
121
+ quoteEntryAmountLong: new BN(0),
122
+ quoteEntryAmountShort: new BN(0),
123
+
124
+ markStd: new BN(0),
125
+ longIntensityCount: 0,
126
+ longIntensityVolume: new BN(0),
127
+ shortIntensityCount: 0,
128
+ shortIntensityVolume: new BN(0),
129
+ volume24h: new BN(0),
130
+ minOrderSize: new BN(0),
131
+ maxPositionSize: new BN(0),
132
+
133
+ bidBaseAssetReserve: new BN(0),
134
+ bidQuoteAssetReserve: new BN(0),
135
+ askBaseAssetReserve: new BN(0),
136
+ askQuoteAssetReserve: new BN(0),
110
137
  };
111
138
 
112
139
  export const mockPerpMarkets: Array<PerpMarketAccount> = [
@@ -114,6 +141,7 @@ export const mockPerpMarkets: Array<PerpMarketAccount> = [
114
141
  status: MarketStatus.INITIALIZED,
115
142
  name: [],
116
143
  contractType: ContractType.PERPETUAL,
144
+ contractTier: ContractTier.A,
117
145
  expiryTs: new BN(0),
118
146
  expiryPrice: new BN(0),
119
147
  marketIndex: 0,
@@ -131,6 +159,8 @@ export const mockPerpMarkets: Array<PerpMarketAccount> = [
131
159
  ifLiquidationFee: 0,
132
160
  liquidatorFee: 0,
133
161
  imfFactor: 0,
162
+ nextFundingRateRecordId: new BN(0),
163
+ nextCurveRecordId: new BN(0),
134
164
  unrealizedPnlImfFactor: 0,
135
165
  unrealizedPnlMaxImbalance: ZERO,
136
166
  unrealizedPnlInitialAssetWeight: 0,
@@ -145,6 +175,9 @@ export const mockPerpMarkets: Array<PerpMarketAccount> = [
145
175
  },
146
176
  {
147
177
  status: MarketStatus.INITIALIZED,
178
+ contractTier: ContractTier.A,
179
+ nextFundingRateRecordId: new BN(0),
180
+ nextCurveRecordId: new BN(0),
148
181
  name: [],
149
182
  contractType: ContractType.PERPETUAL,
150
183
  expiryTs: new BN(0),
@@ -178,6 +211,9 @@ export const mockPerpMarkets: Array<PerpMarketAccount> = [
178
211
  },
179
212
  {
180
213
  status: MarketStatus.INITIALIZED,
214
+ contractTier: ContractTier.A,
215
+ nextFundingRateRecordId: new BN(0),
216
+ nextCurveRecordId: new BN(0),
181
217
  name: [],
182
218
  contractType: ContractType.PERPETUAL,
183
219
  expiryTs: new BN(0),
@@ -260,6 +296,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
260
296
  orderStepSize: new BN(0),
261
297
  orderTickSize: new BN(0),
262
298
  nextFillRecordId: new BN(0),
299
+ nextDepositRecordId: new BN(0),
300
+ ordersEnabled: true,
263
301
  spotFeePool: {
264
302
  scaledBalance: new BN(0),
265
303
  marketIndex: 0,
@@ -330,6 +368,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
330
368
  orderStepSize: new BN(0),
331
369
  orderTickSize: new BN(0),
332
370
  nextFillRecordId: new BN(0),
371
+ nextDepositRecordId: new BN(0),
372
+ ordersEnabled: true,
333
373
  spotFeePool: {
334
374
  scaledBalance: new BN(0),
335
375
  marketIndex: 0,
@@ -400,6 +440,8 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
400
440
  orderStepSize: new BN(0),
401
441
  orderTickSize: new BN(0),
402
442
  nextFillRecordId: new BN(0),
443
+ nextDepositRecordId: new BN(0),
444
+ ordersEnabled: true,
403
445
  spotFeePool: {
404
446
  scaledBalance: new BN(0),
405
447
  marketIndex: 0,
@@ -502,14 +544,14 @@ export const mockStateAccount: StateAccount = {
502
544
  };
503
545
 
504
546
  export class MockUserMap implements UserMapInterface {
505
- private userMap = new Map<string, ClearingHouseUser>();
547
+ private userMap = new Map<string, User>();
506
548
  private userAccountToAuthority = new Map<string, string>();
507
- private clearingHouse: ClearingHouse;
549
+ private driftClient: DriftClient;
508
550
 
509
551
  constructor() {
510
552
  this.userMap = new Map();
511
553
  this.userAccountToAuthority = new Map();
512
- this.clearingHouse = new ClearingHouse({
554
+ this.driftClient = new DriftClient({
513
555
  connection: new Connection('http://localhost:8899'),
514
556
  wallet: new Wallet(new Keypair()),
515
557
  programID: PublicKey.default,
@@ -519,8 +561,8 @@ export class MockUserMap implements UserMapInterface {
519
561
  public async fetchAllUsers(): Promise<void> {}
520
562
 
521
563
  public async addPubkey(userAccountPublicKey: PublicKey): Promise<void> {
522
- const user = new ClearingHouseUser({
523
- clearingHouse: this.clearingHouse,
564
+ const user = new User({
565
+ driftClient: this.driftClient,
524
566
  userAccountPublicKey: userAccountPublicKey,
525
567
  });
526
568
  this.userMap.set(userAccountPublicKey.toBase58(), user);
@@ -544,13 +586,13 @@ export class MockUserMap implements UserMapInterface {
544
586
  return this.userMap.has(key);
545
587
  }
546
588
 
547
- public get(_key: string): ClearingHouseUser | undefined {
589
+ public get(_key: string): User | undefined {
548
590
  return undefined;
549
591
  }
550
592
 
551
- public async mustGet(_key: string): Promise<ClearingHouseUser> {
552
- return new ClearingHouseUser({
553
- clearingHouse: this.clearingHouse,
593
+ public async mustGet(_key: string): Promise<User> {
594
+ return new User({
595
+ driftClient: this.driftClient,
554
596
  userAccountPublicKey: PublicKey.default,
555
597
  });
556
598
  }
@@ -563,7 +605,7 @@ export class MockUserMap implements UserMapInterface {
563
605
 
564
606
  public async updateWithOrderRecord(_record: OrderRecord): Promise<void> {}
565
607
 
566
- public values(): IterableIterator<ClearingHouseUser> {
608
+ public values(): IterableIterator<User> {
567
609
  return this.userMap.values();
568
610
  }
569
611
  }
@@ -1,14 +0,0 @@
1
- import { ClearingHouse } from './clearingHouse';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- export declare type ClearingHouseUserConfig = {
5
- accountSubscription?: ClearingHouseUserAccountSubscriptionConfig;
6
- clearingHouse: ClearingHouse;
7
- userAccountPublicKey: PublicKey;
8
- };
9
- export declare type ClearingHouseUserAccountSubscriptionConfig = {
10
- type: 'websocket';
11
- } | {
12
- type: 'polling';
13
- accountLoader: BulkAccountLoader;
14
- };
@@ -1,14 +0,0 @@
1
- import { ClearingHouse } from './clearingHouse';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- export declare type ClearingHouseUserStatsConfig = {
5
- accountSubscription?: ClearingHouseUserStatsAccountSubscriptionConfig;
6
- clearingHouse: ClearingHouse;
7
- userStatsAccountPublicKey: PublicKey;
8
- };
9
- export declare type ClearingHouseUserStatsAccountSubscriptionConfig = {
10
- type: 'websocket';
11
- } | {
12
- type: 'polling';
13
- accountLoader: BulkAccountLoader;
14
- };
@@ -1,18 +0,0 @@
1
- import { ClearingHouse } from './clearingHouse';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
-
5
- export type ClearingHouseUserStatsConfig = {
6
- accountSubscription?: ClearingHouseUserStatsAccountSubscriptionConfig;
7
- clearingHouse: ClearingHouse;
8
- userStatsAccountPublicKey: PublicKey;
9
- };
10
-
11
- export type ClearingHouseUserStatsAccountSubscriptionConfig =
12
- | {
13
- type: 'websocket';
14
- }
15
- | {
16
- type: 'polling';
17
- accountLoader: BulkAccountLoader;
18
- };