Skip to content

Commit

Permalink
Avoid zero value transfers (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndymionJkb authored Oct 1, 2024
1 parent 448f48e commit 59ed949
Show file tree
Hide file tree
Showing 149 changed files with 308 additions and 215 deletions.
2 changes: 2 additions & 0 deletions pkg/interfaces/contracts/test/IVaultMainMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ interface IVaultMainMock {

function manualSetBufferTotalShares(IERC4626 wrappedToken, uint256 shares) external;

function manualSetBufferBalances(IERC4626 wrappedToken, uint256 underlyingAmount, uint256 wrappedAmount) external;

function manualSettleReentrancy(IERC20 token) external returns (uint256 paid);

function manualSendToReentrancy(IERC20 token, address to, uint256 amount) external;
Expand Down
18 changes: 11 additions & 7 deletions pkg/pool-hooks/contracts/MinimalRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ abstract contract MinimalRouter is RouterCommon, ReentrancyGuardTransient {
IERC20 token = tokens[i];
uint256 amountIn = amountsIn[i];

if (amountIn == 0) {
continue;
}

// There can be only one WETH token in the pool.
if (params.wethIsEth && address(token) == address(_weth)) {
if (address(this).balance < amountIn) {
Expand Down Expand Up @@ -222,26 +226,26 @@ abstract contract MinimalRouter is RouterCommon, ReentrancyGuardTransient {
// minAmountsOut length is checked against tokens length at the Vault.
IERC20[] memory tokens = _vault.getPoolTokens(params.pool);

uint256 ethAmountOut = 0;
for (uint256 i = 0; i < tokens.length; ++i) {
uint256 amountOut = amountsOut[i];

if (amountOut == 0) {
continue;
}

IERC20 token = tokens[i];

// There can be only one WETH token in the pool.
if (params.wethIsEth && address(token) == address(_weth)) {
// Send WETH here and unwrap to native ETH.
_vault.sendTo(_weth, address(this), amountOut);
_weth.withdraw(amountOut);
ethAmountOut = amountOut;
// Send ETH to receiver.
payable(params.receiver).sendValue(amountOut);
} else {
// Transfer the token to the receiver (amountOut).
_vault.sendTo(token, params.receiver, amountOut);
}
}

if (ethAmountOut > 0) {
// Send ETH to receiver.
payable(params.receiver).sendValue(ethAmountOut);
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
301.9k
302.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
245.5k
245.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
340.7k
333.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
266.9k
259.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.6k
196.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
199.2k
181.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.1k
194.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
233.5k
213.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
195.3k
195.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181.4k
181.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.6k
179.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
192.6k
172.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214.4k
214.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.0k
167.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181.9k
166.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
191.7k
176.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.4k
179.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
165.5k
165.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
236.3k
218.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
220.9k
202.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.6k
216.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
255.0k
235.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228.6k
228.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
198.2k
198.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.0k
235.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
211.8k
193.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223.2k
222.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200.9k
188.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210.6k
198.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212.7k
212.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
182.3k
182.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178.4k
178.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
347.6k
347.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
335.1k
335.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
296.8k
297.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232.0k
232.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
327.2k
319.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
253.5k
245.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
208.3k
190.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185.9k
167.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200.9k
181.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
233.6k
213.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185.0k
185.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
167.9k
168.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.6k
179.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179.3k
158.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.0k
167.7k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.6k
153.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
191.7k
176.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
169.1k
169.2k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152.0k
152.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230.1k
212.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
207.7k
189.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
222.4k
202.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
255.1k
235.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
218.3k
218.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
184.1k
184.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235.0k
235.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
198.6k
180.6k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229.7k
229.8k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223.2k
222.9k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
187.6k
175.1k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210.7k
198.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
202.4k
202.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168.2k
168.3k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178.4k
178.5k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348.9k
349.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336.4k
336.5k
Loading

0 comments on commit 59ed949

Please sign in to comment.