@drift-labs/sdk 0.2.0-master.25 → 0.2.0-master.27
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/pollingClearingHouseAccountSubscriber.d.ts +14 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +30 -27
- package/lib/accounts/types.d.ts +9 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +15 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +38 -34
- package/lib/addresses/pda.d.ts +7 -6
- package/lib/addresses/pda.js +31 -27
- package/lib/admin.d.ts +13 -7
- package/lib/admin.js +111 -44
- package/lib/clearingHouse.d.ts +71 -42
- package/lib/clearingHouse.js +767 -278
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +24 -22
- package/lib/clearingHouseUser.js +273 -177
- package/lib/config.d.ts +7 -7
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +12 -12
- package/lib/constants/numericConstants.js +13 -13
- package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
- package/lib/constants/{markets.js → perpMarkets.js} +4 -4
- package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
- package/lib/constants/{banks.js → spotMarkets.js} +16 -16
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/events/types.d.ts +2 -1
- package/lib/events/types.js +1 -0
- package/lib/examples/makeTradeExample.js +7 -7
- package/lib/idl/clearing_house.json +1152 -503
- package/lib/index.d.ts +10 -3
- package/lib/index.js +10 -3
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +1 -1
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +2 -1
- package/lib/math/margin.d.ts +4 -4
- package/lib/math/margin.js +18 -11
- package/lib/math/market.d.ts +11 -10
- package/lib/math/market.js +30 -7
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +6 -6
- package/lib/math/orders.js +31 -16
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +193 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/state.js +2 -2
- package/lib/math/trade.d.ts +4 -4
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumSubscriber.d.ts +23 -0
- package/lib/serum/serumSubscriber.js +41 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/serum/types.js +2 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +4 -2
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +148 -57
- package/lib/types.js +39 -11
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +42 -38
- package/src/accounts/types.ts +12 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +65 -52
- package/src/addresses/pda.ts +49 -44
- package/src/admin.ts +190 -55
- package/src/clearingHouse.ts +1092 -365
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +518 -255
- package/src/config.ts +30 -30
- package/src/constants/numericConstants.ts +17 -15
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/events/types.ts +3 -0
- package/src/examples/makeTradeExample.js +152 -75
- package/src/examples/makeTradeExample.ts +10 -8
- package/src/idl/clearing_house.json +1152 -503
- package/src/index.ts +10 -3
- package/src/math/amm.ts +6 -3
- package/src/math/funding.ts +7 -7
- package/src/math/margin.ts +34 -23
- package/src/math/market.ts +72 -20
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.ts +33 -25
- package/src/math/position.ts +31 -31
- package/src/math/spotBalance.ts +316 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.ts +4 -4
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.ts +13 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.ts +2 -1
- package/src/types.ts +135 -56
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/constants/numericConstants.js +0 -41
- package/src/math/bankBalance.ts +0 -258
- package/src/math/oracles.js +0 -26
- package/src/math/state.js +0 -15
- package/src/orderParams.js +0 -20
- package/src/slot/SlotSubscriber.js +0 -39
- package/src/tokenFaucet.js +0 -189
|
@@ -14,8 +14,8 @@ export declare type ClearingHouseConfig = {
|
|
|
14
14
|
txSenderConfig?: TxSenderConfig;
|
|
15
15
|
userIds?: number[];
|
|
16
16
|
activeUserId?: number;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
perpMarketIndexes?: BN[];
|
|
18
|
+
spotMarketIndexes?: BN[];
|
|
19
19
|
oracleInfos?: OracleInfo[];
|
|
20
20
|
env?: DriftEnv;
|
|
21
21
|
userStats?: boolean;
|
|
@@ -4,9 +4,9 @@ import { PublicKey } from '@solana/web3.js';
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
6
|
import { ClearingHouse } from './clearingHouse';
|
|
7
|
-
import { MarginCategory, Order, UserAccount,
|
|
7
|
+
import { MarginCategory, Order, UserAccount, PerpPosition } from './types';
|
|
8
8
|
import { UserAccountSubscriber, UserAccountEvents, DataAndSlot } from './accounts/types';
|
|
9
|
-
import { PositionDirection, BN } from '.';
|
|
9
|
+
import { PositionDirection, BN, SpotMarketAccount } from '.';
|
|
10
10
|
import { OraclePriceData } from './oracles/types';
|
|
11
11
|
import { ClearingHouseUserConfig } from './clearingHouseUserConfig';
|
|
12
12
|
export declare class ClearingHouseUser {
|
|
@@ -35,9 +35,9 @@ export declare class ClearingHouseUser {
|
|
|
35
35
|
* @param marketIndex
|
|
36
36
|
* @returns userPosition
|
|
37
37
|
*/
|
|
38
|
-
getUserPosition(marketIndex: BN):
|
|
39
|
-
getEmptyPosition(marketIndex: BN):
|
|
40
|
-
getClonedPosition(position:
|
|
38
|
+
getUserPosition(marketIndex: BN): PerpPosition | undefined;
|
|
39
|
+
getEmptyPosition(marketIndex: BN): PerpPosition;
|
|
40
|
+
getClonedPosition(position: PerpPosition): PerpPosition;
|
|
41
41
|
/**
|
|
42
42
|
* @param orderId
|
|
43
43
|
* @returns Order
|
|
@@ -56,7 +56,7 @@ export declare class ClearingHouseUser {
|
|
|
56
56
|
* @returns : the dust base asset amount (ie, < stepsize)
|
|
57
57
|
* @returns : pnl from settle
|
|
58
58
|
*/
|
|
59
|
-
getSettledLPPosition(marketIndex: BN): [
|
|
59
|
+
getSettledLPPosition(marketIndex: BN): [PerpPosition, BN, BN];
|
|
60
60
|
/**
|
|
61
61
|
* calculates Buying Power = FC * MAX_LEVERAGE
|
|
62
62
|
* @returns : Precision QUOTE_PRECISION
|
|
@@ -70,7 +70,7 @@ export declare class ClearingHouseUser {
|
|
|
70
70
|
/**
|
|
71
71
|
* @returns The margin requirement of a certain type (Initial or Maintenance) in USDC. : QUOTE_PRECISION
|
|
72
72
|
*/
|
|
73
|
-
getMarginRequirement(
|
|
73
|
+
getMarginRequirement(marginCategory: MarginCategory, liquidationBuffer?: BN): BN;
|
|
74
74
|
/**
|
|
75
75
|
* @returns The initial margin requirement in USDC. : QUOTE_PRECISION
|
|
76
76
|
*/
|
|
@@ -78,7 +78,7 @@ export declare class ClearingHouseUser {
|
|
|
78
78
|
/**
|
|
79
79
|
* @returns The maintenance margin requirement in USDC. : QUOTE_PRECISION
|
|
80
80
|
*/
|
|
81
|
-
getMaintenanceMarginRequirement(): BN;
|
|
81
|
+
getMaintenanceMarginRequirement(liquidationBuffer?: BN): BN;
|
|
82
82
|
/**
|
|
83
83
|
* calculates unrealized position price pnl
|
|
84
84
|
* @returns : Precision QUOTE_PRECISION
|
|
@@ -89,9 +89,11 @@ export declare class ClearingHouseUser {
|
|
|
89
89
|
* @returns : Precision QUOTE_PRECISION
|
|
90
90
|
*/
|
|
91
91
|
getUnrealizedFundingPNL(marketIndex?: BN): BN;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
getSpotMarketLiabilityValue(marketIndex?: BN, marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
93
|
+
getSpotLiabilityValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
|
|
94
|
+
getSpotMarketAssetValue(marketIndex?: BN, marginCategory?: MarginCategory, includeOpenOrders?: boolean): BN;
|
|
95
|
+
getSpotAssetValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory): BN;
|
|
96
|
+
getNetSpotMarketValue(withWeightMarginCategory?: MarginCategory): BN;
|
|
95
97
|
/**
|
|
96
98
|
* calculates TotalCollateral: collateral + unrealized pnl
|
|
97
99
|
* @returns : Precision QUOTE_PRECISION
|
|
@@ -101,23 +103,23 @@ export declare class ClearingHouseUser {
|
|
|
101
103
|
* calculates sum of position value across all positions in margin system
|
|
102
104
|
* @returns : Precision QUOTE_PRECISION
|
|
103
105
|
*/
|
|
104
|
-
|
|
106
|
+
getTotalPerpPositionValue(marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
105
107
|
/**
|
|
106
108
|
* calculates position value in margin system
|
|
107
109
|
* @returns : Precision QUOTE_PRECISION
|
|
108
110
|
*/
|
|
109
|
-
|
|
110
|
-
getPositionSide(currentPosition: Pick<
|
|
111
|
+
getPerpPositionValue(marketIndex: BN, oraclePriceData: OraclePriceData): BN;
|
|
112
|
+
getPositionSide(currentPosition: Pick<PerpPosition, 'baseAssetAmount'>): PositionDirection | undefined;
|
|
111
113
|
/**
|
|
112
114
|
* calculates average exit price (optionally for closing up to 100% of position)
|
|
113
115
|
* @returns : Precision MARK_PRICE_PRECISION
|
|
114
116
|
*/
|
|
115
|
-
getPositionEstimatedExitPriceAndPnl(position:
|
|
117
|
+
getPositionEstimatedExitPriceAndPnl(position: PerpPosition, amountToClose?: BN, useAMMClose?: boolean): [BN, BN];
|
|
116
118
|
/**
|
|
117
119
|
* calculates current user leverage across all positions
|
|
118
120
|
* @returns : Precision TEN_THOUSAND
|
|
119
121
|
*/
|
|
120
|
-
getLeverage(): BN;
|
|
122
|
+
getLeverage(marginCategory?: MarginCategory): BN;
|
|
121
123
|
/**
|
|
122
124
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
123
125
|
* @params category {Initial, Partial, Maintenance}
|
|
@@ -128,8 +130,8 @@ export declare class ClearingHouseUser {
|
|
|
128
130
|
* calculates margin ratio: total collateral / |total position value|
|
|
129
131
|
* @returns : Precision TEN_THOUSAND
|
|
130
132
|
*/
|
|
131
|
-
getMarginRatio(): BN;
|
|
132
|
-
canBeLiquidated():
|
|
133
|
+
getMarginRatio(marginCategory?: MarginCategory): BN;
|
|
134
|
+
canBeLiquidated(): boolean;
|
|
133
135
|
/**
|
|
134
136
|
* Checks if any user position cumulative funding differs from respective market cumulative funding
|
|
135
137
|
* @returns
|
|
@@ -137,12 +139,12 @@ export declare class ClearingHouseUser {
|
|
|
137
139
|
needsToSettleFundingPayment(): boolean;
|
|
138
140
|
/**
|
|
139
141
|
* Calculate the liquidation price of a position, with optional parameter to calculate the liquidation price after a trade
|
|
140
|
-
* @param
|
|
142
|
+
* @param PerpPosition
|
|
141
143
|
* @param positionBaseSizeChange // change in position size to calculate liquidation price for : Precision 10^13
|
|
142
144
|
* @param partial
|
|
143
145
|
* @returns Precision : MARK_PRICE_PRECISION
|
|
144
146
|
*/
|
|
145
|
-
liquidationPrice(
|
|
147
|
+
liquidationPrice(perpPosition: Pick<PerpPosition, 'marketIndex'>, positionBaseSizeChange?: BN): BN;
|
|
146
148
|
/**
|
|
147
149
|
* Calculates the estimated liquidation price for a position after closing a quote amount of the position.
|
|
148
150
|
* @param positionMarketIndex
|
|
@@ -191,7 +193,7 @@ export declare class ClearingHouseUser {
|
|
|
191
193
|
* @param marketToIgnore
|
|
192
194
|
* @returns positionValue : Precision QUOTE_PRECISION
|
|
193
195
|
*/
|
|
194
|
-
private
|
|
196
|
+
private getTotalPerpPositionValueExcludingMarket;
|
|
195
197
|
private getOracleDataForMarket;
|
|
196
|
-
private
|
|
198
|
+
private getOracleDataForSpotMarket;
|
|
197
199
|
}
|