Skip to content

Commit 1a3a326

Browse files
authored
chore: mint block rewards for 200K blocks at deployment (#13537)
Fund the reward distributor with funds for 200K blocks as part of the deployments.
1 parent b30b5b3 commit 1a3a326

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

yarn-project/end-to-end/src/e2e_fees/failures.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ describe('e2e_fees failures', () => {
9797

9898
expect(txReceipt.status).toBe(TxStatus.APP_LOGIC_REVERTED);
9999

100+
const { sequencerBlockRewards } = await t.getBlockRewards();
101+
100102
// @note There is a potential race condition here if other tests send transactions that get into the same
101103
// epoch and thereby pays out fees at the same time (when proven).
102104
await t.context.watcher.trigger();
@@ -106,7 +108,9 @@ describe('e2e_fees failures', () => {
106108
const feeAmount = txReceipt.transactionFee!;
107109
const expectedProverFee = await t.getProverFee(txReceipt.blockNumber!);
108110
const newSequencerRewards = await t.getCoinbaseSequencerRewards();
109-
expect(newSequencerRewards).toEqual(currentSequencerRewards + feeAmount - expectedProverFee);
111+
expect(newSequencerRewards).toEqual(
112+
currentSequencerRewards + sequencerBlockRewards + feeAmount - expectedProverFee,
113+
);
110114

111115
// and thus we paid the fee
112116
await expectMapping(

yarn-project/end-to-end/src/e2e_fees/fees_test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import {
1010
} from '@aztec/aztec.js';
1111
import { CheatCodes } from '@aztec/aztec.js/testing';
1212
import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants';
13-
import { type DeployL1ContractsArgs, RollupContract, createL1Clients, getPublicClient } from '@aztec/ethereum';
13+
import {
14+
type DeployL1ContractsArgs,
15+
RollupContract,
16+
createL1Clients,
17+
getPublicClient,
18+
l1Artifacts,
19+
} from '@aztec/ethereum';
1420
import { ChainMonitor } from '@aztec/ethereum/test';
1521
import { EthAddress } from '@aztec/foundation/eth-address';
1622
import { TestERC20Abi } from '@aztec/l1-artifacts';
@@ -140,6 +146,26 @@ export class FeesTest {
140146
}
141147
}
142148

149+
async getBlockRewards() {
150+
const rewardDistributor = getContract({
151+
address: this.context.deployL1ContractsValues.l1ContractAddresses.rewardDistributorAddress.toString(),
152+
abi: l1Artifacts.rewardDistributor.contractAbi,
153+
client: this.context.deployL1ContractsValues.publicClient,
154+
});
155+
156+
const blockReward = await rewardDistributor.read.BLOCK_REWARD();
157+
158+
const balance = await this.feeJuiceBridgeTestHarness.getL1FeeJuiceBalance(
159+
EthAddress.fromString(rewardDistributor.address),
160+
);
161+
162+
const toDistribute = balance > blockReward ? blockReward : balance;
163+
const sequencerBlockRewards = toDistribute / 2n;
164+
const proverBlockRewards = toDistribute - sequencerBlockRewards;
165+
166+
return { sequencerBlockRewards, proverBlockRewards };
167+
}
168+
143169
async mintAndBridgeFeeJuice(address: AztecAddress, amount: bigint) {
144170
const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(amount, address);
145171
const { claimSecret: secret, messageLeafIndex: index } = claim;

yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('e2e_fees private_payment', () => {
109109
expect(localTx.data.feePayer).toEqual(bananaFPC.address);
110110

111111
const sequencerRewardsBefore = await t.getCoinbaseSequencerRewards();
112+
const { sequencerBlockRewards } = await t.getBlockRewards();
112113

113114
const tx = localTx.send();
114115
await tx.wait({ timeout: 300, interval: 10 });
@@ -121,7 +122,7 @@ describe('e2e_fees private_payment', () => {
121122
// epoch and thereby pays out fees at the same time (when proven).
122123
const expectedProverFee = await t.getProverFee(receipt.blockNumber!);
123124
await expect(t.getCoinbaseSequencerRewards()).resolves.toEqual(
124-
sequencerRewardsBefore + receipt.transactionFee! - expectedProverFee,
125+
sequencerRewardsBefore + sequencerBlockRewards + receipt.transactionFee! - expectedProverFee,
125126
);
126127
const feeAmount = receipt.transactionFee!;
127128

yarn-project/ethereum/src/deploy_l1_contracts.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,36 @@ export const deploySharedContracts = async (
419419

420420
const registry = new RegistryContract(clients.publicClient, registryAddress);
421421

422+
/* -------------------------------------------------------------------------- */
423+
/* FUND REWARD DISTRIBUTOR START */
424+
/* -------------------------------------------------------------------------- */
425+
426+
const rewardDistributorAddress = await registry.getRewardDistributor();
427+
428+
const rewardDistributor = getContract({
429+
address: rewardDistributorAddress.toString(),
430+
abi: l1Artifacts.rewardDistributor.contractAbi,
431+
client: clients.publicClient,
432+
});
433+
434+
const blockReward = await rewardDistributor.read.BLOCK_REWARD();
435+
436+
const funding = blockReward * 200000n;
437+
const { txHash: fundRewardDistributorTxHash } = await deployer.sendTransaction({
438+
to: feeAssetAddress.toString(),
439+
data: encodeFunctionData({
440+
abi: l1Artifacts.feeAsset.contractAbi,
441+
functionName: 'mint',
442+
args: [rewardDistributorAddress.toString(), funding],
443+
}),
444+
});
445+
446+
logger.verbose(`Funded reward distributor with ${funding} fee asset in ${fundRewardDistributorTxHash}`);
447+
448+
/* -------------------------------------------------------------------------- */
449+
/* FUND REWARD DISTRIBUTOR STOP */
450+
/* -------------------------------------------------------------------------- */
451+
422452
return {
423453
feeAssetAddress,
424454
feeAssetHandlerAddress,

0 commit comments

Comments
 (0)