@aztec/ethereum 3.0.3 → 4.0.0-devnet.1-patch.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/client.js +6 -2
- package/dest/config.d.ts +17 -27
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +51 -54
- package/dest/contracts/empire_base.d.ts +2 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +2 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +22 -15
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +11 -1
- package/dest/contracts/governance_proposer.d.ts +2 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +395 -9
- package/dest/contracts/inbox.d.ts +22 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +36 -1
- package/dest/contracts/index.d.ts +3 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +2 -0
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +1 -1
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +2 -1
- package/dest/contracts/outbox.d.ts +41 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +86 -0
- package/dest/contracts/rollup.d.ts +162 -81
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +691 -132
- package/dest/contracts/tally_slashing_proposer.d.ts +1 -1
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +8 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +17 -2
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +87 -19
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +4964 -1573
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +1 -1
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +3 -3
- package/dest/l1_tx_utils/constants.d.ts +8 -2
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +27 -2
- package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/index.d.ts +3 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +2 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +6 -6
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +35 -143
- package/dest/publisher_manager.d.ts +3 -2
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +2 -2
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +12 -4
- package/dest/test/chain_monitor.js +1 -2
- package/dest/test/eth_cheat_codes.d.ts +13 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +3 -1
- package/dest/test/rollup_cheat_codes.d.ts +5 -2
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +22 -3
- package/dest/test/start_anvil.js +1 -1
- package/dest/test/tx_delayer.js +1 -1
- package/dest/utils.d.ts +15 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +64 -0
- package/package.json +9 -7
- package/src/client.ts +2 -2
- package/src/config.ts +62 -53
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +1 -1
- package/src/contracts/empire_slashing_proposer.ts +22 -28
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/governance.ts +10 -1
- package/src/contracts/governance_proposer.ts +10 -2
- package/src/contracts/inbox.ts +53 -1
- package/src/contracts/index.ts +2 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +5 -2
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/rollup.ts +364 -100
- package/src/contracts/tally_slashing_proposer.ts +5 -1
- package/src/deploy_aztec_l1_contracts.ts +94 -18
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_contract_addresses.ts +22 -20
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/index.ts +2 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +6 -6
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +48 -186
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +11 -3
- package/src/test/chain_monitor.ts +1 -1
- package/src/test/eth_cheat_codes.ts +1 -1
- package/src/test/rollup_cheat_codes.ts +22 -4
- package/src/test/start_anvil.ts +1 -1
- package/src/test/tx_delayer.ts +1 -1
- package/src/utils.ts +82 -0
|
@@ -6,7 +6,6 @@ import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingPro
|
|
|
6
6
|
|
|
7
7
|
import EventEmitter from 'events';
|
|
8
8
|
import {
|
|
9
|
-
type EncodeFunctionDataParameters,
|
|
10
9
|
type GetContractReturnType,
|
|
11
10
|
type Hex,
|
|
12
11
|
type Log,
|
|
@@ -79,11 +78,16 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
79
78
|
public async getRoundInfo(
|
|
80
79
|
rollupAddress: Hex,
|
|
81
80
|
round: bigint,
|
|
82
|
-
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; executed: boolean }> {
|
|
81
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }> {
|
|
83
82
|
const result = await this.proposer.read.getRoundData([rollupAddress, round]);
|
|
83
|
+
const [signalCount, quorum] = await Promise.all([
|
|
84
|
+
this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
|
|
85
|
+
this.getQuorumSize(),
|
|
86
|
+
]);
|
|
84
87
|
return {
|
|
85
88
|
lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
|
|
86
89
|
payloadWithMostSignals: result.payloadWithMostSignals,
|
|
90
|
+
quorumReached: signalCount >= quorum,
|
|
87
91
|
executed: result.executed,
|
|
88
92
|
};
|
|
89
93
|
}
|
|
@@ -95,6 +99,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
95
99
|
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
96
100
|
return {
|
|
97
101
|
to: this.address.toString(),
|
|
102
|
+
abi: EmpireSlashingProposerAbi,
|
|
98
103
|
data: encodeSignal(payload),
|
|
99
104
|
};
|
|
100
105
|
}
|
|
@@ -116,6 +121,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
116
121
|
);
|
|
117
122
|
return {
|
|
118
123
|
to: this.address.toString(),
|
|
124
|
+
abi: EmpireSlashingProposerAbi,
|
|
119
125
|
data: encodeSignalWithSignature(payload, signature),
|
|
120
126
|
};
|
|
121
127
|
}
|
|
@@ -175,6 +181,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
175
181
|
public buildExecuteRoundRequest(round: bigint): L1TxRequest {
|
|
176
182
|
return {
|
|
177
183
|
to: this.address.toString(),
|
|
184
|
+
abi: EmpireSlashingProposerAbi,
|
|
178
185
|
data: encodeFunctionData({
|
|
179
186
|
abi: EmpireSlashingProposerAbi,
|
|
180
187
|
functionName: 'submitRoundWinner',
|
|
@@ -217,24 +224,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
217
224
|
if (typeof round === 'number') {
|
|
218
225
|
round = BigInt(round);
|
|
219
226
|
}
|
|
220
|
-
const
|
|
221
|
-
abi: EmpireSlashingProposerAbi,
|
|
222
|
-
functionName: 'submitRoundWinner',
|
|
223
|
-
args: [round],
|
|
224
|
-
};
|
|
225
|
-
const data = encodeFunctionData(args);
|
|
227
|
+
const request = this.buildExecuteRoundRequest(round);
|
|
226
228
|
const response = await txUtils
|
|
227
|
-
.sendAndMonitorTransaction(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
{
|
|
233
|
-
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
234
|
-
// for the actual slashing dynamically.
|
|
235
|
-
gasLimitBufferPercentage: 50, // +50% gas
|
|
236
|
-
},
|
|
237
|
-
)
|
|
229
|
+
.sendAndMonitorTransaction(request, {
|
|
230
|
+
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
231
|
+
// for the actual slashing dynamically.
|
|
232
|
+
gasLimitBufferPercentage: 50, // +50% gas
|
|
233
|
+
})
|
|
238
234
|
.catch(err => {
|
|
239
235
|
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
240
236
|
throw new ProposalAlreadyExecutedError(round);
|
|
@@ -243,15 +239,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
243
239
|
});
|
|
244
240
|
|
|
245
241
|
if (response.receipt.status === 'reverted') {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
[],
|
|
254
|
-
);
|
|
242
|
+
const args = {
|
|
243
|
+
abi: EmpireSlashingProposerAbi,
|
|
244
|
+
functionName: 'submitRoundWinner' as const,
|
|
245
|
+
args: [round] as const,
|
|
246
|
+
address: this.address.toString(),
|
|
247
|
+
};
|
|
248
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
|
|
255
249
|
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
256
250
|
throw new ProposalAlreadyExecutedError(round);
|
|
257
251
|
}
|
|
@@ -4,13 +4,14 @@ import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
|
|
|
4
4
|
import { type Hex, encodeFunctionData, getContract } from 'viem';
|
|
5
5
|
|
|
6
6
|
import type { L1TxUtils } from '../l1_tx_utils/index.js';
|
|
7
|
+
import type { ViemClient } from '../types.js';
|
|
7
8
|
|
|
8
9
|
export class FeeAssetHandlerContract {
|
|
9
10
|
public address: EthAddress;
|
|
10
11
|
|
|
11
12
|
constructor(
|
|
13
|
+
public readonly client: ViemClient,
|
|
12
14
|
address: Hex | EthAddress,
|
|
13
|
-
public readonly txUtils: L1TxUtils,
|
|
14
15
|
) {
|
|
15
16
|
if (address instanceof EthAddress) {
|
|
16
17
|
address = address.toString();
|
|
@@ -22,7 +23,7 @@ export class FeeAssetHandlerContract {
|
|
|
22
23
|
const contract = getContract({
|
|
23
24
|
abi: FeeAssetHandlerAbi,
|
|
24
25
|
address: this.address.toString(),
|
|
25
|
-
client: this.
|
|
26
|
+
client: this.client,
|
|
26
27
|
});
|
|
27
28
|
return EthAddress.fromString(await contract.read.owner());
|
|
28
29
|
}
|
|
@@ -31,17 +32,18 @@ export class FeeAssetHandlerContract {
|
|
|
31
32
|
const contract = getContract({
|
|
32
33
|
abi: FeeAssetHandlerAbi,
|
|
33
34
|
address: this.address.toString(),
|
|
34
|
-
client: this.
|
|
35
|
+
client: this.client,
|
|
35
36
|
});
|
|
36
37
|
return contract.read.mintAmount();
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
public mint(recipient: Hex | EthAddress) {
|
|
40
|
+
public mint(txUtils: L1TxUtils, recipient: Hex | EthAddress) {
|
|
40
41
|
if (recipient instanceof EthAddress) {
|
|
41
42
|
recipient = recipient.toString();
|
|
42
43
|
}
|
|
43
|
-
return
|
|
44
|
+
return txUtils.sendAndMonitorTransaction({
|
|
44
45
|
to: this.address.toString(),
|
|
46
|
+
abi: FeeAssetHandlerAbi,
|
|
45
47
|
data: encodeFunctionData({
|
|
46
48
|
abi: FeeAssetHandlerAbi,
|
|
47
49
|
functionName: 'mint',
|
|
@@ -50,9 +52,10 @@ export class FeeAssetHandlerContract {
|
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
public setMintAmount(amount: bigint) {
|
|
54
|
-
return
|
|
55
|
+
public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
|
|
56
|
+
return txUtils.sendAndMonitorTransaction({
|
|
55
57
|
to: this.address.toString(),
|
|
58
|
+
abi: FeeAssetHandlerAbi,
|
|
56
59
|
data: encodeFunctionData({
|
|
57
60
|
abi: FeeAssetHandlerAbi,
|
|
58
61
|
functionName: 'setMintAmount',
|
|
@@ -174,6 +174,13 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
174
174
|
return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/** Returns the user's voting power for a specific proposal, checked at pendingThrough timestamp. */
|
|
178
|
+
public async getPowerForProposal(proposalId: bigint): Promise<bigint> {
|
|
179
|
+
const proposal = await this.getProposal(proposalId);
|
|
180
|
+
const pendingThrough = proposal.creation + proposal.config.votingDelay;
|
|
181
|
+
return this.governanceContract.read.powerAt([this.client.account.address, pendingThrough]);
|
|
182
|
+
}
|
|
183
|
+
|
|
177
184
|
public async vote({
|
|
178
185
|
proposalId,
|
|
179
186
|
voteAmount,
|
|
@@ -190,7 +197,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
190
197
|
const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
|
|
191
198
|
const retryDelaySeconds = 12;
|
|
192
199
|
|
|
193
|
-
voteAmount = voteAmount ?? (await this.
|
|
200
|
+
voteAmount = voteAmount ?? (await this.getPowerForProposal(proposalId));
|
|
194
201
|
|
|
195
202
|
let success = false;
|
|
196
203
|
for (let i = 0; i < retries; i++) {
|
|
@@ -204,6 +211,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
204
211
|
|
|
205
212
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
206
213
|
to: this.governanceContract.address,
|
|
214
|
+
abi: GovernanceAbi,
|
|
207
215
|
data: encodedVoteData,
|
|
208
216
|
});
|
|
209
217
|
|
|
@@ -258,6 +266,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
258
266
|
|
|
259
267
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
260
268
|
to: this.governanceContract.address,
|
|
269
|
+
abi: GovernanceAbi,
|
|
261
270
|
data: encodedExecuteData,
|
|
262
271
|
});
|
|
263
272
|
|
|
@@ -62,11 +62,16 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
62
62
|
public async getRoundInfo(
|
|
63
63
|
rollupAddress: Hex,
|
|
64
64
|
round: bigint,
|
|
65
|
-
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; executed: boolean }> {
|
|
65
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }> {
|
|
66
66
|
const result = await this.proposer.read.getRoundData([rollupAddress, round]);
|
|
67
|
+
const [signalCount, quorum] = await Promise.all([
|
|
68
|
+
this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
|
|
69
|
+
this.getQuorumSize(),
|
|
70
|
+
]);
|
|
67
71
|
return {
|
|
68
72
|
lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
|
|
69
73
|
payloadWithMostSignals: result.payloadWithMostSignals,
|
|
74
|
+
quorumReached: signalCount >= quorum,
|
|
70
75
|
executed: result.executed,
|
|
71
76
|
};
|
|
72
77
|
}
|
|
@@ -78,6 +83,7 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
78
83
|
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
79
84
|
return {
|
|
80
85
|
to: this.address.toString(),
|
|
86
|
+
abi: GovernanceProposerAbi,
|
|
81
87
|
data: encodeSignal(payload),
|
|
82
88
|
};
|
|
83
89
|
}
|
|
@@ -99,6 +105,7 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
99
105
|
);
|
|
100
106
|
return {
|
|
101
107
|
to: this.address.toString(),
|
|
108
|
+
abi: GovernanceProposerAbi,
|
|
102
109
|
data: encodeSignalWithSignature(payload, signature),
|
|
103
110
|
};
|
|
104
111
|
}
|
|
@@ -112,8 +119,9 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
112
119
|
}> {
|
|
113
120
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
114
121
|
to: this.address.toString(),
|
|
122
|
+
abi: GovernanceProposerAbi,
|
|
115
123
|
data: encodeFunctionData({
|
|
116
|
-
abi:
|
|
124
|
+
abi: GovernanceProposerAbi,
|
|
117
125
|
functionName: 'submitRoundWinner',
|
|
118
126
|
args: [round],
|
|
119
127
|
}),
|
package/src/contracts/inbox.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
|
|
4
6
|
|
|
@@ -8,8 +10,20 @@ import { getPublicClient } from '../client.js';
|
|
|
8
10
|
import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
|
|
9
11
|
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
10
12
|
import type { ViemClient } from '../types.js';
|
|
13
|
+
import type { L1EventLog } from './log.js';
|
|
11
14
|
import { checkBlockTag } from './utils.js';
|
|
12
15
|
|
|
16
|
+
/** Arguments for the MessageSent event. */
|
|
17
|
+
export type MessageSentArgs = {
|
|
18
|
+
index: bigint;
|
|
19
|
+
leaf: Fr;
|
|
20
|
+
checkpointNumber: CheckpointNumber;
|
|
21
|
+
rollingHash: Buffer16;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Log type for MessageSent events. */
|
|
25
|
+
export type MessageSentLog = L1EventLog<MessageSentArgs>;
|
|
26
|
+
|
|
13
27
|
export class InboxContract {
|
|
14
28
|
private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
|
|
15
29
|
|
|
@@ -45,6 +59,11 @@ export class InboxContract {
|
|
|
45
59
|
return this.inbox;
|
|
46
60
|
}
|
|
47
61
|
|
|
62
|
+
public async getLag(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<bigint> {
|
|
63
|
+
await checkBlockTag(opts.blockNumber, this.client);
|
|
64
|
+
return await this.inbox.read.LAG(opts);
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
|
|
49
68
|
await checkBlockTag(opts.blockNumber, this.client);
|
|
50
69
|
const state = await this.inbox.read.getState(opts);
|
|
@@ -54,6 +73,39 @@ export class InboxContract {
|
|
|
54
73
|
treeInProgress: state.inProgress,
|
|
55
74
|
};
|
|
56
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Fetches MessageSent events within the given block range. */
|
|
78
|
+
async getMessageSentEvents(fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
|
|
79
|
+
const logs = await this.inbox.getEvents.MessageSent({}, { fromBlock, toBlock });
|
|
80
|
+
return logs
|
|
81
|
+
.filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
|
|
82
|
+
.map(log => this.mapMessageSentLog(log));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Fetches MessageSent events for a specific message hash within the given block range. */
|
|
86
|
+
async getMessageSentEventByHash(hash: Hex, fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
|
|
87
|
+
const logs = await this.inbox.getEvents.MessageSent({ hash }, { fromBlock, toBlock });
|
|
88
|
+
return logs.map(log => this.mapMessageSentLog(log));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private mapMessageSentLog(log: {
|
|
92
|
+
blockNumber: bigint | null;
|
|
93
|
+
blockHash: `0x${string}` | null;
|
|
94
|
+
transactionHash: `0x${string}` | null;
|
|
95
|
+
args: { index?: bigint; hash?: `0x${string}`; checkpointNumber?: bigint; rollingHash?: `0x${string}` };
|
|
96
|
+
}): MessageSentLog {
|
|
97
|
+
return {
|
|
98
|
+
l1BlockNumber: log.blockNumber!,
|
|
99
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
100
|
+
l1TransactionHash: log.transactionHash!,
|
|
101
|
+
args: {
|
|
102
|
+
index: log.args.index!,
|
|
103
|
+
leaf: Fr.fromString(log.args.hash!),
|
|
104
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
105
|
+
rollingHash: Buffer16.fromString(log.args.rollingHash!),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
57
109
|
}
|
|
58
110
|
|
|
59
111
|
export type InboxContractState = {
|
package/src/contracts/index.ts
CHANGED
|
@@ -6,7 +6,9 @@ export * from './governance.js';
|
|
|
6
6
|
export * from './governance_proposer.js';
|
|
7
7
|
export * from './gse.js';
|
|
8
8
|
export * from './inbox.js';
|
|
9
|
+
export * from './log.js';
|
|
9
10
|
export * from './multicall.js';
|
|
11
|
+
export * from './outbox.js';
|
|
10
12
|
export * from './registry.js';
|
|
11
13
|
export * from './rollup.js';
|
|
12
14
|
export * from './empire_slashing_proposer.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
|
|
3
|
+
/** Base L1 event log with common fields. */
|
|
4
|
+
export type L1EventLog<T> = {
|
|
5
|
+
/** L1 block number where the event was emitted. */
|
|
6
|
+
l1BlockNumber: bigint;
|
|
7
|
+
/** L1 block hash. */
|
|
8
|
+
l1BlockHash: Buffer32;
|
|
9
|
+
/** L1 transaction hash that emitted the event. */
|
|
10
|
+
l1TransactionHash: `0x${string}`;
|
|
11
|
+
/** Event-specific arguments. */
|
|
12
|
+
args: T;
|
|
13
|
+
};
|
|
@@ -34,10 +34,13 @@ export class Multicall3 {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const encodedForwarderData = encodeFunctionData(forwarderFunctionData);
|
|
37
|
-
|
|
38
37
|
try {
|
|
39
38
|
const { receipt, state } = await l1TxUtils.sendAndMonitorTransaction(
|
|
40
|
-
{
|
|
39
|
+
{
|
|
40
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
41
|
+
data: encodedForwarderData,
|
|
42
|
+
abi: multicall3Abi,
|
|
43
|
+
},
|
|
41
44
|
gasConfig,
|
|
42
45
|
blobConfig,
|
|
43
46
|
);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
|
|
4
|
+
|
|
5
|
+
import { type GetContractReturnType, type Hex, encodeAbiParameters, getContract, hexToBigInt, keccak256 } from 'viem';
|
|
6
|
+
|
|
7
|
+
import { getPublicClient } from '../client.js';
|
|
8
|
+
import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
|
|
9
|
+
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
10
|
+
import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
|
|
11
|
+
|
|
12
|
+
export type ViemL1Actor = {
|
|
13
|
+
actor: Hex;
|
|
14
|
+
chainId: bigint;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ViemL2Actor = {
|
|
18
|
+
actor: Hex;
|
|
19
|
+
version: bigint;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ViemL2ToL1Msg = {
|
|
23
|
+
sender: ViemL2Actor;
|
|
24
|
+
recipient: ViemL1Actor;
|
|
25
|
+
content: Hex;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export class OutboxContract {
|
|
29
|
+
private readonly outbox: GetContractReturnType<typeof OutboxAbi, ViemClient>;
|
|
30
|
+
|
|
31
|
+
static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
|
|
32
|
+
const {
|
|
33
|
+
l1Client,
|
|
34
|
+
l1ContractAddresses: { outboxAddress },
|
|
35
|
+
} = deployL1ContractsValues;
|
|
36
|
+
return new OutboxContract(l1Client, outboxAddress.toString());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static getFromConfig(config: L1ReaderConfig) {
|
|
40
|
+
const client = getPublicClient(config);
|
|
41
|
+
const address = config.l1Contracts.outboxAddress.toString();
|
|
42
|
+
return new OutboxContract(client, address);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static getEpochRootStorageSlot(epoch: EpochNumber) {
|
|
46
|
+
return hexToBigInt(keccak256(encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [BigInt(epoch), 0n])));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
public readonly client: ViemClient,
|
|
51
|
+
address: Hex | EthAddress,
|
|
52
|
+
) {
|
|
53
|
+
if (address instanceof EthAddress) {
|
|
54
|
+
address = address.toString();
|
|
55
|
+
}
|
|
56
|
+
this.outbox = getContract({ address, abi: OutboxAbi, client });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public get address() {
|
|
60
|
+
return this.outbox.address;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getContract(): GetContractReturnType<typeof OutboxAbi, ViemClient> {
|
|
64
|
+
return this.outbox;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public hasMessageBeenConsumedAtEpoch(epoch: EpochNumber, leafId: bigint) {
|
|
68
|
+
return this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epoch), leafId]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public getRootData(epoch: EpochNumber) {
|
|
72
|
+
return this.outbox.read.getRootData([BigInt(epoch)]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public consume(message: ViemL2ToL1Msg, epoch: EpochNumber, leafIndex: bigint, path: Hex[]) {
|
|
76
|
+
const wallet = this.assertWallet();
|
|
77
|
+
return wallet.write.consume([message, BigInt(epoch), leafIndex, path]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async getMessageConsumedEvents(
|
|
81
|
+
l1BlockHash: Hex,
|
|
82
|
+
): Promise<{ epoch: bigint; root: Hex; messageHash: Hex; leafId: bigint }[]> {
|
|
83
|
+
const events = await this.outbox.getEvents.MessageConsumed({}, { blockHash: l1BlockHash, strict: true });
|
|
84
|
+
return events.map(event => ({
|
|
85
|
+
epoch: event.args.epoch!,
|
|
86
|
+
root: event.args.root!,
|
|
87
|
+
messageHash: event.args.messageHash!,
|
|
88
|
+
leafId: event.args.leafId!,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private assertWallet(): GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient> {
|
|
93
|
+
if (!isExtendedClient(this.client)) {
|
|
94
|
+
throw new Error('Wallet client is required for this operation');
|
|
95
|
+
}
|
|
96
|
+
return this.outbox as GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient>;
|
|
97
|
+
}
|
|
98
|
+
}
|