Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ability to pass in feePayer to Provider methods [WIP] #2186

Merged
merged 12 commits into from Dec 5, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Add ability to set args after setting accounts and retrieving pubkyes ([#2160](https://github.com/coral-xyz/anchor/pull/2160))
- ts: Add `.prepare()` to builder pattern ([#2160](https://github.com/coral-xyz/anchor/pull/2160))
- spl: Add `freeze_delegated_account` and `thaw_delegated_account` wrappers ([#2164](https://github.com/coral-xyz/anchor/pull/2164))
- ts: Add `feePayer` check to `AnchorProvider` methods, so that anchor writes the provider's wallet as fee payer if fee payer isn't already set ([#2186](https://github.com/coral-xyz/anchor/pull/2186))
- ts: Add nested PDA inference ([#2194](https://github.com/coral-xyz/anchor/pull/2194))
- ts: Add ability to resolve missing accounts with a custom resolver ([#2194](https://github.com/coral-xyz/anchor/pull/2194))
- ts: Update the Solana web3 library used by anchor ts to version 1.64.0 ([#2220](https://github.com/coral-xyz/anchor/issues/2220))
Expand Down
12 changes: 9 additions & 3 deletions ts/packages/anchor/src/provider.ts
Expand Up @@ -132,7 +132,8 @@ export class AnchorProvider implements Provider {
opts = this.opts;
}

tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = (
await this.connection.getLatestBlockhash(opts.preflightCommitment)
).blockhash;
Expand Down Expand Up @@ -172,6 +173,9 @@ export class AnchorProvider implements Provider {

/**
* Similar to `send`, but for an array of transactions and signers.
*
* @param txWithSigners Array of transactions and signers.
* @param opts Transaction confirmation options.
*/
async sendAll(
txWithSigners: { tx: Transaction; signers?: Signer[] }[],
Expand All @@ -188,7 +192,8 @@ export class AnchorProvider implements Provider {
let tx = r.tx;
let signers = r.signers ?? [];

tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = blockhash.blockhash;

signers.forEach((kp) => {
Expand Down Expand Up @@ -226,7 +231,8 @@ export class AnchorProvider implements Provider {
commitment?: Commitment,
includeAccounts?: boolean | PublicKey[]
): Promise<SuccessfulTxSimulationResponse> {
tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = (
await this.connection.getLatestBlockhash(
commitment ?? this.connection.commitment
Expand Down