@drift-labs/sdk 0.1.29 → 0.1.30-master.2

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 (85) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -1
  2. package/lib/accounts/bulkAccountLoader.js +44 -32
  3. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +15 -0
  4. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +50 -23
  5. package/lib/clearingHouse.d.ts +0 -1
  6. package/lib/clearingHouse.js +0 -14
  7. package/lib/constants/accounts.d.ts +15 -0
  8. package/lib/constants/accounts.js +18 -0
  9. package/lib/factory/clearingHouse.d.ts +14 -4
  10. package/lib/factory/clearingHouse.js +23 -6
  11. package/lib/idl/clearing_house.json +2 -33
  12. package/lib/index.d.ts +0 -1
  13. package/lib/index.js +0 -1
  14. package/lib/math/amm.d.ts +20 -0
  15. package/lib/math/amm.js +151 -1
  16. package/lib/tx/retryTxSender.d.ts +5 -2
  17. package/lib/tx/retryTxSender.js +14 -1
  18. package/lib/util/promiseTimeout.d.ts +1 -0
  19. package/lib/util/promiseTimeout.js +14 -0
  20. package/package.json +1 -1
  21. package/src/accounts/bulkAccountLoader.ts +51 -40
  22. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +73 -30
  23. package/src/clearingHouse.ts +0 -13
  24. package/src/constants/accounts.ts +26 -0
  25. package/src/factory/clearingHouse.ts +47 -7
  26. package/src/idl/clearing_house.json +2 -33
  27. package/src/index.ts +0 -1
  28. package/src/math/amm.ts +212 -1
  29. package/src/tx/retryTxSender.ts +19 -1
  30. package/src/util/promiseTimeout.ts +14 -0
  31. package/lib/math/repeg.d.ts +0 -32
  32. package/lib/math/repeg.js +0 -178
  33. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -210
  34. package/src/accounts/pollingClearingHouseAccountSubscriber.js.map +0 -1
  35. package/src/accounts/pollingOracleSubscriber.js +0 -65
  36. package/src/accounts/pollingOracleSubscriber.js.map +0 -1
  37. package/src/accounts/pollingTokenAccountSubscriber.js +0 -65
  38. package/src/accounts/pollingTokenAccountSubscriber.js.map +0 -1
  39. package/src/accounts/utils.js +0 -8
  40. package/src/accounts/utils.js.map +0 -1
  41. package/src/accounts/webSocketAccountSubscriber.js +0 -64
  42. package/src/accounts/webSocketAccountSubscriber.js.map +0 -1
  43. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -212
  44. package/src/accounts/webSocketClearingHouseAccountSubscriber.js.map +0 -1
  45. package/src/assert/assert.js +0 -10
  46. package/src/assert/assert.js.map +0 -1
  47. package/src/constants/markets.js +0 -167
  48. package/src/constants/markets.js.map +0 -1
  49. package/src/constants/numericConstants.js +0 -22
  50. package/src/constants/numericConstants.js.map +0 -1
  51. package/src/math/conversion.js +0 -16
  52. package/src/math/conversion.js.map +0 -1
  53. package/src/math/funding.js +0 -223
  54. package/src/math/funding.js.map +0 -1
  55. package/src/math/insuranceFund.js +0 -23
  56. package/src/math/insuranceFund.js.map +0 -1
  57. package/src/math/market.js +0 -30
  58. package/src/math/market.js.map +0 -1
  59. package/src/math/orders.js +0 -73
  60. package/src/math/orders.js.map +0 -1
  61. package/src/math/position.js +0 -121
  62. package/src/math/position.js.map +0 -1
  63. package/src/math/repeg.ts +0 -253
  64. package/src/math/trade.js +0 -182
  65. package/src/math/trade.js.map +0 -1
  66. package/src/math/utils.js +0 -27
  67. package/src/math/utils.js.map +0 -1
  68. package/src/oracles/switchboardClient.js +0 -60
  69. package/src/oracles/switchboardClient.js.map +0 -1
  70. package/src/oracles/types.js +0 -3
  71. package/src/oracles/types.js.map +0 -1
  72. package/src/token/index.js +0 -39
  73. package/src/token/index.js.map +0 -1
  74. package/src/tx/defaultTxSender.js +0 -13
  75. package/src/tx/defaultTxSender.js.map +0 -1
  76. package/src/tx/retryTxSender.js +0 -137
  77. package/src/tx/retryTxSender.js.map +0 -1
  78. package/src/tx/types.js +0 -3
  79. package/src/tx/types.js.map +0 -1
  80. package/src/tx/utils.js +0 -9
  81. package/src/tx/utils.js.map +0 -1
  82. package/src/util/computeUnits.js +0 -17
  83. package/src/util/computeUnits.js.map +0 -1
  84. package/src/util/tps.js +0 -17
  85. package/src/util/tps.js.map +0 -1
