-
Notifications
You must be signed in to change notification settings - Fork 607
chore(docs): Update docs on fees and various other updates #12929
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
Changes from 7 commits
fc3bb9d
650680e
7a622fb
bcfeb46
dde9091
d365a96
c827034
2776606
4dd848a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,27 +10,28 @@ This guide shows the various ways this can be done. For more of a background see | |
|
|
||
| ## Methods to pay a tx fee | ||
|
|
||
| ### Natively via an existing balance of fee juice | ||
| 1. Natively via an existing balance of fee juice | ||
|
|
||
| Either your own account or someone else's address has a balance of fee juice, and the transaction is paid for from this balance. | ||
|
|
||
| ### Natively via a balance of fee juice to be claimed | ||
| 2. Natively via a balance of fee juice bridged from L1 to be claimed on L2 | ||
|
|
||
| Processing this transaction first claims bridged fee juice then is paid for from the balance, all in the same public/private tx. | ||
|
|
||
| ### Privately or publicly via a Fee Paying Contract | ||
| 3. Privately or publicly via a Fee Paying Contract | ||
|
|
||
| A fee paying contract (FPC) is created and nominates a token that it accepts to then pay for txs in fee juice. So a user doesn't need to hold fee juice, they only need the token that the FPC accepts. | ||
| A fee paying contract (FPC) is created and nominates a token that it accepts to then pay for transactions in fee juice. So a user doesn't need to hold fee juice, they only need the token that the FPC accepts. | ||
|
|
||
| ### Sponsored Fee Paying Contract (SponsoredFPC) | ||
| 4. Sponsored Fee Paying Contract (SponsoredFPC) | ||
|
|
||
| The most straightforward way to pay for a transaction is via the sponsored fee payment method, bootstrapping some transactions by skipping the need to bridge fee juice to the account. This method uses a type of fee paying contract configured to pay for a number of transactions without requiring payment. | ||
| The most straightforward way to pay for a transaction is via the sponsored fee payment method, bootstrapping some transactions by skipping the need to bridge fee juice to the account. This method uses a type of fee paying contract configured to pay for a number of transactions without requiring payment, but also requires that there is a sponsor to pay for the transactions. | ||
|
critesjosh marked this conversation as resolved.
|
||
|
|
||
| ## Bridging fee-juice | ||
| ## Bridging Fee Juice | ||
|
|
||
| To first get fee juice into an account it needs to be bridged from L1. You can skip this section if you want to first make a transaction via the SponsoredFPC. | ||
|
critesjosh marked this conversation as resolved.
|
||
|
|
||
| :::note | ||
|
|
||
| See here to [Bridge Fee Juice](../../../developers/reference/environment_reference/cli_wallet_reference#bridge-fee-juice) via the CLI wallet. | ||
|
|
||
| ::: | ||
|
|
@@ -51,50 +52,84 @@ Create a new fee juice portal manager and bridge fee juice publicly to Aztec: | |
|
|
||
| #include_code bridge_fee_juice yarn-project/end-to-end/src/spartan/setup_test_wallets.ts javascript | ||
|
|
||
| Bridging can also be done privately with the corresponding function: | ||
| For the mechanisms to complete bridging between L1 and Aztec, we have to wait for 2 Aztec blocks to progress. This can be triggered manually by sending 2 transactions in the sandbox, or by waiting for 2 blocks on a public network. After this, an account should have its fee juice ready to use in transactions. | ||
|
|
||
| #include_code bridge_tokens_private yarn-project/aztec.js/src/ethereum/portal_manager.ts javascript | ||
| Alternatively, the resulting claim object can be used to create a payment method to claim and pay for a transaction in one, where the transaction is the contract's deployment. | ||
|
|
||
| For the mechanisms to complete bridging between L1 and Aztec, any two other transactions on the sandbox are made. After this, an already deployed account should have its fee juice ready to use in transactions. | ||
| ## Examples | ||
|
critesjosh marked this conversation as resolved.
|
||
|
|
||
| Alternatively, the resulting claim object can be used to create a payment method to claim and pay for a transaction in one, where the transaction is the contract's deployment. | ||
| ### Pay with FeeJuice | ||
|
|
||
| To send a transaction from an already deployed account already holding fee juice. A user's fee juice balance is public, so paying for a transaction with fee juice will reveal information about which account is paying for the transaction and how much they paid. | ||
|
|
||
| ## Fee Options | ||
| Note: this example is a public token transfer call, but can equally be a private function call | ||
|
|
||
| Functions pertaining to sending a transaction, such as `deploy` and `send`, each include a `fee` variable defined with the following (optional) parameters: | ||
| ```ts | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I guess this doesn't exist anywhere in the codebase?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not an import statement that is just this. |
||
| import { FeeJuicePaymentMethod } from "@aztec/aztec.js"; | ||
| ``` | ||
|
|
||
| #include_code user_fee_options yarn-project/entrypoints/src/interfaces.ts javascript | ||
| #include_code pay_fee_juice_send yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts javascript | ||
|
critesjosh marked this conversation as resolved.
|
||
|
|
||
| **The equivalent to specify fees via CLI...** | ||
|
|
||
| ### Fee Payment Method | ||
| import { CLI_Fees } from '/components/snippets'; | ||
|
|
||
| The `paymentMethod` is an object for the type of payment. Each of the implementations can be found [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec.js/src/fee). For example: | ||
| <CLI_Fees /> | ||
|
|
||
| #include_code fee_juice_method yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts javascript | ||
| ### Claim and deploy | ||
|
|
||
| ### Gas Settings | ||
| Here we will use the `claim` object previously from the bridging section, and the corresponding `wallet`, to create the fee payment method. The payment method is then used to claim fee juice and pay for account contract deployment. Note the function used to bridge fee juice (private/public) should correspond to how the fee juice is claimed. | ||
|
|
||
| #include_code gas_settings_vars yarn-project/stdlib/src/gas/gas_settings.ts javascript | ||
| ```ts | ||
| import { FeeJuicePaymentMethodWithClaim } from "@aztec/aztec.js"; | ||
| ``` | ||
|
|
||
| import { Gas_Settings_Components, Gas_Settings } from '/components/snippets'; | ||
| #include_code claim_and_deploy yarn-project/bot/src/factory.ts javascript | ||
|
|
||
| <Gas_Settings /> | ||
| **The equivalent to specify fees via CLI...** | ||
|
|
||
| <Gas_Settings_Components /> | ||
| The CLI tool `aztec-wallet` takes the fee payment method via the param: `--payment method=fee_juice,claim` | ||
|
|
||
| #### Claim and Pay | ||
|
|
||
| ### Other params | ||
| Claiming bridged fee juice and using it to pay for transaction fees results in fees being paid publicly. | ||
|
|
||
| Fee and gas padding params can be left to their default values, and the estimateGas boolean can be used when simulating a tx to calculate gas. | ||
| Calling a function, in this case checking the balance of the fee juice contract: | ||
|
|
||
| With the fee options explained, lets do a paid transaction. | ||
| #include_code claim_and_pay yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts javascript | ||
|
|
||
| ## Examples | ||
| ### Fee Paying Contract | ||
|
|
||
| Users can pay fees privately or publicly via FPCs. A FPC must be deployed and funded with fee juice before it can be used to pay for transactions. Users must have the token that the FPC accepts to pay for transactions. They must have a private balance of the token if they want to pay for fees privately, and a public balance if they want to pay for fees publicly. | ||
|
|
||
| Import the appropriate method from aztec.js. | ||
|
|
||
| ```ts | ||
| import { | ||
| PrivateFeePaymentMethod, | ||
| PublicFeePaymentMethod, | ||
| } from "@aztec/aztec.js"; | ||
| ``` | ||
|
|
||
| The fee payment method is created and used as follows, with similar syntax for private or public fee payments: | ||
|
|
||
| #include_code fpc yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts javascript | ||
|
|
||
| In this example, thanks to the FPC's `accepted_asset` being banana tokens, Alice only needs to hold this token and not fee juice. The asset that a FPC accepts for paying fees is determined when the FPC is deployed. The function being called happens to also be a transfer of banana tokens to Bob. | ||
|
|
||
| More on FPCs [here](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slightly hard for me to parse but i assume we have shown CLI method for using FPCs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ### Sponsored Fee Paying Contract | ||
|
|
||
| Creating the SponsoredFPC is as simple as passing it the PXE: | ||
| This method of fee payment will only work for environments where a sponsored fee paying contract is deployed. | ||
| The sandbox comes with a sponsored fee paying contract deployed, so this can be used to pay for transactions without needing to bridge fee juice. | ||
| To use sponsored FPCs in other environments, they will need to be deployed and funded with fee juice. | ||
| Creating the SponsoredFPC is as simple as importing it and passing it the PXE: | ||
|
|
||
| ```ts | ||
| import { SponsoredFeePaymentMethod } from "@aztec/aztec.js"; | ||
|
critesjosh marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ```ts | ||
| const paymentMethod = await SponsoredFeePaymentMethod.new(pxe); | ||
| ``` | ||
|
|
@@ -107,37 +142,28 @@ const paymentMethod = await SponsoredFeePaymentMethod.new(pxe); | |
| myAccountManager.deploy({ fee: { paymentMethod } }); | ||
| ``` | ||
|
|
||
| ### Pay with FeeJuice | ||
|
|
||
| To send a transaction from an already deployed account already holding fee juice: | ||
| (Note: this example is a public token transfer call, but can equally be a private function call) | ||
|
|
||
| #include_code pay_fee_juice_send yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts javascript | ||
|
|
||
| **The equivalent to specify fees via CLI...** | ||
|
|
||
| import { CLI_Fees } from '/components/snippets'; | ||
| ## Fee Options | ||
|
|
||
| <CLI_Fees /> | ||
| Functions pertaining to sending a transaction, such as `deploy` and `send`, each include a `fee` variable defined with the following (optional) parameters: | ||
|
|
||
| ### Claim and deploy | ||
| #include_code user_fee_options yarn-project/entrypoints/src/interfaces.ts javascript | ||
|
|
||
| Here we will use the `claim` object previously from the bridging section, and the corresponding `wallet`, to create the payment method. The payment method is then used to claim fee juice and pay for account contract deployment. Note the function used to bridge fee juice (private/public) should correspond to how the fee juice is claimed. | ||
| ### Fee Payment Method | ||
|
|
||
| #include_code claim_and_deploy yarn-project/bot/src/factory.ts javascript | ||
| The `paymentMethod` is an object for the type of payment. Each of the implementations can be found [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec.js/src/fee). For example: | ||
|
|
||
| #### Claim and Pay | ||
| #include_code fee_juice_method yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts javascript | ||
|
|
||
| Calling a function, in this case checking the balance of the fee juice contract: | ||
| ### Gas Settings | ||
|
critesjosh marked this conversation as resolved.
|
||
|
|
||
| #include_code claim_and_pay yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts javascript | ||
| #include_code gas_settings_vars yarn-project/stdlib/src/gas/gas_settings.ts javascript | ||
|
|
||
| ### Fee Paying Contract | ||
| import { Gas_Settings_Components, Gas_Settings } from '/components/snippets'; | ||
|
|
||
| Similarly with a fee paying contract, the fee payment method is created and used as follows: | ||
| <Gas_Settings /> | ||
|
|
||
| #include_code fpc yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts javascript | ||
| <Gas_Settings_Components /> | ||
|
|
||
| In this example, thanks to the FPC's `accepted_asset` being banana tokens, Alice only needs to hold this token and not fee juice. The function being called happens to also be a transfer of banana tokens to Bob. | ||
| ### Other params | ||
|
|
||
| More on FPCs [here](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr) | ||
| Fee and gas padding params can be left to their default values, and the estimateGas boolean can be used when simulating a tx to calculate gas. | ||
Uh oh!
There was an error while loading. Please reload this page.