@drift-labs/sdk 2.13.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/dlob/DLOB.js +1 -1
- package/lib/driftClient.d.ts +33 -33
- package/lib/driftClient.js +68 -68
- package/lib/events/types.d.ts +1 -0
- package/lib/idl/drift.json +1 -1
- package/lib/math/funding.d.ts +1 -1
- package/lib/math/funding.js +6 -6
- package/lib/math/spotBalance.js +2 -2
- package/lib/token/index.js +1 -1
- package/lib/user.d.ts +8 -9
- package/lib/user.js +108 -113
- package/package.json +3 -3
- package/src/constants/numericConstants.ts +1 -0
- package/src/constants/perpMarkets.ts +10 -0
- package/src/dlob/DLOB.ts +1 -1
- package/src/driftClient.ts +209 -68
- package/src/events/types.ts +15 -0
- package/src/idl/drift.json +1 -1
- package/src/math/funding.ts +7 -8
- package/src/math/spotBalance.ts +14 -7
- package/src/token/index.ts +1 -1
- package/src/user.ts +187 -184
|
@@ -15,6 +15,7 @@ export declare const TEN_THOUSAND: BN;
|
|
|
15
15
|
export declare const BN_MAX: BN;
|
|
16
16
|
export declare const TEN_MILLION: BN;
|
|
17
17
|
export declare const MAX_LEVERAGE: BN;
|
|
18
|
+
export declare const MAX_LEVERAGE_ORDER_SIZE: BN;
|
|
18
19
|
export declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
19
20
|
export declare const PERCENTAGE_PRECISION: BN;
|
|
20
21
|
export declare const CONCENTRATION_PRECISION: BN;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.LIQUIDATION_PCT_PRECISION = void 0;
|
|
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.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.LIQUIDATION_PCT_PRECISION = exports.BID_ASK_SPREAD_PRECISION = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const __1 = require("../");
|
|
7
7
|
exports.ZERO = new __1.BN(0);
|
|
@@ -19,6 +19,7 @@ exports.TEN_THOUSAND = new __1.BN(10000);
|
|
|
19
19
|
exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
|
|
20
20
|
exports.TEN_MILLION = exports.TEN_THOUSAND.mul(exports.TEN_THOUSAND);
|
|
21
21
|
exports.MAX_LEVERAGE = new __1.BN(5);
|
|
22
|
+
exports.MAX_LEVERAGE_ORDER_SIZE = new __1.BN('18446744073709551615');
|
|
22
23
|
exports.PERCENTAGE_PRECISION_EXP = new __1.BN(6);
|
|
23
24
|
exports.PERCENTAGE_PRECISION = new __1.BN(10).pow(exports.PERCENTAGE_PRECISION_EXP);
|
|
24
25
|
exports.CONCENTRATION_PRECISION = exports.PERCENTAGE_PRECISION;
|
|
@@ -34,6 +34,16 @@ exports.DevnetPerpMarkets = [
|
|
|
34
34
|
launchTs: 1637691133472,
|
|
35
35
|
oracleSource: __1.OracleSource.PYTH,
|
|
36
36
|
},
|
|
37
|
+
{
|
|
38
|
+
fullName: 'Aptos',
|
|
39
|
+
category: ['L1', 'Infra'],
|
|
40
|
+
symbol: 'APT-PERP',
|
|
41
|
+
baseAssetSymbol: 'APT',
|
|
42
|
+
marketIndex: 3,
|
|
43
|
+
oracle: new web3_js_1.PublicKey('5d2QJ6u2NveZufmJ4noHja5EHs3Bv1DUMPLG5xfasSVs'),
|
|
44
|
+
launchTs: 1675610186000,
|
|
45
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
46
|
+
},
|
|
37
47
|
];
|
|
38
48
|
exports.MainnetPerpMarkets = [
|
|
39
49
|
{
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -553,7 +553,7 @@ class DLOB {
|
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
555
|
isRestingLimitOrder(order, slot) {
|
|
556
|
-
return order.postOnly || new __1.BN(slot).sub(order.slot).gte(new __1.BN(
|
|
556
|
+
return order.postOnly || new __1.BN(slot).sub(order.slot).gte(new __1.BN(45));
|
|
557
557
|
}
|
|
558
558
|
*getLimitBids(marketIndex, slot, marketType, oraclePriceData) {
|
|
559
559
|
if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ export declare class DriftClient {
|
|
|
100
100
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
101
101
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
102
102
|
getUserAccountsForAuthority(authority: PublicKey): Promise<UserAccount[]>;
|
|
103
|
-
deleteUser(subAccountId?: number): Promise<TransactionSignature>;
|
|
103
|
+
deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
104
104
|
getUser(subAccountId?: number): User;
|
|
105
105
|
getUsers(): User[];
|
|
106
106
|
getUserStats(): UserStats;
|
|
@@ -144,17 +144,17 @@ export declare class DriftClient {
|
|
|
144
144
|
initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
145
145
|
withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
146
146
|
getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
|
|
147
|
-
transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionSignature>;
|
|
147
|
+
transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
148
148
|
getTransferDepositIx(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionInstruction>;
|
|
149
|
-
updateSpotMarketCumulativeInterest(marketIndex: number): Promise<TransactionSignature>;
|
|
149
|
+
updateSpotMarketCumulativeInterest(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
150
150
|
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
151
|
-
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionSignature>;
|
|
151
|
+
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
152
152
|
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
|
|
153
|
-
removePerpLpShares(marketIndex: number, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
154
|
-
removePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
153
|
+
removePerpLpShares(marketIndex: number, sharesToBurn?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
154
|
+
removePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
155
155
|
getRemovePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
156
156
|
getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
157
|
-
addPerpLpShares(amount: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
157
|
+
addPerpLpShares(amount: BN, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
158
158
|
getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
|
|
159
159
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
160
160
|
sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
|
|
@@ -166,43 +166,43 @@ export declare class DriftClient {
|
|
|
166
166
|
* @param makerInfo
|
|
167
167
|
* @returns
|
|
168
168
|
*/
|
|
169
|
-
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo): Promise<{
|
|
169
|
+
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo, txParams?: TxParams): Promise<{
|
|
170
170
|
txSig: TransactionSignature;
|
|
171
171
|
signedFillTx: Transaction;
|
|
172
172
|
}>;
|
|
173
|
-
placePerpOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
173
|
+
placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
|
|
174
174
|
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
175
175
|
getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
176
|
-
updateAMMs(marketIndexes: number[]): Promise<TransactionSignature>;
|
|
176
|
+
updateAMMs(marketIndexes: number[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
177
177
|
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
178
|
-
settleExpiredMarket(marketIndex: number): Promise<TransactionSignature>;
|
|
178
|
+
settleExpiredMarket(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
179
179
|
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
180
|
-
settleExpiredMarketPoolsToRevenuePool(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
181
|
-
cancelOrder(orderId?: number): Promise<TransactionSignature>;
|
|
180
|
+
settleExpiredMarketPoolsToRevenuePool(perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
181
|
+
cancelOrder(orderId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
182
182
|
getCancelOrderIx(orderId?: number): Promise<TransactionInstruction>;
|
|
183
|
-
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
183
|
+
cancelOrderByUserId(userOrderId: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
184
184
|
getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
|
|
185
|
-
cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection): Promise<TransactionSignature>;
|
|
185
|
+
cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection, txParams?: TxParams): Promise<TransactionSignature>;
|
|
186
186
|
getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null): Promise<TransactionInstruction>;
|
|
187
|
-
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
187
|
+
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
188
188
|
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
189
|
-
placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
189
|
+
placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
|
|
190
190
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
191
191
|
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
192
192
|
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
193
193
|
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
|
|
194
194
|
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
195
|
-
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
195
|
+
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
|
|
196
196
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
197
|
-
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount): Promise<TransactionSignature>;
|
|
197
|
+
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|
|
198
198
|
getForceCancelOrdersIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
|
|
199
|
-
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
199
|
+
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
200
200
|
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
201
|
-
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
201
|
+
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
202
202
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
203
203
|
placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
204
204
|
getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
205
|
-
placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
205
|
+
placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
206
206
|
getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
207
207
|
/**
|
|
208
208
|
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
@@ -232,35 +232,35 @@ export declare class DriftClient {
|
|
|
232
232
|
settleeUserAccountPublicKey: PublicKey;
|
|
233
233
|
settleeUserAccount: UserAccount;
|
|
234
234
|
}[], marketIndex: number): Promise<TransactionSignature>;
|
|
235
|
-
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
235
|
+
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
236
236
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
237
|
-
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
237
|
+
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
238
238
|
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
239
|
-
liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
239
|
+
liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
240
240
|
getLiquidateSpotIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
241
|
-
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
241
|
+
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
242
242
|
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
243
|
-
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
243
|
+
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
244
244
|
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
245
|
-
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
245
|
+
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
246
246
|
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
247
|
-
resolveSpotBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
247
|
+
resolveSpotBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
248
248
|
getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
249
|
-
updateFundingRate(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionSignature>;
|
|
249
|
+
updateFundingRate(perpMarketIndex: number, oracle: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
250
250
|
getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
|
|
251
|
-
settleFundingPayment(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
251
|
+
settleFundingPayment(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
252
252
|
getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
253
253
|
triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
|
|
254
254
|
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
|
|
255
255
|
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
256
|
-
initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
256
|
+
initializeInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
257
257
|
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
258
258
|
addInsuranceFundStake(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
259
259
|
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
260
260
|
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
261
261
|
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
262
262
|
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
263
|
-
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionSignature>;
|
|
263
|
+
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
264
264
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
265
265
|
sendTransaction(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
266
266
|
}
|
package/lib/driftClient.js
CHANGED
|
@@ -409,7 +409,7 @@ class DriftClient {
|
|
|
409
409
|
]);
|
|
410
410
|
return programAccounts.map((programAccount) => programAccount.account);
|
|
411
411
|
}
|
|
412
|
-
async deleteUser(subAccountId = 0) {
|
|
412
|
+
async deleteUser(subAccountId = 0, txParams) {
|
|
413
413
|
var _a;
|
|
414
414
|
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
415
415
|
const ix = await this.program.instruction.deleteUser({
|
|
@@ -420,7 +420,7 @@ class DriftClient {
|
|
|
420
420
|
state: await this.getStatePublicKey(),
|
|
421
421
|
},
|
|
422
422
|
});
|
|
423
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix), [], this.opts);
|
|
423
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
424
424
|
await ((_a = this.users.get(subAccountId)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
|
|
425
425
|
this.users.delete(subAccountId);
|
|
426
426
|
return txSig;
|
|
@@ -870,8 +870,8 @@ class DriftClient {
|
|
|
870
870
|
remainingAccounts,
|
|
871
871
|
});
|
|
872
872
|
}
|
|
873
|
-
async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId) {
|
|
874
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId)), [], this.opts);
|
|
873
|
+
async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId, txParams) {
|
|
874
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
875
875
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
876
876
|
toSubAccountId === this.activeSubAccountId) {
|
|
877
877
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
@@ -910,8 +910,8 @@ class DriftClient {
|
|
|
910
910
|
remainingAccounts,
|
|
911
911
|
});
|
|
912
912
|
}
|
|
913
|
-
async updateSpotMarketCumulativeInterest(marketIndex) {
|
|
914
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.updateSpotMarketCumulativeInterestIx(marketIndex)), [], this.opts);
|
|
913
|
+
async updateSpotMarketCumulativeInterest(marketIndex, txParams) {
|
|
914
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.updateSpotMarketCumulativeInterestIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
915
915
|
return txSig;
|
|
916
916
|
}
|
|
917
917
|
async updateSpotMarketCumulativeInterestIx(marketIndex) {
|
|
@@ -924,8 +924,8 @@ class DriftClient {
|
|
|
924
924
|
},
|
|
925
925
|
});
|
|
926
926
|
}
|
|
927
|
-
async settleLP(settleeUserAccountPublicKey, marketIndex) {
|
|
928
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex)), [], this.opts);
|
|
927
|
+
async settleLP(settleeUserAccountPublicKey, marketIndex, txParams) {
|
|
928
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
929
929
|
return txSig;
|
|
930
930
|
}
|
|
931
931
|
async settleLPIx(settleeUserAccountPublicKey, marketIndex) {
|
|
@@ -942,12 +942,12 @@ class DriftClient {
|
|
|
942
942
|
remainingAccounts: remainingAccounts,
|
|
943
943
|
});
|
|
944
944
|
}
|
|
945
|
-
async removePerpLpShares(marketIndex, sharesToBurn) {
|
|
946
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn)), [], this.opts);
|
|
945
|
+
async removePerpLpShares(marketIndex, sharesToBurn, txParams) {
|
|
946
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
947
947
|
return txSig;
|
|
948
948
|
}
|
|
949
|
-
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
950
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn)), [], this.opts);
|
|
949
|
+
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn, txParams) {
|
|
950
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
951
951
|
return txSig;
|
|
952
952
|
}
|
|
953
953
|
async getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
@@ -992,8 +992,8 @@ class DriftClient {
|
|
|
992
992
|
remainingAccounts: remainingAccounts,
|
|
993
993
|
});
|
|
994
994
|
}
|
|
995
|
-
async addPerpLpShares(amount, marketIndex) {
|
|
996
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getAddPerpLpSharesIx(amount, marketIndex)), [], this.opts);
|
|
995
|
+
async addPerpLpShares(amount, marketIndex, txParams) {
|
|
996
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getAddPerpLpSharesIx(amount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
997
997
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
998
998
|
return txSig;
|
|
999
999
|
}
|
|
@@ -1034,14 +1034,14 @@ class DriftClient {
|
|
|
1034
1034
|
* @param makerInfo
|
|
1035
1035
|
* @returns
|
|
1036
1036
|
*/
|
|
1037
|
-
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo) {
|
|
1037
|
+
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams) {
|
|
1038
1038
|
const marketIndex = orderParams.marketIndex;
|
|
1039
1039
|
const orderId = userAccount.nextOrderId;
|
|
1040
|
-
const marketOrderTx = utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams));
|
|
1040
|
+
const marketOrderTx = utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
1041
1041
|
const fillTx = utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1042
1042
|
orderId,
|
|
1043
1043
|
marketIndex,
|
|
1044
|
-
}, makerInfo));
|
|
1044
|
+
}, makerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
1045
1045
|
// Apply the latest blockhash to the txs so that we can sign before sending them
|
|
1046
1046
|
const currentBlockHash = (await this.connection.getLatestBlockhash('finalized')).blockhash;
|
|
1047
1047
|
marketOrderTx.recentBlockhash = currentBlockHash;
|
|
@@ -1053,8 +1053,8 @@ class DriftClient {
|
|
|
1053
1053
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1054
1054
|
return { txSig, signedFillTx };
|
|
1055
1055
|
}
|
|
1056
|
-
async placePerpOrder(orderParams) {
|
|
1057
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams)), [], this.opts);
|
|
1056
|
+
async placePerpOrder(orderParams, txParams) {
|
|
1057
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1058
1058
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1059
1059
|
return txSig;
|
|
1060
1060
|
}
|
|
@@ -1081,8 +1081,8 @@ class DriftClient {
|
|
|
1081
1081
|
remainingAccounts,
|
|
1082
1082
|
});
|
|
1083
1083
|
}
|
|
1084
|
-
async updateAMMs(marketIndexes) {
|
|
1085
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
|
|
1084
|
+
async updateAMMs(marketIndexes, txParams) {
|
|
1085
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateAMMsIx(marketIndexes), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1086
1086
|
return txSig;
|
|
1087
1087
|
}
|
|
1088
1088
|
async getUpdateAMMsIx(marketIndexes) {
|
|
@@ -1115,8 +1115,8 @@ class DriftClient {
|
|
|
1115
1115
|
remainingAccounts,
|
|
1116
1116
|
});
|
|
1117
1117
|
}
|
|
1118
|
-
async settleExpiredMarket(marketIndex) {
|
|
1119
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleExpiredMarketIx(marketIndex)), [], this.opts);
|
|
1118
|
+
async settleExpiredMarket(marketIndex, txParams) {
|
|
1119
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleExpiredMarketIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1120
1120
|
return txSig;
|
|
1121
1121
|
}
|
|
1122
1122
|
async getSettleExpiredMarketIx(marketIndex) {
|
|
@@ -1150,7 +1150,7 @@ class DriftClient {
|
|
|
1150
1150
|
remainingAccounts,
|
|
1151
1151
|
});
|
|
1152
1152
|
}
|
|
1153
|
-
async settleExpiredMarketPoolsToRevenuePool(perpMarketIndex) {
|
|
1153
|
+
async settleExpiredMarketPoolsToRevenuePool(perpMarketIndex, txParams) {
|
|
1154
1154
|
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
1155
1155
|
const spotMarketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
1156
1156
|
const ix = await this.program.instruction.settleExpiredMarketPoolsToRevenuePool({
|
|
@@ -1161,11 +1161,11 @@ class DriftClient {
|
|
|
1161
1161
|
perpMarket: perpMarketPublicKey,
|
|
1162
1162
|
},
|
|
1163
1163
|
});
|
|
1164
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix), [], this.opts);
|
|
1164
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1165
1165
|
return txSig;
|
|
1166
1166
|
}
|
|
1167
|
-
async cancelOrder(orderId) {
|
|
1168
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderIx(orderId)), [], this.opts);
|
|
1167
|
+
async cancelOrder(orderId, txParams) {
|
|
1168
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderIx(orderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1169
1169
|
return txSig;
|
|
1170
1170
|
}
|
|
1171
1171
|
async getCancelOrderIx(orderId) {
|
|
@@ -1183,8 +1183,8 @@ class DriftClient {
|
|
|
1183
1183
|
remainingAccounts,
|
|
1184
1184
|
});
|
|
1185
1185
|
}
|
|
1186
|
-
async cancelOrderByUserId(userOrderId) {
|
|
1187
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
|
|
1186
|
+
async cancelOrderByUserId(userOrderId, txParams) {
|
|
1187
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1188
1188
|
return txSig;
|
|
1189
1189
|
}
|
|
1190
1190
|
async getCancelOrderByUserIdIx(userOrderId) {
|
|
@@ -1205,8 +1205,8 @@ class DriftClient {
|
|
|
1205
1205
|
remainingAccounts,
|
|
1206
1206
|
});
|
|
1207
1207
|
}
|
|
1208
|
-
async cancelOrders(marketType, marketIndex, direction) {
|
|
1209
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrdersIx(marketType, marketIndex, direction)), [], this.opts);
|
|
1208
|
+
async cancelOrders(marketType, marketIndex, direction, txParams) {
|
|
1209
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrdersIx(marketType, marketIndex, direction), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1210
1210
|
return txSig;
|
|
1211
1211
|
}
|
|
1212
1212
|
async getCancelOrdersIx(marketType, marketIndex, direction) {
|
|
@@ -1236,8 +1236,8 @@ class DriftClient {
|
|
|
1236
1236
|
remainingAccounts,
|
|
1237
1237
|
});
|
|
1238
1238
|
}
|
|
1239
|
-
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo) {
|
|
1240
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo)), [], this.opts);
|
|
1239
|
+
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams) {
|
|
1240
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1241
1241
|
return txSig;
|
|
1242
1242
|
}
|
|
1243
1243
|
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
|
|
@@ -1293,8 +1293,8 @@ class DriftClient {
|
|
|
1293
1293
|
remainingAccounts,
|
|
1294
1294
|
});
|
|
1295
1295
|
}
|
|
1296
|
-
async placeSpotOrder(orderParams) {
|
|
1297
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceSpotOrderIx(orderParams)), [], this.opts);
|
|
1296
|
+
async placeSpotOrder(orderParams, txParams) {
|
|
1297
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceSpotOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1298
1298
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1299
1299
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1300
1300
|
return txSig;
|
|
@@ -1477,8 +1477,8 @@ class DriftClient {
|
|
|
1477
1477
|
isSigner: false,
|
|
1478
1478
|
});
|
|
1479
1479
|
}
|
|
1480
|
-
async triggerOrder(userAccountPublicKey, user, order) {
|
|
1481
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getTriggerOrderIx(userAccountPublicKey, user, order)), [], this.opts);
|
|
1480
|
+
async triggerOrder(userAccountPublicKey, user, order, txParams) {
|
|
1481
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1482
1482
|
return txSig;
|
|
1483
1483
|
}
|
|
1484
1484
|
async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
|
|
@@ -1508,8 +1508,8 @@ class DriftClient {
|
|
|
1508
1508
|
remainingAccounts,
|
|
1509
1509
|
});
|
|
1510
1510
|
}
|
|
1511
|
-
async forceCancelOrders(userAccountPublicKey, user) {
|
|
1512
|
-
const { txSig } = await this.txSender.send(utils_1.wrapInTx(await this.getForceCancelOrdersIx(userAccountPublicKey, user)), [], this.opts);
|
|
1511
|
+
async forceCancelOrders(userAccountPublicKey, user, txParams) {
|
|
1512
|
+
const { txSig } = await this.txSender.send(utils_1.wrapInTx(await this.getForceCancelOrdersIx(userAccountPublicKey, user), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1513
1513
|
return txSig;
|
|
1514
1514
|
}
|
|
1515
1515
|
async getForceCancelOrdersIx(userAccountPublicKey, userAccount) {
|
|
@@ -1528,8 +1528,8 @@ class DriftClient {
|
|
|
1528
1528
|
remainingAccounts,
|
|
1529
1529
|
});
|
|
1530
1530
|
}
|
|
1531
|
-
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo) {
|
|
1532
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo)), [], this.opts);
|
|
1531
|
+
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams) {
|
|
1532
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1533
1533
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1534
1534
|
return txSig;
|
|
1535
1535
|
}
|
|
@@ -1582,8 +1582,8 @@ class DriftClient {
|
|
|
1582
1582
|
remainingAccounts,
|
|
1583
1583
|
});
|
|
1584
1584
|
}
|
|
1585
|
-
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo) {
|
|
1586
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo)), [], this.opts);
|
|
1585
|
+
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams) {
|
|
1586
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1587
1587
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1588
1588
|
return txSig;
|
|
1589
1589
|
}
|
|
@@ -1680,8 +1680,8 @@ class DriftClient {
|
|
|
1680
1680
|
remainingAccounts,
|
|
1681
1681
|
});
|
|
1682
1682
|
}
|
|
1683
|
-
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
|
|
1684
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo)), [], this.opts);
|
|
1683
|
+
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo, txParams) {
|
|
1684
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1685
1685
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1686
1686
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1687
1687
|
return txSig;
|
|
@@ -1807,7 +1807,7 @@ class DriftClient {
|
|
|
1807
1807
|
if (!openOrder) {
|
|
1808
1808
|
throw new Error(`No open order with user order id ${userOrderId.toString()}`);
|
|
1809
1809
|
}
|
|
1810
|
-
const cancelOrderIx = await this.
|
|
1810
|
+
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
1811
1811
|
const newOrderParams = {
|
|
1812
1812
|
orderType: openOrder.orderType,
|
|
1813
1813
|
marketType: openOrder.marketType,
|
|
@@ -1853,8 +1853,8 @@ class DriftClient {
|
|
|
1853
1853
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1854
1854
|
return txSig;
|
|
1855
1855
|
}
|
|
1856
|
-
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
1857
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex)), [], this.opts);
|
|
1856
|
+
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams) {
|
|
1857
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1858
1858
|
return txSig;
|
|
1859
1859
|
}
|
|
1860
1860
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -1873,8 +1873,8 @@ class DriftClient {
|
|
|
1873
1873
|
remainingAccounts: remainingAccounts,
|
|
1874
1874
|
});
|
|
1875
1875
|
}
|
|
1876
|
-
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1877
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice)), [], this.opts);
|
|
1876
|
+
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams) {
|
|
1877
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1878
1878
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1879
1879
|
return txSig;
|
|
1880
1880
|
}
|
|
@@ -1899,8 +1899,8 @@ class DriftClient {
|
|
|
1899
1899
|
remainingAccounts: remainingAccounts,
|
|
1900
1900
|
});
|
|
1901
1901
|
}
|
|
1902
|
-
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1903
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1902
|
+
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
1903
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1904
1904
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1905
1905
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1906
1906
|
return txSig;
|
|
@@ -1926,8 +1926,8 @@ class DriftClient {
|
|
|
1926
1926
|
remainingAccounts: remainingAccounts,
|
|
1927
1927
|
});
|
|
1928
1928
|
}
|
|
1929
|
-
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1930
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1929
|
+
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
1930
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1931
1931
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1932
1932
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1933
1933
|
return txSig;
|
|
@@ -1953,8 +1953,8 @@ class DriftClient {
|
|
|
1953
1953
|
remainingAccounts: remainingAccounts,
|
|
1954
1954
|
});
|
|
1955
1955
|
}
|
|
1956
|
-
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
1957
|
-
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice)), [], this.opts);
|
|
1956
|
+
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams) {
|
|
1957
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1958
1958
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1959
1959
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1960
1960
|
return txSig;
|
|
@@ -1980,8 +1980,8 @@ class DriftClient {
|
|
|
1980
1980
|
remainingAccounts: remainingAccounts,
|
|
1981
1981
|
});
|
|
1982
1982
|
}
|
|
1983
|
-
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
1984
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
1983
|
+
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
1984
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1985
1985
|
return txSig;
|
|
1986
1986
|
}
|
|
1987
1987
|
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
@@ -2010,8 +2010,8 @@ class DriftClient {
|
|
|
2010
2010
|
remainingAccounts: remainingAccounts,
|
|
2011
2011
|
});
|
|
2012
2012
|
}
|
|
2013
|
-
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
2014
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
2013
|
+
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2014
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2015
2015
|
return txSig;
|
|
2016
2016
|
}
|
|
2017
2017
|
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
@@ -2039,8 +2039,8 @@ class DriftClient {
|
|
|
2039
2039
|
remainingAccounts: remainingAccounts,
|
|
2040
2040
|
});
|
|
2041
2041
|
}
|
|
2042
|
-
async updateFundingRate(perpMarketIndex, oracle) {
|
|
2043
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateFundingRateIx(perpMarketIndex, oracle)), [], this.opts);
|
|
2042
|
+
async updateFundingRate(perpMarketIndex, oracle, txParams) {
|
|
2043
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateFundingRateIx(perpMarketIndex, oracle), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2044
2044
|
return txSig;
|
|
2045
2045
|
}
|
|
2046
2046
|
async getUpdateFundingRateIx(perpMarketIndex, oracle) {
|
|
@@ -2053,8 +2053,8 @@ class DriftClient {
|
|
|
2053
2053
|
},
|
|
2054
2054
|
});
|
|
2055
2055
|
}
|
|
2056
|
-
async settleFundingPayment(userAccountPublicKey) {
|
|
2057
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleFundingPaymentIx(userAccountPublicKey)), [], this.opts);
|
|
2056
|
+
async settleFundingPayment(userAccountPublicKey, txParams) {
|
|
2057
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleFundingPaymentIx(userAccountPublicKey), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2058
2058
|
return txSig;
|
|
2059
2059
|
}
|
|
2060
2060
|
async getSettleFundingPaymentIx(userAccountPublicKey) {
|
|
@@ -2090,8 +2090,8 @@ class DriftClient {
|
|
|
2090
2090
|
const oracleData = this.getOraclePriceDataAndSlot(oracleKey).data;
|
|
2091
2091
|
return oracleData;
|
|
2092
2092
|
}
|
|
2093
|
-
async initializeInsuranceFundStake(marketIndex) {
|
|
2094
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getInitializeInsuranceFundStakeIx(marketIndex)), [], this.opts);
|
|
2093
|
+
async initializeInsuranceFundStake(marketIndex, txParams) {
|
|
2094
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2095
2095
|
return txSig;
|
|
2096
2096
|
}
|
|
2097
2097
|
async getInitializeInsuranceFundStakeIx(marketIndex) {
|
|
@@ -2225,8 +2225,8 @@ class DriftClient {
|
|
|
2225
2225
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2226
2226
|
return txSig;
|
|
2227
2227
|
}
|
|
2228
|
-
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex) {
|
|
2229
|
-
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex)), [], this.opts);
|
|
2228
|
+
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, txParams) {
|
|
2229
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2230
2230
|
return txSig;
|
|
2231
2231
|
}
|
|
2232
2232
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|
package/lib/events/types.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare type EventMap = {
|
|
|
37
37
|
CurveRecord: Event<CurveRecord>;
|
|
38
38
|
};
|
|
39
39
|
export declare type EventType = keyof EventMap;
|
|
40
|
+
export declare type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord>;
|
|
40
41
|
export interface EventSubscriberEvents {
|
|
41
42
|
newEvent: (event: WrappedEvent<EventType>) => void;
|
|
42
43
|
}
|
package/lib/idl/drift.json
CHANGED
package/lib/math/funding.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { OraclePriceData } from '../oracles/types';
|
|
|
9
9
|
* @param periodAdjustment
|
|
10
10
|
* @returns Estimated funding rate. : Precision //TODO-PRECISION
|
|
11
11
|
*/
|
|
12
|
-
export declare function calculateAllEstimatedFundingRate(market: PerpMarketAccount, oraclePriceData?: OraclePriceData, periodAdjustment?: BN): Promise<[BN, BN, BN, BN, BN]>;
|
|
12
|
+
export declare function calculateAllEstimatedFundingRate(market: PerpMarketAccount, oraclePriceData?: OraclePriceData, periodAdjustment?: BN, now?: BN): Promise<[BN, BN, BN, BN, BN]>;
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
15
|
* @param market
|