@@ -16,7 +16,7 @@ export declare class BulkAccountLoader {
16
16
  loadPromise?: Promise<void>;
17
17
  loadPromiseResolver: () => void;
18
18
  loggingEnabled: boolean;
19
- lastUpdate: number;
19
+ lastTimeLoadingPromiseCleared: number;
20
20
  constructor(connection: Connection, commitment: Commitment, pollingFrequency: number);
21
21
  addAccount(publicKey: PublicKey, callback: (buffer: Buffer) => void): string;
22
22
  removeAccount(publicKey: PublicKey, callbackId: string): void;
@@ -29,5 +29,6 @@ export declare class BulkAccountLoader {
29
29
  getAccountData(publicKey: PublicKey): Buffer | undefined;
30
30
  startPolling(): void;
31
31
  stopPolling(): void;
32
+ log(msg: string, force?: boolean): void;
32
33
  }
33
34
  export {};
@@ -10,18 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BulkAccountLoader = void 0;
13
- const web3_js_1 = require("@solana/web3.js");
14
13
  const uuid_1 = require("uuid");
14
+ const promiseTimeout_1 = require("../util/promiseTimeout");
15
15
  const GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = 99;
16
16
  const oneMinute = 60 * 1000;
17
- const fiveMinutes = 5 * 60 * 1000;
18
17
  class BulkAccountLoader {
19
18
  constructor(connection, commitment, pollingFrequency) {
20
19
  this.accountsToLoad = new Map();
21
20
  this.accountData = new Map();
22
21
  this.errorCallbacks = new Map();
23
22
  this.loggingEnabled = false;
24
- this.lastUpdate = Date.now();
23
+ this.lastTimeLoadingPromiseCleared = Date.now();
25
24
  this.connection = connection;
26
25
  this.commitment = commitment;
27
26
  this.pollingFrequency = pollingFrequency;
@@ -29,11 +28,14 @@ class BulkAccountLoader {
29
28
  addAccount(publicKey, callback) {
30
29
  const existingSize = this.accountsToLoad.size;
31
30
  const callbackId = (0, uuid_1.v4)();
31
+ this.log(`Adding account ${publicKey.toString()} callback id ${callbackId}`);
32
32
  const existingAccountToLoad = this.accountsToLoad.get(publicKey.toString());
33
33
  if (existingAccountToLoad) {
34
+ this.log(`account already exists`);
34
35
  existingAccountToLoad.callbacks.set(callbackId, callback);
35
36
  }
36
37
  else {
38
+ this.log(`account doesn't already exist. creating new callback map`);
37
39
  const callbacks = new Map();
38
40
  callbacks.set(callbackId, callback);
39
41
  const newAccountToLoad = {
@@ -50,6 +52,7 @@ class BulkAccountLoader {
50
52
  return callbackId;
51
53
  }
52
54
  removeAccount(publicKey, callbackId) {
55
+ this.log(`Removing account ${publicKey.toString()} callback id ${callbackId}`);
53
56
  const existingAccountToLoad = this.accountsToLoad.get(publicKey.toString());
54
57
  if (existingAccountToLoad) {
55
58
  existingAccountToLoad.callbacks.delete(callbackId);
@@ -78,13 +81,24 @@ class BulkAccountLoader {
78
81
  load() {
79
82
  return __awaiter(this, void 0, void 0, function* () {
80
83
  if (this.loadPromise) {
81
- return this.loadPromise;
84
+ const now = Date.now();
85
+ if (now - this.lastTimeLoadingPromiseCleared > oneMinute) {
86
+ this.log(`Load promise hasnt been clearing for one minute. Clearing.`);
87
+ this.loadPromise = undefined;
88
+ }
89
+ else {
90
+ this.log(`Load promise exists. Returning early`);
91
+ return this.loadPromise;
92
+ }
82
93
  }
83
94
  this.loadPromise = new Promise((resolver) => {
84
95
  this.loadPromiseResolver = resolver;
85
96
  });
97
+ this.lastTimeLoadingPromiseCleared = Date.now();
98
+ this.log(`Loading`);
86
99
  try {
87
100
  const chunks = this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE);
101
+ this.log(`${chunks.length} chunks`);
88
102
  yield Promise.all(chunks.map((chunk) => {
89
103
  return this.loadChunk(chunk);
90
104
  }));
@@ -95,25 +109,19 @@ class BulkAccountLoader {
95
109
  for (const [_, callback] of this.errorCallbacks) {
96
110
  callback(e);
97
111
  }
112
+ this.log('finished error callbacks');
98
113
  }
99
114
  finally {
115
+ this.log(`resetting load promise`);
100
116
  this.loadPromiseResolver();
101
117
  this.loadPromise = undefined;
102
- const now = Date.now();
103
- if (now - this.lastUpdate > fiveMinutes) {
104
- if (this.loggingEnabled) {
105
- console.log("Haven't seen updated account in five minutes. Bulk account loader creating new Connection Object");
106
- }
107
- this.connection = new web3_js_1.Connection(
108
- // @ts-ignore
109
- this.connection._rpcEndpoint, this.connection.commitment);
110
- }
111
118
  }
112
119
  });
113
120
  }
114
121
  loadChunk(accountsToLoad) {
115
122
  return __awaiter(this, void 0, void 0, function* () {
116
123
  if (accountsToLoad.length === 0) {
124
+ this.log(`no accounts in chunk`);
117
125
  return;
118
126
  }
119
127
  const args = [
@@ -122,11 +130,13 @@ class BulkAccountLoader {
122
130
  }),
123
131
  { commitment: this.commitment },
124
132
  ];
133
+ const rpcResponse = yield (0, promiseTimeout_1.promiseTimeout)(
125
134
  // @ts-ignore
126
- const rpcResponse = yield this.connection._rpcRequest('getMultipleAccounts', args);
127
- const oneMinuteSinceLastUpdate = Date.now() - this.lastUpdate > oneMinute;
128
- if (this.loggingEnabled && oneMinuteSinceLastUpdate) {
129
- console.log('rpcResponse', JSON.stringify(rpcResponse));
135
+ this.connection._rpcRequest('getMultipleAccounts', args), 10 * 1000 // 30 second timeout
136
+ );
137
+ if (rpcResponse === null) {
138
+ this.log('request to rpc timed out', true);
139
+ return;
130
140
  }
131
141
  const newSlot = rpcResponse.result.context.slot;
132
142
  for (const i in accountsToLoad) {
@@ -139,42 +149,43 @@ class BulkAccountLoader {
139
149
  const dataType = rpcResponse.result.value[i].data[1];
140
150
  newBuffer = Buffer.from(raw, dataType);
141
151
  }
142
- if (this.loggingEnabled && oneMinuteSinceLastUpdate) {
143
- console.log('oldRPCResponse', oldRPCResponse);
144
- }
145
152
  if (!oldRPCResponse) {
153
+ this.log('No old rpc response, updating account data');
146
154
  this.accountData.set(key, {
147
155
  slot: newSlot,
148
156
  buffer: newBuffer,
149
157
  });
150
158
  this.handleAccountCallbacks(accountToLoad, newBuffer);
151
- this.lastUpdate = Date.now();
152
159
  continue;
153
160
  }
154
161
  if (newSlot <= oldRPCResponse.slot) {
162
+ this.log(`new slot ${newSlot} old slot ${oldRPCResponse.slot}`);
155
163
  continue;
156
164
  }
157
165
  const oldBuffer = oldRPCResponse.buffer;
158
166
  if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
167
+ this.log('new buffer, updating account data');
159
168
  this.accountData.set(key, {
160
169
  slot: newSlot,
161
170
  buffer: newBuffer,
162
171
  });
163
172
  this.handleAccountCallbacks(accountToLoad, newBuffer);
164
- this.lastUpdate = Date.now();
165
173
  }
166
- else if (this.loggingEnabled) {
167
- console.log('unable to update account for newest slot');
168
- console.log('oldBuffer', oldBuffer);
169
- console.log('newBuffer', newBuffer);
174
+ else {
175
+ this.log('unable to update account for newest slot');
176
+ this.log('oldBuffer ' + oldBuffer);
177
+ this.log('newBuffer ' + newBuffer);
178
+ this.log('buffers equal ' + (newBuffer === null || newBuffer === void 0 ? void 0 : newBuffer.equals(oldBuffer)));
170
179
  }
171
180
  }
172
181
  });
173
182
  }
174
183
  handleAccountCallbacks(accountToLoad, buffer) {
184
+ this.log('handling account callbacks');
175
185
  for (const [_, callback] of accountToLoad.callbacks) {
176
186
  callback(buffer);
177
187
  }
188
+ this.log('finished account callbacks');
178
189
  }
179
190
  getAccountData(publicKey) {
180
191
  const accountData = this.accountData.get(publicKey.toString());
@@ -184,18 +195,19 @@ class BulkAccountLoader {
184
195
  if (this.intervalId) {
185
196
  return;
186
197
  }
187
- if (this.loggingEnabled) {
188
- console.log(`startPolling`);
189
- }
198
+ this.log('startPolling');
190
199
  this.intervalId = setInterval(this.load.bind(this), this.pollingFrequency);
191
200
  }
192
201
  stopPolling() {
193
202
  if (this.intervalId) {
194
203
  clearInterval(this.intervalId);
195
204
  this.intervalId = undefined;
196
- if (this.loggingEnabled) {
197
- console.log(`stopPolling`);
198
- }
205
+ this.log('stopPolling');
206
+ }
207
+ }
208
+ log(msg, force = false) {
209
+ if (this.loggingEnabled || force) {
210
+ console.log(msg);
199
211
  }
200
212
  }
201
213
  }
@@ -6,6 +6,7 @@ import { EventEmitter } from 'events';
6
6
  import { DepositHistoryAccount, ExtendedCurveHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, OrderHistoryAccount, OrderStateAccount, StateAccount, TradeHistoryAccount } from '../types';
7
7
  import { BulkAccountLoader } from './bulkAccountLoader';
8
8
  import { ClearingHouseConfigType } from '../factory/clearingHouse';
9
+ import { PublicKey } from '@solana/web3.js';
9
10
  export declare class PollingClearingHouseAccountSubscriber implements ClearingHouseAccountSubscriber {
10
11
  isSubscribed: boolean;
11
12
  program: Program;
@@ -31,6 +32,7 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
31
32
  constructor(program: Program, accountLoader: BulkAccountLoader);
32
33
  subscribe(optionalSubscriptions?: ClearingHouseAccountTypes[]): Promise<boolean>;
33
34
  updateAccountsToPoll(): Promise<void>;
35
+ getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
34
36
  addToAccountLoader(): Promise<void>;
35
37
  fetch(): Promise<void>;
36
38
  unsubscribe(): Promise<void>;
@@ -47,3 +49,16 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
47
49
  getLiquidationHistoryAccount(): LiquidationHistoryAccount;
48
50
  getOrderHistoryAccount(): OrderHistoryAccount;
49
51
  }
52
+ declare type ClearingHouseAccounts = {
53
+ state: PublicKey;
54
+ markets: PublicKey;
55
+ orderState: PublicKey;
56
+ tradeHistory?: PublicKey;
57
+ depositHistory?: PublicKey;
58
+ fundingPaymentHistory?: PublicKey;
59
+ fundingRateHistory?: PublicKey;
60
+ extendedCurveHistory?: PublicKey;
61
+ liquidationHistory?: PublicKey;
62
+ orderHistory?: PublicKey;
63
+ };
64
+ export {};
@@ -14,6 +14,7 @@ const types_1 = require("./types");
14
14
  const events_1 = require("events");
15
15
  const addresses_1 = require("../addresses");
16
16
  const utils_1 = require("./utils");
17
+ const accounts_1 = require("../constants/accounts");
17
18
  class PollingClearingHouseAccountSubscriber {
18
19
  constructor(program, accountLoader) {
19
20
  this.accountsToPoll = new Map();
@@ -54,75 +55,101 @@ class PollingClearingHouseAccountSubscriber {
54
55
  if (this.accountsToPoll.size > 0) {
55
56
  return;
56
57
  }
57
- const statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
58
- const state = (yield this.program.account.state.fetch(statePublicKey));
59
- this.accountsToPoll.set(statePublicKey.toString(), {
58
+ const accounts = yield this.getClearingHouseAccounts();
59
+ this.accountsToPoll.set(accounts.state.toString(), {
60
60
  key: 'state',
61
- publicKey: statePublicKey,
61
+ publicKey: accounts.state,
62
62
  eventType: 'stateAccountUpdate',
63
63
  });
64
- this.accountsToPoll.set(state.markets.toString(), {
64
+ this.accountsToPoll.set(accounts.markets.toString(), {
65
65
  key: 'markets',
66
- publicKey: state.markets,
66
+ publicKey: accounts.markets,
67
67
  eventType: 'marketsAccountUpdate',
68
68
  });
69
- this.accountsToPoll.set(state.orderState.toString(), {
69
+ this.accountsToPoll.set(accounts.orderState.toString(), {
70
70
  key: 'orderState',
71
- publicKey: state.orderState,
71
+ publicKey: accounts.orderState,
72
72
  eventType: 'orderStateAccountUpdate',
73
73
  });
74
74
  if ((_a = this.optionalExtraSubscriptions) === null || _a === void 0 ? void 0 : _a.includes('tradeHistoryAccount')) {
75
- this.accountsToPoll.set(state.tradeHistory.toString(), {
75
+ this.accountsToPoll.set(accounts.tradeHistory.toString(), {
76
76
  key: 'tradeHistory',
77
- publicKey: state.tradeHistory,
77
+ publicKey: accounts.tradeHistory,
78
78
  eventType: 'tradeHistoryAccountUpdate',
79
79
  });
80
80
  }
81
81
  if ((_b = this.optionalExtraSubscriptions) === null || _b === void 0 ? void 0 : _b.includes('depositHistoryAccount')) {
82
- this.accountsToPoll.set(state.depositHistory.toString(), {
82
+ this.accountsToPoll.set(accounts.depositHistory.toString(), {
83
83
  key: 'depositHistory',
84
- publicKey: state.depositHistory,
84
+ publicKey: accounts.depositHistory,
85
85
  eventType: 'depositHistoryAccountUpdate',
86
86
  });
87
87
  }
88
88
  if ((_c = this.optionalExtraSubscriptions) === null || _c === void 0 ? void 0 : _c.includes('fundingPaymentHistoryAccount')) {
89
- this.accountsToPoll.set(state.fundingPaymentHistory.toString(), {
89
+ this.accountsToPoll.set(accounts.fundingPaymentHistory.toString(), {
90
90
  key: 'fundingPaymentHistory',
91
- publicKey: state.fundingPaymentHistory,
91
+ publicKey: accounts.fundingPaymentHistory,
92
92
  eventType: 'fundingPaymentHistoryAccountUpdate',
93
93
  });
94
94
  }
95
95
  if ((_d = this.optionalExtraSubscriptions) === null || _d === void 0 ? void 0 : _d.includes('fundingRateHistoryAccount')) {
96
- this.accountsToPoll.set(state.fundingRateHistory.toString(), {
96
+ this.accountsToPoll.set(accounts.fundingRateHistory.toString(), {
97
97
  key: 'fundingRateHistory',
98
- publicKey: state.fundingRateHistory,
98
+ publicKey: accounts.fundingRateHistory,
99
99
  eventType: 'fundingRateHistoryAccountUpdate',
100
100
  });
101
101
  }
102
102
  if ((_e = this.optionalExtraSubscriptions) === null || _e === void 0 ? void 0 : _e.includes('curveHistoryAccount')) {
103
- this.accountsToPoll.set(state.extendedCurveHistory.toString(), {
103
+ this.accountsToPoll.set(accounts.extendedCurveHistory.toString(), {
104
104
  key: 'extendedCurveHistory',
105
- publicKey: state.extendedCurveHistory,
105
+ publicKey: accounts.extendedCurveHistory,
106
106
  eventType: 'curveHistoryAccountUpdate',
107
107
  });
108
108
  }
109
109
  if ((_f = this.optionalExtraSubscriptions) === null || _f === void 0 ? void 0 : _f.includes('liquidationHistoryAccount')) {
110
- this.accountsToPoll.set(state.liquidationHistory.toString(), {
110
+ this.accountsToPoll.set(accounts.liquidationHistory.toString(), {
111
111
  key: 'liquidationHistory',
112
- publicKey: state.liquidationHistory,
112
+ publicKey: accounts.liquidationHistory,
113
113
  eventType: 'liquidationHistoryAccountUpdate',
114
114
  });
115
115
  }
116
116
  if ((_g = this.optionalExtraSubscriptions) === null || _g === void 0 ? void 0 : _g.includes('orderHistoryAccount')) {
117
- const orderState = (yield this.program.account.orderState.fetch(state.orderState));
118
- this.accountsToPoll.set(orderState.orderHistory.toString(), {
117
+ this.accountsToPoll.set(accounts.orderHistory.toString(), {
119
118
  key: 'orderHistory',
120
- publicKey: orderState.orderHistory,
119
+ publicKey: accounts.orderHistory,
121
120
  eventType: 'orderHistoryAccountUpdate',
122
121
  });
123
122
  }
124
123
  });
125
124
  }
125
+ getClearingHouseAccounts() {
126
+ var _a;
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ // Skip extra calls to rpc if we already know all the accounts
129
+ if (accounts_1.CLEARING_HOUSE_STATE_ACCOUNTS[this.program.programId.toString()]) {
130
+ return accounts_1.CLEARING_HOUSE_STATE_ACCOUNTS[this.program.programId.toString()];
131
+ }
132
+ const statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
133
+ const state = (yield this.program.account.state.fetch(statePublicKey));
134
+ const accounts = {
135
+ state: statePublicKey,
136
+ markets: state.markets,
137
+ orderState: state.orderState,
138
+ tradeHistory: state.tradeHistory,
139
+ depositHistory: state.depositHistory,
140
+ fundingPaymentHistory: state.fundingPaymentHistory,
141
+ fundingRateHistory: state.fundingRateHistory,
142
+ extendedCurveHistory: state.extendedCurveHistory,
143
+ liquidationHistory: state.liquidationHistory,
144
+ orderHistory: undefined,
145
+ };
146
+ if ((_a = this.optionalExtraSubscriptions) === null || _a === void 0 ? void 0 : _a.includes('orderHistoryAccount')) {
147
+ const orderState = (yield this.program.account.orderState.fetch(state.orderState));
148
+ accounts.orderHistory = orderState.orderHistory;
149
+ }
150
+ return accounts;
151
+ });
152
+ }
126
153
  addToAccountLoader() {
127
154
  return __awaiter(this, void 0, void 0, function* () {
128
155
  for (const [_, accountToPoll] of this.accountsToPoll) {
@@ -113,7 +113,6 @@ export declare class ClearingHouse {
113
113
  */
114
114
  initializeUserAccountAndDepositCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<[TransactionSignature, PublicKey]>;
115
115
  initializeUserAccountForDevnet(mockUSDCFaucet: MockUSDCFaucet, amount: BN): Promise<[TransactionSignature, PublicKey]>;
116
- deleteUser(): Promise<TransactionSignature>;
117
116
  withdrawCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
118
117
  getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
119
118
  openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
@@ -371,20 +371,6 @@ class ClearingHouse {
371
371
  return [txSig, userAccountPublicKey];
372
372
  });
373
373
  }
374
- deleteUser() {
375
- return __awaiter(this, void 0, void 0, function* () {
376
- const userAccountPublicKey = yield this.getUserAccountPublicKey();
377
- const user = yield this.program.account.user.fetch(userAccountPublicKey);
378
- const deleteUserTx = yield this.program.transaction.deleteUser({
379
- accounts: {
380
- user: userAccountPublicKey,
381
- userPositions: user.positions,
382
- authority: this.wallet.publicKey,
383
- },
384
- });
385
- return this.txSender.send(deleteUserTx, [], this.opts);
386
- });
387
- }
388
374
  withdrawCollateral(amount, collateralAccountPublicKey) {
389
375
  return __awaiter(this, void 0, void 0, function* () {
390
376
  return this.txSender.send((0, utils_1.wrapInTx)(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
@@ -0,0 +1,15 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ export declare const CLEARING_HOUSE_STATE_ACCOUNTS: {
3
+ dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
4
+ state: PublicKey;
5
+ markets: PublicKey;
6
+ orderState: PublicKey;
7
+ tradeHistory: PublicKey;
8
+ depositHistory: PublicKey;
9
+ fundingPaymentHistory: PublicKey;
10
+ fundingRateHistory: PublicKey;
11
+ extendedCurveHistory: PublicKey;
12
+ liquidationHistory: PublicKey;
13
+ orderHistory: PublicKey;
14
+ };
15
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLEARING_HOUSE_STATE_ACCOUNTS = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ exports.CLEARING_HOUSE_STATE_ACCOUNTS = {
6
+ dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
7
+ state: new web3_js_1.PublicKey('FExhvPycCCwYnZGeDsVtLhpEQ3yEkVY2k1HuPyfLj91L'),
8
+ markets: new web3_js_1.PublicKey('773hq3SbGPKVj93TXi5qV5CREuhxobywfALjS3XVHhLH'),
9
+ orderState: new web3_js_1.PublicKey('4cC34bWwTPGncBaX2S6v5mH3Lj4Nb3byPMrxQSDcY985'),
10
+ tradeHistory: new web3_js_1.PublicKey('FCuCXEoQppoaCYdttA7rK3HNQfYkTNEGpwuBESzYcENp'),
11
+ depositHistory: new web3_js_1.PublicKey('C7rF2Qy2rnDGQLRijBRRArJyaeuQcFi81BXDrUCQ45ya'),
12
+ fundingPaymentHistory: new web3_js_1.PublicKey('895iPhzwT2tBufLnRpYtBG3gif1HDDUfpH2AqbS5joo4'),
13
+ fundingRateHistory: new web3_js_1.PublicKey('BWiJLMbmrwfqHVpcPJa8715XamNyNYamDDKQVQMnduEC'),
14
+ extendedCurveHistory: new web3_js_1.PublicKey('7vBbqvMdtZLQdTVdzt5y63pZdAFE5W42kP3avngSJKCk'),
15
+ liquidationHistory: new web3_js_1.PublicKey('CSFaaf8yVoTx6NcXUKtNPYAewv76CH2jATqSVRBvUWKM'),
16
+ orderHistory: new web3_js_1.PublicKey('DZ7XfUqyHoRKnJLRApxmJ943xHJ7NDBUTqpbooviEtbU'),
17
+ },
18
+ };
@@ -1,7 +1,6 @@
1
1
  import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
2
2
  import { IWallet } from '../types';
3
3
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
- import { TxSender } from '../tx/types';
5
4
  import { ClearingHouse } from '../clearingHouse';
6
5
  import { Admin } from '../admin';
7
6
  export declare type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
@@ -11,15 +10,26 @@ declare type BaseClearingHouseConfig = {
11
10
  wallet: IWallet;
12
11
  programID: PublicKey;
13
12
  opts?: ConfirmOptions;
14
- txSender?: TxSender;
13
+ txSenderConfig?: TxSenderConfig;
15
14
  };
16
15
  declare type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
17
16
  declare type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
18
17
  accountLoader: BulkAccountLoader;
19
18
  };
20
19
  declare type ClearingHouseConfig = PollingClearingHouseConfiguration | WebSocketClearingHouseConfiguration;
21
- export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSender?: TxSender): WebSocketClearingHouseConfiguration;
22
- export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSender?: TxSender): PollingClearingHouseConfiguration;
20
+ export declare type TxSenderType = 'default' | 'retry';
21
+ declare type BaseTxSenderConfig = {
22
+ type: TxSenderType;
23
+ };
24
+ declare type DefaultTxSenderConfig = BaseTxSenderConfig;
25
+ declare type RetryTxSenderConfig = BaseTxSenderConfig & {
26
+ timeout?: number;
27
+ retrySleep?: number;
28
+ additionalConnections?: Connection[];
29
+ };
30
+ declare type TxSenderConfig = DefaultTxSenderConfig | RetryTxSenderConfig;
31
+ export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): WebSocketClearingHouseConfiguration;
32
+ export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): PollingClearingHouseConfiguration;
23
33
  export declare function getClearingHouse(config: ClearingHouseConfig): ClearingHouse;
24
34
  export declare function getAdmin(config: ClearingHouseConfig): Admin;
25
35
  export {};
@@ -11,18 +11,19 @@ const webSocketClearingHouseAccountSubscriber_1 = require("../accounts/webSocket
11
11
  const defaultTxSender_1 = require("../tx/defaultTxSender");
12
12
  const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
13
13
  const admin_1 = require("../admin");
14
- function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.Provider.defaultOptions(), txSender) {
14
+ const retryTxSender_1 = require("../tx/retryTxSender");
15
+ function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.Provider.defaultOptions(), txSenderConfig) {
15
16
  return {
16
17
  type: 'websocket',
17
18
  connection,
18
19
  wallet,
19
20
  programID,
20
21
  opts,
21
- txSender,
22
+ txSenderConfig,
22
23
  };
23
24
  }
24
25
  exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
25
- function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.Provider.defaultOptions(), txSender) {
26
+ function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.Provider.defaultOptions(), txSenderConfig) {
26
27
  return {
27
28
  type: 'polling',
28
29
  connection,
@@ -30,11 +31,12 @@ function getPollingClearingHouseConfig(connection, wallet, programID, accountLoa
30
31
  programID,
31
32
  accountLoader,
32
33
  opts,
33
- txSender,
34
+ txSenderConfig,
34
35
  };
35
36
  }
36
37
  exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
37
38
  function getClearingHouse(config) {
39
+ var _a;
38
40
  const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
39
41
  const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
40
42
  let accountSubscriber;
@@ -44,11 +46,19 @@ function getClearingHouse(config) {
44
46
  else if (config.type === 'polling') {
45
47
  accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
46
48
  }
47
- const txSender = config.txSender || new defaultTxSender_1.DefaultTxSender(provider);
49
+ let txSender;
50
+ if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
51
+ const txSenderConfig = config.txSenderConfig;
52
+ txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
53
+ }
54
+ else {
55
+ txSender = new defaultTxSender_1.DefaultTxSender(provider);
56
+ }
48
57
  return new clearingHouse_1.ClearingHouse(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
49
58
  }
50
59
  exports.getClearingHouse = getClearingHouse;
51
60
  function getAdmin(config) {
61
+ var _a;
52
62
  const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
53
63
  const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
54
64
  let accountSubscriber;
@@ -58,7 +68,14 @@ function getAdmin(config) {
58
68
  else if (config.type === 'polling') {
59
69
  accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
60
70
  }
61
- const txSender = config.txSender || new defaultTxSender_1.DefaultTxSender(provider);
71
+ let txSender;
72
+ if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
73
+ const txSenderConfig = config.txSenderConfig;
74
+ txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
75
+ }
76
+ else {
77
+ txSender = new defaultTxSender_1.DefaultTxSender(provider);
78
+ }
62
79
  return new admin_1.Admin(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
63
80
  }
64
81
  exports.getAdmin = getAdmin;
@@ -1482,32 +1482,6 @@
1482
1482
  }
1483
1483
  ]
1484
1484
  },
1485
- {
1486
- "name": "deleteUser",
1487
- "accounts": [
1488
- {
1489
- "name": "user",
1490
- "isMut": true,
1491
- "isSigner": false
1492
- },
1493
- {
1494
- "name": "userPositions",
1495
- "isMut": true,
1496
- "isSigner": false
1497
- },
1498
- {
1499
- "name": "userOrders",
1500
- "isMut": true,
1501
- "isSigner": false
1502
- },
1503
- {
1504
- "name": "authority",
1505
- "isMut": false,
1506
- "isSigner": true
1507
- }
1508
- ],
1509
- "args": []
1510
- },
1511
1485
  {
1512
1486
  "name": "settleFundingPayment",
1513
1487
  "accounts": [
@@ -3292,8 +3266,8 @@
3292
3266
  "type": "u128"
3293
3267
  },
3294
3268
  {
3295
- "name": "netRevenueSinceLastFunding",
3296
- "type": "i64"
3269
+ "name": "padding1",
3270
+ "type": "u64"
3297
3271
  },
3298
3272
  {
3299
3273
  "name": "padding2",
@@ -4300,11 +4274,6 @@
4300
4274
  "code": 6060,
4301
4275
  "name": "CantExpireOrders",
4302
4276
  "msg": "CantExpireOrders"
4303
- },
4304
- {
4305
- "code": 6061,
4306
- "name": "InvalidRepegPriceImpact",
4307
- "msg": "AMM repeg mark price impact vs oracle too large"
4308
4277
  }
4309
4278
  ]
4310
4279
  }
package/lib/index.d.ts CHANGED
@@ -28,7 +28,6 @@ export * from './math/position';
28
28
  export * from './math/amm';
29
29
  export * from './math/trade';
30
30
  export * from './math/orders';
31
- export * from './math/repeg';
32
31
  export * from './orders';
33
32
  export * from './orderParams';
34
33
  export * from './wallet';
package/lib/index.js CHANGED
@@ -47,7 +47,6 @@ __exportStar(require("./math/position"), exports);
47
47
  __exportStar(require("./math/amm"), exports);
48
48
  __exportStar(require("./math/trade"), exports);
49
49
  __exportStar(require("./math/orders"), exports);
50
- __exportStar(require("./math/repeg"), exports);
51
50
  __exportStar(require("./orders"), exports);
52
51
  __exportStar(require("./orderParams"), exports);
53
52
  __exportStar(require("./wallet"), exports);