@drift-labs/sdk 2.10.0-beta.1 → 2.10.0-beta.3
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/pollingDriftClientAccountSubscriber.js +12 -3
- package/lib/accounts/types.d.ts +5 -4
- package/lib/adminClient.js +96 -34
- 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 +4 -4
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/driftClient.d.ts +4 -3
- package/lib/driftClient.js +105 -64
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/types.d.ts +13 -13
- package/lib/factory/bigNum.js +4 -4
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +15 -6
- package/lib/math/oracles.js +2 -2
- package/lib/math/repeg.d.ts +1 -1
- package/lib/math/repeg.js +46 -19
- package/lib/math/trade.d.ts +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/testClient.d.ts +8 -0
- package/lib/testClient.js +22 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +43 -43
- package/lib/user.d.ts +1 -0
- package/lib/user.js +10 -6
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +3 -0
- package/lib/userMap/userStatsMap.js +3 -0
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +26 -3
- package/src/adminClient.ts +301 -169
- package/src/driftClient.ts +199 -118
- package/src/driftClientConfig.ts +1 -1
- package/src/idl/drift.json +1 -1
- package/src/index.ts +1 -0
- package/src/math/amm.ts +27 -12
- package/src/math/oracles.ts +6 -4
- package/src/math/repeg.ts +54 -26
- package/src/testClient.ts +40 -0
- package/src/user.ts +5 -0
- package/src/userMap/userMap.ts +2 -0
- package/src/userMap/userStatsMap.ts +2 -0
- package/src/assert/assert.js +0 -9
- package/src/examples/makeTradeExample.js +0 -157
- package/src/token/index.js +0 -38
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -17
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/lib/types.d.ts
CHANGED
|
@@ -317,8 +317,8 @@ export declare enum TradeSide {
|
|
|
317
317
|
Buy = 1,
|
|
318
318
|
Sell = 2
|
|
319
319
|
}
|
|
320
|
-
export
|
|
321
|
-
export
|
|
320
|
+
export type CandleResolution = '1' | '5' | '15' | '60' | '240' | 'D' | 'W' | 'M';
|
|
321
|
+
export type NewUserRecord = {
|
|
322
322
|
ts: BN;
|
|
323
323
|
userAuthority: PublicKey;
|
|
324
324
|
user: PublicKey;
|
|
@@ -326,7 +326,7 @@ export declare type NewUserRecord = {
|
|
|
326
326
|
name: number[];
|
|
327
327
|
referrer: PublicKey;
|
|
328
328
|
};
|
|
329
|
-
export
|
|
329
|
+
export type DepositRecord = {
|
|
330
330
|
ts: BN;
|
|
331
331
|
userAuthority: PublicKey;
|
|
332
332
|
user: PublicKey;
|
|
@@ -347,7 +347,7 @@ export declare type DepositRecord = {
|
|
|
347
347
|
explanation: DepositExplanation;
|
|
348
348
|
transferUser?: PublicKey;
|
|
349
349
|
};
|
|
350
|
-
export
|
|
350
|
+
export type SpotInterestRecord = {
|
|
351
351
|
ts: BN;
|
|
352
352
|
marketIndex: number;
|
|
353
353
|
depositBalance: BN;
|
|
@@ -358,7 +358,7 @@ export declare type SpotInterestRecord = {
|
|
|
358
358
|
optimalBorrowRate: number;
|
|
359
359
|
maxBorrowRate: number;
|
|
360
360
|
};
|
|
361
|
-
export
|
|
361
|
+
export type CurveRecord = {
|
|
362
362
|
ts: BN;
|
|
363
363
|
recordId: BN;
|
|
364
364
|
marketIndex: number;
|
|
@@ -406,7 +406,7 @@ export declare type InsuranceFundStakeRecord = {
|
|
|
406
406
|
userIfSharesAfter: BN;
|
|
407
407
|
totalIfSharesAfter: BN;
|
|
408
408
|
};
|
|
409
|
-
export
|
|
409
|
+
export type LPRecord = {
|
|
410
410
|
ts: BN;
|
|
411
411
|
user: PublicKey;
|
|
412
412
|
action: LPAction;
|
|
@@ -427,7 +427,7 @@ export declare class LPAction {
|
|
|
427
427
|
settleLiquidity: {};
|
|
428
428
|
};
|
|
429
429
|
}
|
|
430
|
-
export
|
|
430
|
+
export type FundingRateRecord = {
|
|
431
431
|
ts: BN;
|
|
432
432
|
recordId: BN;
|
|
433
433
|
marketIndex: number;
|
|
@@ -442,7 +442,7 @@ export declare type FundingRateRecord = {
|
|
|
442
442
|
baseAssetAmountWithAmm: BN;
|
|
443
443
|
baseAssetAmountWithUnsettledLp: BN;
|
|
444
444
|
};
|
|
445
|
-
export
|
|
445
|
+
export type FundingPaymentRecord = {
|
|
446
446
|
ts: BN;
|
|
447
447
|
userAuthority: PublicKey;
|
|
448
448
|
user: PublicKey;
|
|
@@ -453,7 +453,7 @@ export declare type FundingPaymentRecord = {
|
|
|
453
453
|
ammCumulativeFundingLong: BN;
|
|
454
454
|
ammCumulativeFundingShort: BN;
|
|
455
455
|
};
|
|
456
|
-
export
|
|
456
|
+
export type LiquidationRecord = {
|
|
457
457
|
ts: BN;
|
|
458
458
|
user: PublicKey;
|
|
459
459
|
liquidator: PublicKey;
|
|
@@ -491,7 +491,7 @@ export declare class LiquidationType {
|
|
|
491
491
|
liquidateSpot: {};
|
|
492
492
|
};
|
|
493
493
|
}
|
|
494
|
-
export
|
|
494
|
+
export type LiquidatePerpRecord = {
|
|
495
495
|
marketIndex: number;
|
|
496
496
|
oraclePrice: BN;
|
|
497
497
|
baseAssetAmount: BN;
|
|
@@ -503,7 +503,7 @@ export declare type LiquidatePerpRecord = {
|
|
|
503
503
|
liquidatorFee: BN;
|
|
504
504
|
ifFee: BN;
|
|
505
505
|
};
|
|
506
|
-
export
|
|
506
|
+
export type LiquidateSpotRecord = {
|
|
507
507
|
assetMarketIndex: number;
|
|
508
508
|
assetPrice: BN;
|
|
509
509
|
assetTransfer: BN;
|
|
@@ -512,7 +512,7 @@ export declare type LiquidateSpotRecord = {
|
|
|
512
512
|
liabilityTransfer: BN;
|
|
513
513
|
ifFee: BN;
|
|
514
514
|
};
|
|
515
|
-
export
|
|
515
|
+
export type LiquidateBorrowForPerpPnlRecord = {
|
|
516
516
|
perpMarketIndex: number;
|
|
517
517
|
marketOraclePrice: BN;
|
|
518
518
|
pnlTransfer: BN;
|
|
@@ -520,7 +520,7 @@ export declare type LiquidateBorrowForPerpPnlRecord = {
|
|
|
520
520
|
liabilityPrice: BN;
|
|
521
521
|
liabilityTransfer: BN;
|
|
522
522
|
};
|
|
523
|
-
export
|
|
523
|
+
export type LiquidatePerpPnlForDepositRecord = {
|
|
524
524
|
perpMarketIndex: number;
|
|
525
525
|
marketOraclePrice: BN;
|
|
526
526
|
pnlTransfer: BN;
|
|
@@ -528,7 +528,7 @@ export declare type LiquidatePerpPnlForDepositRecord = {
|
|
|
528
528
|
assetPrice: BN;
|
|
529
529
|
assetTransfer: BN;
|
|
530
530
|
};
|
|
531
|
-
export
|
|
531
|
+
export type PerpBankruptcyRecord = {
|
|
532
532
|
marketIndex: number;
|
|
533
533
|
pnl: BN;
|
|
534
534
|
ifPayment: BN;
|
|
@@ -536,13 +536,13 @@ export declare type PerpBankruptcyRecord = {
|
|
|
536
536
|
clawbackUserPayment: BN | null;
|
|
537
537
|
cumulativeFundingRateDelta: BN;
|
|
538
538
|
};
|
|
539
|
-
export
|
|
539
|
+
export type SpotBankruptcyRecord = {
|
|
540
540
|
marketIndex: number;
|
|
541
541
|
borrowAmount: BN;
|
|
542
542
|
cumulativeDepositInterestDelta: BN;
|
|
543
543
|
ifPayment: BN;
|
|
544
544
|
};
|
|
545
|
-
export
|
|
545
|
+
export type SettlePnlRecord = {
|
|
546
546
|
ts: BN;
|
|
547
547
|
user: PublicKey;
|
|
548
548
|
marketIndex: number;
|
|
@@ -553,12 +553,12 @@ export declare type SettlePnlRecord = {
|
|
|
553
553
|
settlePrice: BN;
|
|
554
554
|
explanation: SettlePnlExplanation;
|
|
555
555
|
};
|
|
556
|
-
export
|
|
556
|
+
export type OrderRecord = {
|
|
557
557
|
ts: BN;
|
|
558
558
|
user: PublicKey;
|
|
559
559
|
order: Order;
|
|
560
560
|
};
|
|
561
|
-
export
|
|
561
|
+
export type OrderActionRecord = {
|
|
562
562
|
ts: BN;
|
|
563
563
|
action: OrderAction;
|
|
564
564
|
actionExplanation: OrderActionExplanation;
|
|
@@ -588,7 +588,7 @@ export declare type OrderActionRecord = {
|
|
|
588
588
|
makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
589
589
|
oraclePrice: BN;
|
|
590
590
|
};
|
|
591
|
-
export
|
|
591
|
+
export type StateAccount = {
|
|
592
592
|
admin: PublicKey;
|
|
593
593
|
exchangeStatus: ExchangeStatus;
|
|
594
594
|
whitelistMint: PublicKey;
|
|
@@ -612,7 +612,7 @@ export declare type StateAccount = {
|
|
|
612
612
|
initialPctToLiquidate: number;
|
|
613
613
|
liquidationDuration: number;
|
|
614
614
|
};
|
|
615
|
-
export
|
|
615
|
+
export type PerpMarketAccount = {
|
|
616
616
|
status: MarketStatus;
|
|
617
617
|
contractType: ContractType;
|
|
618
618
|
contractTier: ContractTier;
|
|
@@ -645,7 +645,7 @@ export declare type PerpMarketAccount = {
|
|
|
645
645
|
quoteMaxInsurance: BN;
|
|
646
646
|
};
|
|
647
647
|
};
|
|
648
|
-
export
|
|
648
|
+
export type HistoricalOracleData = {
|
|
649
649
|
lastOraclePrice: BN;
|
|
650
650
|
lastOracleDelay: BN;
|
|
651
651
|
lastOracleConf: BN;
|
|
@@ -653,14 +653,14 @@ export declare type HistoricalOracleData = {
|
|
|
653
653
|
lastOraclePriceTwap5Min: BN;
|
|
654
654
|
lastOraclePriceTwapTs: BN;
|
|
655
655
|
};
|
|
656
|
-
export
|
|
656
|
+
export type HistoricalIndexData = {
|
|
657
657
|
lastIndexBidPrice: BN;
|
|
658
658
|
lastIndexAskPrice: BN;
|
|
659
659
|
lastIndexPriceTwap: BN;
|
|
660
660
|
lastIndexPriceTwap5Min: BN;
|
|
661
661
|
lastIndexPriceTwapTs: BN;
|
|
662
662
|
};
|
|
663
|
-
export
|
|
663
|
+
export type SpotMarketAccount = {
|
|
664
664
|
status: MarketStatus;
|
|
665
665
|
assetTier: AssetTier;
|
|
666
666
|
marketIndex: number;
|
|
@@ -715,11 +715,11 @@ export declare type SpotMarketAccount = {
|
|
|
715
715
|
totalSpotFee: BN;
|
|
716
716
|
ordersEnabled: boolean;
|
|
717
717
|
};
|
|
718
|
-
export
|
|
718
|
+
export type PoolBalance = {
|
|
719
719
|
scaledBalance: BN;
|
|
720
720
|
marketIndex: number;
|
|
721
721
|
};
|
|
722
|
-
export
|
|
722
|
+
export type AMM = {
|
|
723
723
|
baseAssetReserve: BN;
|
|
724
724
|
sqrtK: BN;
|
|
725
725
|
cumulativeFundingRate: BN;
|
|
@@ -797,7 +797,7 @@ export declare type AMM = {
|
|
|
797
797
|
askBaseAssetReserve: BN;
|
|
798
798
|
askQuoteAssetReserve: BN;
|
|
799
799
|
};
|
|
800
|
-
export
|
|
800
|
+
export type PerpPosition = {
|
|
801
801
|
baseAssetAmount: BN;
|
|
802
802
|
lastCumulativeFundingRate: BN;
|
|
803
803
|
marketIndex: number;
|
|
@@ -813,7 +813,7 @@ export declare type PerpPosition = {
|
|
|
813
813
|
lastBaseAssetAmountPerLp: BN;
|
|
814
814
|
lastQuoteAssetAmountPerLp: BN;
|
|
815
815
|
};
|
|
816
|
-
export
|
|
816
|
+
export type UserStatsAccount = {
|
|
817
817
|
numberOfSubAccounts: number;
|
|
818
818
|
numberOfSubAccountsCreated: number;
|
|
819
819
|
makerVolume30D: BN;
|
|
@@ -835,7 +835,7 @@ export declare type UserStatsAccount = {
|
|
|
835
835
|
authority: PublicKey;
|
|
836
836
|
ifStakedQuoteAssetAmount: BN;
|
|
837
837
|
};
|
|
838
|
-
export
|
|
838
|
+
export type UserAccount = {
|
|
839
839
|
authority: PublicKey;
|
|
840
840
|
delegate: PublicKey;
|
|
841
841
|
name: number[];
|
|
@@ -857,7 +857,7 @@ export declare type UserAccount = {
|
|
|
857
857
|
liquidationStartSlot: BN;
|
|
858
858
|
isMarginTradingEnabled: boolean;
|
|
859
859
|
};
|
|
860
|
-
export
|
|
860
|
+
export type SpotPosition = {
|
|
861
861
|
marketIndex: number;
|
|
862
862
|
balanceType: SpotBalanceType;
|
|
863
863
|
scaledBalance: BN;
|
|
@@ -866,7 +866,7 @@ export declare type SpotPosition = {
|
|
|
866
866
|
openAsks: BN;
|
|
867
867
|
cumulativeDeposits: BN;
|
|
868
868
|
};
|
|
869
|
-
export
|
|
869
|
+
export type Order = {
|
|
870
870
|
status: OrderStatus;
|
|
871
871
|
orderType: OrderType;
|
|
872
872
|
marketType: MarketType;
|
|
@@ -892,7 +892,7 @@ export declare type Order = {
|
|
|
892
892
|
auctionEndPrice: BN;
|
|
893
893
|
maxTs: BN;
|
|
894
894
|
};
|
|
895
|
-
export
|
|
895
|
+
export type OrderParams = {
|
|
896
896
|
orderType: OrderType;
|
|
897
897
|
marketType: MarketType;
|
|
898
898
|
userOrderId: number;
|
|
@@ -912,29 +912,29 @@ export declare type OrderParams = {
|
|
|
912
912
|
auctionStartPrice: BN | null;
|
|
913
913
|
auctionEndPrice: BN | null;
|
|
914
914
|
};
|
|
915
|
-
export
|
|
915
|
+
export type NecessaryOrderParams = {
|
|
916
916
|
orderType: OrderType;
|
|
917
917
|
marketIndex: number;
|
|
918
918
|
baseAssetAmount: BN;
|
|
919
919
|
direction: PositionDirection;
|
|
920
920
|
};
|
|
921
|
-
export
|
|
921
|
+
export type OptionalOrderParams = {
|
|
922
922
|
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
923
923
|
} & NecessaryOrderParams;
|
|
924
924
|
export declare const DefaultOrderParams: OrderParams;
|
|
925
|
-
export
|
|
925
|
+
export type MakerInfo = {
|
|
926
926
|
maker: PublicKey;
|
|
927
927
|
makerStats: PublicKey;
|
|
928
928
|
makerUserAccount: UserAccount;
|
|
929
929
|
order: Order;
|
|
930
930
|
};
|
|
931
|
-
export
|
|
931
|
+
export type TakerInfo = {
|
|
932
932
|
taker: PublicKey;
|
|
933
933
|
takerStats: PublicKey;
|
|
934
934
|
takerUserAccount: UserAccount;
|
|
935
935
|
order: Order;
|
|
936
936
|
};
|
|
937
|
-
export
|
|
937
|
+
export type ReferrerInfo = {
|
|
938
938
|
referrer: PublicKey;
|
|
939
939
|
referrerStats: PublicKey;
|
|
940
940
|
};
|
|
@@ -943,7 +943,7 @@ export interface IWallet {
|
|
|
943
943
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
944
944
|
publicKey: PublicKey;
|
|
945
945
|
}
|
|
946
|
-
export
|
|
946
|
+
export type FeeStructure = {
|
|
947
947
|
feeTiers: FeeTier[];
|
|
948
948
|
makerRebateNumerator: BN;
|
|
949
949
|
makerRebateDenominator: BN;
|
|
@@ -951,7 +951,7 @@ export declare type FeeStructure = {
|
|
|
951
951
|
flatFillerFee: BN;
|
|
952
952
|
referrerRewardEpochUpperBound: BN;
|
|
953
953
|
};
|
|
954
|
-
export
|
|
954
|
+
export type FeeTier = {
|
|
955
955
|
feeNumerator: number;
|
|
956
956
|
feeDenominator: number;
|
|
957
957
|
makerRebateNumerator: number;
|
|
@@ -961,12 +961,12 @@ export declare type FeeTier = {
|
|
|
961
961
|
refereeFeeNumerator: number;
|
|
962
962
|
refereeFeeDenominator: number;
|
|
963
963
|
};
|
|
964
|
-
export
|
|
964
|
+
export type OrderFillerRewardStructure = {
|
|
965
965
|
rewardNumerator: BN;
|
|
966
966
|
rewardDenominator: BN;
|
|
967
967
|
timeBasedRewardLowerBound: BN;
|
|
968
968
|
};
|
|
969
|
-
export
|
|
969
|
+
export type OracleGuardRails = {
|
|
970
970
|
priceDivergence: {
|
|
971
971
|
markOracleDivergenceNumerator: BN;
|
|
972
972
|
markOracleDivergenceDenominator: BN;
|
|
@@ -978,8 +978,8 @@ export declare type OracleGuardRails = {
|
|
|
978
978
|
tooVolatileRatio: BN;
|
|
979
979
|
};
|
|
980
980
|
};
|
|
981
|
-
export
|
|
982
|
-
export
|
|
981
|
+
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
982
|
+
export type InsuranceFundStake = {
|
|
983
983
|
marketIndex: number;
|
|
984
984
|
authority: PublicKey;
|
|
985
985
|
ifShares: BN;
|
|
@@ -988,7 +988,7 @@ export declare type InsuranceFundStake = {
|
|
|
988
988
|
lastWithdrawRequestValue: BN;
|
|
989
989
|
lastWithdrawRequestTs: BN;
|
|
990
990
|
};
|
|
991
|
-
export
|
|
991
|
+
export type SerumV3FulfillmentConfigAccount = {
|
|
992
992
|
fulfillmentType: SpotFulfillmentType;
|
|
993
993
|
status: SpotFulfillmentStatus;
|
|
994
994
|
pubkey: PublicKey;
|
package/lib/user.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class User {
|
|
|
29
29
|
fetchAccounts(): Promise<void>;
|
|
30
30
|
unsubscribe(): Promise<void>;
|
|
31
31
|
getUserAccount(): UserAccount;
|
|
32
|
+
forceGetUserAccount(): Promise<UserAccount>;
|
|
32
33
|
getUserAccountAndSlot(): DataAndSlot<UserAccount> | undefined;
|
|
33
34
|
/**
|
|
34
35
|
* Gets the user's current position for a given perp market. If the user has no position returns undefined
|
package/lib/user.js
CHANGED
|
@@ -12,6 +12,12 @@ const pollingUserAccountSubscriber_1 = require("./accounts/pollingUserAccountSub
|
|
|
12
12
|
const webSocketUserAccountSubscriber_1 = require("./accounts/webSocketUserAccountSubscriber");
|
|
13
13
|
const spotPosition_1 = require("./math/spotPosition");
|
|
14
14
|
class User {
|
|
15
|
+
get isSubscribed() {
|
|
16
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
17
|
+
}
|
|
18
|
+
set isSubscribed(val) {
|
|
19
|
+
this._isSubscribed = val;
|
|
20
|
+
}
|
|
15
21
|
constructor(config) {
|
|
16
22
|
var _a;
|
|
17
23
|
this._isSubscribed = false;
|
|
@@ -25,12 +31,6 @@ class User {
|
|
|
25
31
|
}
|
|
26
32
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
27
33
|
}
|
|
28
|
-
get isSubscribed() {
|
|
29
|
-
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
30
|
-
}
|
|
31
|
-
set isSubscribed(val) {
|
|
32
|
-
this._isSubscribed = val;
|
|
33
|
-
}
|
|
34
34
|
/**
|
|
35
35
|
* Subscribe to User state accounts
|
|
36
36
|
* @returns SusbcriptionSuccess result
|
|
@@ -52,6 +52,10 @@ class User {
|
|
|
52
52
|
getUserAccount() {
|
|
53
53
|
return this.accountSubscriber.getUserAccountAndSlot().data;
|
|
54
54
|
}
|
|
55
|
+
async forceGetUserAccount() {
|
|
56
|
+
await this.fetchAccounts();
|
|
57
|
+
return this.accountSubscriber.getUserAccountAndSlot().data;
|
|
58
|
+
}
|
|
55
59
|
getUserAccountAndSlot() {
|
|
56
60
|
return this.accountSubscriber.getUserAccountAndSlot();
|
|
57
61
|
}
|
package/lib/userConfig.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
-
export
|
|
4
|
+
export type UserConfig = {
|
|
5
5
|
accountSubscription?: UserSubscriptionConfig;
|
|
6
6
|
driftClient: DriftClient;
|
|
7
7
|
userAccountPublicKey: PublicKey;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type UserSubscriptionConfig = {
|
|
10
10
|
type: 'websocket';
|
|
11
11
|
} | {
|
|
12
12
|
type: 'polling';
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -26,6 +26,9 @@ class UserMap {
|
|
|
26
26
|
if (this.accountSubscription.type === 'polling') {
|
|
27
27
|
await (0, __1.bulkPollingUserSubscribe)(userArray, this.accountSubscription.accountLoader);
|
|
28
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
await Promise.all(userArray.map((user) => user.subscribe()));
|
|
31
|
+
}
|
|
29
32
|
for (const user of userArray) {
|
|
30
33
|
this.userMap.set(user.getUserAccountPublicKey().toString(), user);
|
|
31
34
|
}
|
|
@@ -30,6 +30,9 @@ class UserStatsMap {
|
|
|
30
30
|
if (this.accountSubscription.type === 'polling') {
|
|
31
31
|
await (0, __1.bulkPollingUserStatsSubscribe)(userStatArray, this.accountSubscription.accountLoader);
|
|
32
32
|
}
|
|
33
|
+
else {
|
|
34
|
+
await Promise.all(userStatArray.map((userStat) => userStat.subscribe()));
|
|
35
|
+
}
|
|
33
36
|
for (const userStat of userStatArray) {
|
|
34
37
|
this.userStatsMap.set(userStat.getAccount().authority.toString(), userStat);
|
|
35
38
|
}
|
package/lib/userStatsConfig.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
-
export
|
|
4
|
+
export type UserStatsConfig = {
|
|
5
5
|
accountSubscription?: UserStatsSubscriptionConfig;
|
|
6
6
|
driftClient: DriftClient;
|
|
7
7
|
userStatsAccountPublicKey: PublicKey;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type UserStatsSubscriptionConfig = {
|
|
10
10
|
type: 'websocket';
|
|
11
11
|
} | {
|
|
12
12
|
type: 'polling';
|
package/package.json
CHANGED
|
@@ -340,21 +340,44 @@ export class PollingDriftClientAccountSubscriber
|
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
async addSpotMarket(marketIndex: number): Promise<boolean> {
|
|
343
|
+
const marketPublicKey = await getSpotMarketPublicKey(
|
|
344
|
+
this.program.programId,
|
|
345
|
+
marketIndex
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
if (this.accountsToPoll.has(marketPublicKey.toString())) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
|
|
343
352
|
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
344
|
-
|
|
353
|
+
|
|
354
|
+
const accountToPoll = this.accountsToPoll.get(marketPublicKey.toString());
|
|
355
|
+
|
|
345
356
|
await this.addAccountToAccountLoader(accountToPoll);
|
|
346
357
|
return true;
|
|
347
358
|
}
|
|
348
359
|
|
|
349
360
|
async addPerpMarket(marketIndex: number): Promise<boolean> {
|
|
361
|
+
const marketPublicKey = await getPerpMarketPublicKey(
|
|
362
|
+
this.program.programId,
|
|
363
|
+
marketIndex
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
if (this.accountsToPoll.has(marketPublicKey.toString())) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
|
|
350
370
|
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
351
|
-
const accountToPoll = this.accountsToPoll.get(
|
|
371
|
+
const accountToPoll = this.accountsToPoll.get(marketPublicKey.toString());
|
|
352
372
|
await this.addAccountToAccountLoader(accountToPoll);
|
|
353
373
|
return true;
|
|
354
374
|
}
|
|
355
375
|
|
|
356
376
|
async addOracle(oracleInfo: OracleInfo): Promise<boolean> {
|
|
357
|
-
if (
|
|
377
|
+
if (
|
|
378
|
+
oracleInfo.publicKey.equals(PublicKey.default) ||
|
|
379
|
+
this.oraclesToPoll.has(oracleInfo.publicKey.toString())
|
|
380
|
+
) {
|
|
358
381
|
return true;
|
|
359
382
|
}
|
|
360
383
|
|