@drift-labs/sdk 0.1.18-orders.1 → 0.1.18

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 (108) hide show
  1. package/README.md +2 -1
  2. package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts +4 -7
  3. package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +1 -0
  4. package/lib/accounts/defaultClearingHouseAccountSubscriber.js +1 -26
  5. package/lib/accounts/defaultUserAccountSubscriber.d.ts +2 -3
  6. package/lib/accounts/defaultUserAccountSubscriber.d.ts.map +1 -0
  7. package/lib/accounts/defaultUserAccountSubscriber.js +4 -13
  8. package/lib/accounts/types.d.ts +6 -32
  9. package/lib/accounts/types.d.ts.map +1 -0
  10. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -0
  11. package/lib/accounts/webSocketAccountSubscriber.d.ts.map +1 -0
  12. package/lib/addresses.d.ts +1 -4
  13. package/lib/addresses.d.ts.map +1 -0
  14. package/lib/addresses.js +1 -28
  15. package/lib/admin.d.ts +6 -10
  16. package/lib/admin.d.ts.map +1 -0
  17. package/lib/admin.js +44 -50
  18. package/lib/assert/assert.d.ts +1 -0
  19. package/lib/assert/assert.d.ts.map +1 -0
  20. package/lib/clearingHouse.d.ts +3 -22
  21. package/lib/clearingHouse.d.ts.map +1 -0
  22. package/lib/clearingHouse.js +7 -238
  23. package/lib/clearingHouseUser.d.ts +17 -10
  24. package/lib/clearingHouseUser.d.ts.map +1 -0
  25. package/lib/clearingHouseUser.js +84 -98
  26. package/lib/config.d.ts +1 -0
  27. package/lib/config.d.ts.map +1 -0
  28. package/lib/config.js +1 -1
  29. package/lib/constants/markets.d.ts +1 -0
  30. package/lib/constants/markets.d.ts.map +1 -0
  31. package/lib/constants/markets.js +16 -0
  32. package/lib/constants/numericConstants.d.ts +1 -0
  33. package/lib/constants/numericConstants.d.ts.map +1 -0
  34. package/lib/examples/makeTradeExample.d.ts +1 -0
  35. package/lib/examples/makeTradeExample.d.ts.map +1 -0
  36. package/lib/idl/clearing_house.json +233 -911
  37. package/lib/index.d.ts +1 -4
  38. package/lib/index.d.ts.map +1 -0
  39. package/lib/index.js +0 -4
  40. package/lib/math/amm.d.ts +1 -1
  41. package/lib/math/amm.d.ts.map +1 -0
  42. package/lib/math/amm.js +8 -31
  43. package/lib/math/conversion.d.ts +1 -0
  44. package/lib/math/conversion.d.ts.map +1 -0
  45. package/lib/math/funding.d.ts +1 -0
  46. package/lib/math/funding.d.ts.map +1 -0
  47. package/lib/math/funding.js +4 -1
  48. package/lib/math/insuranceFund.d.ts +1 -0
  49. package/lib/math/insuranceFund.d.ts.map +1 -0
  50. package/lib/math/market.d.ts +2 -2
  51. package/lib/math/market.d.ts.map +1 -0
  52. package/lib/math/market.js +1 -11
  53. package/lib/math/position.d.ts +2 -4
  54. package/lib/math/position.d.ts.map +1 -0
  55. package/lib/math/position.js +4 -18
  56. package/lib/math/trade.d.ts +1 -0
  57. package/lib/math/trade.d.ts.map +1 -0
  58. package/lib/math/utils.d.ts +1 -0
  59. package/lib/math/utils.d.ts.map +1 -0
  60. package/lib/mockUSDCFaucet.d.ts +1 -0
  61. package/lib/mockUSDCFaucet.d.ts.map +1 -0
  62. package/lib/pythClient.d.ts +1 -0
  63. package/lib/pythClient.d.ts.map +1 -0
  64. package/lib/tx/defaultTxSender.d.ts +1 -0
  65. package/lib/tx/defaultTxSender.d.ts.map +1 -0
  66. package/lib/tx/types.d.ts +1 -0
  67. package/lib/tx/types.d.ts.map +1 -0
  68. package/lib/tx/utils.d.ts +1 -0
  69. package/lib/tx/utils.d.ts.map +1 -0
  70. package/lib/types.d.ts +8 -140
  71. package/lib/types.d.ts.map +1 -0
  72. package/lib/types.js +1 -36
  73. package/lib/util/computeUnits.d.ts +1 -0
  74. package/lib/util/computeUnits.d.ts.map +1 -0
  75. package/lib/util/tps.d.ts +1 -0
  76. package/lib/util/tps.d.ts.map +1 -0
  77. package/lib/wallet.d.ts +1 -0
  78. package/lib/wallet.d.ts.map +1 -0
  79. package/package.json +1 -1
  80. package/src/accounts/defaultClearingHouseAccountSubscriber.ts +5 -52
  81. package/src/accounts/defaultUserAccountSubscriber.ts +6 -31
  82. package/src/accounts/types.ts +5 -42
  83. package/src/addresses.ts +0 -35
  84. package/src/admin.ts +52 -86
  85. package/src/clearingHouse.ts +7 -340
  86. package/src/clearingHouseUser.ts +102 -154
  87. package/src/config.ts +1 -1
  88. package/src/constants/markets.ts +16 -0
  89. package/src/idl/clearing_house.json +233 -911
  90. package/src/index.ts +0 -4
  91. package/src/math/amm.ts +14 -47
  92. package/src/math/funding.ts +5 -1
  93. package/src/math/market.ts +2 -28
  94. package/src/math/position.ts +3 -23
  95. package/src/types.ts +7 -124
  96. package/tsconfig.json +1 -0
  97. package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +0 -28
  98. package/lib/accounts/defaultHistoryAccountSubscriber.js +0 -110
  99. package/lib/math/orders.d.ts +0 -3
  100. package/lib/math/orders.js +0 -30
  101. package/lib/orderParams.d.ts +0 -7
  102. package/lib/orderParams.js +0 -88
  103. package/lib/orders.d.ts +0 -5
  104. package/lib/orders.js +0 -136
  105. package/src/accounts/defaultHistoryAccountSubscriber.ts +0 -176
  106. package/src/math/orders.ts +0 -39
  107. package/src/orderParams.ts +0 -128
  108. package/src/orders.ts +0 -230
