@aztec/ethereum 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +19 -68
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +55 -380
- package/dest/contracts/empire_base.d.ts +4 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +4 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +31 -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/fee_asset_price_oracle.d.ts +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +14 -4
- package/dest/contracts/governance_proposer.d.ts +4 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +404 -9
- package/dest/contracts/inbox.d.ts +24 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +36 -1
- package/dest/contracts/index.d.ts +4 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -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 +177 -96
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +707 -144
- package/dest/contracts/tally_slashing_proposer.d.ts +3 -2
- 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 +259 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +413 -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/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 +5975 -1575
- 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_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -0
- package/dest/l1_tx_utils/config.d.ts +9 -3
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +31 -4
- 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/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- 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 +42 -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 +4 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +3 -0
- package/dest/l1_tx_utils/interfaces.d.ts +2 -2
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
- 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 +15 -5
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +64 -17
- 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 +53 -160
- package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
- 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.d.ts +15 -13
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +7 -9
- 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 +4 -2
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +9 -6
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +32 -6
- package/dest/test/start_anvil.d.ts +3 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +1 -1
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +16 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +64 -0
- package/package.json +33 -14
- package/src/client.ts +2 -2
- package/src/config.ts +65 -459
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +3 -1
- package/src/contracts/empire_slashing_proposer.ts +28 -28
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/governance.ts +13 -4
- package/src/contracts/governance_proposer.ts +16 -2
- package/src/contracts/inbox.ts +55 -3
- package/src/contracts/index.ts +3 -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 +390 -118
- package/src/contracts/tally_slashing_proposer.ts +7 -1
- package/src/deploy_aztec_l1_contracts.ts +650 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_contract_addresses.ts +22 -20
- package/src/l1_reader.ts +8 -0
- package/src/l1_tx_utils/config.ts +44 -6
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- 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 +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +3 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +76 -21
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +67 -206
- package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +11 -3
- package/src/test/chain_monitor.ts +18 -16
- package/src/test/eth_cheat_codes.ts +2 -2
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +32 -9
- package/src/test/start_anvil.ts +3 -1
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +83 -1
- package/dest/deploy_l1_contracts.d.ts +0 -673
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1491
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/deploy_l1_contracts.ts +0 -1869
- package/src/index.ts +0 -17
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
|
@@ -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.
|
|
@@ -12,7 +12,7 @@ export interface IEmpireBase {
|
|
|
12
12
|
getRoundInfo(
|
|
13
13
|
rollupAddress: Hex,
|
|
14
14
|
round: bigint,
|
|
15
|
-
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; executed: boolean }>;
|
|
15
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }>;
|
|
16
16
|
computeRound(slot: SlotNumber): Promise<bigint>;
|
|
17
17
|
createSignalRequest(payload: Hex): L1TxRequest;
|
|
18
18
|
createSignalRequestWithSignature(
|
|
@@ -22,6 +22,8 @@ export interface IEmpireBase {
|
|
|
22
22
|
signerAddress: Hex,
|
|
23
23
|
signer: (msg: TypedDataDefinition) => Promise<Hex>,
|
|
24
24
|
): Promise<L1TxRequest>;
|
|
25
|
+
/** Checks if a payload was ever submitted to governance via submitRoundWinner. */
|
|
26
|
+
hasPayloadBeenProposed(payload: Hex, fromBlock: bigint): Promise<boolean>;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export function encodeSignal(payload: Hex): Hex {
|
|
@@ -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,10 +121,17 @@ 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
|
}
|
|
122
128
|
|
|
129
|
+
/** Checks if a payload was ever submitted to governance via submitRoundWinner. */
|
|
130
|
+
public async hasPayloadBeenProposed(payload: Hex, fromBlock: bigint): Promise<boolean> {
|
|
131
|
+
const events = await this.proposer.getEvents.PayloadSubmitted({ payload }, { fromBlock, strict: true });
|
|
132
|
+
return events.length > 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
123
135
|
public listenToSubmittablePayloads(callback: (args: { payload: `0x${string}`; round: bigint }) => unknown) {
|
|
124
136
|
return this.proposer.watchEvent.PayloadSubmittable(
|
|
125
137
|
{},
|
|
@@ -175,6 +187,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
175
187
|
public buildExecuteRoundRequest(round: bigint): L1TxRequest {
|
|
176
188
|
return {
|
|
177
189
|
to: this.address.toString(),
|
|
190
|
+
abi: EmpireSlashingProposerAbi,
|
|
178
191
|
data: encodeFunctionData({
|
|
179
192
|
abi: EmpireSlashingProposerAbi,
|
|
180
193
|
functionName: 'submitRoundWinner',
|
|
@@ -217,24 +230,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
217
230
|
if (typeof round === 'number') {
|
|
218
231
|
round = BigInt(round);
|
|
219
232
|
}
|
|
220
|
-
const
|
|
221
|
-
abi: EmpireSlashingProposerAbi,
|
|
222
|
-
functionName: 'submitRoundWinner',
|
|
223
|
-
args: [round],
|
|
224
|
-
};
|
|
225
|
-
const data = encodeFunctionData(args);
|
|
233
|
+
const request = this.buildExecuteRoundRequest(round);
|
|
226
234
|
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
|
-
)
|
|
235
|
+
.sendAndMonitorTransaction(request, {
|
|
236
|
+
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
237
|
+
// for the actual slashing dynamically.
|
|
238
|
+
gasLimitBufferPercentage: 50, // +50% gas
|
|
239
|
+
})
|
|
238
240
|
.catch(err => {
|
|
239
241
|
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
240
242
|
throw new ProposalAlreadyExecutedError(round);
|
|
@@ -243,15 +245,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
243
245
|
});
|
|
244
246
|
|
|
245
247
|
if (response.receipt.status === 'reverted') {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
[],
|
|
254
|
-
);
|
|
248
|
+
const args = {
|
|
249
|
+
abi: EmpireSlashingProposerAbi,
|
|
250
|
+
functionName: 'submitRoundWinner' as const,
|
|
251
|
+
args: [round] as const,
|
|
252
|
+
address: this.address.toString(),
|
|
253
|
+
};
|
|
254
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
|
|
255
255
|
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
256
256
|
throw new ProposalAlreadyExecutedError(round);
|
|
257
257
|
}
|
|
@@ -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',
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { memoize } from '@aztec/foundation/decorators';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
|
|
5
|
+
import { type Hex, encodeAbiParameters, getContract, keccak256, parseAbiParameters } from 'viem';
|
|
6
|
+
|
|
7
|
+
import type { ViemClient } from '../types.js';
|
|
8
|
+
import { RollupContract } from './rollup.js';
|
|
9
|
+
|
|
10
|
+
/** Maximum price modifier per checkpoint in basis points. ±100 bps = ±1% */
|
|
11
|
+
export const MAX_FEE_ASSET_PRICE_MODIFIER_BPS = 100n;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validates that a fee asset price modifier is within the allowed range.
|
|
15
|
+
* Validators should call this before attesting to a checkpoint proposal.
|
|
16
|
+
*
|
|
17
|
+
* @param modifier - The fee asset price modifier in basis points
|
|
18
|
+
* @returns true if the modifier is valid (between -100 and +100 bps)
|
|
19
|
+
*/
|
|
20
|
+
export function validateFeeAssetPriceModifier(modifier: bigint): boolean {
|
|
21
|
+
return modifier >= -MAX_FEE_ASSET_PRICE_MODIFIER_BPS && modifier <= MAX_FEE_ASSET_PRICE_MODIFIER_BPS;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Oracle for computing fee asset price modifiers based on Uniswap V4 pool prices.
|
|
26
|
+
* Only active on Ethereum mainnet - returns 0 on other chains.
|
|
27
|
+
*/
|
|
28
|
+
export class FeeAssetPriceOracle {
|
|
29
|
+
constructor(
|
|
30
|
+
private client: ViemClient,
|
|
31
|
+
private readonly rollupContract: RollupContract,
|
|
32
|
+
private log: Logger = createLogger('fee-asset-price-oracle'),
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
@memoize
|
|
36
|
+
async getUniswapOracle(): Promise<UniswapPriceOracle | undefined> {
|
|
37
|
+
const code = await this.client.getCode({ address: STATE_VIEW_ADDRESS.toString() });
|
|
38
|
+
if (code === undefined || code === '0x') {
|
|
39
|
+
this.log.warn('Uniswap V4 StateView contract not found, skipping fee asset price oracle');
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
this.log.info('Uniswap V4 StateView contract found, initializing fee asset price oracle');
|
|
43
|
+
const oracle = new UniswapPriceOracle(this.client, this.log);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
if (!(await oracle.isPoolInitialized())) {
|
|
47
|
+
this.log.warn('Uniswap V4 pool not initialized, skipping fee asset price oracle');
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
this.log.warn(`Failed to check if Uniswap V4 pool is initialized: ${err}`);
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return oracle;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Computes the fee asset price modifier to be used in the next checkpoint proposal.
|
|
60
|
+
*
|
|
61
|
+
* The modifier adjusts the on-chain fee asset price toward the oracle price,
|
|
62
|
+
* clamped to ±1% (±100 basis points) per checkpoint.
|
|
63
|
+
*
|
|
64
|
+
* Returns 0 if not on mainnet or if the oracle query fails.
|
|
65
|
+
*
|
|
66
|
+
* @returns The price modifier in basis points (positive to increase price, negative to decrease)
|
|
67
|
+
*/
|
|
68
|
+
async computePriceModifier(): Promise<bigint> {
|
|
69
|
+
const uniswapOracle = await this.getUniswapOracle();
|
|
70
|
+
if (!uniswapOracle) {
|
|
71
|
+
return 0n;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
// Get current on-chain price (ETH per fee asset, E12)
|
|
76
|
+
const currentPriceE12 = await this.rollupContract.getEthPerFeeAsset();
|
|
77
|
+
|
|
78
|
+
// Get oracle price (median of last N blocks, ETH per fee asset, E12)
|
|
79
|
+
const oraclePriceE12 = await uniswapOracle.getMeanEthPerFeeAssetE12();
|
|
80
|
+
|
|
81
|
+
// Compute modifier in basis points
|
|
82
|
+
const modifier = this.computePriceModifierBps(currentPriceE12, oraclePriceE12);
|
|
83
|
+
|
|
84
|
+
this.log.debug('Computed price modifier', {
|
|
85
|
+
currentPriceE12: currentPriceE12.toString(),
|
|
86
|
+
oraclePriceE12: oraclePriceE12.toString(),
|
|
87
|
+
modifierBps: modifier.toString(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return modifier;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
this.log.warn(`Failed to compute price modifier, using 0: ${err}`);
|
|
93
|
+
return 0n;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gets the current oracle price (ETH per fee asset, scaled by 1e12).
|
|
99
|
+
* Returns undefined if not on mainnet or if the oracle query fails.
|
|
100
|
+
*/
|
|
101
|
+
async getOraclePrice(): Promise<bigint | undefined> {
|
|
102
|
+
const uniswapOracle = await this.getUniswapOracle();
|
|
103
|
+
if (!uniswapOracle) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
return await uniswapOracle.getMeanEthPerFeeAssetE12();
|
|
109
|
+
} catch (err) {
|
|
110
|
+
this.log.warn(`Failed to get oracle price: ${err}`);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Computes the basis points modifier needed to move from current price toward target price.
|
|
117
|
+
*
|
|
118
|
+
* @param currentPrice - Current ETH per fee asset (E12 scale)
|
|
119
|
+
* @param targetPrice - Target ETH per fee asset (E12 scale)
|
|
120
|
+
* @returns Basis points modifier clamped to ±100 (±1%)
|
|
121
|
+
*/
|
|
122
|
+
computePriceModifierBps(currentPrice: bigint, targetPrice: bigint): bigint {
|
|
123
|
+
if (currentPrice === 0n) {
|
|
124
|
+
return MAX_FEE_ASSET_PRICE_MODIFIER_BPS;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Calculate percentage difference in basis points
|
|
128
|
+
// modifierBps = ((targetPrice - currentPrice) / currentPrice) * 10000
|
|
129
|
+
const diff = targetPrice - currentPrice;
|
|
130
|
+
const rawModifierBps = (diff * 10_000n) / currentPrice;
|
|
131
|
+
|
|
132
|
+
// Clamp to ±MAX_FEE_ASSET_PRICE_MODIFIER_BPS
|
|
133
|
+
if (rawModifierBps > MAX_FEE_ASSET_PRICE_MODIFIER_BPS) {
|
|
134
|
+
return MAX_FEE_ASSET_PRICE_MODIFIER_BPS;
|
|
135
|
+
}
|
|
136
|
+
if (rawModifierBps < -MAX_FEE_ASSET_PRICE_MODIFIER_BPS) {
|
|
137
|
+
return -MAX_FEE_ASSET_PRICE_MODIFIER_BPS;
|
|
138
|
+
}
|
|
139
|
+
return rawModifierBps;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Mainnet Uniswap V4 StateView contract address */
|
|
144
|
+
export const STATE_VIEW_ADDRESS = EthAddress.fromString('0x7ffe42c4a5deea5b0fec41c94c136cf115597227');
|
|
145
|
+
|
|
146
|
+
const PRECISION_Q192 = 10n ** 12n * 2n ** 192n;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Converts Uniswap's sqrtPriceX96 directly to ETH per FeeAsset (E12).
|
|
150
|
+
*
|
|
151
|
+
* For an ETH/FeeAsset pool where ETH is currency0 and FeeAsset is currency1:
|
|
152
|
+
* - Uniswap's sqrtPriceX96 = sqrt(FeeAsset/ETH) * 2^96
|
|
153
|
+
* - We need: ETH/FeeAsset with 1e12 precision
|
|
154
|
+
*
|
|
155
|
+
* Math:
|
|
156
|
+
* price = (sqrtPriceX96 / 2^96)^2 = sqrtPriceX96^2 / 2^192 (FeeAsset per ETH)
|
|
157
|
+
* ethPerFeeAsset = 1 / price = 2^192 / sqrtPriceX96^2
|
|
158
|
+
* ethPerFeeAssetE12 = ethPerFeeAsset * 1e12 = 1e12 * 2^192 / sqrtPriceX96^2
|
|
159
|
+
*/
|
|
160
|
+
export function sqrtPriceX96ToEthPerFeeAssetE12(sqrtPriceX96: bigint): bigint {
|
|
161
|
+
if (sqrtPriceX96 === 0n) {
|
|
162
|
+
throw new Error('Cannot convert zero sqrtPriceX96');
|
|
163
|
+
}
|
|
164
|
+
return PRECISION_Q192 / (sqrtPriceX96 * sqrtPriceX96);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Uniswap V4 StateView ABI - only the functions we need
|
|
168
|
+
*/
|
|
169
|
+
const StateViewAbi = [
|
|
170
|
+
{
|
|
171
|
+
type: 'function',
|
|
172
|
+
name: 'getSlot0',
|
|
173
|
+
inputs: [{ name: 'poolId', type: 'bytes32', internalType: 'PoolId' }],
|
|
174
|
+
outputs: [
|
|
175
|
+
{ name: 'sqrtPriceX96', type: 'uint160', internalType: 'uint160' },
|
|
176
|
+
{ name: 'tick', type: 'int24', internalType: 'int24' },
|
|
177
|
+
{ name: 'protocolFee', type: 'uint24', internalType: 'uint24' },
|
|
178
|
+
{ name: 'lpFee', type: 'uint24', internalType: 'uint24' },
|
|
179
|
+
],
|
|
180
|
+
stateMutability: 'view',
|
|
181
|
+
},
|
|
182
|
+
] as const;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Client for querying the ETH/FeeAsset price from Uniswap V4.
|
|
186
|
+
* Returns prices in ETH per FeeAsset format (E12) to match the rollup contract.
|
|
187
|
+
*/
|
|
188
|
+
class UniswapPriceOracle {
|
|
189
|
+
private readonly stateView;
|
|
190
|
+
private readonly poolId: Hex;
|
|
191
|
+
private readonly log: Logger;
|
|
192
|
+
|
|
193
|
+
constructor(
|
|
194
|
+
private readonly client: ViemClient,
|
|
195
|
+
log?: Logger,
|
|
196
|
+
) {
|
|
197
|
+
this.log = log ?? createLogger('uniswap-price-oracle');
|
|
198
|
+
this.stateView = getContract({
|
|
199
|
+
address: STATE_VIEW_ADDRESS.toString(),
|
|
200
|
+
abi: StateViewAbi,
|
|
201
|
+
client,
|
|
202
|
+
});
|
|
203
|
+
this.poolId = this.computePoolId();
|
|
204
|
+
this.log.debug(`Initialized UniswapPriceOracle with poolId: ${this.poolId}`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Computes the PoolId from the pool configuration by hashing its components.
|
|
209
|
+
* PoolId = keccak256(abi.encode(currency0, currency1, fee, tickSpacing, hooks))
|
|
210
|
+
* For mainnet, the value is expected to be: 0xce2899b16743cfd5a954d8122d5e07f410305b1aebee39fd73d9f3b9ebf10c2f
|
|
211
|
+
* Derived anyway to make it simpler to change if needed.
|
|
212
|
+
*/
|
|
213
|
+
@memoize
|
|
214
|
+
computePoolId(): Hex {
|
|
215
|
+
/** ETH/FeeAsset pool configuration (hardcoded for mainnet) */
|
|
216
|
+
const encoded = encodeAbiParameters(parseAbiParameters('address, address, uint24, int24, address'), [
|
|
217
|
+
EthAddress.ZERO.toString(),
|
|
218
|
+
EthAddress.fromString('0xA27EC0006e59f245217Ff08CD52A7E8b169E62D2').toString(),
|
|
219
|
+
500, // 0.05%
|
|
220
|
+
10,
|
|
221
|
+
EthAddress.fromString('0xd53006d1e3110fD319a79AEEc4c527a0d265E080').toString(),
|
|
222
|
+
]);
|
|
223
|
+
return keccak256(encoded);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async isPoolInitialized(): Promise<boolean> {
|
|
227
|
+
const [sqrtPriceX96] = await this.stateView.read.getSlot0([this.poolId], undefined);
|
|
228
|
+
return sqrtPriceX96 !== 0n;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Gets the price as ETH per FeeAsset, scaled by 1e12.
|
|
233
|
+
* This is the format expected by the rollup contract.
|
|
234
|
+
*
|
|
235
|
+
* @param blockNumber - Optional block number to query at (defaults to latest)
|
|
236
|
+
*/
|
|
237
|
+
async getEthPerFeeAssetE12(blockNumber?: bigint): Promise<bigint> {
|
|
238
|
+
const [sqrtPriceX96] = await this.stateView.read.getSlot0(
|
|
239
|
+
[this.poolId],
|
|
240
|
+
blockNumber !== undefined ? { blockNumber } : undefined,
|
|
241
|
+
);
|
|
242
|
+
return sqrtPriceX96ToEthPerFeeAssetE12(sqrtPriceX96);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Gets the median price over the last N blocks as ETH per FeeAsset (E12).
|
|
247
|
+
* Using median helps protect against single-block manipulation.
|
|
248
|
+
*
|
|
249
|
+
* @param numBlocks - Number of recent blocks to sample (default: 5)
|
|
250
|
+
* @returns Median price as ETH per FeeAsset, scaled by 1e12
|
|
251
|
+
*/
|
|
252
|
+
async getMeanEthPerFeeAssetE12(numBlocks: number = 5): Promise<bigint> {
|
|
253
|
+
const currentBlock = await this.client.getBlockNumber();
|
|
254
|
+
const prices: bigint[] = [];
|
|
255
|
+
|
|
256
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
257
|
+
const blockNumber = currentBlock - BigInt(i);
|
|
258
|
+
if (blockNumber < 0n) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
const price = await this.getEthPerFeeAssetE12(blockNumber);
|
|
264
|
+
prices.push(price);
|
|
265
|
+
} catch (err) {
|
|
266
|
+
this.log.warn(`Failed to get price at block ${blockNumber}: ${err}`);
|
|
267
|
+
// Continue with fewer samples
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const filteredPrices = prices.filter(price => price !== 0n);
|
|
272
|
+
|
|
273
|
+
if (filteredPrices.length === 0) {
|
|
274
|
+
throw new Error('Failed to get any price samples from Uniswap oracle');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const mean = filteredPrices.reduce((a, b) => a + b, 0n) / BigInt(filteredPrices.length);
|
|
278
|
+
return mean;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from 'viem';
|
|
15
15
|
|
|
16
16
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
17
|
-
import {
|
|
17
|
+
import { createL1TxUtils } from '../l1_tx_utils/index.js';
|
|
18
18
|
import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
|
|
19
19
|
|
|
20
20
|
export type L1GovernanceContractAddresses = Pick<
|
|
@@ -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,
|
|
@@ -187,10 +194,10 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
187
194
|
retries: number;
|
|
188
195
|
logger: Logger;
|
|
189
196
|
}) {
|
|
190
|
-
const l1TxUtils =
|
|
197
|
+
const l1TxUtils = createL1TxUtils(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
|
|
|
@@ -244,7 +252,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
244
252
|
retries: number;
|
|
245
253
|
logger: Logger;
|
|
246
254
|
}) {
|
|
247
|
-
const l1TxUtils =
|
|
255
|
+
const l1TxUtils = createL1TxUtils(this.client, { logger });
|
|
248
256
|
const retryDelaySeconds = 12;
|
|
249
257
|
let success = false;
|
|
250
258
|
for (let i = 0; i < retries; i++) {
|
|
@@ -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
|
|