@drift-labs/sdk 0.2.0-master.29 → 0.2.0-master.30
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/README.md +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +10 -11
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +4 -4
- package/lib/accounts/types.d.ts +4 -6
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +10 -11
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +6 -8
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/pda.d.ts +5 -5
- package/lib/addresses/pda.js +5 -5
- package/lib/admin.d.ts +27 -28
- package/lib/admin.js +12 -37
- package/lib/clearingHouse.d.ts +61 -62
- package/lib/clearingHouse.js +92 -110
- package/lib/clearingHouseConfig.d.ts +2 -4
- package/lib/clearingHouseUser.d.ts +16 -16
- package/lib/clearingHouseUser.js +16 -16
- package/lib/config.d.ts +2 -4
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +7 -8
- package/lib/constants/numericConstants.js +17 -18
- package/lib/constants/perpMarkets.d.ts +2 -3
- package/lib/constants/perpMarkets.js +3 -3
- package/lib/constants/spotMarkets.d.ts +2 -1
- package/lib/constants/spotMarkets.js +6 -4
- package/lib/dlob/DLOB.d.ts +13 -13
- package/lib/dlob/DLOB.js +36 -40
- package/lib/dlob/DLOBNode.js +2 -2
- package/lib/events/sort.js +1 -1
- package/lib/examples/makeTradeExample.js +3 -3
- package/lib/idl/clearing_house.json +359 -310
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +10 -10
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.js +9 -9
- package/lib/math/margin.js +3 -3
- package/lib/math/market.d.ts +4 -4
- package/lib/math/market.js +7 -7
- package/lib/math/oracles.js +6 -8
- package/lib/math/position.d.ts +2 -2
- package/lib/math/position.js +9 -9
- package/lib/math/repeg.js +7 -6
- package/lib/math/spotBalance.js +5 -5
- package/lib/math/spotPosition.js +2 -2
- package/lib/math/trade.d.ts +6 -6
- package/lib/math/trade.js +15 -19
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/types.d.ts +63 -51
- package/lib/types.js +1 -1
- package/package.json +2 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +15 -15
- package/src/accounts/types.ts +4 -5
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +17 -25
- package/src/addresses/marketAddresses.ts +1 -2
- package/src/addresses/pda.ts +10 -10
- package/src/admin.ts +42 -79
- package/src/clearingHouse.ts +164 -212
- package/src/clearingHouseConfig.ts +2 -3
- package/src/clearingHouseUser.ts +35 -35
- package/src/config.ts +3 -4
- package/src/constants/numericConstants.ts +19 -21
- package/src/constants/perpMarkets.ts +5 -5
- package/src/constants/spotMarkets.ts +8 -5
- package/src/dlob/DLOB.ts +54 -70
- package/src/dlob/DLOBNode.ts +5 -6
- package/src/events/sort.ts +1 -1
- package/src/examples/makeTradeExample.js +2 -2
- package/src/examples/makeTradeExample.ts +5 -8
- package/src/idl/clearing_house.json +359 -310
- package/src/math/amm.ts +14 -11
- package/src/math/conversion.ts +2 -2
- package/src/math/funding.ts +13 -11
- package/src/math/margin.ts +4 -5
- package/src/math/market.ts +5 -5
- package/src/math/oracles.ts +9 -9
- package/src/math/position.ts +11 -19
- package/src/math/repeg.ts +8 -7
- package/src/math/spotBalance.ts +6 -6
- package/src/math/spotPosition.ts +2 -2
- package/src/math/trade.ts +17 -21
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/types.ts +69 -51
- package/tests/dlob/helpers.ts +56 -4
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/constants/markets.js +0 -42
- package/src/events/txEventCache.js +0 -71
- package/src/factory/bigNum.js +0 -390
- package/src/factory/oracleClient.js +0 -20
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -11
- package/src/math/funding.js +0 -248
- package/src/math/repeg.js +0 -128
- package/src/math/trade.js +0 -253
- package/src/math/utils.js +0 -26
- package/src/math/utils.js.map +0 -1
- package/src/oracles/oracleClientCache.js +0 -19
- package/src/oracles/pythClient.js +0 -46
- package/src/oracles/quoteAssetOracleClient.js +0 -32
- package/src/oracles/switchboardClient.js +0 -69
- package/src/oracles/types.js +0 -2
- package/src/userName.js +0 -20
- package/src/wallet.js +0 -35
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SwitchboardDecimal } from '@switchboard-xyz/switchboard-v2';
|
|
2
2
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN, Program, Idl, AnchorProvider } from '@project-serum/anchor';
|
|
4
|
-
import {
|
|
4
|
+
import { PRICE_PRECISION, TEN } from '../constants/numericConstants';
|
|
5
5
|
import { OracleClient, OraclePriceData } from './types';
|
|
6
6
|
import { Wallet } from '../wallet';
|
|
7
7
|
import switchboardV2Idl from '../idl/switchboard_v2.json';
|
|
@@ -74,6 +74,6 @@ function getSwitchboardProgram(connection: Connection): Program {
|
|
|
74
74
|
function convertSwitchboardDecimal(switchboardDecimal: SwitchboardDecimal): BN {
|
|
75
75
|
const switchboardPrecision = TEN.pow(new BN(switchboardDecimal.scale));
|
|
76
76
|
return switchboardDecimal.mantissa
|
|
77
|
-
.mul(
|
|
77
|
+
.mul(PRICE_PRECISION)
|
|
78
78
|
.div(switchboardPrecision);
|
|
79
79
|
}
|
package/src/types.ts
CHANGED
|
@@ -152,7 +152,7 @@ export type DepositRecord = {
|
|
|
152
152
|
deposit?: any;
|
|
153
153
|
withdraw?: any;
|
|
154
154
|
};
|
|
155
|
-
marketIndex:
|
|
155
|
+
marketIndex: number;
|
|
156
156
|
amount: BN;
|
|
157
157
|
oraclePrice: BN;
|
|
158
158
|
referrer: PublicKey;
|
|
@@ -163,7 +163,7 @@ export type DepositRecord = {
|
|
|
163
163
|
export type CurveRecord = {
|
|
164
164
|
ts: BN;
|
|
165
165
|
recordId: BN;
|
|
166
|
-
marketIndex:
|
|
166
|
+
marketIndex: number;
|
|
167
167
|
pegMultiplierBefore: BN;
|
|
168
168
|
baseAssetReserveBefore: BN;
|
|
169
169
|
quoteAssetReserveBefore: BN;
|
|
@@ -183,7 +183,7 @@ export type CurveRecord = {
|
|
|
183
183
|
export declare type InsuranceFundRecord = {
|
|
184
184
|
ts: BN;
|
|
185
185
|
bankIndex: BN;
|
|
186
|
-
marketIndex:
|
|
186
|
+
marketIndex: number;
|
|
187
187
|
userIfFactor: BN;
|
|
188
188
|
totalIfFactor: BN;
|
|
189
189
|
vaultAmountBefore: BN;
|
|
@@ -198,7 +198,7 @@ export type LPRecord = {
|
|
|
198
198
|
user: PublicKey;
|
|
199
199
|
action: LPAction;
|
|
200
200
|
nShares: BN;
|
|
201
|
-
marketIndex:
|
|
201
|
+
marketIndex: number;
|
|
202
202
|
deltaBaseAssetAmount: BN;
|
|
203
203
|
deltaQuoteAssetAmount: BN;
|
|
204
204
|
pnl: BN;
|
|
@@ -213,7 +213,7 @@ export class LPAction {
|
|
|
213
213
|
export type FundingRateRecord = {
|
|
214
214
|
ts: BN;
|
|
215
215
|
recordId: BN;
|
|
216
|
-
marketIndex:
|
|
216
|
+
marketIndex: number;
|
|
217
217
|
fundingRate: BN;
|
|
218
218
|
fundingRateLong: BN;
|
|
219
219
|
fundingRateShort: BN;
|
|
@@ -230,7 +230,7 @@ export type FundingPaymentRecord = {
|
|
|
230
230
|
ts: BN;
|
|
231
231
|
userAuthority: PublicKey;
|
|
232
232
|
user: PublicKey;
|
|
233
|
-
marketIndex:
|
|
233
|
+
marketIndex: number;
|
|
234
234
|
fundingPayment: BN;
|
|
235
235
|
baseAssetAmount: BN;
|
|
236
236
|
userLastCumulativeFunding: BN;
|
|
@@ -274,7 +274,7 @@ export class LiquidationType {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
export type LiquidatePerpRecord = {
|
|
277
|
-
marketIndex:
|
|
277
|
+
marketIndex: number;
|
|
278
278
|
oraclePrice: BN;
|
|
279
279
|
baseAssetAmount: BN;
|
|
280
280
|
quoteAssetAmount: BN;
|
|
@@ -288,41 +288,41 @@ export type LiquidatePerpRecord = {
|
|
|
288
288
|
};
|
|
289
289
|
|
|
290
290
|
export type LiquidateBorrowRecord = {
|
|
291
|
-
assetMarketIndex:
|
|
291
|
+
assetMarketIndex: number;
|
|
292
292
|
assetPrice: BN;
|
|
293
293
|
assetTransfer: BN;
|
|
294
|
-
liabilityMarketIndex:
|
|
294
|
+
liabilityMarketIndex: number;
|
|
295
295
|
liabilityPrice: BN;
|
|
296
296
|
liabilityTransfer: BN;
|
|
297
297
|
ifFee: BN;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
300
|
export type LiquidateBorrowForPerpPnlRecord = {
|
|
301
|
-
perpMarketIndex:
|
|
301
|
+
perpMarketIndex: number;
|
|
302
302
|
marketOraclePrice: BN;
|
|
303
303
|
pnlTransfer: BN;
|
|
304
|
-
liabilityMarketIndex:
|
|
304
|
+
liabilityMarketIndex: number;
|
|
305
305
|
liabilityPrice: BN;
|
|
306
306
|
liabilityTransfer: BN;
|
|
307
307
|
};
|
|
308
308
|
|
|
309
309
|
export type LiquidatePerpPnlForDepositRecord = {
|
|
310
|
-
perpMarketIndex:
|
|
310
|
+
perpMarketIndex: number;
|
|
311
311
|
marketOraclePrice: BN;
|
|
312
312
|
pnlTransfer: BN;
|
|
313
|
-
assetMarketIndex:
|
|
313
|
+
assetMarketIndex: number;
|
|
314
314
|
assetPrice: BN;
|
|
315
315
|
assetTransfer: BN;
|
|
316
316
|
};
|
|
317
317
|
|
|
318
318
|
export type PerpBankruptcyRecord = {
|
|
319
|
-
marketIndex:
|
|
319
|
+
marketIndex: number;
|
|
320
320
|
pnl: BN;
|
|
321
321
|
cumulativeFundingRateDelta: BN;
|
|
322
322
|
};
|
|
323
323
|
|
|
324
324
|
export type BorrowBankruptcyRecord = {
|
|
325
|
-
marketIndex:
|
|
325
|
+
marketIndex: number;
|
|
326
326
|
borrowAmount: BN;
|
|
327
327
|
cumulativeDepositInterestDelta: BN;
|
|
328
328
|
};
|
|
@@ -330,7 +330,7 @@ export type BorrowBankruptcyRecord = {
|
|
|
330
330
|
export type SettlePnlRecord = {
|
|
331
331
|
ts: BN;
|
|
332
332
|
user: PublicKey;
|
|
333
|
-
marketIndex:
|
|
333
|
+
marketIndex: number;
|
|
334
334
|
pnl: BN;
|
|
335
335
|
baseAssetAmount: BN;
|
|
336
336
|
quoteAssetAmountAfter: BN;
|
|
@@ -348,33 +348,30 @@ export type OrderActionRecord = {
|
|
|
348
348
|
ts: BN;
|
|
349
349
|
action: OrderAction;
|
|
350
350
|
actionExplanation: OrderActionExplanation;
|
|
351
|
-
marketIndex:
|
|
351
|
+
marketIndex: number;
|
|
352
|
+
marketType: MarketType;
|
|
352
353
|
filler: PublicKey | null;
|
|
353
354
|
fillerReward: BN | null;
|
|
354
355
|
fillRecordId: BN | null;
|
|
355
|
-
referrer: PublicKey | null;
|
|
356
356
|
baseAssetAmountFilled: BN | null;
|
|
357
357
|
quoteAssetAmountFilled: BN | null;
|
|
358
|
-
takerPnl: BN | null;
|
|
359
|
-
makerPnl: BN | null;
|
|
360
358
|
takerFee: BN | null;
|
|
361
|
-
|
|
362
|
-
referrerReward:
|
|
363
|
-
refereeDiscount: BN | null;
|
|
359
|
+
makerFee: BN | null;
|
|
360
|
+
referrerReward: number | null;
|
|
364
361
|
quoteAssetAmountSurplus: BN | null;
|
|
365
362
|
taker: PublicKey | null;
|
|
366
363
|
takerOrderId: BN | null;
|
|
367
364
|
takerOrderDirection: PositionDirection | null;
|
|
368
365
|
takerOrderBaseAssetAmount: BN | null;
|
|
369
|
-
|
|
370
|
-
|
|
366
|
+
takerOrderCumulativeBaseAssetAmountFilled: BN | null;
|
|
367
|
+
takerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
371
368
|
takerOrderFee: BN | null;
|
|
372
369
|
maker: PublicKey | null;
|
|
373
370
|
makerOrderId: BN | null;
|
|
374
371
|
makerOrderDirection: PositionDirection | null;
|
|
375
372
|
makerOrderBaseAssetAmount: BN | null;
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
makerOrderCumulativeBaseAssetAmountFilled: BN | null;
|
|
374
|
+
makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
378
375
|
makerOrderFee: BN | null;
|
|
379
376
|
oraclePrice: BN;
|
|
380
377
|
};
|
|
@@ -384,15 +381,14 @@ export type StateAccount = {
|
|
|
384
381
|
fundingPaused: boolean;
|
|
385
382
|
exchangePaused: boolean;
|
|
386
383
|
adminControlsPrices: boolean;
|
|
387
|
-
insuranceVault: PublicKey;
|
|
388
384
|
totalFee: BN;
|
|
389
385
|
totalFeeWithdrawn: BN;
|
|
390
386
|
whitelistMint: PublicKey;
|
|
391
387
|
discountMint: PublicKey;
|
|
392
388
|
oracleGuardRails: OracleGuardRails;
|
|
393
389
|
maxDeposit: BN;
|
|
394
|
-
numberOfMarkets:
|
|
395
|
-
numberOfSpotMarkets:
|
|
390
|
+
numberOfMarkets: number;
|
|
391
|
+
numberOfSpotMarkets: number;
|
|
396
392
|
minOrderQuoteAssetAmount: BN;
|
|
397
393
|
signer: PublicKey;
|
|
398
394
|
signerNonce: number;
|
|
@@ -400,6 +396,7 @@ export type StateAccount = {
|
|
|
400
396
|
minPerpAuctionDuration: number;
|
|
401
397
|
defaultSpotAuctionDuration: number;
|
|
402
398
|
liquidationMarginBufferRatio: number;
|
|
399
|
+
srmVault: PublicKey;
|
|
403
400
|
perpFeeStructure: FeeStructure;
|
|
404
401
|
spotFeeStructure: FeeStructure;
|
|
405
402
|
};
|
|
@@ -409,7 +406,7 @@ export type PerpMarketAccount = {
|
|
|
409
406
|
contractType: ContractType;
|
|
410
407
|
expiryTs: BN;
|
|
411
408
|
settlementPrice: BN;
|
|
412
|
-
marketIndex:
|
|
409
|
+
marketIndex: number;
|
|
413
410
|
pubkey: PublicKey;
|
|
414
411
|
amm: AMM;
|
|
415
412
|
baseAssetAmount: BN;
|
|
@@ -434,12 +431,34 @@ export type PerpMarketAccount = {
|
|
|
434
431
|
quoteMaxInsurance: BN;
|
|
435
432
|
};
|
|
436
433
|
|
|
434
|
+
export type HistoricalOracleData = {
|
|
435
|
+
lastOraclePrice: BN;
|
|
436
|
+
lastOracleDelay: BN;
|
|
437
|
+
lastOracleConf: BN;
|
|
438
|
+
lastOraclePriceTwap: BN;
|
|
439
|
+
lastOraclePriceTwap5min: BN;
|
|
440
|
+
lastOraclePriceTwapTs: BN;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
export type HistoricalIndexData = {
|
|
444
|
+
lastIndexBidPrice: BN;
|
|
445
|
+
lastIndexAskPrice: BN;
|
|
446
|
+
lastIndexPriceTwap: BN;
|
|
447
|
+
lastIndexPriceTwap5Min: BN;
|
|
448
|
+
lastIndexPriceTwapTs: BN;
|
|
449
|
+
};
|
|
450
|
+
|
|
437
451
|
export type SpotMarketAccount = {
|
|
438
|
-
marketIndex:
|
|
452
|
+
marketIndex: number;
|
|
439
453
|
pubkey: PublicKey;
|
|
440
454
|
mint: PublicKey;
|
|
441
455
|
vault: PublicKey;
|
|
442
456
|
|
|
457
|
+
oracle: PublicKey;
|
|
458
|
+
oracleSource: OracleSource;
|
|
459
|
+
historicalOracleData: HistoricalOracleData;
|
|
460
|
+
historicalIndexData: HistoricalIndexData;
|
|
461
|
+
|
|
443
462
|
insuranceFundVault: PublicKey;
|
|
444
463
|
insuranceWithdrawEscrowPeriod: BN;
|
|
445
464
|
revenuePool: PoolBalance;
|
|
@@ -461,7 +480,6 @@ export type SpotMarketAccount = {
|
|
|
461
480
|
borrowBalance: BN;
|
|
462
481
|
lastInterestTs: BN;
|
|
463
482
|
lastTwapTs: BN;
|
|
464
|
-
oracle: PublicKey;
|
|
465
483
|
initialAssetWeight: BN;
|
|
466
484
|
maintenanceAssetWeight: BN;
|
|
467
485
|
initialLiabilityWeight: BN;
|
|
@@ -495,21 +513,20 @@ export type AMM = {
|
|
|
495
513
|
lastMarkPriceTwap: BN;
|
|
496
514
|
lastMarkPriceTwap5min: BN;
|
|
497
515
|
lastMarkPriceTwapTs: BN;
|
|
498
|
-
|
|
499
|
-
lastOraclePriceTwap5min: BN;
|
|
500
|
-
lastOraclePriceTwapTs: BN;
|
|
501
|
-
lastOracleMarkSpreadPct: BN;
|
|
502
|
-
lastOracleConfPct: BN;
|
|
516
|
+
|
|
503
517
|
oracle: PublicKey;
|
|
504
518
|
oracleSource: OracleSource;
|
|
519
|
+
historicalOracleData: HistoricalOracleData;
|
|
520
|
+
|
|
521
|
+
lastOracleMarkSpreadPct: BN;
|
|
522
|
+
lastOracleConfPct: BN;
|
|
523
|
+
|
|
505
524
|
fundingPeriod: BN;
|
|
506
525
|
quoteAssetReserve: BN;
|
|
507
526
|
pegMultiplier: BN;
|
|
508
527
|
cumulativeFundingRateLong: BN;
|
|
509
528
|
cumulativeFundingRateShort: BN;
|
|
510
529
|
cumulativeFundingRateLp: BN;
|
|
511
|
-
cumulativeRepegRebateLong: BN;
|
|
512
|
-
cumulativeRepegRebateShort: BN;
|
|
513
530
|
totalFeeMinusDistributions: BN;
|
|
514
531
|
totalFeeWithdrawn: BN;
|
|
515
532
|
totalFee: BN;
|
|
@@ -522,7 +539,6 @@ export type AMM = {
|
|
|
522
539
|
baseAssetAmountStepSize: BN;
|
|
523
540
|
maxBaseAssetAmountRatio: number;
|
|
524
541
|
maxSlippageRatio: number;
|
|
525
|
-
lastOraclePrice: BN;
|
|
526
542
|
baseSpread: number;
|
|
527
543
|
curveUpdateIntensity: number;
|
|
528
544
|
netBaseAssetAmount: BN;
|
|
@@ -553,10 +569,10 @@ export type PerpPosition = {
|
|
|
553
569
|
baseAssetAmount: BN;
|
|
554
570
|
remainderBaseAssetAmount: BN;
|
|
555
571
|
lastCumulativeFundingRate: BN;
|
|
556
|
-
marketIndex:
|
|
572
|
+
marketIndex: number;
|
|
557
573
|
quoteAssetAmount: BN;
|
|
558
574
|
quoteEntryAmount: BN;
|
|
559
|
-
openOrders:
|
|
575
|
+
openOrders: number;
|
|
560
576
|
openBids: BN;
|
|
561
577
|
openAsks: BN;
|
|
562
578
|
settledPnl: BN;
|
|
@@ -603,12 +619,13 @@ export type UserAccount = {
|
|
|
603
619
|
};
|
|
604
620
|
|
|
605
621
|
export type SpotPosition = {
|
|
606
|
-
marketIndex:
|
|
622
|
+
marketIndex: number;
|
|
607
623
|
balanceType: SpotBalanceType;
|
|
608
624
|
balance: BN;
|
|
609
625
|
openOrders: number;
|
|
610
626
|
openBids: BN;
|
|
611
627
|
openAsks: BN;
|
|
628
|
+
cumulativeDeposits: BN;
|
|
612
629
|
};
|
|
613
630
|
|
|
614
631
|
export type Order = {
|
|
@@ -619,7 +636,7 @@ export type Order = {
|
|
|
619
636
|
slot: BN;
|
|
620
637
|
orderId: BN;
|
|
621
638
|
userOrderId: number;
|
|
622
|
-
marketIndex:
|
|
639
|
+
marketIndex: number;
|
|
623
640
|
price: BN;
|
|
624
641
|
baseAssetAmount: BN;
|
|
625
642
|
baseAssetAmountFilled: BN;
|
|
@@ -648,7 +665,7 @@ export type OrderParams = {
|
|
|
648
665
|
direction: PositionDirection;
|
|
649
666
|
baseAssetAmount: BN;
|
|
650
667
|
price: BN;
|
|
651
|
-
marketIndex:
|
|
668
|
+
marketIndex: number;
|
|
652
669
|
reduceOnly: boolean;
|
|
653
670
|
postOnly: boolean;
|
|
654
671
|
immediateOrCancel: boolean;
|
|
@@ -663,7 +680,7 @@ export type OrderParams = {
|
|
|
663
680
|
|
|
664
681
|
export type NecessaryOrderParams = {
|
|
665
682
|
orderType: OrderType;
|
|
666
|
-
marketIndex:
|
|
683
|
+
marketIndex: number;
|
|
667
684
|
baseAssetAmount: BN;
|
|
668
685
|
direction: PositionDirection;
|
|
669
686
|
};
|
|
@@ -679,7 +696,7 @@ export const DefaultOrderParams = {
|
|
|
679
696
|
direction: PositionDirection.LONG,
|
|
680
697
|
baseAssetAmount: ZERO,
|
|
681
698
|
price: ZERO,
|
|
682
|
-
marketIndex:
|
|
699
|
+
marketIndex: 0,
|
|
683
700
|
reduceOnly: false,
|
|
684
701
|
postOnly: false,
|
|
685
702
|
immediateOrCancel: false,
|
|
@@ -749,7 +766,8 @@ export type OracleGuardRails = {
|
|
|
749
766
|
markOracleDivergenceDenominator: BN;
|
|
750
767
|
};
|
|
751
768
|
validity: {
|
|
752
|
-
|
|
769
|
+
slotsBeforeStaleForAmm: BN;
|
|
770
|
+
slotsBeforeStaleForMargin: BN;
|
|
753
771
|
confidenceIntervalMaxSize: BN;
|
|
754
772
|
tooVolatileRatio: BN;
|
|
755
773
|
};
|
|
@@ -759,7 +777,7 @@ export type OracleGuardRails = {
|
|
|
759
777
|
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
760
778
|
|
|
761
779
|
export type InsuranceFundStake = {
|
|
762
|
-
marketIndex:
|
|
780
|
+
marketIndex: number;
|
|
763
781
|
authority: PublicKey;
|
|
764
782
|
|
|
765
783
|
ifShares: BN;
|
|
@@ -774,7 +792,7 @@ export type SerumV3FulfillmentConfigAccount = {
|
|
|
774
792
|
fulfillmentType: SpotFulfillmentType;
|
|
775
793
|
status: SpotFulfillmentStatus;
|
|
776
794
|
pubkey: PublicKey;
|
|
777
|
-
marketIndex:
|
|
795
|
+
marketIndex: number;
|
|
778
796
|
serumProgramId: PublicKey;
|
|
779
797
|
serumMarket: PublicKey;
|
|
780
798
|
serumRequestQueue: PublicKey;
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -41,9 +41,14 @@ export const mockAMM = {
|
|
|
41
41
|
lastMarkPriceTwap: new BN(0),
|
|
42
42
|
lastMarkPriceTwap5min: new BN(0),
|
|
43
43
|
lastMarkPriceTwapTs: new BN(0),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
historicalOracleData: {
|
|
45
|
+
lastOraclePrice: new BN(0),
|
|
46
|
+
lastOracleConf: new BN(0),
|
|
47
|
+
lastOracleDelay: new BN(0),
|
|
48
|
+
lastOraclePriceTwap: new BN(0),
|
|
49
|
+
lastOraclePriceTwap5min: new BN(0),
|
|
50
|
+
lastOraclePriceTwapTs: new BN(0),
|
|
51
|
+
},
|
|
47
52
|
lastOracleMarkSpreadPct: new BN(0),
|
|
48
53
|
lastOracleConfPct: new BN(0),
|
|
49
54
|
oracle: PublicKey.default,
|
|
@@ -65,7 +70,6 @@ export const mockAMM = {
|
|
|
65
70
|
minimumQuoteAssetTradeSize: new BN(0),
|
|
66
71
|
baseAssetAmountStepSize: new BN(0),
|
|
67
72
|
maxBaseAssetAmountRatio: 0,
|
|
68
|
-
lastOraclePrice: new BN(0),
|
|
69
73
|
baseSpread: 0,
|
|
70
74
|
curveUpdateIntensity: 0,
|
|
71
75
|
netBaseAssetAmount: new BN(0),
|
|
@@ -232,6 +236,22 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
232
236
|
balance: new BN(0),
|
|
233
237
|
},
|
|
234
238
|
totalSpotFee: new BN(0),
|
|
239
|
+
oracleSource: OracleSource.PYTH,
|
|
240
|
+
historicalOracleData: {
|
|
241
|
+
lastOraclePrice: new BN(0),
|
|
242
|
+
lastOracleConf: new BN(0),
|
|
243
|
+
lastOracleDelay: new BN(0),
|
|
244
|
+
lastOraclePriceTwap: new BN(0),
|
|
245
|
+
lastOraclePriceTwap5min: new BN(0),
|
|
246
|
+
lastOraclePriceTwapTs: new BN(0),
|
|
247
|
+
},
|
|
248
|
+
historicalIndexData: {
|
|
249
|
+
lastIndexBidPrice: new BN(0),
|
|
250
|
+
lastIndexAskPrice: new BN(0),
|
|
251
|
+
lastIndexPriceTwap: new BN(0),
|
|
252
|
+
lastIndexPriceTwap5Min: new BN(0),
|
|
253
|
+
lastIndexPriceTwapTs: new BN(0),
|
|
254
|
+
},
|
|
235
255
|
},
|
|
236
256
|
{
|
|
237
257
|
marketIndex: new BN(1),
|
|
@@ -275,6 +295,22 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
275
295
|
balance: new BN(0),
|
|
276
296
|
},
|
|
277
297
|
totalSpotFee: new BN(0),
|
|
298
|
+
oracleSource: OracleSource.PYTH,
|
|
299
|
+
historicalOracleData: {
|
|
300
|
+
lastOraclePrice: new BN(0),
|
|
301
|
+
lastOracleConf: new BN(0),
|
|
302
|
+
lastOracleDelay: new BN(0),
|
|
303
|
+
lastOraclePriceTwap: new BN(0),
|
|
304
|
+
lastOraclePriceTwap5min: new BN(0),
|
|
305
|
+
lastOraclePriceTwapTs: new BN(0),
|
|
306
|
+
},
|
|
307
|
+
historicalIndexData: {
|
|
308
|
+
lastIndexBidPrice: new BN(0),
|
|
309
|
+
lastIndexAskPrice: new BN(0),
|
|
310
|
+
lastIndexPriceTwap: new BN(0),
|
|
311
|
+
lastIndexPriceTwap5Min: new BN(0),
|
|
312
|
+
lastIndexPriceTwapTs: new BN(0),
|
|
313
|
+
},
|
|
278
314
|
},
|
|
279
315
|
{
|
|
280
316
|
marketIndex: new BN(2),
|
|
@@ -318,5 +354,21 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
318
354
|
balance: new BN(0),
|
|
319
355
|
},
|
|
320
356
|
totalSpotFee: new BN(0),
|
|
357
|
+
oracleSource: OracleSource.PYTH,
|
|
358
|
+
historicalOracleData: {
|
|
359
|
+
lastOraclePrice: new BN(0),
|
|
360
|
+
lastOracleConf: new BN(0),
|
|
361
|
+
lastOracleDelay: new BN(0),
|
|
362
|
+
lastOraclePriceTwap: new BN(0),
|
|
363
|
+
lastOraclePriceTwap5min: new BN(0),
|
|
364
|
+
lastOraclePriceTwapTs: new BN(0),
|
|
365
|
+
},
|
|
366
|
+
historicalIndexData: {
|
|
367
|
+
lastIndexBidPrice: new BN(0),
|
|
368
|
+
lastIndexAskPrice: new BN(0),
|
|
369
|
+
lastIndexPriceTwap: new BN(0),
|
|
370
|
+
lastIndexPriceTwap5Min: new BN(0),
|
|
371
|
+
lastIndexPriceTwapTs: new BN(0),
|
|
372
|
+
},
|
|
321
373
|
},
|
|
322
374
|
];
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getMarketAddress = void 0;
|
|
13
|
-
const pda_1 = require("./pda");
|
|
14
|
-
const CACHE = new Map();
|
|
15
|
-
function getMarketAddress(programId, marketIndex) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
18
|
-
if (CACHE.has(cacheKey)) {
|
|
19
|
-
return CACHE.get(cacheKey);
|
|
20
|
-
}
|
|
21
|
-
const publicKey = yield pda_1.getMarketPublicKey(programId, marketIndex);
|
|
22
|
-
CACHE.set(cacheKey, publicKey);
|
|
23
|
-
return publicKey;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.getMarketAddress = getMarketAddress;
|
package/src/constants/banks.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Banks = exports.MainnetBanks = exports.DevnetBanks = exports.WRAPPED_SOL_MINT = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const __1 = require("../");
|
|
6
|
-
exports.WRAPPED_SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111112');
|
|
7
|
-
exports.DevnetBanks = [
|
|
8
|
-
{
|
|
9
|
-
symbol: 'USDC',
|
|
10
|
-
bankIndex: new __1.BN(0),
|
|
11
|
-
oracle: web3_js_1.PublicKey.default,
|
|
12
|
-
oracleSource: __1.OracleSource.QUOTE_ASSET,
|
|
13
|
-
mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
symbol: 'SOL',
|
|
17
|
-
bankIndex: new __1.BN(1),
|
|
18
|
-
oracle: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
|
19
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
20
|
-
mint: new web3_js_1.PublicKey(exports.WRAPPED_SOL_MINT),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
symbol: 'BTC',
|
|
24
|
-
bankIndex: new __1.BN(2),
|
|
25
|
-
oracle: new web3_js_1.PublicKey('HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'),
|
|
26
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
27
|
-
mint: new web3_js_1.PublicKey('3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv'),
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
exports.MainnetBanks = [
|
|
31
|
-
{
|
|
32
|
-
symbol: 'USDC',
|
|
33
|
-
bankIndex: new __1.BN(0),
|
|
34
|
-
oracle: web3_js_1.PublicKey.default,
|
|
35
|
-
oracleSource: __1.OracleSource.QUOTE_ASSET,
|
|
36
|
-
mint: new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
exports.Banks = {
|
|
40
|
-
devnet: exports.DevnetBanks,
|
|
41
|
-
'mainnet-beta': exports.MainnetBanks,
|
|
42
|
-
};
|
package/src/constants/markets.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Markets = exports.MainnetMarkets = exports.DevnetMarkets = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
exports.DevnetMarkets = [
|
|
7
|
-
{
|
|
8
|
-
fullName: 'Solana',
|
|
9
|
-
category: ['L1', 'Infra'],
|
|
10
|
-
symbol: 'SOL-PERP',
|
|
11
|
-
baseAssetSymbol: 'SOL',
|
|
12
|
-
marketIndex: new __1.BN(0),
|
|
13
|
-
oracle: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
|
14
|
-
launchTs: 1655751353000,
|
|
15
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
fullName: 'Bitcoin',
|
|
19
|
-
category: ['L1', 'Payment'],
|
|
20
|
-
symbol: 'BTC-PERP',
|
|
21
|
-
baseAssetSymbol: 'BTC',
|
|
22
|
-
marketIndex: new __1.BN(1),
|
|
23
|
-
oracle: new web3_js_1.PublicKey('HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'),
|
|
24
|
-
launchTs: 1655751353000,
|
|
25
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
fullName: 'Ethereum',
|
|
29
|
-
category: ['L1', 'Infra'],
|
|
30
|
-
symbol: 'ETH-PERP',
|
|
31
|
-
baseAssetSymbol: 'ETH',
|
|
32
|
-
marketIndex: new __1.BN(2),
|
|
33
|
-
oracle: new web3_js_1.PublicKey('EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw'),
|
|
34
|
-
launchTs: 1637691133472,
|
|
35
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
exports.MainnetMarkets = [];
|
|
39
|
-
exports.Markets = {
|
|
40
|
-
devnet: exports.DevnetMarkets,
|
|
41
|
-
'mainnet-beta': [],
|
|
42
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TxEventCache = void 0;
|
|
4
|
-
class Node {
|
|
5
|
-
constructor(key, value, next, prev) {
|
|
6
|
-
this.key = key;
|
|
7
|
-
this.value = value;
|
|
8
|
-
this.next = next;
|
|
9
|
-
this.prev = prev;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
// lru cache
|
|
13
|
-
class TxEventCache {
|
|
14
|
-
constructor(maxTx = 1024) {
|
|
15
|
-
this.maxTx = maxTx;
|
|
16
|
-
this.size = 0;
|
|
17
|
-
this.cacheMap = {};
|
|
18
|
-
}
|
|
19
|
-
add(key, events) {
|
|
20
|
-
const existingNode = this.cacheMap[key];
|
|
21
|
-
if (existingNode) {
|
|
22
|
-
this.detach(existingNode);
|
|
23
|
-
this.size--;
|
|
24
|
-
}
|
|
25
|
-
else if (this.size === this.maxTx) {
|
|
26
|
-
delete this.cacheMap[this.tail.key];
|
|
27
|
-
this.detach(this.tail);
|
|
28
|
-
this.size--;
|
|
29
|
-
}
|
|
30
|
-
// Write to head of LinkedList
|
|
31
|
-
if (!this.head) {
|
|
32
|
-
this.head = this.tail = new Node(key, events);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
const node = new Node(key, events, this.head);
|
|
36
|
-
this.head.prev = node;
|
|
37
|
-
this.head = node;
|
|
38
|
-
}
|
|
39
|
-
// update cacheMap with LinkedList key and Node reference
|
|
40
|
-
this.cacheMap[key] = this.head;
|
|
41
|
-
this.size++;
|
|
42
|
-
}
|
|
43
|
-
has(key) {
|
|
44
|
-
return this.cacheMap.hasOwnProperty(key);
|
|
45
|
-
}
|
|
46
|
-
get(key) {
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = this.cacheMap[key]) === null || _a === void 0 ? void 0 : _a.value;
|
|
49
|
-
}
|
|
50
|
-
detach(node) {
|
|
51
|
-
if (node.prev !== undefined) {
|
|
52
|
-
node.prev.next = node.next;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
this.head = node.next;
|
|
56
|
-
}
|
|
57
|
-
if (node.next !== undefined) {
|
|
58
|
-
node.next.prev = node.prev;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.tail = node.prev;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
clear() {
|
|
65
|
-
this.head = undefined;
|
|
66
|
-
this.tail = undefined;
|
|
67
|
-
this.size = 0;
|
|
68
|
-
this.cacheMap = {};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.TxEventCache = TxEventCache;
|