package/lib/util/tps.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
2
  export declare function estimateTps(programId: PublicKey, connection: Connection, failed: boolean): Promise<number>;
3
+ //# sourceMappingURL=tps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tps.d.ts","sourceRoot":"","sources":["../../src/util/tps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAsB,WAAW,CAChC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,OAAO,GACb,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
package/lib/wallet.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare class Wallet implements IWallet {
7
7
  signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
8
8
  get publicKey(): PublicKey;
9
9
  }
10
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,MAAO,YAAW,OAAO;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO;gBAAd,KAAK,EAAE,OAAO;IAE7B,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAKtD,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOrE,IAAI,SAAS,IAAI,SAAS,CAEzB;CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.18-orders.1",
3
+ "version": "0.1.18",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -5,14 +5,12 @@ import {
5
5
  } from './types';
6
6
  import { AccountSubscriber, NotSubscribedError } from './types';
7
7
  import {
8
- CurveHistoryAccount,
9
8
  DepositHistoryAccount,
9
+ ExtendedCurveHistoryAccount,
10
10
  FundingPaymentHistoryAccount,
11
11
  FundingRateHistoryAccount,
12
12
  LiquidationHistoryAccount,
13
13
  MarketsAccount,
14
- OrderHistoryAccount,
15
- OrderStateAccount,
16
14
  StateAccount,
17
15
  TradeHistoryAccount,
18
16
  } from '../types';
@@ -34,10 +32,8 @@ export class DefaultClearingHouseAccountSubscriber
34
32
  depositHistoryAccountSubscriber?: AccountSubscriber<DepositHistoryAccount>;
