@drift-labs/sdk 0.2.0-temp.2 → 2.0.0
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 +27 -29
- package/lib/accounts/bulkAccountLoader.d.ts +2 -0
- package/lib/accounts/bulkAccountLoader.js +36 -29
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +107 -0
- package/lib/accounts/types.d.ts +26 -15
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +15 -9
- package/lib/addresses/pda.js +73 -35
- package/lib/adminClient.d.ts +65 -0
- package/lib/adminClient.js +637 -0
- package/lib/config.d.ts +10 -10
- package/lib/config.js +26 -22
- package/lib/constants/numericConstants.d.ts +29 -12
- package/lib/constants/numericConstants.js +40 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +20 -9
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +63 -0
- package/lib/dlob/DLOB.d.ts +82 -0
- package/lib/dlob/DLOB.js +694 -0
- package/lib/dlob/DLOBNode.d.ts +54 -0
- package/lib/dlob/DLOBNode.js +77 -0
- package/lib/dlob/NodeList.d.ts +27 -0
- package/lib/dlob/NodeList.js +144 -0
- package/lib/driftClient.d.ts +234 -0
- package/lib/driftClient.js +2108 -0
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/events/eventList.d.ts +0 -1
- package/lib/events/eventList.js +0 -7
- package/lib/events/eventSubscriber.d.ts +5 -2
- package/lib/events/eventSubscriber.js +25 -11
- package/lib/events/fetchLogs.d.ts +13 -2
- package/lib/events/fetchLogs.js +45 -14
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +7 -3
- package/lib/events/sort.js +8 -11
- package/lib/events/txEventCache.d.ts +0 -2
- package/lib/events/txEventCache.js +0 -14
- package/lib/events/types.d.ts +11 -3
- package/lib/events/types.js +8 -0
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/examples/makeTradeExample.js +30 -18
- package/lib/factory/bigNum.d.ts +8 -4
- package/lib/factory/bigNum.js +109 -19
- package/lib/idl/drift.json +8392 -0
- package/lib/index.d.ts +29 -12
- package/lib/index.js +29 -12
- package/lib/math/amm.d.ts +9 -6
- package/lib/math/amm.js +91 -38
- package/lib/math/conversion.js +1 -1
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +23 -21
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +82 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +70 -10
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +16 -6
- package/lib/math/orders.js +97 -17
- package/lib/math/position.d.ts +27 -13
- package/lib/math/position.js +91 -37
- package/lib/math/repeg.js +17 -8
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +192 -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/trade.d.ts +10 -10
- package/lib/math/trade.js +27 -31
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +27 -0
- package/lib/serum/serumSubscriber.js +56 -0
- package/lib/serum/types.d.ts +11 -0
- package/{src/oracles → lib/serum}/types.js +0 -0
- package/lib/tokenFaucet.d.ts +1 -0
- package/lib/tokenFaucet.js +23 -12
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +631 -222
- package/lib/types.js +137 -24
- package/lib/user.d.ts +228 -0
- package/lib/user.js +959 -0
- package/lib/userConfig.d.ts +14 -0
- package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
- package/lib/userMap/userMap.d.ts +41 -0
- package/lib/userMap/userMap.js +85 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/lib/userStats.d.ts +18 -0
- package/lib/userStats.js +49 -0
- package/lib/userStatsConfig.d.ts +14 -0
- package/{src/clearingHouseConfig.js → lib/userStatsConfig.js} +0 -0
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +12 -5
- package/src/accounts/bulkAccountLoader.ts +44 -34
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +2 -3
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
- package/src/accounts/types.ts +35 -15
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +3 -4
- package/src/addresses/pda.ts +105 -33
- package/src/adminClient.ts +1207 -0
- package/src/config.ts +41 -34
- package/src/constants/numericConstants.ts +59 -26
- package/src/constants/{markets.ts → perpMarkets.ts} +22 -11
- package/src/constants/spotMarkets.ts +83 -0
- package/src/dlob/DLOB.ts +1120 -0
- package/src/dlob/DLOBNode.ts +155 -0
- package/src/dlob/NodeList.ts +195 -0
- package/src/driftClient.ts +3594 -0
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
- package/src/events/eventList.ts +1 -8
- package/src/events/eventSubscriber.ts +36 -14
- package/src/events/fetchLogs.ts +60 -15
- package/src/events/pollingLogProvider.ts +11 -3
- package/src/events/sort.ts +11 -15
- package/src/events/txEventCache.ts +0 -16
- package/src/events/types.ts +27 -2
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.js +152 -75
- package/src/examples/makeTradeExample.ts +44 -28
- package/src/factory/bigNum.ts +150 -22
- package/src/idl/drift.json +8392 -0
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +29 -12
- package/src/math/amm.ts +161 -48
- package/src/math/conversion.ts +2 -2
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +41 -31
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +133 -0
- package/src/math/market.ts +143 -14
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +168 -26
- package/src/math/position.ts +133 -59
- package/src/math/repeg.ts +19 -9
- package/src/math/spotBalance.ts +319 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +33 -37
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +16 -8
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +99 -0
- package/src/serum/types.ts +13 -0
- package/src/tokenFaucet.ts +38 -15
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.ts +2 -1
- package/src/types.ts +594 -195
- package/src/user.ts +1599 -0
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +124 -0
- package/src/userMap/userStatsMap.ts +108 -0
- package/src/userName.ts +2 -1
- package/src/userStats.ts +75 -0
- package/src/userStatsConfig.ts +18 -0
- package/src/util/getTokenAddress.ts +18 -0
- package/tests/bn/test.ts +46 -11
- package/tests/dlob/helpers.ts +619 -0
- package/tests/dlob/test.ts +4586 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
- package/lib/admin.d.ts +0 -44
- package/lib/admin.js +0 -438
- package/lib/clearingHouse.d.ts +0 -146
- package/lib/clearingHouse.js +0 -1154
- package/lib/clearingHouseUser.d.ts +0 -187
- package/lib/clearingHouseUser.js +0 -634
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -41
- package/lib/constants/markets.d.ts +0 -19
- package/lib/idl/clearing_house.json +0 -4464
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/accounts/bulkAccountLoader.js +0 -197
- package/src/accounts/bulkUserSubscription.js +0 -33
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
- package/src/accounts/pollingOracleSubscriber.js +0 -93
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
- package/src/accounts/pollingUserAccountSubscriber.js +0 -132
- package/src/accounts/types.js +0 -10
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -93
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
- package/src/addresses/marketAddresses.js +0 -26
- package/src/admin.js +0 -517
- package/src/admin.ts +0 -730
- package/src/clearingHouse.ts +0 -1828
- package/src/clearingHouseUser.ts +0 -978
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/config.js +0 -67
- package/src/constants/banks.js +0 -42
- package/src/constants/banks.ts +0 -50
- package/src/constants/markets.js +0 -42
- package/src/constants/numericConstants.js +0 -41
- package/src/events/eventSubscriber.js +0 -139
- package/src/events/fetchLogs.js +0 -50
- package/src/events/pollingLogProvider.js +0 -64
- package/src/events/sort.js +0 -44
- package/src/events/txEventCache.js +0 -71
- package/src/events/types.js +0 -20
- package/src/events/webSocketLogProvider.js +0 -41
- package/src/factory/bigNum.js +0 -390
- package/src/factory/oracleClient.js +0 -20
- package/src/idl/clearing_house.json +0 -4464
- package/src/index.js +0 -69
- package/src/math/amm.js +0 -369
- package/src/math/auction.js +0 -42
- package/src/math/bankBalance.ts +0 -112
- package/src/math/conversion.js +0 -11
- package/src/math/funding.js +0 -248
- package/src/math/oracles.js +0 -26
- package/src/math/repeg.js +0 -128
- package/src/math/state.js +0 -15
- package/src/math/state.ts +0 -14
- package/src/math/trade.js +0 -253
- package/src/math/utils.js +0 -26
- package/src/math/utils.js.map +0 -1
- package/src/mockUSDCFaucet.js +0 -280
- 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/orderParams.js +0 -20
- package/src/orders.ts +0 -245
- package/src/slot/SlotSubscriber.js +0 -39
- package/src/tokenFaucet.js +0 -189
- package/src/types.js +0 -125
- package/src/userName.js +0 -20
- package/src/wallet.js +0 -35
package/lib/types.js
CHANGED
|
@@ -1,18 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultOrderParams = exports.LiquidationType = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.
|
|
3
|
+
exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
// # Utility Types / Enums / Constants
|
|
6
|
+
class ExchangeStatus {
|
|
7
|
+
}
|
|
8
|
+
exports.ExchangeStatus = ExchangeStatus;
|
|
9
|
+
ExchangeStatus.ACTIVE = { active: {} };
|
|
10
|
+
ExchangeStatus.FUNDING_PAUSED = { fundingPaused: {} };
|
|
11
|
+
ExchangeStatus.AMM_PAUSED = { ammPaused: {} };
|
|
12
|
+
ExchangeStatus.FILL_PAUSED = { fillPaused: {} };
|
|
13
|
+
ExchangeStatus.LIQ_PAUSED = { liqPaused: {} };
|
|
14
|
+
ExchangeStatus.WITHDRAW_PAUSED = { withdrawPaused: {} };
|
|
15
|
+
ExchangeStatus.PAUSED = { paused: {} };
|
|
16
|
+
class MarketStatus {
|
|
17
|
+
}
|
|
18
|
+
exports.MarketStatus = MarketStatus;
|
|
19
|
+
MarketStatus.INITIALIZED = { initialized: {} };
|
|
20
|
+
MarketStatus.ACTIVE = { active: {} };
|
|
21
|
+
MarketStatus.FUNDING_PAUSED = { fundingPaused: {} };
|
|
22
|
+
MarketStatus.AMM_PAUSED = { ammPaused: {} };
|
|
23
|
+
MarketStatus.FILL_PAUSED = { fillPaused: {} };
|
|
24
|
+
MarketStatus.WITHDRAW_PAUSED = { withdrawPaused: {} };
|
|
25
|
+
MarketStatus.REDUCE_ONLY = { reduceOnly: {} };
|
|
26
|
+
MarketStatus.SETTLEMENT = { settlement: {} };
|
|
27
|
+
MarketStatus.DELISTED = { delisted: {} };
|
|
28
|
+
class UserStatus {
|
|
29
|
+
}
|
|
30
|
+
exports.UserStatus = UserStatus;
|
|
31
|
+
UserStatus.ACTIVE = { active: {} };
|
|
32
|
+
UserStatus.BEING_LIQUIDATED = { beingLiquidated: {} };
|
|
33
|
+
UserStatus.BANKRUPT = { bankrupt: {} };
|
|
34
|
+
class ContractType {
|
|
35
|
+
}
|
|
36
|
+
exports.ContractType = ContractType;
|
|
37
|
+
ContractType.PERPETUAL = { perpetual: {} };
|
|
38
|
+
ContractType.FUTURE = { future: {} };
|
|
39
|
+
class ContractTier {
|
|
40
|
+
}
|
|
41
|
+
exports.ContractTier = ContractTier;
|
|
42
|
+
ContractTier.A = { a: {} };
|
|
43
|
+
ContractTier.B = { b: {} };
|
|
44
|
+
ContractTier.C = { c: {} };
|
|
45
|
+
ContractTier.SPECULATIVE = { speculative: {} };
|
|
46
|
+
ContractTier.ISOLATED = { isolated: {} };
|
|
47
|
+
class AssetTier {
|
|
48
|
+
}
|
|
49
|
+
exports.AssetTier = AssetTier;
|
|
50
|
+
AssetTier.COLLATERAL = { collateral: {} };
|
|
51
|
+
AssetTier.PROTECTED = { protected: {} };
|
|
52
|
+
AssetTier.CROSS = { cross: {} };
|
|
53
|
+
AssetTier.ISOLATED = { isolated: {} };
|
|
54
|
+
AssetTier.UNLISTED = { unlisted: {} };
|
|
6
55
|
class SwapDirection {
|
|
7
56
|
}
|
|
8
57
|
exports.SwapDirection = SwapDirection;
|
|
9
58
|
SwapDirection.ADD = { add: {} };
|
|
10
59
|
SwapDirection.REMOVE = { remove: {} };
|
|
11
|
-
class
|
|
60
|
+
class SpotBalanceType {
|
|
12
61
|
}
|
|
13
|
-
exports.
|
|
14
|
-
|
|
15
|
-
|
|
62
|
+
exports.SpotBalanceType = SpotBalanceType;
|
|
63
|
+
SpotBalanceType.DEPOSIT = { deposit: {} };
|
|
64
|
+
SpotBalanceType.BORROW = { borrow: {} };
|
|
16
65
|
class PositionDirection {
|
|
17
66
|
}
|
|
18
67
|
exports.PositionDirection = PositionDirection;
|
|
@@ -36,19 +85,16 @@ OrderType.LIMIT = { limit: {} };
|
|
|
36
85
|
OrderType.TRIGGER_MARKET = { triggerMarket: {} };
|
|
37
86
|
OrderType.TRIGGER_LIMIT = { triggerLimit: {} };
|
|
38
87
|
OrderType.MARKET = { market: {} };
|
|
88
|
+
class MarketType {
|
|
89
|
+
}
|
|
90
|
+
exports.MarketType = MarketType;
|
|
91
|
+
MarketType.SPOT = { spot: {} };
|
|
92
|
+
MarketType.PERP = { perp: {} };
|
|
39
93
|
class OrderStatus {
|
|
40
94
|
}
|
|
41
95
|
exports.OrderStatus = OrderStatus;
|
|
42
96
|
OrderStatus.INIT = { init: {} };
|
|
43
97
|
OrderStatus.OPEN = { open: {} };
|
|
44
|
-
class OrderDiscountTier {
|
|
45
|
-
}
|
|
46
|
-
exports.OrderDiscountTier = OrderDiscountTier;
|
|
47
|
-
OrderDiscountTier.NONE = { none: {} };
|
|
48
|
-
OrderDiscountTier.FIRST = { first: {} };
|
|
49
|
-
OrderDiscountTier.SECOND = { second: {} };
|
|
50
|
-
OrderDiscountTier.THIRD = { third: {} };
|
|
51
|
-
OrderDiscountTier.FOURTH = { fourth: {} };
|
|
52
98
|
class OrderAction {
|
|
53
99
|
}
|
|
54
100
|
exports.OrderAction = OrderAction;
|
|
@@ -61,8 +107,8 @@ class OrderActionExplanation {
|
|
|
61
107
|
}
|
|
62
108
|
exports.OrderActionExplanation = OrderActionExplanation;
|
|
63
109
|
OrderActionExplanation.NONE = { none: {} };
|
|
64
|
-
OrderActionExplanation.
|
|
65
|
-
|
|
110
|
+
OrderActionExplanation.INSUFFICIENT_FREE_COLLATERAL = {
|
|
111
|
+
insufficientFreeCollateral: {},
|
|
66
112
|
};
|
|
67
113
|
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
68
114
|
oraclePriceBreachedLimitPrice: {},
|
|
@@ -70,11 +116,63 @@ OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
|
70
116
|
OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
71
117
|
marketOrderFilledToLimitPrice: {},
|
|
72
118
|
};
|
|
119
|
+
OrderActionExplanation.ORDER_EXPIRED = {
|
|
120
|
+
orderExpired: {},
|
|
121
|
+
};
|
|
122
|
+
OrderActionExplanation.LIQUIDATION = {
|
|
123
|
+
liquidation: {},
|
|
124
|
+
};
|
|
125
|
+
OrderActionExplanation.ORDER_FILLED_WITH_AMM = {
|
|
126
|
+
orderFilledWithAMM: {},
|
|
127
|
+
};
|
|
128
|
+
OrderActionExplanation.ORDER_FILLED_WITH_AMM_JIT = {
|
|
129
|
+
orderFilledWithAMMJit: {},
|
|
130
|
+
};
|
|
131
|
+
OrderActionExplanation.ORDER_FILLED_WITH_MATCH = {
|
|
132
|
+
orderFilledWithMatch: {},
|
|
133
|
+
};
|
|
134
|
+
OrderActionExplanation.MARKET_EXPIRED = {
|
|
135
|
+
marketExpired: {},
|
|
136
|
+
};
|
|
137
|
+
OrderActionExplanation.RISK_INCREASING_ORDER = {
|
|
138
|
+
riskingIncreasingOrder: {},
|
|
139
|
+
};
|
|
140
|
+
OrderActionExplanation.ORDER_FILLED_WITH_SERUM = {
|
|
141
|
+
orderFillWithSerum: {},
|
|
142
|
+
};
|
|
73
143
|
class OrderTriggerCondition {
|
|
74
144
|
}
|
|
75
145
|
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
76
146
|
OrderTriggerCondition.ABOVE = { above: {} };
|
|
77
147
|
OrderTriggerCondition.BELOW = { below: {} };
|
|
148
|
+
OrderTriggerCondition.TRIGGERED_ABOVE = { triggeredAbove: {} }; // above condition has been triggered
|
|
149
|
+
OrderTriggerCondition.TRIGGERED_BELOW = { triggeredBelow: {} }; // below condition has been triggered
|
|
150
|
+
class SpotFulfillmentType {
|
|
151
|
+
}
|
|
152
|
+
exports.SpotFulfillmentType = SpotFulfillmentType;
|
|
153
|
+
SpotFulfillmentType.SERUM_v3 = { serumV3: {} };
|
|
154
|
+
class SpotFulfillmentStatus {
|
|
155
|
+
}
|
|
156
|
+
exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
|
|
157
|
+
SpotFulfillmentStatus.ENABLED = { enabled: {} };
|
|
158
|
+
SpotFulfillmentStatus.DISABLED = { disabled: {} };
|
|
159
|
+
class DepositExplanation {
|
|
160
|
+
}
|
|
161
|
+
exports.DepositExplanation = DepositExplanation;
|
|
162
|
+
DepositExplanation.NONE = { none: {} };
|
|
163
|
+
DepositExplanation.TRANSFER = { transfer: {} };
|
|
164
|
+
class SettlePnlExplanation {
|
|
165
|
+
}
|
|
166
|
+
exports.SettlePnlExplanation = SettlePnlExplanation;
|
|
167
|
+
SettlePnlExplanation.NONE = { none: {} };
|
|
168
|
+
SettlePnlExplanation.EXPIRED_POSITION = { expiredPosition: {} };
|
|
169
|
+
class StakeAction {
|
|
170
|
+
}
|
|
171
|
+
exports.StakeAction = StakeAction;
|
|
172
|
+
StakeAction.STAKE = { stake: {} };
|
|
173
|
+
StakeAction.UNSTAKE_REQUEST = { unstakeRequest: {} };
|
|
174
|
+
StakeAction.UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
|
|
175
|
+
StakeAction.UNSTAKE = { unstake: {} };
|
|
78
176
|
function isVariant(object, type) {
|
|
79
177
|
return object.hasOwnProperty(type);
|
|
80
178
|
}
|
|
@@ -85,12 +183,22 @@ function isOneOfVariant(object, types) {
|
|
|
85
183
|
}, false);
|
|
86
184
|
}
|
|
87
185
|
exports.isOneOfVariant = isOneOfVariant;
|
|
186
|
+
function getVariant(object) {
|
|
187
|
+
return Object.keys(object)[0];
|
|
188
|
+
}
|
|
189
|
+
exports.getVariant = getVariant;
|
|
88
190
|
var TradeSide;
|
|
89
191
|
(function (TradeSide) {
|
|
90
192
|
TradeSide[TradeSide["None"] = 0] = "None";
|
|
91
193
|
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
92
194
|
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
93
195
|
})(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
|
|
196
|
+
class LPAction {
|
|
197
|
+
}
|
|
198
|
+
exports.LPAction = LPAction;
|
|
199
|
+
LPAction.ADD_LIQUIDITY = { addLiquidity: {} };
|
|
200
|
+
LPAction.REMOVE_LIQUIDITY = { removeLiquidity: {} };
|
|
201
|
+
LPAction.SETTLE_LIQUIDITY = { settleLiquidity: {} };
|
|
94
202
|
class LiquidationType {
|
|
95
203
|
}
|
|
96
204
|
exports.LiquidationType = LiquidationType;
|
|
@@ -102,24 +210,29 @@ LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
|
|
|
102
210
|
LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
103
211
|
liquidatePerpPnlForDeposit: {},
|
|
104
212
|
};
|
|
213
|
+
LiquidationType.PERP_BANKRUPTCY = {
|
|
214
|
+
perpBankruptcy: {},
|
|
215
|
+
};
|
|
216
|
+
LiquidationType.BORROW_BANKRUPTCY = {
|
|
217
|
+
borrowBankruptcy: {},
|
|
218
|
+
};
|
|
105
219
|
exports.DefaultOrderParams = {
|
|
106
220
|
orderType: OrderType.MARKET,
|
|
221
|
+
marketType: MarketType.PERP,
|
|
107
222
|
userOrderId: 0,
|
|
108
223
|
direction: PositionDirection.LONG,
|
|
109
224
|
baseAssetAmount: _1.ZERO,
|
|
110
225
|
price: _1.ZERO,
|
|
111
|
-
marketIndex:
|
|
226
|
+
marketIndex: 0,
|
|
112
227
|
reduceOnly: false,
|
|
113
228
|
postOnly: false,
|
|
114
229
|
immediateOrCancel: false,
|
|
115
|
-
triggerPrice:
|
|
230
|
+
triggerPrice: null,
|
|
116
231
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
117
232
|
positionLimit: _1.ZERO,
|
|
118
|
-
oraclePriceOffset:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
referrer: false,
|
|
124
|
-
},
|
|
233
|
+
oraclePriceOffset: null,
|
|
234
|
+
auctionDuration: null,
|
|
235
|
+
maxTs: null,
|
|
236
|
+
auctionStartPrice: null,
|
|
237
|
+
auctionEndPrice: null,
|
|
125
238
|
};
|
package/lib/user.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bn.js" />
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
|
+
import { DriftClient } from './driftClient';
|
|
7
|
+
import { MarginCategory, Order, UserAccount, PerpPosition, SpotPosition } from './types';
|
|
8
|
+
import { UserAccountSubscriber, UserAccountEvents, DataAndSlot } from './accounts/types';
|
|
9
|
+
import { PositionDirection, BN, SpotMarketAccount } from '.';
|
|
10
|
+
import { OraclePriceData } from './oracles/types';
|
|
11
|
+
import { UserConfig } from './userConfig';
|
|
12
|
+
export declare class User {
|
|
13
|
+
driftClient: DriftClient;
|
|
14
|
+
userAccountPublicKey: PublicKey;
|
|
15
|
+
accountSubscriber: UserAccountSubscriber;
|
|
16
|
+
_isSubscribed: boolean;
|
|
17
|
+
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
18
|
+
get isSubscribed(): boolean;
|
|
19
|
+
set isSubscribed(val: boolean);
|
|
20
|
+
constructor(config: UserConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to User state accounts
|
|
23
|
+
* @returns SusbcriptionSuccess result
|
|
24
|
+
*/
|
|
25
|
+
subscribe(): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Forces the accountSubscriber to fetch account updates from rpc
|
|
28
|
+
*/
|
|
29
|
+
fetchAccounts(): Promise<void>;
|
|
30
|
+
unsubscribe(): Promise<void>;
|
|
31
|
+
getUserAccount(): UserAccount;
|
|
32
|
+
getUserAccountAndSlot(): DataAndSlot<UserAccount> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the user's current position for a given perp market. If the user has no position returns undefined
|
|
35
|
+
* @param marketIndex
|
|
36
|
+
* @returns userPerpPosition
|
|
37
|
+
*/
|
|
38
|
+
getPerpPosition(marketIndex: number): PerpPosition | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the user's current position for a given spot market. If the user has no position returns undefined
|
|
41
|
+
* @param marketIndex
|
|
42
|
+
* @returns userSpotPosition
|
|
43
|
+
*/
|
|
44
|
+
getSpotPosition(marketIndex: number): SpotPosition | undefined;
|
|
45
|
+
getEmptyPosition(marketIndex: number): PerpPosition;
|
|
46
|
+
getClonedPosition(position: PerpPosition): PerpPosition;
|
|
47
|
+
/**
|
|
48
|
+
* @param orderId
|
|
49
|
+
* @returns Order
|
|
50
|
+
*/
|
|
51
|
+
getOrder(orderId: number): Order | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* @param userOrderId
|
|
54
|
+
* @returns Order
|
|
55
|
+
*/
|
|
56
|
+
getOrderByUserOrderId(userOrderId: number): Order | undefined;
|
|
57
|
+
getUserAccountPublicKey(): PublicKey;
|
|
58
|
+
exists(): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* calculates the total open bids/asks in a perp market (including lps)
|
|
61
|
+
* @returns : open bids
|
|
62
|
+
* @returns : open asks
|
|
63
|
+
*/
|
|
64
|
+
getPerpBidAsks(marketIndex: number): [BN, BN];
|
|
65
|
+
/**
|
|
66
|
+
* calculates the open bids and asks for an lp
|
|
67
|
+
* @returns : lp open bids
|
|
68
|
+
* @returns : lp open asks
|
|
69
|
+
*/
|
|
70
|
+
getLPBidAsks(marketIndex: number): [BN, BN];
|
|
71
|
+
/**
|
|
72
|
+
* calculates the market position if the lp position was settled
|
|
73
|
+
* @returns : the settled userPosition
|
|
74
|
+
* @returns : the dust base asset amount (ie, < stepsize)
|
|
75
|
+
* @returns : pnl from settle
|
|
76
|
+
*/
|
|
77
|
+
getSettledLPPosition(marketIndex: number): [PerpPosition, BN, BN];
|
|
78
|
+
/**
|
|
79
|
+
* calculates Buying Power = FC * MAX_LEVERAGE
|
|
80
|
+
* @returns : Precision QUOTE_PRECISION
|
|
81
|
+
*/
|
|
82
|
+
getBuyingPower(marketIndex: number): BN;
|
|
83
|
+
/**
|
|
84
|
+
* calculates Free Collateral = Total collateral - initial margin requirement
|
|
85
|
+
* @returns : Precision QUOTE_PRECISION
|
|
86
|
+
*/
|
|
87
|
+
getFreeCollateral(): BN;
|
|
88
|
+
/**
|
|
89
|
+
* @returns The margin requirement of a certain type (Initial or Maintenance) in USDC. : QUOTE_PRECISION
|
|
90
|
+
*/
|
|
91
|
+
getMarginRequirement(marginCategory: MarginCategory, liquidationBuffer?: BN): BN;
|
|
92
|
+
/**
|
|
93
|
+
* @returns The initial margin requirement in USDC. : QUOTE_PRECISION
|
|
94
|
+
*/
|
|
95
|
+
getInitialMarginRequirement(): BN;
|
|
96
|
+
/**
|
|
97
|
+
* @returns The maintenance margin requirement in USDC. : QUOTE_PRECISION
|
|
98
|
+
*/
|
|
99
|
+
getMaintenanceMarginRequirement(liquidationBuffer?: BN): BN;
|
|
100
|
+
/**
|
|
101
|
+
* calculates unrealized position price pnl
|
|
102
|
+
* @returns : Precision QUOTE_PRECISION
|
|
103
|
+
*/
|
|
104
|
+
getUnrealizedPNL(withFunding?: boolean, marketIndex?: number, withWeightMarginCategory?: MarginCategory): BN;
|
|
105
|
+
/**
|
|
106
|
+
* calculates unrealized funding payment pnl
|
|
107
|
+
* @returns : Precision QUOTE_PRECISION
|
|
108
|
+
*/
|
|
109
|
+
getUnrealizedFundingPNL(marketIndex?: number): BN;
|
|
110
|
+
getSpotMarketLiabilityValue(marketIndex?: number, marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
111
|
+
getSpotLiabilityValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
|
|
112
|
+
getSpotMarketAssetValue(marketIndex?: number, marginCategory?: MarginCategory, includeOpenOrders?: boolean): BN;
|
|
113
|
+
getSpotAssetValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory): BN;
|
|
114
|
+
getNetSpotMarketValue(withWeightMarginCategory?: MarginCategory): BN;
|
|
115
|
+
/**
|
|
116
|
+
* calculates TotalCollateral: collateral + unrealized pnl
|
|
117
|
+
* @returns : Precision QUOTE_PRECISION
|
|
118
|
+
*/
|
|
119
|
+
getTotalCollateral(marginCategory?: MarginCategory): BN;
|
|
120
|
+
/**
|
|
121
|
+
* calculates sum of position value across all positions in margin system
|
|
122
|
+
* @returns : Precision QUOTE_PRECISION
|
|
123
|
+
*/
|
|
124
|
+
getTotalPerpPositionValue(marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
125
|
+
/**
|
|
126
|
+
* calculates position value in margin system
|
|
127
|
+
* @returns : Precision QUOTE_PRECISION
|
|
128
|
+
*/
|
|
129
|
+
getPerpPositionValue(marketIndex: number, oraclePriceData: OraclePriceData): BN;
|
|
130
|
+
getPositionSide(currentPosition: Pick<PerpPosition, 'baseAssetAmount'>): PositionDirection | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* calculates average exit price (optionally for closing up to 100% of position)
|
|
133
|
+
* @returns : Precision PRICE_PRECISION
|
|
134
|
+
*/
|
|
135
|
+
getPositionEstimatedExitPriceAndPnl(position: PerpPosition, amountToClose?: BN, useAMMClose?: boolean): [BN, BN];
|
|
136
|
+
/**
|
|
137
|
+
* calculates current user leverage across all positions
|
|
138
|
+
* @returns : Precision TEN_THOUSAND
|
|
139
|
+
*/
|
|
140
|
+
getLeverage(): BN;
|
|
141
|
+
getTotalLiabilityValue(): BN;
|
|
142
|
+
getTotalAssetValue(): BN;
|
|
143
|
+
/**
|
|
144
|
+
* calculates max allowable leverage exceeding hitting requirement category
|
|
145
|
+
* @params category {Initial, Maintenance}
|
|
146
|
+
* @returns : Precision TEN_THOUSAND
|
|
147
|
+
*/
|
|
148
|
+
getMaxLeverage(marketIndex: number, category?: MarginCategory): BN;
|
|
149
|
+
/**
|
|
150
|
+
* calculates margin ratio: total collateral / |total position value|
|
|
151
|
+
* @returns : Precision TEN_THOUSAND
|
|
152
|
+
*/
|
|
153
|
+
getMarginRatio(): BN;
|
|
154
|
+
canBeLiquidated(): boolean;
|
|
155
|
+
isBeingLiquidated(): boolean;
|
|
156
|
+
isBankrupt(): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Checks if any user position cumulative funding differs from respective market cumulative funding
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
needsToSettleFundingPayment(): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Calculate the liquidation price of a position, with optional parameter to calculate the liquidation price after a trade
|
|
164
|
+
* @param PerpPosition
|
|
165
|
+
* @param positionBaseSizeChange // change in position size to calculate liquidation price for : Precision 10^13
|
|
166
|
+
* @param partial
|
|
167
|
+
* @returns Precision : PRICE_PRECISION
|
|
168
|
+
*/
|
|
169
|
+
liquidationPrice(perpPosition: Pick<PerpPosition, 'marketIndex'>, positionBaseSizeChange?: BN): BN;
|
|
170
|
+
/**
|
|
171
|
+
* Calculates the estimated liquidation price for a position after closing a quote amount of the position.
|
|
172
|
+
* @param positionMarketIndex
|
|
173
|
+
* @param closeQuoteAmount
|
|
174
|
+
* @returns : Precision PRICE_PRECISION
|
|
175
|
+
*/
|
|
176
|
+
liquidationPriceAfterClose(positionMarketIndex: number, closeQuoteAmount: BN): BN;
|
|
177
|
+
/**
|
|
178
|
+
* Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
|
|
179
|
+
*
|
|
180
|
+
* To Calculate Max Quote Available:
|
|
181
|
+
*
|
|
182
|
+
* Case 1: SameSide
|
|
183
|
+
* => Remaining quote to get to maxLeverage
|
|
184
|
+
*
|
|
185
|
+
* Case 2: NOT SameSide && currentLeverage <= maxLeverage
|
|
186
|
+
* => Current opposite position x2 + remaining to get to maxLeverage
|
|
187
|
+
*
|
|
188
|
+
* Case 3: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition > maxLeverage
|
|
189
|
+
* => strictly reduce current position size
|
|
190
|
+
*
|
|
191
|
+
* Case 4: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition < maxLeverage
|
|
192
|
+
* => current position + remaining to get to maxLeverage
|
|
193
|
+
*
|
|
194
|
+
* @param targetMarketIndex
|
|
195
|
+
* @param tradeSide
|
|
196
|
+
* @returns tradeSizeAllowed : Precision QUOTE_PRECISION
|
|
197
|
+
*/
|
|
198
|
+
getMaxTradeSizeUSDC(targetMarketIndex: number, tradeSide: PositionDirection): BN;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the leverage ratio for the account after adding (or subtracting) the given quote size to the given position
|
|
201
|
+
* @param targetMarketIndex
|
|
202
|
+
* @param positionMarketIndex
|
|
203
|
+
* @param tradeQuoteAmount
|
|
204
|
+
* @returns leverageRatio : Precision TEN_THOUSAND
|
|
205
|
+
*/
|
|
206
|
+
accountLeverageRatioAfterTrade(targetMarketIndex: number, tradeQuoteAmount: BN, tradeSide: PositionDirection, includeOpenOrders?: boolean): BN;
|
|
207
|
+
/**
|
|
208
|
+
* Calculates how much fee will be taken for a given sized trade
|
|
209
|
+
* @param quoteAmount
|
|
210
|
+
* @returns feeForQuote : Precision QUOTE_PRECISION
|
|
211
|
+
*/
|
|
212
|
+
calculateFeeForQuoteAmount(quoteAmount: BN): BN;
|
|
213
|
+
/**
|
|
214
|
+
* Calculates a user's max withdrawal amounts for a spot market. If reduceOnly is true,
|
|
215
|
+
* it will return the max withdrawal amount without opening a liability for the user
|
|
216
|
+
* @param marketIndex
|
|
217
|
+
* @returns withdrawalLimit : Precision is the token precision for the chosen SpotMarket
|
|
218
|
+
*/
|
|
219
|
+
getWithdrawalLimit(marketIndex: number, reduceOnly?: boolean): BN;
|
|
220
|
+
/**
|
|
221
|
+
* Get the total position value, excluding any position coming from the given target market
|
|
222
|
+
* @param marketToIgnore
|
|
223
|
+
* @returns positionValue : Precision QUOTE_PRECISION
|
|
224
|
+
*/
|
|
225
|
+
private getTotalPerpPositionValueExcludingMarket;
|
|
226
|
+
private getOracleDataForPerpMarket;
|
|
227
|
+
private getOracleDataForSpotMarket;
|
|
228
|
+
}
|