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