35
33
  fundingPaymentHistoryAccountSubscriber?: AccountSubscriber<FundingPaymentHistoryAccount>;
36
34
  fundingRateHistoryAccountSubscriber?: AccountSubscriber<FundingRateHistoryAccount>;
37
- curveHistoryAccountSubscriber?: AccountSubscriber<CurveHistoryAccount>;
35
+ curveHistoryAccountSubscriber?: AccountSubscriber<ExtendedCurveHistoryAccount>;
38
36
  liquidationHistoryAccountSubscriber?: AccountSubscriber<LiquidationHistoryAccount>;
39
- orderStateAccountSubscriber?: AccountSubscriber<OrderStateAccount>;
40
- orderHistoryAccountSubscriber?: AccountSubscriber<OrderHistoryAccount>;
41
37
 
42
38
  optionalExtraSubscriptions: ClearingHouseAccountTypes[] = [];
43
39
 
@@ -96,21 +92,6 @@ export class DefaultClearingHouseAccountSubscriber
96
92
  this.eventEmitter.emit('update');
97
93
  });
98
94
 
99
- this.orderStateAccountSubscriber = new WebSocketAccountSubscriber(
100
- 'orderState',
101
- this.program,
102
- state.orderState
103
- );
104
-
105
- await this.orderStateAccountSubscriber.subscribe(
106
- (data: OrderStateAccount) => {
107
- this.eventEmitter.emit('orderStateAccountUpdate', data);
108
- this.eventEmitter.emit('update');
109
- }
110
- );
111
-
112
- const orderState = this.orderStateAccountSubscriber.data;
113
-
114
95
  // create subscribers for other state accounts
115
96
 
116
97
  this.tradeHistoryAccountSubscriber = new WebSocketAccountSubscriber(
@@ -145,15 +126,9 @@ export class DefaultClearingHouseAccountSubscriber
145
126
  );
146
127
 
147
128
  this.curveHistoryAccountSubscriber = new WebSocketAccountSubscriber(
148
- 'curveHistory',
129
+ 'extendedCurveHistory',
149
130
  this.program,
150
- state.curveHistory
151
- );
152
-
153
- this.orderHistoryAccountSubscriber = new WebSocketAccountSubscriber(
154
- 'orderHistory',
155
- this.program,
156
- orderState.orderHistory
131
+ state.extendedCurveHistory
157
132
  );
158
133
 
159
134
  const extraSusbcribersToUse: {
@@ -197,12 +172,6 @@ export class DefaultClearingHouseAccountSubscriber
197
172
  eventType: 'curveHistoryAccountUpdate',
198
173
  });
199
174
 
200
- if (optionalSubscriptions?.includes('orderHistoryAccount'))
201
- extraSusbcribersToUse.push({
202
- subscriber: this.orderHistoryAccountSubscriber,
203
- eventType: 'orderHistoryAccountUpdate',
204
- });
205
-
206
175
  this.optionalExtraSubscriptions = optionalSubscriptions ?? [];
207
176
 
208
177
  // await all subcriptions in parallel to boost performance
@@ -250,7 +219,6 @@ export class DefaultClearingHouseAccountSubscriber
250
219
 
251
220
  await this.stateAccountSubscriber.unsubscribe();
252
221
  await this.marketsAccountSubscriber.unsubscribe();
253
- await this.orderStateAccountSubscriber.unsubscribe();
254
222
 
255
223
  if (this.optionalExtraSubscriptions.includes('tradeHistoryAccount')) {
256
224
  await this.tradeHistoryAccountSubscriber.unsubscribe();
@@ -278,10 +246,6 @@ export class DefaultClearingHouseAccountSubscriber
278
246
  await this.liquidationHistoryAccountSubscriber.unsubscribe();
279
247
  }
280
248
 
281
- if (this.optionalExtraSubscriptions.includes('orderHistoryAccount')) {
282
- await this.orderHistoryAccountSubscriber.unsubscribe();
283
- }
284
-
285
249
  this.isSubscribed = false;
