@drift-labs/sdk 2.31.1-beta.8 → 2.32.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/VERSION +1 -1
- package/lib/constants/perpMarkets.js +20 -0
- package/lib/dlob/orderBookLevels.js +2 -2
- package/lib/driftClient.d.ts +53 -5
- package/lib/driftClient.js +203 -196
- package/lib/idl/drift.json +31 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/marinade/index.d.ts +11 -0
- package/lib/marinade/index.js +36 -0
- package/lib/marinade/types.d.ts +1963 -0
- package/lib/marinade/types.js +1965 -0
- package/lib/math/spotBalance.d.ts +9 -2
- package/lib/math/spotBalance.js +54 -6
- package/lib/math/superStake.d.ts +22 -0
- package/lib/math/superStake.js +108 -0
- package/lib/math/utils.d.ts +1 -0
- package/lib/math/utils.js +5 -1
- package/lib/orderParams.d.ts +18 -5
- package/lib/orderParams.js +17 -1
- package/lib/user.d.ts +45 -1
- package/lib/user.js +227 -9
- package/package.json +1 -1
- package/src/assert/assert.js +9 -0
- package/src/constants/perpMarkets.ts +20 -0
- package/src/dlob/orderBookLevels.ts +3 -2
- package/src/driftClient.ts +383 -225
- package/src/idl/drift.json +31 -1
- package/src/index.ts +3 -0
- package/src/marinade/idl/idl.json +1962 -0
- package/src/marinade/index.ts +64 -0
- package/src/marinade/types.ts +3925 -0
- package/src/math/spotBalance.ts +83 -5
- package/src/math/superStake.ts +148 -0
- package/src/math/utils.ts +4 -0
- package/src/orderParams.ts +35 -5
- package/src/token/index.js +38 -0
- package/src/user.ts +453 -15
- package/src/util/computeUnits.js +27 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/spot/test.ts +156 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.28
|
|
@@ -124,6 +124,16 @@ exports.DevnetPerpMarkets = [
|
|
|
124
124
|
launchTs: 1683125906000,
|
|
125
125
|
oracleSource: __1.OracleSource.PYTH,
|
|
126
126
|
},
|
|
127
|
+
{
|
|
128
|
+
fullName: 'RNDR',
|
|
129
|
+
category: ['Infra'],
|
|
130
|
+
symbol: 'RNDR-PERP',
|
|
131
|
+
baseAssetSymbol: 'RNDR',
|
|
132
|
+
marketIndex: 12,
|
|
133
|
+
oracle: new web3_js_1.PublicKey('C2QvUPBiU3fViSyqA4nZgGyYqLgYf9PRpd8B8oLoo48w'),
|
|
134
|
+
launchTs: 1683125906000,
|
|
135
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
136
|
+
},
|
|
127
137
|
];
|
|
128
138
|
exports.MainnetPerpMarkets = [
|
|
129
139
|
{
|
|
@@ -246,6 +256,16 @@ exports.MainnetPerpMarkets = [
|
|
|
246
256
|
launchTs: 1683125906000,
|
|
247
257
|
oracleSource: __1.OracleSource.PYTH,
|
|
248
258
|
},
|
|
259
|
+
{
|
|
260
|
+
fullName: 'RNDR',
|
|
261
|
+
category: ['Infra'],
|
|
262
|
+
symbol: 'RNDR-PERP',
|
|
263
|
+
baseAssetSymbol: 'RNDR',
|
|
264
|
+
marketIndex: 12,
|
|
265
|
+
oracle: new web3_js_1.PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
|
|
266
|
+
launchTs: 1683125906000,
|
|
267
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
268
|
+
},
|
|
249
269
|
];
|
|
250
270
|
exports.PerpMarkets = {
|
|
251
271
|
devnet: exports.DevnetPerpMarkets,
|
|
@@ -92,7 +92,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, })
|
|
|
92
92
|
pegMultiplier: updatedAmm.pegMultiplier,
|
|
93
93
|
};
|
|
94
94
|
const getL2Bids = function* () {
|
|
95
|
-
while (numBids < numOrders) {
|
|
95
|
+
while (numBids < numOrders && baseSize.gt(__1.ZERO)) {
|
|
96
96
|
const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'base', baseSize, __1.SwapDirection.ADD);
|
|
97
97
|
const quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(bidAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), bidAmm.pegMultiplier, __1.SwapDirection.ADD);
|
|
98
98
|
const price = quoteSwapped.mul(__1.BASE_PRECISION).div(baseSize);
|
|
@@ -115,7 +115,7 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, })
|
|
|
115
115
|
pegMultiplier: updatedAmm.pegMultiplier,
|
|
116
116
|
};
|
|
117
117
|
const getL2Asks = function* () {
|
|
118
|
-
while (numAsks < numOrders) {
|
|
118
|
+
while (numAsks < numOrders && askSize.gt(__1.ZERO)) {
|
|
119
119
|
const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, __1.calculateAmmReservesAfterSwap)(askAmm, 'base', askSize, __1.SwapDirection.REMOVE);
|
|
120
120
|
const quoteSwapped = (0, __1.calculateQuoteAssetAmountSwapped)(askAmm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), askAmm.pegMultiplier, __1.SwapDirection.REMOVE);
|
|
121
121
|
const price = quoteSwapped.mul(__1.BASE_PRECISION).div(askSize);
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type RemainingAccountParams = {
|
|
|
19
19
|
userAccounts: UserAccount[];
|
|
20
20
|
writablePerpMarketIndexes?: number[];
|
|
21
21
|
writableSpotMarketIndexes?: number[];
|
|
22
|
-
readablePerpMarketIndex?: number;
|
|
22
|
+
readablePerpMarketIndex?: number | number[];
|
|
23
23
|
readableSpotMarketIndexes?: number[];
|
|
24
24
|
useMarketLastSlotCache?: boolean;
|
|
25
25
|
};
|
|
@@ -44,6 +44,8 @@ export declare class DriftClient {
|
|
|
44
44
|
txSender: TxSender;
|
|
45
45
|
perpMarketLastSlotCache: Map<number, number>;
|
|
46
46
|
spotMarketLastSlotCache: Map<number, number>;
|
|
47
|
+
mustIncludePerpMarketIndexes: Set<number>;
|
|
48
|
+
mustIncludeSpotMarketIndexes: Set<number>;
|
|
47
49
|
authority: PublicKey;
|
|
48
50
|
marketLookupTable: PublicKey;
|
|
49
51
|
lookupTableAccount: AddressLookupTableAccount;
|
|
@@ -114,6 +116,7 @@ export declare class DriftClient {
|
|
|
114
116
|
initializeReferrerName(name: string): Promise<TransactionSignature>;
|
|
115
117
|
updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
|
|
116
118
|
updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
|
|
119
|
+
getUpdateUserMarginTradingEnabledIx(marginTradingEnabled: boolean, subAccountId?: number, userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
117
120
|
updateUserMarginTradingEnabled(marginTradingEnabled: boolean, subAccountId?: number): Promise<TransactionSignature>;
|
|
118
121
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
119
122
|
fetchAllUserAccounts(includeIdle?: boolean): Promise<ProgramAccount<UserAccount>[]>;
|
|
@@ -124,6 +127,7 @@ export declare class DriftClient {
|
|
|
124
127
|
getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
|
|
125
128
|
deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
126
129
|
getUser(subAccountId?: number, authority?: PublicKey): User;
|
|
130
|
+
hasUser(subAccountId?: number, authority?: PublicKey): boolean;
|
|
127
131
|
getUsers(): User[];
|
|
128
132
|
getUserStats(): UserStats;
|
|
129
133
|
fetchReferrerNameAccount(name: string): Promise<ReferrerNameAccount | undefined>;
|
|
@@ -161,7 +165,20 @@ export declare class DriftClient {
|
|
|
161
165
|
* @param amount
|
|
162
166
|
*/
|
|
163
167
|
convertToPricePrecision(amount: BN | number): BN;
|
|
168
|
+
/**
|
|
169
|
+
* Each drift instruction must include perp and sport market accounts in the ix remaining accounts.
|
|
170
|
+
* Use this function to force a subset of markets to be included in the remaining accounts for every ix
|
|
171
|
+
*
|
|
172
|
+
* @param perpMarketIndexes
|
|
173
|
+
* @param spotMarketIndexes
|
|
174
|
+
*/
|
|
175
|
+
mustIncludeMarketsInIx({ perpMarketIndexes, spotMarketIndexes, }: {
|
|
176
|
+
perpMarketIndexes: number[];
|
|
177
|
+
spotMarketIndexes: number[];
|
|
178
|
+
}): void;
|
|
164
179
|
getRemainingAccounts(params: RemainingAccountParams): AccountMeta[];
|
|
180
|
+
addPerpMarketToRemainingAccountMaps(marketIndex: number, writable: boolean, oracleAccountMap: Map<string, AccountMeta>, spotMarketAccountMap: Map<number, AccountMeta>, perpMarketAccountMap: Map<number, AccountMeta>): void;
|
|
181
|
+
addSpotMarketToRemainingAccountMaps(marketIndex: number, writable: boolean, oracleAccountMap: Map<string, AccountMeta>, spotMarketAccountMap: Map<number, AccountMeta>): void;
|
|
165
182
|
getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
|
|
166
183
|
oracleAccountMap: Map<string, AccountMeta>;
|
|
167
184
|
spotMarketAccountMap: Map<number, AccountMeta>;
|
|
@@ -188,10 +205,14 @@ export declare class DriftClient {
|
|
|
188
205
|
deposit(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
189
206
|
getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
|
|
190
207
|
private checkIfAccountExists;
|
|
191
|
-
|
|
208
|
+
getWrappedSolAccountCreationIxs(amount: BN, includeRent?: boolean): Promise<{
|
|
209
|
+
ixs: anchor.web3.TransactionInstruction[];
|
|
210
|
+
signers: Signer[];
|
|
211
|
+
pubkey: PublicKey;
|
|
212
|
+
}>;
|
|
192
213
|
getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
|
|
193
214
|
/**
|
|
194
|
-
* Creates the
|
|
215
|
+
* Creates the User account for a user, and deposits some initial collateral
|
|
195
216
|
* @param amount
|
|
196
217
|
* @param userTokenAccount
|
|
197
218
|
* @param marketIndex
|
|
@@ -252,7 +273,6 @@ export declare class DriftClient {
|
|
|
252
273
|
signedFillTx: Transaction;
|
|
253
274
|
}>;
|
|
254
275
|
placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
|
|
255
|
-
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
256
276
|
getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
257
277
|
updateAMMs(marketIndexes: number[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
258
278
|
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
@@ -270,6 +290,8 @@ export declare class DriftClient {
|
|
|
270
290
|
marketIndex?: number;
|
|
271
291
|
direction?: PositionDirection;
|
|
272
292
|
}, placeOrderParams: OrderParams[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
293
|
+
placeOrders(params: OrderParams[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
294
|
+
getPlaceOrdersIx(params: OrderParams[]): Promise<TransactionInstruction>;
|
|
273
295
|
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
274
296
|
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
275
297
|
getRevertFillIx(): Promise<TransactionInstruction>;
|
|
@@ -305,6 +327,22 @@ export declare class DriftClient {
|
|
|
305
327
|
reduceOnly?: SwapReduceOnly;
|
|
306
328
|
txParams?: TxParams;
|
|
307
329
|
}): Promise<TransactionSignature>;
|
|
330
|
+
getJupiterSwapIx({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, userAccountPublicKey, }: {
|
|
331
|
+
jupiterClient: JupiterClient;
|
|
332
|
+
outMarketIndex: number;
|
|
333
|
+
inMarketIndex: number;
|
|
334
|
+
outAssociatedTokenAccount?: PublicKey;
|
|
335
|
+
inAssociatedTokenAccount?: PublicKey;
|
|
336
|
+
amount: BN;
|
|
337
|
+
slippageBps?: number;
|
|
338
|
+
swapMode?: SwapMode;
|
|
339
|
+
route?: Route;
|
|
340
|
+
reduceOnly?: SwapReduceOnly;
|
|
341
|
+
userAccountPublicKey?: PublicKey;
|
|
342
|
+
}): Promise<{
|
|
343
|
+
ixs: TransactionInstruction[];
|
|
344
|
+
lookupTables: AddressLookupTableAccount[];
|
|
345
|
+
}>;
|
|
308
346
|
/**
|
|
309
347
|
* Get the drift begin_swap and end_swap instructions
|
|
310
348
|
*
|
|
@@ -314,8 +352,10 @@ export declare class DriftClient {
|
|
|
314
352
|
* @param inTokenAccount the token account to move the tokens being sold
|
|
315
353
|
* @param outTokenAccount the token account to receive the tokens being bought
|
|
316
354
|
* @param limitPrice the limit price of the swap
|
|
355
|
+
* @param reduceOnly
|
|
356
|
+
* @param userAccountPublicKey optional, specify a custom userAccountPublicKey to use instead of getting the current user account; can be helpful if the account is being created within the current tx
|
|
317
357
|
*/
|
|
318
|
-
getSwapIx({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, reduceOnly, }: {
|
|
358
|
+
getSwapIx({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, reduceOnly, userAccountPublicKey, }: {
|
|
319
359
|
outMarketIndex: number;
|
|
320
360
|
inMarketIndex: number;
|
|
321
361
|
amountIn: BN;
|
|
@@ -323,10 +363,18 @@ export declare class DriftClient {
|
|
|
323
363
|
outTokenAccount: PublicKey;
|
|
324
364
|
limitPrice?: BN;
|
|
325
365
|
reduceOnly?: SwapReduceOnly;
|
|
366
|
+
userAccountPublicKey?: PublicKey;
|
|
326
367
|
}): Promise<{
|
|
327
368
|
beginSwapIx: TransactionInstruction;
|
|
328
369
|
endSwapIx: TransactionInstruction;
|
|
329
370
|
}>;
|
|
371
|
+
stakeForMSOL({ amount }: {
|
|
372
|
+
amount: BN;
|
|
373
|
+
}): Promise<TxSigAndSlot>;
|
|
374
|
+
getStakeForMSOLIx({ amount, userAccountPublicKey, }: {
|
|
375
|
+
amount: BN;
|
|
376
|
+
userAccountPublicKey?: PublicKey;
|
|
377
|
+
}): Promise<TransactionInstruction[]>;
|
|
330
378
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
|
|
331
379
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
332
380
|
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|