@@ -126,10 +126,8 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
126126 ) external nonReentrant onlySolver {
127127 executeInteractions (interactions[0 ]);
128128
129- (
130- GPv2Transfer.Data[] memory inTransfers ,
131- GPv2Transfer.Data[] memory outTransfers
132- ) = computeTradeExecutions (tokens, clearingPrices, trades);
129+ (GPv2Transfer.Data[] memory inTransfers , GPv2Transfer.Data[] memory outTransfers ) =
130+ computeTradeExecutions (tokens, clearingPrices, trades);
133131
134132 vaultRelayer.transferFromAccounts (inTransfers);
135133
@@ -150,26 +148,22 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
150148 /// @param trade The trade to match directly against Balancer liquidity. The
151149 /// order will always be fully executed, so the trade's `executedAmount`
152150 /// field is used to represent a swap limit amount.
153- function swap (
154- IVault.BatchSwapStep[] calldata swaps ,
155- IERC20 [] calldata tokens ,
156- GPv2Trade.Data calldata trade
157- ) external nonReentrant onlySolver {
151+ function swap (IVault.BatchSwapStep[] calldata swaps , IERC20 [] calldata tokens , GPv2Trade.Data calldata trade )
152+ external
153+ nonReentrant
154+ onlySolver
155+ {
158156 RecoveredOrder memory recoveredOrder = allocateRecoveredOrder ();
159157 GPv2Order.Data memory order = recoveredOrder.data;
160158 recoverOrderFromTrade (recoveredOrder, tokens, trade);
161159
162- IVault.SwapKind kind = order.kind == GPv2Order.KIND_SELL
163- ? IVault.SwapKind.GIVEN_IN
164- : IVault.SwapKind.GIVEN_OUT;
160+ IVault.SwapKind kind = order.kind == GPv2Order.KIND_SELL ? IVault.SwapKind.GIVEN_IN : IVault.SwapKind.GIVEN_OUT;
165161
166162 IVault.FundManagement memory funds;
167163 funds.sender = recoveredOrder.owner;
168- funds.fromInternalBalance =
169- order.sellTokenBalance == GPv2Order.BALANCE_INTERNAL;
164+ funds.fromInternalBalance = order.sellTokenBalance == GPv2Order.BALANCE_INTERNAL;
170165 funds.recipient = payable (recoveredOrder.receiver);
171- funds.toInternalBalance =
172- order.buyTokenBalance == GPv2Order.BALANCE_INTERNAL;
166+ funds.toInternalBalance = order.buyTokenBalance == GPv2Order.BALANCE_INTERNAL;
173167
174168 int256 [] memory limits = new int256 [](tokens.length );
175169 uint256 limitAmount = trade.executedAmount;
@@ -205,27 +199,19 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
205199 );
206200
207201 bytes memory orderUid = recoveredOrder.uid;
208- uint256 executedSellAmount = tokenDeltas[trade.sellTokenIndex]
209- .toUint256 ();
210- uint256 executedBuyAmount = (- tokenDeltas[trade.buyTokenIndex])
211- .toUint256 ();
202+ uint256 executedSellAmount = tokenDeltas[trade.sellTokenIndex].toUint256 ();
203+ uint256 executedBuyAmount = (- tokenDeltas[trade.buyTokenIndex]).toUint256 ();
212204
213205 // NOTE: Check that the orders were completely filled and update their
214206 // filled amounts to avoid replaying them. The limit price and order
215207 // validity has already been verified when executing the swap through
216208 // the `limit` and `deadline` parameters.
217209 require (filledAmount[orderUid] == 0 , "GPv2: order filled " );
218210 if (order.kind == GPv2Order.KIND_SELL) {
219- require (
220- executedSellAmount == order.sellAmount,
221- "GPv2: sell amount not respected "
222- );
211+ require (executedSellAmount == order.sellAmount, "GPv2: sell amount not respected " );
223212 filledAmount[orderUid] = order.sellAmount;
224213 } else {
225- require (
226- executedBuyAmount == order.buyAmount,
227- "GPv2: buy amount not respected "
228- );
214+ require (executedBuyAmount == order.buyAmount, "GPv2: buy amount not respected " );
229215 filledAmount[orderUid] = order.buyAmount;
230216 }
231217
@@ -248,7 +234,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
248234 /// must be the sender of this message. See [`extractOrderUidParams`]
249235 /// for details on orderUid.
250236 function invalidateOrder (bytes calldata orderUid ) external {
251- (, address owner , ) = orderUid.extractOrderUidParams ();
237+ (, address owner ,) = orderUid.extractOrderUidParams ();
252238 require (owner == msg .sender , "GPv2: caller does not own order " );
253239 filledAmount[orderUid] = type (uint256 ).max;
254240 emit OrderInvalidated (owner, orderUid);
@@ -259,9 +245,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
259245 ///
260246 /// @param orderUids The unique identifiers of the expired order to free
261247 /// storage for.
262- function freeFilledAmountStorage (
263- bytes [] calldata orderUids
264- ) external onlyInteraction {
248+ function freeFilledAmountStorage (bytes [] calldata orderUids ) external onlyInteraction {
265249 freeOrderStorage (filledAmount, orderUids);
266250 }
267251
@@ -270,9 +254,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
270254 ///
271255 /// @param orderUids The unique identifiers of the expired order to free
272256 /// storage for.
273- function freePreSignatureStorage (
274- bytes [] calldata orderUids
275- ) external onlyInteraction {
257+ function freePreSignatureStorage (bytes [] calldata orderUids ) external onlyInteraction {
276258 freeOrderStorage (preSignature, orderUids);
277259 }
278260
@@ -291,13 +273,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
291273 IERC20 [] calldata tokens ,
292274 uint256 [] calldata clearingPrices ,
293275 GPv2Trade.Data[] calldata trades
294- )
295- internal
296- returns (
297- GPv2Transfer.Data[] memory inTransfers ,
298- GPv2Transfer.Data[] memory outTransfers
299- )
300- {
276+ ) internal returns (GPv2Transfer.Data[] memory inTransfers , GPv2Transfer.Data[] memory outTransfers ) {
301277 RecoveredOrder memory recoveredOrder = allocateRecoveredOrder ();
302278
303279 inTransfers = new GPv2Transfer.Data [](trades.length );
@@ -365,10 +341,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
365341 // amount_y = amount_x * price_x / price_y
366342 // ```
367343
368- require (
369- order.sellAmount.mul (sellPrice) >= order.buyAmount.mul (buyPrice),
370- "GPv2: limit price not respected "
371- );
344+ require (order.sellAmount.mul (sellPrice) >= order.buyAmount.mul (buyPrice), "GPv2: limit price not respected " );
372345
373346 uint256 executedSellAmount;
374347 uint256 executedBuyAmount;
@@ -378,31 +351,20 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
378351 if (order.kind == GPv2Order.KIND_SELL) {
379352 if (order.partiallyFillable) {
380353 executedSellAmount = executedAmount;
381- executedFeeAmount = order.feeAmount.mul (executedSellAmount).div (
382- order.sellAmount
383- );
354+ executedFeeAmount = order.feeAmount.mul (executedSellAmount).div (order.sellAmount);
384355 } else {
385356 executedSellAmount = order.sellAmount;
386357 executedFeeAmount = order.feeAmount;
387358 }
388359
389- executedBuyAmount = executedSellAmount.mul (sellPrice).ceilDiv (
390- buyPrice
391- );
360+ executedBuyAmount = executedSellAmount.mul (sellPrice).ceilDiv (buyPrice);
392361
393- currentFilledAmount = filledAmount[orderUid].add (
394- executedSellAmount
395- );
396- require (
397- currentFilledAmount <= order.sellAmount,
398- "GPv2: order filled "
399- );
362+ currentFilledAmount = filledAmount[orderUid].add (executedSellAmount);
363+ require (currentFilledAmount <= order.sellAmount, "GPv2: order filled " );
400364 } else {
401365 if (order.partiallyFillable) {
402366 executedBuyAmount = executedAmount;
403- executedFeeAmount = order.feeAmount.mul (executedBuyAmount).div (
404- order.buyAmount
405- );
367+ executedFeeAmount = order.feeAmount.mul (executedBuyAmount).div (order.buyAmount);
406368 } else {
407369 executedBuyAmount = order.buyAmount;
408370 executedFeeAmount = order.feeAmount;
@@ -411,10 +373,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
411373 executedSellAmount = executedBuyAmount.mul (buyPrice).div (sellPrice);
412374
413375 currentFilledAmount = filledAmount[orderUid].add (executedBuyAmount);
414- require (
415- currentFilledAmount <= order.buyAmount,
416- "GPv2: order filled "
417- );
376+ require (currentFilledAmount <= order.buyAmount, "GPv2: order filled " );
418377 }
419378
420379 executedSellAmount = executedSellAmount.add (executedFeeAmount);
@@ -443,25 +402,16 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
443402
444403 /// @dev Execute a list of arbitrary contract calls from this contract.
445404 /// @param interactions The list of interactions to execute.
446- function executeInteractions (
447- GPv2Interaction.Data[] calldata interactions
448- ) internal {
405+ function executeInteractions (GPv2Interaction.Data[] calldata interactions ) internal {
449406 for (uint256 i; i < interactions.length ; ++ i) {
450407 GPv2Interaction.Data calldata interaction = interactions[i];
451408
452409 // To prevent possible attack on user funds, we explicitly disable
453410 // any interactions with the vault relayer contract.
454- require (
455- interaction.target != address (vaultRelayer),
456- "GPv2: forbidden interaction "
457- );
411+ require (interaction.target != address (vaultRelayer), "GPv2: forbidden interaction " );
458412 GPv2Interaction.execute (interaction);
459413
460- emit Interaction (
461- interaction.target,
462- interaction.value,
463- GPv2Interaction.selector (interaction)
464- );
414+ emit Interaction (interaction.target, interaction.value, GPv2Interaction.selector (interaction));
465415 }
466416 }
467417
@@ -471,14 +421,11 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
471421 ///
472422 /// @param orderUids Order refund data for freeing storage.
473423 /// @param orderStorage Order storage mapped on a UID.
474- function freeOrderStorage (
475- mapping (bytes => uint256 ) storage orderStorage ,
476- bytes [] calldata orderUids
477- ) internal {
424+ function freeOrderStorage (mapping (bytes => uint256 ) storage orderStorage , bytes [] calldata orderUids ) internal {
478425 for (uint256 i; i < orderUids.length ; ++ i) {
479426 bytes calldata orderUid = orderUids[i];
480427
481- (, , uint32 validTo ) = orderUid.extractOrderUidParams ();
428+ (,, uint32 validTo ) = orderUid.extractOrderUidParams ();
482429 // solhint-disable-next-line not-rely-on-time
483430 require (validTo < block .timestamp , "GPv2: order still valid " );
484431
0 commit comments