@@ -38,6 +38,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
3838 * @param maxAmountToSwap Max amount to be swapped
3939 * @param amountToReceive Amount to be received from the swap
4040 * @return amountSold The amount sold during the swap
41+ * @return amountBought The amount bought during the swap
4142 */
4243 function _buyOnParaSwap (
4344 uint256 toAmountOffset ,
@@ -46,7 +47,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
4647 IERC20Detailed assetToSwapTo ,
4748 uint256 maxAmountToSwap ,
4849 uint256 amountToReceive
49- ) internal returns (uint256 amountSold ) {
50+ ) internal returns (uint256 amountSold , uint256 amountBought ) {
5051 (bytes memory buyCalldata , IParaSwapAugustus augustus ) = abi.decode (
5152 paraswapData,
5253 (bytes , IParaSwapAugustus)
@@ -73,7 +74,6 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
7374 uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf (address (this ));
7475
7576 address tokenTransferProxy = augustus.getTokenTransferProxy ();
76- assetToSwapFrom.safeApprove (tokenTransferProxy, 0 );
7777 assetToSwapFrom.safeApprove (tokenTransferProxy, maxAmountToSwap);
7878
7979 if (toAmountOffset != 0 ) {
@@ -98,13 +98,15 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
9898 revert (0 , returndatasize ())
9999 }
100100 }
101+ // Reset allowance
102+ assetToSwapFrom.safeApprove (tokenTransferProxy, 0 );
101103
102104 uint256 balanceAfterAssetFrom = assetToSwapFrom.balanceOf (address (this ));
103105 amountSold = balanceBeforeAssetFrom - balanceAfterAssetFrom;
104106 require (amountSold <= maxAmountToSwap, 'WRONG_BALANCE_AFTER_SWAP ' );
105- uint256 amountReceived = assetToSwapTo.balanceOf (address (this )) - balanceBeforeAssetTo;
106- require (amountReceived >= amountToReceive, 'INSUFFICIENT_AMOUNT_RECEIVED ' );
107+ amountBought = assetToSwapTo.balanceOf (address (this )) - balanceBeforeAssetTo;
108+ require (amountBought >= amountToReceive, 'INSUFFICIENT_AMOUNT_RECEIVED ' );
107109
108- emit Bought (address (assetToSwapFrom), address (assetToSwapTo), amountSold, amountReceived );
110+ emit Bought (address (assetToSwapFrom), address (assetToSwapTo), amountSold, amountBought );
109111 }
110112}
0 commit comments