@aztec/aztec.js 0.80.0 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account/{contract.d.ts → account_contract.d.ts} +11 -5
- package/dest/account/account_contract.d.ts.map +1 -0
- package/dest/account/{contract.js → account_contract.js} +5 -1
- package/dest/account/index.d.ts +2 -3
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +1 -2
- package/dest/account/interface.d.ts +1 -13
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -0
- package/dest/account_manager/account_manager.d.ts +105 -0
- package/dest/account_manager/account_manager.d.ts.map +1 -0
- package/dest/account_manager/account_manager.js +165 -0
- package/dest/account_manager/deploy_account_method.d.ts +4 -4
- package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_method.js +28 -13
- package/dest/account_manager/deploy_account_sent_tx.d.ts +3 -3
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_sent_tx.js +2 -2
- package/dest/account_manager/index.d.ts +1 -104
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +1 -157
- package/dest/api/account.d.ts +2 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/contract.d.ts +4 -1
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +3 -0
- package/dest/api/fee.d.ts +1 -1
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/utils.d.ts +2 -1
- package/dest/api/utils.d.ts.map +1 -1
- package/dest/api/utils.js +2 -1
- package/dest/api/wallet.d.ts +1 -1
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.d.ts +22 -57
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +12 -67
- package/dest/contract/batch_call.d.ts +6 -18
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +25 -54
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract_base.d.ts +2 -2
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +38 -18
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +34 -41
- package/dest/contract/deploy_method.d.ts +7 -8
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +27 -32
- package/dest/contract/deploy_proven_tx.d.ts +2 -3
- package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.d.ts +2 -3
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +4 -4
- package/dest/contract/protocol_contracts.d.ts +1 -1
- package/dest/contract/protocol_contracts.d.ts.map +1 -1
- package/dest/contract/proven_tx.d.ts +3 -4
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.d.ts +4 -16
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +6 -37
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.d.ts +17 -0
- package/dest/contract/wait_for_proven.d.ts.map +1 -0
- package/dest/contract/wait_for_proven.js +17 -0
- package/dest/deployment/broadcast_function.js +12 -8
- package/dest/deployment/contract_deployer.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- package/dest/deployment/register_class.d.ts +1 -1
- package/dest/deployment/register_class.d.ts.map +1 -1
- package/dest/deployment/register_class.js +6 -11
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts +3 -2
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +12 -8
- package/dest/ethereum/portal_manager.d.ts +20 -11
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +64 -30
- package/dest/fee/fee_juice_payment_method.d.ts +3 -3
- package/dest/fee/fee_juice_payment_method.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method.js +3 -2
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +4 -4
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -5
- package/dest/fee/private_fee_payment_method.d.ts +6 -6
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +13 -12
- package/dest/fee/public_fee_payment_method.d.ts +7 -7
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +10 -11
- package/dest/fee/utils.d.ts +13 -0
- package/dest/fee/utils.d.ts.map +1 -0
- package/dest/fee/utils.js +32 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/test/aztec_cheat_codes.d.ts +2 -2
- package/dest/test/aztec_cheat_codes.d.ts.map +1 -1
- package/dest/test/aztec_cheat_codes.js +3 -3
- package/dest/utils/authwit.d.ts +16 -9
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +26 -35
- package/dest/wallet/account_wallet.d.ts +6 -6
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +15 -17
- package/dest/wallet/base_wallet.d.ts +12 -35
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +11 -64
- package/dest/wallet/index.d.ts +2 -2
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -1
- package/dest/wallet/signerless_wallet.d.ts +3 -3
- package/dest/wallet/signerless_wallet.d.ts.map +1 -1
- package/dest/wallet/signerless_wallet.js +3 -6
- package/dest/wallet/wallet.d.ts +11 -0
- package/dest/wallet/wallet.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/account/{contract.ts → account_contract.ts} +17 -4
- package/src/account/index.ts +2 -3
- package/src/account/interface.ts +1 -12
- package/src/account_manager/account_manager.ts +235 -0
- package/src/account_manager/deploy_account_method.ts +35 -15
- package/src/account_manager/deploy_account_sent_tx.ts +4 -4
- package/src/account_manager/index.ts +1 -227
- package/src/api/account.ts +2 -8
- package/src/api/contract.ts +5 -5
- package/src/api/fee.ts +1 -1
- package/src/api/utils.ts +1 -1
- package/src/api/wallet.ts +7 -1
- package/src/contract/base_contract_interaction.ts +32 -88
- package/src/contract/batch_call.ts +40 -43
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +1 -1
- package/src/contract/contract_function_interaction.ts +85 -56
- package/src/contract/deploy_method.ts +24 -26
- package/src/contract/deploy_proven_tx.ts +2 -3
- package/src/contract/deploy_sent_tx.ts +6 -6
- package/src/contract/protocol_contracts.ts +1 -1
- package/src/contract/proven_tx.ts +2 -3
- package/src/contract/sent_tx.ts +6 -47
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/contract/wait_for_proven.ts +38 -0
- package/src/deployment/broadcast_function.ts +40 -40
- package/src/deployment/contract_deployer.ts +1 -1
- package/src/deployment/register_class.ts +9 -22
- package/src/entrypoint/default_multi_call_entrypoint.ts +14 -7
- package/src/ethereum/portal_manager.ts +73 -24
- package/src/fee/fee_juice_payment_method.ts +4 -5
- package/src/fee/fee_juice_payment_method_with_claim.ts +24 -20
- package/src/fee/private_fee_payment_method.ts +29 -28
- package/src/fee/public_fee_payment_method.ts +29 -29
- package/src/fee/utils.ts +39 -0
- package/src/index.ts +1 -1
- package/src/test/aztec_cheat_codes.ts +3 -3
- package/src/utils/authwit.ts +32 -35
- package/src/wallet/account_wallet.ts +18 -17
- package/src/wallet/base_wallet.ts +27 -88
- package/src/wallet/index.ts +2 -2
- package/src/wallet/signerless_wallet.ts +9 -8
- package/src/wallet/wallet.ts +34 -0
- package/dest/account/contract.d.ts.map +0 -1
- package/dest/account/wallet.d.ts +0 -11
- package/dest/account/wallet.d.ts.map +0 -1
- package/dest/api/entrypoint.d.ts +0 -2
- package/dest/api/entrypoint.d.ts.map +0 -1
- package/dest/api/entrypoint.js +0 -1
- package/dest/entrypoint/default_entrypoint.d.ts +0 -12
- package/dest/entrypoint/default_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/default_entrypoint.js +0 -28
- package/dest/entrypoint/entrypoint.d.ts +0 -39
- package/dest/entrypoint/entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/entrypoint.js +0 -20
- package/dest/entrypoint/payload.d.ts +0 -128
- package/dest/entrypoint/payload.d.ts.map +0 -1
- package/dest/entrypoint/payload.js +0 -143
- package/dest/fee/fee_payment_method.d.ts +0 -22
- package/dest/fee/fee_payment_method.d.ts.map +0 -1
- package/dest/fee/fee_payment_method.js +0 -3
- package/src/account/wallet.ts +0 -13
- package/src/api/entrypoint.ts +0 -1
- package/src/entrypoint/default_entrypoint.ts +0 -39
- package/src/entrypoint/entrypoint.ts +0 -60
- package/src/entrypoint/payload.ts +0 -238
- package/src/fee/fee_payment_method.ts +0 -22
- /package/dest/{account → wallet}/wallet.js +0 -0
|
@@ -5,6 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
7
|
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
8
|
+
import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
|
|
8
9
|
import { FeeJuicePortalAbi } from '@aztec/l1-artifacts/FeeJuicePortalAbi';
|
|
9
10
|
import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
|
|
10
11
|
import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
@@ -15,6 +16,8 @@ import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
|
15
16
|
|
|
16
17
|
import { type GetContractReturnType, type Hex, getContract, toFunctionSelector } from 'viem';
|
|
17
18
|
|
|
19
|
+
import type { Wallet } from '../index.js';
|
|
20
|
+
|
|
18
21
|
// docs:start:claim_type
|
|
19
22
|
// docs:start:claim_type_amount
|
|
20
23
|
/** L1 to L2 message info to claim it on L2. */
|
|
@@ -55,19 +58,39 @@ export async function generateClaimSecret(logger?: Logger): Promise<[Fr, Fr]> {
|
|
|
55
58
|
/** Helper for managing an ERC20 on L1. */
|
|
56
59
|
export class L1TokenManager {
|
|
57
60
|
private contract: GetContractReturnType<typeof TestERC20Abi, ViemWalletClient>;
|
|
61
|
+
private handler: GetContractReturnType<typeof FeeAssetHandlerAbi, ViemWalletClient> | undefined;
|
|
58
62
|
|
|
59
63
|
public constructor(
|
|
60
64
|
/** Address of the ERC20 contract. */
|
|
61
|
-
public readonly
|
|
65
|
+
public readonly tokenAddress: EthAddress,
|
|
66
|
+
/** Address of the handler/faucet contract. */
|
|
67
|
+
public readonly handlerAddress: EthAddress | undefined,
|
|
62
68
|
private publicClient: ViemPublicClient,
|
|
63
69
|
private walletClient: ViemWalletClient,
|
|
64
70
|
private logger: Logger,
|
|
65
71
|
) {
|
|
66
72
|
this.contract = getContract({
|
|
67
|
-
address: this.
|
|
73
|
+
address: this.tokenAddress.toString(),
|
|
68
74
|
abi: TestERC20Abi,
|
|
69
75
|
client: this.walletClient,
|
|
70
76
|
});
|
|
77
|
+
if (this.handlerAddress) {
|
|
78
|
+
this.handler = getContract({
|
|
79
|
+
address: this.handlerAddress.toString(),
|
|
80
|
+
abi: FeeAssetHandlerAbi,
|
|
81
|
+
client: this.walletClient,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Returns the amount of tokens available to mint via the handler.
|
|
87
|
+
* @throws if the handler is not provided.
|
|
88
|
+
*/
|
|
89
|
+
public async getMintAmount() {
|
|
90
|
+
if (!this.handler) {
|
|
91
|
+
throw new Error('Minting handler was not provided');
|
|
92
|
+
}
|
|
93
|
+
return await this.handler.read.mintAmount();
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
/**
|
|
@@ -79,16 +102,18 @@ export class L1TokenManager {
|
|
|
79
102
|
}
|
|
80
103
|
|
|
81
104
|
/**
|
|
82
|
-
* Mints tokens for the given address. Returns once the tx has been mined.
|
|
83
|
-
* @param amount - Amount to mint.
|
|
105
|
+
* Mints a fixed amount of tokens for the given address. Returns once the tx has been mined.
|
|
84
106
|
* @param address - Address to mint the tokens for.
|
|
85
107
|
* @param addressName - Optional name of the address for logging.
|
|
86
108
|
*/
|
|
87
|
-
public async mint(
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
public async mint(address: Hex, addressName?: string) {
|
|
110
|
+
if (!this.handler) {
|
|
111
|
+
throw new Error('Minting handler was not provided');
|
|
112
|
+
}
|
|
113
|
+
const mintAmount = await this.getMintAmount();
|
|
114
|
+
this.logger.info(`Minting ${mintAmount} tokens for ${stringifyEthAddress(address, addressName)}`);
|
|
115
|
+
// NOTE: the handler mints a fixed amount.
|
|
116
|
+
await this.handler.write.mint([address]);
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
/**
|
|
@@ -113,11 +138,12 @@ export class L1FeeJuicePortalManager {
|
|
|
113
138
|
constructor(
|
|
114
139
|
portalAddress: EthAddress,
|
|
115
140
|
tokenAddress: EthAddress,
|
|
141
|
+
handlerAddress: EthAddress,
|
|
116
142
|
private readonly publicClient: ViemPublicClient,
|
|
117
143
|
private readonly walletClient: ViemWalletClient,
|
|
118
144
|
private readonly logger: Logger,
|
|
119
145
|
) {
|
|
120
|
-
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
146
|
+
this.tokenManager = new L1TokenManager(tokenAddress, handlerAddress, publicClient, walletClient, logger);
|
|
121
147
|
this.contract = getContract({
|
|
122
148
|
address: portalAddress.toString(),
|
|
123
149
|
abi: FeeJuicePortalAbi,
|
|
@@ -136,16 +162,21 @@ export class L1FeeJuicePortalManager {
|
|
|
136
162
|
* @param amount - Amount of tokens to send.
|
|
137
163
|
* @param mint - Whether to mint the tokens before sending (only during testing).
|
|
138
164
|
*/
|
|
139
|
-
public async bridgeTokensPublic(to: AztecAddress, amount: bigint, mint = false): Promise<L2AmountClaim> {
|
|
165
|
+
public async bridgeTokensPublic(to: AztecAddress, amount: bigint | undefined, mint = false): Promise<L2AmountClaim> {
|
|
140
166
|
const [claimSecret, claimSecretHash] = await generateClaimSecret();
|
|
167
|
+
const mintableAmount = await this.tokenManager.getMintAmount();
|
|
168
|
+
const amountToBridge = amount ?? mintableAmount;
|
|
141
169
|
if (mint) {
|
|
142
|
-
|
|
170
|
+
if (amountToBridge !== mintableAmount) {
|
|
171
|
+
throw new Error(`Minting amount must be ${mintableAmount}`);
|
|
172
|
+
}
|
|
173
|
+
await this.tokenManager.mint(this.walletClient.account.address);
|
|
143
174
|
}
|
|
144
175
|
|
|
145
|
-
await this.tokenManager.approve(
|
|
176
|
+
await this.tokenManager.approve(amountToBridge, this.contract.address, 'FeeJuice Portal');
|
|
146
177
|
|
|
147
178
|
this.logger.info('Sending L1 Fee Juice to L2 to be claimed publicly');
|
|
148
|
-
const args = [to.toString(),
|
|
179
|
+
const args = [to.toString(), amountToBridge, claimSecretHash.toString()] as const;
|
|
149
180
|
|
|
150
181
|
await this.contract.simulate.depositToAztecPublic(args);
|
|
151
182
|
|
|
@@ -162,13 +193,13 @@ export class L1FeeJuicePortalManager {
|
|
|
162
193
|
'DepositToAztecPublic',
|
|
163
194
|
log =>
|
|
164
195
|
log.args.secretHash === claimSecretHash.toString() &&
|
|
165
|
-
log.args.amount ===
|
|
196
|
+
log.args.amount === amountToBridge &&
|
|
166
197
|
log.args.to === to.toString(),
|
|
167
198
|
this.logger,
|
|
168
199
|
);
|
|
169
200
|
|
|
170
201
|
return {
|
|
171
|
-
claimAmount:
|
|
202
|
+
claimAmount: amountToBridge,
|
|
172
203
|
claimSecret,
|
|
173
204
|
claimSecretHash,
|
|
174
205
|
messageHash: log.args.key,
|
|
@@ -178,26 +209,36 @@ export class L1FeeJuicePortalManager {
|
|
|
178
209
|
|
|
179
210
|
/**
|
|
180
211
|
* Creates a new instance
|
|
181
|
-
* @param
|
|
212
|
+
* @param walletOrPxe - Wallet or PXE client used for retrieving the L1 contract addresses.
|
|
182
213
|
* @param publicClient - L1 public client.
|
|
183
214
|
* @param walletClient - L1 wallet client.
|
|
184
215
|
* @param logger - Logger.
|
|
185
216
|
*/
|
|
186
217
|
public static async new(
|
|
187
|
-
|
|
218
|
+
walletOrPxe: Wallet | PXE,
|
|
188
219
|
publicClient: ViemPublicClient,
|
|
189
220
|
walletClient: ViemWalletClient,
|
|
190
221
|
logger: Logger,
|
|
191
222
|
): Promise<L1FeeJuicePortalManager> {
|
|
192
223
|
const {
|
|
193
|
-
l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress },
|
|
194
|
-
} = await
|
|
224
|
+
l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress, feeAssetHandlerAddress },
|
|
225
|
+
} = await walletOrPxe.getNodeInfo();
|
|
195
226
|
|
|
196
227
|
if (feeJuiceAddress.isZero() || feeJuicePortalAddress.isZero()) {
|
|
197
228
|
throw new Error('Portal or token not deployed on L1');
|
|
198
229
|
}
|
|
230
|
+
if (!feeAssetHandlerAddress || feeAssetHandlerAddress.isZero()) {
|
|
231
|
+
throw new Error('Handler not deployed on L1, or handler address is zero');
|
|
232
|
+
}
|
|
199
233
|
|
|
200
|
-
return new L1FeeJuicePortalManager(
|
|
234
|
+
return new L1FeeJuicePortalManager(
|
|
235
|
+
feeJuicePortalAddress,
|
|
236
|
+
feeJuiceAddress,
|
|
237
|
+
feeAssetHandlerAddress,
|
|
238
|
+
publicClient,
|
|
239
|
+
walletClient,
|
|
240
|
+
logger,
|
|
241
|
+
);
|
|
201
242
|
}
|
|
202
243
|
}
|
|
203
244
|
|
|
@@ -209,11 +250,12 @@ export class L1ToL2TokenPortalManager {
|
|
|
209
250
|
constructor(
|
|
210
251
|
portalAddress: EthAddress,
|
|
211
252
|
tokenAddress: EthAddress,
|
|
253
|
+
handlerAddress: EthAddress | undefined,
|
|
212
254
|
protected publicClient: ViemPublicClient,
|
|
213
255
|
protected walletClient: ViemWalletClient,
|
|
214
256
|
protected logger: Logger,
|
|
215
257
|
) {
|
|
216
|
-
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
258
|
+
this.tokenManager = new L1TokenManager(tokenAddress, handlerAddress, publicClient, walletClient, logger);
|
|
217
259
|
this.portal = getContract({
|
|
218
260
|
address: portalAddress.toString(),
|
|
219
261
|
abi: TokenPortalAbi,
|
|
@@ -267,6 +309,7 @@ export class L1ToL2TokenPortalManager {
|
|
|
267
309
|
};
|
|
268
310
|
}
|
|
269
311
|
|
|
312
|
+
// docs:start:bridge_tokens_private
|
|
270
313
|
/**
|
|
271
314
|
* Bridges tokens from L1 to L2 privately. Handles token approvals. Returns once the tx has been mined.
|
|
272
315
|
* @param to - Address to send the tokens to on L2.
|
|
@@ -278,6 +321,7 @@ export class L1ToL2TokenPortalManager {
|
|
|
278
321
|
amount: bigint,
|
|
279
322
|
mint = false,
|
|
280
323
|
): Promise<L2AmountClaimWithRecipient> {
|
|
324
|
+
// docs:end:bridge_tokens_private
|
|
281
325
|
const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint);
|
|
282
326
|
|
|
283
327
|
this.logger.info('Sending L1 tokens to L2 to be claimed privately');
|
|
@@ -312,7 +356,11 @@ export class L1ToL2TokenPortalManager {
|
|
|
312
356
|
|
|
313
357
|
private async bridgeSetup(amount: bigint, mint: boolean) {
|
|
314
358
|
if (mint) {
|
|
315
|
-
await this.tokenManager.
|
|
359
|
+
const mintableAmount = await this.tokenManager.getMintAmount();
|
|
360
|
+
if (amount !== mintableAmount) {
|
|
361
|
+
throw new Error(`Minting amount must be ${mintableAmount} for testing`);
|
|
362
|
+
}
|
|
363
|
+
await this.tokenManager.mint(this.walletClient.account.address);
|
|
316
364
|
}
|
|
317
365
|
await this.tokenManager.approve(amount, this.portal.address, 'TokenPortal');
|
|
318
366
|
return generateClaimSecret();
|
|
@@ -326,12 +374,13 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
|
326
374
|
constructor(
|
|
327
375
|
portalAddress: EthAddress,
|
|
328
376
|
tokenAddress: EthAddress,
|
|
377
|
+
handlerAddress: EthAddress | undefined,
|
|
329
378
|
outboxAddress: EthAddress,
|
|
330
379
|
publicClient: ViemPublicClient,
|
|
331
380
|
walletClient: ViemWalletClient,
|
|
332
381
|
logger: Logger,
|
|
333
382
|
) {
|
|
334
|
-
super(portalAddress, tokenAddress, publicClient, walletClient, logger);
|
|
383
|
+
super(portalAddress, tokenAddress, handlerAddress, publicClient, walletClient, logger);
|
|
335
384
|
this.outbox = getContract({
|
|
336
385
|
address: outboxAddress.toString(),
|
|
337
386
|
abi: OutboxAbi,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
3
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
2
|
-
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
|
|
5
|
-
import type { FeePaymentMethod } from './fee_payment_method.js';
|
|
6
|
-
|
|
7
6
|
// docs:start:fee_juice_method
|
|
8
7
|
/**
|
|
9
8
|
* Pay fee directly in the Fee Juice.
|
|
@@ -16,8 +15,8 @@ export class FeeJuicePaymentMethod implements FeePaymentMethod {
|
|
|
16
15
|
return Promise.resolve(ProtocolContractAddress.FeeJuice);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
return Promise.resolve(
|
|
18
|
+
getExecutionPayload(): Promise<ExecutionPayload> {
|
|
19
|
+
return Promise.resolve(ExecutionPayload.empty());
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
getFeePayer(): Promise<AztecAddress> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
4
4
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
5
5
|
|
|
6
6
|
import { getFeeJuice } from '../contract/protocol_contracts.js';
|
|
@@ -20,30 +20,34 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Creates
|
|
24
|
-
* @returns
|
|
23
|
+
* Creates an execution payload to pay the fee in Fee Juice.
|
|
24
|
+
* @returns An execution payload that just contains the claim function call.
|
|
25
25
|
*/
|
|
26
|
-
override async
|
|
26
|
+
override async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
27
27
|
const canonicalFeeJuice = await getFeeJuice(this.senderWallet);
|
|
28
28
|
const selector = await FunctionSelector.fromNameAndParameters(
|
|
29
29
|
canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!,
|
|
30
30
|
);
|
|
31
31
|
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
return new ExecutionPayload(
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
to: ProtocolContractAddress.FeeJuice,
|
|
36
|
+
name: 'claim',
|
|
37
|
+
selector,
|
|
38
|
+
isStatic: false,
|
|
39
|
+
args: [
|
|
40
|
+
this.senderWallet.getAddress().toField(),
|
|
41
|
+
new Fr(this.claim.claimAmount),
|
|
42
|
+
this.claim.claimSecret,
|
|
43
|
+
new Fr(this.claim.messageLeafIndex),
|
|
44
|
+
],
|
|
45
|
+
returnTypes: [],
|
|
46
|
+
type: FunctionType.PRIVATE,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
[],
|
|
50
|
+
[],
|
|
51
|
+
);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import {
|
|
4
|
+
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
3
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
6
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
5
7
|
|
|
6
|
-
import type { Wallet } from '../
|
|
7
|
-
import {
|
|
8
|
-
import { SignerlessWallet } from '../wallet/signerless_wallet.js';
|
|
9
|
-
import type { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
9
|
+
import { simulateWithoutSignature } from './utils.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Holds information about how the fee for a transaction is to be paid.
|
|
@@ -38,11 +38,10 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
38
38
|
*/
|
|
39
39
|
getAsset(): Promise<AztecAddress> {
|
|
40
40
|
if (!this.assetPromise) {
|
|
41
|
-
// We use
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
signerlessWallet,
|
|
41
|
+
// We use the utility method to avoid a signature because this function could be triggered
|
|
42
|
+
// before the associated account is deployed.
|
|
43
|
+
this.assetPromise = simulateWithoutSignature(
|
|
44
|
+
this.wallet,
|
|
46
45
|
this.paymentContract,
|
|
47
46
|
{
|
|
48
47
|
name: 'get_accepted_asset',
|
|
@@ -68,9 +67,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
68
67
|
isInitializer: false,
|
|
69
68
|
},
|
|
70
69
|
[],
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
this.assetPromise = interaction.simulate();
|
|
70
|
+
) as Promise<AztecAddress>;
|
|
74
71
|
}
|
|
75
72
|
return this.assetPromise!;
|
|
76
73
|
}
|
|
@@ -80,17 +77,17 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
/**
|
|
83
|
-
* Creates
|
|
80
|
+
* Creates an execution payload to pay the fee using a private function through an FPC in the desired asset
|
|
84
81
|
* @param gasSettings - The gas settings.
|
|
85
|
-
* @returns
|
|
82
|
+
* @returns An execution payload that contains the required function calls and auth witnesses.
|
|
86
83
|
*/
|
|
87
|
-
async
|
|
84
|
+
async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
|
|
88
85
|
// We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit
|
|
89
86
|
// (maxFee) to be in token denomination.
|
|
90
87
|
const maxFee = this.setMaxFeeToOne ? Fr.ONE : gasSettings.getFeeLimit();
|
|
91
88
|
const nonce = Fr.random();
|
|
92
89
|
|
|
93
|
-
await this.wallet.createAuthWit({
|
|
90
|
+
const witness = await this.wallet.createAuthWit({
|
|
94
91
|
caller: this.paymentContract,
|
|
95
92
|
action: {
|
|
96
93
|
name: 'transfer_to_public',
|
|
@@ -103,16 +100,20 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
103
100
|
},
|
|
104
101
|
});
|
|
105
102
|
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
return new ExecutionPayload(
|
|
104
|
+
[
|
|
105
|
+
{
|
|
106
|
+
name: 'fee_entrypoint_private',
|
|
107
|
+
to: this.paymentContract,
|
|
108
|
+
selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
|
|
109
|
+
type: FunctionType.PRIVATE,
|
|
110
|
+
isStatic: false,
|
|
111
|
+
args: [maxFee, nonce],
|
|
112
|
+
returnTypes: [],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
[witness],
|
|
116
|
+
[],
|
|
117
|
+
);
|
|
117
118
|
}
|
|
118
119
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
|
|
2
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
3
4
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
5
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
6
7
|
|
|
7
|
-
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
8
8
|
import type { AccountWallet } from '../wallet/account_wallet.js';
|
|
9
|
-
import {
|
|
10
|
-
import type { FeePaymentMethod } from './fee_payment_method.js';
|
|
9
|
+
import { simulateWithoutSignature } from './utils.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Holds information about how the fee for a transaction is to be paid.
|
|
@@ -32,11 +31,10 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
32
31
|
*/
|
|
33
32
|
getAsset(): Promise<AztecAddress> {
|
|
34
33
|
if (!this.assetPromise) {
|
|
35
|
-
// We use
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
signerlessWallet,
|
|
34
|
+
// We use the utility method to avoid a signature because this function could be triggered
|
|
35
|
+
// before the associated account is deployed.
|
|
36
|
+
this.assetPromise = simulateWithoutSignature(
|
|
37
|
+
this.wallet,
|
|
40
38
|
this.paymentContract,
|
|
41
39
|
{
|
|
42
40
|
name: 'get_accepted_asset',
|
|
@@ -62,9 +60,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
62
60
|
isInitializer: false,
|
|
63
61
|
},
|
|
64
62
|
[],
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
this.assetPromise = interaction.simulate();
|
|
63
|
+
) as Promise<AztecAddress>;
|
|
68
64
|
}
|
|
69
65
|
return this.assetPromise!;
|
|
70
66
|
}
|
|
@@ -74,11 +70,11 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
/**
|
|
77
|
-
* Creates
|
|
73
|
+
* Creates an execution payload to pay the fee using a public function through an FPC in the desired asset
|
|
78
74
|
* @param gasSettings - The gas settings.
|
|
79
|
-
* @returns
|
|
75
|
+
* @returns An execution payload that contains the required function calls.
|
|
80
76
|
*/
|
|
81
|
-
async
|
|
77
|
+
async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
|
|
82
78
|
const nonce = Fr.random();
|
|
83
79
|
const maxFee = gasSettings.getFeeLimit();
|
|
84
80
|
|
|
@@ -98,17 +94,21 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
98
94
|
true,
|
|
99
95
|
);
|
|
100
96
|
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
return new ExecutionPayload(
|
|
98
|
+
[
|
|
99
|
+
...(await setPublicAuthWitInteraction.request()).calls,
|
|
100
|
+
{
|
|
101
|
+
name: 'fee_entrypoint_public',
|
|
102
|
+
to: this.paymentContract,
|
|
103
|
+
selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
|
|
104
|
+
type: FunctionType.PRIVATE,
|
|
105
|
+
isStatic: false,
|
|
106
|
+
args: [maxFee, nonce],
|
|
107
|
+
returnTypes: [],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
[],
|
|
111
|
+
[],
|
|
112
|
+
);
|
|
113
113
|
}
|
|
114
114
|
}
|
package/src/fee/utils.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
2
|
+
import { type FunctionAbi, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
5
|
+
|
|
6
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
7
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
8
|
+
import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Use a wallet to simulate a function avoiding the wallet's entrypoint, as a SignerlessWallet would do
|
|
12
|
+
* @param wallet - The wallet to use for the simulation.
|
|
13
|
+
* @param contractAddress - The address of the contract to call.
|
|
14
|
+
* @param abi - The ABI of the function to simulate.
|
|
15
|
+
* @param args - The arguments to pass to the function.
|
|
16
|
+
* @returns The return values of the function call.
|
|
17
|
+
*/
|
|
18
|
+
export async function simulateWithoutSignature(
|
|
19
|
+
wallet: Wallet,
|
|
20
|
+
contractAddress: AztecAddress,
|
|
21
|
+
abi: FunctionAbi,
|
|
22
|
+
args: any[],
|
|
23
|
+
) {
|
|
24
|
+
const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, args);
|
|
25
|
+
|
|
26
|
+
const request = await interaction.request();
|
|
27
|
+
const maxFeesPerGas = (await wallet.getCurrentBaseFees()).mul(1.5);
|
|
28
|
+
const paymentMethod = new FeeJuicePaymentMethod(AztecAddress.ZERO);
|
|
29
|
+
const gasSettings = GasSettings.default({ maxFeesPerGas });
|
|
30
|
+
const fee = { gasSettings, paymentMethod };
|
|
31
|
+
|
|
32
|
+
const { l1ChainId: chainId, protocolVersion } = await wallet.getNodeInfo();
|
|
33
|
+
const entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
|
|
34
|
+
const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee, {});
|
|
35
|
+
|
|
36
|
+
const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true);
|
|
37
|
+
const rawReturnValues = simulationResult.getPrivateReturnValues().values;
|
|
38
|
+
return decodeFromAbi(abi.returnTypes, rawReturnValues!);
|
|
39
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -48,7 +48,7 @@ export {
|
|
|
48
48
|
GlobalVariables,
|
|
49
49
|
} from '@aztec/stdlib/tx';
|
|
50
50
|
export { Body, L2Block } from '@aztec/stdlib/block';
|
|
51
|
-
export {
|
|
51
|
+
export { LogId, type LogFilter, EncryptedLogPayload } from '@aztec/stdlib/logs';
|
|
52
52
|
export { L1EventPayload, EventMetadata } from '@aztec/stdlib/event';
|
|
53
53
|
export { L1ToL2Message, L2Actor, L1Actor } from '@aztec/stdlib/messaging';
|
|
54
54
|
export { UniqueNote, ExtendedNote, Comparator, Note } from '@aztec/stdlib/note';
|
|
@@ -62,13 +62,13 @@ export class AztecCheatCodes {
|
|
|
62
62
|
/**
|
|
63
63
|
* Loads the value stored at the given slot in the private storage of the given contract.
|
|
64
64
|
* @param contract - The address of the contract
|
|
65
|
-
* @param
|
|
65
|
+
* @param recipient - The address whose public key was used to encrypt the note
|
|
66
66
|
* @param slot - The storage slot to lookup
|
|
67
67
|
* @returns The notes stored at the given slot
|
|
68
68
|
*/
|
|
69
|
-
public async loadPrivate(
|
|
69
|
+
public async loadPrivate(recipient: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise<Note[]> {
|
|
70
70
|
const extendedNotes = await this.pxe.getNotes({
|
|
71
|
-
|
|
71
|
+
recipient,
|
|
72
72
|
contractAddress: contract,
|
|
73
73
|
storageSlot: new Fr(slot),
|
|
74
74
|
});
|