@@ -46,7 +46,7 @@ contract BridgeTest is Test {
46
46
vm.selectFork (_ethereumFork);
47
47
router = new EnsoRouter ();
48
48
shortcuts = EnsoShortcuts (payable (router.shortcuts ()));
49
- lzReceiver = new LayerZeroReceiver (address (this ), address (router), address (this ), 100_000 );
49
+ lzReceiver = new LayerZeroReceiver (address (this ), address (router), address (this ));
50
50
51
51
address [] memory ofts = new address [](2 );
52
52
ofts[0 ] = ethPool;
@@ -60,7 +60,7 @@ contract BridgeTest is Test {
60
60
uint256 balanceBefore = weth.balanceOf (address (this ));
61
61
62
62
(bytes32 [] memory commands , bytes [] memory state ) = _buildWethDeposit (ETH_AMOUNT);
63
- bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, commands, state);
63
+ bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, 0 , 0 , commands, state);
64
64
65
65
// transfer funds
66
66
(bool success ,) = address (lzReceiver).call { value: ETH_AMOUNT }("" );
@@ -78,7 +78,7 @@ contract BridgeTest is Test {
78
78
79
79
// TOO MUCH VALUE ATTEMPTED TO TRANSFER
80
80
(bytes32 [] memory commands , bytes [] memory state ) = _buildWethDeposit (ETH_AMOUNT * 100 );
81
- bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, commands, state);
81
+ bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, 0 , 0 , commands, state);
82
82
83
83
// transfer funds
84
84
(bool success ,) = address (lzReceiver).call { value: ETH_AMOUNT }("" );
@@ -91,32 +91,21 @@ contract BridgeTest is Test {
91
91
assertEq (balanceBefore, address (this ).balance);
92
92
}
93
93
94
- function testEthBridgeWithShortcutOutOfGas () public {
94
+ function testEthBridgeWithLessThanEstimateGas () public {
95
95
vm.selectFork (_ethereumFork);
96
96
97
97
(bytes32 [] memory commands , bytes [] memory state ) = _buildWethDeposit (ETH_AMOUNT);
98
- bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, commands, state);
98
+ // exact gas amount needed for execution
99
+ uint256 estimatedGas = 75_272 ;
100
+ bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, 0 , estimatedGas, commands, state);
99
101
100
102
// transfer funds
101
103
(bool success ,) = address (lzReceiver).call { value: ETH_AMOUNT }("" );
102
104
if (! success) revert TransferFailed ();
103
105
// trigger compose with insufficient gas
104
- vm.expectRevert ();
105
- lzReceiver.lzCompose { gas: 108_000 }(ethPool, bytes32 (0 ), message, address (0 ), "" );
106
- }
107
-
108
- function testEthBridgeWithLessThanReserveGas () public {
109
- vm.selectFork (_ethereumFork);
110
-
111
- (bytes32 [] memory commands , bytes [] memory state ) = _buildWethDeposit (ETH_AMOUNT);
112
- bytes memory message = _buildLzComposeMessage (ETH_AMOUNT, commands, state);
113
-
114
- // transfer funds
115
- (bool success ,) = address (lzReceiver).call { value: ETH_AMOUNT }("" );
116
- if (! success) revert TransferFailed ();
117
- // trigger compose with insufficient gas
118
- vm.expectRevert ();
119
- lzReceiver.lzCompose { gas: 99_000 }(ethPool, bytes32 (0 ), message, address (0 ), "" );
106
+ vm.expectRevert (abi.encodeWithSelector (LayerZeroReceiver.InsufficientGas.selector , bytes32 (0 ), estimatedGas, estimatedGas - 1 ));
107
+ // exactly 1 less gas than needed for lz compose
108
+ lzReceiver.lzCompose { gas: 85_663 }(ethPool, bytes32 (0 ), message, address (0 ), "" );
120
109
}
121
110
122
111
function testUsdcBridge () public {
@@ -125,7 +114,7 @@ contract BridgeTest is Test {
125
114
uint256 balanceBefore = IERC20 (usdc).balanceOf (vitalik);
126
115
127
116
(bytes32 [] memory commands , bytes [] memory state ) = _buildTransfer (usdc, vitalik, USDC_AMOUNT);
128
- bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, commands, state);
117
+ bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, 0 , 0 , commands, state);
129
118
130
119
// transfer funds
131
120
vm.startPrank (usdcPool);
@@ -145,7 +134,7 @@ contract BridgeTest is Test {
145
134
146
135
(bytes32 [] memory commands , bytes [] memory state ) =
147
136
_buildTokenAndValueTransfer (usdc, vitalik, USDC_AMOUNT, ETH_AMOUNT);
148
- bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, commands, state);
137
+ bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, ETH_AMOUNT, 0 , commands, state);
149
138
150
139
// transfer funds
151
140
vm.startPrank (usdcPool);
@@ -168,7 +157,7 @@ contract BridgeTest is Test {
168
157
169
158
// TOO MUCH VALUE ATTEMPTED TO TRANSFER
170
159
(bytes32 [] memory commands , bytes [] memory state ) = _buildTransfer (usdc, vitalik, USDC_AMOUNT * 100 );
171
- bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, commands, state);
160
+ bytes memory message = _buildLzComposeMessage (USDC_AMOUNT, 0 , 0 , commands, state);
172
161
173
162
// transfer funds
174
163
vm.startPrank (usdcPool);
@@ -201,13 +190,8 @@ contract BridgeTest is Test {
201
190
uint256 wethBalanceBefore = weth.balanceOf (address (this ));
202
191
203
192
// sweep
204
- address [] memory tokens = new address [](2 );
205
- tokens[0 ] = eth;
206
- tokens[1 ] = address (weth);
207
- uint256 [] memory amounts = new uint256 [](2 );
208
- amounts[0 ] = address (lzReceiver).balance;
209
- amounts[1 ] = weth.balanceOf (address (lzReceiver));
210
- lzReceiver.sweep (tokens, amounts);
193
+ lzReceiver.sweep (bytes32 (uint256 (1 )), eth, address (lzReceiver).balance);
194
+ lzReceiver.sweep (bytes32 (uint256 (2 )), address (weth), weth.balanceOf (address (lzReceiver)));
211
195
212
196
uint256 ethBalanceAfter = address (this ).balance;
213
197
uint256 wethBalanceAfter = weth.balanceOf (address (this ));
@@ -219,6 +203,8 @@ contract BridgeTest is Test {
219
203
220
204
function _buildLzComposeMessage (
221
205
uint256 amount ,
206
+ uint256 nativeDrop ,
207
+ uint256 estimatedGas ,
222
208
bytes32 [] memory commands ,
223
209
bytes [] memory state
224
210
)
@@ -230,7 +216,7 @@ contract BridgeTest is Test {
230
216
bytes memory shortcutData =
231
217
abi.encodeWithSelector (shortcuts.executeShortcut.selector , bytes32 (0 ), bytes32 (0 ), commands, state);
232
218
// encode callback data
233
- bytes memory callbackData = abi.encode (address (this ), shortcutData);
219
+ bytes memory callbackData = abi.encode (address (this ), nativeDrop, estimatedGas, shortcutData);
234
220
// encode message
235
221
message = OFTComposeMsgCodec.encode (
236
222
uint64 (0 ),
0 commit comments