286
250
  }
287
251
 
@@ -343,7 +307,7 @@ export class DefaultClearingHouseAccountSubscriber
343
307
  return this.fundingRateHistoryAccountSubscriber.data;
344
308
  }
345
309
 
346
- public getCurveHistoryAccount(): CurveHistoryAccount {
310
+ public getCurveHistoryAccount(): ExtendedCurveHistoryAccount {
347
311
  this.assertIsSubscribed();
348
312
  this.assertOptionalIsSubscribed('curveHistoryAccount');
349
313
  return this.curveHistoryAccountSubscriber.data;
@@ -354,15 +318,4 @@ export class DefaultClearingHouseAccountSubscriber
354
318
  this.assertOptionalIsSubscribed('liquidationHistoryAccount');
355
319
  return this.liquidationHistoryAccountSubscriber.data;
356
320
  }
357
-
358
- public getOrderHistoryAccount(): OrderHistoryAccount {
359
- this.assertIsSubscribed();
360
- this.assertOptionalIsSubscribed('orderHistoryAccount');
361
- return this.orderHistoryAccountSubscriber.data;
362
- }
363
-
364
- public getOrderStateAccount(): OrderStateAccount {
365
- this.assertIsSubscribed();
366
- return this.orderStateAccountSubscriber.data;
367
- }
368
321
  }
@@ -8,12 +8,9 @@ import { Program } from '@project-serum/anchor';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
9
9
  import { EventEmitter } from 'events';
10
10
  import { PublicKey } from '@solana/web3.js';
11
- import {
12
- getUserAccountPublicKey,
13
- getUserOrdersAccountPublicKey,
14
- } from '../addresses';
11
+ import { getUserAccountPublicKey } from '../addresses';
15
12
  import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
16
- import { UserAccount, UserOrdersAccount, UserPositionsAccount } from '../types';
13
+ import { UserAccount, UserPositionsAccount } from '../types';
17
14
 
18
15
  export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
19
16
  isSubscribed: boolean;
@@ -23,7 +20,6 @@ export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
23
20
 
24
21
  userDataAccountSubscriber: AccountSubscriber<UserAccount>;
25
22
  userPositionsAccountSubscriber: AccountSubscriber<UserPositionsAccount>;
26
- userOrdersAccountSubscriber: AccountSubscriber<UserOrdersAccount>;
27
23
 
28
24
  public constructor(program: Program, authority: PublicKey) {
29
25
  this.isSubscribed = false;
@@ -65,23 +61,6 @@ export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
65
61
  }
66
62
  );
67
63
 
68
- const userOrdersPublicKey = await getUserOrdersAccountPublicKey(
69
- this.program.programId,
70
- this.authority
71
- );
72
-
73
- this.userOrdersAccountSubscriber = new WebSocketAccountSubscriber(
74
- 'userOrders',
75
- this.program,
76
- userOrdersPublicKey
77
- );
78
- await this.userOrdersAccountSubscriber.subscribe(
79
- (data: UserOrdersAccount) => {
80
- this.eventEmitter.emit('userOrdersData', data);
81
- this.eventEmitter.emit('update');
82
- }
83
- );
84
-
85
64
  this.eventEmitter.emit('update');
86
65
  this.isSubscribed = true;
87
66
  return true;
@@ -91,7 +70,6 @@ export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
91
70
  await Promise.all([
92
71
  this.userDataAccountSubscriber.fetch(),
93
72
  this.userPositionsAccountSubscriber.fetch(),
94
- this.userOrdersAccountSubscriber.fetch(),
95
73
  ]);
96
74
  }
97
75
 
@@ -100,9 +78,10 @@ export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
100
78
  return;
101
79
  }
102
80
 
