@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.0b941701
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account.d.ts +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +6 -4
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +21 -3
- package/dest/config.d.ts +68 -23
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +145 -32
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +25 -8
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +75 -2
- package/dest/contracts/empire_slashing_proposer.d.ts +67 -0
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/empire_slashing_proposer.js +209 -0
- package/dest/contracts/errors.d.ts +7 -0
- package/dest/contracts/errors.d.ts.map +1 -0
- package/dest/contracts/errors.js +12 -0
- package/dest/contracts/fee_asset_handler.d.ts +20 -0
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
- package/dest/contracts/fee_asset_handler.js +57 -0
- package/dest/contracts/fee_juice.d.ts +6 -7
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/fee_juice.js +27 -20
- package/dest/contracts/governance.d.ts +45 -32
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +96 -85
- package/dest/contracts/governance_proposer.d.ts +17 -13
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +428 -25
- package/dest/contracts/gse.d.ts +32 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +72 -0
- package/dest/contracts/inbox.d.ts +47 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +80 -0
- package/dest/contracts/index.d.ts +11 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +10 -2
- 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 +21 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +156 -0
- 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/registry.d.ts +10 -5
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +44 -16
- package/dest/contracts/rollup.d.ts +297 -53
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1123 -116
- package/dest/contracts/slasher_contract.d.ts +44 -0
- package/dest/contracts/slasher_contract.d.ts.map +1 -0
- package/dest/contracts/slasher_contract.js +75 -0
- package/dest/contracts/tally_slashing_proposer.d.ts +140 -0
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/tally_slashing_proposer.js +313 -0
- package/dest/contracts/utils.d.ts +3 -0
- package/dest/contracts/utils.d.ts.map +1 -0
- package/dest/contracts/utils.js +11 -0
- package/dest/deploy_aztec_l1_contracts.d.ts +260 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +398 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +21 -0
- package/dest/eth-signer/eth-signer.d.ts.map +1 -0
- package/dest/eth-signer/eth-signer.js +5 -0
- package/dest/eth-signer/index.d.ts +2 -0
- package/dest/eth-signer/index.d.ts.map +1 -0
- package/dest/eth-signer/index.js +1 -0
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- 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 +80735 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +166 -0
- package/dest/l1_contract_addresses.d.ts +24 -4
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +25 -21
- package/dest/l1_reader.d.ts +4 -2
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +14 -8
- package/dest/l1_tx_utils/config.d.ts +59 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +96 -0
- package/dest/l1_tx_utils/constants.d.ts +12 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +39 -0
- package/dest/l1_tx_utils/factory.d.ts +24 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +12 -0
- 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/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +12 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +12 -0
- package/dest/l1_tx_utils/interfaces.d.ts +76 -0
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
- package/dest/l1_tx_utils/interfaces.js +4 -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.d.ts +94 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +623 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +323 -0
- package/dest/l1_tx_utils/signer.d.ts +4 -0
- package/dest/l1_tx_utils/signer.d.ts.map +1 -0
- package/dest/l1_tx_utils/signer.js +16 -0
- package/dest/l1_tx_utils/types.d.ts +67 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +26 -0
- package/dest/l1_tx_utils/utils.d.ts +4 -0
- package/dest/l1_tx_utils/utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/utils.js +14 -0
- package/dest/l1_types.d.ts +6 -0
- package/dest/l1_types.d.ts.map +1 -0
- package/dest/l1_types.js +1 -0
- package/dest/publisher_manager.d.ts +15 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +88 -0
- package/dest/queries.d.ts +5 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +61 -12
- package/dest/test/chain_monitor.d.ts +75 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +213 -0
- package/dest/test/delayed_tx_utils.d.ts +8 -3
- package/dest/test/delayed_tx_utils.d.ts.map +1 -1
- package/dest/test/delayed_tx_utils.js +13 -6
- package/dest/test/eth_cheat_codes.d.ts +229 -0
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +560 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes_with_state.js +1 -1
- package/dest/test/index.d.ts +4 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +3 -0
- package/dest/test/rollup_cheat_codes.d.ts +88 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +283 -0
- package/dest/test/start_anvil.d.ts +9 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +16 -7
- package/dest/test/tx_delayer.d.ts +18 -7
- package/dest/test/tx_delayer.d.ts.map +1 -1
- package/dest/test/tx_delayer.js +97 -20
- package/dest/test/upgrade_utils.d.ts +6 -5
- package/dest/test/upgrade_utils.d.ts.map +1 -1
- package/dest/test/upgrade_utils.js +23 -16
- package/dest/types.d.ts +62 -8
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -1
- package/dest/utils.d.ts +16 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +61 -88
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +51 -23
- package/src/account.ts +5 -0
- package/src/client.ts +43 -5
- package/src/config.ts +207 -41
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +77 -7
- package/src/contracts/empire_slashing_proposer.ts +270 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +64 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +88 -78
- package/src/contracts/governance_proposer.ts +71 -24
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +115 -0
- package/src/contracts/index.ts +10 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +155 -0
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/registry.ts +51 -26
- package/src/contracts/rollup.ts +875 -89
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/tally_slashing_proposer.ts +318 -0
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_aztec_l1_contracts.ts +619 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/eth-signer/eth-signer.ts +25 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +254 -0
- package/src/l1_contract_addresses.ts +49 -34
- package/src/l1_reader.ts +17 -9
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +161 -0
- package/src/l1_tx_utils/constants.ts +29 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- 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/forwarder_l1_tx_utils.ts +119 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +14 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +738 -0
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +419 -0
- package/src/l1_tx_utils/signer.ts +28 -0
- package/src/l1_tx_utils/types.ts +85 -0
- package/src/l1_tx_utils/utils.ts +16 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +106 -0
- package/src/queries.ts +82 -16
- package/src/test/chain_monitor.ts +245 -0
- package/src/test/delayed_tx_utils.ts +34 -6
- package/src/test/eth_cheat_codes.ts +588 -0
- package/src/test/eth_cheat_codes_with_state.ts +1 -1
- package/src/test/index.ts +3 -0
- package/src/test/rollup_cheat_codes.ts +321 -0
- package/src/test/start_anvil.ts +24 -5
- package/src/test/tx_delayer.ts +130 -27
- package/src/test/upgrade_utils.ts +30 -21
- package/src/types.ts +71 -7
- package/src/utils.ts +79 -91
- package/src/zkPassportVerifierAddress.ts +15 -0
- package/dest/contracts/forwarder.d.ts +0 -24
- package/dest/contracts/forwarder.d.ts.map +0 -1
- package/dest/contracts/forwarder.js +0 -101
- package/dest/contracts/slashing_proposer.d.ts +0 -21
- package/dest/contracts/slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/slashing_proposer.js +0 -47
- package/dest/deploy_l1_contracts.d.ts +0 -21210
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -687
- package/dest/eth_cheat_codes.d.ts +0 -147
- package/dest/eth_cheat_codes.d.ts.map +0 -1
- package/dest/eth_cheat_codes.js +0 -303
- package/dest/index.d.ts +0 -14
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -13
- package/dest/l1_tx_utils.d.ts +0 -192
- package/dest/l1_tx_utils.d.ts.map +0 -1
- package/dest/l1_tx_utils.js +0 -641
- package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
- package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils_with_blobs.js +0 -64
- package/src/contracts/forwarder.ts +0 -132
- package/src/contracts/slashing_proposer.ts +0 -51
- package/src/deploy_l1_contracts.ts +0 -948
- package/src/eth_cheat_codes.ts +0 -314
- package/src/index.ts +0 -13
- package/src/l1_tx_utils.ts +0 -847
- package/src/l1_tx_utils_with_blobs.ts +0 -86
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# L1 Contract Wrappers
|
|
2
|
+
|
|
3
|
+
This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
|
|
8
|
+
|
|
9
|
+
## Type Safety
|
|
10
|
+
|
|
11
|
+
### Explicit Return Types
|
|
12
|
+
|
|
13
|
+
Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Good: Explicit return type
|
|
17
|
+
async getSlotNumber(): Promise<SlotNumber> {
|
|
18
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Bad: Inferred return type (slow)
|
|
22
|
+
async getSlotNumber() {
|
|
23
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Branded and Domain Types
|
|
28
|
+
|
|
29
|
+
Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
|
|
30
|
+
|
|
31
|
+
- `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
|
|
32
|
+
- `EthAddress` instead of `` `0x${string}` `` or `Hex`
|
|
33
|
+
- `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
|
|
34
|
+
- Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
|
|
35
|
+
|
|
36
|
+
Type conversions happen inside wrapper methods, not at the call site:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
|
|
40
|
+
const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
|
|
41
|
+
return {
|
|
42
|
+
archive: Fr.fromString(result.archive),
|
|
43
|
+
headerHash: Buffer32.fromString(result.headerHash),
|
|
44
|
+
blockCount: result.blockCount,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Wrapper Pattern
|
|
50
|
+
|
|
51
|
+
### Basic Structure
|
|
52
|
+
|
|
53
|
+
Each wrapper follows a consistent structure:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
export class FooContract {
|
|
57
|
+
private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
public readonly client: ViemClient,
|
|
61
|
+
address: Hex | EthAddress,
|
|
62
|
+
) {
|
|
63
|
+
if (address instanceof EthAddress) {
|
|
64
|
+
address = address.toString();
|
|
65
|
+
}
|
|
66
|
+
this.foo = getContract({ address, abi: FooAbi, client });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public get address(): Hex {
|
|
70
|
+
return this.foo.address;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
|
|
74
|
+
return this.foo;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
|
|
80
|
+
|
|
81
|
+
### Static Factory Methods
|
|
82
|
+
|
|
83
|
+
Wrappers may provide static factory methods for common initialization patterns:
|
|
84
|
+
|
|
85
|
+
- `getFromConfig(config)` - construct from configuration object
|
|
86
|
+
- `getFromL1ContractsValues(deployResult)` - construct from deployment result
|
|
87
|
+
|
|
88
|
+
### Wallet Assertions
|
|
89
|
+
|
|
90
|
+
For write operations that require a wallet, use an assertion helper:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
|
|
94
|
+
if (!isExtendedClient(this.client)) {
|
|
95
|
+
throw new Error('Wallet client is required for this operation');
|
|
96
|
+
}
|
|
97
|
+
return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Event Handling
|
|
102
|
+
|
|
103
|
+
### Event Log Types
|
|
104
|
+
|
|
105
|
+
Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
type L1EventLog<T> = {
|
|
109
|
+
l1BlockNumber: bigint;
|
|
110
|
+
l1BlockHash: Buffer32;
|
|
111
|
+
l1TransactionHash: Hex;
|
|
112
|
+
args: T;
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Event Fetching
|
|
117
|
+
|
|
118
|
+
Methods that fetch events convert viem's raw logs to domain types:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
122
|
+
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
123
|
+
return logs.map(log => ({
|
|
124
|
+
l1BlockNumber: log.blockNumber!,
|
|
125
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
126
|
+
l1TransactionHash: log.transactionHash!,
|
|
127
|
+
args: {
|
|
128
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
129
|
+
// ... convert other fields
|
|
130
|
+
},
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Event Listeners
|
|
136
|
+
|
|
137
|
+
For reactive event handling, wrapper methods convert arguments before invoking callbacks:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
public listenToCheckpointInvalidated(
|
|
141
|
+
callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
|
|
142
|
+
): WatchContractEventReturnType {
|
|
143
|
+
return this.rollup.watchEvent.CheckpointInvalidated({}, {
|
|
144
|
+
onLogs: logs => {
|
|
145
|
+
for (const log of logs) {
|
|
146
|
+
if (log.args.checkpointNumber !== undefined) {
|
|
147
|
+
callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Error Handling
|
|
156
|
+
|
|
157
|
+
Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
|
|
@@ -1,19 +1,89 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
1
4
|
import { EmpireBaseAbi } from '@aztec/l1-artifacts/EmpireBaseAbi';
|
|
2
5
|
|
|
3
|
-
import { type Hex, encodeFunctionData } from 'viem';
|
|
6
|
+
import { type Hex, type TypedDataDefinition, encodeFunctionData } from 'viem';
|
|
4
7
|
|
|
5
|
-
import type { L1TxRequest } from '../l1_tx_utils.js';
|
|
8
|
+
import type { L1TxRequest } from '../l1_tx_utils/index.js';
|
|
6
9
|
|
|
7
10
|
export interface IEmpireBase {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
get address(): EthAddress;
|
|
12
|
+
getRoundInfo(
|
|
13
|
+
rollupAddress: Hex,
|
|
14
|
+
round: bigint,
|
|
15
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }>;
|
|
16
|
+
computeRound(slot: SlotNumber): Promise<bigint>;
|
|
17
|
+
createSignalRequest(payload: Hex): L1TxRequest;
|
|
18
|
+
createSignalRequestWithSignature(
|
|
19
|
+
payload: Hex,
|
|
20
|
+
slot: SlotNumber,
|
|
21
|
+
chainId: number,
|
|
22
|
+
signerAddress: Hex,
|
|
23
|
+
signer: (msg: TypedDataDefinition) => Promise<Hex>,
|
|
24
|
+
): Promise<L1TxRequest>;
|
|
11
25
|
}
|
|
12
26
|
|
|
13
|
-
export function
|
|
27
|
+
export function encodeSignal(payload: Hex): Hex {
|
|
14
28
|
return encodeFunctionData({
|
|
15
29
|
abi: EmpireBaseAbi,
|
|
16
|
-
functionName: '
|
|
30
|
+
functionName: 'signal',
|
|
17
31
|
args: [payload],
|
|
18
32
|
});
|
|
19
33
|
}
|
|
34
|
+
|
|
35
|
+
export function encodeSignalWithSignature(payload: Hex, signature: Signature) {
|
|
36
|
+
return encodeFunctionData({
|
|
37
|
+
abi: EmpireBaseAbi,
|
|
38
|
+
functionName: 'signalWithSig',
|
|
39
|
+
args: [payload, signature.toViemSignature()],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Signs a signal proposal using EIP-712 typed data for use with signalWithSig
|
|
45
|
+
* @param walletClient - The viem wallet client to sign with
|
|
46
|
+
* @param payload - The payload address to signal
|
|
47
|
+
* @param verifyingContract - The address of the EmpireBase contract
|
|
48
|
+
* @param chainId - The chain ID where the contract is deployed
|
|
49
|
+
* @param account - The account to sign with (optional if hoisted on wallet client)
|
|
50
|
+
* @returns The EIP-712 signature
|
|
51
|
+
*/
|
|
52
|
+
export async function signSignalWithSig(
|
|
53
|
+
signer: (msg: TypedDataDefinition) => Promise<Hex>,
|
|
54
|
+
payload: Hex,
|
|
55
|
+
slot: SlotNumber,
|
|
56
|
+
instance: Hex,
|
|
57
|
+
verifyingContract: Hex,
|
|
58
|
+
chainId: number,
|
|
59
|
+
): Promise<Signature> {
|
|
60
|
+
const domain = {
|
|
61
|
+
name: 'EmpireBase',
|
|
62
|
+
version: '1',
|
|
63
|
+
chainId,
|
|
64
|
+
verifyingContract,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const types = {
|
|
68
|
+
EIP712Domain: [
|
|
69
|
+
{ name: 'name', type: 'string' },
|
|
70
|
+
{ name: 'version', type: 'string' },
|
|
71
|
+
{ name: 'chainId', type: 'uint256' },
|
|
72
|
+
{ name: 'verifyingContract', type: 'address' },
|
|
73
|
+
],
|
|
74
|
+
Signal: [
|
|
75
|
+
{ name: 'payload', type: 'address' },
|
|
76
|
+
{ name: 'slot', type: 'uint256' },
|
|
77
|
+
{ name: 'instance', type: 'address' },
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const message = {
|
|
82
|
+
payload,
|
|
83
|
+
slot: BigInt(slot),
|
|
84
|
+
instance,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const typedData = { domain, types, primaryType: 'Signal', message };
|
|
88
|
+
return Signature.fromString(await signer(typedData));
|
|
89
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
5
|
+
import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingProposerAbi';
|
|
6
|
+
|
|
7
|
+
import EventEmitter from 'events';
|
|
8
|
+
import {
|
|
9
|
+
type EncodeFunctionDataParameters,
|
|
10
|
+
type GetContractReturnType,
|
|
11
|
+
type Hex,
|
|
12
|
+
type Log,
|
|
13
|
+
type TypedDataDefinition,
|
|
14
|
+
encodeFunctionData,
|
|
15
|
+
getContract,
|
|
16
|
+
} from 'viem';
|
|
17
|
+
|
|
18
|
+
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
19
|
+
import type { ViemClient } from '../types.js';
|
|
20
|
+
import { FormattedViemError, tryExtractEvent } from '../utils.js';
|
|
21
|
+
import { type IEmpireBase, encodeSignal, encodeSignalWithSignature, signSignalWithSig } from './empire_base.js';
|
|
22
|
+
|
|
23
|
+
export class ProposalAlreadyExecutedError extends Error {
|
|
24
|
+
constructor(round: bigint) {
|
|
25
|
+
super(`Proposal already executed: ${round}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class EmpireSlashingProposerContract extends EventEmitter implements IEmpireBase {
|
|
30
|
+
private readonly logger = createLogger('ethereum:contracts:empire_slashing_proposer');
|
|
31
|
+
private readonly proposer: GetContractReturnType<typeof EmpireSlashingProposerAbi, ViemClient>;
|
|
32
|
+
|
|
33
|
+
public readonly type = 'empire' as const;
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
public readonly client: ViemClient,
|
|
37
|
+
address: Hex | EthAddress,
|
|
38
|
+
) {
|
|
39
|
+
super();
|
|
40
|
+
this.proposer = getContract({
|
|
41
|
+
address: typeof address === 'string' ? address : address.toString(),
|
|
42
|
+
abi: EmpireSlashingProposerAbi,
|
|
43
|
+
client,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public get address() {
|
|
48
|
+
return EthAddress.fromString(this.proposer.address);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public getQuorumSize() {
|
|
52
|
+
return this.proposer.read.QUORUM_SIZE();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public getRoundSize() {
|
|
56
|
+
return this.proposer.read.ROUND_SIZE();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public getLifetimeInRounds() {
|
|
60
|
+
return this.proposer.read.LIFETIME_IN_ROUNDS();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getExecutionDelayInRounds() {
|
|
64
|
+
return this.proposer.read.EXECUTION_DELAY_IN_ROUNDS();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public getCurrentRound() {
|
|
68
|
+
return this.proposer.read.getCurrentRound();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public computeRound(slot: SlotNumber): Promise<bigint> {
|
|
72
|
+
return this.proposer.read.computeRound([BigInt(slot)]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public getInstance() {
|
|
76
|
+
return this.proposer.read.getInstance();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async getRoundInfo(
|
|
80
|
+
rollupAddress: Hex,
|
|
81
|
+
round: bigint,
|
|
82
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }> {
|
|
83
|
+
const result = await this.proposer.read.getRoundData([rollupAddress, round]);
|
|
84
|
+
const [signalCount, quorum] = await Promise.all([
|
|
85
|
+
this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
|
|
86
|
+
this.getQuorumSize(),
|
|
87
|
+
]);
|
|
88
|
+
return {
|
|
89
|
+
lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
|
|
90
|
+
payloadWithMostSignals: result.payloadWithMostSignals,
|
|
91
|
+
quorumReached: signalCount >= quorum,
|
|
92
|
+
executed: result.executed,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint> {
|
|
97
|
+
return this.proposer.read.signalCount([rollupAddress, round, payload]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
101
|
+
return {
|
|
102
|
+
to: this.address.toString(),
|
|
103
|
+
data: encodeSignal(payload),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public async createSignalRequestWithSignature(
|
|
108
|
+
payload: Hex,
|
|
109
|
+
slot: SlotNumber,
|
|
110
|
+
chainId: number,
|
|
111
|
+
signerAddress: Hex,
|
|
112
|
+
signer: (msg: TypedDataDefinition) => Promise<Hex>,
|
|
113
|
+
): Promise<L1TxRequest> {
|
|
114
|
+
const signature = await signSignalWithSig(
|
|
115
|
+
signer,
|
|
116
|
+
payload,
|
|
117
|
+
slot,
|
|
118
|
+
await this.getInstance(),
|
|
119
|
+
this.address.toString(),
|
|
120
|
+
chainId,
|
|
121
|
+
);
|
|
122
|
+
return {
|
|
123
|
+
to: this.address.toString(),
|
|
124
|
+
data: encodeSignalWithSignature(payload, signature),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public listenToSubmittablePayloads(callback: (args: { payload: `0x${string}`; round: bigint }) => unknown) {
|
|
129
|
+
return this.proposer.watchEvent.PayloadSubmittable(
|
|
130
|
+
{},
|
|
131
|
+
{
|
|
132
|
+
strict: true,
|
|
133
|
+
onLogs: logs => {
|
|
134
|
+
for (const log of logs) {
|
|
135
|
+
const { payload, round } = log.args;
|
|
136
|
+
if (payload && round) {
|
|
137
|
+
callback({ payload, round });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public listenToPayloadSubmitted(callback: (args: { round: bigint; payload: `0x${string}` }) => unknown) {
|
|
146
|
+
return this.proposer.watchEvent.PayloadSubmitted(
|
|
147
|
+
{},
|
|
148
|
+
{
|
|
149
|
+
onLogs: logs => {
|
|
150
|
+
for (const log of logs) {
|
|
151
|
+
const { payload, round } = log.args;
|
|
152
|
+
if (round && payload) {
|
|
153
|
+
callback({ round, payload });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public listenToSignalCasted(
|
|
162
|
+
callback: (args: { round: bigint; payload: `0x${string}`; signaler: `0x${string}` }) => unknown,
|
|
163
|
+
) {
|
|
164
|
+
return this.proposer.watchEvent.SignalCast(
|
|
165
|
+
{},
|
|
166
|
+
{
|
|
167
|
+
onLogs: logs => {
|
|
168
|
+
for (const log of logs) {
|
|
169
|
+
const { round, payload, signaler } = log.args;
|
|
170
|
+
if (round && payload && signaler) {
|
|
171
|
+
callback({ round, payload, signaler });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Creates an L1TxRequest to submit the round winner for the given round. */
|
|
180
|
+
public buildExecuteRoundRequest(round: bigint): L1TxRequest {
|
|
181
|
+
return {
|
|
182
|
+
to: this.address.toString(),
|
|
183
|
+
data: encodeFunctionData({
|
|
184
|
+
abi: EmpireSlashingProposerAbi,
|
|
185
|
+
functionName: 'submitRoundWinner',
|
|
186
|
+
args: [round],
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Tries to extract a PayloadSubmitted event from the given logs. */
|
|
192
|
+
public tryExtractPayloadSubmittedEvent(logs: Log[]) {
|
|
193
|
+
return tryExtractEvent(logs, this.address.toString(), EmpireSlashingProposerAbi, 'PayloadSubmitted');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Wait for a round to be reached.
|
|
198
|
+
*
|
|
199
|
+
* @param round - The round to wait for.
|
|
200
|
+
* @param pollingIntervalSeconds - The interval in seconds to poll for the round.
|
|
201
|
+
* @returns True if the round was reached, false otherwise.
|
|
202
|
+
*/
|
|
203
|
+
public waitForRound(round: bigint, pollingIntervalSeconds: number = 1): Promise<boolean> {
|
|
204
|
+
return retryUntil(
|
|
205
|
+
async () => {
|
|
206
|
+
const currentRound = await this.proposer.read.getCurrentRound().catch(e => {
|
|
207
|
+
this.logger.error('Error getting current round', e);
|
|
208
|
+
return undefined;
|
|
209
|
+
});
|
|
210
|
+
return currentRound !== undefined && currentRound >= round;
|
|
211
|
+
},
|
|
212
|
+
`Waiting for round ${round} to be reached`,
|
|
213
|
+
0, // no timeout
|
|
214
|
+
pollingIntervalSeconds,
|
|
215
|
+
).catch(() => false);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public async executeRound(
|
|
219
|
+
txUtils: L1TxUtils,
|
|
220
|
+
round: bigint | number,
|
|
221
|
+
): ReturnType<typeof txUtils.sendAndMonitorTransaction> {
|
|
222
|
+
if (typeof round === 'number') {
|
|
223
|
+
round = BigInt(round);
|
|
224
|
+
}
|
|
225
|
+
const args: EncodeFunctionDataParameters<typeof EmpireSlashingProposerAbi, 'submitRoundWinner'> = {
|
|
226
|
+
abi: EmpireSlashingProposerAbi,
|
|
227
|
+
functionName: 'submitRoundWinner',
|
|
228
|
+
args: [round],
|
|
229
|
+
};
|
|
230
|
+
const data = encodeFunctionData(args);
|
|
231
|
+
const response = await txUtils
|
|
232
|
+
.sendAndMonitorTransaction(
|
|
233
|
+
{
|
|
234
|
+
to: this.address.toString(),
|
|
235
|
+
data,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
239
|
+
// for the actual slashing dynamically.
|
|
240
|
+
gasLimitBufferPercentage: 50, // +50% gas
|
|
241
|
+
},
|
|
242
|
+
)
|
|
243
|
+
.catch(err => {
|
|
244
|
+
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
245
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
246
|
+
}
|
|
247
|
+
throw err;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
if (response.receipt.status === 'reverted') {
|
|
251
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(
|
|
252
|
+
data,
|
|
253
|
+
{
|
|
254
|
+
...args,
|
|
255
|
+
address: this.address.toString(),
|
|
256
|
+
},
|
|
257
|
+
undefined,
|
|
258
|
+
[],
|
|
259
|
+
);
|
|
260
|
+
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
261
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
262
|
+
}
|
|
263
|
+
const errorMessage = `Failed to execute round ${round}, TxHash: ${response.receipt.transactionHash}, Error: ${
|
|
264
|
+
error ?? 'Unknown error'
|
|
265
|
+
}`;
|
|
266
|
+
throw new Error(errorMessage);
|
|
267
|
+
}
|
|
268
|
+
return response;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class BlockTagTooOldError extends Error {
|
|
2
|
+
constructor(blockTag: bigint | number, latestBlock: bigint | number) {
|
|
3
|
+
super(`Block tag ${blockTag} is more than 128 blocks behind the latest block ${latestBlock}`);
|
|
4
|
+
this.name = 'BlockTagTooOldError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class NoCommitteeError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super('The committee does not exist on L1');
|
|
11
|
+
this.name = 'NoCommitteeError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
|
|
3
|
+
|
|
4
|
+
import { type Hex, encodeFunctionData, getContract } from 'viem';
|
|
5
|
+
|
|
6
|
+
import type { L1TxUtils } from '../l1_tx_utils/index.js';
|
|
7
|
+
import type { ViemClient } from '../types.js';
|
|
8
|
+
|
|
9
|
+
export class FeeAssetHandlerContract {
|
|
10
|
+
public address: EthAddress;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
public readonly client: ViemClient,
|
|
14
|
+
address: Hex | EthAddress,
|
|
15
|
+
) {
|
|
16
|
+
if (address instanceof EthAddress) {
|
|
17
|
+
address = address.toString();
|
|
18
|
+
}
|
|
19
|
+
this.address = EthAddress.fromString(address);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async getOwner(): Promise<EthAddress> {
|
|
23
|
+
const contract = getContract({
|
|
24
|
+
abi: FeeAssetHandlerAbi,
|
|
25
|
+
address: this.address.toString(),
|
|
26
|
+
client: this.client,
|
|
27
|
+
});
|
|
28
|
+
return EthAddress.fromString(await contract.read.owner());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public getMintAmount() {
|
|
32
|
+
const contract = getContract({
|
|
33
|
+
abi: FeeAssetHandlerAbi,
|
|
34
|
+
address: this.address.toString(),
|
|
35
|
+
client: this.client,
|
|
36
|
+
});
|
|
37
|
+
return contract.read.mintAmount();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public mint(txUtils: L1TxUtils, recipient: Hex | EthAddress) {
|
|
41
|
+
if (recipient instanceof EthAddress) {
|
|
42
|
+
recipient = recipient.toString();
|
|
43
|
+
}
|
|
44
|
+
return txUtils.sendAndMonitorTransaction({
|
|
45
|
+
to: this.address.toString(),
|
|
46
|
+
data: encodeFunctionData({
|
|
47
|
+
abi: FeeAssetHandlerAbi,
|
|
48
|
+
functionName: 'mint',
|
|
49
|
+
args: [recipient],
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
|
|
55
|
+
return txUtils.sendAndMonitorTransaction({
|
|
56
|
+
to: this.address.toString(),
|
|
57
|
+
data: encodeFunctionData({
|
|
58
|
+
abi: FeeAssetHandlerAbi,
|
|
59
|
+
functionName: 'setMintAmount',
|
|
60
|
+
args: [amount],
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts';
|
|
2
|
+
import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
3
3
|
|
|
4
4
|
import { type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
5
5
|
|
|
6
|
-
import type
|
|
6
|
+
import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
|
|
7
7
|
|
|
8
8
|
export class FeeJuiceContract {
|
|
9
|
-
private readonly
|
|
10
|
-
private readonly walletFeeJuice: GetContractReturnType<typeof FeeJuiceAbi, L1Clients['walletClient']> | undefined;
|
|
9
|
+
private readonly feeJuiceContract: GetContractReturnType<typeof FeeJuiceAbi, ViemClient>;
|
|
11
10
|
|
|
12
11
|
constructor(
|
|
13
|
-
address: Hex,
|
|
14
|
-
public readonly
|
|
15
|
-
public readonly walletClient: L1Clients['walletClient'] | undefined,
|
|
12
|
+
address: Hex | EthAddress,
|
|
13
|
+
public readonly client: ViemClient,
|
|
16
14
|
) {
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (address instanceof EthAddress) {
|
|
16
|
+
address = address.toString();
|
|
17
|
+
}
|
|
18
|
+
this.feeJuiceContract = getContract({ address, abi: FeeJuiceAbi, client });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public get address() {
|
|
22
|
-
return EthAddress.fromString(this.
|
|
22
|
+
return EthAddress.fromString(this.feeJuiceContract.address);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async getOwner(): Promise<EthAddress> {
|
|
26
|
+
return EthAddress.fromString(await this.feeJuiceContract.read.owner());
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
private assertWalletFeeJuice() {
|
|
26
|
-
if (!this.
|
|
29
|
+
private assertWalletFeeJuice(): GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient> {
|
|
30
|
+
if (!isExtendedClient(this.client)) {
|
|
27
31
|
throw new Error('Wallet client is required for this operation');
|
|
28
32
|
}
|
|
29
|
-
return this.
|
|
33
|
+
return this.feeJuiceContract as GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient>;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
public async mint(to: Hex, amount: bigint) {
|
|
33
37
|
const walletFeeJuice = this.assertWalletFeeJuice();
|
|
34
38
|
const tx = await walletFeeJuice.write.mint([to, amount]);
|
|
35
|
-
await this.
|
|
39
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
|
|
40
|
+
|
|
41
|
+
if (receipt.status === 'success') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Mint failed');
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
public async approve(spender: Hex, amount: bigint) {
|
|
39
48
|
const walletFeeJuice = this.assertWalletFeeJuice();
|
|
40
49
|
const tx = await walletFeeJuice.write.approve([spender, amount]);
|
|
41
|
-
await this.
|
|
50
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
|
|
51
|
+
|
|
52
|
+
if (receipt.status === 'success') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Approve failed');
|
|
42
56
|
}
|
|
43
57
|
}
|