@@ -324,15 +324,15 @@ export class TokenRouterProgram {
324
324
accounts : {
325
325
preparedOrder : PublicKey ;
326
326
senderToken : PublicKey ;
327
- sender ?: PublicKey ;
327
+ senderTokenAuthority ?: PublicKey ;
328
328
} ,
329
329
args : PrepareMarketOrderArgs ,
330
330
) : Promise < { transferAuthority : PublicKey ; ix : TransactionInstruction } > {
331
331
const { preparedOrder, senderToken } = accounts ;
332
332
const { amountIn } = args ;
333
333
334
- let { sender } = accounts ;
335
- sender ??= await ( async ( ) => {
334
+ let { senderTokenAuthority } = accounts ;
335
+ senderTokenAuthority ??= await ( async ( ) => {
336
336
const tokenAccount = await splToken . getAccount (
337
337
this . program . provider . connection ,
338
338
senderToken ,
@@ -344,7 +344,12 @@ export class TokenRouterProgram {
344
344
345
345
return {
346
346
transferAuthority,
347
- ix : splToken . createApproveInstruction ( senderToken , transferAuthority , sender , amountIn ) ,
347
+ ix : splToken . createApproveInstruction (
348
+ senderToken ,
349
+ transferAuthority ,
350
+ senderTokenAuthority ,
351
+ amountIn ,
352
+ ) ,
348
353
} ;
349
354
}
350
355
@@ -353,19 +358,39 @@ export class TokenRouterProgram {
353
358
payer : PublicKey ;
354
359
preparedOrder : PublicKey ;
355
360
senderToken : PublicKey ;
361
+ senderTokenAuthority ?: PublicKey ;
356
362
refundToken ?: PublicKey ;
357
- sender ?: PublicKey ;
363
+ programTransferAuthority ?: PublicKey | null ;
364
+ sender ?: PublicKey | null ;
358
365
} ,
359
- args : PrepareMarketOrderArgs ,
360
- ) : Promise < [ approveIx : TransactionInstruction , prepareIx : TransactionInstruction ] > {
361
- const { payer, preparedOrder, senderToken, sender } = accounts ;
362
- let { refundToken } = accounts ;
366
+ args : { useTransferAuthority ?: boolean } & PrepareMarketOrderArgs ,
367
+ ) : Promise < [ approveIx : TransactionInstruction | null , prepareIx : TransactionInstruction ] > {
368
+ const { payer, preparedOrder, senderToken, senderTokenAuthority } = accounts ;
369
+
370
+ let { refundToken, programTransferAuthority, sender } = accounts ;
363
371
refundToken ??= senderToken ;
364
372
365
- const { transferAuthority, ix : approveIx } = await this . approveTransferAuthorityIx (
366
- { preparedOrder, senderToken, sender } ,
367
- args ,
368
- ) ;
373
+ let { useTransferAuthority } = args ;
374
+ useTransferAuthority ??= true ;
375
+
376
+ let approveIx : TransactionInstruction | null = null ;
377
+
378
+ if ( sender === undefined ) {
379
+ sender = null ;
380
+ }
381
+
382
+ if ( programTransferAuthority === undefined ) {
383
+ if ( useTransferAuthority ) {
384
+ const approveResult = await this . approveTransferAuthorityIx (
385
+ { preparedOrder, senderToken, senderTokenAuthority } ,
386
+ args ,
387
+ ) ;
388
+ programTransferAuthority = approveResult . transferAuthority ;
389
+ approveIx = approveResult . ix ;
390
+ } else {
391
+ programTransferAuthority = null ;
392
+ }
393
+ }
369
394
370
395
const prepareIx = await this . program . methods
371
396
. prepareMarketOrder ( {
@@ -376,7 +401,9 @@ export class TokenRouterProgram {
376
401
. accounts ( {
377
402
payer,
378
403
custodian : this . checkedCustodianComposite ( ) ,
379
- transferAuthority,
404
+ programTransferAuthority,
405
+ // @ts -ignore Sender can be null.
406
+ sender,
380
407
preparedOrder,
381
408
senderToken,
382
409
refundToken,
0 commit comments