@drift-labs/sdk 0.2.0-master.32 → 0.2.0-master.33
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.
- package/lib/accounts/bulkAccountLoader.js +2 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +8 -8
- package/lib/accounts/types.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +7 -7
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +4 -4
- package/lib/addresses/pda.js +23 -22
- package/lib/admin.d.ts +30 -32
- package/lib/admin.js +111 -119
- package/lib/clearingHouse.d.ts +43 -34
- package/lib/clearingHouse.js +353 -193
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +26 -5
- package/lib/clearingHouseUser.js +151 -51
- package/lib/config.d.ts +2 -0
- package/lib/config.js +5 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/dlob/DLOB.d.ts +18 -11
- package/lib/dlob/DLOB.js +179 -107
- package/lib/dlob/DLOBNode.js +2 -10
- package/lib/dlob/NodeList.js +1 -1
- package/lib/events/eventSubscriber.d.ts +1 -0
- package/lib/events/eventSubscriber.js +11 -4
- package/lib/events/fetchLogs.d.ts +3 -1
- package/lib/events/fetchLogs.js +13 -5
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +1 -1
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/factory/bigNum.d.ts +5 -4
- package/lib/factory/bigNum.js +36 -6
- package/lib/idl/clearing_house.json +1527 -1242
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/math/amm.js +9 -9
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.js +10 -10
- package/lib/math/margin.js +6 -1
- package/lib/math/market.js +9 -9
- package/lib/math/orders.d.ts +7 -3
- package/lib/math/orders.js +39 -31
- package/lib/math/repeg.js +3 -3
- package/lib/math/spotBalance.js +3 -3
- package/lib/math/spotPosition.js +2 -2
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +4 -0
- package/lib/serum/serumSubscriber.js +16 -1
- package/lib/types.d.ts +60 -75
- package/lib/types.js +2 -1
- package/lib/userMap/userMap.d.ts +17 -1
- package/lib/userMap/userMap.js +12 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +9 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +8 -8
- package/src/addresses/marketAddresses.ts +2 -2
- package/src/addresses/pda.ts +20 -20
- package/src/admin.ts +246 -221
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +556 -236
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +237 -87
- package/src/config.ts +8 -1
- package/src/constants/numericConstants.ts +5 -1
- package/src/dlob/DLOB.ts +257 -120
- package/src/dlob/DLOBNode.ts +2 -14
- package/src/dlob/NodeList.ts +1 -1
- package/src/events/eventList.js +77 -0
- package/src/events/eventSubscriber.ts +18 -4
- package/src/events/fetchLogs.ts +20 -5
- package/src/events/pollingLogProvider.ts +1 -1
- package/src/events/types.ts +2 -1
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.js +157 -0
- package/src/factory/bigNum.ts +59 -6
- package/src/idl/clearing_house.json +1527 -1242
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +3 -0
- package/src/math/amm.ts +9 -9
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +20 -10
- package/src/math/margin.ts +7 -1
- package/src/math/market.ts +9 -9
- package/src/math/orders.ts +44 -29
- package/src/math/repeg.ts +3 -3
- package/src/math/spotBalance.ts +4 -4
- package/src/math/spotPosition.ts +2 -2
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +20 -1
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/types.ts +65 -51
- package/src/userMap/userMap.ts +25 -1
- package/src/userName.ts +2 -1
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/bn/test.ts +22 -1
- package/tests/dlob/helpers.ts +252 -81
- package/tests/dlob/test.ts +1040 -219
package/tests/dlob/helpers.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import {
|
|
3
3
|
AMM,
|
|
4
4
|
AssetTier,
|
|
5
5
|
PerpPosition,
|
|
6
6
|
BN,
|
|
7
|
+
ClearingHouse,
|
|
8
|
+
ClearingHouseUser,
|
|
7
9
|
PerpMarketAccount,
|
|
8
10
|
SpotMarketAccount,
|
|
9
11
|
MarketStatus,
|
|
@@ -13,7 +15,12 @@ import {
|
|
|
13
15
|
BASE_PRECISION,
|
|
14
16
|
QUOTE_PRECISION,
|
|
15
17
|
AMM_TO_QUOTE_PRECISION_RATIO,
|
|
18
|
+
StateAccount,
|
|
19
|
+
UserMapInterface,
|
|
20
|
+
Wallet,
|
|
21
|
+
OrderRecord,
|
|
16
22
|
} from '../../src';
|
|
23
|
+
import { ExchangeStatus } from '../../lib';
|
|
17
24
|
|
|
18
25
|
export const mockPerpPosition: PerpPosition = {
|
|
19
26
|
baseAssetAmount: new BN(0),
|
|
@@ -70,18 +77,20 @@ export const mockAMM: AMM = {
|
|
|
70
77
|
cumulativeFeePerLp: new BN(0),
|
|
71
78
|
cumulativeNetBaseAssetAmountPerLp: new BN(0),
|
|
72
79
|
userLpShares: new BN(0),
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
baseAssetAmountWithUnsettledLp: new BN(0),
|
|
81
|
+
orderStepSize: new BN(0),
|
|
82
|
+
orderTickSize: new BN(1),
|
|
83
|
+
maxFillReserveFraction: 0,
|
|
77
84
|
baseSpread: 0,
|
|
78
85
|
curveUpdateIntensity: 0,
|
|
79
|
-
|
|
86
|
+
baseAssetAmountWithAmm: new BN(0),
|
|
87
|
+
baseAssetAmountLong: new BN(0),
|
|
88
|
+
baseAssetAmountShort: new BN(0),
|
|
80
89
|
quoteAssetAmountLong: new BN(0),
|
|
81
90
|
quoteAssetAmountShort: new BN(0),
|
|
82
91
|
terminalQuoteAssetReserve: new BN(0),
|
|
83
92
|
feePool: {
|
|
84
|
-
|
|
93
|
+
scaledBalance: new BN(0),
|
|
85
94
|
marketIndex: 0,
|
|
86
95
|
},
|
|
87
96
|
totalExchangeFee: new BN(0),
|
|
@@ -94,110 +103,110 @@ export const mockAMM: AMM = {
|
|
|
94
103
|
longSpread: new BN(0),
|
|
95
104
|
shortSpread: new BN(0),
|
|
96
105
|
maxSpread: 0,
|
|
97
|
-
marketPosition: mockPerpPosition,
|
|
98
|
-
marketPositionPerLp: mockPerpPosition,
|
|
99
106
|
ammJitIntensity: 0,
|
|
100
107
|
maxBaseAssetReserve: new BN(0),
|
|
101
108
|
minBaseAssetReserve: new BN(0),
|
|
102
109
|
cumulativeSocialLoss: new BN(0),
|
|
110
|
+
baseAssetAmountPerLp: new BN(0),
|
|
111
|
+
quoteAssetAmountPerLp: new BN(0),
|
|
103
112
|
};
|
|
104
113
|
|
|
105
114
|
export const mockPerpMarkets: Array<PerpMarketAccount> = [
|
|
106
115
|
{
|
|
107
116
|
status: MarketStatus.INITIALIZED,
|
|
117
|
+
name: [],
|
|
108
118
|
contractType: ContractType.PERPETUAL,
|
|
109
119
|
expiryTs: new BN(0),
|
|
110
|
-
|
|
120
|
+
expiryPrice: new BN(0),
|
|
111
121
|
marketIndex: 0,
|
|
112
122
|
pubkey: PublicKey.default,
|
|
113
123
|
amm: mockAMM,
|
|
114
|
-
|
|
115
|
-
baseAssetAmountLong: new BN(0),
|
|
116
|
-
baseAssetAmountShort: new BN(0),
|
|
117
|
-
openInterest: new BN(0),
|
|
124
|
+
numberOfUsers: new BN(0),
|
|
118
125
|
marginRatioInitial: 0,
|
|
119
126
|
marginRatioMaintenance: 0,
|
|
120
127
|
nextFillRecordId: new BN(0),
|
|
121
128
|
pnlPool: {
|
|
122
|
-
|
|
129
|
+
scaledBalance: new BN(0),
|
|
123
130
|
marketIndex: 0,
|
|
124
131
|
},
|
|
125
132
|
ifLiquidationFee: new BN(0),
|
|
126
133
|
liquidatorFee: new BN(0),
|
|
127
134
|
imfFactor: new BN(0),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
unrealizedPnlImfFactor: new BN(0),
|
|
136
|
+
unrealizedPnlMaxImbalance: new BN(0),
|
|
137
|
+
unrealizedPnlInitialAssetWeight: 0,
|
|
138
|
+
unrealizedPnlMaintenanceAssetWeight: 0,
|
|
139
|
+
insuranceClaim: {
|
|
140
|
+
revenueWithdrawSinceLastSettle: new BN(0),
|
|
141
|
+
maxRevenueWithdrawPerPeriod: new BN(0),
|
|
142
|
+
lastRevenueWithdrawTs: new BN(0),
|
|
143
|
+
quoteSettledInsurance: new BN(0),
|
|
144
|
+
quoteMaxInsurance: new BN(0),
|
|
145
|
+
},
|
|
137
146
|
},
|
|
138
147
|
{
|
|
139
148
|
status: MarketStatus.INITIALIZED,
|
|
149
|
+
name: [],
|
|
140
150
|
contractType: ContractType.PERPETUAL,
|
|
141
151
|
expiryTs: new BN(0),
|
|
142
|
-
|
|
152
|
+
expiryPrice: new BN(0),
|
|
143
153
|
marketIndex: 1,
|
|
144
154
|
pubkey: PublicKey.default,
|
|
145
155
|
amm: mockAMM,
|
|
146
|
-
|
|
147
|
-
baseAssetAmountLong: new BN(0),
|
|
148
|
-
baseAssetAmountShort: new BN(0),
|
|
149
|
-
openInterest: new BN(0),
|
|
156
|
+
numberOfUsers: new BN(0),
|
|
150
157
|
marginRatioInitial: 0,
|
|
151
158
|
marginRatioMaintenance: 0,
|
|
152
159
|
nextFillRecordId: new BN(0),
|
|
153
160
|
pnlPool: {
|
|
154
|
-
|
|
161
|
+
scaledBalance: new BN(0),
|
|
155
162
|
marketIndex: 0,
|
|
156
163
|
},
|
|
157
164
|
ifLiquidationFee: new BN(0),
|
|
158
165
|
liquidatorFee: new BN(0),
|
|
159
166
|
imfFactor: new BN(0),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
unrealizedPnlImfFactor: new BN(0),
|
|
168
|
+
unrealizedPnlMaxImbalance: new BN(0),
|
|
169
|
+
unrealizedPnlInitialAssetWeight: 0,
|
|
170
|
+
unrealizedPnlMaintenanceAssetWeight: 0,
|
|
171
|
+
insuranceClaim: {
|
|
172
|
+
revenueWithdrawSinceLastSettle: new BN(0),
|
|
173
|
+
maxRevenueWithdrawPerPeriod: new BN(0),
|
|
174
|
+
lastRevenueWithdrawTs: new BN(0),
|
|
175
|
+
quoteSettledInsurance: new BN(0),
|
|
176
|
+
quoteMaxInsurance: new BN(0),
|
|
177
|
+
},
|
|
169
178
|
},
|
|
170
179
|
{
|
|
171
180
|
status: MarketStatus.INITIALIZED,
|
|
181
|
+
name: [],
|
|
172
182
|
contractType: ContractType.PERPETUAL,
|
|
173
183
|
expiryTs: new BN(0),
|
|
174
|
-
|
|
184
|
+
expiryPrice: new BN(0),
|
|
175
185
|
marketIndex: 2,
|
|
176
186
|
pubkey: PublicKey.default,
|
|
177
187
|
amm: mockAMM,
|
|
178
|
-
|
|
179
|
-
baseAssetAmountLong: new BN(0),
|
|
180
|
-
baseAssetAmountShort: new BN(0),
|
|
181
|
-
openInterest: new BN(0),
|
|
188
|
+
numberOfUsers: new BN(0),
|
|
182
189
|
marginRatioInitial: 0,
|
|
183
190
|
marginRatioMaintenance: 0,
|
|
184
191
|
nextFillRecordId: new BN(0),
|
|
185
192
|
pnlPool: {
|
|
186
|
-
|
|
193
|
+
scaledBalance: new BN(0),
|
|
187
194
|
marketIndex: 0,
|
|
188
195
|
},
|
|
189
196
|
ifLiquidationFee: new BN(0),
|
|
190
197
|
liquidatorFee: new BN(0),
|
|
191
198
|
imfFactor: new BN(0),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
unrealizedPnlImfFactor: new BN(0),
|
|
200
|
+
unrealizedPnlMaxImbalance: new BN(0),
|
|
201
|
+
unrealizedPnlInitialAssetWeight: 0,
|
|
202
|
+
unrealizedPnlMaintenanceAssetWeight: 0,
|
|
203
|
+
insuranceClaim: {
|
|
204
|
+
revenueWithdrawSinceLastSettle: new BN(0),
|
|
205
|
+
maxRevenueWithdrawPerPeriod: new BN(0),
|
|
206
|
+
lastRevenueWithdrawTs: new BN(0),
|
|
207
|
+
quoteSettledInsurance: new BN(0),
|
|
208
|
+
quoteMaxInsurance: new BN(0),
|
|
209
|
+
},
|
|
201
210
|
},
|
|
202
211
|
];
|
|
203
212
|
|
|
@@ -210,16 +219,21 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
210
219
|
pubkey: PublicKey.default,
|
|
211
220
|
mint: DevnetSpotMarkets[0].mint,
|
|
212
221
|
vault: PublicKey.default,
|
|
213
|
-
insuranceFundVault: PublicKey.default,
|
|
214
|
-
insuranceWithdrawEscrowPeriod: new BN(0),
|
|
215
222
|
revenuePool: {
|
|
216
|
-
|
|
223
|
+
scaledBalance: new BN(0),
|
|
217
224
|
marketIndex: 0,
|
|
218
225
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
insuranceFund: {
|
|
227
|
+
vault: PublicKey.default,
|
|
228
|
+
totalShares: new BN(0),
|
|
229
|
+
userShares: new BN(0),
|
|
230
|
+
sharesBase: new BN(0),
|
|
231
|
+
unstakingPeriod: new BN(0),
|
|
232
|
+
lastRevenueSettleTs: new BN(0),
|
|
233
|
+
revenueSettlePeriod: new BN(0),
|
|
234
|
+
totalFactor: 0,
|
|
235
|
+
userFactor: 0,
|
|
236
|
+
},
|
|
223
237
|
ifLiquidationFee: new BN(0),
|
|
224
238
|
liquidatorFee: new BN(0),
|
|
225
239
|
decimals: 6,
|
|
@@ -243,9 +257,10 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
243
257
|
borrowTokenTwap: new BN(0),
|
|
244
258
|
utilizationTwap: new BN(0),
|
|
245
259
|
orderStepSize: new BN(0),
|
|
260
|
+
orderTickSize: new BN(0),
|
|
246
261
|
nextFillRecordId: new BN(0),
|
|
247
262
|
spotFeePool: {
|
|
248
|
-
|
|
263
|
+
scaledBalance: new BN(0),
|
|
249
264
|
marketIndex: 0,
|
|
250
265
|
},
|
|
251
266
|
totalSpotFee: new BN(0),
|
|
@@ -262,7 +277,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
262
277
|
lastIndexBidPrice: new BN(0),
|
|
263
278
|
lastIndexAskPrice: new BN(0),
|
|
264
279
|
lastIndexPriceTwap: new BN(0),
|
|
265
|
-
|
|
280
|
+
lastIndexPriceTwap5min: new BN(0),
|
|
266
281
|
lastIndexPriceTwapTs: new BN(0),
|
|
267
282
|
},
|
|
268
283
|
},
|
|
@@ -274,16 +289,21 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
274
289
|
pubkey: PublicKey.default,
|
|
275
290
|
mint: DevnetSpotMarkets[1].mint,
|
|
276
291
|
vault: PublicKey.default,
|
|
277
|
-
insuranceFundVault: PublicKey.default,
|
|
278
|
-
insuranceWithdrawEscrowPeriod: new BN(0),
|
|
279
292
|
revenuePool: {
|
|
280
|
-
|
|
293
|
+
scaledBalance: new BN(0),
|
|
281
294
|
marketIndex: 0,
|
|
282
295
|
},
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
296
|
+
insuranceFund: {
|
|
297
|
+
vault: PublicKey.default,
|
|
298
|
+
totalShares: new BN(0),
|
|
299
|
+
userShares: new BN(0),
|
|
300
|
+
sharesBase: new BN(0),
|
|
301
|
+
unstakingPeriod: new BN(0),
|
|
302
|
+
lastRevenueSettleTs: new BN(0),
|
|
303
|
+
revenueSettlePeriod: new BN(0),
|
|
304
|
+
totalFactor: 0,
|
|
305
|
+
userFactor: 0,
|
|
306
|
+
},
|
|
287
307
|
ifLiquidationFee: new BN(0),
|
|
288
308
|
liquidatorFee: new BN(0),
|
|
289
309
|
decimals: 9,
|
|
@@ -307,9 +327,10 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
307
327
|
borrowTokenTwap: new BN(0),
|
|
308
328
|
utilizationTwap: new BN(0),
|
|
309
329
|
orderStepSize: new BN(0),
|
|
330
|
+
orderTickSize: new BN(0),
|
|
310
331
|
nextFillRecordId: new BN(0),
|
|
311
332
|
spotFeePool: {
|
|
312
|
-
|
|
333
|
+
scaledBalance: new BN(0),
|
|
313
334
|
marketIndex: 0,
|
|
314
335
|
},
|
|
315
336
|
totalSpotFee: new BN(0),
|
|
@@ -326,7 +347,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
326
347
|
lastIndexBidPrice: new BN(0),
|
|
327
348
|
lastIndexAskPrice: new BN(0),
|
|
328
349
|
lastIndexPriceTwap: new BN(0),
|
|
329
|
-
|
|
350
|
+
lastIndexPriceTwap5min: new BN(0),
|
|
330
351
|
lastIndexPriceTwapTs: new BN(0),
|
|
331
352
|
},
|
|
332
353
|
},
|
|
@@ -338,16 +359,21 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
338
359
|
pubkey: PublicKey.default,
|
|
339
360
|
mint: DevnetSpotMarkets[2].mint,
|
|
340
361
|
vault: PublicKey.default,
|
|
341
|
-
insuranceFundVault: PublicKey.default,
|
|
342
|
-
insuranceWithdrawEscrowPeriod: new BN(0),
|
|
343
362
|
revenuePool: {
|
|
344
|
-
|
|
363
|
+
scaledBalance: new BN(0),
|
|
345
364
|
marketIndex: 0,
|
|
346
365
|
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
366
|
+
insuranceFund: {
|
|
367
|
+
vault: PublicKey.default,
|
|
368
|
+
totalShares: new BN(0),
|
|
369
|
+
userShares: new BN(0),
|
|
370
|
+
sharesBase: new BN(0),
|
|
371
|
+
unstakingPeriod: new BN(0),
|
|
372
|
+
lastRevenueSettleTs: new BN(0),
|
|
373
|
+
revenueSettlePeriod: new BN(0),
|
|
374
|
+
totalFactor: 0,
|
|
375
|
+
userFactor: 0,
|
|
376
|
+
},
|
|
351
377
|
ifLiquidationFee: new BN(0),
|
|
352
378
|
liquidatorFee: new BN(0),
|
|
353
379
|
decimals: 6,
|
|
@@ -371,9 +397,10 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
371
397
|
borrowTokenTwap: new BN(0),
|
|
372
398
|
utilizationTwap: new BN(0),
|
|
373
399
|
orderStepSize: new BN(0),
|
|
400
|
+
orderTickSize: new BN(0),
|
|
374
401
|
nextFillRecordId: new BN(0),
|
|
375
402
|
spotFeePool: {
|
|
376
|
-
|
|
403
|
+
scaledBalance: new BN(0),
|
|
377
404
|
marketIndex: 0,
|
|
378
405
|
},
|
|
379
406
|
totalSpotFee: new BN(0),
|
|
@@ -390,8 +417,152 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
390
417
|
lastIndexBidPrice: new BN(0),
|
|
391
418
|
lastIndexAskPrice: new BN(0),
|
|
392
419
|
lastIndexPriceTwap: new BN(0),
|
|
393
|
-
|
|
420
|
+
lastIndexPriceTwap5min: new BN(0),
|
|
394
421
|
lastIndexPriceTwapTs: new BN(0),
|
|
395
422
|
},
|
|
396
423
|
},
|
|
397
424
|
];
|
|
425
|
+
|
|
426
|
+
export const mockStateAccount: StateAccount = {
|
|
427
|
+
admin: PublicKey.default,
|
|
428
|
+
defaultMarketOrderTimeInForce: 0,
|
|
429
|
+
defaultSpotAuctionDuration: 0,
|
|
430
|
+
discountMint: PublicKey.default,
|
|
431
|
+
exchangeStatus: ExchangeStatus.ACTIVE,
|
|
432
|
+
liquidationMarginBufferRatio: 0,
|
|
433
|
+
lpCooldownTime: new BN(0),
|
|
434
|
+
minPerpAuctionDuration: 0,
|
|
435
|
+
numberOfMarkets: 0,
|
|
436
|
+
numberOfSpotMarkets: 0,
|
|
437
|
+
oracleGuardRails: {
|
|
438
|
+
priceDivergence: {
|
|
439
|
+
markOracleDivergenceNumerator: new BN(0),
|
|
440
|
+
markOracleDivergenceDenominator: new BN(0),
|
|
441
|
+
},
|
|
442
|
+
validity: {
|
|
443
|
+
slotsBeforeStaleForAmm: new BN(0),
|
|
444
|
+
slotsBeforeStaleForMargin: new BN(0),
|
|
445
|
+
confidenceIntervalMaxSize: new BN(0),
|
|
446
|
+
tooVolatileRatio: new BN(0),
|
|
447
|
+
},
|
|
448
|
+
useForLiquidations: true,
|
|
449
|
+
},
|
|
450
|
+
perpFeeStructure: {
|
|
451
|
+
feeTiers: [
|
|
452
|
+
{
|
|
453
|
+
feeNumerator: 0,
|
|
454
|
+
feeDenominator: 0,
|
|
455
|
+
makerRebateNumerator: 0,
|
|
456
|
+
makerRebateDenominator: 0,
|
|
457
|
+
referrerRewardNumerator: 0,
|
|
458
|
+
referrerRewardDenominator: 0,
|
|
459
|
+
refereeFeeNumerator: 0,
|
|
460
|
+
refereeFeeDenominator: 0,
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
makerRebateNumerator: new BN(0),
|
|
464
|
+
makerRebateDenominator: new BN(0),
|
|
465
|
+
fillerRewardStructure: {
|
|
466
|
+
rewardNumerator: new BN(0),
|
|
467
|
+
rewardDenominator: new BN(0),
|
|
468
|
+
timeBasedRewardLowerBound: new BN(0),
|
|
469
|
+
},
|
|
470
|
+
flatFillerFee: new BN(0),
|
|
471
|
+
referrerRewardEpochUpperBound: new BN(0),
|
|
472
|
+
},
|
|
473
|
+
settlementDuration: 0,
|
|
474
|
+
signer: PublicKey.default,
|
|
475
|
+
signerNonce: 0,
|
|
476
|
+
spotFeeStructure: {
|
|
477
|
+
feeTiers: [
|
|
478
|
+
{
|
|
479
|
+
feeNumerator: 0,
|
|
480
|
+
feeDenominator: 0,
|
|
481
|
+
makerRebateNumerator: 0,
|
|
482
|
+
makerRebateDenominator: 0,
|
|
483
|
+
referrerRewardNumerator: 0,
|
|
484
|
+
referrerRewardDenominator: 0,
|
|
485
|
+
refereeFeeNumerator: 0,
|
|
486
|
+
refereeFeeDenominator: 0,
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
makerRebateNumerator: new BN(0),
|
|
490
|
+
makerRebateDenominator: new BN(0),
|
|
491
|
+
fillerRewardStructure: {
|
|
492
|
+
rewardNumerator: new BN(0),
|
|
493
|
+
rewardDenominator: new BN(0),
|
|
494
|
+
timeBasedRewardLowerBound: new BN(0),
|
|
495
|
+
},
|
|
496
|
+
flatFillerFee: new BN(0),
|
|
497
|
+
referrerRewardEpochUpperBound: new BN(0),
|
|
498
|
+
},
|
|
499
|
+
srmVault: PublicKey.default,
|
|
500
|
+
whitelistMint: PublicKey.default,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export class MockUserMap implements UserMapInterface {
|
|
504
|
+
private userMap = new Map<string, ClearingHouseUser>();
|
|
505
|
+
private userAccountToAuthority = new Map<string, string>();
|
|
506
|
+
private clearingHouse: ClearingHouse;
|
|
507
|
+
|
|
508
|
+
constructor() {
|
|
509
|
+
this.userMap = new Map();
|
|
510
|
+
this.userAccountToAuthority = new Map();
|
|
511
|
+
this.clearingHouse = new ClearingHouse({
|
|
512
|
+
connection: new Connection('http://localhost:8899'),
|
|
513
|
+
wallet: new Wallet(new Keypair()),
|
|
514
|
+
programID: PublicKey.default,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
public async fetchAllUsers(): Promise<void> {}
|
|
519
|
+
|
|
520
|
+
public async addPubkey(userAccountPublicKey: PublicKey): Promise<void> {
|
|
521
|
+
const user = new ClearingHouseUser({
|
|
522
|
+
clearingHouse: this.clearingHouse,
|
|
523
|
+
userAccountPublicKey: userAccountPublicKey,
|
|
524
|
+
});
|
|
525
|
+
this.userMap.set(userAccountPublicKey.toBase58(), user);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// mock function
|
|
529
|
+
public addUserAccountAuthority(
|
|
530
|
+
userAccountPublicKey: PublicKey,
|
|
531
|
+
authorityPublicKey: PublicKey
|
|
532
|
+
): void {
|
|
533
|
+
if (!this.userMap.has(userAccountPublicKey.toBase58())) {
|
|
534
|
+
this.addPubkey(userAccountPublicKey);
|
|
535
|
+
}
|
|
536
|
+
this.userAccountToAuthority.set(
|
|
537
|
+
userAccountPublicKey.toBase58(),
|
|
538
|
+
authorityPublicKey.toBase58()
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
public has(key: string): boolean {
|
|
543
|
+
return this.userMap.has(key);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
public get(_key: string): ClearingHouseUser | undefined {
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
public async mustGet(_key: string): Promise<ClearingHouseUser> {
|
|
551
|
+
return new ClearingHouseUser({
|
|
552
|
+
clearingHouse: this.clearingHouse,
|
|
553
|
+
userAccountPublicKey: PublicKey.default,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
public getUserAuthority(key: string): PublicKey | undefined {
|
|
558
|
+
return new PublicKey(
|
|
559
|
+
this.userAccountToAuthority.get(key) || PublicKey.default.toBase58()
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
public async updateWithOrderRecord(_record: OrderRecord): Promise<void> {}
|
|
564
|
+
|
|
565
|
+
public values(): IterableIterator<ClearingHouseUser> {
|
|
566
|
+
return this.userMap.values();
|
|
567
|
+
}
|
|
568
|
+
}
|