Skip to content

Commit 8cc07e0

Browse files
authored
[ FIX ] posaune0423/fix tx fee payer (#1837)
1 parent fc066b8 commit 8cc07e0

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

sdk/src/driftClient.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ export class DriftClient {
11021102
this.wallet.publicKey // only allow payer to initialize own user stats account
11031103
),
11041104
authority: this.wallet.publicKey,
1105-
payer: this.wallet.publicKey,
1105+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
11061106
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
11071107
systemProgram: anchor.web3.SystemProgram.programId,
11081108
state: await this.getStatePublicKey(),
@@ -1142,7 +1142,7 @@ export class DriftClient {
11421142
accounts: {
11431143
signedMsgUserOrders: signedMsgUserAccountPublicKey,
11441144
authority,
1145-
payer: this.wallet.publicKey,
1145+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
11461146
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
11471147
systemProgram: anchor.web3.SystemProgram.programId,
11481148
},
@@ -1183,7 +1183,7 @@ export class DriftClient {
11831183
accounts: {
11841184
signedMsgUserOrders: signedMsgUserAccountPublicKey,
11851185
authority,
1186-
payer: this.wallet.publicKey,
1186+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
11871187
systemProgram: anchor.web3.SystemProgram.programId,
11881188
user: await getUserAccountPublicKey(
11891189
this.program.programId,
@@ -1321,7 +1321,7 @@ export class DriftClient {
13211321
authority ?? this.wallet.publicKey
13221322
),
13231323
authority: authority ?? this.wallet.publicKey,
1324-
payer: this.wallet.publicKey,
1324+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
13251325
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
13261326
systemProgram: anchor.web3.SystemProgram.programId,
13271327
},
@@ -1407,7 +1407,7 @@ export class DriftClient {
14071407
user: userAccountPublicKey,
14081408
userStats: this.getUserStatsAccountPublicKey(),
14091409
authority: this.wallet.publicKey,
1410-
payer: this.wallet.publicKey,
1410+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
14111411
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
14121412
systemProgram: anchor.web3.SystemProgram.programId,
14131413
state: await this.getStatePublicKey(),
@@ -1457,7 +1457,7 @@ export class DriftClient {
14571457
user: userAccountPublicKey,
14581458
authority: this.wallet.publicKey,
14591459
userStats: this.getUserStatsAccountPublicKey(),
1460-
payer: this.wallet.publicKey,
1460+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
14611461
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
14621462
systemProgram: anchor.web3.SystemProgram.programId,
14631463
},
@@ -8630,7 +8630,7 @@ export class DriftClient {
86308630
this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
86318631
),
86328632
authority: this.wallet.publicKey,
8633-
payer: this.wallet.publicKey,
8633+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
86348634
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
86358635
systemProgram: anchor.web3.SystemProgram.programId,
86368636
state: await this.getStatePublicKey(),
@@ -9743,7 +9743,7 @@ export class DriftClient {
97439743
const tx = await asV0Tx({
97449744
connection: this.connection,
97459745
ixs: [pullIx],
9746-
payer: this.wallet.publicKey,
9746+
payer: this.wallet.payer?.publicKey ?? this.wallet.publicKey,
97479747
computeUnitLimitMultiple: 1.3,
97489748
lookupTables: await this.fetchAllLookupTableAccounts(),
97499749
});

sdk/src/tx/baseTxSender.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,18 @@ export abstract class BaseTxSender implements TxSender {
173173

174174
if (preSigned) {
175175
signedTx = tx;
176-
// @ts-ignore
177-
} else if (this.wallet.payer) {
178-
// @ts-ignore
179-
tx.sign((additionalSigners ?? []).concat(this.wallet.payer));
180-
signedTx = tx;
181176
} else {
177+
// Sign with user first for instruction authorities
182178
signedTx = await this.txHandler.signVersionedTx(
183179
tx,
184180
additionalSigners,
185181
undefined,
186182
this.wallet
187183
);
184+
// Add payer signature if available
185+
if (this.wallet.payer) {
186+
signedTx.sign([this.wallet.payer]);
187+
}
188188
}
189189

190190
if (opts === undefined) {

sdk/src/tx/txHandler.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class TxHandler {
191191

192192
[wallet, confirmationOpts] = this.getProps(wallet, confirmationOpts);
193193

194-
tx.feePayer = wallet.publicKey;
194+
tx.feePayer = wallet.payer?.publicKey ?? wallet.publicKey;
195195
recentBlockhash = recentBlockhash
196196
? recentBlockhash
197197
: await this.getLatestBlockhashForTransaction();
@@ -398,7 +398,7 @@ export class TxHandler {
398398
[wallet] = this.getProps(wallet);
399399

400400
const message = new TransactionMessage({
401-
payerKey: wallet.publicKey,
401+
payerKey: wallet.payer?.publicKey ?? wallet.publicKey,
402402
recentBlockhash: recentBlockhash.blockhash,
403403
instructions: ixs,
404404
}).compileToLegacyMessage();
@@ -420,7 +420,7 @@ export class TxHandler {
420420
[wallet] = this.getProps(wallet);
421421

422422
const message = new TransactionMessage({
423-
payerKey: wallet.publicKey,
423+
payerKey: wallet.payer?.publicKey ?? wallet.publicKey,
424424
recentBlockhash: recentBlockhash.blockhash,
425425
instructions: ixs,
426426
}).compileToV0Message(lookupTableAccounts);
@@ -649,7 +649,8 @@ export class TxHandler {
649649
for (const tx of Object.values(txsMap)) {
650650
if (!tx) continue;
651651
tx.recentBlockhash = recentBlockhash.blockhash;
652-
tx.feePayer = wallet?.publicKey ?? this.wallet?.publicKey;
652+
tx.feePayer =
653+
wallet?.payer?.publicKey ?? wallet?.publicKey ?? this.wallet?.publicKey;
653654

654655
// @ts-ignore
655656
tx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
@@ -689,7 +690,8 @@ export class TxHandler {
689690
// Extra handling for legacy transactions
690691
for (const [_key, tx] of filteredTxEntries) {
691692
if (this.isLegacyTransaction(tx)) {
692-
(tx as Transaction).feePayer = wallet.publicKey;
693+
(tx as Transaction).feePayer =
694+
wallet.payer?.publicKey ?? wallet.publicKey;
693695
}
694696
}
695697

0 commit comments

Comments
 (0)