Skip to content

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

Merged
Henry-E merged 12 commits into
otter-sec:masterfrom
surfertas:surfertas/anchorts/add-feepayer
Dec 5, 2022
Merged

allow ability to pass in feePayer to Provider methods [WIP]#2186
Henry-E merged 12 commits into
otter-sec:masterfrom
surfertas:surfertas/anchorts/add-feepayer

Conversation

@surfertas

Copy link
Copy Markdown
Contributor

Allow passing in an optional feePayer param to the send methods of the Provider class. This allows the caller to specify who pays for the transaction, as opposed to hard coding it to the connected wallet.

closes #2180

Reference discord discussion:

https://discord.com/channels/889577356681945098/891724485177245717/1020066171329982605

@vercel

vercel Bot commented Sep 16, 2022

Copy link
Copy Markdown

@surfertas is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@Henry-E

Henry-E commented Sep 16, 2022

Copy link
Copy Markdown

Instead of adding a new argument, could the code instead check if feePayer has already been set in the transaction and if not then it assigns the provider's wallet?

If you could also add something to the changelog in the PR that references this PR that would be helpful too.

@Henry-E

Henry-E commented Sep 17, 2022

Copy link
Copy Markdown

Looks good to me! Will merge it in shortly

@surfertas surfertas changed the title allow ability to pass in feePayer to Provider methods allow ability to pass in feePayer to Provider methods [WIP] Sep 17, 2022
@surfertas

surfertas commented Sep 17, 2022

Copy link
Copy Markdown
Contributor Author

@Henry-E Was wondering if we should be using a strict equality check for undefined or use a null check to handle both cases?

@Henry-E

Henry-E commented Sep 17, 2022

Copy link
Copy Markdown

In the default transaction it looks like feePayer is actually undefined

    Transaction {
      signatures: [],
      feePayer: undefined,
      instructions: [],
      recentBlockhash: undefined,
      lastValidBlockHeight: undefined,
      nonceInfo: undefined,
      _message: undefined,
      _json: undefined
    }

so you should be checking

if (tx.feePayer === undefined)

You should probably add a client test then to /misc, to send a tx, then load up the processed transaction to confirm that the fee payer was assigned correctly, since it looks like this code probably wouldn't have worked.

@surfertas

Copy link
Copy Markdown
Contributor Author

Yeah sounds good, technically the null check will capture undefined as well afiak, but the strict equality check for undefined is more concise! Will put that test up.

@armaniferrante

Copy link
Copy Markdown
Contributor

Yeah sounds good, technically the null check will capture undefined as well afiak, but the strict equality check for undefined is more concise! Will put that test up.

I'm not sure this is true. We should check for both?

@surfertas

Copy link
Copy Markdown
Contributor Author

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null

tx.feePayer == null will handle both null and undefined. Shall we go with that?

@Henry-E

Henry-E commented Sep 23, 2022

Copy link
Copy Markdown

Sure, if tx.feepayer == null works for both then that should be fine. Just to be safe lets add a client test to tests/misc that sends three transactions

  • one transaction with the usual undefined feepayer
  • one with a custom fee payer
  • one transaction with a feepayer manually set to null
    Then check the transaction signature to confirm that all three have the correct fee payer.

(I might be able to add these tests next week if you aren't able to add them)

@surfertas

Copy link
Copy Markdown
Contributor Author

@Henry-E sorry hate to ask, but if you have time can you throw up thoses tests? Just got backed up with work. Sincere apologies.

@Henry-E

Henry-E commented Nov 22, 2022

Copy link
Copy Markdown
  • It's a pretty useful added feature that fixes some over reaching behaviour of the anchor provider. Namely it allows the transaction creator to add their own feePayer which isn't over written by the anchor provider default wallet.
  • It doesn't have tests which isn't great but the logic seems simple enough and the logical or || should handle the null case nicely when the feePayer is undefined or null (or 0?).

Just going to wait for tests to run again and then merge.

@Henry-E
Henry-E merged commit 50724df into otter-sec:master Dec 5, 2022
Henry-E added a commit to Henry-E/anchor that referenced this pull request Dec 6, 2022
…c#2186)

* allow ability to pass in feePayer to Provider methods

* align comments

* prettier

* check if feePayer set, handle if not

* remove unnecessary spaces in comments

* update changelog

* strict equality check

* use null check

* use logical or

* use logical or

Co-authored-by: Henry-E <henry.elder@adaptcentre.ie>
akash-osec pushed a commit to akash-osec/anchor that referenced this pull request Mar 25, 2026
…c#2186)

* allow ability to pass in feePayer to Provider methods

* align comments

* prettier

* check if feePayer set, handle if not

* remove unnecessary spaces in comments

* update changelog

* strict equality check

* use null check

* use logical or

* use logical or

Co-authored-by: Henry-E <henry.elder@adaptcentre.ie>
@jamie-osec jamie-osec added this to the Pre-1.0 milestone Jun 24, 2026
akash-osec pushed a commit to akash-osec/anchor that referenced this pull request Jul 25, 2026
…c#2186)

* allow ability to pass in feePayer to Provider methods

* align comments

* prettier

* check if feePayer set, handle if not

* remove unnecessary spaces in comments

* update changelog

* strict equality check

* use null check

* use logical or

* use logical or

Co-authored-by: Henry-E <henry.elder@adaptcentre.ie>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for setting a transaction feePayer, instead of enforcing the connected wallet to always be the feePayer.

4 participants