@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.2.0-master.37",
3
+ "version": "0.2.0-master.39",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,4 +1,4 @@
1
- import { ClearingHouseUserStats } from '../clearingHouseUserStats';
1
+ import { UserStats } from '../userStats';
2
2
  import { BulkAccountLoader } from './bulkAccountLoader';
3
3
  import { PollingUserStatsAccountSubscriber } from './pollingUserStatsAccountSubscriber';
4
4
 
@@ -7,7 +7,7 @@ import { PollingUserStatsAccountSubscriber } from './pollingUserStatsAccountSubs
7
7
  * @param accountLoader
8
8
  */
9
9
  export async function bulkPollingUserStatsSubscribe(
10
- userStats: ClearingHouseUserStats[],
10
+ userStats: UserStats[],
11
11
  accountLoader: BulkAccountLoader
12
12
  ): Promise<void> {
13
13
  if (userStats.length === 0) {
@@ -1,4 +1,4 @@
1
- import { ClearingHouseUser } from '../clearingHouseUser';
1
+ import { User } from '../user';
2
2
  import { BulkAccountLoader } from './bulkAccountLoader';
3
3
  import { PollingUserAccountSubscriber } from './pollingUserAccountSubscriber';
4
4
 
@@ -7,7 +7,7 @@ import { PollingUserAccountSubscriber } from './pollingUserAccountSubscriber';
7
7
  * @param accountLoader
8
8
  */
9
9
  export async function bulkPollingUserSubscribe(
10
- users: ClearingHouseUser[],
10
+ users: User[],
11
11
  accountLoader: BulkAccountLoader
12
12
  ): Promise<void> {
13
13
  if (users.length === 0) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  DataAndSlot,
3
3
  AccountToPoll,
4
- ClearingHouseAccountEvents,
5
- ClearingHouseAccountSubscriber,
4
+ DriftClientAccountEvents,
5
+ DriftClientAccountSubscriber,
6
6
  NotSubscribedError,
7
7
  OraclesToPoll,
8
8
  } from './types';
@@ -16,7 +16,7 @@ import {
16
16
  UserAccount,
17
17
  } from '../types';
18
18
  import {
19
- getClearingHouseStateAccountPublicKey,
19
+ getDriftStateAccountPublicKey,
20
20
  getSpotMarketPublicKey,
21
21
  getPerpMarketPublicKey,
22
22
  } from '../addresses/pda';
@@ -27,8 +27,8 @@ import { OracleInfo, OraclePriceData } from '../oracles/types';
27
27
  import { OracleClientCache } from '../oracles/oracleClientCache';
28
28
  import { QUOTE_ORACLE_PRICE_DATA } from '../oracles/quoteAssetOracleClient';
29
29
 
30
- export class PollingClearingHouseAccountSubscriber
31
- implements ClearingHouseAccountSubscriber
30
+ export class PollingDriftClientAccountSubscriber
31
+ implements DriftClientAccountSubscriber
32
32
  {
33
33
  isSubscribed: boolean;
34
34
  program: Program;
@@ -37,7 +37,7 @@ export class PollingClearingHouseAccountSubscriber
37
37
  oracleInfos: OracleInfo[];
38
38
  oracleClientCache = new OracleClientCache();
39
39
 
40
- eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
40
+ eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
41
41
 
42
42
  accountLoader: BulkAccountLoader;
43
43
  accountsToPoll = new Map<string, AccountToPoll>();
@@ -113,11 +113,13 @@ export class PollingClearingHouseAccountSubscriber
113
113
  return;
114
114
  }
115
115
 
116
- const accounts = await this.getClearingHouseAccounts();
116
+ const statePublicKey = await getDriftStateAccountPublicKey(
117
+ this.program.programId
118
+ );
117
119
 
118
- this.accountsToPoll.set(accounts.state.toString(), {
120
+ this.accountsToPoll.set(statePublicKey.toString(), {
119
121
  key: 'state',
120
- publicKey: accounts.state,
122
+ publicKey: statePublicKey,
121
123
  eventType: 'stateAccountUpdate',
122
124
  });
123
125
 
@@ -190,18 +192,6 @@ export class PollingClearingHouseAccountSubscriber
190
192
  return true;
191
193
  }
192
194
 
193
- async getClearingHouseAccounts(): Promise<ClearingHouseAccounts> {
194
- const statePublicKey = await getClearingHouseStateAccountPublicKey(
195
- this.program.programId
196
- );
197
-
198
- const accounts = {
199
- state: statePublicKey,
200
- };
201
-
202
- return accounts;
203
- }
204
-
205
195
  async addToAccountLoader(): Promise<void> {
206
196
  for (const [_, accountToPoll] of this.accountsToPoll) {
207
197
  this.addAccountToAccountLoader(accountToPoll);
@@ -427,7 +417,3 @@ export class PollingClearingHouseAccountSubscriber
427
417
  return this.oracles.get(oraclePublicKey.toString());
428
418
  }
429
419
  }
430
-
431
- type ClearingHouseAccounts = {
432
- state: PublicKey;
433
- };
@@ -2,7 +2,7 @@ import {
2
2
  DataAndSlot,
3
3
  NotSubscribedError,
4
4
  OracleEvents,
5
- OracleSubscriber,
5
+ OracleAccountSubscriber,
6
6
  } from './types';
7
7
  import { Program } from '@project-serum/anchor';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -11,7 +11,7 @@ import { PublicKey } from '@solana/web3.js';
11
11
  import { BulkAccountLoader } from './bulkAccountLoader';
12
12
  import { OracleClient, OraclePriceData } from '../oracles/types';
13
13
 
14
- export class PollingOracleSubscriber implements OracleSubscriber {
14
+ export class PollingOracleAccountSubscriber implements OracleAccountSubscriber {
15
15
  isSubscribed: boolean;
16
16
  program: Program;
17
17
  eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
@@ -23,7 +23,7 @@ export class NotSubscribedError extends Error {
23
23
  name = 'NotSubscribedError';
24
24
  }
25
25
 
26
- export interface ClearingHouseAccountEvents {
26
+ export interface DriftClientAccountEvents {
27
27
  stateAccountUpdate: (payload: StateAccount) => void;
28
28
  perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
29
29
  spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
@@ -33,8 +33,8 @@ export interface ClearingHouseAccountEvents {
33
33
  error: (e: Error) => void;
34
34
  }
35
35
 
36
- export interface ClearingHouseAccountSubscriber {
37
- eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
36
+ export interface DriftClientAccountSubscriber {
37
+ eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
38
38
  isSubscribed: boolean;
39
39
 
40
40
  subscribe(): Promise<boolean>;
@@ -99,7 +99,7 @@ export interface OracleEvents {
99
99
  error: (e: Error) => void;
100
100
  }
101
101
 
102
- export interface OracleSubscriber {
102
+ export interface OracleAccountSubscriber {
103
103
  eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
104
104
  isSubscribed: boolean;
105
105
 
@@ -1,6 +1,6 @@
1
1
  import {
2
- ClearingHouseAccountSubscriber,
3
- ClearingHouseAccountEvents,
2
+ DriftClientAccountSubscriber,
3
+ DriftClientAccountEvents,
4
4
  DataAndSlot,
5
5
  } from './types';
6
6
  import { AccountSubscriber, NotSubscribedError } from './types';
@@ -9,7 +9,7 @@ import { Program } from '@project-serum/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import {
12
- getClearingHouseStateAccountPublicKey,
12
+ getDriftStateAccountPublicKey,
13
13
  getSpotMarketPublicKey,
14
14
  getPerpMarketPublicKey,
15
15
  } from '../addresses/pda';
@@ -20,8 +20,8 @@ import { OracleClientCache } from '../oracles/oracleClientCache';
20
20
  import * as Buffer from 'buffer';
21
21
  import { QUOTE_ORACLE_PRICE_DATA } from '../oracles/quoteAssetOracleClient';
22
22
 
23
- export class WebSocketClearingHouseAccountSubscriber
24
- implements ClearingHouseAccountSubscriber
23
+ export class WebSocketDriftClientAccountSubscriber
24
+ implements DriftClientAccountSubscriber
25
25
  {
26
26
  isSubscribed: boolean;
27
27
  program: Program;
@@ -30,7 +30,7 @@ export class WebSocketClearingHouseAccountSubscriber
30
30
  oracleInfos: OracleInfo[];
31
31
  oracleClientCache = new OracleClientCache();
32
32
 
33
- eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
33
+ eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
34
34
  stateAccountSubscriber?: AccountSubscriber<StateAccount>;
35
35
  perpMarketAccountSubscribers = new Map<
36
36
  number,
@@ -75,7 +75,7 @@ export class WebSocketClearingHouseAccountSubscriber
75
75
  this.subscriptionPromiseResolver = res;
76
76
  });
77
77
 
78
- const statePublicKey = await getClearingHouseStateAccountPublicKey(
78
+ const statePublicKey = await getDriftStateAccountPublicKey(
79
79
  this.program.programId
80
80
  );
81
81
 
@@ -2,19 +2,19 @@ import { PublicKey } from '@solana/web3.js';
2
2
  import * as anchor from '@project-serum/anchor';
3
3
  import { BN } from '@project-serum/anchor';
4
4
 
5
- export async function getClearingHouseStateAccountPublicKeyAndNonce(
5
+ export async function getDriftStateAccountPublicKeyAndNonce(
6
6
  programId: PublicKey
7
7
  ): Promise<[PublicKey, number]> {
8
8
  return PublicKey.findProgramAddress(
9
- [Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))],
9
+ [Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))],
10
10
  programId
11
11
  );
12
12
  }
13
13
 
14
- export async function getClearingHouseStateAccountPublicKey(
14
+ export async function getDriftStateAccountPublicKey(
15
15
  programId: PublicKey
16
16
  ): Promise<PublicKey> {
17
- return (await getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
17
+ return (await getDriftStateAccountPublicKeyAndNonce(programId))[0];
18
18
  }
19
19
 
20
20
  export async function getUserAccountPublicKeyAndNonce(
@@ -145,11 +145,9 @@ export function getInsuranceFundStakeAccountPublicKey(
145
145
  )[0];
146
146
  }
147
147
 
148
- export function getClearingHouseSignerPublicKey(
149
- programId: PublicKey
150
- ): PublicKey {
148
+ export function getDriftSignerPublicKey(programId: PublicKey): PublicKey {
151
149
  return PublicKey.findProgramAddressSync(
152
- [Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house_signer'))],
150
+ [Buffer.from(anchor.utils.bytes.utf8.encode('drift_signer'))],
153
151
  programId
154
152
  )[0];
155
153
  }
@@ -16,7 +16,7 @@ import { DEFAULT_MARKET_NAME, encodeName } from './userName';
16
16
  import { BN } from '@project-serum/anchor';
17
17
  import * as anchor from '@project-serum/anchor';
18
18
  import {
19
- getClearingHouseStateAccountPublicKeyAndNonce,
19
+ getDriftStateAccountPublicKeyAndNonce,
20
20
  getSpotMarketPublicKey,
21
21
  getSpotMarketVaultPublicKey,
22
22
  getPerpMarketPublicKey,
@@ -26,12 +26,12 @@ import {
26
26
  } from './addresses/pda';
27
27
  import { squareRootBN } from './math/utils';
28
28
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
29
- import { ClearingHouse } from './clearingHouse';
29
+ import { DriftClient } from './driftClient';
30
30
  import { PEG_PRECISION } from './constants/numericConstants';
31
31
  import { calculateTargetPriceTrade } from './math/trade';
32
32
  import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
33
33
 
34
- export class Admin extends ClearingHouse {
34
+ export class AdminClient extends DriftClient {
35
35
  public async initialize(
36
36
  usdcMint: PublicKey,
37
37
  _adminControlsPrices: boolean
@@ -43,18 +43,17 @@ export class Admin extends ClearingHouse {
43
43
  throw new Error('Clearing house already initialized');
44
44
  }
45
45
 
46
- const [clearingHouseStatePublicKey] =
47
- await getClearingHouseStateAccountPublicKeyAndNonce(
48
- this.program.programId
49
- );
46
+ const [driftStatePublicKey] = await getDriftStateAccountPublicKeyAndNonce(
47
+ this.program.programId
48
+ );
50
49
 
51
50
  const initializeTx = await this.program.transaction.initialize({
52
51
  accounts: {
53
52
  admin: this.wallet.publicKey,
54
- state: clearingHouseStatePublicKey,
53
+ state: driftStatePublicKey,
55
54
  quoteAssetMint: usdcMint,
56
55
  rent: SYSVAR_RENT_PUBKEY,
57
- clearingHouseSigner: this.getSignerPublicKey(),
56
+ driftSigner: this.getSignerPublicKey(),
58
57
  systemProgram: anchor.web3.SystemProgram.programId,
59
58
  tokenProgram: TOKEN_PROGRAM_ID,
60
59
  },
@@ -81,8 +80,9 @@ export class Admin extends ClearingHouse {
81
80
  initialLiabilityWeight: number,
82
81
  maintenanceLiabilityWeight: number,
83
82
  imfFactor = 0,
84
- liquidationFee = 0,
85
- activeStatus = true
83
+ liquidatorFee = 0,
84
+ activeStatus = true,
85
+ name = DEFAULT_MARKET_NAME
86
86
  ): Promise<TransactionSignature> {
87
87
  const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
88
88
  const spotMarket = await getSpotMarketPublicKey(
@@ -100,6 +100,7 @@ export class Admin extends ClearingHouse {
100
100
  spotMarketIndex
101
101
  );
102
102
 
103
+ const nameBuffer = encodeName(name);
103
104
  const initializeTx = await this.program.transaction.initializeSpotMarket(
104
105
  optimalUtilization,
105
106
  optimalRate,
@@ -110,8 +111,9 @@ export class Admin extends ClearingHouse {
110
111
  initialLiabilityWeight,
111
112
  maintenanceLiabilityWeight,
112
113
  imfFactor,
113
- liquidationFee,
114
+ liquidatorFee,
114
115
  activeStatus,
116
+ nameBuffer,
115
117
  {
116
118
  accounts: {
117
119
  admin: this.wallet.publicKey,
@@ -119,7 +121,7 @@ export class Admin extends ClearingHouse {
119
121
  spotMarket,
120
122
  spotMarketVault,
121
123
  insuranceFundVault,
122
- clearingHouseSigner: this.getSignerPublicKey(),
124
+ driftSigner: this.getSignerPublicKey(),
123
125
  spotMarketMint: mint,
124
126
  oracle,
125
127
  rent: SYSVAR_RENT_PUBKEY,
@@ -163,7 +165,7 @@ export class Admin extends ClearingHouse {
163
165
  state: await this.getStatePublicKey(),
164
166
  baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
165
167
  quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
166
- clearingHouseSigner: this.getSignerPublicKey(),
168
+ driftSigner: this.getSignerPublicKey(),
167
169
  serumProgram,
168
170
  serumMarket,
169
171
  serumOpenOrders,
@@ -184,7 +186,7 @@ export class Admin extends ClearingHouse {
184
186
  oracleSource: OracleSource = OracleSource.PYTH,
185
187
  marginRatioInitial = 2000,
186
188
  marginRatioMaintenance = 500,
187
- liquidationFee = 0,
189
+ liquidatorFee = 0,
188
190
  activeStatus = true,
189
191
  name = DEFAULT_MARKET_NAME
190
192
  ): Promise<TransactionSignature> {
@@ -203,7 +205,7 @@ export class Admin extends ClearingHouse {
203
205
  oracleSource,
204
206
  marginRatioInitial,
205
207
  marginRatioMaintenance,
206
- liquidationFee,
208
+ liquidatorFee,
207
209
  activeStatus,
208
210
  nameBuffer,
209
211
  {
@@ -414,7 +416,7 @@ export class Admin extends ClearingHouse {
414
416
  perpMarketIndex
415
417
  ),
416
418
  sourceVault,
417
- clearingHouseSigner: this.getSignerPublicKey(),
419
+ driftSigner: this.getSignerPublicKey(),
418
420
  quoteSpotMarket: spotMarket.pubkey,
419
421
  spotMarketVault: spotMarket.vault,
420
422
  tokenProgram: TOKEN_PROGRAM_ID,
@@ -474,6 +476,27 @@ export class Admin extends ClearingHouse {
474
476
  );
475
477
  }
476
478
 
479
+ public async updatePerpMarketImfFactor(
480
+ perpMarketIndex: number,
481
+ imfFactor: number,
482
+ unrealizedPnlImfFactor: number
483
+ ): Promise<TransactionSignature> {
484
+ return await this.program.rpc.updatePerpMarketImfFactor(
485
+ imfFactor,
486
+ unrealizedPnlImfFactor,
487
+ {
488
+ accounts: {
489
+ admin: this.wallet.publicKey,
490
+ state: await this.getStatePublicKey(),
491
+ perpMarket: await getPerpMarketPublicKey(
492
+ this.program.programId,
493
+ perpMarketIndex
494
+ ),
495
+ },
496
+ }
497
+ );
498
+ }
499
+
477
500
  public async updatePerpMarketBaseSpread(
478
501
  perpMarketIndex: number,
479
502
  baseSpread: number
@@ -524,6 +547,24 @@ export class Admin extends ClearingHouse {
524
547
  });
525
548
  }
526
549
 
550
+ public async updateSpotMarketName(
551
+ spotMarketIndex: number,
552
+ name: string
553
+ ): Promise<TransactionSignature> {
554
+ const nameBuffer = encodeName(name);
555
+
556
+ return await this.program.rpc.updateSpotMarketName(nameBuffer, {
557
+ accounts: {
558
+ admin: this.wallet.publicKey,
559
+ state: await this.getStatePublicKey(),
560
+ spotMarket: await getSpotMarketPublicKey(
561
+ this.program.programId,
562
+ spotMarketIndex
563
+ ),
564
+ },
565
+ });
566
+ }
567
+
527
568
  public async updatePerpMarketMaxSpread(
528
569
  perpMarketIndex: number,
529
570
  maxSpread: number
@@ -753,6 +794,43 @@ export class Admin extends ClearingHouse {
753
794
  });
754
795
  }
755
796
 
797
+ public async updateSpotMarketStepSizeAndTickSize(
798
+ spotMarketIndex: number,
799
+ stepSize: BN,
800
+ tickSize: BN
801
+ ): Promise<TransactionSignature> {
802
+ return await this.program.rpc.updateSpotMarketStepSizeAndTickSize(
803
+ stepSize,
804
+ tickSize,
805
+ {
806
+ accounts: {
807
+ admin: this.wallet.publicKey,
808
+ state: await this.getStatePublicKey(),
809
+ spotMarket: await getSpotMarketPublicKey(
810
+ this.program.programId,
811
+ spotMarketIndex
812
+ ),
813
+ },
814
+ }
815
+ );
816
+ }
817
+
818
+ public async updateSpotMarketMinOrderSize(
819
+ spotMarketIndex: number,
820
+ orderSize: BN
821
+ ): Promise<TransactionSignature> {
822
+ return await this.program.rpc.updateSpotMarketMinOrderSize(orderSize, {
823
+ accounts: {
824
+ admin: this.wallet.publicKey,
825
+ state: await this.getStatePublicKey(),
826
+ spotMarket: await getSpotMarketPublicKey(
827
+ this.program.programId,
828
+ spotMarketIndex
829
+ ),
830
+ },
831
+ });
832
+ }
833
+
756
834
  public async updatePerpMarketExpiry(
757
835
  perpMarketIndex: number,
758
836
  expiryTs: BN
@@ -852,6 +930,29 @@ export class Admin extends ClearingHouse {
852
930
  );
853
931
  }
854
932
 
933
+ public async updateSpotMarketBorrowRate(
934
+ spotMarketIndex: number,
935
+ optimalUtilization: number,
936
+ optimalBorrowRate: number,
937
+ optimalMaxRate: number
938
+ ): Promise<TransactionSignature> {
939
+ return await this.program.rpc.updateSpotMarketBorrowRate(
940
+ optimalUtilization,
941
+ optimalBorrowRate,
942
+ optimalMaxRate,
943
+ {
944
+ accounts: {
945
+ admin: this.wallet.publicKey,
946
+ state: await this.getStatePublicKey(),
947
+ spotMarket: await getSpotMarketPublicKey(
948
+ this.program.programId,
949
+ spotMarketIndex
950
+ ),
951
+ },
952
+ }
953
+ );
954
+ }
955
+
855
956
  public async updateSpotMarketAssetTier(
856
957
  spotMarketIndex: number,
857
958
  assetTier: AssetTier
@@ -965,7 +1066,10 @@ export class Admin extends ClearingHouse {
965
1066
  accounts: {
966
1067
  admin: this.wallet.publicKey,
967
1068
  state: await this.getStatePublicKey(),
968
- perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey,
1069
+ perpMarket: await getPerpMarketPublicKey(
1070
+ this.program.programId,
1071
+ perpMarketIndex
1072
+ ),
969
1073
  },
970
1074
  }
971
1075
  );
@@ -984,6 +1088,27 @@ export class Admin extends ClearingHouse {
984
1088
  });
985
1089
  }
986
1090
 
1091
+ public async updatePerpMarketUnrealizedAssetWeight(
1092
+ perpMarketIndex: number,
1093
+ unrealizedInitialAssetWeight: number,
1094
+ unrealizedMaintenanceAssetWeight: number
1095
+ ): Promise<TransactionSignature> {
1096
+ return await this.program.rpc.updatePerpMarketUnrealizedAssetWeight(
1097
+ unrealizedInitialAssetWeight,
1098
+ unrealizedMaintenanceAssetWeight,
1099
+ {
1100
+ accounts: {
1101
+ admin: this.wallet.publicKey,
1102
+ state: await this.getStatePublicKey(),
1103
+ perpMarket: await getPerpMarketPublicKey(
1104
+ this.program.programId,
1105
+ perpMarketIndex
1106
+ ),
1107
+ },
1108
+ }
1109
+ );
1110
+ }
1111
+
987
1112
  public async updatePerpMarketMaxImbalances(
988
1113
  perpMarketIndex: number,
989
1114
  unrealizedMaxImbalance: BN,
@@ -1037,4 +1162,46 @@ export class Admin extends ClearingHouse {
1037
1162
  },
1038
1163
  });
1039
1164
  }
1165
+
1166
+ public async updatePerpMarketLiquidationFee(
1167
+ perpMarketIndex: number,
1168
+ liquidatorFee: number,
1169
+ ifLiquidationFee: number
1170
+ ): Promise<TransactionSignature> {
1171
+ return await this.program.rpc.updatePerpMarketLiquidationFee(
1172
+ liquidatorFee,
1173
+ ifLiquidationFee,
1174
+ {
1175
+ accounts: {
1176
+ admin: this.wallet.publicKey,
1177
+ state: await this.getStatePublicKey(),
1178
+ perpMarket: await getPerpMarketPublicKey(
1179
+ this.program.programId,
1180
+ perpMarketIndex
1181
+ ),
1182
+ },
1183
+ }
1184
+ );
1185
+ }
1186
+
1187
+ public async updateSpotMarketLiquidationFee(
1188
+ spotMarketIndex: number,
1189
+ liquidatorFee: number,
1190
+ ifLiquidationFee: number
1191
+ ): Promise<TransactionSignature> {
1192
+ return await this.program.rpc.updateSpotMarketLiquidationFee(
1193
+ liquidatorFee,
1194
+ ifLiquidationFee,
1195
+ {
1196
+ accounts: {
1197
+ admin: this.wallet.publicKey,
1198
+ state: await this.getStatePublicKey(),
1199
+ spotMarket: await getSpotMarketPublicKey(
1200
+ this.program.programId,
1201
+ spotMarketIndex
1202
+ ),
1203
+ },
1204
+ }
1205
+ );
1206
+ }
1040
1207
  }
package/src/config.ts CHANGED
@@ -29,7 +29,7 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
29
29
  devnet: {
30
30
  ENV: 'devnet',
31
31
  PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
32
- CLEARING_HOUSE_PROGRAM_ID: 'jAEeKs9twxAJmXZHqS2p459xW7FMDjoyvuqthRo9qGS',
32
+ CLEARING_HOUSE_PROGRAM_ID: 'H4G1xzAoqSW8n1Edmeowqsgc895tSNCeDPafYjv4Md7i',
33
33
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
34
34
  SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
35
35
  V2_ALPHA_TICKET_MINT_ADDRESS:
@@ -18,6 +18,10 @@ export const TEN_MILLION = TEN_THOUSAND.mul(TEN_THOUSAND);
18
18
 
19
19
  export const MAX_LEVERAGE = new BN(5);
20
20
 
21
+ export const PERCENTAGE_PRECISION_EXP = new BN(6);
22
+ export const PERCENTAGE_PRECISION = new BN(10).pow(PERCENTAGE_PRECISION_EXP);
23
+ export const CONCENTRATION_PRECISION = PERCENTAGE_PRECISION;
24
+
21
25
  export const QUOTE_PRECISION_EXP = new BN(6);
22
26
  export const FUNDING_RATE_BUFFER_PRECISION_EXP = new BN(3);
23
27
  export const PRICE_PRECISION_EXP = new BN(6);
package/src/dlob/DLOB.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  BN,
5
5
  calculateAskPrice,
6
6
  calculateBidPrice,
7
- ClearingHouse,
7
+ DriftClient,
8
8
  convertToNumber,
9
9
  isAuctionComplete,
10
10
  isOrderExpired,
@@ -1021,17 +1021,17 @@ export class DLOB {
1021
1021
 
1022
1022
  public printTopOfOrderLists(
1023
1023
  sdkConfig: any,
1024
- clearingHouse: ClearingHouse,
1024
+ driftClient: DriftClient,
1025
1025
  slotSubscriber: SlotSubscriber,
1026
1026
  marketIndex: number,
1027
1027
  marketType: MarketType
1028
1028
  ) {
1029
1029
  if (isVariant(marketType, 'perp')) {
1030
- const market = clearingHouse.getPerpMarketAccount(marketIndex);
1030
+ const market = driftClient.getPerpMarketAccount(marketIndex);
1031
1031
 
1032
1032
  const slot = slotSubscriber.getSlot();
1033
1033
  const oraclePriceData =
1034
- clearingHouse.getOracleDataForPerpMarket(marketIndex);
1034
+ driftClient.getOracleDataForPerpMarket(marketIndex);
1035
1035
  const fallbackAsk = calculateAskPrice(market, oraclePriceData);
1036
1036
  const fallbackBid = calculateBidPrice(market, oraclePriceData);
1037
1037
 
@@ -1077,7 +1077,7 @@ export class DLOB {
1077
1077
  } else if (isVariant(marketType, 'spot')) {
1078
1078
  const slot = slotSubscriber.getSlot();
1079
1079
  const oraclePriceData =
1080
- clearingHouse.getOracleDataForPerpMarket(marketIndex);
1080
+ driftClient.getOracleDataForPerpMarket(marketIndex);
1081
1081
 
1082
1082
  const bestAsk = this.getBestAsk(
1083
1083
  marketIndex,