Skip to content

Commit c00b20b

Browse files
authored
chore(docs): Fix some stuff on fees, rm confusing storage example (#13501)
Updates fees to correctly show how to use them with a standalone PXE. Addresses some feedback that the storage example was confusing (since its acutally code that errors).
1 parent 58c143b commit c00b20b

File tree

5 files changed

+94
-90
lines changed
  • docs
    • docs/developers
    • versioned_docs
      • version-v0.85.0-alpha-testnet.0/developers/guides/js_apps
      • version-v0.85.0/developers

5 files changed

+94
-90
lines changed

docs/docs/developers/guides/js_apps/pay_fees.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,31 @@ import {
125125
} from "@aztec/aztec.js";
126126
```
127127

128-
The FPC contract must be registered in a users PXE before it can be used.
128+
A FPC contract must be registered in a users PXE before it can be used. This will automatically happen if you deploy a FPC to your sandbox, but must be added manually if you are using a standalone PXE.
129129

130130
```ts
131131
import { FPCContract } from "@aztec/noir-contracts.js/FPC";
132+
import { getContractInstanceFromDeployParams } from "@aztec/aztec.js";
132133

133134
// ... (set up the wallet and PXE)
134135

136+
// get the deployed FPC contract instance
137+
const fpcContractInstance = getContractInstanceFromDeployParams(
138+
FPCContract.artifact,
139+
fpcDeployParams // the params used to deploy the FPC
140+
);
135141
// register the already deployed FPC contract in users PXE
136-
const fpcContract = FPCContract.at(fpcAddress, userWallet);
137-
await pxe.registerContract(fpcContract);
142+
await pxe.registerContract({
143+
instance: fpcContractInstance,
144+
artifact: FPCContract.artifact,
145+
});
138146
```
139147

140148
The fee payment method is created and used as follows, with similar syntax for private or public fee payments:
141149

142150
#include_code fpc yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts javascript
143151

144-
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.
152+
In this example, thanks to this 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.
145153

146154
More on FPCs [here](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/fees/fpc_contract/src/main.nr)
147155

@@ -154,6 +162,8 @@ The sandbox comes with a sponsored fee paying contract deployed, so this can be
154162
To use sponsored FPCs in other environments, they will need to be deployed and funded with fee juice.
155163
Using a SponsoredFPC payment method is as simple as importing it, registering it and passing it the PXE:
156164

165+
#### Sandbox with PXE
166+
157167
```ts
158168
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
159169
```
@@ -162,20 +172,28 @@ import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
162172
const paymentMethod = new SponsoredFeePaymentMethod(deployedSponsoredFPC);
163173
```
164174

165-
Register the SponsoredFPC in the PXE:
175+
#### Standalone PXE (e.g. Testnet)
176+
177+
Register the default SponsoredFPC in the PXE:
166178

167179
```ts
168180
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
169181

170182
// ... (set up the wallet and PXE)
171183

172184
// register the already deployed SponsoredFPC contract in users PXE
173-
const fpcContract = SponsoredFPCContract.at(sponsoredFpcAddress, userWallet);
174-
await pxe.registerContract(fpcContract);
185+
const sponseredFPC = await getSponsoredFPCInstance();
186+
await pxe.registerContract({
187+
instance: sponsoredFPC,
188+
artifact: SponsoredFPCContract.artifact,
189+
});
190+
const paymentMethod = new SponsoredFeePaymentMethod(sponseredFPC.address);
175191
```
176192

177-
Then a transaction can specify this as the `paymentMethod` in the fee object.
178-
You can see an example of how to get a deployed instance of the sponsored FPC in the sandbox [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec/src/sandbox/sponsored_fpc.ts#L15).
193+
You can see an example implementation for `getSponsoredFPCInstance()` [here](https://github.com/AztecProtocol/aztec-packages/blob/360a5f628b4edaf1ea9b328d9e9231f60fdc81a0/yarn-project/aztec/src/sandbox/sponsored_fpc.ts#L5).
194+
195+
Once this is set up, a transaction can specify this as the `paymentMethod` in the fee object.
196+
You can see an example of how to get a deployed instance of a sponsored FPC in the sandbox [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec/src/sandbox/sponsored_fpc.ts#L15).
179197
For example, a contract can be deployed with an fpc as follows:
180198

181199
```ts

docs/docs/developers/reference/smart_contract_reference/storage/index.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,13 @@ On this and the following pages in this section, you’ll learn:
2626

2727
Aztec contracts have three different modes of execution: private, public, and utility. How storage is accessed depends on the execution mode: for example, `PublicImmutable` can be read in all execution modes but only initialized in public, while `PrivateMutable` is entirely unavailable in public.
2828

29-
Aztec.nr prevents developers from calling functions unavailable in the current execution mode via the `context` variable that is injected into all contract functions. Its type indicates the current execution mode:
29+
Aztec.nr prevents developers from calling functions unavailable in the current execution mode via the `Context` variable that is injected into all contract functions. Its type indicates the current execution mode:
3030

3131
- `&mut PrivateContext` for private execution
3232
- `&mut PublicContext` for public execution
3333
- `UtilityContext` for utility execution
3434

35-
All state variables are generic over this `Context` type, and expose different methods in each execution mode. In the example above, `PublicImmutable`'s `initialize` function is only available with a public execution context, and so the following code results in a compilation error:
36-
37-
```rust
38-
#[storage]
39-
struct Storage {
40-
variable: PublicImmutable<Field>,
41-
}
42-
43-
#[private]
44-
fn some_private_function() {
45-
storage.variable.initialize(0);
46-
// ^ ERROR: Expected type PublicImmutable<_, &mut PublicContext>, found type PublicImmutable<Field, &mut PrivateContext>
47-
}
48-
```
49-
50-
The `Context` generic type parameter is not visible in the code above as it is automatically injected by the `#[storage]` macro, in order to reduce boilerplate. Similarly, all state variables in that struct (e.g. `PublicImmutable`) similarly have that same type parameter automatically passed to them.
35+
All state variables are generic over this `Context` type, and expose different methods in each execution mode.
5136

5237
## Map
5338

docs/versioned_docs/version-v0.85.0-alpha-testnet.0/developers/guides/js_apps/pay_fees.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ First get the node info and create a public client pointing to the sandbox's anv
4747
```javascript title="get_node_info_pub_client" showLineNumbers
4848
const info = await pxe.getNodeInfo();
4949
const publicClient = getPublicClient({
50-
l1RpcUrls: ['http://localhost:8545'],
50+
l1RpcUrls: ["http://localhost:8545"],
5151
l1ChainId: foundry.id,
5252
});
5353
```
54-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/spartan/smoke.test.ts#L52-L58" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/spartan/smoke.test.ts#L52-L58</a></sub></sup>
5554

55+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/spartan/smoke.test.ts#L52-L58" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/spartan/smoke.test.ts#L52-L58</a></sub></sup>
5656
5757
After importing:
5858

@@ -66,8 +66,8 @@ Create a new fee juice portal manager and bridge fee juice publicly to Aztec:
6666
const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, log);
6767
const claim = await portal.bridgeTokensPublic(recipient, amount, true /* mint */);
6868
```
69-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts#L110-L113" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/spartan/setup_test_wallets.ts#L110-L113</a></sub></sup>
7069

70+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts#L110-L113" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/spartan/setup_test_wallets.ts#L110-L113</a></sub></sup>
7171
7272
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.
7373

@@ -102,8 +102,8 @@ const { transactionFee } = await bananaCoin.methods
102102
.send({ fee: { gasSettings, paymentMethod } })
103103
.wait();
104104
```
105-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L86-L92" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L86-L92</a></sub></sup>
106105

106+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L86-L92" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L86-L92</a></sub></sup>
107107
108108
**The equivalent to specify fees via CLI...**
109109

@@ -125,8 +125,8 @@ const paymentMethod = new FeeJuicePaymentMethodWithClaim(wallet, claim);
125125
const sentTx = account.deploy({ fee: { paymentMethod } });
126126
const txHash = await sentTx.getTxHash();
127127
```
128-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/bot/src/factory.ts#L121-L126" target="_blank" rel="noopener noreferrer">Source code: yarn-project/bot/src/factory.ts#L121-L126</a></sub></sup>
129128

129+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/bot/src/factory.ts#L121-L126" target="_blank" rel="noopener noreferrer">Source code: yarn-project/bot/src/factory.ts#L121-L126</a></sub></sup>
130130
131131
**The equivalent to specify fees via CLI...**
132132

@@ -146,8 +146,8 @@ const receipt = await feeJuiceContract
146146
.send({ fee: { gasSettings, paymentMethod } })
147147
.wait();
148148
```
149-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L67-L74" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L67-L74</a></sub></sup>
150149

150+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L67-L74" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts#L67-L74</a></sub></sup>
151151
152152
### Fee Paying Contract
153153

@@ -162,7 +162,7 @@ import {
162162
} from "@aztec/aztec.js";
163163
```
164164

165-
The FPC contract must be registered in a users PXE before it can be used.
165+
A FPC contract must be registered in a users PXE before it can be used. This will automatically happen if you deploy a FPC to your sandbox, but must be added manually if you are using a standalone PXE.
166166

167167
```ts
168168
import { FPCContract } from "@aztec/noir-contracts.js/FPC";
@@ -187,10 +187,10 @@ const tx = await bananaCoin.methods
187187
})
188188
.wait();
189189
```
190-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts#L59-L69" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts#L59-L69</a></sub></sup>
191190

191+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts#L59-L69" target="_blank" rel="noopener noreferrer">Source code: yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts#L59-L69</a></sub></sup>
192192
193-
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.
193+
In this example, thanks to this 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.
194194

195195
More on FPCs [here](https://github.com/AztecProtocol/aztec-packages/tree/v0.85.0-alpha-testnet.0/noir-projects/noir-contracts/contracts/fees/fpc_contract/src/main.nr)
196196

@@ -211,16 +211,20 @@ import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
211211
const paymentMethod = new SponsoredFeePaymentMethod(deployedSponsoredFPC);
212212
```
213213

214-
Register the SponsoredFPC in the PXE:
214+
Register the default SponsoredFPC in the PXE:
215215

216216
```ts
217217
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
218218

219219
// ... (set up the wallet and PXE)
220220

221221
// register the already deployed SponsoredFPC contract in users PXE
222-
const fpcContract = SponsoredFPCContract.at(sponsoredFpcAddress, userWallet);
223-
await pxe.registerContract(fpcContract);
222+
const sponseredFPC = await getSponsoredFPCInstance();
223+
await pxe.registerContract({
224+
instance: sponsoredFPC,
225+
artifact: SponsoredFPCContract.artifact,
226+
});
227+
const paymentMethod = new SponsoredFeePaymentMethod(sponseredFPC.address);
224228
```
225229

226230
Then a transaction can specify this as the `paymentMethod` in the fee object.
@@ -242,19 +246,19 @@ Functions pertaining to sending a transaction, such as `deploy` and `send`, each
242246
/** Fee options as set by a user. */
243247
export type UserFeeOptions = {
244248
/** The fee payment method to use */
245-
paymentMethod?: FeePaymentMethod;
249+
paymentMethod?: FeePaymentMethod,
246250
/** The gas settings */
247-
gasSettings?: Partial<FieldsOf<GasSettings>>;
251+
gasSettings?: Partial<FieldsOf<GasSettings>>,
248252
/** Percentage to pad the base fee by, if empty, defaults to 0.5 */
249-
baseFeePadding?: number;
253+
baseFeePadding?: number,
250254
/** Whether to run an initial simulation of the tx with high gas limit to figure out actual gas settings. */
251-
estimateGas?: boolean;
255+
estimateGas?: boolean,
252256
/** Percentage to pad the estimated gas limits by, if empty, defaults to 0.1. Only relevant if estimateGas is set. */
253-
estimatedGasPadding?: number;
257+
estimatedGasPadding?: number,
254258
};
255259
```
256-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/entrypoints/src/interfaces.ts#L79-L93" target="_blank" rel="noopener noreferrer">Source code: yarn-project/entrypoints/src/interfaces.ts#L79-L93</a></sub></sup>
257260

261+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/entrypoints/src/interfaces.ts#L79-L93" target="_blank" rel="noopener noreferrer">Source code: yarn-project/entrypoints/src/interfaces.ts#L79-L93</a></sub></sup>
258262
259263
### Fee Payment Method
260264

@@ -266,8 +270,8 @@ The `paymentMethod` is an object for the type of payment. Each of the implementa
266270
*/
267271
export class FeeJuicePaymentMethod implements FeePaymentMethod {
268272
```
269-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts#L6-L11" target="_blank" rel="noopener noreferrer">Source code: yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts#L6-L11</a></sub></sup>
270273
274+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts#L6-L11" target="_blank" rel="noopener noreferrer">Source code: yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts#L6-L11</a></sub></sup>
271275
272276
### Gas Settings
273277
@@ -281,8 +285,8 @@ export class GasSettings {
281285
public readonly maxPriorityFeesPerGas: GasFees,
282286
) {}
283287
```
284-
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/stdlib/src/gas/gas_settings.ts#L11-L20" target="_blank" rel="noopener noreferrer">Source code: yarn-project/stdlib/src/gas/gas_settings.ts#L11-L20</a></sub></sup>
285288
289+
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/v0.85.0-alpha-testnet.0/yarn-project/stdlib/src/gas/gas_settings.ts#L11-L20" target="_blank" rel="noopener noreferrer">Source code: yarn-project/stdlib/src/gas/gas_settings.ts#L11-L20</a></sub></sup>
286290
287291
import { Gas_Settings_Components, Gas_Settings } from '@site/src/components/Snippets/snippets';
288292

0 commit comments

Comments
 (0)