103
- this.userDataAccountSubscriber.unsubscribe();
104
- this.userPositionsAccountSubscriber.unsubscribe();
105
- this.userOrdersAccountSubscriber.unsubscribe();
81
+ await Promise.all([
82
+ this.userDataAccountSubscriber.unsubscribe(),
83
+ this.userPositionsAccountSubscriber.unsubscribe(),
84
+ ]);
106
85
 
107
86
  this.isSubscribed = false;
108
87
  }
@@ -124,8 +103,4 @@ export class DefaultUserAccountSubscriber implements UserAccountSubscriber {
124
103
  this.assertIsSubscribed();
125
104
  return this.userPositionsAccountSubscriber.data;
126
105
  }
127
-
128
- public getUserOrdersAccount(): UserOrdersAccount {
129
- return this.userOrdersAccountSubscriber.data;
130
- }
131
106
  }
@@ -1,16 +1,13 @@
1
1
  import {
2
- CurveHistoryAccount,
3
2
  DepositHistoryAccount,
3
+ ExtendedCurveHistoryAccount,
4
4
  FundingPaymentHistoryAccount,
5
5
  FundingRateHistoryAccount,
6
6
  LiquidationHistoryAccount,
7
7
  MarketsAccount,
8
- OrderHistoryAccount,
9
- OrderStateAccount,
10
8
  StateAccount,
11
9
  TradeHistoryAccount,
12
10
  UserAccount,
13
- UserOrdersAccount,
14
11
  UserPositionsAccount,
15
12
  } from '../types';
16
13
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -20,7 +17,7 @@ export interface AccountSubscriber<T> {
20
17
  data?: T;
21
18
  subscribe(onChange: (data: T) => void): Promise<void>;
22
19
  fetch(): Promise<void>;
23
- unsubscribe(): void;
20
+ unsubscribe(): Promise<void>;
24
21
  }
25
22
 
