@@ -264,103 +264,6 @@ export class DriftClient {
264264 return this . _isSubscribed && this . accountSubscriber . isSubscribed ;
265265 }
266266
267- public async getDepositIntoIsolatedPerpPositionIx ( {
268- perpMarketIndex,
269- amount,
270- spotMarketIndex,
271- subAccountId,
272- userTokenAccount,
273- } : {
274- perpMarketIndex : number ;
275- amount : BN ;
276- spotMarketIndex ?: number ; // defaults to perp.quoteSpotMarketIndex
277- subAccountId ?: number ;
278- userTokenAccount ?: PublicKey ; // defaults ATA for spot market mint
279- } ) : Promise < TransactionInstruction > {
280- const user = await this . getUserAccountPublicKey ( subAccountId ) ;
281- const userStats = this . getUserStatsAccountPublicKey ( ) ;
282- const statePk = await this . getStatePublicKey ( ) ;
283- const perp = this . getPerpMarketAccount ( perpMarketIndex ) ;
284- const spotIndex = spotMarketIndex ?? perp . quoteSpotMarketIndex ;
285- const spot = this . getSpotMarketAccount ( spotIndex ) ;
286-
287- const remainingAccounts = this . getRemainingAccounts ( {
288- userAccounts : [ this . getUserAccount ( subAccountId ) ] ,
289- readablePerpMarketIndex : perpMarketIndex ,
290- writableSpotMarketIndexes : [ spotIndex ] ,
291- } ) ;
292-
293- // token program and transfer hook mints need to be present for deposit
294- this . addTokenMintToRemainingAccounts ( spot , remainingAccounts ) ;
295- if ( this . isTransferHook ( spot ) ) {
296- await this . addExtraAccountMetasToRemainingAccounts (
297- spot . mint ,
298- remainingAccounts
299- ) ;
300- }
301-
302- const tokenProgram = this . getTokenProgramForSpotMarket ( spot ) ;
303- const ata =
304- userTokenAccount ??
305- ( await this . getAssociatedTokenAccount (
306- spotIndex ,
307- false ,
308- tokenProgram
309- ) ) ;
310-
311- return await this . program . instruction . depositIntoIsolatedPerpPosition (
312- spotIndex ,
313- perpMarketIndex ,
314- amount ,
315- {
316- accounts : {
317- state : statePk ,
318- user,
319- userStats,
320- authority : this . wallet . publicKey ,
321- spotMarketVault : spot . vault ,
322- userTokenAccount : ata ,
323- tokenProgram,
324- } ,
325- remainingAccounts,
326- }
327- ) ;
328- }
329-
330- public async getTransferIsolatedPerpPositionDepositIx ( {
331- perpMarketIndex,
332- amount,
333- spotMarketIndex,
334- subAccountId,
335- } : {
336- perpMarketIndex : number ;
337- amount : BN ;
338- spotMarketIndex ?: number ; // defaults to perp.quoteSpotMarketIndex
339- subAccountId ?: number ;
340- } ) : Promise < TransactionInstruction > {
341- const user = await this . getUserAccountPublicKey ( subAccountId ) ;
342- const userStats = this . getUserStatsAccountPublicKey ( ) ;
343- const statePk = await this . getStatePublicKey ( ) ;
344- const perp = this . getPerpMarketAccount ( perpMarketIndex ) ;
345- const spotIndex = spotMarketIndex ?? perp . quoteSpotMarketIndex ;
346- const spot = this . getSpotMarketAccount ( spotIndex ) ;
347-
348- return await this . program . instruction . transferIsolatedPerpPositionDeposit (
349- spotIndex ,
350- perpMarketIndex ,
351- amount ,
352- {
353- accounts : {
354- user,
355- userStats,
356- authority : this . wallet . publicKey ,
357- state : statePk ,
358- spotMarketVault : spot . vault ,
359- } ,
360- }
361- ) ;
362- }
363-
364267 public set isSubscribed ( val : boolean ) {
365268 this . _isSubscribed = val ;
366269 }
@@ -4384,29 +4287,27 @@ export class DriftClient {
43844287
43854288 const txKeys = Object . keys ( ixPromisesForTxs ) ;
43864289
4387-
43884290 const preIxs : TransactionInstruction [ ] = [ ] ;
4389- if ( isVariant ( orderParams . marketType , 'perp' ) && isolatedPositionDepositAmount ?. gt ?.( ZERO ) ) {
4291+ if (
4292+ isVariant ( orderParams . marketType , 'perp' ) &&
4293+ isolatedPositionDepositAmount ?. gt ?.( ZERO )
4294+ ) {
43904295 preIxs . push (
4391- await this . getTransferIsolatedPerpPositionDepositIx ( {
4392- perpMarketIndex : orderParams . marketIndex ,
4393- amount : isolatedPositionDepositAmount as BN ,
4394- subAccountId : userAccount . subAccountId ,
4395- } )
4296+ await this . getTransferIsolatedPerpPositionDepositIx (
4297+ isolatedPositionDepositAmount as BN ,
4298+ orderParams . marketIndex ,
4299+ userAccount . subAccountId
4300+ )
43964301 ) ;
43974302 }
43984303
4399-
44004304 ixPromisesForTxs . marketOrderTx = ( async ( ) => {
44014305 const placeOrdersIx = await this . getPlaceOrdersIx (
44024306 [ orderParams , ...bracketOrdersParams ] ,
44034307 userAccount . subAccountId
44044308 ) ;
44054309 if ( preIxs . length ) {
4406- return [
4407- ...preIxs ,
4408- placeOrdersIx ,
4409- ] as unknown as TransactionInstruction ;
4310+ return [ ...preIxs , placeOrdersIx ] as unknown as TransactionInstruction ;
44104311 }
44114312 return placeOrdersIx ;
44124313 } ) ( ) ;
@@ -4530,11 +4431,11 @@ export class DriftClient {
45304431 const preIxs : TransactionInstruction [ ] = [ ] ;
45314432 if ( isolatedPositionDepositAmount ?. gt ?.( ZERO ) ) {
45324433 preIxs . push (
4533- await this . getTransferIsolatedPerpPositionDepositIx ( {
4534- perpMarketIndex : orderParams . marketIndex ,
4535- amount : isolatedPositionDepositAmount as BN ,
4536- subAccountId,
4537- } )
4434+ await this . getTransferIsolatedPerpPositionDepositIx (
4435+ isolatedPositionDepositAmount as BN ,
4436+ orderParams . marketIndex ,
4437+ subAccountId
4438+ )
45384439 ) ;
45394440 }
45404441
@@ -4918,7 +4819,6 @@ export class DriftClient {
49184819 useMarketLastSlotCache : true ,
49194820 } ) ;
49204821
4921-
49224822 return await this . program . instruction . cancelOrders (
49234823 marketType ?? null ,
49244824 marketIndex ?? null ,
@@ -4993,13 +4893,16 @@ export class DriftClient {
49934893 const preIxs : TransactionInstruction [ ] = [ ] ;
49944894 if ( params ?. length === 1 ) {
49954895 const p = params [ 0 ] ;
4996- if ( isVariant ( p . marketType , 'perp' ) && isolatedPositionDepositAmount ?. gt ?.( ZERO ) ) {
4896+ if (
4897+ isVariant ( p . marketType , 'perp' ) &&
4898+ isolatedPositionDepositAmount ?. gt ?.( ZERO )
4899+ ) {
49974900 preIxs . push (
4998- await this . getTransferIsolatedPerpPositionDepositIx ( {
4999- perpMarketIndex : p . marketIndex ,
5000- amount : isolatedPositionDepositAmount as BN ,
5001- subAccountId,
5002- } )
4901+ await this . getTransferIsolatedPerpPositionDepositIx (
4902+ isolatedPositionDepositAmount as BN ,
4903+ p . marketIndex ,
4904+ subAccountId
4905+ )
50034906 ) ;
50044907 }
50054908 }
@@ -6470,13 +6373,16 @@ export class DriftClient {
64706373 subAccountId
64716374 ) ;
64726375
6473- if ( isVariant ( orderParams . marketType , 'perp' ) && isolatedPositionDepositAmount ?. gt ?.( ZERO ) ) {
6376+ if (
6377+ isVariant ( orderParams . marketType , 'perp' ) &&
6378+ isolatedPositionDepositAmount ?. gt ?.( ZERO )
6379+ ) {
64746380 placeAndTakeIxs . push (
6475- await this . getTransferIsolatedPerpPositionDepositIx ( {
6476- perpMarketIndex : orderParams . marketIndex ,
6477- amount : isolatedPositionDepositAmount as BN ,
6478- subAccountId,
6479- } )
6381+ await this . getTransferIsolatedPerpPositionDepositIx (
6382+ isolatedPositionDepositAmount as BN ,
6383+ orderParams . marketIndex ,
6384+ subAccountId
6385+ )
64806386 ) ;
64816387 }
64826388
@@ -10758,4 +10664,4 @@ export class DriftClient {
1075810664 forceVersionedTransaction,
1075910665 } ) ;
1076010666 }
10761- }
10667+ }
0 commit comments