@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
- package/lib/accounts/types.d.ts +2 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
- package/lib/admin.d.ts +5 -2
- package/lib/admin.js +30 -4
- package/lib/clearingHouse.d.ts +3 -0
- package/lib/clearingHouse.js +19 -1
- package/lib/clearingHouseUser.d.ts +11 -9
- package/lib/clearingHouseUser.js +184 -108
- package/lib/config.js +1 -1
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/idl/clearing_house.json +123 -203
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/math/market.d.ts +3 -2
- package/lib/math/market.js +17 -12
- package/lib/math/orders.d.ts +3 -3
- package/lib/math/orders.js +31 -16
- package/lib/math/position.d.ts +3 -3
- package/lib/math/position.js +23 -16
- package/lib/math/repeg.js +8 -0
- package/lib/math/spotBalance.d.ts +3 -0
- package/lib/math/spotBalance.js +18 -1
- package/lib/math/spotPosition.d.ts +5 -1
- package/lib/math/spotPosition.js +16 -1
- package/lib/types.d.ts +25 -24
- package/lib/types.js +9 -3
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
- package/src/accounts/types.ts +1 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
- package/src/admin.ts +50 -8
- package/src/clearingHouse.ts +30 -1
- package/src/clearingHouseUser.ts +366 -167
- package/src/config.ts +1 -1
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/idl/clearing_house.json +123 -203
- package/src/index.ts +5 -0
- package/src/math/market.ts +22 -13
- package/src/math/orders.ts +29 -21
- package/src/math/position.ts +36 -22
- package/src/math/repeg.ts +9 -0
- package/src/math/spotBalance.ts +26 -0
- package/src/math/spotPosition.ts +42 -1
- package/src/types.ts +26 -24
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/my-script/.env +0 -7
- package/my-script/getUserStats.ts +0 -106
- package/my-script/multiConnections.ts +0 -119
- package/my-script/test-regex.ts +0 -11
- package/my-script/utils.ts +0 -52
- package/src/accounts/bulkAccountLoader.js +0 -249
- package/src/accounts/bulkUserStatsSubscription.js +0 -75
- package/src/accounts/bulkUserSubscription.js +0 -75
- package/src/accounts/fetch.js +0 -92
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
- package/src/accounts/pollingOracleSubscriber.js +0 -156
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
- package/src/accounts/pollingUserAccountSubscriber.js +0 -208
- package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
- package/src/accounts/types.js +0 -28
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -138
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
- package/src/addresses/pda.js +0 -186
- package/src/admin.js +0 -1284
- package/src/assert/assert.js +0 -9
- package/src/clearingHouse.js +0 -3433
- package/src/clearingHouseConfig.js +0 -2
- package/src/clearingHouseUser.js +0 -874
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/clearingHouseUserStats.js +0 -115
- package/src/clearingHouseUserStatsConfig.js +0 -2
- package/src/config.js +0 -80
- package/src/constants/numericConstants.js +0 -48
- package/src/constants/perpMarkets.js +0 -42
- package/src/constants/spotMarkets.js +0 -51
- package/src/events/eventList.js +0 -120
- package/src/events/eventSubscriber.js +0 -202
- package/src/events/fetchLogs.js +0 -117
- package/src/events/pollingLogProvider.js +0 -113
- package/src/events/sort.js +0 -41
- package/src/events/txEventCache.js +0 -74
- package/src/events/types.js +0 -25
- package/src/events/webSocketLogProvider.js +0 -76
- package/src/factory/bigNum.js +0 -393
- package/src/factory/oracleClient.js +0 -20
- package/src/index.js +0 -75
- package/src/math/amm.js +0 -422
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -12
- package/src/math/funding.js +0 -296
- package/src/math/insurance.js +0 -27
- package/src/math/margin.js +0 -77
- package/src/math/market.js +0 -105
- package/src/math/oracles.js +0 -56
- package/src/math/orders.js +0 -153
- package/src/math/position.js +0 -172
- package/src/math/repeg.js +0 -128
- package/src/math/spotBalance.js +0 -176
- package/src/math/spotMarket.js +0 -8
- package/src/math/spotPosition.js +0 -8
- package/src/math/trade.js +0 -260
- package/src/math/utils.js +0 -27
- package/src/oracles/oracleClientCache.js +0 -20
- package/src/oracles/pythClient.js +0 -81
- package/src/oracles/quoteAssetOracleClient.js +0 -63
- package/src/oracles/switchboardClient.js +0 -101
- package/src/oracles/types.js +0 -2
- package/src/orderParams.js +0 -28
- package/src/serum/serumSubscriber.js +0 -102
- package/src/serum/types.js +0 -2
- package/src/slot/SlotSubscriber.js +0 -86
- package/src/token/index.js +0 -38
- package/src/tokenFaucet.js +0 -323
- package/src/tx/retryTxSender.js +0 -280
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -18
- package/src/types.js +0 -216
- package/src/userName.js +0 -20
- package/src/util/computeUnits.js +0 -62
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -61
- package/src/wallet.js +0 -72
|
@@ -53,6 +53,7 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
53
53
|
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
54
54
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
55
55
|
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
56
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
56
57
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
57
58
|
}
|
|
58
59
|
declare type ClearingHouseAccounts = {
|
|
@@ -262,6 +262,9 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
262
262
|
getSpotMarketAccountAndSlot(marketIndex) {
|
|
263
263
|
return this.spotMarket.get(marketIndex.toNumber());
|
|
264
264
|
}
|
|
265
|
+
getSpotMarketAccountsAndSlots() {
|
|
266
|
+
return Array.from(this.spotMarket.values());
|
|
267
|
+
}
|
|
265
268
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
266
269
|
this.assertIsSubscribed();
|
|
267
270
|
if (oraclePublicKey.equals(web3_js_1.PublicKey.default)) {
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import { SpotMarketAccount, PerpMarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
4
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
6
|
import { EventEmitter } from 'events';
|
|
@@ -38,6 +39,7 @@ export interface ClearingHouseAccountSubscriber {
|
|
|
38
39
|
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
39
40
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
40
41
|
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
42
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
41
43
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
42
44
|
}
|
|
43
45
|
export interface UserAccountEvents {
|
|
@@ -45,5 +45,6 @@ export declare class WebSocketClearingHouseAccountSubscriber implements Clearing
|
|
|
45
45
|
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
46
46
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
47
47
|
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
48
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
48
49
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
49
50
|
}
|
|
@@ -181,6 +181,9 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
181
181
|
return this.spotMarketAccountSubscribers.get(marketIndex.toNumber())
|
|
182
182
|
.dataAndSlot;
|
|
183
183
|
}
|
|
184
|
+
getSpotMarketAccountsAndSlots() {
|
|
185
|
+
return Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
186
|
+
}
|
|
184
187
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
185
188
|
this.assertIsSubscribed();
|
|
186
189
|
if (oraclePublicKey.equals(web3_js_1.PublicKey.default)) {
|
package/lib/admin.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class Admin extends ClearingHouse {
|
|
|
10
10
|
initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN): Promise<TransactionSignature>;
|
|
11
11
|
moveAmmPrice(marketIndex: BN, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
12
|
updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
13
|
+
updateConcentrationScale(marketIndex: BN, concentrationScale: BN): Promise<TransactionSignature>;
|
|
13
14
|
moveAmmToPrice(perpMarketIndex: BN, targetPrice: BN): Promise<TransactionSignature>;
|
|
14
15
|
repegAmmCurve(newPeg: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
15
16
|
updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
|
|
@@ -32,7 +33,8 @@ export declare class Admin extends ClearingHouse {
|
|
|
32
33
|
updateFee(fees: FeeStructure): Promise<TransactionSignature>;
|
|
33
34
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
34
35
|
updateWithdrawGuardThreshold(marketIndex: BN, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
|
|
35
|
-
updateSpotMarketIfFactor(marketIndex: BN, userIfFactor: BN, totalIfFactor: BN
|
|
36
|
+
updateSpotMarketIfFactor(marketIndex: BN, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
|
|
37
|
+
updateSpotMarketRevenueSettlePeriod(marketIndex: BN, revenueSettlePeriod: BN): Promise<TransactionSignature>;
|
|
36
38
|
updateInsuranceWithdrawEscrowPeriod(marketIndex: BN, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
|
|
37
39
|
updateLpCooldownTime(marketIndex: BN, cooldownTime: BN): Promise<TransactionSignature>;
|
|
38
40
|
updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
@@ -45,7 +47,8 @@ export declare class Admin extends ClearingHouse {
|
|
|
45
47
|
updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
|
|
46
48
|
updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
|
|
47
49
|
disableAdminControlsPrices(): Promise<TransactionSignature>;
|
|
48
|
-
|
|
50
|
+
updatePerpAuctionDuration(minDuration: BN | number): Promise<TransactionSignature>;
|
|
51
|
+
updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
|
|
49
52
|
updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
50
53
|
updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
51
54
|
updateMarketMaxImbalances(marketIndex: BN, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
package/lib/admin.js
CHANGED
|
@@ -148,6 +148,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
148
148
|
},
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
+
async updateConcentrationScale(marketIndex, concentrationScale) {
|
|
152
|
+
return await this.program.rpc.updateConcentrationScale(concentrationScale, {
|
|
153
|
+
accounts: {
|
|
154
|
+
state: await this.getStatePublicKey(),
|
|
155
|
+
admin: this.wallet.publicKey,
|
|
156
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
151
160
|
async moveAmmToPrice(perpMarketIndex, targetPrice) {
|
|
152
161
|
const market = this.getPerpMarketAccount(perpMarketIndex);
|
|
153
162
|
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
@@ -373,8 +382,17 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
373
382
|
},
|
|
374
383
|
});
|
|
375
384
|
}
|
|
376
|
-
async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor
|
|
377
|
-
return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor,
|
|
385
|
+
async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor) {
|
|
386
|
+
return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, {
|
|
387
|
+
accounts: {
|
|
388
|
+
admin: this.wallet.publicKey,
|
|
389
|
+
state: await this.getStatePublicKey(),
|
|
390
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
async updateSpotMarketRevenueSettlePeriod(marketIndex, revenueSettlePeriod) {
|
|
395
|
+
return await this.program.rpc.updateSpotMarketRevenueSettlePeriod(revenueSettlePeriod, {
|
|
378
396
|
accounts: {
|
|
379
397
|
admin: this.wallet.publicKey,
|
|
380
398
|
state: await this.getStatePublicKey(),
|
|
@@ -484,8 +502,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
484
502
|
},
|
|
485
503
|
});
|
|
486
504
|
}
|
|
487
|
-
async
|
|
488
|
-
return await this.program.rpc.
|
|
505
|
+
async updatePerpAuctionDuration(minDuration) {
|
|
506
|
+
return await this.program.rpc.updatePerpAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), {
|
|
507
|
+
accounts: {
|
|
508
|
+
admin: this.wallet.publicKey,
|
|
509
|
+
state: await this.getStatePublicKey(),
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async updateSpotAuctionDuration(defaultAuctionDuration) {
|
|
514
|
+
return await this.program.rpc.updateSpotAuctionDuration(defaultAuctionDuration, {
|
|
489
515
|
accounts: {
|
|
490
516
|
admin: this.wallet.publicKey,
|
|
491
517
|
state: await this.getStatePublicKey(),
|
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export declare class ClearingHouse {
|
|
|
53
53
|
getPerpMarketAccount(marketIndex: BN | number): PerpMarketAccount | undefined;
|
|
54
54
|
getPerpMarketAccounts(): PerpMarketAccount[];
|
|
55
55
|
getSpotMarketAccount(marketIndex: BN | number): SpotMarketAccount | undefined;
|
|
56
|
+
getSpotMarketAccounts(): SpotMarketAccount[];
|
|
56
57
|
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
57
58
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
58
59
|
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
@@ -69,6 +70,7 @@ export declare class ClearingHouse {
|
|
|
69
70
|
getInitializeUserInstructions(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
70
71
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
71
72
|
updateUserName(name: string, userId?: number): Promise<TransactionSignature>;
|
|
73
|
+
updateUserCustomMarginRatio(marginRatio: number, userId?: number): Promise<TransactionSignature>;
|
|
72
74
|
getUser(userId?: number): ClearingHouseUser;
|
|
73
75
|
getUsers(): ClearingHouseUser[];
|
|
74
76
|
getUserStats(): ClearingHouseUserStats;
|
|
@@ -191,6 +193,7 @@ export declare class ClearingHouse {
|
|
|
191
193
|
getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
|
|
192
194
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
193
195
|
getOracleDataForMarket(marketIndex: BN): OraclePriceData;
|
|
196
|
+
getOracleDataForSpotMarket(marketIndex: BN): OraclePriceData;
|
|
194
197
|
initializeInsuranceFundStake(marketIndex: BN): Promise<TransactionSignature>;
|
|
195
198
|
getInitializeInsuranceFundStakeIx(marketIndex: BN): Promise<TransactionInstruction>;
|
|
196
199
|
addInsuranceFundStake(marketIndex: BN, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
package/lib/clearingHouse.js
CHANGED
|
@@ -188,6 +188,11 @@ class ClearingHouse {
|
|
|
188
188
|
marketIndex = marketIndex instanceof anchor_1.BN ? marketIndex : new anchor_1.BN(marketIndex);
|
|
189
189
|
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data;
|
|
190
190
|
}
|
|
191
|
+
getSpotMarketAccounts() {
|
|
192
|
+
return this.accountSubscriber
|
|
193
|
+
.getSpotMarketAccountsAndSlots()
|
|
194
|
+
.map((value) => value.data);
|
|
195
|
+
}
|
|
191
196
|
getQuoteSpotMarketAccount() {
|
|
192
197
|
return this.accountSubscriber.getSpotMarketAccountAndSlot(numericConstants_1.QUOTE_SPOT_MARKET_INDEX).data;
|
|
193
198
|
}
|
|
@@ -296,6 +301,14 @@ class ClearingHouse {
|
|
|
296
301
|
},
|
|
297
302
|
});
|
|
298
303
|
}
|
|
304
|
+
async updateUserCustomMarginRatio(marginRatio, userId = 0) {
|
|
305
|
+
return await this.program.rpc.updateUserCustomMarginRatio(userId, marginRatio, {
|
|
306
|
+
accounts: {
|
|
307
|
+
user: await this.getUserAccountPublicKey(),
|
|
308
|
+
authority: this.wallet.publicKey,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
299
312
|
getUser(userId) {
|
|
300
313
|
userId = userId !== null && userId !== void 0 ? userId : this.activeUserId;
|
|
301
314
|
if (!this.users.has(userId)) {
|
|
@@ -384,7 +397,7 @@ class ClearingHouse {
|
|
|
384
397
|
perpMarketAccountMap.set(params.readablePerpMarketIndex.toNumber(), {
|
|
385
398
|
pubkey: marketAccount.pubkey,
|
|
386
399
|
isSigner: false,
|
|
387
|
-
isWritable:
|
|
400
|
+
isWritable: false,
|
|
388
401
|
});
|
|
389
402
|
oracleAccountMap.set(marketAccount.amm.oracle.toString(), {
|
|
390
403
|
pubkey: marketAccount.amm.oracle,
|
|
@@ -1989,6 +2002,11 @@ class ClearingHouse {
|
|
|
1989
2002
|
const oracleData = this.getOraclePriceDataAndSlot(oracleKey).data;
|
|
1990
2003
|
return oracleData;
|
|
1991
2004
|
}
|
|
2005
|
+
getOracleDataForSpotMarket(marketIndex) {
|
|
2006
|
+
const oracleKey = this.getSpotMarketAccount(marketIndex).oracle;
|
|
2007
|
+
const oracleData = this.getOraclePriceDataAndSlot(oracleKey).data;
|
|
2008
|
+
return oracleData;
|
|
2009
|
+
}
|
|
1992
2010
|
async initializeInsuranceFundStake(marketIndex) {
|
|
1993
2011
|
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getInitializeInsuranceFundStakeIx(marketIndex)), [], this.opts);
|
|
1994
2012
|
return txSig;
|
|
@@ -6,7 +6,7 @@ import StrictEventEmitter from 'strict-event-emitter-types';
|
|
|
6
6
|
import { ClearingHouse } from './clearingHouse';
|
|
7
7
|
import { MarginCategory, Order, UserAccount, PerpPosition } from './types';
|
|
8
8
|
import { UserAccountSubscriber, UserAccountEvents, DataAndSlot } from './accounts/types';
|
|
9
|
-
import { PositionDirection, BN } from '.';
|
|
9
|
+
import { PositionDirection, BN, SpotMarketAccount } from '.';
|
|
10
10
|
import { OraclePriceData } from './oracles/types';
|
|
11
11
|
import { ClearingHouseUserConfig } from './clearingHouseUserConfig';
|
|
12
12
|
export declare class ClearingHouseUser {
|
|
@@ -70,7 +70,7 @@ export declare class ClearingHouseUser {
|
|
|
70
70
|
/**
|
|
71
71
|
* @returns The margin requirement of a certain type (Initial or Maintenance) in USDC. : QUOTE_PRECISION
|
|
72
72
|
*/
|
|
73
|
-
getMarginRequirement(
|
|
73
|
+
getMarginRequirement(marginCategory: MarginCategory, liquidationBuffer?: BN): BN;
|
|
74
74
|
/**
|
|
75
75
|
* @returns The initial margin requirement in USDC. : QUOTE_PRECISION
|
|
76
76
|
*/
|
|
@@ -89,8 +89,10 @@ export declare class ClearingHouseUser {
|
|
|
89
89
|
* @returns : Precision QUOTE_PRECISION
|
|
90
90
|
*/
|
|
91
91
|
getUnrealizedFundingPNL(marketIndex?: BN): BN;
|
|
92
|
-
getSpotMarketLiabilityValue(marketIndex?: BN,
|
|
93
|
-
|
|
92
|
+
getSpotMarketLiabilityValue(marketIndex?: BN, marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
93
|
+
getSpotLiabilityValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
|
|
94
|
+
getSpotMarketAssetValue(marketIndex?: BN, marginCategory?: MarginCategory, includeOpenOrders?: boolean): BN;
|
|
95
|
+
getSpotAssetValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory): BN;
|
|
94
96
|
getNetSpotMarketValue(withWeightMarginCategory?: MarginCategory): BN;
|
|
95
97
|
/**
|
|
96
98
|
* calculates TotalCollateral: collateral + unrealized pnl
|
|
@@ -101,12 +103,12 @@ export declare class ClearingHouseUser {
|
|
|
101
103
|
* calculates sum of position value across all positions in margin system
|
|
102
104
|
* @returns : Precision QUOTE_PRECISION
|
|
103
105
|
*/
|
|
104
|
-
|
|
106
|
+
getTotalPerpPositionValue(marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
|
|
105
107
|
/**
|
|
106
108
|
* calculates position value in margin system
|
|
107
109
|
* @returns : Precision QUOTE_PRECISION
|
|
108
110
|
*/
|
|
109
|
-
|
|
111
|
+
getPerpPositionValue(marketIndex: BN, oraclePriceData: OraclePriceData): BN;
|
|
110
112
|
getPositionSide(currentPosition: Pick<PerpPosition, 'baseAssetAmount'>): PositionDirection | undefined;
|
|
111
113
|
/**
|
|
112
114
|
* calculates average exit price (optionally for closing up to 100% of position)
|
|
@@ -117,7 +119,7 @@ export declare class ClearingHouseUser {
|
|
|
117
119
|
* calculates current user leverage across all positions
|
|
118
120
|
* @returns : Precision TEN_THOUSAND
|
|
119
121
|
*/
|
|
120
|
-
getLeverage(): BN;
|
|
122
|
+
getLeverage(marginCategory?: MarginCategory): BN;
|
|
121
123
|
/**
|
|
122
124
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
123
125
|
* @params category {Initial, Partial, Maintenance}
|
|
@@ -128,7 +130,7 @@ export declare class ClearingHouseUser {
|
|
|
128
130
|
* calculates margin ratio: total collateral / |total position value|
|
|
129
131
|
* @returns : Precision TEN_THOUSAND
|
|
130
132
|
*/
|
|
131
|
-
getMarginRatio(): BN;
|
|
133
|
+
getMarginRatio(marginCategory?: MarginCategory): BN;
|
|
132
134
|
canBeLiquidated(): boolean;
|
|
133
135
|
/**
|
|
134
136
|
* Checks if any user position cumulative funding differs from respective market cumulative funding
|
|
@@ -191,7 +193,7 @@ export declare class ClearingHouseUser {
|
|
|
191
193
|
* @param marketToIgnore
|
|
192
194
|
* @returns positionValue : Precision QUOTE_PRECISION
|
|
193
195
|
*/
|
|
194
|
-
private
|
|
196
|
+
private getTotalPerpPositionValueExcludingMarket;
|
|
195
197
|
private getOracleDataForMarket;
|
|
196
198
|
private getOracleDataForSpotMarket;
|
|
197
199
|
}
|