@drift-labs/sdk 0.2.0-master.37 → 0.2.0-master.39
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 +14 -14
- package/lib/accounts/bulkUserStatsSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +3 -8
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +6 -13
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/types.d.ts +4 -4
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.d.ts → webSocketDriftClientAccountSubscriber.d.ts} +3 -3
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +4 -4
- package/lib/addresses/pda.d.ts +3 -3
- package/lib/addresses/pda.js +10 -10
- package/lib/{admin.d.ts → adminClient.d.ts} +12 -4
- package/lib/{admin.js → adminClient.js} +89 -15
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +3 -0
- package/lib/constants/numericConstants.js +5 -2
- package/lib/dlob/DLOB.d.ts +2 -2
- package/lib/dlob/DLOB.js +4 -4
- package/lib/{clearingHouse.d.ts → driftClient.d.ts} +21 -20
- package/lib/{clearingHouse.js → driftClient.js} +48 -37
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +3 -3
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/examples/makeTradeExample.js +13 -13
- package/lib/idl/{clearing_house.json → drift.json} +717 -143
- package/lib/index.d.ts +10 -10
- package/lib/index.js +10 -10
- package/lib/math/orders.d.ts +4 -4
- package/lib/math/orders.js +3 -3
- package/lib/serum/serumFulfillmentConfigMap.d.ts +3 -3
- package/lib/serum/serumFulfillmentConfigMap.js +3 -3
- package/lib/types.d.ts +38 -2
- package/lib/types.js +2 -1
- package/lib/{clearingHouseUser.d.ts → user.d.ts} +16 -10
- package/lib/{clearingHouseUser.js → user.js} +54 -46
- package/lib/userConfig.d.ts +14 -0
- package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
- package/lib/userMap/userMap.d.ts +17 -17
- package/lib/userMap/userMap.js +15 -15
- package/lib/userMap/userStatsMap.d.ts +7 -7
- package/lib/userMap/userStatsMap.js +10 -10
- package/lib/{clearingHouseUserStats.d.ts → userStats.d.ts} +5 -5
- package/lib/{clearingHouseUserStats.js → userStats.js} +8 -8
- package/lib/userStatsConfig.d.ts +14 -0
- package/lib/{clearingHouseUserStatsConfig.js → userStatsConfig.js} +0 -0
- package/package.json +1 -1
- package/src/accounts/bulkUserStatsSubscription.ts +2 -2
- package/src/accounts/bulkUserSubscription.ts +2 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +11 -25
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/types.ts +4 -4
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +7 -7
- package/src/addresses/pda.ts +6 -8
- package/src/{admin.ts → adminClient.ts} +185 -18
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +4 -0
- package/src/dlob/DLOB.ts +5 -5
- package/src/{clearingHouse.ts → driftClient.ts} +85 -68
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +3 -3
- package/src/examples/makeTradeExample.ts +15 -17
- package/src/idl/{clearing_house.json → drift.json} +717 -143
- package/src/index.ts +10 -10
- package/src/math/orders.ts +7 -13
- package/src/serum/serumFulfillmentConfigMap.ts +5 -5
- package/src/types.ts +41 -2
- package/src/{clearingHouseUser.ts → user.ts} +60 -54
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +29 -29
- package/src/userMap/userStatsMap.ts +21 -23
- package/src/{clearingHouseUserStats.ts → userStats.ts} +10 -10
- package/src/userStatsConfig.ts +18 -0
- package/tests/dlob/helpers.ts +55 -13
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/clearingHouseUserStatsConfig.d.ts +0 -14
- package/src/clearingHouseUserStatsConfig.ts +0 -18
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.AdminClient = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const types_1 = require("./types");
|
|
29
29
|
const userName_1 = require("./userName");
|
|
@@ -32,24 +32,24 @@ const anchor = __importStar(require("@project-serum/anchor"));
|
|
|
32
32
|
const pda_1 = require("./addresses/pda");
|
|
33
33
|
const utils_1 = require("./math/utils");
|
|
34
34
|
const spl_token_1 = require("@solana/spl-token");
|
|
35
|
-
const
|
|
35
|
+
const driftClient_1 = require("./driftClient");
|
|
36
36
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
37
37
|
const trade_1 = require("./math/trade");
|
|
38
38
|
const amm_1 = require("./math/amm");
|
|
39
|
-
class
|
|
39
|
+
class AdminClient extends driftClient_1.DriftClient {
|
|
40
40
|
async initialize(usdcMint, _adminControlsPrices) {
|
|
41
41
|
const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
|
|
42
42
|
if (stateAccountRPCResponse.value !== null) {
|
|
43
43
|
throw new Error('Clearing house already initialized');
|
|
44
44
|
}
|
|
45
|
-
const [
|
|
45
|
+
const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
|
|
46
46
|
const initializeTx = await this.program.transaction.initialize({
|
|
47
47
|
accounts: {
|
|
48
48
|
admin: this.wallet.publicKey,
|
|
49
|
-
state:
|
|
49
|
+
state: driftStatePublicKey,
|
|
50
50
|
quoteAssetMint: usdcMint,
|
|
51
51
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
52
|
-
|
|
52
|
+
driftSigner: this.getSignerPublicKey(),
|
|
53
53
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
54
54
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
55
55
|
},
|
|
@@ -57,19 +57,20 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
57
57
|
const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
58
58
|
return [initializeTxSig];
|
|
59
59
|
}
|
|
60
|
-
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0,
|
|
60
|
+
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
61
61
|
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
62
62
|
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
63
63
|
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
64
64
|
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
65
|
-
const
|
|
65
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
66
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
|
|
66
67
|
accounts: {
|
|
67
68
|
admin: this.wallet.publicKey,
|
|
68
69
|
state: await this.getStatePublicKey(),
|
|
69
70
|
spotMarket,
|
|
70
71
|
spotMarketVault,
|
|
71
72
|
insuranceFundVault,
|
|
72
|
-
|
|
73
|
+
driftSigner: this.getSignerPublicKey(),
|
|
73
74
|
spotMarketMint: mint,
|
|
74
75
|
oracle,
|
|
75
76
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
@@ -94,7 +95,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
94
95
|
state: await this.getStatePublicKey(),
|
|
95
96
|
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
96
97
|
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
97
|
-
|
|
98
|
+
driftSigner: this.getSignerPublicKey(),
|
|
98
99
|
serumProgram,
|
|
99
100
|
serumMarket,
|
|
100
101
|
serumOpenOrders,
|
|
@@ -104,10 +105,10 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500,
|
|
108
|
+
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
108
109
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
|
|
109
110
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
110
|
-
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance,
|
|
111
|
+
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
111
112
|
accounts: {
|
|
112
113
|
state: await this.getStatePublicKey(),
|
|
113
114
|
admin: this.wallet.publicKey,
|
|
@@ -215,7 +216,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
215
216
|
state: await this.getStatePublicKey(),
|
|
216
217
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
217
218
|
sourceVault,
|
|
218
|
-
|
|
219
|
+
driftSigner: this.getSignerPublicKey(),
|
|
219
220
|
quoteSpotMarket: spotMarket.pubkey,
|
|
220
221
|
spotMarketVault: spotMarket.vault,
|
|
221
222
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -250,6 +251,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
250
251
|
},
|
|
251
252
|
});
|
|
252
253
|
}
|
|
254
|
+
async updatePerpMarketImfFactor(perpMarketIndex, imfFactor, unrealizedPnlImfFactor) {
|
|
255
|
+
return await this.program.rpc.updatePerpMarketImfFactor(imfFactor, unrealizedPnlImfFactor, {
|
|
256
|
+
accounts: {
|
|
257
|
+
admin: this.wallet.publicKey,
|
|
258
|
+
state: await this.getStatePublicKey(),
|
|
259
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
}
|
|
253
263
|
async updatePerpMarketBaseSpread(perpMarketIndex, baseSpread) {
|
|
254
264
|
return await this.program.rpc.updatePerpMarketBaseSpread(baseSpread, {
|
|
255
265
|
accounts: {
|
|
@@ -278,6 +288,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
278
288
|
},
|
|
279
289
|
});
|
|
280
290
|
}
|
|
291
|
+
async updateSpotMarketName(spotMarketIndex, name) {
|
|
292
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
293
|
+
return await this.program.rpc.updateSpotMarketName(nameBuffer, {
|
|
294
|
+
accounts: {
|
|
295
|
+
admin: this.wallet.publicKey,
|
|
296
|
+
state: await this.getStatePublicKey(),
|
|
297
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
281
301
|
async updatePerpMarketMaxSpread(perpMarketIndex, maxSpread) {
|
|
282
302
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
283
303
|
return await this.program.rpc.updatePerpMarketMaxSpread(maxSpread, {
|
|
@@ -401,6 +421,24 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
401
421
|
},
|
|
402
422
|
});
|
|
403
423
|
}
|
|
424
|
+
async updateSpotMarketStepSizeAndTickSize(spotMarketIndex, stepSize, tickSize) {
|
|
425
|
+
return await this.program.rpc.updateSpotMarketStepSizeAndTickSize(stepSize, tickSize, {
|
|
426
|
+
accounts: {
|
|
427
|
+
admin: this.wallet.publicKey,
|
|
428
|
+
state: await this.getStatePublicKey(),
|
|
429
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
async updateSpotMarketMinOrderSize(spotMarketIndex, orderSize) {
|
|
434
|
+
return await this.program.rpc.updateSpotMarketMinOrderSize(orderSize, {
|
|
435
|
+
accounts: {
|
|
436
|
+
admin: this.wallet.publicKey,
|
|
437
|
+
state: await this.getStatePublicKey(),
|
|
438
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
439
|
+
},
|
|
440
|
+
});
|
|
441
|
+
}
|
|
404
442
|
async updatePerpMarketExpiry(perpMarketIndex, expiryTs) {
|
|
405
443
|
return await this.program.rpc.updatePerpMarketExpiry(expiryTs, {
|
|
406
444
|
accounts: {
|
|
@@ -454,6 +492,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
454
492
|
},
|
|
455
493
|
});
|
|
456
494
|
}
|
|
495
|
+
async updateSpotMarketBorrowRate(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate) {
|
|
496
|
+
return await this.program.rpc.updateSpotMarketBorrowRate(optimalUtilization, optimalBorrowRate, optimalMaxRate, {
|
|
497
|
+
accounts: {
|
|
498
|
+
admin: this.wallet.publicKey,
|
|
499
|
+
state: await this.getStatePublicKey(),
|
|
500
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
}
|
|
457
504
|
async updateSpotMarketAssetTier(spotMarketIndex, assetTier) {
|
|
458
505
|
return await this.program.rpc.updateSpotMarketAssetTier(assetTier, {
|
|
459
506
|
accounts: {
|
|
@@ -519,7 +566,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
519
566
|
accounts: {
|
|
520
567
|
admin: this.wallet.publicKey,
|
|
521
568
|
state: await this.getStatePublicKey(),
|
|
522
|
-
perpMarket: this.
|
|
569
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
523
570
|
},
|
|
524
571
|
});
|
|
525
572
|
}
|
|
@@ -532,6 +579,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
532
579
|
},
|
|
533
580
|
});
|
|
534
581
|
}
|
|
582
|
+
async updatePerpMarketUnrealizedAssetWeight(perpMarketIndex, unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight) {
|
|
583
|
+
return await this.program.rpc.updatePerpMarketUnrealizedAssetWeight(unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight, {
|
|
584
|
+
accounts: {
|
|
585
|
+
admin: this.wallet.publicKey,
|
|
586
|
+
state: await this.getStatePublicKey(),
|
|
587
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
}
|
|
535
591
|
async updatePerpMarketMaxImbalances(perpMarketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
|
|
536
592
|
return await this.program.rpc.updatePerpMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
|
|
537
593
|
accounts: {
|
|
@@ -559,5 +615,23 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
559
615
|
},
|
|
560
616
|
});
|
|
561
617
|
}
|
|
618
|
+
async updatePerpMarketLiquidationFee(perpMarketIndex, liquidatorFee, ifLiquidationFee) {
|
|
619
|
+
return await this.program.rpc.updatePerpMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
|
|
620
|
+
accounts: {
|
|
621
|
+
admin: this.wallet.publicKey,
|
|
622
|
+
state: await this.getStatePublicKey(),
|
|
623
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
async updateSpotMarketLiquidationFee(spotMarketIndex, liquidatorFee, ifLiquidationFee) {
|
|
628
|
+
return await this.program.rpc.updateSpotMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
|
|
629
|
+
accounts: {
|
|
630
|
+
admin: this.wallet.publicKey,
|
|
631
|
+
state: await this.getStatePublicKey(),
|
|
632
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
}
|
|
562
636
|
}
|
|
563
|
-
exports.
|
|
637
|
+
exports.AdminClient = AdminClient;
|
package/lib/config.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.configs = {
|
|
|
7
7
|
devnet: {
|
|
8
8
|
ENV: 'devnet',
|
|
9
9
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
10
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
10
|
+
CLEARING_HOUSE_PROGRAM_ID: 'H4G1xzAoqSW8n1Edmeowqsgc895tSNCeDPafYjv4Md7i',
|
|
11
11
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
12
12
|
SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
|
|
13
13
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
@@ -15,6 +15,9 @@ export declare const TEN_THOUSAND: BN;
|
|
|
15
15
|
export declare const BN_MAX: BN;
|
|
16
16
|
export declare const TEN_MILLION: BN;
|
|
17
17
|
export declare const MAX_LEVERAGE: BN;
|
|
18
|
+
export declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
19
|
+
export declare const PERCENTAGE_PRECISION: BN;
|
|
20
|
+
export declare const CONCENTRATION_PRECISION: BN;
|
|
18
21
|
export declare const QUOTE_PRECISION_EXP: BN;
|
|
19
22
|
export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
|
|
20
23
|
export declare const PRICE_PRECISION_EXP: BN;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.LAMPORTS_EXP = void 0;
|
|
3
|
+
exports.BID_ASK_SPREAD_PRECISION = exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.PRICE_DIV_PEG = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_RATE_BUFFER_PRECISION = exports.FUNDING_RATE_PRECISION = exports.PRICE_PRECISION = exports.QUOTE_PRECISION = exports.LIQUIDATION_FEE_PRECISION = exports.SPOT_MARKET_IMF_PRECISION = exports.SPOT_MARKET_IMF_PRECISION_EXP = exports.SPOT_MARKET_BALANCE_PRECISION = exports.SPOT_MARKET_BALANCE_PRECISION_EXP = exports.SPOT_MARKET_WEIGHT_PRECISION = exports.SPOT_MARKET_UTILIZATION_PRECISION = exports.SPOT_MARKET_UTILIZATION_PRECISION_EXP = exports.SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION = exports.SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP = exports.SPOT_MARKET_RATE_PRECISION = exports.SPOT_MARKET_RATE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.PRICE_PRECISION_EXP = exports.FUNDING_RATE_BUFFER_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.CONCENTRATION_PRECISION = exports.PERCENTAGE_PRECISION = exports.PERCENTAGE_PRECISION_EXP = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.NINE = exports.EIGHT = exports.SEVEN = exports.SIX = exports.FIVE = exports.FOUR = exports.THREE = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
4
|
+
exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const __1 = require("../");
|
|
7
7
|
exports.ZERO = new __1.BN(0);
|
|
@@ -19,6 +19,9 @@ exports.TEN_THOUSAND = new __1.BN(10000);
|
|
|
19
19
|
exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
|
|
20
20
|
exports.TEN_MILLION = exports.TEN_THOUSAND.mul(exports.TEN_THOUSAND);
|
|
21
21
|
exports.MAX_LEVERAGE = new __1.BN(5);
|
|
22
|
+
exports.PERCENTAGE_PRECISION_EXP = new __1.BN(6);
|
|
23
|
+
exports.PERCENTAGE_PRECISION = new __1.BN(10).pow(exports.PERCENTAGE_PRECISION_EXP);
|
|
24
|
+
exports.CONCENTRATION_PRECISION = exports.PERCENTAGE_PRECISION;
|
|
22
25
|
exports.QUOTE_PRECISION_EXP = new __1.BN(6);
|
|
23
26
|
exports.FUNDING_RATE_BUFFER_PRECISION_EXP = new __1.BN(3);
|
|
24
27
|
exports.PRICE_PRECISION_EXP = new __1.BN(6);
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { NodeList } from './NodeList';
|
|
3
|
-
import { MarketType, BN,
|
|
3
|
+
import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, UserMapInterface, MarketTypeStr, StateAccount } from '..';
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { DLOBNode, TriggerOrderNode } from '..';
|
|
6
6
|
export declare type MarketNodeLists = {
|
|
@@ -77,6 +77,6 @@ export declare class DLOB {
|
|
|
77
77
|
getBestAsk(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
78
78
|
getBestBid(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): BN;
|
|
79
79
|
findNodesToTrigger(marketIndex: number, slot: number, oraclePrice: BN, marketType: MarketType): NodeToTrigger[];
|
|
80
|
-
printTopOfOrderLists(sdkConfig: any,
|
|
80
|
+
printTopOfOrderLists(sdkConfig: any, driftClient: DriftClient, slotSubscriber: SlotSubscriber, marketIndex: number, marketType: MarketType): void;
|
|
81
81
|
}
|
|
82
82
|
export {};
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -649,11 +649,11 @@ class DLOB {
|
|
|
649
649
|
}
|
|
650
650
|
return nodesToTrigger;
|
|
651
651
|
}
|
|
652
|
-
printTopOfOrderLists(sdkConfig,
|
|
652
|
+
printTopOfOrderLists(sdkConfig, driftClient, slotSubscriber, marketIndex, marketType) {
|
|
653
653
|
if ((0, __1.isVariant)(marketType, 'perp')) {
|
|
654
|
-
const market =
|
|
654
|
+
const market = driftClient.getPerpMarketAccount(marketIndex);
|
|
655
655
|
const slot = slotSubscriber.getSlot();
|
|
656
|
-
const oraclePriceData =
|
|
656
|
+
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
657
657
|
const fallbackAsk = (0, __1.calculateAskPrice)(market, oraclePriceData);
|
|
658
658
|
const fallbackBid = (0, __1.calculateBidPrice)(market, oraclePriceData);
|
|
659
659
|
const bestAsk = this.getBestAsk(marketIndex, fallbackAsk, slot, marketType, oraclePriceData);
|
|
@@ -674,7 +674,7 @@ class DLOB {
|
|
|
674
674
|
}
|
|
675
675
|
else if ((0, __1.isVariant)(marketType, 'spot')) {
|
|
676
676
|
const slot = slotSubscriber.getSlot();
|
|
677
|
-
const oraclePriceData =
|
|
677
|
+
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
678
678
|
const bestAsk = this.getBestAsk(marketIndex, undefined, slot, marketType, oraclePriceData);
|
|
679
679
|
const bestBid = this.getBestBid(marketIndex, undefined, slot, marketType, oraclePriceData);
|
|
680
680
|
const mid = bestAsk.add(bestBid).div(new __1.BN(2));
|
|
@@ -7,13 +7,13 @@ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transactio
|
|
|
7
7
|
import { TokenFaucet } from './tokenFaucet';
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
|
-
import {
|
|
10
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './accounts/types';
|
|
11
11
|
import { TxSender } from './tx/types';
|
|
12
12
|
import { OraclePriceData } from './oracles/types';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { DriftClientConfig } from './driftClientConfig';
|
|
14
|
+
import { User } from './user';
|
|
15
|
+
import { UserSubscriptionConfig } from './userConfig';
|
|
16
|
+
import { UserStats } from './userStats';
|
|
17
17
|
declare type RemainingAccountParams = {
|
|
18
18
|
userAccounts: UserAccount[];
|
|
19
19
|
writablePerpMarketIndexes?: number[];
|
|
@@ -23,21 +23,21 @@ declare type RemainingAccountParams = {
|
|
|
23
23
|
useMarketLastSlotCache?: boolean;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* #
|
|
26
|
+
* # DriftClient
|
|
27
27
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
28
28
|
*/
|
|
29
|
-
export declare class
|
|
29
|
+
export declare class DriftClient {
|
|
30
30
|
connection: Connection;
|
|
31
31
|
wallet: IWallet;
|
|
32
32
|
program: Program;
|
|
33
33
|
provider: AnchorProvider;
|
|
34
34
|
opts?: ConfirmOptions;
|
|
35
|
-
users: Map<number,
|
|
36
|
-
userStats?:
|
|
35
|
+
users: Map<number, User>;
|
|
36
|
+
userStats?: UserStats;
|
|
37
37
|
activeSubAccountId: number;
|
|
38
|
-
userAccountSubscriptionConfig:
|
|
39
|
-
accountSubscriber:
|
|
40
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
38
|
+
userAccountSubscriptionConfig: UserSubscriptionConfig;
|
|
39
|
+
accountSubscriber: DriftClientAccountSubscriber;
|
|
40
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
41
41
|
_isSubscribed: boolean;
|
|
42
42
|
txSender: TxSender;
|
|
43
43
|
perpMarketLastSlotCache: Map<number, number>;
|
|
@@ -45,9 +45,9 @@ export declare class ClearingHouse {
|
|
|
45
45
|
authority: PublicKey;
|
|
46
46
|
get isSubscribed(): boolean;
|
|
47
47
|
set isSubscribed(val: boolean);
|
|
48
|
-
constructor(config:
|
|
49
|
-
createUsers(subAccountIds: number[], accountSubscriptionConfig:
|
|
50
|
-
createUser(subAccountId: number, accountSubscriptionConfig:
|
|
48
|
+
constructor(config: DriftClientConfig);
|
|
49
|
+
createUsers(subAccountIds: number[], accountSubscriptionConfig: UserSubscriptionConfig): void;
|
|
50
|
+
createUser(subAccountId: number, accountSubscriptionConfig: UserSubscriptionConfig): User;
|
|
51
51
|
subscribe(): Promise<boolean>;
|
|
52
52
|
subscribeUsers(): Promise<boolean>[];
|
|
53
53
|
/**
|
|
@@ -69,7 +69,7 @@ export declare class ClearingHouse {
|
|
|
69
69
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
70
70
|
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
71
71
|
/**
|
|
72
|
-
* Update the wallet to use for
|
|
72
|
+
* Update the wallet to use for drift transactions and linked user account
|
|
73
73
|
* @param newWallet
|
|
74
74
|
* @param subAccountIds
|
|
75
75
|
* @param activeSubAccountId
|
|
@@ -85,9 +85,9 @@ export declare class ClearingHouse {
|
|
|
85
85
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
86
86
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
87
87
|
deleteUser(subAccountId?: number): Promise<TransactionSignature>;
|
|
88
|
-
getUser(subAccountId?: number):
|
|
89
|
-
getUsers():
|
|
90
|
-
getUserStats():
|
|
88
|
+
getUser(subAccountId?: number): User;
|
|
89
|
+
getUsers(): User[];
|
|
90
|
+
getUserStats(): UserStats;
|
|
91
91
|
userStatsAccountPublicKey: PublicKey;
|
|
92
92
|
getUserStatsAccountPublicKey(): PublicKey;
|
|
93
93
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
@@ -168,6 +168,7 @@ export declare class ClearingHouse {
|
|
|
168
168
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
169
169
|
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
170
170
|
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
171
|
+
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
|
|
171
172
|
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
172
173
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
173
174
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
@@ -216,7 +217,7 @@ export declare class ClearingHouse {
|
|
|
216
217
|
getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
|
|
217
218
|
settleFundingPayment(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
218
219
|
getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
219
|
-
triggerEvent(eventName: keyof
|
|
220
|
+
triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
|
|
220
221
|
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
|
|
221
222
|
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
222
223
|
initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|