Skip to content

solana-client-tools: expose Wallet::fee_payer_key() helper #3767

@karl-dz

Description

@karl-dz

Target repo

doublezerofoundation/doublezero-offchain

Background

In crates/solana-client-tools/src/payer.rs, Wallet has:

pub struct Wallet {
    pub connection: SolanaConnection,
    pub signer: Keypair,
    pub compute_unit_price_ix: Option<Instruction>,
    pub verbose: bool,
    pub fee_payer: Option<Keypair>,
    pub dry_run: bool,
}

When --fee-payer is unset, the signer (-k) pays. When --fee-payer is set, that keypair pays instead. Today there is no helper for "give me the pubkey that will actually pay this transaction's fees", so call sites that need it have to spell out:

wallet.fee_payer.as_ref().map(Signer::pubkey).unwrap_or_else(|| wallet.pubkey())

This came up during code review of doublezerofoundation/doublezero-offchain#373, where configure.rs was passing wallet_key (the signer pubkey) as the funding address to create_associated_token_account_idempotent. When --fee-payer is set, the funding address should be the fee-payer's pubkey, not the signer's. The in-PR fix uses the boilerplate above. A Wallet::fee_payer_key(&self) -> Pubkey helper would prevent every future call site from re-deriving it (and getting it wrong).

Proposal

Add to impl Wallet in crates/solana-client-tools/src/payer.rs:

/// Pubkey of the account that pays transaction fees and account rent for
/// this wallet: the `--fee-payer` keypair if set, otherwise the signer.
pub fn fee_payer_key(&self) -> Pubkey {
    self.fee_payer.as_ref().map(Signer::pubkey).unwrap_or_else(|| self.signer.pubkey())
}

Then audit existing call sites that pass wallet.pubkey() or wallet_key as a "funding address" or "rent payer". They likely all want wallet.fee_payer_key() instead.

Cross-references

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions