@drift-labs/sdk 0.2.0-temp.2 → 2.0.1
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/src/types.ts
CHANGED
|
@@ -2,12 +2,62 @@ import { PublicKey, Transaction } from '@solana/web3.js';
|
|
|
2
2
|
import { BN, ZERO } from '.';
|
|
3
3
|
|
|
4
4
|
// # Utility Types / Enums / Constants
|
|
5
|
+
|
|
6
|
+
export class ExchangeStatus {
|
|
7
|
+
static readonly ACTIVE = { active: {} };
|
|
8
|
+
static readonly FUNDING_PAUSED = { fundingPaused: {} };
|
|
9
|
+
static readonly AMM_PAUSED = { ammPaused: {} };
|
|
10
|
+
static readonly FILL_PAUSED = { fillPaused: {} };
|
|
11
|
+
static readonly LIQ_PAUSED = { liqPaused: {} };
|
|
12
|
+
static readonly WITHDRAW_PAUSED = { withdrawPaused: {} };
|
|
13
|
+
static readonly PAUSED = { paused: {} };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class MarketStatus {
|
|
17
|
+
static readonly INITIALIZED = { initialized: {} };
|
|
18
|
+
static readonly ACTIVE = { active: {} };
|
|
19
|
+
static readonly FUNDING_PAUSED = { fundingPaused: {} };
|
|
20
|
+
static readonly AMM_PAUSED = { ammPaused: {} };
|
|
21
|
+
static readonly FILL_PAUSED = { fillPaused: {} };
|
|
22
|
+
static readonly WITHDRAW_PAUSED = { withdrawPaused: {} };
|
|
23
|
+
static readonly REDUCE_ONLY = { reduceOnly: {} };
|
|
24
|
+
static readonly SETTLEMENT = { settlement: {} };
|
|
25
|
+
static readonly DELISTED = { delisted: {} };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class UserStatus {
|
|
29
|
+
static readonly ACTIVE = { active: {} };
|
|
30
|
+
static readonly BEING_LIQUIDATED = { beingLiquidated: {} };
|
|
31
|
+
static readonly BANKRUPT = { bankrupt: {} };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ContractType {
|
|
35
|
+
static readonly PERPETUAL = { perpetual: {} };
|
|
36
|
+
static readonly FUTURE = { future: {} };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class ContractTier {
|
|
40
|
+
static readonly A = { a: {} };
|
|
41
|
+
static readonly B = { b: {} };
|
|
42
|
+
static readonly C = { c: {} };
|
|
43
|
+
static readonly SPECULATIVE = { speculative: {} };
|
|
44
|
+
static readonly ISOLATED = { isolated: {} };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class AssetTier {
|
|
48
|
+
static readonly COLLATERAL = { collateral: {} };
|
|
49
|
+
static readonly PROTECTED = { protected: {} };
|
|
50
|
+
static readonly CROSS = { cross: {} };
|
|
51
|
+
static readonly ISOLATED = { isolated: {} };
|
|
52
|
+
static readonly UNLISTED = { unlisted: {} };
|
|
53
|
+
}
|
|
54
|
+
|
|
5
55
|
export class SwapDirection {
|
|
6
56
|
static readonly ADD = { add: {} };
|
|
7
57
|
static readonly REMOVE = { remove: {} };
|
|
8
58
|
}
|
|
9
59
|
|
|
10
|
-
export class
|
|
60
|
+
export class SpotBalanceType {
|
|
11
61
|
static readonly DEPOSIT = { deposit: {} };
|
|
12
62
|
static readonly BORROW = { borrow: {} };
|
|
13
63
|
}
|
|
@@ -35,19 +85,17 @@ export class OrderType {
|
|
|
35
85
|
static readonly MARKET = { market: {} };
|
|
36
86
|
}
|
|
37
87
|
|
|
88
|
+
export declare type MarketTypeStr = 'perp' | 'spot';
|
|
89
|
+
export class MarketType {
|
|
90
|
+
static readonly SPOT = { spot: {} };
|
|
91
|
+
static readonly PERP = { perp: {} };
|
|
92
|
+
}
|
|
93
|
+
|
|
38
94
|
export class OrderStatus {
|
|
39
95
|
static readonly INIT = { init: {} };
|
|
40
96
|
static readonly OPEN = { open: {} };
|
|
41
97
|
}
|
|
42
98
|
|
|
43
|
-
export class OrderDiscountTier {
|
|
44
|
-
static readonly NONE = { none: {} };
|
|
45
|
-
static readonly FIRST = { first: {} };
|
|
46
|
-
static readonly SECOND = { second: {} };
|
|
47
|
-
static readonly THIRD = { third: {} };
|
|
48
|
-
static readonly FOURTH = { fourth: {} };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
99
|
export class OrderAction {
|
|
52
100
|
static readonly PLACE = { place: {} };
|
|
53
101
|
static readonly CANCEL = { cancel: {} };
|
|
@@ -58,8 +106,8 @@ export class OrderAction {
|
|
|
58
106
|
|
|
59
107
|
export class OrderActionExplanation {
|
|
60
108
|
static readonly NONE = { none: {} };
|
|
61
|
-
static readonly
|
|
62
|
-
|
|
109
|
+
static readonly INSUFFICIENT_FREE_COLLATERAL = {
|
|
110
|
+
insufficientFreeCollateral: {},
|
|
63
111
|
};
|
|
64
112
|
static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
65
113
|
oraclePriceBreachedLimitPrice: {},
|
|
@@ -67,11 +115,63 @@ export class OrderActionExplanation {
|
|
|
67
115
|
static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
68
116
|
marketOrderFilledToLimitPrice: {},
|
|
69
117
|
};
|
|
118
|
+
static readonly ORDER_EXPIRED = {
|
|
119
|
+
orderExpired: {},
|
|
120
|
+
};
|
|
121
|
+
static readonly LIQUIDATION = {
|
|
122
|
+
liquidation: {},
|
|
123
|
+
};
|
|
124
|
+
static readonly ORDER_FILLED_WITH_AMM = {
|
|
125
|
+
orderFilledWithAMM: {},
|
|
126
|
+
};
|
|
127
|
+
static readonly ORDER_FILLED_WITH_AMM_JIT = {
|
|
128
|
+
orderFilledWithAMMJit: {},
|
|
129
|
+
};
|
|
130
|
+
static readonly ORDER_FILLED_WITH_MATCH = {
|
|
131
|
+
orderFilledWithMatch: {},
|
|
132
|
+
};
|
|
133
|
+
static readonly MARKET_EXPIRED = {
|
|
134
|
+
marketExpired: {},
|
|
135
|
+
};
|
|
136
|
+
static readonly RISK_INCREASING_ORDER = {
|
|
137
|
+
riskingIncreasingOrder: {},
|
|
138
|
+
};
|
|
139
|
+
static readonly ORDER_FILLED_WITH_SERUM = {
|
|
140
|
+
orderFillWithSerum: {},
|
|
141
|
+
};
|
|
70
142
|
}
|
|
71
143
|
|
|
72
144
|
export class OrderTriggerCondition {
|
|
73
145
|
static readonly ABOVE = { above: {} };
|
|
74
146
|
static readonly BELOW = { below: {} };
|
|
147
|
+
static readonly TRIGGERED_ABOVE = { triggeredAbove: {} }; // above condition has been triggered
|
|
148
|
+
static readonly TRIGGERED_BELOW = { triggeredBelow: {} }; // below condition has been triggered
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class SpotFulfillmentType {
|
|
152
|
+
static readonly SERUM_v3 = { serumV3: {} };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export class SpotFulfillmentStatus {
|
|
156
|
+
static readonly ENABLED = { enabled: {} };
|
|
157
|
+
static readonly DISABLED = { disabled: {} };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class DepositExplanation {
|
|
161
|
+
static readonly NONE = { none: {} };
|
|
162
|
+
static readonly TRANSFER = { transfer: {} };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export class SettlePnlExplanation {
|
|
166
|
+
static readonly NONE = { none: {} };
|
|
167
|
+
static readonly EXPIRED_POSITION = { expiredPosition: {} };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class StakeAction {
|
|
171
|
+
static readonly STAKE = { stake: {} };
|
|
172
|
+
static readonly UNSTAKE_REQUEST = { unstakeRequest: {} };
|
|
173
|
+
static readonly UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
|
|
174
|
+
static readonly UNSTAKE = { unstake: {} };
|
|
75
175
|
}
|
|
76
176
|
|
|
77
177
|
export function isVariant(object: unknown, type: string) {
|
|
@@ -84,6 +184,10 @@ export function isOneOfVariant(object: unknown, types: string[]) {
|
|
|
84
184
|
}, false);
|
|
85
185
|
}
|
|
86
186
|
|
|
187
|
+
export function getVariant(object: unknown): string {
|
|
188
|
+
return Object.keys(object)[0];
|
|
189
|
+
}
|
|
190
|
+
|
|
87
191
|
export enum TradeSide {
|
|
88
192
|
None = 0,
|
|
89
193
|
Buy = 1,
|
|
@@ -100,6 +204,15 @@ export type CandleResolution =
|
|
|
100
204
|
| 'W'
|
|
101
205
|
| 'M';
|
|
102
206
|
|
|
207
|
+
export type NewUserRecord = {
|
|
208
|
+
ts: BN;
|
|
209
|
+
userAuthority: PublicKey;
|
|
210
|
+
user: PublicKey;
|
|
211
|
+
subAccount: number;
|
|
212
|
+
name: number[];
|
|
213
|
+
referrer: PublicKey;
|
|
214
|
+
};
|
|
215
|
+
|
|
103
216
|
export type DepositRecord = {
|
|
104
217
|
ts: BN;
|
|
105
218
|
userAuthority: PublicKey;
|
|
@@ -108,17 +221,36 @@ export type DepositRecord = {
|
|
|
108
221
|
deposit?: any;
|
|
109
222
|
withdraw?: any;
|
|
110
223
|
};
|
|
111
|
-
|
|
224
|
+
marketIndex: number;
|
|
112
225
|
amount: BN;
|
|
113
226
|
oraclePrice: BN;
|
|
114
|
-
|
|
115
|
-
|
|
227
|
+
marketDepositBalance: BN;
|
|
228
|
+
marketWithdrawBalance: BN;
|
|
229
|
+
marketCumulativeDepositInterest: BN;
|
|
230
|
+
marketCumulativeBorrowInterest: BN;
|
|
231
|
+
totalDepositsAfter: BN;
|
|
232
|
+
totalWithdrawsAfter: BN;
|
|
233
|
+
depositRecordId: BN;
|
|
234
|
+
explanation: DepositExplanation;
|
|
235
|
+
transferUser?: PublicKey;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export type SpotInterestRecord = {
|
|
239
|
+
ts: BN;
|
|
240
|
+
marketIndex: number;
|
|
241
|
+
depositBalance: BN;
|
|
242
|
+
cumulativeDepositInterest: BN;
|
|
243
|
+
borrowBalance: BN;
|
|
244
|
+
cumulativeBorrowInterest: BN;
|
|
245
|
+
optimalUtilization: number;
|
|
246
|
+
optimalBorrowRate: number;
|
|
247
|
+
maxBorrowRate: number;
|
|
116
248
|
};
|
|
117
249
|
|
|
118
250
|
export type CurveRecord = {
|
|
119
251
|
ts: BN;
|
|
120
252
|
recordId: BN;
|
|
121
|
-
marketIndex:
|
|
253
|
+
marketIndex: number;
|
|
122
254
|
pegMultiplierBefore: BN;
|
|
123
255
|
baseAssetReserveBefore: BN;
|
|
124
256
|
quoteAssetReserveBefore: BN;
|
|
@@ -129,32 +261,84 @@ export type CurveRecord = {
|
|
|
129
261
|
sqrtKAfter: BN;
|
|
130
262
|
baseAssetAmountLong: BN;
|
|
131
263
|
baseAssetAmountShort: BN;
|
|
132
|
-
|
|
133
|
-
|
|
264
|
+
baseAssetAmountWithAmm: BN;
|
|
265
|
+
totalFee: BN;
|
|
266
|
+
totalFeeMinusDistributions: BN;
|
|
267
|
+
adjustmentCost: BN;
|
|
268
|
+
numberOfUsers: BN;
|
|
134
269
|
oraclePrice: BN;
|
|
135
|
-
|
|
270
|
+
fillRecord: BN;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export declare type InsuranceFundRecord = {
|
|
274
|
+
ts: BN;
|
|
275
|
+
spotMarketIndex: number;
|
|
276
|
+
perpMarketIndex: number;
|
|
277
|
+
userIfFactor: number;
|
|
278
|
+
totalIfFactor: number;
|
|
279
|
+
vaultAmountBefore: BN;
|
|
280
|
+
insuranceVaultAmountBefore: BN;
|
|
281
|
+
totalIfSharesBefore: BN;
|
|
282
|
+
totalIfSharesAfter: BN;
|
|
283
|
+
amount: BN;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export declare type InsuranceFundStakeRecord = {
|
|
287
|
+
ts: BN;
|
|
288
|
+
userAuthority: PublicKey;
|
|
289
|
+
action: StakeAction;
|
|
290
|
+
amount: BN;
|
|
291
|
+
marketIndex: number;
|
|
292
|
+
insuranceVaultAmountBefore: BN;
|
|
293
|
+
ifSharesBefore: BN;
|
|
294
|
+
userIfSharesBefore: BN;
|
|
295
|
+
totalIfSharesBefore: BN;
|
|
296
|
+
ifSharesAfter: BN;
|
|
297
|
+
userIfSharesAfter: BN;
|
|
298
|
+
totalIfSharesAfter: BN;
|
|
136
299
|
};
|
|
137
300
|
|
|
301
|
+
export type LPRecord = {
|
|
302
|
+
ts: BN;
|
|
303
|
+
user: PublicKey;
|
|
304
|
+
action: LPAction;
|
|
305
|
+
nShares: BN;
|
|
306
|
+
marketIndex: number;
|
|
307
|
+
deltaBaseAssetAmount: BN;
|
|
308
|
+
deltaQuoteAssetAmount: BN;
|
|
309
|
+
pnl: BN;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export class LPAction {
|
|
313
|
+
static readonly ADD_LIQUIDITY = { addLiquidity: {} };
|
|
314
|
+
static readonly REMOVE_LIQUIDITY = { removeLiquidity: {} };
|
|
315
|
+
static readonly SETTLE_LIQUIDITY = { settleLiquidity: {} };
|
|
316
|
+
}
|
|
317
|
+
|
|
138
318
|
export type FundingRateRecord = {
|
|
139
319
|
ts: BN;
|
|
140
320
|
recordId: BN;
|
|
141
|
-
marketIndex:
|
|
321
|
+
marketIndex: number;
|
|
142
322
|
fundingRate: BN;
|
|
323
|
+
fundingRateLong: BN;
|
|
324
|
+
fundingRateShort: BN;
|
|
143
325
|
cumulativeFundingRateLong: BN;
|
|
144
326
|
cumulativeFundingRateShort: BN;
|
|
145
327
|
oraclePriceTwap: BN;
|
|
146
328
|
markPriceTwap: BN;
|
|
329
|
+
periodRevenue: BN;
|
|
330
|
+
baseAssetAmountWithAmm: BN;
|
|
331
|
+
baseAssetAmountWithUnsettledLp: BN;
|
|
147
332
|
};
|
|
148
333
|
|
|
149
334
|
export type FundingPaymentRecord = {
|
|
150
335
|
ts: BN;
|
|
151
336
|
userAuthority: PublicKey;
|
|
152
337
|
user: PublicKey;
|
|
153
|
-
marketIndex:
|
|
338
|
+
marketIndex: number;
|
|
154
339
|
fundingPayment: BN;
|
|
155
340
|
baseAssetAmount: BN;
|
|
156
341
|
userLastCumulativeFunding: BN;
|
|
157
|
-
userLastFundingRateTs: BN;
|
|
158
342
|
ammCumulativeFundingLong: BN;
|
|
159
343
|
ammCumulativeFundingShort: BN;
|
|
160
344
|
};
|
|
@@ -166,10 +350,16 @@ export type LiquidationRecord = {
|
|
|
166
350
|
liquidationType: LiquidationType;
|
|
167
351
|
marginRequirement: BN;
|
|
168
352
|
totalCollateral: BN;
|
|
353
|
+
marginFreed: BN;
|
|
354
|
+
liquidationId: number;
|
|
355
|
+
bankrupt: boolean;
|
|
356
|
+
canceledOrderIds: BN[];
|
|
169
357
|
liquidatePerp: LiquidatePerpRecord;
|
|
170
|
-
|
|
358
|
+
liquidateSpot: LiquidateSpotRecord;
|
|
171
359
|
liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
|
|
172
360
|
liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
|
|
361
|
+
perpBankruptcy: PerpBankruptcyRecord;
|
|
362
|
+
spotBankruptcy: SpotBankruptcyRecord;
|
|
173
363
|
};
|
|
174
364
|
|
|
175
365
|
export class LiquidationType {
|
|
@@ -181,144 +371,263 @@ export class LiquidationType {
|
|
|
181
371
|
static readonly LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
182
372
|
liquidatePerpPnlForDeposit: {},
|
|
183
373
|
};
|
|
374
|
+
static readonly PERP_BANKRUPTCY = {
|
|
375
|
+
perpBankruptcy: {},
|
|
376
|
+
};
|
|
377
|
+
static readonly BORROW_BANKRUPTCY = {
|
|
378
|
+
borrowBankruptcy: {},
|
|
379
|
+
};
|
|
184
380
|
}
|
|
185
381
|
|
|
186
382
|
export type LiquidatePerpRecord = {
|
|
187
|
-
marketIndex:
|
|
188
|
-
orderIds: BN[];
|
|
383
|
+
marketIndex: number;
|
|
189
384
|
oraclePrice: BN;
|
|
190
385
|
baseAssetAmount: BN;
|
|
191
386
|
quoteAssetAmount: BN;
|
|
192
|
-
|
|
193
|
-
liquidatorPnl: BN;
|
|
194
|
-
canceledOrdersFee: BN;
|
|
387
|
+
lpShares: BN;
|
|
195
388
|
userOrderId: BN;
|
|
196
389
|
liquidatorOrderId: BN;
|
|
197
390
|
fillRecordId: BN;
|
|
391
|
+
liquidatorFee: BN;
|
|
392
|
+
ifFee: BN;
|
|
198
393
|
};
|
|
199
394
|
|
|
200
|
-
export type
|
|
201
|
-
|
|
395
|
+
export type LiquidateSpotRecord = {
|
|
396
|
+
assetMarketIndex: number;
|
|
202
397
|
assetPrice: BN;
|
|
203
398
|
assetTransfer: BN;
|
|
204
|
-
|
|
399
|
+
liabilityMarketIndex: number;
|
|
205
400
|
liabilityPrice: BN;
|
|
206
401
|
liabilityTransfer: BN;
|
|
402
|
+
ifFee: BN;
|
|
207
403
|
};
|
|
208
404
|
|
|
209
405
|
export type LiquidateBorrowForPerpPnlRecord = {
|
|
210
|
-
|
|
406
|
+
perpMarketIndex: number;
|
|
211
407
|
marketOraclePrice: BN;
|
|
212
408
|
pnlTransfer: BN;
|
|
213
|
-
|
|
409
|
+
liabilityMarketIndex: number;
|
|
214
410
|
liabilityPrice: BN;
|
|
215
411
|
liabilityTransfer: BN;
|
|
216
412
|
};
|
|
217
413
|
|
|
218
414
|
export type LiquidatePerpPnlForDepositRecord = {
|
|
219
|
-
|
|
415
|
+
perpMarketIndex: number;
|
|
220
416
|
marketOraclePrice: BN;
|
|
221
417
|
pnlTransfer: BN;
|
|
222
|
-
|
|
418
|
+
assetMarketIndex: number;
|
|
223
419
|
assetPrice: BN;
|
|
224
420
|
assetTransfer: BN;
|
|
225
421
|
};
|
|
226
422
|
|
|
423
|
+
export type PerpBankruptcyRecord = {
|
|
424
|
+
marketIndex: number;
|
|
425
|
+
pnl: BN;
|
|
426
|
+
ifPayment: BN;
|
|
427
|
+
clawbackUser: PublicKey | null;
|
|
428
|
+
clawbackUserPayment: BN | null;
|
|
429
|
+
cumulativeFundingRateDelta: BN;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
export type SpotBankruptcyRecord = {
|
|
433
|
+
marketIndex: number;
|
|
434
|
+
borrowAmount: BN;
|
|
435
|
+
cumulativeDepositInterestDelta: BN;
|
|
436
|
+
ifPayment: BN;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
export type SettlePnlRecord = {
|
|
440
|
+
ts: BN;
|
|
441
|
+
user: PublicKey;
|
|
442
|
+
marketIndex: number;
|
|
443
|
+
pnl: BN;
|
|
444
|
+
baseAssetAmount: BN;
|
|
445
|
+
quoteAssetAmountAfter: BN;
|
|
446
|
+
quoteEntryAmount: BN;
|
|
447
|
+
settlePrice: BN;
|
|
448
|
+
explanation: SettlePnlExplanation;
|
|
449
|
+
};
|
|
450
|
+
|
|
227
451
|
export type OrderRecord = {
|
|
228
452
|
ts: BN;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
453
|
+
user: PublicKey;
|
|
454
|
+
order: Order;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
export type OrderActionRecord = {
|
|
458
|
+
ts: BN;
|
|
235
459
|
action: OrderAction;
|
|
236
460
|
actionExplanation: OrderActionExplanation;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
461
|
+
marketIndex: number;
|
|
462
|
+
marketType: MarketType;
|
|
463
|
+
filler: PublicKey | null;
|
|
464
|
+
fillerReward: BN | null;
|
|
465
|
+
fillRecordId: BN | null;
|
|
466
|
+
baseAssetAmountFilled: BN | null;
|
|
467
|
+
quoteAssetAmountFilled: BN | null;
|
|
468
|
+
takerFee: BN | null;
|
|
469
|
+
makerFee: BN | null;
|
|
470
|
+
referrerReward: number | null;
|
|
471
|
+
quoteAssetAmountSurplus: BN | null;
|
|
472
|
+
spotFulfillmentMethodFee: BN | null;
|
|
473
|
+
taker: PublicKey | null;
|
|
474
|
+
takerOrderId: number | null;
|
|
475
|
+
takerOrderDirection: PositionDirection | null;
|
|
476
|
+
takerOrderBaseAssetAmount: BN | null;
|
|
477
|
+
takerOrderCumulativeBaseAssetAmountFilled: BN | null;
|
|
478
|
+
takerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
479
|
+
maker: PublicKey | null;
|
|
480
|
+
makerOrderId: number | null;
|
|
481
|
+
makerOrderDirection: PositionDirection | null;
|
|
482
|
+
makerOrderBaseAssetAmount: BN | null;
|
|
483
|
+
makerOrderCumulativeBaseAssetAmountFilled: BN | null;
|
|
484
|
+
makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
|
|
246
485
|
oraclePrice: BN;
|
|
247
486
|
};
|
|
248
487
|
|
|
249
488
|
export type StateAccount = {
|
|
250
489
|
admin: PublicKey;
|
|
251
|
-
|
|
252
|
-
exchangePaused: boolean;
|
|
253
|
-
adminControlsPrices: boolean;
|
|
254
|
-
insuranceVault: PublicKey;
|
|
255
|
-
insuranceVaultAuthority: PublicKey;
|
|
256
|
-
insuranceVaultNonce: number;
|
|
257
|
-
marginRatioInitial: BN;
|
|
258
|
-
marginRatioMaintenance: BN;
|
|
259
|
-
marginRatioPartial: BN;
|
|
260
|
-
partialLiquidationClosePercentageNumerator: BN;
|
|
261
|
-
partialLiquidationClosePercentageDenominator: BN;
|
|
262
|
-
partialLiquidationPenaltyPercentageNumerator: BN;
|
|
263
|
-
partialLiquidationPenaltyPercentageDenominator: BN;
|
|
264
|
-
fullLiquidationPenaltyPercentageNumerator: BN;
|
|
265
|
-
fullLiquidationPenaltyPercentageDenominator: BN;
|
|
266
|
-
partialLiquidationLiquidatorShareDenominator: BN;
|
|
267
|
-
fullLiquidationLiquidatorShareDenominator: BN;
|
|
268
|
-
feeStructure: FeeStructure;
|
|
269
|
-
totalFee: BN;
|
|
270
|
-
totalFeeWithdrawn: BN;
|
|
490
|
+
exchangeStatus: ExchangeStatus;
|
|
271
491
|
whitelistMint: PublicKey;
|
|
272
492
|
discountMint: PublicKey;
|
|
273
493
|
oracleGuardRails: OracleGuardRails;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
494
|
+
numberOfAuthorities: BN;
|
|
495
|
+
numberOfSubAccounts: BN;
|
|
496
|
+
numberOfMarkets: number;
|
|
497
|
+
numberOfSpotMarkets: number;
|
|
498
|
+
minPerpAuctionDuration: number;
|
|
499
|
+
defaultMarketOrderTimeInForce: number;
|
|
500
|
+
defaultSpotAuctionDuration: number;
|
|
501
|
+
liquidationMarginBufferRatio: number;
|
|
502
|
+
settlementDuration: number;
|
|
503
|
+
signer: PublicKey;
|
|
504
|
+
signerNonce: number;
|
|
505
|
+
srmVault: PublicKey;
|
|
506
|
+
perpFeeStructure: FeeStructure;
|
|
507
|
+
spotFeeStructure: FeeStructure;
|
|
508
|
+
lpCooldownTime: BN;
|
|
278
509
|
};
|
|
279
510
|
|
|
280
|
-
export type
|
|
281
|
-
|
|
282
|
-
|
|
511
|
+
export type PerpMarketAccount = {
|
|
512
|
+
status: MarketStatus;
|
|
513
|
+
contractType: ContractType;
|
|
514
|
+
contractTier: ContractTier;
|
|
515
|
+
expiryTs: BN;
|
|
516
|
+
expiryPrice: BN;
|
|
517
|
+
marketIndex: number;
|
|
283
518
|
pubkey: PublicKey;
|
|
519
|
+
name: number[];
|
|
284
520
|
amm: AMM;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
baseAssetAmountShort: BN;
|
|
288
|
-
openInterest: BN;
|
|
521
|
+
numberOfUsersWithBase: number;
|
|
522
|
+
numberOfUsers: number;
|
|
289
523
|
marginRatioInitial: number;
|
|
290
524
|
marginRatioMaintenance: number;
|
|
291
525
|
nextFillRecordId: BN;
|
|
526
|
+
nextFundingRateRecordId: BN;
|
|
527
|
+
nextCurveRecordId: BN;
|
|
292
528
|
pnlPool: PoolBalance;
|
|
293
|
-
|
|
529
|
+
liquidatorFee: number;
|
|
530
|
+
ifLiquidationFee: number;
|
|
531
|
+
imfFactor: number;
|
|
532
|
+
unrealizedPnlImfFactor: number;
|
|
533
|
+
unrealizedPnlMaxImbalance: BN;
|
|
534
|
+
unrealizedPnlInitialAssetWeight: number;
|
|
535
|
+
unrealizedPnlMaintenanceAssetWeight: number;
|
|
536
|
+
insuranceClaim: {
|
|
537
|
+
revenueWithdrawSinceLastSettle: BN;
|
|
538
|
+
maxRevenueWithdrawPerPeriod: BN;
|
|
539
|
+
lastRevenueWithdrawTs: BN;
|
|
540
|
+
quoteSettledInsurance: BN;
|
|
541
|
+
quoteMaxInsurance: BN;
|
|
542
|
+
};
|
|
294
543
|
};
|
|
295
544
|
|
|
296
|
-
export type
|
|
297
|
-
|
|
545
|
+
export type HistoricalOracleData = {
|
|
546
|
+
lastOraclePrice: BN;
|
|
547
|
+
lastOracleDelay: BN;
|
|
548
|
+
lastOracleConf: BN;
|
|
549
|
+
lastOraclePriceTwap: BN;
|
|
550
|
+
lastOraclePriceTwap5Min: BN;
|
|
551
|
+
lastOraclePriceTwapTs: BN;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
export type HistoricalIndexData = {
|
|
555
|
+
lastIndexBidPrice: BN;
|
|
556
|
+
lastIndexAskPrice: BN;
|
|
557
|
+
lastIndexPriceTwap: BN;
|
|
558
|
+
lastIndexPriceTwap5Min: BN;
|
|
559
|
+
lastIndexPriceTwapTs: BN;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
export type SpotMarketAccount = {
|
|
563
|
+
status: MarketStatus;
|
|
564
|
+
assetTier: AssetTier;
|
|
565
|
+
|
|
566
|
+
marketIndex: number;
|
|
298
567
|
pubkey: PublicKey;
|
|
299
568
|
mint: PublicKey;
|
|
300
569
|
vault: PublicKey;
|
|
301
|
-
|
|
302
|
-
|
|
570
|
+
|
|
571
|
+
oracle: PublicKey;
|
|
572
|
+
oracleSource: OracleSource;
|
|
573
|
+
historicalOracleData: HistoricalOracleData;
|
|
574
|
+
historicalIndexData: HistoricalIndexData;
|
|
575
|
+
|
|
576
|
+
insuranceFund: {
|
|
577
|
+
vault: PublicKey;
|
|
578
|
+
totalShares: BN;
|
|
579
|
+
userShares: BN;
|
|
580
|
+
sharesBase: BN;
|
|
581
|
+
unstakingPeriod: BN;
|
|
582
|
+
lastRevenueSettleTs: BN;
|
|
583
|
+
revenueSettlePeriod: BN;
|
|
584
|
+
totalFactor: number;
|
|
585
|
+
userFactor: number;
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
revenuePool: PoolBalance;
|
|
589
|
+
|
|
590
|
+
ifLiquidationFee: number;
|
|
591
|
+
|
|
303
592
|
decimals: number;
|
|
304
|
-
optimalUtilization:
|
|
305
|
-
optimalBorrowRate:
|
|
306
|
-
maxBorrowRate:
|
|
593
|
+
optimalUtilization: number;
|
|
594
|
+
optimalBorrowRate: number;
|
|
595
|
+
maxBorrowRate: number;
|
|
307
596
|
cumulativeDepositInterest: BN;
|
|
308
597
|
cumulativeBorrowInterest: BN;
|
|
598
|
+
totalSocialLoss: BN;
|
|
599
|
+
totalQuoteSocialLoss: BN;
|
|
309
600
|
depositBalance: BN;
|
|
310
601
|
borrowBalance: BN;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
602
|
+
maxTokenDeposits: BN;
|
|
603
|
+
|
|
604
|
+
lastInterestTs: BN;
|
|
605
|
+
lastTwapTs: BN;
|
|
606
|
+
initialAssetWeight: number;
|
|
607
|
+
maintenanceAssetWeight: number;
|
|
608
|
+
initialLiabilityWeight: number;
|
|
609
|
+
maintenanceLiabilityWeight: number;
|
|
610
|
+
liquidatorFee: number;
|
|
611
|
+
imfFactor: number;
|
|
612
|
+
|
|
613
|
+
withdrawGuardThreshold: BN;
|
|
614
|
+
depositTokenTwap: BN;
|
|
615
|
+
borrowTokenTwap: BN;
|
|
616
|
+
utilizationTwap: BN;
|
|
617
|
+
nextDepositRecordId: BN;
|
|
618
|
+
|
|
619
|
+
orderStepSize: BN;
|
|
620
|
+
orderTickSize: BN;
|
|
621
|
+
nextFillRecordId: BN;
|
|
622
|
+
spotFeePool: PoolBalance;
|
|
623
|
+
totalSpotFee: BN;
|
|
624
|
+
|
|
625
|
+
ordersEnabled: boolean;
|
|
318
626
|
};
|
|
319
627
|
|
|
320
628
|
export type PoolBalance = {
|
|
321
|
-
|
|
629
|
+
scaledBalance: BN;
|
|
630
|
+
marketIndex: number;
|
|
322
631
|
};
|
|
323
632
|
|
|
324
633
|
export type AMM = {
|
|
@@ -328,139 +637,209 @@ export type AMM = {
|
|
|
328
637
|
lastFundingRate: BN;
|
|
329
638
|
lastFundingRateTs: BN;
|
|
330
639
|
lastMarkPriceTwap: BN;
|
|
640
|
+
lastMarkPriceTwap5Min: BN;
|
|
331
641
|
lastMarkPriceTwapTs: BN;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
lastOracleMarkSpreadPct: BN;
|
|
335
|
-
lastOracleConfPct: BN;
|
|
642
|
+
lastTradeTs: BN;
|
|
643
|
+
|
|
336
644
|
oracle: PublicKey;
|
|
337
645
|
oracleSource: OracleSource;
|
|
646
|
+
historicalOracleData: HistoricalOracleData;
|
|
647
|
+
|
|
648
|
+
lastOracleReservePriceSpreadPct: BN;
|
|
649
|
+
lastOracleConfPct: BN;
|
|
650
|
+
|
|
338
651
|
fundingPeriod: BN;
|
|
339
652
|
quoteAssetReserve: BN;
|
|
340
653
|
pegMultiplier: BN;
|
|
341
654
|
cumulativeFundingRateLong: BN;
|
|
342
655
|
cumulativeFundingRateShort: BN;
|
|
343
|
-
|
|
344
|
-
|
|
656
|
+
last24hAvgFundingRate: BN;
|
|
657
|
+
lastFundingRateShort: BN;
|
|
658
|
+
lastFundingRateLong: BN;
|
|
659
|
+
|
|
660
|
+
totalLiquidationFee: BN;
|
|
345
661
|
totalFeeMinusDistributions: BN;
|
|
346
662
|
totalFeeWithdrawn: BN;
|
|
347
663
|
totalFee: BN;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
664
|
+
userLpShares: BN;
|
|
665
|
+
baseAssetAmountWithUnsettledLp: BN;
|
|
666
|
+
orderStepSize: BN;
|
|
667
|
+
orderTickSize: BN;
|
|
668
|
+
maxFillReserveFraction: number;
|
|
351
669
|
maxSlippageRatio: number;
|
|
352
|
-
lastOraclePrice: BN;
|
|
353
670
|
baseSpread: number;
|
|
354
671
|
curveUpdateIntensity: number;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
672
|
+
baseAssetAmountWithAmm: BN;
|
|
673
|
+
baseAssetAmountLong: BN;
|
|
674
|
+
baseAssetAmountShort: BN;
|
|
675
|
+
quoteAssetAmount: BN;
|
|
358
676
|
terminalQuoteAssetReserve: BN;
|
|
677
|
+
concentrationCoef: BN;
|
|
359
678
|
feePool: PoolBalance;
|
|
360
679
|
totalExchangeFee: BN;
|
|
361
680
|
totalMmFee: BN;
|
|
362
681
|
netRevenueSinceLastFunding: BN;
|
|
363
682
|
lastUpdateSlot: BN;
|
|
683
|
+
lastOracleNormalisedPrice: BN;
|
|
684
|
+
lastOracleValid: boolean;
|
|
364
685
|
lastBidPriceTwap: BN;
|
|
365
686
|
lastAskPriceTwap: BN;
|
|
366
|
-
longSpread:
|
|
367
|
-
shortSpread:
|
|
687
|
+
longSpread: number;
|
|
688
|
+
shortSpread: number;
|
|
368
689
|
maxSpread: number;
|
|
690
|
+
|
|
691
|
+
baseAssetAmountPerLp: BN;
|
|
692
|
+
quoteAssetAmountPerLp: BN;
|
|
693
|
+
|
|
694
|
+
ammJitIntensity: number;
|
|
695
|
+
maxOpenInterest: BN;
|
|
696
|
+
maxBaseAssetReserve: BN;
|
|
697
|
+
minBaseAssetReserve: BN;
|
|
698
|
+
totalSocialLoss: BN;
|
|
699
|
+
|
|
700
|
+
quoteBreakEvenAmountLong: BN;
|
|
701
|
+
quoteBreakEvenAmountShort: BN;
|
|
702
|
+
quoteEntryAmountLong: BN;
|
|
703
|
+
quoteEntryAmountShort: BN;
|
|
704
|
+
|
|
705
|
+
markStd: BN;
|
|
706
|
+
oracleStd: BN;
|
|
707
|
+
longIntensityCount: number;
|
|
708
|
+
longIntensityVolume: BN;
|
|
709
|
+
shortIntensityCount: number;
|
|
710
|
+
shortIntensityVolume: BN;
|
|
711
|
+
volume24H: BN;
|
|
712
|
+
minOrderSize: BN;
|
|
713
|
+
maxPositionSize: BN;
|
|
714
|
+
|
|
715
|
+
bidBaseAssetReserve: BN;
|
|
716
|
+
bidQuoteAssetReserve: BN;
|
|
717
|
+
askBaseAssetReserve: BN;
|
|
718
|
+
askQuoteAssetReserve: BN;
|
|
369
719
|
};
|
|
370
720
|
|
|
371
721
|
// # User Account Types
|
|
372
|
-
export type
|
|
722
|
+
export type PerpPosition = {
|
|
373
723
|
baseAssetAmount: BN;
|
|
374
724
|
lastCumulativeFundingRate: BN;
|
|
375
|
-
marketIndex:
|
|
725
|
+
marketIndex: number;
|
|
376
726
|
quoteAssetAmount: BN;
|
|
377
727
|
quoteEntryAmount: BN;
|
|
378
|
-
|
|
379
|
-
|
|
728
|
+
quoteBreakEvenAmount: BN;
|
|
729
|
+
openOrders: number;
|
|
380
730
|
openBids: BN;
|
|
381
731
|
openAsks: BN;
|
|
732
|
+
settledPnl: BN;
|
|
733
|
+
lpShares: BN;
|
|
734
|
+
remainderBaseAssetAmount: number;
|
|
735
|
+
lastNetBaseAssetAmountPerLp: BN;
|
|
736
|
+
lastNetQuoteAssetAmountPerLp: BN;
|
|
382
737
|
};
|
|
383
738
|
|
|
384
|
-
export type
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
739
|
+
export type UserStatsAccount = {
|
|
740
|
+
numberOfSubAccounts: number;
|
|
741
|
+
numberOfSubAccountsCreated: number;
|
|
742
|
+
makerVolume30D: BN;
|
|
743
|
+
takerVolume30D: BN;
|
|
744
|
+
fillerVolume30D: BN;
|
|
745
|
+
lastMakerVolume30DTs: BN;
|
|
746
|
+
lastTakerVolume30DTs: BN;
|
|
747
|
+
lastFillerVolume30DTs: BN;
|
|
391
748
|
fees: {
|
|
392
749
|
totalFeePaid: BN;
|
|
393
750
|
totalFeeRebate: BN;
|
|
394
751
|
totalTokenDiscount: BN;
|
|
395
|
-
totalReferralReward: BN;
|
|
396
752
|
totalRefereeDiscount: BN;
|
|
753
|
+
totalReferrerReward: BN;
|
|
754
|
+
current_epoch_referrer_reward: BN;
|
|
397
755
|
};
|
|
398
|
-
|
|
756
|
+
referrer: PublicKey;
|
|
757
|
+
isReferrer: boolean;
|
|
758
|
+
authority: PublicKey;
|
|
759
|
+
ifStakedQuoteAssetAmount: BN;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
export type UserAccount = {
|
|
763
|
+
authority: PublicKey;
|
|
764
|
+
delegate: PublicKey;
|
|
765
|
+
name: number[];
|
|
766
|
+
subAccountId: number;
|
|
767
|
+
spotPositions: SpotPosition[];
|
|
768
|
+
perpPositions: PerpPosition[];
|
|
399
769
|
orders: Order[];
|
|
400
|
-
|
|
770
|
+
status: UserStatus;
|
|
771
|
+
nextLiquidationId: number;
|
|
772
|
+
nextOrderId: number;
|
|
773
|
+
maxMarginRatio: number;
|
|
774
|
+
lastAddPerpLpSharesTs: BN;
|
|
775
|
+
settledPerpPnl: BN;
|
|
776
|
+
totalDeposits: BN;
|
|
777
|
+
totalWithdraws: BN;
|
|
778
|
+
totalSocialLoss: BN;
|
|
779
|
+
cumulativePerpFunding: BN;
|
|
401
780
|
};
|
|
402
781
|
|
|
403
|
-
export type
|
|
404
|
-
|
|
405
|
-
balanceType:
|
|
406
|
-
|
|
782
|
+
export type SpotPosition = {
|
|
783
|
+
marketIndex: number;
|
|
784
|
+
balanceType: SpotBalanceType;
|
|
785
|
+
scaledBalance: BN;
|
|
786
|
+
openOrders: number;
|
|
787
|
+
openBids: BN;
|
|
788
|
+
openAsks: BN;
|
|
789
|
+
cumulativeDeposits: BN;
|
|
407
790
|
};
|
|
408
791
|
|
|
409
792
|
export type Order = {
|
|
410
793
|
status: OrderStatus;
|
|
411
794
|
orderType: OrderType;
|
|
412
|
-
|
|
795
|
+
marketType: MarketType;
|
|
413
796
|
slot: BN;
|
|
414
|
-
orderId:
|
|
797
|
+
orderId: number;
|
|
415
798
|
userOrderId: number;
|
|
416
|
-
marketIndex:
|
|
799
|
+
marketIndex: number;
|
|
417
800
|
price: BN;
|
|
418
801
|
baseAssetAmount: BN;
|
|
419
802
|
baseAssetAmountFilled: BN;
|
|
420
803
|
quoteAssetAmount: BN;
|
|
421
804
|
quoteAssetAmountFilled: BN;
|
|
422
|
-
fee: BN;
|
|
423
805
|
direction: PositionDirection;
|
|
424
806
|
reduceOnly: boolean;
|
|
425
807
|
triggerPrice: BN;
|
|
426
808
|
triggerCondition: OrderTriggerCondition;
|
|
427
|
-
triggered: boolean;
|
|
428
|
-
discountTier: OrderDiscountTier;
|
|
429
809
|
existingPositionDirection: PositionDirection;
|
|
430
|
-
referrer: PublicKey;
|
|
431
810
|
postOnly: boolean;
|
|
432
811
|
immediateOrCancel: boolean;
|
|
433
|
-
oraclePriceOffset:
|
|
812
|
+
oraclePriceOffset: number;
|
|
434
813
|
auctionDuration: number;
|
|
435
814
|
auctionStartPrice: BN;
|
|
436
815
|
auctionEndPrice: BN;
|
|
816
|
+
maxTs: BN;
|
|
437
817
|
};
|
|
438
818
|
|
|
439
819
|
export type OrderParams = {
|
|
440
820
|
orderType: OrderType;
|
|
821
|
+
marketType: MarketType;
|
|
441
822
|
userOrderId: number;
|
|
442
823
|
direction: PositionDirection;
|
|
443
824
|
baseAssetAmount: BN;
|
|
444
825
|
price: BN;
|
|
445
|
-
marketIndex:
|
|
826
|
+
marketIndex: number;
|
|
446
827
|
reduceOnly: boolean;
|
|
447
828
|
postOnly: boolean;
|
|
448
829
|
immediateOrCancel: boolean;
|
|
449
|
-
triggerPrice: BN;
|
|
830
|
+
triggerPrice: BN | null;
|
|
450
831
|
triggerCondition: OrderTriggerCondition;
|
|
451
832
|
positionLimit: BN;
|
|
452
|
-
oraclePriceOffset:
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
referrer: boolean;
|
|
458
|
-
};
|
|
833
|
+
oraclePriceOffset: number | null;
|
|
834
|
+
auctionDuration: number | null;
|
|
835
|
+
maxTs: BN | null;
|
|
836
|
+
auctionStartPrice: BN | null;
|
|
837
|
+
auctionEndPrice: BN | null;
|
|
459
838
|
};
|
|
460
839
|
|
|
461
840
|
export type NecessaryOrderParams = {
|
|
462
841
|
orderType: OrderType;
|
|
463
|
-
marketIndex:
|
|
842
|
+
marketIndex: number;
|
|
464
843
|
baseAssetAmount: BN;
|
|
465
844
|
direction: PositionDirection;
|
|
466
845
|
};
|
|
@@ -469,38 +848,46 @@ export type OptionalOrderParams = {
|
|
|
469
848
|
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
470
849
|
} & NecessaryOrderParams;
|
|
471
850
|
|
|
472
|
-
export const DefaultOrderParams = {
|
|
851
|
+
export const DefaultOrderParams: OrderParams = {
|
|
473
852
|
orderType: OrderType.MARKET,
|
|
853
|
+
marketType: MarketType.PERP,
|
|
474
854
|
userOrderId: 0,
|
|
475
855
|
direction: PositionDirection.LONG,
|
|
476
856
|
baseAssetAmount: ZERO,
|
|
477
857
|
price: ZERO,
|
|
478
|
-
marketIndex:
|
|
858
|
+
marketIndex: 0,
|
|
479
859
|
reduceOnly: false,
|
|
480
860
|
postOnly: false,
|
|
481
861
|
immediateOrCancel: false,
|
|
482
|
-
triggerPrice:
|
|
862
|
+
triggerPrice: null,
|
|
483
863
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
484
864
|
positionLimit: ZERO,
|
|
485
|
-
oraclePriceOffset:
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
referrer: false,
|
|
491
|
-
},
|
|
865
|
+
oraclePriceOffset: null,
|
|
866
|
+
auctionDuration: null,
|
|
867
|
+
maxTs: null,
|
|
868
|
+
auctionStartPrice: null,
|
|
869
|
+
auctionEndPrice: null,
|
|
492
870
|
};
|
|
493
871
|
|
|
494
872
|
export type MakerInfo = {
|
|
495
873
|
maker: PublicKey;
|
|
874
|
+
makerStats: PublicKey;
|
|
875
|
+
makerUserAccount: UserAccount;
|
|
496
876
|
order: Order;
|
|
497
877
|
};
|
|
498
878
|
|
|
499
879
|
export type TakerInfo = {
|
|
500
880
|
taker: PublicKey;
|
|
881
|
+
takerStats: PublicKey;
|
|
882
|
+
takerUserAccount: UserAccount;
|
|
501
883
|
order: Order;
|
|
502
884
|
};
|
|
503
885
|
|
|
886
|
+
export type ReferrerInfo = {
|
|
887
|
+
referrer: PublicKey;
|
|
888
|
+
referrerStats: PublicKey;
|
|
889
|
+
};
|
|
890
|
+
|
|
504
891
|
// # Misc Types
|
|
505
892
|
export interface IWallet {
|
|
506
893
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
@@ -509,40 +896,29 @@ export interface IWallet {
|
|
|
509
896
|
}
|
|
510
897
|
|
|
511
898
|
export type FeeStructure = {
|
|
512
|
-
|
|
513
|
-
feeDenominator: BN;
|
|
514
|
-
discountTokenTiers: {
|
|
515
|
-
firstTier: {
|
|
516
|
-
minimumBalance: BN;
|
|
517
|
-
discountNumerator: BN;
|
|
518
|
-
discountDenominator: BN;
|
|
519
|
-
};
|
|
520
|
-
secondTier: {
|
|
521
|
-
minimumBalance: BN;
|
|
522
|
-
discountNumerator: BN;
|
|
523
|
-
discountDenominator: BN;
|
|
524
|
-
};
|
|
525
|
-
thirdTier: {
|
|
526
|
-
minimumBalance: BN;
|
|
527
|
-
discountNumerator: BN;
|
|
528
|
-
discountDenominator: BN;
|
|
529
|
-
};
|
|
530
|
-
fourthTier: {
|
|
531
|
-
minimumBalance: BN;
|
|
532
|
-
discountNumerator: BN;
|
|
533
|
-
discountDenominator: BN;
|
|
534
|
-
};
|
|
535
|
-
};
|
|
536
|
-
referralDiscount: {
|
|
537
|
-
referrerRewardNumerator: BN;
|
|
538
|
-
referrerRewardDenominator: BN;
|
|
539
|
-
refereeDiscountNumerator: BN;
|
|
540
|
-
refereeDiscountDenominator: BN;
|
|
541
|
-
};
|
|
899
|
+
feeTiers: FeeTier[];
|
|
542
900
|
makerRebateNumerator: BN;
|
|
543
901
|
makerRebateDenominator: BN;
|
|
544
902
|
fillerRewardStructure: OrderFillerRewardStructure;
|
|
545
|
-
|
|
903
|
+
flatFillerFee: BN;
|
|
904
|
+
referrerRewardEpochUpperBound: BN;
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
export type FeeTier = {
|
|
908
|
+
feeNumerator: number;
|
|
909
|
+
feeDenominator: number;
|
|
910
|
+
makerRebateNumerator: number;
|
|
911
|
+
makerRebateDenominator: number;
|
|
912
|
+
referrerRewardNumerator: number;
|
|
913
|
+
referrerRewardDenominator: number;
|
|
914
|
+
refereeFeeNumerator: number;
|
|
915
|
+
refereeFeeDenominator: number;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
export type OrderFillerRewardStructure = {
|
|
919
|
+
rewardNumerator: BN;
|
|
920
|
+
rewardDenominator: BN;
|
|
921
|
+
timeBasedRewardLowerBound: BN;
|
|
546
922
|
};
|
|
547
923
|
|
|
548
924
|
export type OracleGuardRails = {
|
|
@@ -551,17 +927,40 @@ export type OracleGuardRails = {
|
|
|
551
927
|
markOracleDivergenceDenominator: BN;
|
|
552
928
|
};
|
|
553
929
|
validity: {
|
|
554
|
-
|
|
930
|
+
slotsBeforeStaleForAmm: BN;
|
|
931
|
+
slotsBeforeStaleForMargin: BN;
|
|
555
932
|
confidenceIntervalMaxSize: BN;
|
|
556
933
|
tooVolatileRatio: BN;
|
|
557
934
|
};
|
|
558
|
-
useForLiquidations: boolean;
|
|
559
935
|
};
|
|
560
936
|
|
|
561
|
-
export type
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
937
|
+
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
938
|
+
|
|
939
|
+
export type InsuranceFundStake = {
|
|
940
|
+
marketIndex: number;
|
|
941
|
+
authority: PublicKey;
|
|
942
|
+
|
|
943
|
+
ifShares: BN;
|
|
944
|
+
ifBase: BN;
|
|
945
|
+
|
|
946
|
+
lastWithdrawRequestShares: BN;
|
|
947
|
+
lastWithdrawRequestValue: BN;
|
|
948
|
+
lastWithdrawRequestTs: BN;
|
|
565
949
|
};
|
|
566
950
|
|
|
567
|
-
export type
|
|
951
|
+
export type SerumV3FulfillmentConfigAccount = {
|
|
952
|
+
fulfillmentType: SpotFulfillmentType;
|
|
953
|
+
status: SpotFulfillmentStatus;
|
|
954
|
+
pubkey: PublicKey;
|
|
955
|
+
marketIndex: number;
|
|
956
|
+
serumProgramId: PublicKey;
|
|
957
|
+
serumMarket: PublicKey;
|
|
958
|
+
serumRequestQueue: PublicKey;
|
|
959
|
+
serumEventQueue: PublicKey;
|
|
960
|
+
serumBids: PublicKey;
|
|
961
|
+
serumAsks: PublicKey;
|
|
962
|
+
serumBaseVault: PublicKey;
|
|
963
|
+
serumQuoteVault: PublicKey;
|
|
964
|
+
serumOpenOrders: PublicKey;
|
|
965
|
+
serumSignerNonce: BN;
|
|
966
|
+
};
|