26
23
  export class NotSubscribedError extends Error {
@@ -37,9 +34,7 @@ export interface ClearingHouseAccountEvents {
37
34
  tradeHistoryAccountUpdate: (payload: TradeHistoryAccount) => void;
38
35
  liquidationHistoryAccountUpdate: (payload: LiquidationHistoryAccount) => void;
39
36
  depositHistoryAccountUpdate: (payload: DepositHistoryAccount) => void;
40
- curveHistoryAccountUpdate: (payload: CurveHistoryAccount) => void;
41
- orderHistoryAccountUpdate: (payload: OrderHistoryAccount) => void;
42
- orderStateAccountUpdate: (payload: OrderStateAccount) => void;
37
+ curveHistoryAccountUpdate: (payload: ExtendedCurveHistoryAccount) => void;
43
38
  update: void;
44
39
  }
45
40
 
@@ -49,8 +44,7 @@ export type ClearingHouseAccountTypes =
49
44
  | 'fundingPaymentHistoryAccount'
50
45
  | 'fundingRateHistoryAccount'
51
46
  | 'curveHistoryAccount'
52
- | 'liquidationHistoryAccount'
53
- | 'orderHistoryAccount';
47
+ | 'liquidationHistoryAccount';
54
48
 
55
49
  export interface ClearingHouseAccountSubscriber {
56
50
  eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
@@ -70,43 +64,13 @@ export interface ClearingHouseAccountSubscriber {
70
64
  getDepositHistoryAccount(): DepositHistoryAccount;
71
65
  getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
72
66
  getFundingRateHistoryAccount(): FundingRateHistoryAccount;
73
- getCurveHistoryAccount(): CurveHistoryAccount;
74
- getLiquidationHistoryAccount(): LiquidationHistoryAccount;
75
- getOrderStateAccount(): OrderStateAccount;
76
- getOrderHistoryAccount(): OrderHistoryAccount;
77
- }
78
-
79
- export interface HistoryAccountEvents {
80
- fundingPaymentHistoryAccountUpdate: (
81
- payload: FundingPaymentHistoryAccount
82
- ) => void;
83
- fundingRateHistoryAccountUpdate: (payload: FundingRateHistoryAccount) => void;
84
- tradeHistoryAccountUpdate: (payload: TradeHistoryAccount) => void;
85
- liquidationHistoryAccountUpdate: (payload: LiquidationHistoryAccount) => void;
86
- depositHistoryAccountUpdate: (payload: DepositHistoryAccount) => void;
87
- curveHistoryAccountUpdate: (payload: CurveHistoryAccount) => void;
88
- update: void;
89
- }
90
-
91
- export interface HistoryAccountSubscriber {
92
- eventEmitter: StrictEventEmitter<EventEmitter, HistoryAccountEvents>;
93
- isSubscribed: boolean;
94
-
95
- subscribe(): Promise<boolean>;
96
- unsubscribe(): Promise<void>;
97
-
98
- getTradeHistoryAccount(): TradeHistoryAccount;
99
- getDepositHistoryAccount(): DepositHistoryAccount;
100
- getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
101
- getFundingRateHistoryAccount(): FundingRateHistoryAccount;
102
- getCurveHistoryAccount(): CurveHistoryAccount;
67
+ getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
103
68
  getLiquidationHistoryAccount(): LiquidationHistoryAccount;
104
69
  }
105
70
 
106
71
  export interface UserAccountEvents {
107
72
  userAccountData: (payload: UserAccount) => void;
108
73
  userPositionsData: (payload: UserPositionsAccount) => void;
109
- userOrdersData: (payload: UserOrdersAccount) => void;
110
74
  update: void;
111
75
  }
112
76
 
@@ -120,5 +84,4 @@ export interface UserAccountSubscriber {
120
84
 
121
85
  getUserAccount(): UserAccount;
122
86
  getUserPositionsAccount(): UserPositionsAccount;
123
- getUserOrdersAccount(): UserOrdersAccount;
124
87
  }
package/src/addresses.ts CHANGED
@@ -10,21 +10,6 @@ export async function getClearingHouseStateAccountPublicKeyAndNonce(
10
10
  );
11
11
  }
12
12
 
13
- export async function getOrderStateAccountPublicKey(
14
- programId: PublicKey
15
- ): Promise<PublicKey> {
16
- return (await getOrderStateAccountPublicKeyAndNonce(programId))[0];
17
- }
18
-
19
- export async function getOrderStateAccountPublicKeyAndNonce(
20
- programId: PublicKey
21
- ): Promise<[PublicKey, number]> {
22
- return anchor.web3.PublicKey.findProgramAddress(
23
- [Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))],
24
- programId
25
- );
26
- }
27
-
28
13
  export async function getClearingHouseStateAccountPublicKey(
29
14
  programId: PublicKey
30
15
  ): Promise<PublicKey> {
@@ -47,23 +32,3 @@ export async function getUserAccountPublicKey(
47
32
  ): Promise<PublicKey> {
48
33
  return (await getUserAccountPublicKeyAndNonce(programId, authority))[0];
49
34
  }
50
-
51
- export async function getUserOrdersAccountPublicKeyAndNonce(
52
- programId: PublicKey,
53
- authority: PublicKey
54
- ): Promise<[PublicKey, number]> {
55
- return anchor.web3.PublicKey.findProgramAddress(
56
- [
57
- Buffer.from(anchor.utils.bytes.utf8.encode('user_orders')),
58
- authority.toBuffer(),
59
- ],
60
- programId
61
- );
62
- }
63
-
64
- export async function getUserOrdersAccountPublicKey(
65
- programId: PublicKey,
66
- authority: PublicKey
67
- ): Promise<PublicKey> {
68
- return (await getUserOrdersAccountPublicKeyAndNonce(programId, authority))[0];
69
- }
package/src/admin.ts CHANGED
@@ -5,20 +5,10 @@ import {
5
5
  SYSVAR_RENT_PUBKEY,
6
6
  TransactionSignature,
7
7
  } from '@solana/web3.js';
8
- import {
9
- FeeStructure,
10
- IWallet,
11
- OracleGuardRails,
12
- OracleSource,
13
- OrderFillerRewardStructure,
14
- } from './types';
8
+ import { FeeStructure, IWallet, OracleGuardRails, OracleSource } from './types';
15
9
  import { BN, Idl, Program, Provider } from '@project-serum/anchor';
16
10
  import * as anchor from '@project-serum/anchor';
17
- import {
18
- getClearingHouseStateAccountPublicKey,
19
- getClearingHouseStateAccountPublicKeyAndNonce,
20
- getOrderStateAccountPublicKeyAndNonce,
21
- } from './addresses';
11
+ import { getClearingHouseStateAccountPublicKeyAndNonce } from './addresses';
22
12
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
23
13
  import { ClearingHouse } from './clearingHouse';
24
14
  import { PEG_PRECISION } from './constants/numericConstants';
@@ -58,9 +48,7 @@ export class Admin extends ClearingHouse {
58
48
  public async initialize(
59
49
  usdcMint: PublicKey,
60
50
  adminControlsPrices: boolean
61
- ): Promise<
62
- [TransactionSignature, TransactionSignature, TransactionSignature]
63
- > {
51
+ ): Promise<[TransactionSignature, TransactionSignature]> {
64
52
  const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(
65
53
  await this.getStatePublicKey()
66
54
  );
@@ -165,7 +153,7 @@ export class Admin extends ClearingHouse {
165
153
  await this.program.account.depositHistory.createInstruction(
166
154
  depositHistory
167
155
  ),
168
- await this.program.account.curveHistory.createInstruction(
156
+ await this.program.account.extendedCurveHistory.createInstruction(
169
157
  curveHistory
170
158
  ),
171
159
  ],
@@ -184,40 +172,7 @@ export class Admin extends ClearingHouse {
184
172
  this.opts
185
173
  );
186
174
 
187
- const initializeOrderStateTxSig = await this.initializeOrderState();
188
-
189
- return [initializeTxSig, initializeHistoryTxSig, initializeOrderStateTxSig];
190
- }
191
-
192
- public async initializeOrderState(): Promise<TransactionSignature> {
193
- const orderHistory = anchor.web3.Keypair.generate();
194
- const [orderStatePublicKey, orderStateNonce] =
195
- await getOrderStateAccountPublicKeyAndNonce(this.program.programId);
196
- const clearingHouseStatePublicKey =
197
- await getClearingHouseStateAccountPublicKey(this.program.programId);
198
-
199
- const initializeOrderStateTx =
200
- await this.program.transaction.initializeOrderState(orderStateNonce, {
201
- accounts: {
202
- admin: this.wallet.publicKey,
203
- state: clearingHouseStatePublicKey,
204
- orderHistory: orderHistory.publicKey,
205
- orderState: orderStatePublicKey,
206
- rent: SYSVAR_RENT_PUBKEY,
207
- systemProgram: anchor.web3.SystemProgram.programId,
208
- },
209
- instructions: [
210
- await this.program.account.orderHistory.createInstruction(
211
- orderHistory
212
- ),
213
- ],
214
- });
215
-
216
- return await this.txSender.send(
217
- initializeOrderStateTx,
218
- [orderHistory],
219
- this.opts
220
- );
175
+ return [initializeTxSig, initializeHistoryTxSig];
221
176
  }
222
177
 
223
178
  public async initializeMarket(
@@ -275,13 +230,38 @@ export class Admin extends ClearingHouse {
275
230
  marketIndex: BN
276
231
  ): Promise<TransactionSignature> {
277
232
  const state = this.getStateAccount();
233
+ const markets = this.getMarketsAccount();
234
+ const marketData = markets.markets[marketIndex.toNumber()];
235
+ const ammData = marketData.amm;
236
+
278
237
  return await this.program.rpc.updateK(sqrtK, marketIndex, {
279
238
  accounts: {
280
239
  state: await this.getStatePublicKey(),
281
240
  admin: this.wallet.publicKey,
282
241
  markets: state.markets,
242
+ curveHistory: state.extendedCurveHistory,
243
+ oracle: ammData.oracle,
244
+ },
245
+ });
246
+ }
247
+
248
+ public async updateCurveHistory(): Promise<TransactionSignature> {
249
+ const extendedCurveHistory = anchor.web3.Keypair.generate();
250
+
251
+ const state = this.getStateAccount();
252
+ return await this.program.rpc.updateCurveHistory({
253
+ accounts: {
254
+ state: await this.getStatePublicKey(),
255
+ admin: this.wallet.publicKey,
283
256
  curveHistory: state.curveHistory,
257
+ extendedCurveHistory: extendedCurveHistory.publicKey,
284
258
  },
259
+ instructions: [
260
+ await this.program.account.extendedCurveHistory.createInstruction(
261
+ extendedCurveHistory
262
+ ),
263
+ ],
264
+ signers: [extendedCurveHistory],
285
265
  });
286
266
  }
287
267
 
@@ -334,7 +314,26 @@ export class Admin extends ClearingHouse {
334
314
  admin: this.wallet.publicKey,
335
315
  oracle: ammData.oracle,
336
316
  markets: state.markets,
337
- curveHistory: state.curveHistory,
317
+ curveHistory: state.extendedCurveHistory,
318
+ },
319
+ });
320
+ }
321
+
322
+ public async updateAmmOracleTwap(
323
+ marketIndex: BN
324
+ ): Promise<TransactionSignature> {
325
+ const state = this.getStateAccount();
326
+ const markets = this.getMarketsAccount();
327
+ const marketData = markets.markets[marketIndex.toNumber()];
328
+ const ammData = marketData.amm;
329
+
330
+ return await this.program.rpc.updateAmmOracleTwap(marketIndex, {
331
+ accounts: {
332
+ state: await this.getStatePublicKey(),
333
+ admin: this.wallet.publicKey,
334
+ oracle: ammData.oracle,
335
+ markets: state.markets,
336
+ curveHistory: state.extendedCurveHistory,
338
337
  },
339
338
  });
340
339
  }
@@ -500,21 +499,6 @@ export class Admin extends ClearingHouse {
500
499
  );
501
500
  }
