-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathRevShareContractsUpgraderIntegration.t.sol
More file actions
129 lines (110 loc) · 5.5 KB
/
Copy pathRevShareContractsUpgraderIntegration.t.sol
File metadata and controls
129 lines (110 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import {RevShareUpgradeAndSetup} from "src/template/RevShareUpgradeAndSetup.sol";
import {IntegrationBase} from "./IntegrationBase.t.sol";
contract RevShareContractsUpgraderIntegrationTest is IntegrationBase {
RevShareUpgradeAndSetup public revShareTask;
function setUp() public {
// Create forks for L1 (mainnet) and L2s (OP, Ink, and Soneium)
// OP Mainnet L2 is needed for relaying L1→L2 deposits from FeesDepositor
_mainnetForkId = vm.createFork("http://127.0.0.1:8545");
_opMainnetForkId = vm.createFork("http://127.0.0.1:9545");
_inkMainnetForkId = vm.createFork("http://127.0.0.1:9546");
_soneiumMainnetForkId = vm.createFork("http://127.0.0.1:9547");
// Configure Ink and Soneium chains with production config values
// Values from test/tasks/example/eth/017-revshare-upgrade-and-setup-sony-ink/config.toml
l2Chains.push(
L2ChainConfig({
forkId: _inkMainnetForkId,
portal: INK_MAINNET_PORTAL,
l1Messenger: INK_MAINNET_L1_MESSENGER,
minWithdrawalAmount: 2 ether,
l1WithdrawalRecipient: 0xed9B99a703BaD32AC96FDdc313c0652e379251Fd,
withdrawalGasLimit: 800000,
chainFeesRecipient: 0x5f077b4c3509C2c192e50B6654d924Fcb8126A60,
name: "Ink Mainnet"
})
);
l2Chains.push(
L2ChainConfig({
forkId: _soneiumMainnetForkId,
portal: SONEIUM_MAINNET_PORTAL,
l1Messenger: SONEIUM_MAINNET_L1_MESSENGER,
minWithdrawalAmount: 2 ether,
l1WithdrawalRecipient: 0xed9B99a703BaD32AC96FDdc313c0652e379251Fd,
withdrawalGasLimit: 800000,
chainFeesRecipient: 0xF07b3169ffF67A8AECdBb18d9761AEeE34591112,
name: "Soneium Mainnet"
})
);
revShareTask = new RevShareUpgradeAndSetup();
// Switch to mainnet fork for task execution
vm.selectFork(_mainnetForkId);
}
/// @notice Test the integration of upgradeAndSetupRevShare (Ink and Soneium only - need proxy upgrade)
function test_upgradeAndSetupRevShare_integration() public {
// Step 1: Record logs for L1→L2 message relay
vm.recordLogs();
// Step 2: Execute task simulation
revShareTask.simulate("test/tasks/example/eth/017-revshare-upgrade-and-setup-sony-ink/config.toml");
// Step 3: Relay deposit transactions from L1 to all L2s
uint256[] memory forkIds = new uint256[](l2Chains.length);
address[] memory portals = new address[](l2Chains.length);
for (uint256 i = 0; i < l2Chains.length; i++) {
forkIds[i] = l2Chains[i].forkId;
portals[i] = l2Chains[i].portal;
}
_relayAllMessages(forkIds, IS_SIMULATE, portals);
// Step 4: Assert L2 state for all chains
for (uint256 i = 0; i < l2Chains.length; i++) {
L2ChainConfig memory chain = l2Chains[i];
vm.selectFork(chain.forkId);
address l1Withdrawer = _computeL1WithdrawerAddress(
chain.minWithdrawalAmount, chain.l1WithdrawalRecipient, chain.withdrawalGasLimit
);
address revShareCalculator = _computeRevShareCalculatorAddress(l1Withdrawer, chain.chainFeesRecipient);
_assertL2State(
l1Withdrawer,
revShareCalculator,
chain.minWithdrawalAmount,
chain.l1WithdrawalRecipient,
chain.withdrawalGasLimit,
chain.chainFeesRecipient
);
}
// Step 5: Fund vaults for all chains
for (uint256 i = 0; i < l2Chains.length; i++) {
_fundVaults(5 ether, l2Chains[i].forkId);
}
// Step 6: Disburse fees in all chains and assert withdrawals
// Expected L1Withdrawer share = 15 ether * 15% = 2.25 ether
// It is 15 ether instead of 20 because net revenue doesn't count L1FeeVault's balance
// For details on the rev share calculation, check the SuperchainRevSharesCalculator contract.
// https://github.com/ethereum-optimism/optimism/blob/f392d4b7e8bc5d1c8d38fcf19c8848764f8bee3b/packages/contracts-bedrock/src/L2/SuperchainRevSharesCalculator.sol#L67-L101
uint256 expectedWithdrawalAmount = 2.25 ether;
for (uint256 i = 0; i < l2Chains.length; i++) {
L2ChainConfig memory chain = l2Chains[i];
address l1Withdrawer = _computeL1WithdrawerAddress(
chain.minWithdrawalAmount, chain.l1WithdrawalRecipient, chain.withdrawalGasLimit
);
_executeDisburseAndAssertWithdrawal(
ChainConfig({
l1ForkId: _mainnetForkId,
l2ForkId: chain.forkId,
l1Withdrawer: l1Withdrawer,
l1WithdrawalRecipient: chain.l1WithdrawalRecipient,
expectedWithdrawalAmount: expectedWithdrawalAmount,
portal: chain.portal,
l1Messenger: chain.l1Messenger,
withdrawalGasLimit: chain.withdrawalGasLimit
}),
OPConfig({
opL2ForkId: _opMainnetForkId,
opL1Messenger: OP_MAINNET_L1_MESSENGER,
opPortal: OP_MAINNET_PORTAL,
feesDepositorTarget: OP_MAINNET_FEES_DEPOSITOR_TARGET
})
);
}
}
}