@drift-labs/sdk 2.20.0-beta.0 → 2.20.0-beta.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.
- package/lib/accounts/bulkAccountLoader.d.ts +2 -1
- package/lib/accounts/bulkAccountLoader.js +7 -7
- package/lib/accounts/fetch.d.ts +1 -0
- package/lib/accounts/fetch.js +8 -4
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/types.d.ts +5 -4
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +13 -2
- package/lib/adminClient.js +61 -57
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +6 -5
- package/lib/dlob/DLOB.js +105 -75
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.d.ts +5 -2
- package/lib/driftClient.js +137 -95
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +14 -14
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +13 -13
- package/lib/factory/oracleClient.js +4 -4
- package/lib/idl/drift.json +82 -4
- package/lib/index.js +5 -1
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +23 -23
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +4 -4
- package/lib/math/market.js +15 -15
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +27 -24
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +9 -9
- package/lib/math/spotMarket.js +3 -3
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +42 -42
- package/lib/math/utils.js +1 -1
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tokenFaucet.js +5 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +71 -44
- package/lib/user.js +63 -63
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -5
- package/src/accounts/fetch.ts +8 -0
- package/src/addresses/pda.ts +13 -0
- package/src/dlob/DLOB.ts +55 -8
- package/src/driftClient.ts +77 -0
- package/src/idl/drift.json +82 -4
- package/src/math/orders.ts +5 -1
- package/src/types.ts +29 -0
- package/src/userMap/userStatsMap.ts +1 -4
- package/tests/amm/test.ts +24 -28
- package/tests/dlob/test.ts +67 -73
package/lib/types.d.ts
CHANGED
|
@@ -308,8 +308,8 @@ export declare enum TradeSide {
|
|
|
308
308
|
Buy = 1,
|
|
309
309
|
Sell = 2
|
|
310
310
|
}
|
|
311
|
-
export
|
|
312
|
-
export
|
|
311
|
+
export type CandleResolution = '1' | '5' | '15' | '60' | '240' | 'D' | 'W' | 'M';
|
|
312
|
+
export type NewUserRecord = {
|
|
313
313
|
ts: BN;
|
|
314
314
|
userAuthority: PublicKey;
|
|
315
315
|
user: PublicKey;
|
|
@@ -317,7 +317,7 @@ export declare type NewUserRecord = {
|
|
|
317
317
|
name: number[];
|
|
318
318
|
referrer: PublicKey;
|
|
319
319
|
};
|
|
320
|
-
export
|
|
320
|
+
export type DepositRecord = {
|
|
321
321
|
ts: BN;
|
|
322
322
|
userAuthority: PublicKey;
|
|
323
323
|
user: PublicKey;
|
|
@@ -338,7 +338,7 @@ export declare type DepositRecord = {
|
|
|
338
338
|
explanation: DepositExplanation;
|
|
339
339
|
transferUser?: PublicKey;
|
|
340
340
|
};
|
|
341
|
-
export
|
|
341
|
+
export type SpotInterestRecord = {
|
|
342
342
|
ts: BN;
|
|
343
343
|
marketIndex: number;
|
|
344
344
|
depositBalance: BN;
|
|
@@ -349,7 +349,7 @@ export declare type SpotInterestRecord = {
|
|
|
349
349
|
optimalBorrowRate: number;
|
|
350
350
|
maxBorrowRate: number;
|
|
351
351
|
};
|
|
352
|
-
export
|
|
352
|
+
export type CurveRecord = {
|
|
353
353
|
ts: BN;
|
|
354
354
|
recordId: BN;
|
|
355
355
|
marketIndex: number;
|
|
@@ -397,7 +397,7 @@ export declare type InsuranceFundStakeRecord = {
|
|
|
397
397
|
userIfSharesAfter: BN;
|
|
398
398
|
totalIfSharesAfter: BN;
|
|
399
399
|
};
|
|
400
|
-
export
|
|
400
|
+
export type LPRecord = {
|
|
401
401
|
ts: BN;
|
|
402
402
|
user: PublicKey;
|
|
403
403
|
action: LPAction;
|
|
@@ -418,7 +418,7 @@ export declare class LPAction {
|
|
|
418
418
|
settleLiquidity: {};
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
|
-
export
|
|
421
|
+
export type FundingRateRecord = {
|
|
422
422
|
ts: BN;
|
|
423
423
|
recordId: BN;
|
|
424
424
|
marketIndex: number;
|
|
@@ -433,7 +433,7 @@ export declare type FundingRateRecord = {
|
|
|
433
433
|
baseAssetAmountWithAmm: BN;
|
|
434
434
|
baseAssetAmountWithUnsettledLp: BN;
|
|
435
435
|
};
|
|
436
|
-
export
|
|
436
|
+
export type FundingPaymentRecord = {
|
|
437
437
|
ts: BN;
|
|
438
438
|
userAuthority: PublicKey;
|
|
439
439
|
user: PublicKey;
|
|
@@ -444,7 +444,7 @@ export declare type FundingPaymentRecord = {
|
|
|
444
444
|
ammCumulativeFundingLong: BN;
|
|
445
445
|
ammCumulativeFundingShort: BN;
|
|
446
446
|
};
|
|
447
|
-
export
|
|
447
|
+
export type LiquidationRecord = {
|
|
448
448
|
ts: BN;
|
|
449
449
|
user: PublicKey;
|
|
450
450
|
liquidator: PublicKey;
|
|
@@ -482,7 +482,7 @@ export declare class LiquidationType {
|
|
|
482
482
|
liquidateSpot: {};
|
|
483
483
|
};
|
|
484
484
|
}
|
|
485
|
-
export
|
|
485
|
+
export type LiquidatePerpRecord = {
|
|
486
486
|
marketIndex: number;
|
|
487
487
|
oraclePrice: BN;
|
|
488
488
|
baseAssetAmount: BN;
|
|
@@ -494,7 +494,7 @@ export declare type LiquidatePerpRecord = {
|
|
|
494
494
|
liquidatorFee: BN;
|
|
495
495
|
ifFee: BN;
|
|
496
496
|
};
|
|
497
|
-
export
|
|
497
|
+
export type LiquidateSpotRecord = {
|
|
498
498
|
assetMarketIndex: number;
|
|
499
499
|
assetPrice: BN;
|
|
500
500
|
assetTransfer: BN;
|
|
@@ -503,7 +503,7 @@ export declare type LiquidateSpotRecord = {
|
|
|
503
503
|
liabilityTransfer: BN;
|
|
504
504
|
ifFee: BN;
|
|
505
505
|
};
|
|
506
|
-
export
|
|
506
|
+
export type LiquidateBorrowForPerpPnlRecord = {
|
|
507
507
|
perpMarketIndex: number;
|
|
508
508
|
marketOraclePrice: BN;
|
|
509
509
|
pnlTransfer: BN;
|
|
@@ -511,7 +511,7 @@ export declare type LiquidateBorrowForPerpPnlRecord = {
|
|
|
511
511
|
liabilityPrice: BN;
|
|
512
512
|
liabilityTransfer: BN;
|
|
513
513
|
};
|
|
514
|
-
export
|
|
514
|
+
export type LiquidatePerpPnlForDepositRecord = {
|
|
515
515
|
perpMarketIndex: number;
|
|
516
516
|
marketOraclePrice: BN;
|
|
517
517
|
pnlTransfer: BN;
|
|
@@ -519,7 +519,7 @@ export declare type LiquidatePerpPnlForDepositRecord = {
|
|
|
519
519
|
assetPrice: BN;
|
|
520
520
|
assetTransfer: BN;
|
|
521
521
|
};
|
|
522
|
-
export
|
|
522
|
+
export type PerpBankruptcyRecord = {
|
|
523
523
|
marketIndex: number;
|
|
524
524
|
pnl: BN;
|
|
525
525
|
ifPayment: BN;
|
|
@@ -527,13 +527,13 @@ export declare type PerpBankruptcyRecord = {
|
|
|
527
527
|
clawbackUserPayment: BN | null;
|
|
528
528
|
cumulativeFundingRateDelta: BN;
|
|
529
529
|
};
|
|
530
|
-
export
|
|
530
|
+
export type SpotBankruptcyRecord = {
|
|
531
531
|
marketIndex: number;
|
|
532
532
|
borrowAmount: BN;
|
|
533
533
|
cumulativeDepositInterestDelta: BN;
|
|
534
534
|
ifPayment: BN;
|
|
535
535
|
};
|
|
536
|
-
export
|
|
536
|
+
export type SettlePnlRecord = {
|
|
537
537
|
ts: BN;
|
|
538
538
|
user: PublicKey;
|
|
539
539
|
marketIndex: number;
|
|
@@ -544,12 +544,12 @@ export declare type SettlePnlRecord = {
|
|
|
544
544
|
settlePrice: BN;
|
|
545
545
|
explanation: SettlePnlExplanation;
|
|
546
546
|
};
|
|
547
|
-
export
|
|
547
|
+
export type OrderRecord = {
|
|
548
548
|
ts: BN;
|
|
549
549
|
user: PublicKey;
|
|
550
550
|
order: Order;
|
|
551
551
|
};
|
|
552
|
-
export
|
|
552
|
+
export type OrderActionRecord = {
|
|
553
553
|
ts: BN;
|
|
554
554
|
action: OrderAction;
|
|
555
555
|
actionExplanation: OrderActionExplanation;
|
|
@@ -579,7 +579,7 @@ export declare type OrderActionRecord = {
|
|
|
579
579
|
makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
580
580
|
oraclePrice: BN;
|
|
581
581
|
};
|
|
582
|
-
export
|
|
582
|
+
export type StateAccount = {
|
|
583
583
|
admin: PublicKey;
|
|
584
584
|
exchangeStatus: number;
|
|
585
585
|
whitelistMint: PublicKey;
|
|
@@ -603,7 +603,7 @@ export declare type StateAccount = {
|
|
|
603
603
|
initialPctToLiquidate: number;
|
|
604
604
|
liquidationDuration: number;
|
|
605
605
|
};
|
|
606
|
-
export
|
|
606
|
+
export type PerpMarketAccount = {
|
|
607
607
|
status: MarketStatus;
|
|
608
608
|
contractType: ContractType;
|
|
609
609
|
contractTier: ContractTier;
|
|
@@ -636,7 +636,7 @@ export declare type PerpMarketAccount = {
|
|
|
636
636
|
quoteMaxInsurance: BN;
|
|
637
637
|
};
|
|
638
638
|
};
|
|
639
|
-
export
|
|
639
|
+
export type HistoricalOracleData = {
|
|
640
640
|
lastOraclePrice: BN;
|
|
641
641
|
lastOracleDelay: BN;
|
|
642
642
|
lastOracleConf: BN;
|
|
@@ -644,14 +644,14 @@ export declare type HistoricalOracleData = {
|
|
|
644
644
|
lastOraclePriceTwap5Min: BN;
|
|
645
645
|
lastOraclePriceTwapTs: BN;
|
|
646
646
|
};
|
|
647
|
-
export
|
|
647
|
+
export type HistoricalIndexData = {
|
|
648
648
|
lastIndexBidPrice: BN;
|
|
649
649
|
lastIndexAskPrice: BN;
|
|
650
650
|
lastIndexPriceTwap: BN;
|
|
651
651
|
lastIndexPriceTwap5Min: BN;
|
|
652
652
|
lastIndexPriceTwapTs: BN;
|
|
653
653
|
};
|
|
654
|
-
export
|
|
654
|
+
export type SpotMarketAccount = {
|
|
655
655
|
status: MarketStatus;
|
|
656
656
|
assetTier: AssetTier;
|
|
657
657
|
marketIndex: number;
|
|
@@ -706,11 +706,11 @@ export declare type SpotMarketAccount = {
|
|
|
706
706
|
totalSpotFee: BN;
|
|
707
707
|
ordersEnabled: boolean;
|
|
708
708
|
};
|
|
709
|
-
export
|
|
709
|
+
export type PoolBalance = {
|
|
710
710
|
scaledBalance: BN;
|
|
711
711
|
marketIndex: number;
|
|
712
712
|
};
|
|
713
|
-
export
|
|
713
|
+
export type AMM = {
|
|
714
714
|
baseAssetReserve: BN;
|
|
715
715
|
sqrtK: BN;
|
|
716
716
|
cumulativeFundingRate: BN;
|
|
@@ -788,7 +788,7 @@ export declare type AMM = {
|
|
|
788
788
|
askBaseAssetReserve: BN;
|
|
789
789
|
askQuoteAssetReserve: BN;
|
|
790
790
|
};
|
|
791
|
-
export
|
|
791
|
+
export type PerpPosition = {
|
|
792
792
|
baseAssetAmount: BN;
|
|
793
793
|
lastCumulativeFundingRate: BN;
|
|
794
794
|
marketIndex: number;
|
|
@@ -804,7 +804,7 @@ export declare type PerpPosition = {
|
|
|
804
804
|
lastBaseAssetAmountPerLp: BN;
|
|
805
805
|
lastQuoteAssetAmountPerLp: BN;
|
|
806
806
|
};
|
|
807
|
-
export
|
|
807
|
+
export type UserStatsAccount = {
|
|
808
808
|
numberOfSubAccounts: number;
|
|
809
809
|
numberOfSubAccountsCreated: number;
|
|
810
810
|
makerVolume30D: BN;
|
|
@@ -826,7 +826,7 @@ export declare type UserStatsAccount = {
|
|
|
826
826
|
authority: PublicKey;
|
|
827
827
|
ifStakedQuoteAssetAmount: BN;
|
|
828
828
|
};
|
|
829
|
-
export
|
|
829
|
+
export type UserAccount = {
|
|
830
830
|
authority: PublicKey;
|
|
831
831
|
delegate: PublicKey;
|
|
832
832
|
name: number[];
|
|
@@ -848,7 +848,7 @@ export declare type UserAccount = {
|
|
|
848
848
|
liquidationStartSlot: BN;
|
|
849
849
|
isMarginTradingEnabled: boolean;
|
|
850
850
|
};
|
|
851
|
-
export
|
|
851
|
+
export type SpotPosition = {
|
|
852
852
|
marketIndex: number;
|
|
853
853
|
balanceType: SpotBalanceType;
|
|
854
854
|
scaledBalance: BN;
|
|
@@ -857,7 +857,7 @@ export declare type SpotPosition = {
|
|
|
857
857
|
openAsks: BN;
|
|
858
858
|
cumulativeDeposits: BN;
|
|
859
859
|
};
|
|
860
|
-
export
|
|
860
|
+
export type Order = {
|
|
861
861
|
status: OrderStatus;
|
|
862
862
|
orderType: OrderType;
|
|
863
863
|
marketType: MarketType;
|
|
@@ -883,7 +883,7 @@ export declare type Order = {
|
|
|
883
883
|
auctionEndPrice: BN;
|
|
884
884
|
maxTs: BN;
|
|
885
885
|
};
|
|
886
|
-
export
|
|
886
|
+
export type OrderParams = {
|
|
887
887
|
orderType: OrderType;
|
|
888
888
|
marketType: MarketType;
|
|
889
889
|
userOrderId: number;
|
|
@@ -914,33 +914,33 @@ export declare class PostOnlyParams {
|
|
|
914
914
|
tryPostOnly: {};
|
|
915
915
|
};
|
|
916
916
|
}
|
|
917
|
-
export
|
|
917
|
+
export type NecessaryOrderParams = {
|
|
918
918
|
orderType: OrderType;
|
|
919
919
|
marketIndex: number;
|
|
920
920
|
baseAssetAmount: BN;
|
|
921
921
|
direction: PositionDirection;
|
|
922
922
|
};
|
|
923
|
-
export
|
|
923
|
+
export type OptionalOrderParams = {
|
|
924
924
|
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
925
925
|
} & NecessaryOrderParams;
|
|
926
926
|
export declare const DefaultOrderParams: OrderParams;
|
|
927
|
-
export
|
|
927
|
+
export type MakerInfo = {
|
|
928
928
|
maker: PublicKey;
|
|
929
929
|
makerStats: PublicKey;
|
|
930
930
|
makerUserAccount: UserAccount;
|
|
931
931
|
order?: Order;
|
|
932
932
|
};
|
|
933
|
-
export
|
|
933
|
+
export type TakerInfo = {
|
|
934
934
|
taker: PublicKey;
|
|
935
935
|
takerStats: PublicKey;
|
|
936
936
|
takerUserAccount: UserAccount;
|
|
937
937
|
order: Order;
|
|
938
938
|
};
|
|
939
|
-
export
|
|
939
|
+
export type ReferrerInfo = {
|
|
940
940
|
referrer: PublicKey;
|
|
941
941
|
referrerStats: PublicKey;
|
|
942
942
|
};
|
|
943
|
-
export
|
|
943
|
+
export type TxParams = {
|
|
944
944
|
computeUnits?: number;
|
|
945
945
|
computeUnitsPrice?: number;
|
|
946
946
|
};
|
|
@@ -949,7 +949,7 @@ export interface IWallet {
|
|
|
949
949
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
950
950
|
publicKey: PublicKey;
|
|
951
951
|
}
|
|
952
|
-
export
|
|
952
|
+
export type FeeStructure = {
|
|
953
953
|
feeTiers: FeeTier[];
|
|
954
954
|
makerRebateNumerator: BN;
|
|
955
955
|
makerRebateDenominator: BN;
|
|
@@ -957,7 +957,7 @@ export declare type FeeStructure = {
|
|
|
957
957
|
flatFillerFee: BN;
|
|
958
958
|
referrerRewardEpochUpperBound: BN;
|
|
959
959
|
};
|
|
960
|
-
export
|
|
960
|
+
export type FeeTier = {
|
|
961
961
|
feeNumerator: number;
|
|
962
962
|
feeDenominator: number;
|
|
963
963
|
makerRebateNumerator: number;
|
|
@@ -967,12 +967,12 @@ export declare type FeeTier = {
|
|
|
967
967
|
refereeFeeNumerator: number;
|
|
968
968
|
refereeFeeDenominator: number;
|
|
969
969
|
};
|
|
970
|
-
export
|
|
970
|
+
export type OrderFillerRewardStructure = {
|
|
971
971
|
rewardNumerator: BN;
|
|
972
972
|
rewardDenominator: BN;
|
|
973
973
|
timeBasedRewardLowerBound: BN;
|
|
974
974
|
};
|
|
975
|
-
export
|
|
975
|
+
export type OracleGuardRails = {
|
|
976
976
|
priceDivergence: {
|
|
977
977
|
markOracleDivergenceNumerator: BN;
|
|
978
978
|
markOracleDivergenceDenominator: BN;
|
|
@@ -984,8 +984,8 @@ export declare type OracleGuardRails = {
|
|
|
984
984
|
tooVolatileRatio: BN;
|
|
985
985
|
};
|
|
986
986
|
};
|
|
987
|
-
export
|
|
988
|
-
export
|
|
987
|
+
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
988
|
+
export type InsuranceFundStake = {
|
|
989
989
|
marketIndex: number;
|
|
990
990
|
authority: PublicKey;
|
|
991
991
|
ifShares: BN;
|
|
@@ -994,7 +994,7 @@ export declare type InsuranceFundStake = {
|
|
|
994
994
|
lastWithdrawRequestValue: BN;
|
|
995
995
|
lastWithdrawRequestTs: BN;
|
|
996
996
|
};
|
|
997
|
-
export
|
|
997
|
+
export type SerumV3FulfillmentConfigAccount = {
|
|
998
998
|
fulfillmentType: SpotFulfillmentType;
|
|
999
999
|
status: SpotFulfillmentStatus;
|
|
1000
1000
|
pubkey: PublicKey;
|
|
@@ -1010,3 +1010,30 @@ export declare type SerumV3FulfillmentConfigAccount = {
|
|
|
1010
1010
|
serumOpenOrders: PublicKey;
|
|
1011
1011
|
serumSignerNonce: BN;
|
|
1012
1012
|
};
|
|
1013
|
+
export type ReferrerNameAccount = {
|
|
1014
|
+
name: number[];
|
|
1015
|
+
user: PublicKey;
|
|
1016
|
+
authority: PublicKey;
|
|
1017
|
+
userStats: PublicKey;
|
|
1018
|
+
};
|
|
1019
|
+
export type PerpMarketExtendedInfo = {
|
|
1020
|
+
marketIndex: number;
|
|
1021
|
+
/**
|
|
1022
|
+
* Min order size measured in base asset, using base precision
|
|
1023
|
+
*/
|
|
1024
|
+
minOrderSize: BN;
|
|
1025
|
+
/**
|
|
1026
|
+
* Margin maintenance percentage, using margin precision (1e4)
|
|
1027
|
+
*/
|
|
1028
|
+
marginMaintenance: number;
|
|
1029
|
+
/**
|
|
1030
|
+
* Max insurance available, measured in quote asset, using quote preicision
|
|
1031
|
+
*/
|
|
1032
|
+
availableInsurance: BN;
|
|
1033
|
+
/**
|
|
1034
|
+
* Pnl pool available, this is measured in quote asset, using quote precision.
|
|
1035
|
+
* Should be generated by using getTokenAmount and passing in the scaled balance of the base asset + quote spot account
|
|
1036
|
+
*/
|
|
1037
|
+
pnlPoolValue: BN;
|
|
1038
|
+
contractTier: ContractTier;
|
|
1039
|
+
};
|