@drift-labs/sdk 2.84.0-beta.5 → 2.84.0-beta.7
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/adminClient.d.ts +4 -2
- package/lib/adminClient.js +21 -4
- package/lib/blockhashSubscriber/BlockhashSubscriber.d.ts +7 -1
- package/lib/blockhashSubscriber/BlockhashSubscriber.js +11 -2
- package/lib/constants/spotMarkets.js +10 -0
- package/lib/driftClient.d.ts +30 -3
- package/lib/driftClient.js +108 -82
- package/lib/factory/oracleClient.js +13 -0
- package/lib/idl/drift.json +17 -0
- package/lib/math/spotBalance.js +7 -1
- package/lib/oracles/pythPullClient.d.ts +18 -0
- package/lib/oracles/pythPullClient.js +60 -0
- package/lib/tx/txHandler.d.ts +23 -20
- package/lib/tx/txHandler.js +56 -57
- package/lib/types.d.ts +17 -0
- package/lib/types.js +4 -0
- package/package.json +11 -9
- package/src/adminClient.ts +45 -3
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +15 -2
- package/src/constants/spotMarkets.ts +10 -0
- package/src/driftClient.ts +308 -167
- package/src/factory/oracleClient.ts +17 -0
- package/src/idl/drift.json +17 -0
- package/src/math/spotBalance.ts +15 -1
- package/src/oracles/pythPullClient.ts +112 -0
- package/src/tx/txHandler.ts +87 -78
- package/src/types.ts +12 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.84.0-beta.
|
|
1
|
+
2.84.0-beta.7
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -89,6 +89,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
89
89
|
getUpdateSpotMarketRevenueSettlePeriodIx(spotMarketIndex: number, revenueSettlePeriod: BN): Promise<TransactionInstruction>;
|
|
90
90
|
updateSpotMarketMaxTokenDeposits(spotMarketIndex: number, maxTokenDeposits: BN): Promise<TransactionSignature>;
|
|
91
91
|
getUpdateSpotMarketMaxTokenDepositsIx(spotMarketIndex: number, maxTokenDeposits: BN): Promise<TransactionInstruction>;
|
|
92
|
+
updateSpotMarketMaxTokenBorrows(spotMarketIndex: number, maxTokenBorrows: BN): Promise<TransactionSignature>;
|
|
93
|
+
getUpdateSpotMarketMaxTokenBorrowsIx(spotMarketIndex: number, maxTokenBorrows: BN): Promise<TransactionInstruction>;
|
|
92
94
|
updateSpotMarketScaleInitialAssetWeightStart(spotMarketIndex: number, scaleInitialAssetWeightStart: BN): Promise<TransactionSignature>;
|
|
93
95
|
getUpdateSpotMarketScaleInitialAssetWeightStartIx(spotMarketIndex: number, scaleInitialAssetWeightStart: BN): Promise<TransactionInstruction>;
|
|
94
96
|
updateInsuranceFundUnstakingPeriod(spotMarketIndex: number, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
|
|
@@ -125,8 +127,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
125
127
|
getUpdateDiscountMintIx(discountMint: PublicKey): Promise<TransactionInstruction>;
|
|
126
128
|
updateSpotMarketMarginWeights(spotMarketIndex: number, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number): Promise<TransactionSignature>;
|
|
127
129
|
getUpdateSpotMarketMarginWeightsIx(spotMarketIndex: number, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number): Promise<TransactionInstruction>;
|
|
128
|
-
updateSpotMarketBorrowRate(spotMarketIndex: number, optimalUtilization: number, optimalBorrowRate: number, optimalMaxRate: number): Promise<TransactionSignature>;
|
|
129
|
-
getUpdateSpotMarketBorrowRateIx(spotMarketIndex: number, optimalUtilization: number, optimalBorrowRate: number, optimalMaxRate: number): Promise<TransactionInstruction>;
|
|
130
|
+
updateSpotMarketBorrowRate(spotMarketIndex: number, optimalUtilization: number, optimalBorrowRate: number, optimalMaxRate: number, minBorrowRate?: number | undefined): Promise<TransactionSignature>;
|
|
131
|
+
getUpdateSpotMarketBorrowRateIx(spotMarketIndex: number, optimalUtilization: number, optimalBorrowRate: number, optimalMaxRate: number, minBorrowRate?: number | undefined): Promise<TransactionInstruction>;
|
|
130
132
|
updateSpotMarketAssetTier(spotMarketIndex: number, assetTier: AssetTier): Promise<TransactionSignature>;
|
|
131
133
|
getUpdateSpotMarketAssetTierIx(spotMarketIndex: number, assetTier: AssetTier): Promise<TransactionInstruction>;
|
|
132
134
|
updateSpotMarketStatus(spotMarketIndex: number, marketStatus: MarketStatus): Promise<TransactionSignature>;
|
package/lib/adminClient.js
CHANGED
|
@@ -829,6 +829,23 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
829
829
|
},
|
|
830
830
|
});
|
|
831
831
|
}
|
|
832
|
+
async updateSpotMarketMaxTokenBorrows(spotMarketIndex, maxTokenBorrows) {
|
|
833
|
+
const updateSpotMarketMaxTokenBorrowsIx = await this.getUpdateSpotMarketMaxTokenBorrowsIx(spotMarketIndex, maxTokenBorrows);
|
|
834
|
+
const tx = await this.buildTransaction(updateSpotMarketMaxTokenBorrowsIx);
|
|
835
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
836
|
+
return txSig;
|
|
837
|
+
}
|
|
838
|
+
async getUpdateSpotMarketMaxTokenBorrowsIx(spotMarketIndex, maxTokenBorrows) {
|
|
839
|
+
return this.program.instruction.updateSpotMarketMaxTokenBorrows(maxTokenBorrows, {
|
|
840
|
+
accounts: {
|
|
841
|
+
admin: this.isSubscribed
|
|
842
|
+
? this.getStateAccount().admin
|
|
843
|
+
: this.wallet.publicKey,
|
|
844
|
+
state: await this.getStatePublicKey(),
|
|
845
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
846
|
+
},
|
|
847
|
+
});
|
|
848
|
+
}
|
|
832
849
|
async updateSpotMarketScaleInitialAssetWeightStart(spotMarketIndex, scaleInitialAssetWeightStart) {
|
|
833
850
|
const updateSpotMarketScaleInitialAssetWeightStartIx = await this.getUpdateSpotMarketScaleInitialAssetWeightStartIx(spotMarketIndex, scaleInitialAssetWeightStart);
|
|
834
851
|
const tx = await this.buildTransaction(updateSpotMarketScaleInitialAssetWeightStartIx);
|
|
@@ -1150,14 +1167,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1150
1167
|
},
|
|
1151
1168
|
});
|
|
1152
1169
|
}
|
|
1153
|
-
async updateSpotMarketBorrowRate(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate) {
|
|
1154
|
-
const updateSpotMarketBorrowRateIx = await this.getUpdateSpotMarketBorrowRateIx(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate);
|
|
1170
|
+
async updateSpotMarketBorrowRate(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate, minBorrowRate) {
|
|
1171
|
+
const updateSpotMarketBorrowRateIx = await this.getUpdateSpotMarketBorrowRateIx(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate, minBorrowRate);
|
|
1155
1172
|
const tx = await this.buildTransaction(updateSpotMarketBorrowRateIx);
|
|
1156
1173
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1157
1174
|
return txSig;
|
|
1158
1175
|
}
|
|
1159
|
-
async getUpdateSpotMarketBorrowRateIx(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate) {
|
|
1160
|
-
return await this.program.instruction.updateSpotMarketBorrowRate(optimalUtilization, optimalBorrowRate, optimalMaxRate, {
|
|
1176
|
+
async getUpdateSpotMarketBorrowRateIx(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate, minBorrowRate) {
|
|
1177
|
+
return await this.program.instruction.updateSpotMarketBorrowRate(optimalUtilization, optimalBorrowRate, optimalMaxRate, minBorrowRate, {
|
|
1161
1178
|
accounts: {
|
|
1162
1179
|
admin: this.isSubscribed
|
|
1163
1180
|
? this.getStateAccount().admin
|
|
@@ -13,7 +13,13 @@ export declare class BlockhashSubscriber {
|
|
|
13
13
|
getBlockhashCacheSize(): number;
|
|
14
14
|
getLatestBlockHeight(): number;
|
|
15
15
|
getLatestBlockHeightContext(): Context | undefined;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Returns the latest cached blockhash, based on an offset from the latest obtained
|
|
18
|
+
* @param offset Offset to use, defaulting to 0
|
|
19
|
+
* @param offsetType If 'seconds', it will use calculate the actual element offset based on the update interval; otherwise it will return a fixed index
|
|
20
|
+
* @returns Cached blockhash at the given offset, or undefined
|
|
21
|
+
*/
|
|
22
|
+
getLatestBlockhash(offset?: number, offsetType?: 'index' | 'seconds'): BlockhashWithExpiryBlockHeight | undefined;
|
|
17
23
|
pruneBlockhashes(): void;
|
|
18
24
|
updateBlockhash(): Promise<void>;
|
|
19
25
|
subscribe(): Promise<void>;
|
|
@@ -23,11 +23,20 @@ class BlockhashSubscriber {
|
|
|
23
23
|
getLatestBlockHeightContext() {
|
|
24
24
|
return this.latestBlockHeightContext;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Returns the latest cached blockhash, based on an offset from the latest obtained
|
|
28
|
+
* @param offset Offset to use, defaulting to 0
|
|
29
|
+
* @param offsetType If 'seconds', it will use calculate the actual element offset based on the update interval; otherwise it will return a fixed index
|
|
30
|
+
* @returns Cached blockhash at the given offset, or undefined
|
|
31
|
+
*/
|
|
32
|
+
getLatestBlockhash(offset = 0, offsetType = 'index') {
|
|
27
33
|
if (this.blockhashes.length === 0) {
|
|
28
34
|
return undefined;
|
|
29
35
|
}
|
|
30
|
-
const
|
|
36
|
+
const elementOffset = offsetType == 'seconds'
|
|
37
|
+
? Math.floor((offset * 1000) / this.updateIntervalMs)
|
|
38
|
+
: offset;
|
|
39
|
+
const clampedOffset = Math.max(0, Math.min(this.blockhashes.length - 1, elementOffset));
|
|
31
40
|
return this.blockhashes[this.blockhashes.length - 1 - clampedOffset];
|
|
32
41
|
}
|
|
33
42
|
pruneBlockhashes() {
|
|
@@ -228,6 +228,16 @@ exports.MainnetSpotMarkets = [
|
|
|
228
228
|
precisionExp: numericConstants_1.NINE,
|
|
229
229
|
launchTs: 1716595200000,
|
|
230
230
|
},
|
|
231
|
+
{
|
|
232
|
+
symbol: 'USDY',
|
|
233
|
+
marketIndex: 18,
|
|
234
|
+
oracle: new web3_js_1.PublicKey('DiqUGbq5CV8Tjcae1whjrX97qPo6gU7BKAvKNFc2vrX8'),
|
|
235
|
+
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
236
|
+
mint: new web3_js_1.PublicKey('A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6'),
|
|
237
|
+
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
238
|
+
precisionExp: numericConstants_1.SIX,
|
|
239
|
+
launchTs: 1718811089000,
|
|
240
|
+
},
|
|
231
241
|
];
|
|
232
242
|
exports.SpotMarkets = {
|
|
233
243
|
devnet: exports.DevnetSpotMarkets,
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
4
|
-
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode } from './types';
|
|
4
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord } from './types';
|
|
5
5
|
import * as anchor from '@coral-xyz/anchor';
|
|
6
6
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
7
7
|
import { TokenFaucet } from './tokenFaucet';
|
|
@@ -99,7 +99,9 @@ export declare class DriftClient {
|
|
|
99
99
|
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
100
100
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
101
101
|
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
102
|
+
getSerumV3FulfillmentConfigs(): Promise<SerumV3FulfillmentConfigAccount[]>;
|
|
102
103
|
getPhoenixV1FulfillmentConfig(phoenixMarket: PublicKey): Promise<PhoenixV1FulfillmentConfigAccount>;
|
|
104
|
+
getPhoenixV1FulfillmentConfigs(): Promise<PhoenixV1FulfillmentConfigAccount[]>;
|
|
103
105
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
104
106
|
/**
|
|
105
107
|
* Update the wallet to use for drift transactions and linked user account
|
|
@@ -292,6 +294,12 @@ export declare class DriftClient {
|
|
|
292
294
|
*/
|
|
293
295
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN, subAccountId?: number): Promise<TransactionSignature>;
|
|
294
296
|
sendSignedTx(tx: Transaction, opts?: ConfirmOptions): Promise<TransactionSignature>;
|
|
297
|
+
prepareMarketOrderTxs(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo, cancelExistingOrders?: boolean, settlePnl?: boolean): Promise<{
|
|
298
|
+
cancelExistingOrdersTx?: Transaction | VersionedTransaction;
|
|
299
|
+
settlePnlTx?: Transaction | VersionedTransaction;
|
|
300
|
+
fillTx?: Transaction | VersionedTransaction;
|
|
301
|
+
marketOrderTx: Transaction | VersionedTransaction;
|
|
302
|
+
}>;
|
|
295
303
|
/**
|
|
296
304
|
* Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
|
|
297
305
|
* @param orderParams
|
|
@@ -330,11 +338,17 @@ export declare class DriftClient {
|
|
|
330
338
|
direction?: PositionDirection;
|
|
331
339
|
}, placeOrderParams: OrderParams[], txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
332
340
|
placeOrders(params: OrderParams[], txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
341
|
+
preparePlaceOrdersTx(params: OrderParams[], txParams?: TxParams, subAccountId?: number): Promise<{
|
|
342
|
+
placeOrdersTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
|
|
343
|
+
}>;
|
|
333
344
|
getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number): Promise<TransactionInstruction>;
|
|
334
345
|
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerPublicKey?: number): Promise<TransactionSignature>;
|
|
335
346
|
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number): Promise<TransactionInstruction>;
|
|
336
347
|
getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
337
348
|
placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
349
|
+
preparePlaceSpotOrderTx(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<{
|
|
350
|
+
placeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
|
|
351
|
+
}>;
|
|
338
352
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
|
|
339
353
|
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
340
354
|
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
@@ -447,6 +461,11 @@ export declare class DriftClient {
|
|
|
447
461
|
updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
448
462
|
getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
449
463
|
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
464
|
+
preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, exitEarlyIfSimFails?: boolean): Promise<{
|
|
465
|
+
placeAndTakeTx: Transaction | VersionedTransaction;
|
|
466
|
+
cancelExistingOrdersTx: Transaction | VersionedTransaction;
|
|
467
|
+
settlePnlTx: Transaction | VersionedTransaction;
|
|
468
|
+
}>;
|
|
450
469
|
placeAndTakePerpWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, exitEarlyIfSimFails?: boolean): Promise<{
|
|
451
470
|
txSig: TransactionSignature;
|
|
452
471
|
signedCancelExistingOrdersTx?: Transaction;
|
|
@@ -455,6 +474,9 @@ export declare class DriftClient {
|
|
|
455
474
|
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
456
475
|
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
457
476
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
477
|
+
preparePlaceAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<{
|
|
478
|
+
placeAndTakeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
|
|
479
|
+
}>;
|
|
458
480
|
placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
459
481
|
getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
460
482
|
placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
@@ -687,8 +709,13 @@ export declare class DriftClient {
|
|
|
687
709
|
sendTransaction(tx: Transaction | VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
688
710
|
buildTransaction(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[], forceVersionedTransaction?: boolean, recentBlockhash?: BlockhashWithExpiryBlockHeight): Promise<Transaction | VersionedTransaction>;
|
|
689
711
|
buildBulkTransactions(instructions: (TransactionInstruction | TransactionInstruction[])[], txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[], forceVersionedTransaction?: boolean): Promise<(Transaction | VersionedTransaction)[]>;
|
|
690
|
-
|
|
691
|
-
|
|
712
|
+
buildTransactionsMap(instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>, txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[], forceVersionedTransaction?: boolean): Promise<MappedRecord<Record<string, anchor.web3.TransactionInstruction | anchor.web3.TransactionInstruction[]>, anchor.web3.Transaction | anchor.web3.VersionedTransaction>>;
|
|
713
|
+
buildAndSignTransactionsMap(instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>, txParams?: TxParams, txVersion?: TransactionVersion, lookupTables?: AddressLookupTableAccount[], forceVersionedTransaction?: boolean): Promise<{
|
|
714
|
+
signedTxMap: Record<string, anchor.web3.Transaction>;
|
|
715
|
+
signedTxData: SignedTxData[];
|
|
716
|
+
} | {
|
|
717
|
+
signedTxMap: MappedRecord<Record<string, anchor.web3.TransactionInstruction | anchor.web3.TransactionInstruction[]>, anchor.web3.Transaction | anchor.web3.VersionedTransaction>;
|
|
718
|
+
signedTxData: SignedTxData[];
|
|
692
719
|
}>;
|
|
693
720
|
}
|
|
694
721
|
export {};
|
package/lib/driftClient.js
CHANGED
|
@@ -304,10 +304,18 @@ class DriftClient {
|
|
|
304
304
|
const address = await (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
305
305
|
return (await this.program.account.serumV3FulfillmentConfig.fetch(address));
|
|
306
306
|
}
|
|
307
|
+
async getSerumV3FulfillmentConfigs() {
|
|
308
|
+
const accounts = await this.program.account.serumV3FulfillmentConfig.all();
|
|
309
|
+
return accounts.map((account) => account.account);
|
|
310
|
+
}
|
|
307
311
|
async getPhoenixV1FulfillmentConfig(phoenixMarket) {
|
|
308
312
|
const address = await (0, pda_1.getPhoenixFulfillmentConfigPublicKey)(this.program.programId, phoenixMarket);
|
|
309
313
|
return (await this.program.account.phoenixV1FulfillmentConfig.fetch(address));
|
|
310
314
|
}
|
|
315
|
+
async getPhoenixV1FulfillmentConfigs() {
|
|
316
|
+
const accounts = await this.program.account.phoenixV1FulfillmentConfig.all();
|
|
317
|
+
return accounts.map((account) => account.account);
|
|
318
|
+
}
|
|
311
319
|
async fetchMarketLookupTableAccount() {
|
|
312
320
|
if (this.lookupTableAccount)
|
|
313
321
|
return this.lookupTableAccount;
|
|
@@ -1510,6 +1518,40 @@ class DriftClient {
|
|
|
1510
1518
|
const { txSig } = await this.sendTransaction(tx, undefined, opts !== null && opts !== void 0 ? opts : this.opts, true);
|
|
1511
1519
|
return txSig;
|
|
1512
1520
|
}
|
|
1521
|
+
async prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, cancelExistingOrders, settlePnl) {
|
|
1522
|
+
const marketIndex = orderParams.marketIndex;
|
|
1523
|
+
const orderId = userAccount.nextOrderId;
|
|
1524
|
+
const ixPromisesForTxs = {
|
|
1525
|
+
cancelExistingOrdersTx: undefined,
|
|
1526
|
+
settlePnlTx: undefined,
|
|
1527
|
+
fillTx: undefined,
|
|
1528
|
+
marketOrderTx: undefined,
|
|
1529
|
+
};
|
|
1530
|
+
const txKeys = Object.keys(ixPromisesForTxs);
|
|
1531
|
+
ixPromisesForTxs.marketOrderTx = this.getPlaceOrdersIx([orderParams, ...bracketOrdersParams], userAccount.subAccountId);
|
|
1532
|
+
/* Cancel open orders in market if requested */
|
|
1533
|
+
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
1534
|
+
ixPromisesForTxs.cancelExistingOrdersTx = this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, userAccount.subAccountId);
|
|
1535
|
+
}
|
|
1536
|
+
/* Settle PnL after fill if requested */
|
|
1537
|
+
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
1538
|
+
ixPromisesForTxs.settlePnlTx = this.settlePNLIx(userAccountPublicKey, userAccount, marketIndex);
|
|
1539
|
+
}
|
|
1540
|
+
// use versioned transactions if there is a lookup table account and wallet is compatible
|
|
1541
|
+
if (this.txVersion === 0) {
|
|
1542
|
+
ixPromisesForTxs.fillTx = this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1543
|
+
orderId,
|
|
1544
|
+
marketIndex,
|
|
1545
|
+
}, makerInfo, referrerInfo, userAccount.subAccountId);
|
|
1546
|
+
}
|
|
1547
|
+
const ixs = await Promise.all(Object.values(ixPromisesForTxs));
|
|
1548
|
+
const ixsMap = ixs.reduce((acc, ix, i) => {
|
|
1549
|
+
acc[txKeys[i]] = ix;
|
|
1550
|
+
return acc;
|
|
1551
|
+
}, {});
|
|
1552
|
+
const txsMap = (await this.buildTransactionsMap(ixsMap, txParams));
|
|
1553
|
+
return txsMap;
|
|
1554
|
+
}
|
|
1513
1555
|
/**
|
|
1514
1556
|
* Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
|
|
1515
1557
|
* @param orderParams
|
|
@@ -1522,53 +1564,15 @@ class DriftClient {
|
|
|
1522
1564
|
* @returns
|
|
1523
1565
|
*/
|
|
1524
1566
|
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, cancelExistingOrders, settlePnl) {
|
|
1525
|
-
const
|
|
1526
|
-
const
|
|
1527
|
-
const
|
|
1528
|
-
const ixsToSign = [];
|
|
1529
|
-
const keys = {
|
|
1530
|
-
signedCancelExistingOrdersTx: 'signedCancelExistingOrdersTx',
|
|
1531
|
-
signedSettlePnlTx: 'signedSettlePnlTx',
|
|
1532
|
-
signedFillTx: 'signedFillTx',
|
|
1533
|
-
signedMarketOrderTx: 'signedMarketOrderTx',
|
|
1534
|
-
};
|
|
1535
|
-
/* Cancel open orders in market if requested */
|
|
1536
|
-
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
1537
|
-
ixsToSign.push({
|
|
1538
|
-
key: keys.signedCancelExistingOrdersTx,
|
|
1539
|
-
ix: await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, userAccount.subAccountId),
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1542
|
-
/* Settle PnL after fill if requested */
|
|
1543
|
-
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
1544
|
-
ixsToSign.push({
|
|
1545
|
-
key: keys.signedSettlePnlTx,
|
|
1546
|
-
ix: await this.settlePNLIx(userAccountPublicKey, userAccount, marketIndex),
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
// use versioned transactions if there is a lookup table account and wallet is compatible
|
|
1550
|
-
if (this.txVersion === 0) {
|
|
1551
|
-
ixsToSign.push({
|
|
1552
|
-
key: keys.signedFillTx,
|
|
1553
|
-
ix: await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1554
|
-
orderId,
|
|
1555
|
-
marketIndex,
|
|
1556
|
-
}, makerInfo, referrerInfo, userAccount.subAccountId),
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
// Apply the latest blockhash to the txs so that we can sign before sending them
|
|
1560
|
-
ixsToSign.push({
|
|
1561
|
-
key: keys.signedMarketOrderTx,
|
|
1562
|
-
ix: ordersIx,
|
|
1563
|
-
});
|
|
1564
|
-
const signedTransactions = await this.buildAndSignBulkTransactions(ixsToSign.map((ix) => ix.ix), ixsToSign.map((ix) => ix.key), txParams);
|
|
1565
|
-
const { txSig, slot } = await this.sendTransaction(signedTransactions[keys.signedMarketOrderTx], [], this.opts, true);
|
|
1567
|
+
const preppedTxs = await this.prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams, referrerInfo, cancelExistingOrders, settlePnl);
|
|
1568
|
+
const signedTxs = (await this.txHandler.getSignedTransactionMap(preppedTxs, this.wallet)).signedTxMap;
|
|
1569
|
+
const { txSig, slot } = await this.sendTransaction(signedTxs.marketOrderTx, [], this.opts, true);
|
|
1566
1570
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1567
1571
|
return {
|
|
1568
1572
|
txSig,
|
|
1569
|
-
signedFillTx:
|
|
1570
|
-
signedCancelExistingOrdersTx:
|
|
1571
|
-
signedSettlePnlTx:
|
|
1573
|
+
signedFillTx: signedTxs.fillTx,
|
|
1574
|
+
signedCancelExistingOrdersTx: signedTxs.cancelExistingOrdersTx,
|
|
1575
|
+
signedSettlePnlTx: signedTxs.settlePnlTx,
|
|
1572
1576
|
};
|
|
1573
1577
|
}
|
|
1574
1578
|
async placePerpOrder(orderParams, txParams, subAccountId) {
|
|
@@ -1780,9 +1784,16 @@ class DriftClient {
|
|
|
1780
1784
|
return txSig;
|
|
1781
1785
|
}
|
|
1782
1786
|
async placeOrders(params, txParams, subAccountId) {
|
|
1783
|
-
const { txSig } = await this.sendTransaction(
|
|
1787
|
+
const { txSig } = await this.sendTransaction((await this.preparePlaceOrdersTx(params, txParams, subAccountId))
|
|
1788
|
+
.placeOrdersTx, [], this.opts, false);
|
|
1784
1789
|
return txSig;
|
|
1785
1790
|
}
|
|
1791
|
+
async preparePlaceOrdersTx(params, txParams, subAccountId) {
|
|
1792
|
+
const tx = await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams);
|
|
1793
|
+
return {
|
|
1794
|
+
placeOrdersTx: tx,
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1786
1797
|
async getPlaceOrdersIx(params, subAccountId) {
|
|
1787
1798
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1788
1799
|
const readablePerpMarketIndex = [];
|
|
@@ -1893,11 +1904,18 @@ class DriftClient {
|
|
|
1893
1904
|
});
|
|
1894
1905
|
}
|
|
1895
1906
|
async placeSpotOrder(orderParams, txParams, subAccountId) {
|
|
1896
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1907
|
+
const { txSig, slot } = await this.sendTransaction((await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId))
|
|
1908
|
+
.placeSpotOrderTx, [], this.opts, false);
|
|
1897
1909
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1898
1910
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1899
1911
|
return txSig;
|
|
1900
1912
|
}
|
|
1913
|
+
async preparePlaceSpotOrderTx(orderParams, txParams, subAccountId) {
|
|
1914
|
+
const tx = await this.buildTransaction(await this.getPlaceSpotOrderIx(orderParams, subAccountId), txParams);
|
|
1915
|
+
return {
|
|
1916
|
+
placeSpotOrderTx: tx,
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1901
1919
|
async getPlaceSpotOrderIx(orderParams, subAccountId) {
|
|
1902
1920
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
1903
1921
|
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
@@ -2500,13 +2518,12 @@ class DriftClient {
|
|
|
2500
2518
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2501
2519
|
return txSig;
|
|
2502
2520
|
}
|
|
2503
|
-
async
|
|
2521
|
+
async preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails) {
|
|
2504
2522
|
const placeAndTakeIxs = [];
|
|
2505
|
-
const txsToSign =
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
settlePnlTx: 'settlePnlTx',
|
|
2523
|
+
const txsToSign = {
|
|
2524
|
+
placeAndTakeTx: undefined,
|
|
2525
|
+
cancelExistingOrdersTx: undefined,
|
|
2526
|
+
settlePnlTx: undefined,
|
|
2510
2527
|
};
|
|
2511
2528
|
// Get recent block hash so that we can re-use it for all transactions. Makes this logic run faster with fewer RPC requests
|
|
2512
2529
|
const recentBlockHash = await this.txHandler.getLatestBlockhashForTransaction();
|
|
@@ -2532,29 +2549,20 @@ class DriftClient {
|
|
|
2532
2549
|
earlyExitFailedPlaceAndTakeSim = true;
|
|
2533
2550
|
return;
|
|
2534
2551
|
}
|
|
2535
|
-
txsToSign.
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
computeUnits: simulationResult.computeUnits,
|
|
2540
|
-
}, undefined, undefined, undefined, recentBlockHash),
|
|
2541
|
-
});
|
|
2552
|
+
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, {
|
|
2553
|
+
...txParamsWithoutImplicitSimulation,
|
|
2554
|
+
computeUnits: simulationResult.computeUnits,
|
|
2555
|
+
}, undefined, undefined, undefined, recentBlockHash);
|
|
2542
2556
|
}
|
|
2543
2557
|
else {
|
|
2544
|
-
txsToSign.
|
|
2545
|
-
key: keys.placeAndTakeIx,
|
|
2546
|
-
tx: await this.buildTransaction(placeAndTakeIxs, txParams, undefined, undefined, undefined, recentBlockHash),
|
|
2547
|
-
});
|
|
2558
|
+
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, txParams, undefined, undefined, undefined, recentBlockHash);
|
|
2548
2559
|
}
|
|
2549
2560
|
return;
|
|
2550
2561
|
};
|
|
2551
2562
|
const prepCancelOrderTx = async () => {
|
|
2552
2563
|
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
2553
2564
|
const cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, subAccountId);
|
|
2554
|
-
txsToSign.
|
|
2555
|
-
key: keys.cancelExistingOrdersTx,
|
|
2556
|
-
tx: await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion, undefined, undefined, recentBlockHash),
|
|
2557
|
-
});
|
|
2565
|
+
txsToSign.cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion, undefined, undefined, recentBlockHash);
|
|
2558
2566
|
}
|
|
2559
2567
|
return;
|
|
2560
2568
|
};
|
|
@@ -2562,10 +2570,7 @@ class DriftClient {
|
|
|
2562
2570
|
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
2563
2571
|
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
2564
2572
|
const settlePnlIx = await this.settlePNLIx(userAccountPublicKey, this.getUserAccount(subAccountId), orderParams.marketIndex);
|
|
2565
|
-
txsToSign.
|
|
2566
|
-
key: keys.settlePnlTx,
|
|
2567
|
-
tx: await this.buildTransaction([settlePnlIx], txParams, this.txVersion, undefined, undefined, recentBlockHash),
|
|
2568
|
-
});
|
|
2573
|
+
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion, undefined, undefined, recentBlockHash);
|
|
2569
2574
|
}
|
|
2570
2575
|
return;
|
|
2571
2576
|
};
|
|
@@ -2577,13 +2582,17 @@ class DriftClient {
|
|
|
2577
2582
|
if (earlyExitFailedPlaceAndTakeSim) {
|
|
2578
2583
|
return null;
|
|
2579
2584
|
}
|
|
2580
|
-
|
|
2581
|
-
|
|
2585
|
+
return txsToSign;
|
|
2586
|
+
}
|
|
2587
|
+
async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails) {
|
|
2588
|
+
const txsToSign = await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams, txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails);
|
|
2589
|
+
const signedTxs = (await this.txHandler.getSignedTransactionMap(txsToSign, this.provider.wallet)).signedTxMap;
|
|
2590
|
+
const { txSig, slot } = await this.sendTransaction(signedTxs.placeAndTakeTx, [], this.opts, true);
|
|
2582
2591
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2583
2592
|
return {
|
|
2584
2593
|
txSig,
|
|
2585
|
-
signedCancelExistingOrdersTx: signedTxs
|
|
2586
|
-
signedSettlePnlTx: signedTxs
|
|
2594
|
+
signedCancelExistingOrdersTx: signedTxs.cancelExistingOrdersTx,
|
|
2595
|
+
signedSettlePnlTx: signedTxs.settlePnlTx,
|
|
2587
2596
|
};
|
|
2588
2597
|
}
|
|
2589
2598
|
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId) {
|
|
@@ -2684,8 +2693,14 @@ class DriftClient {
|
|
|
2684
2693
|
remainingAccounts,
|
|
2685
2694
|
});
|
|
2686
2695
|
}
|
|
2696
|
+
async preparePlaceAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
2697
|
+
const tx = await this.buildTransaction(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo, subAccountId), txParams);
|
|
2698
|
+
return {
|
|
2699
|
+
placeAndTakeSpotOrderTx: tx,
|
|
2700
|
+
};
|
|
2701
|
+
}
|
|
2687
2702
|
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
2688
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
2703
|
+
const { txSig, slot } = await this.sendTransaction((await this.preparePlaceAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams, subAccountId)).placeAndTakeSpotOrderTx, [], this.opts, false);
|
|
2689
2704
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2690
2705
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
2691
2706
|
return txSig;
|
|
@@ -2876,9 +2891,9 @@ class DriftClient {
|
|
|
2876
2891
|
oraclePriceOffset: newOraclePriceOffset || null,
|
|
2877
2892
|
triggerPrice: newTriggerPrice || null,
|
|
2878
2893
|
triggerCondition: newTriggerCondition || null,
|
|
2879
|
-
auctionDuration: auctionDuration ||
|
|
2880
|
-
auctionStartPrice: auctionStartPrice ||
|
|
2881
|
-
auctionEndPrice: auctionEndPrice ||
|
|
2894
|
+
auctionDuration: auctionDuration || null,
|
|
2895
|
+
auctionStartPrice: auctionStartPrice || null,
|
|
2896
|
+
auctionEndPrice: auctionEndPrice || null,
|
|
2882
2897
|
reduceOnly: reduceOnly != undefined ? reduceOnly : null,
|
|
2883
2898
|
postOnly: postOnly != undefined ? postOnly : null,
|
|
2884
2899
|
immediateOrCancel: immediateOrCancel != undefined ? immediateOrCancel : null,
|
|
@@ -3658,9 +3673,21 @@ class DriftClient {
|
|
|
3658
3673
|
forceVersionedTransaction,
|
|
3659
3674
|
});
|
|
3660
3675
|
}
|
|
3661
|
-
async
|
|
3676
|
+
async buildTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
|
|
3677
|
+
return this.txHandler.buildTransactionsMap({
|
|
3678
|
+
instructionsMap,
|
|
3679
|
+
txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
|
|
3680
|
+
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
3681
|
+
connection: this.connection,
|
|
3682
|
+
preFlightCommitment: this.opts.preflightCommitment,
|
|
3683
|
+
fetchMarketLookupTableAccount: this.fetchMarketLookupTableAccount.bind(this),
|
|
3684
|
+
lookupTables,
|
|
3685
|
+
forceVersionedTransaction,
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
async buildAndSignTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
|
|
3662
3689
|
return this.txHandler.buildAndSignTransactionMap({
|
|
3663
|
-
|
|
3690
|
+
instructionsMap,
|
|
3664
3691
|
txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
|
|
3665
3692
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
3666
3693
|
connection: this.connection,
|
|
@@ -3668,7 +3695,6 @@ class DriftClient {
|
|
|
3668
3695
|
fetchMarketLookupTableAccount: this.fetchMarketLookupTableAccount.bind(this),
|
|
3669
3696
|
lookupTables,
|
|
3670
3697
|
forceVersionedTransaction,
|
|
3671
|
-
keys,
|
|
3672
3698
|
});
|
|
3673
3699
|
}
|
|
3674
3700
|
}
|
|
@@ -8,19 +8,32 @@ const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
|
8
8
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
9
|
const prelaunchOracleClient_1 = require("../oracles/prelaunchOracleClient");
|
|
10
10
|
const switchboardClient_1 = require("../oracles/switchboardClient");
|
|
11
|
+
const pythPullClient_1 = require("../oracles/pythPullClient");
|
|
11
12
|
function getOracleClient(oracleSource, connection, program) {
|
|
12
13
|
if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
|
|
13
14
|
return new pythClient_1.PythClient(connection);
|
|
14
15
|
}
|
|
16
|
+
if ((0, types_1.isVariant)(oracleSource, 'pythPull')) {
|
|
17
|
+
return new pythPullClient_1.PythPullClient(connection);
|
|
18
|
+
}
|
|
15
19
|
if ((0, types_1.isVariant)(oracleSource, 'pyth1K')) {
|
|
16
20
|
return new pythClient_1.PythClient(connection, new anchor_1.BN(1000));
|
|
17
21
|
}
|
|
22
|
+
if ((0, types_1.isVariant)(oracleSource, 'pyth1KPull')) {
|
|
23
|
+
return new pythPullClient_1.PythPullClient(connection, new anchor_1.BN(1000));
|
|
24
|
+
}
|
|
18
25
|
if ((0, types_1.isVariant)(oracleSource, 'pyth1M')) {
|
|
19
26
|
return new pythClient_1.PythClient(connection, new anchor_1.BN(1000000));
|
|
20
27
|
}
|
|
28
|
+
if ((0, types_1.isVariant)(oracleSource, 'pyth1MPull')) {
|
|
29
|
+
return new pythPullClient_1.PythPullClient(connection, new anchor_1.BN(1000000));
|
|
30
|
+
}
|
|
21
31
|
if ((0, types_1.isVariant)(oracleSource, 'pythStableCoin')) {
|
|
22
32
|
return new pythClient_1.PythClient(connection, undefined, true);
|
|
23
33
|
}
|
|
34
|
+
if ((0, types_1.isVariant)(oracleSource, 'pythStableCoinPull')) {
|
|
35
|
+
return new pythPullClient_1.PythPullClient(connection, undefined, true);
|
|
36
|
+
}
|
|
24
37
|
if ((0, types_1.isVariant)(oracleSource, 'switchboard')) {
|
|
25
38
|
return new switchboardClient_1.SwitchboardClient(connection);
|
|
26
39
|
}
|
package/lib/idl/drift.json
CHANGED
|
@@ -9254,6 +9254,18 @@
|
|
|
9254
9254
|
},
|
|
9255
9255
|
{
|
|
9256
9256
|
"name": "Prelaunch"
|
|
9257
|
+
},
|
|
9258
|
+
{
|
|
9259
|
+
"name": "PythPull"
|
|
9260
|
+
},
|
|
9261
|
+
{
|
|
9262
|
+
"name": "Pyth1KPull"
|
|
9263
|
+
},
|
|
9264
|
+
{
|
|
9265
|
+
"name": "Pyth1MPull"
|
|
9266
|
+
},
|
|
9267
|
+
{
|
|
9268
|
+
"name": "PythStableCoinPull"
|
|
9257
9269
|
}
|
|
9258
9270
|
]
|
|
9259
9271
|
}
|
|
@@ -11992,6 +12004,11 @@
|
|
|
11992
12004
|
"code": 6266,
|
|
11993
12005
|
"name": "OracleStaleForAMM",
|
|
11994
12006
|
"msg": "OracleStaleForAMM"
|
|
12007
|
+
},
|
|
12008
|
+
{
|
|
12009
|
+
"code": 6267,
|
|
12010
|
+
"name": "UnableToParsePullOracleMessage",
|
|
12011
|
+
"msg": "Unable to parse pull oracle message"
|
|
11995
12012
|
}
|
|
11996
12013
|
]
|
|
11997
12014
|
}
|
package/lib/math/spotBalance.js
CHANGED
|
@@ -237,6 +237,12 @@ function calculateSpotMarketBorrowCapacity(spotMarketAccount, targetBorrowRate)
|
|
|
237
237
|
else {
|
|
238
238
|
remainingCapacity = anchor_1.BN.max(numericConstants_1.ZERO, totalCapacity.sub(tokenBorrowAmount));
|
|
239
239
|
}
|
|
240
|
+
if (spotMarketAccount.maxTokenBorrowsFraction > 0) {
|
|
241
|
+
const maxTokenBorrows = spotMarketAccount.maxTokenDeposits
|
|
242
|
+
.mul(new anchor_1.BN(spotMarketAccount.maxTokenBorrowsFraction))
|
|
243
|
+
.divn(10000);
|
|
244
|
+
remainingCapacity = anchor_1.BN.min(remainingCapacity, anchor_1.BN.max(numericConstants_1.ZERO, maxTokenBorrows.sub(tokenBorrowAmount)));
|
|
245
|
+
}
|
|
240
246
|
return { totalCapacity, remainingCapacity };
|
|
241
247
|
}
|
|
242
248
|
exports.calculateSpotMarketBorrowCapacity = calculateSpotMarketBorrowCapacity;
|
|
@@ -260,7 +266,7 @@ function calculateInterestRate(bank, delta = numericConstants_1.ZERO) {
|
|
|
260
266
|
.mul(borrowRateSlope)
|
|
261
267
|
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION);
|
|
262
268
|
}
|
|
263
|
-
return interestRate;
|
|
269
|
+
return anchor_1.BN.max(interestRate, new anchor_1.BN(bank.minBorrowRate).mul(numericConstants_2.PERCENTAGE_PRECISION.divn(200)));
|
|
264
270
|
}
|
|
265
271
|
exports.calculateInterestRate = calculateInterestRate;
|
|
266
272
|
function calculateDepositRate(bank, delta = numericConstants_1.ZERO) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bn.js" />
|
|
3
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { OracleClient, OraclePriceData } from './types';
|
|
5
|
+
import { BN, Program } from '@coral-xyz/anchor';
|
|
6
|
+
import { PythSolanaReceiverProgram } from '@pythnetwork/pyth-solana-receiver';
|
|
7
|
+
import { PriceUpdateAccount } from '@pythnetwork/pyth-solana-receiver/lib/PythSolanaReceiver';
|
|
8
|
+
export declare class PythPullClient implements OracleClient {
|
|
9
|
+
private connection;
|
|
10
|
+
private multiple;
|
|
11
|
+
private stableCoin;
|
|
12
|
+
readonly receiver: Program<PythSolanaReceiverProgram>;
|
|
13
|
+
readonly decodeFunc: (name: string, data: Buffer) => PriceUpdateAccount;
|
|
14
|
+
constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
|
|
15
|
+
getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
|
|
16
|
+
getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
|
|
17
|
+
}
|
|
18
|
+
export declare function convertPythPrice(price: BN, exponent: number, multiple: BN): BN;
|