@drift-labs/sdk 2.153.0-beta.0 → 2.153.0-beta.2
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/VERSION +1 -1
- package/lib/browser/adminClient.d.ts +4 -0
- package/lib/browser/adminClient.js +36 -0
- package/lib/browser/constants/txConstants.d.ts +0 -1
- package/lib/browser/constants/txConstants.js +1 -2
- package/lib/browser/driftClient.d.ts +6 -6
- package/lib/browser/driftClient.js +36 -184
- package/lib/browser/idl/drift.json +46 -2
- package/lib/node/adminClient.d.ts +4 -0
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +36 -0
- package/lib/node/constants/txConstants.d.ts +0 -1
- package/lib/node/constants/txConstants.d.ts.map +1 -1
- package/lib/node/constants/txConstants.js +1 -2
- package/lib/node/driftClient.d.ts +6 -6
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +36 -184
- package/lib/node/idl/drift.json +46 -2
- package/package.json +1 -1
- package/src/adminClient.ts +56 -0
- package/src/constants/txConstants.ts +0 -2
- package/src/driftClient.ts +52 -264
- package/src/idl/drift.json +46 -2
- package/lib/browser/markets.d.ts +0 -5
- package/lib/browser/markets.js +0 -16
- package/lib/node/markets.d.ts +0 -6
- package/lib/node/markets.d.ts.map +0 -1
- package/lib/node/markets.js +0 -16
- package/src/markets.ts +0 -24
package/src/driftClient.ts
CHANGED
|
@@ -221,7 +221,6 @@ import {
|
|
|
221
221
|
} from './math/builder';
|
|
222
222
|
import { TitanClient, SwapMode as TitanSwapMode } from './titan/titanClient';
|
|
223
223
|
import { UnifiedSwapClient } from './swap/UnifiedSwapClient';
|
|
224
|
-
import { DEFAULT_COMMITMENT_LEVEL } from './constants';
|
|
225
224
|
|
|
226
225
|
/**
|
|
227
226
|
* Union type for swap clients (Titan and Jupiter) - Legacy type
|
|
@@ -429,17 +428,19 @@ export class DriftClient {
|
|
|
429
428
|
});
|
|
430
429
|
}
|
|
431
430
|
|
|
432
|
-
this.marketLookupTable = config.marketLookupTable
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
431
|
+
this.marketLookupTable = config.marketLookupTable;
|
|
432
|
+
if (!this.marketLookupTable) {
|
|
433
|
+
this.marketLookupTable = new PublicKey(
|
|
434
|
+
configs[this.env].MARKET_LOOKUP_TABLE
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
437
|
|
|
438
|
-
this.marketLookupTables = config.marketLookupTables
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
438
|
+
this.marketLookupTables = config.marketLookupTables;
|
|
439
|
+
if (!this.marketLookupTables) {
|
|
440
|
+
this.marketLookupTables = configs[this.env].MARKET_LOOKUP_TABLES.map(
|
|
441
|
+
(tableAddr) => new PublicKey(tableAddr)
|
|
442
|
+
);
|
|
443
|
+
}
|
|
443
444
|
|
|
444
445
|
const delistedMarketSetting =
|
|
445
446
|
config.delistedMarketSetting || DelistedMarketSetting.Unsubscribe;
|
|
@@ -9074,14 +9075,8 @@ export class DriftClient {
|
|
|
9074
9075
|
);
|
|
9075
9076
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9076
9077
|
|
|
9077
|
-
const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
|
|
9078
|
-
if (!liquidatorUser) {
|
|
9079
|
-
throw new Error(
|
|
9080
|
-
`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`
|
|
9081
|
-
);
|
|
9082
|
-
}
|
|
9083
9078
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9084
|
-
userAccounts: [
|
|
9079
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
9085
9080
|
useMarketLastSlotCache: true,
|
|
9086
9081
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
9087
9082
|
});
|
|
@@ -9142,17 +9137,7 @@ export class DriftClient {
|
|
|
9142
9137
|
lookupTables: AddressLookupTableAccount[];
|
|
9143
9138
|
}> {
|
|
9144
9139
|
const liabilityMarket = this.getSpotMarketAccount(liabilityMarketIndex);
|
|
9145
|
-
if (!liabilityMarket) {
|
|
9146
|
-
throw new Error(
|
|
9147
|
-
`Liability spot market account not found for index ${liabilityMarketIndex}`
|
|
9148
|
-
);
|
|
9149
|
-
}
|
|
9150
9140
|
const assetMarket = this.getSpotMarketAccount(assetMarketIndex);
|
|
9151
|
-
if (!assetMarket) {
|
|
9152
|
-
throw new Error(
|
|
9153
|
-
`Asset spot market account not found for index ${assetMarketIndex}`
|
|
9154
|
-
);
|
|
9155
|
-
}
|
|
9156
9141
|
|
|
9157
9142
|
if (!quote) {
|
|
9158
9143
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
@@ -9191,7 +9176,7 @@ export class DriftClient {
|
|
|
9191
9176
|
outputMint: liabilityMarket.mint,
|
|
9192
9177
|
});
|
|
9193
9178
|
|
|
9194
|
-
const preInstructions
|
|
9179
|
+
const preInstructions = [];
|
|
9195
9180
|
if (!liabilityTokenAccount) {
|
|
9196
9181
|
const tokenProgram = this.getTokenProgramForSpotMarket(liabilityMarket);
|
|
9197
9182
|
liabilityTokenAccount = await this.getAssociatedTokenAccount(
|
|
@@ -9301,17 +9286,7 @@ export class DriftClient {
|
|
|
9301
9286
|
});
|
|
9302
9287
|
|
|
9303
9288
|
const liabilitySpotMarket = this.getSpotMarketAccount(liabilityMarketIndex);
|
|
9304
|
-
if (!liabilitySpotMarket) {
|
|
9305
|
-
throw new Error(
|
|
9306
|
-
`Liability spot market account not found for index ${liabilityMarketIndex}`
|
|
9307
|
-
);
|
|
9308
|
-
}
|
|
9309
9289
|
const assetSpotMarket = this.getSpotMarketAccount(assetMarketIndex);
|
|
9310
|
-
if (!assetSpotMarket) {
|
|
9311
|
-
throw new Error(
|
|
9312
|
-
`Asset spot market account not found for index ${assetMarketIndex}`
|
|
9313
|
-
);
|
|
9314
|
-
}
|
|
9315
9290
|
|
|
9316
9291
|
const liabilityTokenProgram =
|
|
9317
9292
|
this.getTokenProgramForSpotMarket(liabilitySpotMarket);
|
|
@@ -9427,17 +9402,7 @@ export class DriftClient {
|
|
|
9427
9402
|
});
|
|
9428
9403
|
|
|
9429
9404
|
const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
9430
|
-
if (!inSpotMarket) {
|
|
9431
|
-
throw new Error(
|
|
9432
|
-
`In spot market account not found for index ${inMarketIndex}`
|
|
9433
|
-
);
|
|
9434
|
-
}
|
|
9435
9405
|
const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
9436
|
-
if (!outSpotMarket) {
|
|
9437
|
-
throw new Error(
|
|
9438
|
-
`Out spot market account not found for index ${outMarketIndex}`
|
|
9439
|
-
);
|
|
9440
|
-
}
|
|
9441
9406
|
|
|
9442
9407
|
if (this.isToken2022(inSpotMarket) || this.isToken2022(outSpotMarket)) {
|
|
9443
9408
|
remainingAccounts.push({
|
|
@@ -9563,15 +9528,9 @@ export class DriftClient {
|
|
|
9563
9528
|
liquidatorSubAccountId
|
|
9564
9529
|
);
|
|
9565
9530
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9566
|
-
const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
|
|
9567
|
-
if (!liquidatorUser) {
|
|
9568
|
-
throw new Error(
|
|
9569
|
-
`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`
|
|
9570
|
-
);
|
|
9571
|
-
}
|
|
9572
9531
|
|
|
9573
9532
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9574
|
-
userAccounts: [
|
|
9533
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
9575
9534
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
9576
9535
|
writableSpotMarketIndexes: [liabilityMarketIndex],
|
|
9577
9536
|
});
|
|
@@ -9644,15 +9603,9 @@ export class DriftClient {
|
|
|
9644
9603
|
liquidatorSubAccountId
|
|
9645
9604
|
);
|
|
9646
9605
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9647
|
-
const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
|
|
9648
|
-
if (!liquidatorUser) {
|
|
9649
|
-
throw new Error(
|
|
9650
|
-
`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`
|
|
9651
|
-
);
|
|
9652
|
-
}
|
|
9653
9606
|
|
|
9654
9607
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9655
|
-
userAccounts: [
|
|
9608
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
9656
9609
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
9657
9610
|
writableSpotMarketIndexes: [assetMarketIndex],
|
|
9658
9611
|
});
|
|
@@ -9714,15 +9667,9 @@ export class DriftClient {
|
|
|
9714
9667
|
liquidatorSubAccountId
|
|
9715
9668
|
);
|
|
9716
9669
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9717
|
-
const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
|
|
9718
|
-
if (!liquidatorUser) {
|
|
9719
|
-
throw new Error(
|
|
9720
|
-
`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`
|
|
9721
|
-
);
|
|
9722
|
-
}
|
|
9723
9670
|
|
|
9724
9671
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9725
|
-
userAccounts: [
|
|
9672
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
9726
9673
|
writablePerpMarketIndexes: [marketIndex],
|
|
9727
9674
|
writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
9728
9675
|
});
|
|
@@ -9789,22 +9736,12 @@ export class DriftClient {
|
|
|
9789
9736
|
);
|
|
9790
9737
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9791
9738
|
|
|
9792
|
-
const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
|
|
9793
|
-
if (!liquidatorUser) {
|
|
9794
|
-
throw new Error(
|
|
9795
|
-
`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`
|
|
9796
|
-
);
|
|
9797
|
-
}
|
|
9798
|
-
|
|
9799
9739
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9800
|
-
userAccounts: [
|
|
9740
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
9801
9741
|
writableSpotMarketIndexes: [marketIndex],
|
|
9802
9742
|
});
|
|
9803
9743
|
|
|
9804
9744
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
9805
|
-
if (!spotMarket) {
|
|
9806
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
9807
|
-
}
|
|
9808
9745
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
9809
9746
|
|
|
9810
9747
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
@@ -9884,11 +9821,6 @@ export class DriftClient {
|
|
|
9884
9821
|
perpMarketIndex: number
|
|
9885
9822
|
): Promise<TransactionInstruction> {
|
|
9886
9823
|
const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
|
|
9887
|
-
if (!perpMarket) {
|
|
9888
|
-
throw new Error(
|
|
9889
|
-
`Perp market account not found for index ${perpMarketIndex}`
|
|
9890
|
-
);
|
|
9891
|
-
}
|
|
9892
9824
|
|
|
9893
9825
|
if (!isVariant(perpMarket.amm.oracleSource, 'prelaunch')) {
|
|
9894
9826
|
throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
|
|
@@ -9924,13 +9856,8 @@ export class DriftClient {
|
|
|
9924
9856
|
makers: [PublicKey, PublicKey][]
|
|
9925
9857
|
): Promise<TransactionInstruction> {
|
|
9926
9858
|
const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
|
|
9927
|
-
if (!perpMarket) {
|
|
9928
|
-
throw new Error(
|
|
9929
|
-
`Perp market account not found for index ${perpMarketIndex}`
|
|
9930
|
-
);
|
|
9931
|
-
}
|
|
9932
9859
|
|
|
9933
|
-
const remainingAccounts
|
|
9860
|
+
const remainingAccounts = [];
|
|
9934
9861
|
for (const [maker, makerStats] of makers) {
|
|
9935
9862
|
remainingAccounts.push({
|
|
9936
9863
|
pubkey: maker,
|
|
@@ -9978,7 +9905,7 @@ export class DriftClient {
|
|
|
9978
9905
|
userAccountPublicKey
|
|
9979
9906
|
)) as UserAccount;
|
|
9980
9907
|
|
|
9981
|
-
const writablePerpMarketIndexes
|
|
9908
|
+
const writablePerpMarketIndexes = [];
|
|
9982
9909
|
for (const position of userAccount.perpPositions) {
|
|
9983
9910
|
if (!positionIsAvailable(position)) {
|
|
9984
9911
|
writablePerpMarketIndexes.push(position.marketIndex);
|
|
@@ -10003,25 +9930,15 @@ export class DriftClient {
|
|
|
10003
9930
|
this.eventEmitter.emit(eventName, data);
|
|
10004
9931
|
}
|
|
10005
9932
|
|
|
10006
|
-
public getOracleDataForPerpMarket(
|
|
10007
|
-
marketIndex: number
|
|
10008
|
-
): OraclePriceData | undefined {
|
|
9933
|
+
public getOracleDataForPerpMarket(marketIndex: number): OraclePriceData {
|
|
10009
9934
|
return this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(
|
|
10010
9935
|
marketIndex
|
|
10011
|
-
)
|
|
9936
|
+
).data;
|
|
10012
9937
|
}
|
|
10013
9938
|
|
|
10014
|
-
public getMMOracleDataForPerpMarket(
|
|
10015
|
-
marketIndex: number
|
|
10016
|
-
): MMOraclePriceData | undefined {
|
|
9939
|
+
public getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData {
|
|
10017
9940
|
const perpMarket = this.getPerpMarketAccount(marketIndex);
|
|
10018
|
-
if (!perpMarket) {
|
|
10019
|
-
throw new Error(`Perp market account not found for index ${marketIndex}`);
|
|
10020
|
-
}
|
|
10021
9941
|
const oracleData = this.getOracleDataForPerpMarket(marketIndex);
|
|
10022
|
-
if (!oracleData) {
|
|
10023
|
-
return undefined;
|
|
10024
|
-
}
|
|
10025
9942
|
const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
|
|
10026
9943
|
const isMMOracleActive = !perpMarket.amm.mmOracleSlot.eq(ZERO);
|
|
10027
9944
|
const pctDiff = perpMarket.amm.mmOraclePrice
|
|
@@ -10050,7 +9967,7 @@ export class DriftClient {
|
|
|
10050
9967
|
isExchangeOracleMoreRecent = false;
|
|
10051
9968
|
} else if (
|
|
10052
9969
|
!doSlotCheckForRecency &&
|
|
10053
|
-
|
|
9970
|
+
oracleData.sequenceId < mmOracleSequenceId
|
|
10054
9971
|
) {
|
|
10055
9972
|
isExchangeOracleMoreRecent = false;
|
|
10056
9973
|
}
|
|
@@ -10087,12 +10004,10 @@ export class DriftClient {
|
|
|
10087
10004
|
}
|
|
10088
10005
|
}
|
|
10089
10006
|
|
|
10090
|
-
public getOracleDataForSpotMarket(
|
|
10091
|
-
marketIndex: number
|
|
10092
|
-
): OraclePriceData | undefined {
|
|
10007
|
+
public getOracleDataForSpotMarket(marketIndex: number): OraclePriceData {
|
|
10093
10008
|
return this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(
|
|
10094
10009
|
marketIndex
|
|
10095
|
-
)
|
|
10010
|
+
).data;
|
|
10096
10011
|
}
|
|
10097
10012
|
|
|
10098
10013
|
public async initializeInsuranceFundStake(
|
|
@@ -10119,14 +10034,9 @@ export class DriftClient {
|
|
|
10119
10034
|
marketIndex
|
|
10120
10035
|
);
|
|
10121
10036
|
|
|
10122
|
-
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
10123
|
-
if (!spotMarket) {
|
|
10124
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10125
|
-
}
|
|
10126
|
-
|
|
10127
10037
|
const accounts = {
|
|
10128
10038
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
10129
|
-
spotMarket:
|
|
10039
|
+
spotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
10130
10040
|
userStats: getUserStatsAccountPublicKey(
|
|
10131
10041
|
this.program.programId,
|
|
10132
10042
|
this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
|
|
@@ -10152,9 +10062,6 @@ export class DriftClient {
|
|
|
10152
10062
|
collateralAccountPublicKey: PublicKey
|
|
10153
10063
|
): Promise<TransactionInstruction> {
|
|
10154
10064
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
10155
|
-
if (!spotMarket) {
|
|
10156
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10157
|
-
}
|
|
10158
10065
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10159
10066
|
this.program.programId,
|
|
10160
10067
|
this.wallet.publicKey,
|
|
@@ -10275,12 +10182,9 @@ export class DriftClient {
|
|
|
10275
10182
|
*/
|
|
10276
10183
|
fromSubaccount?: boolean;
|
|
10277
10184
|
}): Promise<TransactionInstruction[]> {
|
|
10278
|
-
const addIfStakeIxs
|
|
10185
|
+
const addIfStakeIxs = [];
|
|
10279
10186
|
|
|
10280
10187
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
10281
|
-
if (!spotMarketAccount) {
|
|
10282
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10283
|
-
}
|
|
10284
10188
|
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
10285
10189
|
const createWSOLTokenAccount =
|
|
10286
10190
|
isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
@@ -10374,9 +10278,6 @@ export class DriftClient {
|
|
|
10374
10278
|
txParams?: TxParams
|
|
10375
10279
|
): Promise<TransactionSignature> {
|
|
10376
10280
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
10377
|
-
if (!spotMarketAccount) {
|
|
10378
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10379
|
-
}
|
|
10380
10281
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10381
10282
|
this.program.programId,
|
|
10382
10283
|
this.wallet.publicKey,
|
|
@@ -10412,9 +10313,6 @@ export class DriftClient {
|
|
|
10412
10313
|
txParams?: TxParams
|
|
10413
10314
|
): Promise<TransactionSignature> {
|
|
10414
10315
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
10415
|
-
if (!spotMarketAccount) {
|
|
10416
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10417
|
-
}
|
|
10418
10316
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10419
10317
|
this.program.programId,
|
|
10420
10318
|
this.wallet.publicKey,
|
|
@@ -10450,11 +10348,8 @@ export class DriftClient {
|
|
|
10450
10348
|
collateralAccountPublicKey: PublicKey,
|
|
10451
10349
|
txParams?: TxParams
|
|
10452
10350
|
): Promise<TransactionSignature> {
|
|
10453
|
-
const removeIfStakeIxs
|
|
10351
|
+
const removeIfStakeIxs = [];
|
|
10454
10352
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
10455
|
-
if (!spotMarketAccount) {
|
|
10456
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10457
|
-
}
|
|
10458
10353
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10459
10354
|
this.program.programId,
|
|
10460
10355
|
this.wallet.publicKey,
|
|
@@ -10564,9 +10459,6 @@ export class DriftClient {
|
|
|
10564
10459
|
): Promise<TransactionInstruction> {
|
|
10565
10460
|
const marketIndex = QUOTE_SPOT_MARKET_INDEX;
|
|
10566
10461
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
10567
|
-
if (!spotMarket) {
|
|
10568
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10569
|
-
}
|
|
10570
10462
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10571
10463
|
this.program.programId,
|
|
10572
10464
|
authority,
|
|
@@ -10606,9 +10498,6 @@ export class DriftClient {
|
|
|
10606
10498
|
): Promise<TransactionInstruction> {
|
|
10607
10499
|
const marketIndex = GOV_SPOT_MARKET_INDEX;
|
|
10608
10500
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
10609
|
-
if (!spotMarket) {
|
|
10610
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10611
|
-
}
|
|
10612
10501
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
10613
10502
|
this.program.programId,
|
|
10614
10503
|
authority,
|
|
@@ -10649,11 +10538,6 @@ export class DriftClient {
|
|
|
10649
10538
|
spotMarketIndex: number
|
|
10650
10539
|
): Promise<TransactionInstruction> {
|
|
10651
10540
|
const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
|
|
10652
|
-
if (!spotMarketAccount) {
|
|
10653
|
-
throw new Error(
|
|
10654
|
-
`Spot market account not found for index ${spotMarketIndex}`
|
|
10655
|
-
);
|
|
10656
|
-
}
|
|
10657
10541
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
10658
10542
|
|
|
10659
10543
|
const remainingAccounts = [];
|
|
@@ -10702,24 +10586,13 @@ export class DriftClient {
|
|
|
10702
10586
|
spotMarketIndex: number,
|
|
10703
10587
|
perpMarketIndex: number
|
|
10704
10588
|
): Promise<TransactionInstruction> {
|
|
10705
|
-
const userAccount = this.getUserAccount();
|
|
10706
|
-
if (!userAccount) {
|
|
10707
|
-
throw new Error(
|
|
10708
|
-
`User account not found. Something is wrong with driftClient config`
|
|
10709
|
-
);
|
|
10710
|
-
}
|
|
10711
10589
|
const remainingAccounts = this.getRemainingAccounts({
|
|
10712
|
-
userAccounts: [
|
|
10590
|
+
userAccounts: [this.getUserAccount()],
|
|
10713
10591
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
10714
10592
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
10715
10593
|
});
|
|
10716
10594
|
|
|
10717
10595
|
const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
|
|
10718
|
-
if (!spotMarket) {
|
|
10719
|
-
throw new Error(
|
|
10720
|
-
`Spot market account not found for index ${spotMarketIndex}`
|
|
10721
|
-
);
|
|
10722
|
-
}
|
|
10723
10596
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
10724
10597
|
|
|
10725
10598
|
return await this.program.instruction.resolvePerpPnlDeficit(
|
|
@@ -10745,9 +10618,6 @@ export class DriftClient {
|
|
|
10745
10618
|
userTokenAccountPublicKey: PublicKey
|
|
10746
10619
|
): Promise<TransactionInstruction> {
|
|
10747
10620
|
const spotMarket = await this.getSpotMarketAccount(marketIndex);
|
|
10748
|
-
if (!spotMarket) {
|
|
10749
|
-
throw new Error(`Spot market account not found for index ${marketIndex}`);
|
|
10750
|
-
}
|
|
10751
10621
|
|
|
10752
10622
|
const remainingAccounts = [];
|
|
10753
10623
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
@@ -10801,17 +10671,9 @@ export class DriftClient {
|
|
|
10801
10671
|
|
|
10802
10672
|
public getPerpMarketExtendedInfo(
|
|
10803
10673
|
marketIndex: number
|
|
10804
|
-
): PerpMarketExtendedInfo
|
|
10674
|
+
): PerpMarketExtendedInfo {
|
|
10805
10675
|
const marketAccount = this.getPerpMarketAccount(marketIndex);
|
|
10806
|
-
if (!marketAccount) {
|
|
10807
|
-
return undefined;
|
|
10808
|
-
}
|
|
10809
10676
|
const quoteAccount = this.getSpotMarketAccount(QUOTE_SPOT_MARKET_INDEX);
|
|
10810
|
-
if (!quoteAccount) {
|
|
10811
|
-
throw new Error(
|
|
10812
|
-
`Quote spot market account not found. Something is wrong with driftClient config`
|
|
10813
|
-
);
|
|
10814
|
-
}
|
|
10815
10677
|
|
|
10816
10678
|
const extendedInfo: PerpMarketExtendedInfo = {
|
|
10817
10679
|
marketIndex,
|
|
@@ -10862,23 +10724,18 @@ export class DriftClient {
|
|
|
10862
10724
|
feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
|
|
10863
10725
|
|
|
10864
10726
|
if (marketIndex !== undefined) {
|
|
10865
|
-
let marketAccount
|
|
10866
|
-
| null
|
|
10867
|
-
| undefined
|
|
10868
|
-
| PerpMarketAccount
|
|
10869
|
-
| SpotMarketAccount = null;
|
|
10870
|
-
let feeAdjustment = 1;
|
|
10727
|
+
let marketAccount = null;
|
|
10871
10728
|
if (isVariant(marketType, 'perp')) {
|
|
10872
10729
|
marketAccount = this.getPerpMarketAccount(marketIndex);
|
|
10873
|
-
feeAdjustment = marketAccount?.feeAdjustment ?? 0;
|
|
10874
10730
|
} else {
|
|
10875
10731
|
marketAccount = this.getSpotMarketAccount(marketIndex);
|
|
10876
10732
|
}
|
|
10877
|
-
|
|
10733
|
+
|
|
10734
|
+
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
10878
10735
|
if (userHLM) {
|
|
10879
10736
|
takerFee *= 2;
|
|
10880
10737
|
}
|
|
10881
|
-
makerFee += (makerFee * feeAdjustment) / 100;
|
|
10738
|
+
makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
|
|
10882
10739
|
}
|
|
10883
10740
|
|
|
10884
10741
|
return {
|
|
@@ -10929,9 +10786,7 @@ export class DriftClient {
|
|
|
10929
10786
|
return this.receiverProgram;
|
|
10930
10787
|
}
|
|
10931
10788
|
|
|
10932
|
-
public async getSwitchboardOnDemandProgram(): Promise<
|
|
10933
|
-
Program30<Idl30> | undefined
|
|
10934
|
-
> {
|
|
10789
|
+
public async getSwitchboardOnDemandProgram(): Promise<Program30<Idl30>> {
|
|
10935
10790
|
if (this.sbOnDemandProgram === undefined) {
|
|
10936
10791
|
this.sbOnDemandProgram = await AnchorUtils.loadProgramFromConnection(
|
|
10937
10792
|
this.connection
|
|
@@ -11234,9 +11089,6 @@ export class DriftClient {
|
|
|
11234
11089
|
numSignatures = 3
|
|
11235
11090
|
): Promise<TransactionInstruction | undefined> {
|
|
11236
11091
|
const program = await this.getSwitchboardOnDemandProgram();
|
|
11237
|
-
if (!program) {
|
|
11238
|
-
return undefined;
|
|
11239
|
-
}
|
|
11240
11092
|
const feedAccount = new PullFeed(program, feed);
|
|
11241
11093
|
if (!this.sbProgramFeedConfigs) {
|
|
11242
11094
|
this.sbProgramFeedConfigs = new Map();
|
|
@@ -11265,7 +11117,7 @@ export class DriftClient {
|
|
|
11265
11117
|
feed: PublicKey,
|
|
11266
11118
|
recentSlothash?: Slothash,
|
|
11267
11119
|
numSignatures = 3
|
|
11268
|
-
): Promise<TransactionSignature
|
|
11120
|
+
): Promise<TransactionSignature> {
|
|
11269
11121
|
const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(
|
|
11270
11122
|
feed,
|
|
11271
11123
|
recentSlothash,
|
|
@@ -11398,12 +11250,7 @@ export class DriftClient {
|
|
|
11398
11250
|
const signingAuthority =
|
|
11399
11251
|
overrides?.signingAuthority ?? this.wallet.publicKey;
|
|
11400
11252
|
const userAccount =
|
|
11401
|
-
overrides?.user
|
|
11402
|
-
if (!userAccount) {
|
|
11403
|
-
throw new Error(
|
|
11404
|
-
`User account not found for subAccountId ${subAccountId}`
|
|
11405
|
-
);
|
|
11406
|
-
}
|
|
11253
|
+
overrides?.user.getUserAccount() ?? this.getUserAccount(subAccountId);
|
|
11407
11254
|
|
|
11408
11255
|
const remainingAccounts = this.getRemainingAccounts({
|
|
11409
11256
|
userAccounts: depositToTradeArgs?.isMakingNewAccount ? [] : [userAccount],
|
|
@@ -11543,11 +11390,6 @@ export class DriftClient {
|
|
|
11543
11390
|
spotMarketIndex: number
|
|
11544
11391
|
): Promise<TransactionInstruction> {
|
|
11545
11392
|
const spotMarket = await this.getSpotMarketAccount(spotMarketIndex);
|
|
11546
|
-
if (!spotMarket) {
|
|
11547
|
-
throw new Error(
|
|
11548
|
-
`Spot market account not found for index ${spotMarketIndex}`
|
|
11549
|
-
);
|
|
11550
|
-
}
|
|
11551
11393
|
return this.program.instruction.pauseSpotMarketDepositWithdraw({
|
|
11552
11394
|
accounts: {
|
|
11553
11395
|
state: await this.getStatePublicKey(),
|
|
@@ -11604,17 +11446,12 @@ export class DriftClient {
|
|
|
11604
11446
|
data.set(oraclePrice.toArrayLike(Buffer, 'le', 8), 5); // next 8 bytes
|
|
11605
11447
|
data.set(oracleSequenceId.toArrayLike(Buffer, 'le', 8), 13); // next 8 bytes
|
|
11606
11448
|
|
|
11607
|
-
const perpMarket = this.getPerpMarketAccount(marketIndex);
|
|
11608
|
-
if (!perpMarket) {
|
|
11609
|
-
throw new Error(`Perp market account not found for index ${marketIndex}`);
|
|
11610
|
-
}
|
|
11611
|
-
|
|
11612
11449
|
// Build the instruction manually
|
|
11613
11450
|
return new TransactionInstruction({
|
|
11614
11451
|
programId: this.program.programId,
|
|
11615
11452
|
keys: [
|
|
11616
11453
|
{
|
|
11617
|
-
pubkey:
|
|
11454
|
+
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
11618
11455
|
isWritable: true,
|
|
11619
11456
|
isSigner: false,
|
|
11620
11457
|
},
|
|
@@ -11665,16 +11502,12 @@ export class DriftClient {
|
|
|
11665
11502
|
data.set(discriminatorBuffer, 0);
|
|
11666
11503
|
data.writeInt8(ammSpreadAdjustment, 5); // next byte
|
|
11667
11504
|
|
|
11668
|
-
const perpMarket = this.getPerpMarketAccount(marketIndex);
|
|
11669
|
-
if (!perpMarket) {
|
|
11670
|
-
throw new Error(`Perp market account not found for index ${marketIndex}`);
|
|
11671
|
-
}
|
|
11672
11505
|
// Build the instruction manually
|
|
11673
11506
|
return new TransactionInstruction({
|
|
11674
11507
|
programId: this.program.programId,
|
|
11675
11508
|
keys: [
|
|
11676
11509
|
{
|
|
11677
|
-
pubkey:
|
|
11510
|
+
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
11678
11511
|
isWritable: true,
|
|
11679
11512
|
isSigner: false,
|
|
11680
11513
|
},
|
|
@@ -11843,17 +11676,12 @@ export class DriftClient {
|
|
|
11843
11676
|
readablePerpMarketIndex: perpMarketIndexes,
|
|
11844
11677
|
});
|
|
11845
11678
|
|
|
11846
|
-
const quoteMarket = this.getSpotMarketAccount(0);
|
|
11847
|
-
if (!quoteMarket) {
|
|
11848
|
-
throw new Error(`Quote spot market account not found for index 0`);
|
|
11849
|
-
}
|
|
11850
|
-
|
|
11851
11679
|
return this.program.instruction.updateAmmCache({
|
|
11852
11680
|
accounts: {
|
|
11853
11681
|
state: await this.getStatePublicKey(),
|
|
11854
11682
|
keeper: this.wallet.publicKey,
|
|
11855
11683
|
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
11856
|
-
quoteMarket:
|
|
11684
|
+
quoteMarket: this.getSpotMarketAccount(0).pubkey,
|
|
11857
11685
|
},
|
|
11858
11686
|
remainingAccounts,
|
|
11859
11687
|
});
|
|
@@ -11877,11 +11705,6 @@ export class DriftClient {
|
|
|
11877
11705
|
constituent: ConstituentAccount
|
|
11878
11706
|
): Promise<TransactionInstruction> {
|
|
11879
11707
|
const spotMarket = this.getSpotMarketAccount(constituent.spotMarketIndex);
|
|
11880
|
-
if (!spotMarket) {
|
|
11881
|
-
throw new Error(
|
|
11882
|
-
`Spot market account not found for index ${constituent.spotMarketIndex}`
|
|
11883
|
-
);
|
|
11884
|
-
}
|
|
11885
11708
|
return this.program.instruction.updateConstituentOracleInfo({
|
|
11886
11709
|
accounts: {
|
|
11887
11710
|
keeper: this.wallet.publicKey,
|
|
@@ -11943,26 +11766,12 @@ export class DriftClient {
|
|
|
11943
11766
|
lpPool,
|
|
11944
11767
|
outMarketIndex
|
|
11945
11768
|
);
|
|
11946
|
-
|
|
11947
|
-
const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
11948
|
-
if (!inSpotMarket) {
|
|
11949
|
-
throw new Error(
|
|
11950
|
-
`Spot market account not found for index ${inMarketIndex}`
|
|
11951
|
-
);
|
|
11952
|
-
}
|
|
11953
|
-
const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
11954
|
-
if (!outSpotMarket) {
|
|
11955
|
-
throw new Error(
|
|
11956
|
-
`Spot market account not found for index ${outMarketIndex}`
|
|
11957
|
-
);
|
|
11958
|
-
}
|
|
11959
|
-
|
|
11960
11769
|
const userInTokenAccount = await getAssociatedTokenAddress(
|
|
11961
|
-
|
|
11770
|
+
this.getSpotMarketAccount(inMarketIndex).mint,
|
|
11962
11771
|
userAuthority
|
|
11963
11772
|
);
|
|
11964
11773
|
const userOutTokenAccount = await getAssociatedTokenAddress(
|
|
11965
|
-
|
|
11774
|
+
this.getSpotMarketAccount(outMarketIndex).mint,
|
|
11966
11775
|
userAuthority
|
|
11967
11776
|
);
|
|
11968
11777
|
const inConstituent = getConstituentPublicKey(
|
|
@@ -11975,8 +11784,8 @@ export class DriftClient {
|
|
|
11975
11784
|
lpPool,
|
|
11976
11785
|
outMarketIndex
|
|
11977
11786
|
);
|
|
11978
|
-
const inMarketMint =
|
|
11979
|
-
const outMarketMint =
|
|
11787
|
+
const inMarketMint = this.getSpotMarketAccount(inMarketIndex).mint;
|
|
11788
|
+
const outMarketMint = this.getSpotMarketAccount(outMarketIndex).mint;
|
|
11980
11789
|
|
|
11981
11790
|
const constituentTargetBase = getConstituentTargetBasePublicKey(
|
|
11982
11791
|
this.program.programId,
|
|
@@ -12175,11 +11984,6 @@ export class DriftClient {
|
|
|
12175
11984
|
});
|
|
12176
11985
|
|
|
12177
11986
|
const spotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
12178
|
-
if (!spotMarket) {
|
|
12179
|
-
throw new Error(
|
|
12180
|
-
`Spot market account not found for index ${inMarketIndex}`
|
|
12181
|
-
);
|
|
12182
|
-
}
|
|
12183
11987
|
const inMarketMint = spotMarket.mint;
|
|
12184
11988
|
const isSolMarket = inMarketMint.equals(WRAPPED_SOL_MINT);
|
|
12185
11989
|
|
|
@@ -12395,11 +12199,6 @@ export class DriftClient {
|
|
|
12395
12199
|
});
|
|
12396
12200
|
|
|
12397
12201
|
const spotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
12398
|
-
if (!spotMarket) {
|
|
12399
|
-
throw new Error(
|
|
12400
|
-
`Spot market account not found for index ${outMarketIndex}`
|
|
12401
|
-
);
|
|
12402
|
-
}
|
|
12403
12202
|
const outMarketMint = spotMarket.mint;
|
|
12404
12203
|
const outConstituent = getConstituentPublicKey(
|
|
12405
12204
|
this.program.programId,
|
|
@@ -12511,11 +12310,6 @@ export class DriftClient {
|
|
|
12511
12310
|
});
|
|
12512
12311
|
|
|
12513
12312
|
const spotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
12514
|
-
if (!spotMarket) {
|
|
12515
|
-
throw new Error(
|
|
12516
|
-
`Spot market account not found for index ${outMarketIndex}`
|
|
12517
|
-
);
|
|
12518
|
-
}
|
|
12519
12313
|
const outMarketMint = spotMarket.mint;
|
|
12520
12314
|
const outConstituent = getConstituentPublicKey(
|
|
12521
12315
|
this.program.programId,
|
|
@@ -12750,11 +12544,11 @@ export class DriftClient {
|
|
|
12750
12544
|
lpPoolId: number,
|
|
12751
12545
|
perpMarketIndexes: number[]
|
|
12752
12546
|
): Promise<TransactionInstruction> {
|
|
12753
|
-
const remainingAccounts
|
|
12547
|
+
const remainingAccounts = [];
|
|
12754
12548
|
remainingAccounts.push(
|
|
12755
12549
|
...perpMarketIndexes.map((index) => {
|
|
12756
12550
|
return {
|
|
12757
|
-
pubkey: this.getPerpMarketAccount(index)
|
|
12551
|
+
pubkey: this.getPerpMarketAccount(index).pubkey,
|
|
12758
12552
|
isSigner: false,
|
|
12759
12553
|
isWritable: true,
|
|
12760
12554
|
};
|
|
@@ -12862,8 +12656,7 @@ export class DriftClient {
|
|
|
12862
12656
|
txVersion: txVersion ?? this.txVersion,
|
|
12863
12657
|
txParams: txParams ?? this.txParams,
|
|
12864
12658
|
connection: this.connection,
|
|
12865
|
-
preFlightCommitment:
|
|
12866
|
-
this.opts?.preflightCommitment ?? DEFAULT_COMMITMENT_LEVEL,
|
|
12659
|
+
preFlightCommitment: this.opts.preflightCommitment,
|
|
12867
12660
|
fetchAllMarketLookupTableAccounts:
|
|
12868
12661
|
this.fetchAllLookupTableAccounts.bind(this),
|
|
12869
12662
|
lookupTables,
|
|
@@ -12880,20 +12673,17 @@ export class DriftClient {
|
|
|
12880
12673
|
lookupTables?: AddressLookupTableAccount[],
|
|
12881
12674
|
forceVersionedTransaction?: boolean
|
|
12882
12675
|
): Promise<(Transaction | VersionedTransaction)[]> {
|
|
12883
|
-
|
|
12676
|
+
return this.txHandler.buildBulkTransactions({
|
|
12884
12677
|
instructions,
|
|
12885
12678
|
txVersion: txVersion ?? this.txVersion,
|
|
12886
12679
|
txParams: txParams ?? this.txParams,
|
|
12887
12680
|
connection: this.connection,
|
|
12888
|
-
preFlightCommitment:
|
|
12889
|
-
this.opts?.preflightCommitment ?? DEFAULT_COMMITMENT_LEVEL,
|
|
12681
|
+
preFlightCommitment: this.opts.preflightCommitment,
|
|
12890
12682
|
fetchAllMarketLookupTableAccounts:
|
|
12891
12683
|
this.fetchAllLookupTableAccounts.bind(this),
|
|
12892
12684
|
lookupTables,
|
|
12893
12685
|
forceVersionedTransaction,
|
|
12894
12686
|
});
|
|
12895
|
-
|
|
12896
|
-
return txns.filter(Boolean) as (Transaction | VersionedTransaction)[];
|
|
12897
12687
|
}
|
|
12898
12688
|
|
|
12899
12689
|
async buildTransactionsMap(
|
|
@@ -12911,8 +12701,7 @@ export class DriftClient {
|
|
|
12911
12701
|
txVersion: txVersion ?? this.txVersion,
|
|
12912
12702
|
txParams: txParams ?? this.txParams,
|
|
12913
12703
|
connection: this.connection,
|
|
12914
|
-
preFlightCommitment:
|
|
12915
|
-
this.opts?.preflightCommitment ?? DEFAULT_COMMITMENT_LEVEL,
|
|
12704
|
+
preFlightCommitment: this.opts.preflightCommitment,
|
|
12916
12705
|
fetchAllMarketLookupTableAccounts:
|
|
12917
12706
|
this.fetchAllLookupTableAccounts.bind(this),
|
|
12918
12707
|
lookupTables,
|
|
@@ -12935,8 +12724,7 @@ export class DriftClient {
|
|
|
12935
12724
|
txVersion: txVersion ?? this.txVersion,
|
|
12936
12725
|
txParams: txParams ?? this.txParams,
|
|
12937
12726
|
connection: this.connection,
|
|
12938
|
-
preFlightCommitment:
|
|
12939
|
-
this.opts?.preflightCommitment ?? DEFAULT_COMMITMENT_LEVEL,
|
|
12727
|
+
preFlightCommitment: this.opts.preflightCommitment,
|
|
12940
12728
|
fetchAllMarketLookupTableAccounts:
|
|
12941
12729
|
this.fetchAllLookupTableAccounts.bind(this),
|
|
12942
12730
|
lookupTables,
|