@@ -2877,23 +2877,27 @@ export class DriftClient {
28772877 marketIndex : number ,
28782878 associatedTokenAccount : PublicKey ,
28792879 subAccountId ?: number ,
2880- reduceOnly = false
2880+ reduceOnly = false ,
2881+ overrides ?: {
2882+ authority ?: PublicKey ;
2883+ }
28812884 ) : Promise < TransactionInstruction [ ] > {
28822885 const spotMarketAccount = this . getSpotMarketAccount ( marketIndex ) ;
28832886
28842887 const isSolMarket = spotMarketAccount . mint . equals ( WRAPPED_SOL_MINT ) ;
28852888
2886- const signerAuthority = this . wallet . publicKey ;
2889+ const signer = overrides ?. authority ?? this . wallet . publicKey ;
28872890
28882891 const createWSOLTokenAccount =
2889- isSolMarket && associatedTokenAccount . equals ( signerAuthority ) ;
2892+ isSolMarket && associatedTokenAccount . equals ( signer ) ;
28902893
28912894 const instructions = [ ] ;
28922895
28932896 if ( createWSOLTokenAccount ) {
28942897 const { ixs, pubkey } = await this . getWrappedSolAccountCreationIxs (
28952898 amount ,
2896- true
2899+ true ,
2900+ overrides
28972901 ) ;
28982902
28992903 associatedTokenAccount = pubkey ;
@@ -2907,7 +2911,8 @@ export class DriftClient {
29072911 associatedTokenAccount ,
29082912 subAccountId ,
29092913 reduceOnly ,
2910- true
2914+ true ,
2915+ overrides
29112916 ) ;
29122917
29132918 instructions . push ( depositCollateralIx ) ;
@@ -2917,8 +2922,8 @@ export class DriftClient {
29172922 instructions . push (
29182923 createCloseAccountInstruction (
29192924 associatedTokenAccount ,
2920- signerAuthority ,
2921- signerAuthority ,
2925+ signer ,
2926+ signer ,
29222927 [ ]
29232928 )
29242929 ) ;
@@ -2987,14 +2992,18 @@ export class DriftClient {
29872992 subAccountId ?: number ,
29882993 reduceOnly = false ,
29892994 txParams ?: TxParams ,
2990- initSwiftAccount = false
2995+ initSwiftAccount = false ,
2996+ overrides ?: {
2997+ authority ?: PublicKey ;
2998+ }
29912999 ) : Promise < VersionedTransaction | Transaction > {
29923000 const instructions = await this . getDepositTxnIx (
29933001 amount ,
29943002 marketIndex ,
29953003 associatedTokenAccount ,
29963004 subAccountId ,
2997- reduceOnly
3005+ reduceOnly ,
3006+ overrides
29983007 ) ;
29993008
30003009 if ( initSwiftAccount ) {
@@ -3029,6 +3038,9 @@ export class DriftClient {
30293038 * @param associatedTokenAccount can be the wallet public key if using native sol
30303039 * @param subAccountId subaccountId to deposit
30313040 * @param reduceOnly if true, deposit must not increase account risk
3041+ * @param txParams transaction parameters
3042+ * @param initSwiftAccount if true, initialize a swift account for the user
3043+ * @param overrides allows overriding authority for the deposit transaction
30323044 */
30333045 public async deposit (
30343046 amount : BN ,
@@ -3037,7 +3049,10 @@ export class DriftClient {
30373049 subAccountId ?: number ,
30383050 reduceOnly = false ,
30393051 txParams ?: TxParams ,
3040- initSwiftAccount = false
3052+ initSwiftAccount = false ,
3053+ overrides ?: {
3054+ authority ?: PublicKey ;
3055+ }
30413056 ) : Promise < TransactionSignature > {
30423057 const tx = await this . createDepositTxn (
30433058 amount ,
@@ -3046,7 +3061,8 @@ export class DriftClient {
30463061 subAccountId ,
30473062 reduceOnly ,
30483063 txParams ,
3049- initSwiftAccount
3064+ initSwiftAccount ,
3065+ overrides
30503066 ) ;
30513067
30523068 const { txSig, slot } = await this . sendTransaction ( tx , [ ] , this . opts ) ;
@@ -3060,7 +3076,10 @@ export class DriftClient {
30603076 userTokenAccount : PublicKey ,
30613077 subAccountId ?: number ,
30623078 reduceOnly = false ,
3063- userInitialized = true
3079+ userInitialized = true ,
3080+ overrides ?: {
3081+ authority ?: PublicKey ;
3082+ }
30643083 ) : Promise < TransactionInstruction > {
30653084 const userAccountPublicKey = await getUserAccountPublicKey (
30663085 this . program . programId ,
@@ -3092,6 +3111,7 @@ export class DriftClient {
30923111 ) ;
30933112 }
30943113
3114+ const authority = overrides ?. authority ?? this . wallet . publicKey ;
30953115 const tokenProgram = this . getTokenProgramForSpotMarket ( spotMarketAccount ) ;
30963116 return await this . program . instruction . deposit (
30973117 marketIndex ,
@@ -3105,7 +3125,7 @@ export class DriftClient {
31053125 user : userAccountPublicKey ,
31063126 userStats : this . getUserStatsAccountPublicKey ( ) ,
31073127 userTokenAccount : userTokenAccount ,
3108- authority : this . wallet . publicKey ,
3128+ authority,
31093129 tokenProgram,
31103130 } ,
31113131 remainingAccounts,
@@ -3125,14 +3145,17 @@ export class DriftClient {
31253145
31263146 public async getWrappedSolAccountCreationIxs (
31273147 amount : BN ,
3128- includeRent ?: boolean
3148+ includeRent ?: boolean ,
3149+ overrides ?: {
3150+ authority ?: PublicKey ;
3151+ }
31293152 ) : Promise < {
31303153 ixs : anchor . web3 . TransactionInstruction [ ] ;
31313154 /** @deprecated - this array is always going to be empty, in the current implementation */
31323155 signers : Signer [ ] ;
31333156 pubkey : PublicKey ;
31343157 } > {
3135- const authority = this . wallet . publicKey ;
3158+ const authority = overrides ?. authority ?? this . wallet . publicKey ;
31363159
31373160 // Generate a random seed for wrappedSolAccount.
31383161 const seed = Keypair . generate ( ) . publicKey . toBase58 ( ) . slice ( 0 , 32 ) ;
0 commit comments