@aztec/aztec.js 0.65.2 → 0.67.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/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +3 -3
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +5 -2
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +3 -3
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/proven_tx.js +3 -3
- package/dest/contract/sent_tx.d.ts +0 -5
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +2 -12
- 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 +8 -3
- package/dest/index.d.ts +5 -5
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -5
- package/dest/main.js +1 -1
- package/dest/rpc_clients/node/index.d.ts +2 -2
- package/dest/rpc_clients/node/index.d.ts.map +1 -1
- package/dest/rpc_clients/node/index.js +1 -1
- package/dest/utils/anvil_test_watcher.d.ts.map +1 -1
- package/dest/utils/anvil_test_watcher.js +5 -5
- package/dest/utils/cheat_codes.d.ts +2 -125
- package/dest/utils/cheat_codes.d.ts.map +1 -1
- package/dest/utils/cheat_codes.js +12 -236
- package/dest/utils/index.d.ts +1 -0
- package/dest/utils/index.d.ts.map +1 -1
- package/dest/utils/index.js +2 -1
- package/dest/utils/node.d.ts +4 -0
- package/dest/utils/node.d.ts.map +1 -0
- package/dest/utils/node.js +16 -0
- package/dest/utils/portal_manager.d.ts +8 -8
- package/dest/utils/portal_manager.d.ts.map +1 -1
- package/dest/utils/portal_manager.js +1 -1
- package/dest/utils/pxe.d.ts +2 -2
- package/dest/utils/pxe.d.ts.map +1 -1
- package/dest/utils/pxe.js +1 -1
- package/dest/wallet/account_wallet.d.ts +1 -0
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +4 -1
- package/dest/wallet/base_wallet.d.ts +2 -4
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +2 -14
- package/dest/wallet/signerless_wallet.d.ts +1 -0
- package/dest/wallet/signerless_wallet.d.ts.map +1 -1
- package/dest/wallet/signerless_wallet.js +4 -1
- package/package.json +12 -8
- package/src/contract/base_contract_interaction.ts +2 -2
- package/src/contract/deploy_method.ts +5 -1
- package/src/contract/deploy_sent_tx.ts +2 -2
- package/src/contract/proven_tx.ts +0 -4
- package/src/contract/sent_tx.ts +1 -16
- package/src/deployment/register_class.ts +8 -1
- package/src/index.ts +7 -10
- package/src/rpc_clients/node/index.ts +2 -2
- package/src/utils/anvil_test_watcher.ts +4 -4
- package/src/utils/cheat_codes.ts +17 -254
- package/src/utils/index.ts +1 -0
- package/src/utils/node.ts +17 -0
- package/src/utils/portal_manager.ts +7 -7
- package/src/utils/pxe.ts +2 -2
- package/src/wallet/account_wallet.ts +4 -0
- package/src/wallet/base_wallet.ts +3 -15
- package/src/wallet/signerless_wallet.ts +4 -0
package/src/index.ts
CHANGED
|
@@ -32,9 +32,9 @@ export {
|
|
|
32
32
|
type ContractNotes,
|
|
33
33
|
type ContractStorageLayout,
|
|
34
34
|
type DeployOptions,
|
|
35
|
+
type ProfileResult,
|
|
35
36
|
type SendMethodOptions,
|
|
36
37
|
type WaitOpts,
|
|
37
|
-
type ProfileResult,
|
|
38
38
|
} from './contract/index.js';
|
|
39
39
|
|
|
40
40
|
export { ContractDeployer } from './deployment/index.js';
|
|
@@ -42,7 +42,6 @@ export { ContractDeployer } from './deployment/index.js';
|
|
|
42
42
|
export {
|
|
43
43
|
AnvilTestWatcher,
|
|
44
44
|
CheatCodes,
|
|
45
|
-
EthCheatCodes,
|
|
46
45
|
L1FeeJuicePortalManager,
|
|
47
46
|
L1ToL2TokenPortalManager,
|
|
48
47
|
L1TokenManager,
|
|
@@ -54,14 +53,15 @@ export {
|
|
|
54
53
|
generatePublicKey,
|
|
55
54
|
readFieldCompressedString,
|
|
56
55
|
waitForPXE,
|
|
56
|
+
waitForNode,
|
|
57
57
|
type AztecAddressLike,
|
|
58
58
|
type EthAddressLike,
|
|
59
59
|
type EventSelectorLike,
|
|
60
60
|
type FieldLike,
|
|
61
61
|
type FunctionSelectorLike,
|
|
62
62
|
type L2AmountClaim,
|
|
63
|
-
type L2Claim,
|
|
64
63
|
type L2AmountClaimWithRecipient,
|
|
64
|
+
type L2Claim,
|
|
65
65
|
type WrappedFieldLike,
|
|
66
66
|
} from './utils/index.js';
|
|
67
67
|
|
|
@@ -112,9 +112,7 @@ export {
|
|
|
112
112
|
Comparator,
|
|
113
113
|
CompleteAddress,
|
|
114
114
|
ContractClass2BlockL2Logs,
|
|
115
|
-
EncryptedL2BlockL2Logs,
|
|
116
115
|
EncryptedLogPayload,
|
|
117
|
-
EncryptedNoteL2BlockL2Logs,
|
|
118
116
|
EpochProofQuote,
|
|
119
117
|
EpochProofQuotePayload,
|
|
120
118
|
EventMetadata,
|
|
@@ -127,9 +125,7 @@ export {
|
|
|
127
125
|
L1ToL2Message,
|
|
128
126
|
L2Actor,
|
|
129
127
|
L2Block,
|
|
130
|
-
L2BlockL2Logs,
|
|
131
128
|
LogId,
|
|
132
|
-
LogType,
|
|
133
129
|
MerkleTreeId,
|
|
134
130
|
Note,
|
|
135
131
|
PackedValues,
|
|
@@ -143,15 +139,16 @@ export {
|
|
|
143
139
|
UnencryptedL2Log,
|
|
144
140
|
UniqueNote,
|
|
145
141
|
createAztecNodeClient,
|
|
142
|
+
getTimestampRangeForEpoch,
|
|
146
143
|
merkleTreeIds,
|
|
147
144
|
mockEpochProofQuote,
|
|
148
145
|
mockTx,
|
|
149
146
|
type AztecNode,
|
|
147
|
+
type EpochConstants,
|
|
150
148
|
type LogFilter,
|
|
151
149
|
type PXE,
|
|
152
150
|
type PartialAddress,
|
|
153
151
|
type PublicKey,
|
|
154
|
-
type SyncStatus,
|
|
155
152
|
} from '@aztec/circuit-types';
|
|
156
153
|
|
|
157
154
|
// TODO: These kinds of things have no place on our public api.
|
|
@@ -161,7 +158,7 @@ export { decodeFromAbi, encodeArguments, type AbiType } from '@aztec/foundation/
|
|
|
161
158
|
export { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
162
159
|
export { sha256 } from '@aztec/foundation/crypto';
|
|
163
160
|
export { makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
164
|
-
export {
|
|
161
|
+
export { createLogger, type Logger } from '@aztec/foundation/log';
|
|
165
162
|
export { retry, retryUntil } from '@aztec/foundation/retry';
|
|
166
163
|
export { to2Fields, toBigInt } from '@aztec/foundation/serialize';
|
|
167
164
|
export { sleep } from '@aztec/foundation/sleep';
|
|
@@ -169,7 +166,7 @@ export { elapsed } from '@aztec/foundation/timer';
|
|
|
169
166
|
export { type FieldsOf } from '@aztec/foundation/types';
|
|
170
167
|
export { fileURLToPath } from '@aztec/foundation/url';
|
|
171
168
|
|
|
172
|
-
export { deployL1Contract, deployL1Contracts, type DeployL1Contracts } from '@aztec/ethereum';
|
|
169
|
+
export { EthCheatCodes, deployL1Contract, deployL1Contracts, type DeployL1Contracts } from '@aztec/ethereum';
|
|
173
170
|
|
|
174
171
|
// Start of section that exports public api via granular api.
|
|
175
172
|
// Here you *can* do `export *` as the granular api defacto exports things explicitly.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PXE } from '@aztec/circuit-types';
|
|
2
2
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
4
|
import { NoRetryError, makeBackoff, retry } from '@aztec/foundation/retry';
|
|
5
5
|
|
|
6
6
|
import { Axios, type AxiosError } from 'axios';
|
|
@@ -51,7 +51,7 @@ async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndp
|
|
|
51
51
|
* @param _logger - Debug logger to warn version incompatibilities.
|
|
52
52
|
* @returns A PXE client.
|
|
53
53
|
*/
|
|
54
|
-
export function createCompatibleClient(rpcUrl: string, logger:
|
|
54
|
+
export function createCompatibleClient(rpcUrl: string, logger: Logger): Promise<PXE> {
|
|
55
55
|
// Use axios due to timeout issues with fetch when proving TXs.
|
|
56
56
|
const fetch = async (host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) => {
|
|
57
57
|
return await retry(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EthCheatCodes, type Logger, createLogger } from '@aztec/aztec.js';
|
|
2
2
|
import { type EthAddress } from '@aztec/circuits.js';
|
|
3
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
4
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
@@ -18,7 +18,7 @@ export class AnvilTestWatcher {
|
|
|
18
18
|
|
|
19
19
|
private filledRunningPromise?: RunningPromise;
|
|
20
20
|
|
|
21
|
-
private logger:
|
|
21
|
+
private logger: Logger = createLogger(`aztecjs:utils:watcher`);
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
24
|
private cheatcodes: EthCheatCodes,
|
|
@@ -31,7 +31,7 @@ export class AnvilTestWatcher {
|
|
|
31
31
|
client: publicClient,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
this.logger.
|
|
34
|
+
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async start() {
|
|
@@ -48,7 +48,7 @@ export class AnvilTestWatcher {
|
|
|
48
48
|
if (isAutoMining) {
|
|
49
49
|
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
|
|
50
50
|
this.filledRunningPromise.start();
|
|
51
|
-
this.logger.info(`Watcher started`);
|
|
51
|
+
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
52
52
|
} else {
|
|
53
53
|
this.logger.info(`Watcher not started because not auto mining`);
|
|
54
54
|
}
|
package/src/utils/cheat_codes.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { type EpochProofClaim, type Note, type PXE } from '@aztec/circuit-types';
|
|
2
2
|
import { type AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
|
|
3
3
|
import { deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
|
|
4
|
-
import { type L1ContractAddresses } from '@aztec/ethereum';
|
|
5
|
-
import {
|
|
6
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
7
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { EthCheatCodes, type L1ContractAddresses } from '@aztec/ethereum';
|
|
5
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
8
6
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
9
7
|
|
|
10
|
-
import fs from 'fs';
|
|
11
8
|
import {
|
|
12
9
|
type GetContractReturnType,
|
|
13
10
|
type Hex,
|
|
@@ -49,254 +46,12 @@ export class CheatCodes {
|
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
/**
|
|
53
|
-
* A class that provides utility functions for interacting with ethereum (L1).
|
|
54
|
-
*/
|
|
55
|
-
export class EthCheatCodes {
|
|
56
|
-
constructor(
|
|
57
|
-
/**
|
|
58
|
-
* The RPC URL to use for interacting with the chain
|
|
59
|
-
*/
|
|
60
|
-
public rpcUrl: string,
|
|
61
|
-
/**
|
|
62
|
-
* The logger to use for the eth cheatcodes
|
|
63
|
-
*/
|
|
64
|
-
public logger = createDebugLogger('aztec:cheat_codes:eth'),
|
|
65
|
-
) {}
|
|
66
|
-
|
|
67
|
-
async rpcCall(method: string, params: any[]) {
|
|
68
|
-
const paramsString = JSON.stringify(params);
|
|
69
|
-
const content = {
|
|
70
|
-
body: `{"jsonrpc":"2.0", "method": "${method}", "params": ${paramsString}, "id": 1}`,
|
|
71
|
-
method: 'POST',
|
|
72
|
-
headers: { 'Content-Type': 'application/json' },
|
|
73
|
-
};
|
|
74
|
-
return await (await fetch(this.rpcUrl, content)).json();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get the auto mine status of the underlying chain
|
|
79
|
-
* @returns True if automine is on, false otherwise
|
|
80
|
-
*/
|
|
81
|
-
public async isAutoMining(): Promise<boolean> {
|
|
82
|
-
try {
|
|
83
|
-
const res = await this.rpcCall('anvil_getAutomine', []);
|
|
84
|
-
return res.result;
|
|
85
|
-
} catch (err) {
|
|
86
|
-
this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get the current blocknumber
|
|
93
|
-
* @returns The current block number
|
|
94
|
-
*/
|
|
95
|
-
public async blockNumber(): Promise<number> {
|
|
96
|
-
const res = await this.rpcCall('eth_blockNumber', []);
|
|
97
|
-
return parseInt(res.result, 16);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the current chainId
|
|
102
|
-
* @returns The current chainId
|
|
103
|
-
*/
|
|
104
|
-
public async chainId(): Promise<number> {
|
|
105
|
-
const res = await this.rpcCall('eth_chainId', []);
|
|
106
|
-
return parseInt(res.result, 16);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get the current timestamp
|
|
111
|
-
* @returns The current timestamp
|
|
112
|
-
*/
|
|
113
|
-
public async timestamp(): Promise<number> {
|
|
114
|
-
const res = await this.rpcCall('eth_getBlockByNumber', ['latest', true]);
|
|
115
|
-
return parseInt(res.result.timestamp, 16);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Advance the chain by a number of blocks
|
|
120
|
-
* @param numberOfBlocks - The number of blocks to mine
|
|
121
|
-
* @returns The current chainId
|
|
122
|
-
*/
|
|
123
|
-
public async mine(numberOfBlocks = 1): Promise<void> {
|
|
124
|
-
const res = await this.rpcCall('hardhat_mine', [numberOfBlocks]);
|
|
125
|
-
if (res.error) {
|
|
126
|
-
throw new Error(`Error mining: ${res.error.message}`);
|
|
127
|
-
}
|
|
128
|
-
this.logger.verbose(`Mined ${numberOfBlocks} L1 blocks`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Set the balance of an account
|
|
133
|
-
* @param account - The account to set the balance for
|
|
134
|
-
* @param balance - The balance to set
|
|
135
|
-
*/
|
|
136
|
-
public async setBalance(account: EthAddress, balance: bigint): Promise<void> {
|
|
137
|
-
const res = await this.rpcCall('anvil_setBalance', [account.toString(), toHex(balance)]);
|
|
138
|
-
if (res.error) {
|
|
139
|
-
throw new Error(`Error setting balance for ${account}: ${res.error.message}`);
|
|
140
|
-
}
|
|
141
|
-
this.logger.verbose(`Set balance for ${account} to ${balance}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Set the interval between blocks (block time)
|
|
146
|
-
* @param interval - The interval to use between blocks
|
|
147
|
-
*/
|
|
148
|
-
public async setBlockInterval(interval: number): Promise<void> {
|
|
149
|
-
const res = await this.rpcCall('anvil_setBlockTimestampInterval', [interval]);
|
|
150
|
-
if (res.error) {
|
|
151
|
-
throw new Error(`Error setting block interval: ${res.error.message}`);
|
|
152
|
-
}
|
|
153
|
-
this.logger.verbose(`Set L1 block interval to ${interval}`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Set the next block timestamp
|
|
158
|
-
* @param timestamp - The timestamp to set the next block to
|
|
159
|
-
*/
|
|
160
|
-
public async setNextBlockTimestamp(timestamp: number): Promise<void> {
|
|
161
|
-
const res = await this.rpcCall('evm_setNextBlockTimestamp', [timestamp]);
|
|
162
|
-
if (res.error) {
|
|
163
|
-
throw new Error(`Error setting next block timestamp: ${res.error.message}`);
|
|
164
|
-
}
|
|
165
|
-
this.logger.verbose(`Set L1 next block timestamp to ${timestamp}`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Set the next block timestamp and mines the block
|
|
170
|
-
* @param timestamp - The timestamp to set the next block to
|
|
171
|
-
*/
|
|
172
|
-
public async warp(timestamp: number | bigint): Promise<void> {
|
|
173
|
-
const res = await this.rpcCall('evm_setNextBlockTimestamp', [Number(timestamp)]);
|
|
174
|
-
if (res.error) {
|
|
175
|
-
throw new Error(`Error warping: ${res.error.message}`);
|
|
176
|
-
}
|
|
177
|
-
await this.mine();
|
|
178
|
-
this.logger.verbose(`Warped L1 timestamp to ${timestamp}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Dumps the current chain state to a file.
|
|
183
|
-
* @param fileName - The file name to dump state into
|
|
184
|
-
*/
|
|
185
|
-
public async dumpChainState(fileName: string): Promise<void> {
|
|
186
|
-
const res = await this.rpcCall('hardhat_dumpState', []);
|
|
187
|
-
if (res.error) {
|
|
188
|
-
throw new Error(`Error dumping state: ${res.error.message}`);
|
|
189
|
-
}
|
|
190
|
-
const jsonContent = JSON.stringify(res.result);
|
|
191
|
-
fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8');
|
|
192
|
-
this.logger.verbose(`Dumped state to ${fileName}`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Loads the chain state from a file.
|
|
197
|
-
* @param fileName - The file name to load state from
|
|
198
|
-
*/
|
|
199
|
-
public async loadChainState(fileName: string): Promise<void> {
|
|
200
|
-
const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8'));
|
|
201
|
-
const res = await this.rpcCall('hardhat_loadState', [data]);
|
|
202
|
-
if (res.error) {
|
|
203
|
-
throw new Error(`Error loading state: ${res.error.message}`);
|
|
204
|
-
}
|
|
205
|
-
this.logger.verbose(`Loaded state from ${fileName}`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Load the value at a storage slot of a contract address on eth
|
|
210
|
-
* @param contract - The contract address
|
|
211
|
-
* @param slot - The storage slot
|
|
212
|
-
* @returns - The value at the storage slot
|
|
213
|
-
*/
|
|
214
|
-
public async load(contract: EthAddress, slot: bigint): Promise<bigint> {
|
|
215
|
-
const res = await this.rpcCall('eth_getStorageAt', [contract.toString(), toHex(slot), 'latest']);
|
|
216
|
-
return BigInt(res.result);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Set the value at a storage slot of a contract address on eth
|
|
221
|
-
* @param contract - The contract address
|
|
222
|
-
* @param slot - The storage slot
|
|
223
|
-
* @param value - The value to set the storage slot to
|
|
224
|
-
*/
|
|
225
|
-
public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void> {
|
|
226
|
-
// for the rpc call, we need to change value to be a 32 byte hex string.
|
|
227
|
-
const res = await this.rpcCall('hardhat_setStorageAt', [contract.toString(), toHex(slot), toHex(value, true)]);
|
|
228
|
-
if (res.error) {
|
|
229
|
-
throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${res.error.message}`);
|
|
230
|
-
}
|
|
231
|
-
this.logger.verbose(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Computes the slot value for a given map and key.
|
|
236
|
-
* @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
|
|
237
|
-
* @param key - The key to lookup in the map
|
|
238
|
-
* @returns The storage slot of the value in the map
|
|
239
|
-
*/
|
|
240
|
-
public keccak256(baseSlot: bigint, key: bigint): bigint {
|
|
241
|
-
// abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
|
|
242
|
-
const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
|
|
243
|
-
return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Send transactions impersonating an externally owned account or contract.
|
|
248
|
-
* @param who - The address to impersonate
|
|
249
|
-
*/
|
|
250
|
-
public async startImpersonating(who: EthAddress | Hex): Promise<void> {
|
|
251
|
-
const res = await this.rpcCall('hardhat_impersonateAccount', [who.toString()]);
|
|
252
|
-
if (res.error) {
|
|
253
|
-
throw new Error(`Error impersonating ${who}: ${res.error.message}`);
|
|
254
|
-
}
|
|
255
|
-
this.logger.verbose(`Impersonating ${who}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Stop impersonating an account that you are currently impersonating.
|
|
260
|
-
* @param who - The address to stop impersonating
|
|
261
|
-
*/
|
|
262
|
-
public async stopImpersonating(who: EthAddress | Hex): Promise<void> {
|
|
263
|
-
const res = await this.rpcCall('hardhat_stopImpersonatingAccount', [who.toString()]);
|
|
264
|
-
if (res.error) {
|
|
265
|
-
throw new Error(`Error when stopping the impersonation of ${who}: ${res.error.message}`);
|
|
266
|
-
}
|
|
267
|
-
this.logger.verbose(`Stopped impersonating ${who}`);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Set the bytecode for a contract
|
|
272
|
-
* @param contract - The contract address
|
|
273
|
-
* @param bytecode - The bytecode to set
|
|
274
|
-
*/
|
|
275
|
-
public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void> {
|
|
276
|
-
const res = await this.rpcCall('hardhat_setCode', [contract.toString(), bytecode]);
|
|
277
|
-
if (res.error) {
|
|
278
|
-
throw new Error(`Error setting bytecode for ${contract}: ${res.error.message}`);
|
|
279
|
-
}
|
|
280
|
-
this.logger.verbose(`Set bytecode for ${contract} to ${bytecode}`);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Get the bytecode for a contract
|
|
285
|
-
* @param contract - The contract address
|
|
286
|
-
* @returns The bytecode for the contract
|
|
287
|
-
*/
|
|
288
|
-
public async getBytecode(contract: EthAddress): Promise<`0x${string}`> {
|
|
289
|
-
const res = await this.rpcCall('eth_getCode', [contract.toString(), 'latest']);
|
|
290
|
-
return res.result;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
49
|
/** Cheat codes for the L1 rollup contract. */
|
|
295
50
|
export class RollupCheatCodes {
|
|
296
51
|
private client: WalletClient & PublicClient;
|
|
297
52
|
private rollup: GetContractReturnType<typeof RollupAbi, WalletClient>;
|
|
298
53
|
|
|
299
|
-
private logger =
|
|
54
|
+
private logger = createLogger('aztecjs:cheat_codes');
|
|
300
55
|
|
|
301
56
|
constructor(private ethCheatCodes: EthCheatCodes, addresses: Pick<L1ContractAddresses, 'rollupAddress'>) {
|
|
302
57
|
this.client = createWalletClient({ chain: foundry, transport: http(ethCheatCodes.rpcUrl) }).extend(publicActions);
|
|
@@ -327,8 +82,11 @@ export class RollupCheatCodes {
|
|
|
327
82
|
/** The pending chain tip */ pending: bigint;
|
|
328
83
|
/** The proven chain tip */ proven: bigint;
|
|
329
84
|
}> {
|
|
330
|
-
const
|
|
331
|
-
return {
|
|
85
|
+
const res = await this.rollup.read.getTips();
|
|
86
|
+
return {
|
|
87
|
+
pending: res.pendingBlockNumber,
|
|
88
|
+
proven: res.provenBlockNumber,
|
|
89
|
+
};
|
|
332
90
|
}
|
|
333
91
|
|
|
334
92
|
/** Fetches the epoch and slot duration config from the rollup contract */
|
|
@@ -370,8 +128,13 @@ export class RollupCheatCodes {
|
|
|
370
128
|
/** Returns the current proof claim (if any) */
|
|
371
129
|
public async getProofClaim(): Promise<EpochProofClaim | undefined> {
|
|
372
130
|
// REFACTOR: This code is duplicated from l1-publisher
|
|
373
|
-
const
|
|
374
|
-
|
|
131
|
+
const {
|
|
132
|
+
epochToProve,
|
|
133
|
+
basisPointFee,
|
|
134
|
+
bondAmount,
|
|
135
|
+
bondProvider: bondProviderHex,
|
|
136
|
+
proposerClaimant: proposerClaimantHex,
|
|
137
|
+
} = await this.rollup.read.getProofClaim();
|
|
375
138
|
|
|
376
139
|
const bondProvider = EthAddress.fromString(bondProviderHex);
|
|
377
140
|
const proposerClaimant = EthAddress.fromString(proposerClaimantHex);
|
|
@@ -396,7 +159,7 @@ export class RollupCheatCodes {
|
|
|
396
159
|
public async markAsProven(maybeBlockNumber?: number | bigint) {
|
|
397
160
|
const blockNumber = maybeBlockNumber
|
|
398
161
|
? BigInt(maybeBlockNumber)
|
|
399
|
-
: await this.rollup.read.
|
|
162
|
+
: await this.rollup.read.getTips().then(({ pendingBlockNumber }) => pendingBlockNumber);
|
|
400
163
|
|
|
401
164
|
await this.asOwner(async account => {
|
|
402
165
|
await this.rollup.write.setAssumeProvenThroughBlockNumber([blockNumber], { account, chain: this.client.chain });
|
|
@@ -434,7 +197,7 @@ export class AztecCheatCodes {
|
|
|
434
197
|
/**
|
|
435
198
|
* The logger to use for the aztec cheatcodes
|
|
436
199
|
*/
|
|
437
|
-
public logger =
|
|
200
|
+
public logger = createLogger('aztecjs:cheat_codes'),
|
|
438
201
|
) {}
|
|
439
202
|
|
|
440
203
|
/**
|
package/src/utils/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './abi_types.js';
|
|
|
4
4
|
export * from './cheat_codes.js';
|
|
5
5
|
export * from './authwit.js';
|
|
6
6
|
export * from './pxe.js';
|
|
7
|
+
export * from './node.js';
|
|
7
8
|
export * from './anvil_test_watcher.js';
|
|
8
9
|
export * from './field_compressed_string.js';
|
|
9
10
|
export * from './portal_manager.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AztecNode } from '@aztec/circuit-types';
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
|
+
|
|
5
|
+
export const waitForNode = async (node: AztecNode, logger?: Logger) => {
|
|
6
|
+
await retryUntil(async () => {
|
|
7
|
+
try {
|
|
8
|
+
logger?.verbose('Attempting to contact Aztec node...');
|
|
9
|
+
await node.getNodeInfo();
|
|
10
|
+
logger?.verbose('Contacted Aztec node');
|
|
11
|
+
return true;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
logger?.verbose('Failed to contact Aztec Node');
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, 'RPC Get Node Info');
|
|
17
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AztecAddress,
|
|
3
|
-
type DebugLogger,
|
|
4
3
|
EthAddress,
|
|
5
4
|
Fr,
|
|
5
|
+
type Logger,
|
|
6
6
|
type PXE,
|
|
7
7
|
type SiblingPath,
|
|
8
8
|
computeSecretHash,
|
|
@@ -49,7 +49,7 @@ function stringifyEthAddress(address: EthAddress | Hex, name?: string) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** Generates a pair secret and secret hash */
|
|
52
|
-
export function generateClaimSecret(logger?:
|
|
52
|
+
export function generateClaimSecret(logger?: Logger): [Fr, Fr] {
|
|
53
53
|
const secret = Fr.random();
|
|
54
54
|
const secretHash = computeSecretHash(secret);
|
|
55
55
|
logger?.verbose(`Generated claim secret=${secret.toString()} hash=${secretHash.toString()}`);
|
|
@@ -65,7 +65,7 @@ export class L1TokenManager {
|
|
|
65
65
|
public readonly address: EthAddress,
|
|
66
66
|
private publicClient: PublicClient<HttpTransport, Chain>,
|
|
67
67
|
private walletClient: WalletClient<HttpTransport, Chain, Account>,
|
|
68
|
-
private logger:
|
|
68
|
+
private logger: Logger,
|
|
69
69
|
) {
|
|
70
70
|
this.contract = getContract({
|
|
71
71
|
address: this.address.toString(),
|
|
@@ -122,7 +122,7 @@ export class L1FeeJuicePortalManager {
|
|
|
122
122
|
tokenAddress: EthAddress,
|
|
123
123
|
private readonly publicClient: PublicClient<HttpTransport, Chain>,
|
|
124
124
|
private readonly walletClient: WalletClient<HttpTransport, Chain, Account>,
|
|
125
|
-
private readonly logger:
|
|
125
|
+
private readonly logger: Logger,
|
|
126
126
|
) {
|
|
127
127
|
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
128
128
|
this.contract = getContract({
|
|
@@ -192,7 +192,7 @@ export class L1FeeJuicePortalManager {
|
|
|
192
192
|
pxe: PXE,
|
|
193
193
|
publicClient: PublicClient<HttpTransport, Chain>,
|
|
194
194
|
walletClient: WalletClient<HttpTransport, Chain, Account>,
|
|
195
|
-
logger:
|
|
195
|
+
logger: Logger,
|
|
196
196
|
): Promise<L1FeeJuicePortalManager> {
|
|
197
197
|
const {
|
|
198
198
|
l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress },
|
|
@@ -216,7 +216,7 @@ export class L1ToL2TokenPortalManager {
|
|
|
216
216
|
tokenAddress: EthAddress,
|
|
217
217
|
protected publicClient: PublicClient<HttpTransport, Chain>,
|
|
218
218
|
protected walletClient: WalletClient<HttpTransport, Chain, Account>,
|
|
219
|
-
protected logger:
|
|
219
|
+
protected logger: Logger,
|
|
220
220
|
) {
|
|
221
221
|
this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
|
|
222
222
|
this.portal = getContract({
|
|
@@ -334,7 +334,7 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
|
334
334
|
outboxAddress: EthAddress,
|
|
335
335
|
publicClient: PublicClient<HttpTransport, Chain>,
|
|
336
336
|
walletClient: WalletClient<HttpTransport, Chain, Account>,
|
|
337
|
-
logger:
|
|
337
|
+
logger: Logger,
|
|
338
338
|
) {
|
|
339
339
|
super(portalAddress, tokenAddress, publicClient, walletClient, logger);
|
|
340
340
|
this.outbox = getContract({
|
package/src/utils/pxe.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type PXE } from '@aztec/circuit-types';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
4
|
|
|
5
|
-
export const waitForPXE = async (pxe: PXE, logger?:
|
|
5
|
+
export const waitForPXE = async (pxe: PXE, logger?: Logger) => {
|
|
6
6
|
await retryUntil(async () => {
|
|
7
7
|
try {
|
|
8
8
|
logger?.verbose('Attempting to contact PXE...');
|
|
@@ -34,6 +34,10 @@ export class AccountWallet extends BaseWallet {
|
|
|
34
34
|
return this.account.getVersion();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
38
|
+
return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
|
|
39
|
+
}
|
|
40
|
+
|
|
37
41
|
/**
|
|
38
42
|
* Computes an authentication witness from either a message hash or an intent.
|
|
39
43
|
*
|
|
@@ -6,12 +6,10 @@ import {
|
|
|
6
6
|
type IncomingNotesFilter,
|
|
7
7
|
type L2Block,
|
|
8
8
|
type LogFilter,
|
|
9
|
-
type OutgoingNotesFilter,
|
|
10
9
|
type PXE,
|
|
11
10
|
type PXEInfo,
|
|
12
11
|
type PrivateExecutionResult,
|
|
13
12
|
type SiblingPath,
|
|
14
|
-
type SyncStatus,
|
|
15
13
|
type Tx,
|
|
16
14
|
type TxExecutionRequest,
|
|
17
15
|
type TxHash,
|
|
@@ -44,6 +42,8 @@ import { type IntentAction, type IntentInnerHash } from '../utils/authwit.js';
|
|
|
44
42
|
export abstract class BaseWallet implements Wallet {
|
|
45
43
|
constructor(protected readonly pxe: PXE, private scopes?: AztecAddress[]) {}
|
|
46
44
|
|
|
45
|
+
abstract isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;
|
|
46
|
+
|
|
47
47
|
abstract getCompleteAddress(): CompleteAddress;
|
|
48
48
|
|
|
49
49
|
abstract getChainId(): Fr;
|
|
@@ -131,9 +131,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
131
131
|
getIncomingNotes(filter: IncomingNotesFilter): Promise<UniqueNote[]> {
|
|
132
132
|
return this.pxe.getIncomingNotes(filter);
|
|
133
133
|
}
|
|
134
|
-
getOutgoingNotes(filter: OutgoingNotesFilter): Promise<UniqueNote[]> {
|
|
135
|
-
return this.pxe.getOutgoingNotes(filter);
|
|
136
|
-
}
|
|
137
134
|
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
|
|
138
135
|
return this.pxe.getPublicStorageAt(contract, storageSlot);
|
|
139
136
|
}
|
|
@@ -172,12 +169,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
172
169
|
getNodeInfo(): Promise<NodeInfo> {
|
|
173
170
|
return this.pxe.getNodeInfo();
|
|
174
171
|
}
|
|
175
|
-
isGlobalStateSynchronized() {
|
|
176
|
-
return this.pxe.isGlobalStateSynchronized();
|
|
177
|
-
}
|
|
178
|
-
getSyncStatus(): Promise<SyncStatus> {
|
|
179
|
-
return this.pxe.getSyncStatus();
|
|
180
|
-
}
|
|
181
172
|
addAuthWitness(authWitness: AuthWitness) {
|
|
182
173
|
return this.pxe.addAuthWitness(authWitness);
|
|
183
174
|
}
|
|
@@ -200,10 +191,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
200
191
|
event: EventMetadataDefinition,
|
|
201
192
|
from: number,
|
|
202
193
|
limit: number,
|
|
203
|
-
vpks: Point[] = [
|
|
204
|
-
this.getCompleteAddress().publicKeys.masterIncomingViewingPublicKey,
|
|
205
|
-
this.getCompleteAddress().publicKeys.masterOutgoingViewingPublicKey,
|
|
206
|
-
],
|
|
194
|
+
vpks: Point[] = [this.getCompleteAddress().publicKeys.masterIncomingViewingPublicKey],
|
|
207
195
|
): Promise<T[]> {
|
|
208
196
|
return this.pxe.getEncryptedEvents(event, from, limit, vpks);
|
|
209
197
|
}
|
|
@@ -42,4 +42,8 @@ export class SignerlessWallet extends BaseWallet {
|
|
|
42
42
|
createAuthWit(_intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise<AuthWitness> {
|
|
43
43
|
throw new Error('SignerlessWallet: Method createAuthWit not implemented.');
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
47
|
+
return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
|
|
48
|
+
}
|
|
45
49
|
}
|