@aztec/aztec.js 0.73.0 → 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2
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/README.md +1 -1
- package/dest/account/contract.js +5 -3
- package/dest/account/index.js +8 -2
- package/dest/account/interface.js +4 -3
- package/dest/account/wallet.js +3 -2
- package/dest/account_manager/deploy_account_method.js +22 -25
- package/dest/account_manager/deploy_account_sent_tx.js +16 -17
- package/dest/account_manager/index.js +67 -78
- package/dest/api/abi.js +0 -1
- package/dest/api/account.js +0 -1
- package/dest/api/addresses.js +0 -1
- package/dest/api/cheat_codes.js +25 -0
- package/dest/api/deployment.js +0 -1
- package/dest/api/entrypoint.js +0 -1
- package/dest/api/eth_address.js +0 -1
- package/dest/api/ethereum/anvil_test_watcher.js +113 -0
- package/dest/api/ethereum/chain_monitor.js +69 -0
- package/dest/api/ethereum/cheat_codes.js +142 -0
- package/dest/api/ethereum/index.js +6 -0
- package/dest/api/ethereum/l1_contracts.js +13 -0
- package/dest/api/ethereum/portal_manager.js +284 -0
- package/dest/api/fee.js +0 -1
- package/dest/api/fields.js +0 -1
- package/dest/api/interfaces/pxe.js +1 -2
- package/dest/api/log.js +1 -0
- package/dest/api/log_id.js +0 -1
- package/dest/api/tx_hash.js +0 -1
- package/dest/api/wallet.js +1 -2
- package/dest/contract/base_contract_interaction.js +75 -52
- package/dest/contract/batch_call.js +57 -39
- package/dest/contract/checker.js +29 -20
- package/dest/contract/contract.js +22 -27
- package/dest/contract/contract_base.js +21 -30
- package/dest/contract/contract_function_interaction.js +48 -48
- package/dest/contract/deploy_method.js +99 -84
- package/dest/contract/deploy_proven_tx.js +8 -11
- package/dest/contract/deploy_sent_tx.js +19 -22
- package/dest/contract/get_gas_limits.js +2 -4
- package/dest/contract/index.js +4 -6
- package/dest/contract/proven_tx.js +7 -10
- package/dest/contract/sent_tx.js +32 -34
- package/dest/contract/unsafe_contract.js +2 -10
- package/dest/deployment/broadcast_function.js +28 -26
- package/dest/deployment/contract_deployer.js +15 -14
- package/dest/deployment/deploy_instance.js +1 -3
- package/dest/deployment/index.js +0 -1
- package/dest/deployment/protocol_contracts.js +2 -5
- package/dest/deployment/register_class.js +8 -8
- package/dest/entrypoint/default_entrypoint.js +8 -5
- package/dest/entrypoint/default_multi_call_entrypoint.js +66 -23
- package/dest/entrypoint/entrypoint.js +0 -1
- package/dest/entrypoint/payload.js +73 -82
- package/dest/fee/fee_juice_payment_method.js +3 -4
- package/dest/fee/fee_juice_payment_method_with_claim.js +11 -14
- package/dest/fee/fee_payment_method.js +3 -2
- package/dest/fee/no_fee_payment_method.js +2 -4
- package/dest/fee/private_fee_payment_method.js +36 -34
- package/dest/fee/public_fee_payment_method.js +34 -31
- package/dest/index.js +8 -9
- package/dest/rpc_clients/index.js +0 -1
- package/dest/rpc_clients/node/index.js +30 -16
- package/dest/rpc_clients/pxe_client.js +5 -3
- package/dest/utils/abi_types.js +1 -2
- package/dest/utils/authwit.js +15 -15
- package/dest/utils/aztec_cheatcodes.js +62 -0
- package/dest/utils/field_compressed_string.js +2 -4
- package/dest/utils/index.js +5 -12
- package/dest/utils/node.js +4 -5
- package/dest/utils/pub_key.js +1 -3
- package/dest/utils/pxe.js +3 -5
- package/dest/wallet/account_wallet.js +118 -81
- package/dest/wallet/account_wallet_with_private_key.js +9 -15
- package/dest/wallet/base_wallet.js +7 -5
- package/dest/wallet/index.js +2 -4
- package/dest/wallet/signerless_wallet.js +4 -6
- package/package.json +14 -17
- package/src/api/account.ts +7 -1
- package/src/api/cheat_codes.ts +35 -0
- package/src/{utils → api/ethereum}/anvil_test_watcher.ts +2 -1
- package/src/{utils → api/ethereum}/cheat_codes.ts +6 -109
- package/src/api/ethereum/index.ts +15 -0
- package/src/{utils → api/ethereum}/l1_contracts.ts +1 -1
- package/src/{utils → api/ethereum}/portal_manager.ts +4 -9
- package/src/api/interfaces/pxe.ts +1 -1
- package/src/api/log.ts +1 -0
- package/src/api/wallet.ts +1 -1
- package/src/contract/contract_function_interaction.ts +1 -1
- package/src/contract/index.ts +2 -2
- package/src/entrypoint/default_multi_call_entrypoint.ts +2 -1
- package/src/entrypoint/entrypoint.ts +1 -1
- package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
- package/src/index.ts +7 -35
- package/src/utils/aztec_cheatcodes.ts +75 -0
- package/src/utils/index.ts +19 -11
- package/src/utils/node.ts +2 -0
- package/src/wallet/index.ts +1 -1
- package/dest/account/contract.d.ts +0 -33
- package/dest/account/contract.d.ts.map +0 -1
- package/dest/account/index.d.ts +0 -15
- package/dest/account/index.d.ts.map +0 -1
- package/dest/account/interface.d.ts +0 -30
- package/dest/account/interface.d.ts.map +0 -1
- package/dest/account/wallet.d.ts +0 -10
- package/dest/account/wallet.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_method.d.ts +0 -15
- package/dest/account_manager/deploy_account_method.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_sent_tx.d.ts +0 -29
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +0 -1
- package/dest/account_manager/index.d.ts +0 -99
- package/dest/account_manager/index.d.ts.map +0 -1
- package/dest/api/abi.d.ts +0 -4
- package/dest/api/abi.d.ts.map +0 -1
- package/dest/api/account.d.ts +0 -4
- package/dest/api/account.d.ts.map +0 -1
- package/dest/api/addresses.d.ts +0 -3
- package/dest/api/addresses.d.ts.map +0 -1
- package/dest/api/deployment.d.ts +0 -4
- package/dest/api/deployment.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/eth_address.d.ts +0 -2
- package/dest/api/eth_address.d.ts.map +0 -1
- package/dest/api/ethereum.d.ts +0 -3
- package/dest/api/ethereum.d.ts.map +0 -1
- package/dest/api/ethereum.js +0 -3
- package/dest/api/fee.d.ts +0 -7
- package/dest/api/fee.d.ts.map +0 -1
- package/dest/api/fields.d.ts +0 -2
- package/dest/api/fields.d.ts.map +0 -1
- package/dest/api/interfaces/pxe.d.ts +0 -2
- package/dest/api/interfaces/pxe.d.ts.map +0 -1
- package/dest/api/log_id.d.ts +0 -2
- package/dest/api/log_id.d.ts.map +0 -1
- package/dest/api/tx_hash.d.ts +0 -2
- package/dest/api/tx_hash.d.ts.map +0 -1
- package/dest/api/wallet.d.ts +0 -2
- package/dest/api/wallet.d.ts.map +0 -1
- package/dest/barretenberg-threads.wasm.gz +0 -0
- package/dest/barretenberg.wasm.gz +0 -0
- package/dest/contract/base_contract_interaction.d.ts +0 -82
- package/dest/contract/base_contract_interaction.d.ts.map +0 -1
- package/dest/contract/batch_call.d.ts +0 -27
- package/dest/contract/batch_call.d.ts.map +0 -1
- package/dest/contract/checker.d.ts +0 -11
- package/dest/contract/checker.d.ts.map +0 -1
- package/dest/contract/contract.d.ts +0 -41
- package/dest/contract/contract.d.ts.map +0 -1
- package/dest/contract/contract_base.d.ts +0 -61
- package/dest/contract/contract_base.d.ts.map +0 -1
- package/dest/contract/contract_function_interaction.d.ts +0 -67
- package/dest/contract/contract_function_interaction.d.ts.map +0 -1
- package/dest/contract/deploy_method.d.ts +0 -110
- package/dest/contract/deploy_method.d.ts.map +0 -1
- package/dest/contract/deploy_proven_tx.d.ts +0 -19
- package/dest/contract/deploy_proven_tx.d.ts.map +0 -1
- package/dest/contract/deploy_sent_tx.d.ts +0 -43
- package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
- package/dest/contract/get_gas_limits.d.ts +0 -18
- package/dest/contract/get_gas_limits.d.ts.map +0 -1
- package/dest/contract/index.d.ts +0 -45
- package/dest/contract/index.d.ts.map +0 -1
- package/dest/contract/proven_tx.d.ts +0 -16
- package/dest/contract/proven_tx.d.ts.map +0 -1
- package/dest/contract/sent_tx.d.ts +0 -60
- package/dest/contract/sent_tx.d.ts.map +0 -1
- package/dest/contract/unsafe_contract.d.ts +0 -15
- package/dest/contract/unsafe_contract.d.ts.map +0 -1
- package/dest/deployment/broadcast_function.d.ts +0 -24
- package/dest/deployment/broadcast_function.d.ts.map +0 -1
- package/dest/deployment/contract_deployer.d.ts +0 -27
- package/dest/deployment/contract_deployer.d.ts.map +0 -1
- package/dest/deployment/deploy_instance.d.ts +0 -10
- package/dest/deployment/deploy_instance.d.ts.map +0 -1
- package/dest/deployment/index.d.ts +0 -2
- package/dest/deployment/index.d.ts.map +0 -1
- package/dest/deployment/protocol_contracts.d.ts +0 -7
- package/dest/deployment/protocol_contracts.d.ts.map +0 -1
- package/dest/deployment/register_class.d.ts +0 -6
- package/dest/deployment/register_class.d.ts.map +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_multi_call_entrypoint.d.ts +0 -15
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/entrypoint.d.ts +0 -31
- package/dest/entrypoint/entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/payload.d.ts +0 -125
- package/dest/entrypoint/payload.d.ts.map +0 -1
- package/dest/fee/fee_juice_payment_method.d.ts +0 -14
- package/dest/fee/fee_juice_payment_method.d.ts.map +0 -1
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +0 -17
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +0 -1
- package/dest/fee/fee_payment_method.d.ts +0 -22
- package/dest/fee/fee_payment_method.d.ts.map +0 -1
- package/dest/fee/no_fee_payment_method.d.ts +0 -13
- package/dest/fee/no_fee_payment_method.d.ts.map +0 -1
- package/dest/fee/private_fee_payment_method.d.ts +0 -51
- package/dest/fee/private_fee_payment_method.d.ts.map +0 -1
- package/dest/fee/public_fee_payment_method.d.ts +0 -41
- package/dest/fee/public_fee_payment_method.d.ts.map +0 -1
- package/dest/index.d.ts +0 -51
- package/dest/index.d.ts.map +0 -1
- package/dest/main.js +0 -2
- package/dest/main.js.LICENSE.txt +0 -25
- package/dest/rpc_clients/index.d.ts +0 -3
- package/dest/rpc_clients/index.d.ts.map +0 -1
- package/dest/rpc_clients/node/index.d.ts +0 -11
- package/dest/rpc_clients/node/index.d.ts.map +0 -1
- package/dest/rpc_clients/pxe_client.d.ts +0 -9
- package/dest/rpc_clients/pxe_client.d.ts.map +0 -1
- package/dest/utils/abi_types.d.ts +0 -26
- package/dest/utils/abi_types.d.ts.map +0 -1
- package/dest/utils/anvil_test_watcher.d.ts +0 -28
- package/dest/utils/anvil_test_watcher.d.ts.map +0 -1
- package/dest/utils/anvil_test_watcher.js +0 -108
- package/dest/utils/authwit.d.ts +0 -59
- package/dest/utils/authwit.d.ts.map +0 -1
- package/dest/utils/chain_monitor.d.ts +0 -21
- package/dest/utils/chain_monitor.d.ts.map +0 -1
- package/dest/utils/chain_monitor.js +0 -58
- package/dest/utils/cheat_codes.d.ts +0 -137
- package/dest/utils/cheat_codes.d.ts.map +0 -1
- package/dest/utils/cheat_codes.js +0 -225
- package/dest/utils/field_compressed_string.d.ts +0 -17
- package/dest/utils/field_compressed_string.d.ts.map +0 -1
- package/dest/utils/index.d.ts +0 -12
- package/dest/utils/index.d.ts.map +0 -1
- package/dest/utils/l1_contracts.d.ts +0 -3
- package/dest/utils/l1_contracts.d.ts.map +0 -1
- package/dest/utils/l1_contracts.js +0 -15
- package/dest/utils/node.d.ts +0 -4
- package/dest/utils/node.d.ts.map +0 -1
- package/dest/utils/portal_manager.d.ts +0 -130
- package/dest/utils/portal_manager.d.ts.map +0 -1
- package/dest/utils/portal_manager.js +0 -265
- package/dest/utils/pub_key.d.ts +0 -8
- package/dest/utils/pub_key.d.ts.map +0 -1
- package/dest/utils/pxe.d.ts +0 -4
- package/dest/utils/pxe.d.ts.map +0 -1
- package/dest/wallet/account_wallet.d.ts +0 -73
- package/dest/wallet/account_wallet.d.ts.map +0 -1
- package/dest/wallet/account_wallet_with_private_key.d.ts +0 -26
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
- package/dest/wallet/base_wallet.d.ts +0 -64
- package/dest/wallet/base_wallet.d.ts.map +0 -1
- package/dest/wallet/index.d.ts +0 -17
- package/dest/wallet/index.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.d.ts +0 -22
- package/dest/wallet/signerless_wallet.d.ts.map +0 -1
- package/src/api/ethereum.ts +0 -2
- /package/src/{utils → api/ethereum}/chain_monitor.ts +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/circuits.js';
|
|
2
|
+
import { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
5
|
+
import { createWalletClient, getContract, http, publicActions } from 'viem';
|
|
6
|
+
import { foundry } from 'viem/chains';
|
|
7
|
+
export { EthCheatCodes };
|
|
8
|
+
/** Cheat codes for the L1 rollup contract. */ export class RollupCheatCodes {
|
|
9
|
+
ethCheatCodes;
|
|
10
|
+
client;
|
|
11
|
+
rollup;
|
|
12
|
+
logger;
|
|
13
|
+
constructor(ethCheatCodes, addresses){
|
|
14
|
+
this.ethCheatCodes = ethCheatCodes;
|
|
15
|
+
this.logger = createLogger('aztecjs:cheat_codes');
|
|
16
|
+
this.client = createWalletClient({
|
|
17
|
+
chain: foundry,
|
|
18
|
+
transport: http(ethCheatCodes.rpcUrl)
|
|
19
|
+
}).extend(publicActions);
|
|
20
|
+
this.rollup = getContract({
|
|
21
|
+
abi: RollupAbi,
|
|
22
|
+
address: addresses.rollupAddress.toString(),
|
|
23
|
+
client: this.client
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Returns the current slot */ async getSlot() {
|
|
27
|
+
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
28
|
+
return await this.rollup.read.getSlotAt([
|
|
29
|
+
ts
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
/** Returns the current epoch */ async getEpoch() {
|
|
33
|
+
const slotNumber = await this.getSlot();
|
|
34
|
+
return await this.rollup.read.getEpochAtSlot([
|
|
35
|
+
slotNumber
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the pending and proven chain tips
|
|
40
|
+
* @returns The pending and proven chain tips
|
|
41
|
+
*/ async getTips() {
|
|
42
|
+
const res = await this.rollup.read.getTips();
|
|
43
|
+
return {
|
|
44
|
+
pending: res.pendingBlockNumber,
|
|
45
|
+
proven: res.provenBlockNumber
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Fetches the epoch and slot duration config from the rollup contract */ async getConfig() {
|
|
49
|
+
const [epochDuration, slotDuration] = await Promise.all([
|
|
50
|
+
this.rollup.read.getEpochDuration(),
|
|
51
|
+
this.rollup.read.getSlotDuration()
|
|
52
|
+
]);
|
|
53
|
+
return {
|
|
54
|
+
epochDuration,
|
|
55
|
+
slotDuration
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Warps time in L1 until the next epoch */ async advanceToNextEpoch() {
|
|
59
|
+
const slot = await this.getSlot();
|
|
60
|
+
const { epochDuration, slotDuration } = await this.getConfig();
|
|
61
|
+
const slotsUntilNextEpoch = epochDuration - slot % epochDuration + 1n;
|
|
62
|
+
const timeToNextEpoch = slotsUntilNextEpoch * slotDuration;
|
|
63
|
+
const l1Timestamp = BigInt((await this.client.getBlock()).timestamp);
|
|
64
|
+
await this.ethCheatCodes.warp(Number(l1Timestamp + timeToNextEpoch), true);
|
|
65
|
+
this.logger.warn(`Advanced to next epoch`);
|
|
66
|
+
}
|
|
67
|
+
/** Warps time in L1 until the beginning of the next slot. */ async advanceToNextSlot() {
|
|
68
|
+
const currentSlot = await this.getSlot();
|
|
69
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([
|
|
70
|
+
currentSlot + 1n
|
|
71
|
+
]);
|
|
72
|
+
await this.ethCheatCodes.warp(Number(timestamp));
|
|
73
|
+
this.logger.warn(`Advanced to slot ${currentSlot + 1n}`);
|
|
74
|
+
return [
|
|
75
|
+
timestamp,
|
|
76
|
+
currentSlot + 1n
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Warps time in L1 equivalent to however many slots.
|
|
81
|
+
* @param howMany - The number of slots to advance.
|
|
82
|
+
*/ async advanceSlots(howMany) {
|
|
83
|
+
const l1Timestamp = (await this.client.getBlock()).timestamp;
|
|
84
|
+
const slotDuration = await this.rollup.read.getSlotDuration();
|
|
85
|
+
const timeToWarp = BigInt(howMany) * slotDuration;
|
|
86
|
+
await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, true);
|
|
87
|
+
const [slot, epoch] = await Promise.all([
|
|
88
|
+
this.getSlot(),
|
|
89
|
+
this.getEpoch()
|
|
90
|
+
]);
|
|
91
|
+
this.logger.warn(`Advanced ${howMany} slots up to slot ${slot} in epoch ${epoch}`);
|
|
92
|
+
}
|
|
93
|
+
/** Returns the current proof claim (if any) */ async getProofClaim() {
|
|
94
|
+
// REFACTOR: This code is duplicated from l1-publisher
|
|
95
|
+
const { epochToProve, basisPointFee, bondAmount, bondProvider: bondProviderHex, proposerClaimant: proposerClaimantHex } = await this.rollup.read.getProofClaim();
|
|
96
|
+
const bondProvider = EthAddress.fromString(bondProviderHex);
|
|
97
|
+
const proposerClaimant = EthAddress.fromString(proposerClaimantHex);
|
|
98
|
+
if (bondProvider.isZero() && proposerClaimant.isZero() && epochToProve === 0n) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
epochToProve,
|
|
103
|
+
basisPointFee,
|
|
104
|
+
bondAmount,
|
|
105
|
+
bondProvider,
|
|
106
|
+
proposerClaimant
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Marks the specified block (or latest if none) as proven
|
|
111
|
+
* @param maybeBlockNumber - The block number to mark as proven (defaults to latest pending)
|
|
112
|
+
*/ async markAsProven(maybeBlockNumber) {
|
|
113
|
+
const blockNumber = maybeBlockNumber ? BigInt(maybeBlockNumber) : await this.rollup.read.getTips().then(({ pendingBlockNumber })=>pendingBlockNumber);
|
|
114
|
+
await this.asOwner(async (account)=>{
|
|
115
|
+
await this.rollup.write.setAssumeProvenThroughBlockNumber([
|
|
116
|
+
blockNumber
|
|
117
|
+
], {
|
|
118
|
+
account,
|
|
119
|
+
chain: this.client.chain
|
|
120
|
+
});
|
|
121
|
+
this.logger.warn(`Marked ${blockNumber} as proven`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Executes an action impersonated as the owner of the Rollup contract.
|
|
126
|
+
* @param action - The action to execute
|
|
127
|
+
*/ async asOwner(action) {
|
|
128
|
+
const owner = await this.rollup.read.owner();
|
|
129
|
+
await this.ethCheatCodes.startImpersonating(owner);
|
|
130
|
+
await action(owner, this.rollup);
|
|
131
|
+
await this.ethCheatCodes.stopImpersonating(owner);
|
|
132
|
+
}
|
|
133
|
+
/** Directly calls the L1 gas fee oracle. */ async updateL1GasFeeOracle() {
|
|
134
|
+
await this.asOwner(async (account, rollup)=>{
|
|
135
|
+
await rollup.write.updateL1GasFeeOracle({
|
|
136
|
+
account,
|
|
137
|
+
chain: this.client.chain
|
|
138
|
+
});
|
|
139
|
+
this.logger.warn(`Updated L1 gas fee oracle`);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { L1FeeJuicePortalManager, L1ToL2TokenPortalManager, L1TokenManager, L1TokenPortalManager, generateClaimSecret } from './portal_manager.js';
|
|
2
|
+
export { getL1ContractAddresses } from './l1_contracts.js';
|
|
3
|
+
export { RollupCheatCodes, EthCheatCodes } from './cheat_codes.js';
|
|
4
|
+
export { ChainMonitor } from './chain_monitor.js';
|
|
5
|
+
export { AnvilTestWatcher } from './anvil_test_watcher.js';
|
|
6
|
+
export { deployL1Contract, deployL1Contracts, DeployL1Contracts } from '@aztec/ethereum/deploy-l1-contracts';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
2
|
+
import { createPXEClient } from '../../rpc_clients/index.js';
|
|
3
|
+
export const getL1ContractAddresses = async (url)=>{
|
|
4
|
+
const pxeClient = createPXEClient(url);
|
|
5
|
+
const response = await retryUntil(async ()=>{
|
|
6
|
+
try {
|
|
7
|
+
return (await pxeClient.getNodeInfo()).l1ContractAddresses;
|
|
8
|
+
} catch (err) {
|
|
9
|
+
// do nothing
|
|
10
|
+
}
|
|
11
|
+
}, 'isNodeReady', 120, 1);
|
|
12
|
+
return response;
|
|
13
|
+
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { EthAddress, Fr } from '@aztec/circuits.js';
|
|
2
|
+
import { computeSecretHash } from '@aztec/circuits.js/hash';
|
|
3
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
4
|
+
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
5
|
+
import { FeeJuicePortalAbi, OutboxAbi, TestERC20Abi, TokenPortalAbi } from '@aztec/l1-artifacts';
|
|
6
|
+
import { getContract, toFunctionSelector } from 'viem';
|
|
7
|
+
/** Stringifies an eth address for logging. */ function stringifyEthAddress(address, name) {
|
|
8
|
+
return name ? `${name} (${address.toString()})` : address.toString();
|
|
9
|
+
}
|
|
10
|
+
/** Generates a pair secret and secret hash */ export async function generateClaimSecret(logger) {
|
|
11
|
+
const secret = Fr.random();
|
|
12
|
+
const secretHash = await computeSecretHash(secret);
|
|
13
|
+
logger?.verbose(`Generated claim secret=${secret.toString()} hash=${secretHash.toString()}`);
|
|
14
|
+
return [
|
|
15
|
+
secret,
|
|
16
|
+
secretHash
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
/** Helper for managing an ERC20 on L1. */ export class L1TokenManager {
|
|
20
|
+
address;
|
|
21
|
+
publicClient;
|
|
22
|
+
walletClient;
|
|
23
|
+
logger;
|
|
24
|
+
contract;
|
|
25
|
+
constructor(/** Address of the ERC20 contract. */ address, publicClient, walletClient, logger){
|
|
26
|
+
this.address = address;
|
|
27
|
+
this.publicClient = publicClient;
|
|
28
|
+
this.walletClient = walletClient;
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
this.contract = getContract({
|
|
31
|
+
address: this.address.toString(),
|
|
32
|
+
abi: TestERC20Abi,
|
|
33
|
+
client: this.walletClient
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the balance of the given address.
|
|
38
|
+
* @param address - Address to get the balance of.
|
|
39
|
+
*/ async getL1TokenBalance(address) {
|
|
40
|
+
return await this.contract.read.balanceOf([
|
|
41
|
+
address
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mints tokens for the given address. Returns once the tx has been mined.
|
|
46
|
+
* @param amount - Amount to mint.
|
|
47
|
+
* @param address - Address to mint the tokens for.
|
|
48
|
+
* @param addressName - Optional name of the address for logging.
|
|
49
|
+
*/ async mint(amount, address, addressName) {
|
|
50
|
+
this.logger.info(`Minting ${amount} tokens for ${stringifyEthAddress(address, addressName)}`);
|
|
51
|
+
await this.publicClient.waitForTransactionReceipt({
|
|
52
|
+
hash: await this.contract.write.mint([
|
|
53
|
+
address,
|
|
54
|
+
amount
|
|
55
|
+
])
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Approves tokens for the given address. Returns once the tx has been mined.
|
|
60
|
+
* @param amount - Amount to approve.
|
|
61
|
+
* @param address - Address to approve the tokens for.
|
|
62
|
+
* @param addressName - Optional name of the address for logging.
|
|
63
|
+
*/ async approve(amount, address, addressName = '') {
|
|
64
|
+
this.logger.info(`Approving ${amount} tokens for ${stringifyEthAddress(address, addressName)}`);
|
|
65
|
+
await this.publicClient.waitForTransactionReceipt({
|
|
66
|
+
hash: await this.contract.write.approve([
|
|
67
|
+
address,
|
|
68
|
+
amount
|
|
69
|
+
])
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Helper for interacting with the FeeJuicePortal on L1. */ export class L1FeeJuicePortalManager {
|
|
74
|
+
publicClient;
|
|
75
|
+
walletClient;
|
|
76
|
+
logger;
|
|
77
|
+
tokenManager;
|
|
78
|
+
contract;
|
|
79
|
+
constructor(portalAddress, tokenAddress, publicClient, walletClient, logger){
|
|
80
|
+
this.publicClient = publicClient;
|
|
81
|
+
this.walletClient = walletClient;
|
|
82
|
+
this.logger = logger;
|
|
83
|
+
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
84
|
+
this.contract = getContract({
|
|
85
|
+
address: portalAddress.toString(),
|
|
86
|
+
abi: FeeJuicePortalAbi,
|
|
87
|
+
client: this.walletClient
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Returns the associated token manager for the L1 ERC20. */ getTokenManager() {
|
|
91
|
+
return this.tokenManager;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Bridges fee juice from L1 to L2 publicly. Handles L1 ERC20 approvals. Returns once the tx has been mined.
|
|
95
|
+
* @param to - Address to send the tokens to on L2.
|
|
96
|
+
* @param amount - Amount of tokens to send.
|
|
97
|
+
* @param mint - Whether to mint the tokens before sending (only during testing).
|
|
98
|
+
*/ async bridgeTokensPublic(to, amount, mint = false) {
|
|
99
|
+
const [claimSecret, claimSecretHash] = await generateClaimSecret();
|
|
100
|
+
if (mint) {
|
|
101
|
+
await this.tokenManager.mint(amount, this.walletClient.account.address);
|
|
102
|
+
}
|
|
103
|
+
await this.tokenManager.approve(amount, this.contract.address, 'FeeJuice Portal');
|
|
104
|
+
this.logger.info('Sending L1 Fee Juice to L2 to be claimed publicly');
|
|
105
|
+
const args = [
|
|
106
|
+
to.toString(),
|
|
107
|
+
amount,
|
|
108
|
+
claimSecretHash.toString()
|
|
109
|
+
];
|
|
110
|
+
await this.contract.simulate.depositToAztecPublic(args);
|
|
111
|
+
const txReceipt = await this.publicClient.waitForTransactionReceipt({
|
|
112
|
+
hash: await this.contract.write.depositToAztecPublic(args)
|
|
113
|
+
});
|
|
114
|
+
const log = extractEvent(txReceipt.logs, this.contract.address, this.contract.abi, 'DepositToAztecPublic', (log)=>log.args.secretHash === claimSecretHash.toString() && log.args.amount === amount && log.args.to === to.toString(), this.logger);
|
|
115
|
+
return {
|
|
116
|
+
claimAmount: amount,
|
|
117
|
+
claimSecret,
|
|
118
|
+
claimSecretHash,
|
|
119
|
+
messageHash: log.args.key,
|
|
120
|
+
messageLeafIndex: log.args.index
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new instance
|
|
125
|
+
* @param pxe - PXE client used for retrieving the L1 contract addresses.
|
|
126
|
+
* @param publicClient - L1 public client.
|
|
127
|
+
* @param walletClient - L1 wallet client.
|
|
128
|
+
* @param logger - Logger.
|
|
129
|
+
*/ static async new(pxe, publicClient, walletClient, logger) {
|
|
130
|
+
const { l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress } } = await pxe.getNodeInfo();
|
|
131
|
+
if (feeJuiceAddress.isZero() || feeJuicePortalAddress.isZero()) {
|
|
132
|
+
throw new Error('Portal or token not deployed on L1');
|
|
133
|
+
}
|
|
134
|
+
return new L1FeeJuicePortalManager(feeJuicePortalAddress, feeJuiceAddress, publicClient, walletClient, logger);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Helper for interacting with a test TokenPortal on L1 for sending tokens to L2. */ export class L1ToL2TokenPortalManager {
|
|
138
|
+
publicClient;
|
|
139
|
+
walletClient;
|
|
140
|
+
logger;
|
|
141
|
+
portal;
|
|
142
|
+
tokenManager;
|
|
143
|
+
constructor(portalAddress, tokenAddress, publicClient, walletClient, logger){
|
|
144
|
+
this.publicClient = publicClient;
|
|
145
|
+
this.walletClient = walletClient;
|
|
146
|
+
this.logger = logger;
|
|
147
|
+
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
148
|
+
this.portal = getContract({
|
|
149
|
+
address: portalAddress.toString(),
|
|
150
|
+
abi: TokenPortalAbi,
|
|
151
|
+
client: this.walletClient
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** Returns the token manager for the underlying L1 token. */ getTokenManager() {
|
|
155
|
+
return this.tokenManager;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Bridges tokens from L1 to L2. Handles token approvals. Returns once the tx has been mined.
|
|
159
|
+
* @param to - Address to send the tokens to on L2.
|
|
160
|
+
* @param amount - Amount of tokens to send.
|
|
161
|
+
* @param mint - Whether to mint the tokens before sending (only during testing).
|
|
162
|
+
*/ async bridgeTokensPublic(to, amount, mint = false) {
|
|
163
|
+
const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint);
|
|
164
|
+
this.logger.info('Sending L1 tokens to L2 to be claimed publicly');
|
|
165
|
+
const { request } = await this.portal.simulate.depositToAztecPublic([
|
|
166
|
+
to.toString(),
|
|
167
|
+
amount,
|
|
168
|
+
claimSecretHash.toString()
|
|
169
|
+
]);
|
|
170
|
+
const txReceipt = await this.publicClient.waitForTransactionReceipt({
|
|
171
|
+
hash: await this.walletClient.writeContract(request)
|
|
172
|
+
});
|
|
173
|
+
const log = extractEvent(txReceipt.logs, this.portal.address, this.portal.abi, 'DepositToAztecPublic', (log)=>log.args.secretHash === claimSecretHash.toString() && log.args.amount === amount && log.args.to === to.toString(), this.logger);
|
|
174
|
+
return {
|
|
175
|
+
claimAmount: amount,
|
|
176
|
+
claimSecret,
|
|
177
|
+
claimSecretHash,
|
|
178
|
+
messageHash: log.args.key,
|
|
179
|
+
messageLeafIndex: log.args.index
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Bridges tokens from L1 to L2 privately. Handles token approvals. Returns once the tx has been mined.
|
|
184
|
+
* @param to - Address to send the tokens to on L2.
|
|
185
|
+
* @param amount - Amount of tokens to send.
|
|
186
|
+
* @param mint - Whether to mint the tokens before sending (only during testing).
|
|
187
|
+
*/ async bridgeTokensPrivate(to, amount, mint = false) {
|
|
188
|
+
const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint);
|
|
189
|
+
this.logger.info('Sending L1 tokens to L2 to be claimed privately');
|
|
190
|
+
const { request } = await this.portal.simulate.depositToAztecPrivate([
|
|
191
|
+
amount,
|
|
192
|
+
claimSecretHash.toString()
|
|
193
|
+
]);
|
|
194
|
+
const txReceipt = await this.publicClient.waitForTransactionReceipt({
|
|
195
|
+
hash: await this.walletClient.writeContract(request)
|
|
196
|
+
});
|
|
197
|
+
const log = extractEvent(txReceipt.logs, this.portal.address, this.portal.abi, 'DepositToAztecPrivate', (log)=>log.args.amount === amount && log.args.secretHashForL2MessageConsumption === claimSecretHash.toString(), this.logger);
|
|
198
|
+
this.logger.info(`Claim message secret: ${claimSecret.toString()}, claim message secret hash: ${claimSecretHash.toString()}`);
|
|
199
|
+
return {
|
|
200
|
+
claimAmount: amount,
|
|
201
|
+
claimSecret,
|
|
202
|
+
claimSecretHash,
|
|
203
|
+
recipient: to,
|
|
204
|
+
messageHash: log.args.key,
|
|
205
|
+
messageLeafIndex: log.args.index
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async bridgeSetup(amount, mint) {
|
|
209
|
+
if (mint) {
|
|
210
|
+
await this.tokenManager.mint(amount, this.walletClient.account.address);
|
|
211
|
+
}
|
|
212
|
+
await this.tokenManager.approve(amount, this.portal.address, 'TokenPortal');
|
|
213
|
+
return generateClaimSecret();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** Helper for interacting with a test TokenPortal on L1 for both withdrawing from and bridging to L2. */ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
217
|
+
outbox;
|
|
218
|
+
constructor(portalAddress, tokenAddress, outboxAddress, publicClient, walletClient, logger){
|
|
219
|
+
super(portalAddress, tokenAddress, publicClient, walletClient, logger);
|
|
220
|
+
this.outbox = getContract({
|
|
221
|
+
address: outboxAddress.toString(),
|
|
222
|
+
abi: OutboxAbi,
|
|
223
|
+
client: walletClient
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Withdraws funds from the portal by consuming an L2 to L1 message. Returns once the tx is mined on L1.
|
|
228
|
+
* @param amount - Amount to withdraw.
|
|
229
|
+
* @param recipient - Who will receive the funds.
|
|
230
|
+
* @param blockNumber - L2 block number of the message.
|
|
231
|
+
* @param messageIndex - Index of the message.
|
|
232
|
+
* @param siblingPath - Sibling path of the message.
|
|
233
|
+
*/ async withdrawFunds(amount, recipient, blockNumber, messageIndex, siblingPath) {
|
|
234
|
+
this.logger.info(`Sending L1 tx to consume message at block ${blockNumber} index ${messageIndex} to withdraw ${amount}`);
|
|
235
|
+
const isConsumedBefore = await this.outbox.read.hasMessageBeenConsumedAtBlockAndIndex([
|
|
236
|
+
blockNumber,
|
|
237
|
+
messageIndex
|
|
238
|
+
]);
|
|
239
|
+
if (isConsumedBefore) {
|
|
240
|
+
throw new Error(`L1 to L2 message at block ${blockNumber} index ${messageIndex} has already been consumed`);
|
|
241
|
+
}
|
|
242
|
+
// Call function on L1 contract to consume the message
|
|
243
|
+
const { request: withdrawRequest } = await this.portal.simulate.withdraw([
|
|
244
|
+
recipient.toString(),
|
|
245
|
+
amount,
|
|
246
|
+
false,
|
|
247
|
+
BigInt(blockNumber),
|
|
248
|
+
messageIndex,
|
|
249
|
+
siblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
250
|
+
]);
|
|
251
|
+
await this.publicClient.waitForTransactionReceipt({
|
|
252
|
+
hash: await this.walletClient.writeContract(withdrawRequest)
|
|
253
|
+
});
|
|
254
|
+
const isConsumedAfter = await this.outbox.read.hasMessageBeenConsumedAtBlockAndIndex([
|
|
255
|
+
blockNumber,
|
|
256
|
+
messageIndex
|
|
257
|
+
]);
|
|
258
|
+
if (!isConsumedAfter) {
|
|
259
|
+
throw new Error(`L1 to L2 message at block ${blockNumber} index ${messageIndex} not consumed after withdrawal`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Computes the L2 to L1 message leaf for the given parameters.
|
|
264
|
+
* @param amount - Amount to bridge.
|
|
265
|
+
* @param recipient - Recipient on L1.
|
|
266
|
+
* @param l2Bridge - Address of the L2 bridge.
|
|
267
|
+
* @param callerOnL1 - Caller address on L1.
|
|
268
|
+
*/ getL2ToL1MessageLeaf(amount, recipient, l2Bridge, callerOnL1 = EthAddress.ZERO) {
|
|
269
|
+
const content = sha256ToField([
|
|
270
|
+
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
271
|
+
recipient.toBuffer32(),
|
|
272
|
+
new Fr(amount).toBuffer(),
|
|
273
|
+
callerOnL1.toBuffer32()
|
|
274
|
+
]);
|
|
275
|
+
const leaf = sha256ToField([
|
|
276
|
+
l2Bridge.toBuffer(),
|
|
277
|
+
new Fr(1).toBuffer(),
|
|
278
|
+
EthAddress.fromString(this.portal.address).toBuffer32() ?? Buffer.alloc(32, 0),
|
|
279
|
+
new Fr(this.publicClient.chain.id).toBuffer(),
|
|
280
|
+
content.toBuffer()
|
|
281
|
+
]);
|
|
282
|
+
return leaf;
|
|
283
|
+
}
|
|
284
|
+
}
|
package/dest/api/fee.js
CHANGED
|
@@ -3,4 +3,3 @@ export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js';
|
|
|
3
3
|
export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js';
|
|
4
4
|
export { FeeJuicePaymentMethodWithClaim } from '../fee/fee_juice_payment_method_with_claim.js';
|
|
5
5
|
export { NoFeePaymentMethod } from '../fee/no_fee_payment_method.js';
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmVlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS9mZWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFDM0UsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sc0NBQXNDLENBQUM7QUFDL0UsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDN0UsT0FBTyxFQUFFLDhCQUE4QixFQUFFLE1BQU0sK0NBQStDLENBQUM7QUFDL0YsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0saUNBQWlDLENBQUMifQ==
|
package/dest/api/fields.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export { Point, Fr, Fq, GrumpkinScalar } from '@aztec/foundation/fields';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS9maWVsZHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLGNBQWMsRUFBRSxNQUFNLDBCQUEwQixDQUFDIn0=
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHhlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwaS9pbnRlcmZhY2VzL3B4ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
|
1
|
+
export { };
|
package/dest/api/log.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createLogger } from '@aztec/foundation/log';
|
package/dest/api/log_id.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export { LogId } from '@aztec/circuit-types/log_id';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX2lkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS9sb2dfaWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLDZCQUE2QixDQUFDIn0=
|
package/dest/api/tx_hash.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export { TxHash } from '@aztec/circuit-types/tx_hash';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfaGFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGkvdHhfaGFzaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sOEJBQThCLENBQUMifQ==
|
package/dest/api/wallet.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { AccountWallet, AccountWalletWithSecretKey as AccountWalletWithSecretKey, SignerlessWallet, getWallet
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS93YWxsZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNMLGFBQWEsRUFDYiwwQkFBMEIsSUFBSSwwQkFBMEIsRUFDeEQsZ0JBQWdCLEVBRWhCLFNBQVMsR0FDVixNQUFNLG9CQUFvQixDQUFDIn0=
|
|
1
|
+
export { AccountWallet, AccountWalletWithSecretKey as AccountWalletWithSecretKey, SignerlessWallet, getWallet } from '../wallet/index.js';
|