502
501
 
503
- public async updateOrderFillerRewardStructure(
504
- orderFillerRewardStructure: OrderFillerRewardStructure
505
- ): Promise<TransactionSignature> {
506
- return await this.program.rpc.updateOrderFillerRewardStructure(
507
- orderFillerRewardStructure,
508
- {
509
- accounts: {
510
- admin: this.wallet.publicKey,
511
- state: await this.getStatePublicKey(),
512
- orderState: await this.getOrderStatePublicKey(),
513
- },
514
- }
515
- );
516
- }
517
-
518
502
  public async updateFee(fees: FeeStructure): Promise<TransactionSignature> {
519
503
  return await this.program.rpc.updateFee(fees, {
520
504
  accounts: {
@@ -555,30 +539,12 @@ export class Admin extends ClearingHouse {
555
539
  );
556
540
  }
557
541
 
558
- public async updateMarketMinimumQuoteAssetTradeSize(
559
- marketIndex: BN,
560
- minimumTradeSize: BN
561
- ): Promise<TransactionSignature> {
562
- const state = this.getStateAccount();
563
- return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(
564
- marketIndex,
565
- minimumTradeSize,
566
- {
567
- accounts: {
568
- admin: this.wallet.publicKey,
569
- state: await this.getStatePublicKey(),
570
- markets: state.markets,
571
- },
572
- }
573
- );
574
- }
575
-
576
- public async updateMarketMinimumBaseAssetTradeSize(
542
+ public async updateMarketMinimumTradeSize(
577
543
  marketIndex: BN,
578
544
  minimumTradeSize: BN
579
545
  ): Promise<TransactionSignature> {
580
546
  const state = this.getStateAccount();
581
- return await this.program.rpc.updateMarketMinimumBaseAssetTradeSize(
547
+ return await this.program.rpc.updateMarketMinimumTradeSize(
582
548
  marketIndex,
583
549
  minimumTradeSize,
584
550
  {