@drift-labs/sdk 2.145.0 → 2.146.0-alpha.13
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/.env +4 -0
- package/VERSION +1 -1
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +8 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/browser/adminClient.d.ts +5 -1
- package/lib/browser/adminClient.js +57 -23
- package/lib/browser/constants/numericConstants.d.ts +2 -0
- package/lib/browser/constants/numericConstants.js +5 -1
- package/lib/browser/constants/perpMarkets.js +0 -2
- package/lib/browser/decode/user.js +4 -0
- package/lib/browser/driftClient.d.ts +25 -10
- package/lib/browser/driftClient.js +238 -41
- package/lib/browser/driftClientConfig.d.ts +7 -2
- package/lib/browser/idl/drift.json +245 -22
- package/lib/browser/index.d.ts +4 -0
- package/lib/browser/index.js +9 -1
- package/lib/browser/marginCalculation.d.ts +86 -0
- package/lib/browser/marginCalculation.js +209 -0
- package/lib/browser/math/margin.d.ts +1 -1
- package/lib/browser/math/margin.js +8 -1
- package/lib/browser/math/position.d.ts +1 -0
- package/lib/browser/math/position.js +10 -2
- package/lib/browser/math/spotPosition.d.ts +1 -1
- package/lib/browser/math/spotPosition.js +3 -2
- package/lib/browser/math/superStake.d.ts +3 -2
- package/lib/browser/types.d.ts +13 -0
- package/lib/browser/types.js +12 -1
- package/lib/browser/user.d.ts +59 -11
- package/lib/browser/user.js +348 -43
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +8 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/node/adminClient.d.ts +5 -1
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +57 -23
- package/lib/node/constants/numericConstants.d.ts +2 -0
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +5 -1
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +0 -2
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +4 -0
- package/lib/node/driftClient.d.ts +25 -10
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +238 -41
- package/lib/node/driftClientConfig.d.ts +7 -2
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/idl/drift.json +245 -22
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +9 -1
- package/lib/node/marginCalculation.d.ts +87 -0
- package/lib/node/marginCalculation.d.ts.map +1 -0
- package/lib/node/marginCalculation.js +209 -0
- package/lib/node/math/margin.d.ts +1 -1
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +8 -1
- package/lib/node/math/position.d.ts +1 -0
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +10 -2
- package/lib/node/math/spotPosition.d.ts +1 -1
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/spotPosition.js +3 -2
- package/lib/node/math/superStake.d.ts +3 -2
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/types.d.ts +13 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +12 -1
- package/lib/node/user.d.ts +59 -11
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +348 -43
- package/package.json +1 -1
- package/scripts/deposit-isolated-positions.ts +110 -0
- package/scripts/single-grpc-client-test.ts +71 -21
- package/scripts/withdraw-isolated-positions.ts +174 -0
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +8 -1
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +566 -167
- package/src/adminClient.ts +74 -25
- package/src/constants/numericConstants.ts +5 -0
- package/src/constants/perpMarkets.ts +0 -3
- package/src/decode/user.ts +7 -1
- package/src/driftClient.ts +465 -52
- package/src/driftClientConfig.ts +15 -8
- package/src/idl/drift.json +246 -23
- package/src/index.ts +4 -0
- package/src/margin/README.md +143 -0
- package/src/marginCalculation.ts +306 -0
- package/src/math/margin.ts +13 -1
- package/src/math/position.ts +12 -2
- package/src/math/spotPosition.ts +6 -2
- package/src/types.ts +16 -0
- package/src/user.ts +623 -81
- package/tests/amm/test.ts +1 -1
- package/tests/dlob/helpers.ts +6 -3
- package/tests/user/getMarginCalculation.ts +405 -0
- package/tests/user/test.ts +0 -7
|
@@ -22,9 +22,13 @@ export declare class AdminClient extends DriftClient {
|
|
|
22
22
|
initializeOpenbookV2FulfillmentConfig(marketIndex: number, openbookMarket: PublicKey): Promise<TransactionSignature>;
|
|
23
23
|
getInitializeOpenbookV2FulfillmentConfigIx(marketIndex: number, openbookMarket: PublicKey): Promise<TransactionInstruction>;
|
|
24
24
|
initializePerpMarket(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, contractTier?: ContractTier, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, ifLiquidatorFee?: number, imfFactor?: number, activeStatus?: boolean, baseSpread?: number, maxSpread?: number, maxOpenInterest?: BN, maxRevenueWithdrawPerPeriod?: BN, quoteMaxInsurance?: BN, orderStepSize?: BN, orderTickSize?: BN, minOrderSize?: BN, concentrationCoefScale?: BN, curveUpdateIntensity?: number, ammJitIntensity?: number, name?: string, lpPoolId?: number): Promise<TransactionSignature>;
|
|
25
|
-
getInitializePerpMarketIx(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, contractTier?: ContractTier, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, ifLiquidatorFee?: number, imfFactor?: number, activeStatus?: boolean, baseSpread?: number, maxSpread?: number, maxOpenInterest?: BN, maxRevenueWithdrawPerPeriod?: BN, quoteMaxInsurance?: BN, orderStepSize?: BN, orderTickSize?: BN, minOrderSize?: BN, concentrationCoefScale?: BN, curveUpdateIntensity?: number, ammJitIntensity?: number, name?: string,
|
|
25
|
+
getInitializePerpMarketIx(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, contractTier?: ContractTier, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, ifLiquidatorFee?: number, imfFactor?: number, activeStatus?: boolean, baseSpread?: number, maxSpread?: number, maxOpenInterest?: BN, maxRevenueWithdrawPerPeriod?: BN, quoteMaxInsurance?: BN, orderStepSize?: BN, orderTickSize?: BN, minOrderSize?: BN, concentrationCoefScale?: BN, curveUpdateIntensity?: number, ammJitIntensity?: number, name?: string, lpPoolId?: number, includeInitAmmCacheIx?: boolean): Promise<TransactionInstruction[]>;
|
|
26
26
|
initializeAmmCache(txParams?: TxParams): Promise<TransactionSignature>;
|
|
27
27
|
getInitializeAmmCacheIx(): Promise<TransactionInstruction>;
|
|
28
|
+
resizeAmmCache(txParams?: TxParams): Promise<TransactionSignature>;
|
|
29
|
+
getResizeAmmCacheIx(): Promise<TransactionInstruction>;
|
|
30
|
+
deleteAmmCache(txParams?: TxParams): Promise<TransactionSignature>;
|
|
31
|
+
getDeleteAmmCacheIx(): Promise<TransactionInstruction>;
|
|
28
32
|
updateInitialAmmCacheInfo(perpMarketIndexes: number[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
29
33
|
getUpdateInitialAmmCacheInfoIx(perpMarketIndexes: number[]): Promise<TransactionInstruction>;
|
|
30
34
|
overrideAmmCacheInfo(perpMarketIndex: number, params: {
|
|
@@ -210,7 +210,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
210
210
|
const ammCachePublicKey = (0, pda_1.getAmmCachePublicKey)(this.program.programId);
|
|
211
211
|
const ammCacheAccount = await this.connection.getAccountInfo(ammCachePublicKey);
|
|
212
212
|
const mustInitializeAmmCache = (ammCacheAccount === null || ammCacheAccount === void 0 ? void 0 : ammCacheAccount.data) == null;
|
|
213
|
-
const initializeMarketIxs = await this.getInitializePerpMarketIx(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, contractTier, marginRatioInitial, marginRatioMaintenance, liquidatorFee, ifLiquidatorFee, imfFactor, activeStatus, baseSpread, maxSpread, maxOpenInterest, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, orderStepSize, orderTickSize, minOrderSize, concentrationCoefScale, curveUpdateIntensity, ammJitIntensity, name,
|
|
213
|
+
const initializeMarketIxs = await this.getInitializePerpMarketIx(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, contractTier, marginRatioInitial, marginRatioMaintenance, liquidatorFee, ifLiquidatorFee, imfFactor, activeStatus, baseSpread, maxSpread, maxOpenInterest, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, orderStepSize, orderTickSize, minOrderSize, concentrationCoefScale, curveUpdateIntensity, ammJitIntensity, name, lpPoolId, mustInitializeAmmCache);
|
|
214
214
|
const tx = await this.buildTransaction(initializeMarketIxs);
|
|
215
215
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
216
216
|
while (this.getStateAccount().numberOfMarkets <= currentPerpMarketIndex) {
|
|
@@ -224,7 +224,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
224
224
|
await this.accountSubscriber.setPerpOracleMap();
|
|
225
225
|
return txSig;
|
|
226
226
|
}
|
|
227
|
-
async getInitializePerpMarketIx(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, contractTier = types_1.ContractTier.SPECULATIVE, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, ifLiquidatorFee = 10000, imfFactor = 0, activeStatus = true, baseSpread = 0, maxSpread = 142500, maxOpenInterest = numericConstants_1.ZERO, maxRevenueWithdrawPerPeriod = numericConstants_1.ZERO, quoteMaxInsurance = numericConstants_1.ZERO, orderStepSize = numericConstants_1.BASE_PRECISION.divn(10000), orderTickSize = numericConstants_1.PRICE_PRECISION.divn(100000), minOrderSize = numericConstants_1.BASE_PRECISION.divn(10000), concentrationCoefScale = numericConstants_1.ONE, curveUpdateIntensity = 0, ammJitIntensity = 0, name = userName_1.DEFAULT_MARKET_NAME,
|
|
227
|
+
async getInitializePerpMarketIx(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, contractTier = types_1.ContractTier.SPECULATIVE, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, ifLiquidatorFee = 10000, imfFactor = 0, activeStatus = true, baseSpread = 0, maxSpread = 142500, maxOpenInterest = numericConstants_1.ZERO, maxRevenueWithdrawPerPeriod = numericConstants_1.ZERO, quoteMaxInsurance = numericConstants_1.ZERO, orderStepSize = numericConstants_1.BASE_PRECISION.divn(10000), orderTickSize = numericConstants_1.PRICE_PRECISION.divn(100000), minOrderSize = numericConstants_1.BASE_PRECISION.divn(10000), concentrationCoefScale = numericConstants_1.ONE, curveUpdateIntensity = 0, ammJitIntensity = 0, name = userName_1.DEFAULT_MARKET_NAME, lpPoolId = 0, includeInitAmmCacheIx = false) {
|
|
228
228
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
229
229
|
const ixs = [];
|
|
230
230
|
if (includeInitAmmCacheIx) {
|
|
@@ -257,15 +257,49 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
257
257
|
return await this.program.instruction.initializeAmmCache({
|
|
258
258
|
accounts: {
|
|
259
259
|
state: await this.getStatePublicKey(),
|
|
260
|
-
admin: this.
|
|
261
|
-
? this.
|
|
262
|
-
: this.
|
|
260
|
+
admin: this.useHotWalletAdmin
|
|
261
|
+
? this.wallet.publicKey
|
|
262
|
+
: this.getStateAccount().admin,
|
|
263
263
|
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
264
264
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
265
265
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
266
266
|
},
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
|
+
async resizeAmmCache(txParams) {
|
|
270
|
+
const initializeAmmCacheIx = await this.getResizeAmmCacheIx();
|
|
271
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
272
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
273
|
+
return txSig;
|
|
274
|
+
}
|
|
275
|
+
async getResizeAmmCacheIx() {
|
|
276
|
+
return await this.program.instruction.resizeAmmCache({
|
|
277
|
+
accounts: {
|
|
278
|
+
state: await this.getStatePublicKey(),
|
|
279
|
+
admin: this.useHotWalletAdmin
|
|
280
|
+
? this.wallet.publicKey
|
|
281
|
+
: this.getStateAccount().admin,
|
|
282
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
283
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
284
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async deleteAmmCache(txParams) {
|
|
289
|
+
const deleteAmmCacheIx = await this.getDeleteAmmCacheIx();
|
|
290
|
+
const tx = await this.buildTransaction(deleteAmmCacheIx, txParams);
|
|
291
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
292
|
+
return txSig;
|
|
293
|
+
}
|
|
294
|
+
async getDeleteAmmCacheIx() {
|
|
295
|
+
return await this.program.instruction.deleteAmmCache({
|
|
296
|
+
accounts: {
|
|
297
|
+
state: await this.getStatePublicKey(),
|
|
298
|
+
admin: this.getStateAccount().admin,
|
|
299
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
}
|
|
269
303
|
async updateInitialAmmCacheInfo(perpMarketIndexes, txParams) {
|
|
270
304
|
const initializeAmmCacheIx = await this.getUpdateInitialAmmCacheInfoIx(perpMarketIndexes);
|
|
271
305
|
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
@@ -281,9 +315,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
281
315
|
return await this.program.instruction.updateInitialAmmCacheInfo({
|
|
282
316
|
accounts: {
|
|
283
317
|
state: await this.getStatePublicKey(),
|
|
284
|
-
admin: this.
|
|
285
|
-
? this.
|
|
286
|
-
: this.
|
|
318
|
+
admin: this.useHotWalletAdmin
|
|
319
|
+
? this.wallet.publicKey
|
|
320
|
+
: this.getStateAccount().admin,
|
|
287
321
|
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
288
322
|
},
|
|
289
323
|
remainingAccounts,
|
|
@@ -306,9 +340,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
306
340
|
}, params), {
|
|
307
341
|
accounts: {
|
|
308
342
|
state: await this.getStatePublicKey(),
|
|
309
|
-
admin: this.
|
|
310
|
-
? this.
|
|
311
|
-
: this.
|
|
343
|
+
admin: this.useHotWalletAdmin
|
|
344
|
+
? this.wallet.publicKey
|
|
345
|
+
: this.getStateAccount().admin,
|
|
312
346
|
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
313
347
|
},
|
|
314
348
|
});
|
|
@@ -323,9 +357,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
323
357
|
return this.program.instruction.resetAmmCache({
|
|
324
358
|
accounts: {
|
|
325
359
|
state: await this.getStatePublicKey(),
|
|
326
|
-
admin: this.
|
|
327
|
-
? this.
|
|
328
|
-
: this.
|
|
360
|
+
admin: this.useHotWalletAdmin
|
|
361
|
+
? this.wallet.publicKey
|
|
362
|
+
: this.getStateAccount().admin,
|
|
329
363
|
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
330
364
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
331
365
|
},
|
|
@@ -2582,9 +2616,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
2582
2616
|
return await this.program.instruction.updateConstituentPausedOperations(pausedOperations, {
|
|
2583
2617
|
accounts: {
|
|
2584
2618
|
constituent,
|
|
2585
|
-
admin: this.
|
|
2586
|
-
? this.
|
|
2587
|
-
: this.
|
|
2619
|
+
admin: this.useHotWalletAdmin
|
|
2620
|
+
? this.wallet.publicKey
|
|
2621
|
+
: this.getStateAccount().admin,
|
|
2588
2622
|
state: await this.getStatePublicKey(),
|
|
2589
2623
|
},
|
|
2590
2624
|
});
|
|
@@ -2977,9 +3011,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
2977
3011
|
async getUpdatePerpMarketLpPoolFeeTransferScalarIx(marketIndex, lpFeeTransferScalar, lpExchangeFeeExcluscionScalar) {
|
|
2978
3012
|
return this.program.instruction.updatePerpMarketLpPoolFeeTransferScalar(lpFeeTransferScalar !== null && lpFeeTransferScalar !== void 0 ? lpFeeTransferScalar : null, lpExchangeFeeExcluscionScalar !== null && lpExchangeFeeExcluscionScalar !== void 0 ? lpExchangeFeeExcluscionScalar : null, {
|
|
2979
3013
|
accounts: {
|
|
2980
|
-
admin: this.
|
|
2981
|
-
? this.
|
|
2982
|
-
: this.
|
|
3014
|
+
admin: this.useHotWalletAdmin
|
|
3015
|
+
? this.wallet.publicKey
|
|
3016
|
+
: this.getStateAccount().admin,
|
|
2983
3017
|
state: await this.getStatePublicKey(),
|
|
2984
3018
|
perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
2985
3019
|
},
|
|
@@ -2994,9 +3028,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
2994
3028
|
async getUpdatePerpMarketLpPoolPausedOperationsIx(marketIndex, pausedOperations) {
|
|
2995
3029
|
return this.program.instruction.updatePerpMarketLpPoolPausedOperations(pausedOperations, {
|
|
2996
3030
|
accounts: {
|
|
2997
|
-
admin: this.
|
|
2998
|
-
? this.
|
|
2999
|
-
: this.
|
|
3031
|
+
admin: this.useHotWalletAdmin
|
|
3032
|
+
? this.wallet.publicKey
|
|
3033
|
+
: this.getStateAccount().admin,
|
|
3000
3034
|
state: await this.getStatePublicKey(),
|
|
3001
3035
|
perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
3002
3036
|
},
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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_ORDER_SIZE = 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.GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = exports.MAX_PREDICTION_PRICE = exports.FUEL_START_TS = exports.FUEL_WINDOW = exports.DUST_POSITION_SIZE = exports.SLOT_TIME_ESTIMATE_MS = exports.IDLE_TIME_SLOTS = exports.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS = exports.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.GOV_SPOT_MARKET_INDEX = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.PRICE_TIMES_AMM_TO_QUOTE_PRECISION_RATIO = exports.FUNDING_RATE_OFFSET_DENOMINATOR = exports.LIQUIDATION_PCT_PRECISION = exports.BID_ASK_SPREAD_PRECISION = void 0;
|
|
4
|
+
exports.MIN_I64 = exports.MAX_I64 = exports.GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = exports.MAX_PREDICTION_PRICE = exports.FUEL_START_TS = exports.FUEL_WINDOW = exports.DUST_POSITION_SIZE = exports.SLOT_TIME_ESTIMATE_MS = exports.IDLE_TIME_SLOTS = exports.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS = exports.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.GOV_SPOT_MARKET_INDEX = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.PRICE_TIMES_AMM_TO_QUOTE_PRECISION_RATIO = exports.FUNDING_RATE_OFFSET_DENOMINATOR = exports.LIQUIDATION_PCT_PRECISION = exports.BID_ASK_SPREAD_PRECISION = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
const bigNum_1 = require("../factory/bigNum");
|
|
7
8
|
exports.ZERO = new anchor_1.BN(0);
|
|
8
9
|
exports.ONE = new anchor_1.BN(1);
|
|
9
10
|
exports.TWO = new anchor_1.BN(2);
|
|
@@ -75,3 +76,6 @@ exports.FUEL_WINDOW = new anchor_1.BN(60 * 60 * 24 * 28); // 28 days
|
|
|
75
76
|
exports.FUEL_START_TS = new anchor_1.BN(1723147200); // unix timestamp
|
|
76
77
|
exports.MAX_PREDICTION_PRICE = exports.PRICE_PRECISION;
|
|
77
78
|
exports.GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = 99;
|
|
79
|
+
// integer constants
|
|
80
|
+
exports.MAX_I64 = bigNum_1.BigNum.fromPrint('9223372036854775807').val;
|
|
81
|
+
exports.MIN_I64 = bigNum_1.BigNum.fromPrint('-9223372036854775808').val;
|
|
@@ -1202,8 +1202,6 @@ exports.MainnetPerpMarkets = [
|
|
|
1202
1202
|
oracle: new web3_js_1.PublicKey('GAzR3C5cn7gGVvuqJB57wSYTPWP3n2Lw4mRJRxvTvqYy'),
|
|
1203
1203
|
launchTs: 1747318237000,
|
|
1204
1204
|
oracleSource: types_1.OracleSource.PYTH_LAZER,
|
|
1205
|
-
pythFeedId: '0x6d74813ee17291d5be18a355fe4d43fd300d625caea6554d49f740e7d112141e',
|
|
1206
|
-
pythLazerId: 1571,
|
|
1207
1205
|
},
|
|
1208
1206
|
{
|
|
1209
1207
|
fullName: 'PUMP',
|
|
@@ -71,6 +71,8 @@ function decodeUser(buffer) {
|
|
|
71
71
|
const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
|
|
72
72
|
const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
|
|
73
73
|
const openOrders = buffer.readUInt8(offset + 94);
|
|
74
|
+
const positionFlag = buffer.readUInt8(offset + 95);
|
|
75
|
+
const isolatedPositionScaledBalance = readUnsignedBigInt64LE(buffer, offset + 96);
|
|
74
76
|
if (baseAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
75
77
|
openOrders === 0 &&
|
|
76
78
|
quoteAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
@@ -117,6 +119,8 @@ function decodeUser(buffer) {
|
|
|
117
119
|
openOrders,
|
|
118
120
|
perLpBase,
|
|
119
121
|
maxMarginRatio,
|
|
122
|
+
positionFlag,
|
|
123
|
+
isolatedPositionScaledBalance,
|
|
120
124
|
});
|
|
121
125
|
}
|
|
122
126
|
const orders = [];
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as anchor from '@coral-xyz/anchor';
|
|
6
6
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
7
7
|
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
8
|
-
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SignedMsgOrderParamsMessage,
|
|
8
|
+
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SignedMsgOrderParamsMessage, TxParams, UserAccount, UserStatsAccount, ProtectedMakerModeConfig, SignedMsgOrderParamsDelegateMessage, PostOnlyParams, LPPoolAccount, ConstituentAccount, ConstituentTargetBaseAccount, AmmCache } from './types';
|
|
9
9
|
import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
10
10
|
import { TokenFaucet } from './tokenFaucet';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
@@ -26,6 +26,7 @@ import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/
|
|
|
26
26
|
import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
|
|
27
27
|
import { Slothash } from './slot/SlothashSubscriber';
|
|
28
28
|
import { SignedMsgOrderParams } from './types';
|
|
29
|
+
import { TakerInfo } from './types';
|
|
29
30
|
import { ConstituentMap } from './constituentMap/constituentMap';
|
|
30
31
|
import { RevenueShareEscrowMap } from './userMap/revenueShareEscrowMap';
|
|
31
32
|
import { TitanClient } from './titan/titanClient';
|
|
@@ -89,6 +90,7 @@ export declare class DriftClient {
|
|
|
89
90
|
sbOnDemandProgram?: Program30<Idl30>;
|
|
90
91
|
sbProgramFeedConfigs?: Map<string, any>;
|
|
91
92
|
get isSubscribed(): boolean;
|
|
93
|
+
private getPrePlaceOrderIxs;
|
|
92
94
|
set isSubscribed(val: boolean);
|
|
93
95
|
constructor(config: DriftClientConfig);
|
|
94
96
|
getUserMapKey(subAccountId: number, authority: PublicKey): string;
|
|
@@ -302,6 +304,7 @@ export declare class DriftClient {
|
|
|
302
304
|
getUserAccountAndSlot(subAccountId?: number, authority?: PublicKey): DataAndSlot<UserAccount> | undefined;
|
|
303
305
|
getSpotPosition(marketIndex: number, subAccountId?: number): SpotPosition | undefined;
|
|
304
306
|
getQuoteAssetTokenAmount(): BN;
|
|
307
|
+
getIsolatedPerpPositionTokenAmount(perpMarketIndex: number, subAccountId?: number): BN;
|
|
305
308
|
/**
|
|
306
309
|
* Returns the token amount for a given market. The spot market precision is based on the token mint decimals.
|
|
307
310
|
* Positive if it is a deposit, negative if it is a borrow.
|
|
@@ -433,6 +436,13 @@ export declare class DriftClient {
|
|
|
433
436
|
getTransferPoolsIx(depositFromMarketIndex: number, depositToMarketIndex: number, borrowFromMarketIndex: number, borrowToMarketIndex: number, depositAmount: BN | undefined, borrowAmount: BN | undefined, fromSubAccountId: number, toSubAccountId: number, isToNewSubAccount?: boolean): Promise<TransactionInstruction>;
|
|
434
437
|
transferPerpPosition(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
435
438
|
getTransferPerpPositionIx(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN): Promise<TransactionInstruction>;
|
|
439
|
+
depositIntoIsolatedPerpPosition(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
440
|
+
getDepositIntoIsolatedPerpPositionIx(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number): Promise<TransactionInstruction>;
|
|
441
|
+
transferIsolatedPerpPositionDeposit(amount: BN, perpMarketIndex: number, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
442
|
+
getTransferIsolatedPerpPositionDepositIx(amount: BN, perpMarketIndex: number, subAccountId?: number, noAmountBuffer?: boolean): Promise<TransactionInstruction>;
|
|
443
|
+
withdrawFromIsolatedPerpPosition(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
444
|
+
getWithdrawFromIsolatedPerpPositionIxsBundle(amount: BN, perpMarketIndex: number, subAccountId?: number, userTokenAccount?: PublicKey): Promise<TransactionInstruction[]>;
|
|
445
|
+
getWithdrawFromIsolatedPerpPositionIx(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number): Promise<TransactionInstruction>;
|
|
436
446
|
updateSpotMarketCumulativeInterest(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
437
447
|
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
438
448
|
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
@@ -449,7 +459,7 @@ export declare class DriftClient {
|
|
|
449
459
|
*/
|
|
450
460
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN, subAccountId?: number): Promise<TransactionSignature>;
|
|
451
461
|
sendSignedTx(tx: Transaction | VersionedTransaction, opts?: ConfirmOptions): Promise<TransactionSignature>;
|
|
452
|
-
prepareMarketOrderTxs(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo, cancelExistingOrders?: boolean, settlePnl?: boolean, positionMaxLev?: number): Promise<{
|
|
462
|
+
prepareMarketOrderTxs(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo, cancelExistingOrders?: boolean, settlePnl?: boolean, positionMaxLev?: number, isolatedPositionDepositAmount?: BN): Promise<{
|
|
453
463
|
cancelExistingOrdersTx?: Transaction | VersionedTransaction;
|
|
454
464
|
settlePnlTx?: Transaction | VersionedTransaction;
|
|
455
465
|
fillTx?: Transaction | VersionedTransaction;
|
|
@@ -472,7 +482,7 @@ export declare class DriftClient {
|
|
|
472
482
|
signedCancelExistingOrdersTx?: Transaction;
|
|
473
483
|
signedSettlePnlTx?: Transaction;
|
|
474
484
|
}>;
|
|
475
|
-
placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
485
|
+
placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number, isolatedPositionDepositAmount?: BN): Promise<TransactionSignature>;
|
|
476
486
|
getPlacePerpOrderIx(orderParams: OptionalOrderParams, subAccountId?: number, depositToTradeArgs?: {
|
|
477
487
|
isMakingNewAccount: boolean;
|
|
478
488
|
depositMarketIndex: number;
|
|
@@ -483,7 +493,9 @@ export declare class DriftClient {
|
|
|
483
493
|
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
484
494
|
settleExpiredMarketPoolsToRevenuePool(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
485
495
|
getSettleExpiredMarketPoolsToRevenuePoolIx(perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
486
|
-
cancelOrder(orderId?: number, txParams?: TxParams, subAccountId?: number
|
|
496
|
+
cancelOrder(orderId?: number, txParams?: TxParams, subAccountId?: number, overrides?: {
|
|
497
|
+
withdrawIsolatedDepositAmount?: BN;
|
|
498
|
+
}): Promise<TransactionSignature>;
|
|
487
499
|
getCancelOrderIx(orderId?: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
488
500
|
cancelOrderByUserId(userOrderId: number, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
489
501
|
getCancelOrderByUserIdIx(userOrderId: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
@@ -517,8 +529,8 @@ export declare class DriftClient {
|
|
|
517
529
|
marketIndex?: number;
|
|
518
530
|
direction?: PositionDirection;
|
|
519
531
|
}, placeOrderParams: OrderParams[], txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
520
|
-
placeOrders(params: OrderParams[], txParams?: TxParams, subAccountId?: number, optionalIxs?: TransactionInstruction[]): Promise<TransactionSignature>;
|
|
521
|
-
preparePlaceOrdersTx(params: OrderParams[], txParams?: TxParams, subAccountId?: number, optionalIxs?: TransactionInstruction[]): Promise<{
|
|
532
|
+
placeOrders(params: OrderParams[], txParams?: TxParams, subAccountId?: number, optionalIxs?: TransactionInstruction[], isolatedPositionDepositAmount?: BN): Promise<TransactionSignature>;
|
|
533
|
+
preparePlaceOrdersTx(params: OrderParams[], txParams?: TxParams, subAccountId?: number, optionalIxs?: TransactionInstruction[], isolatedPositionDepositAmount?: BN): Promise<{
|
|
522
534
|
placeOrdersTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
|
|
523
535
|
}>;
|
|
524
536
|
getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number, overrides?: {
|
|
@@ -542,6 +554,7 @@ export declare class DriftClient {
|
|
|
542
554
|
/**
|
|
543
555
|
* Swap tokens in drift account using titan or jupiter
|
|
544
556
|
* @param swapClient swap client to find routes and instructions (Titan or Jupiter)
|
|
557
|
+
* @param jupiterClient @deprecated Use swapClient instead. Legacy parameter for backward compatibility
|
|
545
558
|
* @param outMarketIndex the market index of the token you're buying
|
|
546
559
|
* @param inMarketIndex the market index of the token you're selling
|
|
547
560
|
* @param outAssociatedTokenAccount the token account to receive the token being sold on titan or jupiter
|
|
@@ -555,8 +568,10 @@ export declare class DriftClient {
|
|
|
555
568
|
* @param quote pass in the quote response from Jupiter quote's API
|
|
556
569
|
* @param txParams
|
|
557
570
|
*/
|
|
558
|
-
swap({ swapClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, reduceOnly, txParams, v6, quote, onlyDirectRoutes, }: {
|
|
559
|
-
swapClient
|
|
571
|
+
swap({ swapClient, jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, reduceOnly, txParams, v6, quote, onlyDirectRoutes, }: {
|
|
572
|
+
swapClient?: UnifiedSwapClient | SwapClient;
|
|
573
|
+
/** @deprecated Use swapClient instead. Legacy parameter for backward compatibility */
|
|
574
|
+
jupiterClient?: JupiterClient;
|
|
560
575
|
outMarketIndex: number;
|
|
561
576
|
inMarketIndex: number;
|
|
562
577
|
outAssociatedTokenAccount?: PublicKey;
|
|
@@ -671,7 +686,7 @@ export declare class DriftClient {
|
|
|
671
686
|
updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
672
687
|
getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
673
688
|
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
674
|
-
preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, exitEarlyIfSimFails?: boolean, auctionDurationPercentage?: number, optionalIxs?: TransactionInstruction[]): Promise<{
|
|
689
|
+
preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, exitEarlyIfSimFails?: boolean, auctionDurationPercentage?: number, optionalIxs?: TransactionInstruction[], isolatedPositionDepositAmount?: BN): Promise<{
|
|
675
690
|
placeAndTakeTx: Transaction | VersionedTransaction;
|
|
676
691
|
cancelExistingOrdersTx: Transaction | VersionedTransaction;
|
|
677
692
|
settlePnlTx: Transaction | VersionedTransaction;
|
|
@@ -870,7 +885,6 @@ export declare class DriftClient {
|
|
|
870
885
|
bitFlags?: number;
|
|
871
886
|
policy?: ModifyOrderPolicy;
|
|
872
887
|
maxTs?: BN;
|
|
873
|
-
txParams?: TxParams;
|
|
874
888
|
}, subAccountId?: number): Promise<TransactionInstruction>;
|
|
875
889
|
settlePNLs(users: {
|
|
876
890
|
settleeUserAccountPublicKey: PublicKey;
|
|
@@ -1208,5 +1222,6 @@ export declare class DriftClient {
|
|
|
1208
1222
|
signedTxMap: MappedRecord<Record<string, anchor.web3.TransactionInstruction | anchor.web3.TransactionInstruction[]>, anchor.web3.Transaction | anchor.web3.VersionedTransaction>;
|
|
1209
1223
|
signedTxData: SignedTxData[];
|
|
1210
1224
|
}>;
|
|
1225
|
+
isOrderIncreasingPosition(orderParams: OptionalOrderParams, userAccount: UserAccount): boolean;
|
|
1211
1226
|
}
|
|
1212
1227
|
export {};
|