diff --git a/src/utils/zap/Zap.sol b/src/utils/zap/Zap.sol index c2f0c712..aeae49b5 100644 --- a/src/utils/zap/Zap.sol +++ b/src/utils/zap/Zap.sol @@ -19,7 +19,6 @@ import {Reentrancy} from "./utils/Reentrancy.sol"; /// @author @barrasso /// @author @moss-eth contract Zap is Reentrancy, Errors { - /// @custom:circle address public immutable USDC; @@ -101,11 +100,7 @@ contract Zap is Reentrancy, Errors { /// @param _tolerance acceptable slippage for wrapping and selling /// @param _receiver address to receive USDx /// @return zapped amount of USDx received - function zapIn( - uint256 _amount, - uint256 _tolerance, - address _receiver - ) + function zapIn(uint256 _amount, uint256 _tolerance, address _receiver) external returns (uint256 zapped) { @@ -116,10 +111,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the zapped USDx - function _zapIn( - uint256 _amount, - uint256 _tolerance - ) + function _zapIn(uint256 _amount, uint256 _tolerance) internal returns (uint256 zapped) { @@ -133,11 +125,7 @@ contract Zap is Reentrancy, Errors { /// @param _tolerance acceptable slippage for buying and unwrapping /// @param _receiver address to receive USDC /// @return zapped amount of USDC received - function zapOut( - uint256 _amount, - uint256 _tolerance, - address _receiver - ) + function zapOut(uint256 _amount, uint256 _tolerance, address _receiver) external returns (uint256 zapped) { @@ -148,10 +136,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the zapped USDC - function _zapOut( - uint256 _amount, - uint256 _tolerance - ) + function _zapOut(uint256 _amount, uint256 _tolerance) internal returns (uint256 zapped) { @@ -178,10 +163,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 wrapped) - { + ) external returns (uint256 wrapped) { _pull(_token, msg.sender, _amount); wrapped = _wrap(_token, _synthId, _amount, _tolerance); _push(ISpotMarket(SPOT_MARKET).getSynth(_synthId), _receiver, wrapped); @@ -194,10 +176,7 @@ contract Zap is Reentrancy, Errors { uint128 _synthId, uint256 _amount, uint256 _tolerance - ) - internal - returns (uint256 wrapped) - { + ) internal returns (uint256 wrapped) { IERC20(_token).approve(SPOT_MARKET, _amount); (wrapped,) = ISpotMarket(SPOT_MARKET).wrap({ marketId: _synthId, @@ -221,10 +200,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 unwrapped) - { + ) external returns (uint256 unwrapped) { address synth = ISpotMarket(SPOT_MARKET).getSynth(_synthId); _pull(synth, msg.sender, _amount); unwrapped = _unwrap(_synthId, _amount, _tolerance); @@ -233,11 +209,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the unwrapped token - function _unwrap( - uint128 _synthId, - uint256 _amount, - uint256 _tolerance - ) + function _unwrap(uint128 _synthId, uint256 _amount, uint256 _tolerance) private returns (uint256 unwrapped) { @@ -266,10 +238,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 received, address synth) - { + ) external returns (uint256 received, address synth) { synth = ISpotMarket(SPOT_MARKET).getSynth(_synthId); _pull(USDX, msg.sender, _amount); received = _buy(_synthId, _amount, _tolerance); @@ -278,11 +247,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the bought synth - function _buy( - uint128 _synthId, - uint256 _amount, - uint256 _tolerance - ) + function _buy(uint128 _synthId, uint256 _amount, uint256 _tolerance) internal returns (uint256 received) { @@ -311,10 +276,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 received) - { + ) external returns (uint256 received) { address synth = ISpotMarket(SPOT_MARKET).getSynth(_synthId); _pull(synth, msg.sender, _amount); received = _sell(_synthId, _amount, _tolerance); @@ -323,11 +285,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the sold USDX - function _sell( - uint128 _synthId, - uint256 _amount, - uint256 _tolerance - ) + function _sell(uint128 _synthId, uint256 _amount, uint256 _tolerance) internal returns (uint256 received) { @@ -365,11 +323,7 @@ contract Zap is Reentrancy, Errors { uint256 _unwrapTolerance, uint256 _swapTolerance, address _receiver - ) - external - isAuthorized(_accountId) - requireStage(Stage.UNSET) - { + ) external isAuthorized(_accountId) requireStage(Stage.UNSET) { stage = Stage.LEVEL1; bytes memory params = abi.encode( @@ -410,12 +364,7 @@ contract Zap is Reentrancy, Errors { uint256 _premium, address, bytes calldata _params - ) - external - onlyAave - requireStage(Stage.LEVEL1) - returns (bool) - { + ) external onlyAave requireStage(Stage.LEVEL1) returns (bool) { stage = Stage.LEVEL2; (,,, address _collateral,,,, address _receiver) = abi.decode( @@ -448,11 +397,7 @@ contract Zap is Reentrancy, Errors { uint256 _flashloan, uint256 _premium, bytes calldata _params - ) - internal - requireStage(Stage.LEVEL2) - returns (uint256 unwound) - { + ) internal requireStage(Stage.LEVEL2) returns (uint256 unwound) { ( uint128 _accountId, uint128 _collateralId, @@ -575,10 +520,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint128 _accountId, address _receiver - ) - external - isAuthorized(_accountId) - { + ) external isAuthorized(_accountId) { _withdraw(_synthId, _amount, _accountId); address synth = _synthId == USDX_ID ? USDX @@ -589,11 +531,7 @@ contract Zap is Reentrancy, Errors { /// @custom:synthetix RBAC permission required: "PERPS_MODIFY_COLLATERAL" /// @dev following execution, this contract will hold the withdrawn /// collateral - function _withdraw( - uint128 _synthId, - uint256 _amount, - uint128 _accountId - ) + function _withdraw(uint128 _synthId, uint256 _amount, uint128 _accountId) internal { IPerpsMarket market = IPerpsMarket(PERPS_MARKET); @@ -690,10 +628,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 deducted) - { + ) external returns (uint256 deducted) { _pull(_from, msg.sender, _tolerance); deducted = _swapFor(_from, _amount, _tolerance); _push(USDC, _receiver, _amount); @@ -705,11 +640,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the swapped USDC - function _swapFor( - address _from, - uint256 _amount, - uint256 _tolerance - ) + function _swapFor(address _from, uint256 _amount, uint256 _tolerance) internal returns (uint256 deducted) { @@ -749,10 +680,7 @@ contract Zap is Reentrancy, Errors { uint256 _amount, uint256 _tolerance, address _receiver - ) - external - returns (uint256 received) - { + ) external returns (uint256 received) { _pull(_from, msg.sender, _amount); received = _swapWith(_from, _amount, _tolerance); _push(USDC, _receiver, received); @@ -760,11 +688,7 @@ contract Zap is Reentrancy, Errors { /// @dev allowance is assumed /// @dev following execution, this contract will hold the swapped USDC - function _swapWith( - address _from, - uint256 _amount, - uint256 _tolerance - ) + function _swapWith(address _from, uint256 _amount, uint256 _tolerance) internal returns (uint256 received) { @@ -798,11 +722,7 @@ contract Zap is Reentrancy, Errors { /// @param _from address of sender /// @param _amount amount of token to pull /// @return success boolean representing execution success - function _pull( - address _token, - address _from, - uint256 _amount - ) + function _pull(address _token, address _from, uint256 _amount) internal returns (bool) { @@ -822,11 +742,7 @@ contract Zap is Reentrancy, Errors { /// @param _receiver address of receiver /// @param _amount amount of token to push /// @return success boolean representing execution success - function _push( - address _token, - address _receiver, - uint256 _amount - ) + function _push(address _token, address _receiver, uint256 _amount) internal returns (bool) { @@ -839,5 +755,4 @@ contract Zap is Reentrancy, Errors { revert PushFailed(bytes(reason)); } } - } diff --git a/src/utils/zap/interfaces/IAave.sol b/src/utils/zap/interfaces/IAave.sol index 125ac73e..7dee75b0 100644 --- a/src/utils/zap/interfaces/IAave.sol +++ b/src/utils/zap/interfaces/IAave.sol @@ -2,14 +2,11 @@ pragma solidity 0.8.27; interface IPool { - function flashLoanSimple( address receiverAddress, address asset, uint256 amount, bytes calldata params, uint16 referralCode - ) - external; - + ) external; } diff --git a/src/utils/zap/interfaces/IERC20.sol b/src/utils/zap/interfaces/IERC20.sol index 9e55e7b0..c0bd51d7 100644 --- a/src/utils/zap/interfaces/IERC20.sol +++ b/src/utils/zap/interfaces/IERC20.sol @@ -2,15 +2,11 @@ pragma solidity 0.8.27; interface IERC20 { - function decimals() external view returns (uint8); function balanceOf(address account) external view returns (uint256); - function allowance( - address owner, - address spender - ) + function allowance(address owner, address spender) external view returns (uint256); @@ -19,12 +15,7 @@ interface IERC20 { function approve(address spender, uint256 amount) external returns (bool); - function transferFrom( - address from, - address to, - uint256 amount - ) + function transferFrom(address from, address to, uint256 amount) external returns (bool); - } diff --git a/src/utils/zap/interfaces/ISynthetix.sol b/src/utils/zap/interfaces/ISynthetix.sol index 62d73a4a..757160d4 100644 --- a/src/utils/zap/interfaces/ISynthetix.sol +++ b/src/utils/zap/interfaces/ISynthetix.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.27; interface ISpotMarket { - struct Data { uint256 fixedFees; uint256 utilizationFees; @@ -19,58 +18,40 @@ interface ISpotMarket { uint128 marketId, uint256 wrapAmount, uint256 minAmountReceived - ) - external - returns (uint256 amountToMint, Data memory fees); + ) external returns (uint256 amountToMint, Data memory fees); function unwrap( uint128 marketId, uint256 unwrapAmount, uint256 minAmountReceived - ) - external - returns (uint256 returnCollateralAmount, Data memory fees); + ) external returns (uint256 returnCollateralAmount, Data memory fees); function buy( uint128 marketId, uint256 usdAmount, uint256 minAmountReceived, address referrer - ) - external - returns (uint256 synthAmount, Data memory fees); + ) external returns (uint256 synthAmount, Data memory fees); function sell( uint128 marketId, uint256 synthAmount, uint256 minUsdAmount, address referrer - ) - external - returns (uint256 usdAmountReceived, Data memory fees); - + ) external returns (uint256 usdAmountReceived, Data memory fees); } interface IPerpsMarket { - function modifyCollateral( uint128 accountId, uint128 synthMarketId, int256 amountDelta - ) - external; + ) external; - function renouncePermission( - uint128 accountId, - bytes32 permission - ) + function renouncePermission(uint128 accountId, bytes32 permission) external; - function isAuthorized( - uint128 accountId, - bytes32 permission, - address target - ) + function isAuthorized(uint128 accountId, bytes32 permission, address target) external view returns (bool isAuthorized); @@ -81,5 +62,4 @@ interface IPerpsMarket { external view returns (uint256 accountDebt); - } diff --git a/src/utils/zap/interfaces/IUniswap.sol b/src/utils/zap/interfaces/IUniswap.sol index c4109ece..86ef43d5 100644 --- a/src/utils/zap/interfaces/IUniswap.sol +++ b/src/utils/zap/interfaces/IUniswap.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.27; interface IRouter { - struct ExactInputSingleParams { address tokenIn; address tokenOut; @@ -32,11 +31,9 @@ interface IRouter { external payable returns (uint256 amountIn); - } interface IQuoter { - struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; @@ -70,5 +67,4 @@ interface IQuoter { uint32 initializedTicksCrossed, uint256 gasEstimate ); - } diff --git a/src/utils/zap/utils/Errors.sol b/src/utils/zap/utils/Errors.sol index 989eef46..8d373a13 100644 --- a/src/utils/zap/utils/Errors.sol +++ b/src/utils/zap/utils/Errors.sol @@ -4,7 +4,6 @@ pragma solidity 0.8.27; /// @title zap errors /// @author @jaredborders contract Errors { - /// @notice thrown when a wrap operation fails /// @param reason string for the failure error WrapFailed(string reason); @@ -42,5 +41,4 @@ contract Errors { /// @notice thrown when caller is not Aave pool address /// @param caller address of the msg.sender error OnlyAave(address caller); - } diff --git a/src/utils/zap/utils/Flush.sol b/src/utils/zap/utils/Flush.sol index 46267fb5..0c52b2af 100644 --- a/src/utils/zap/utils/Flush.sol +++ b/src/utils/zap/utils/Flush.sol @@ -6,7 +6,6 @@ import {IERC20} from "../interfaces/IERC20.sol"; /// @title token flushing utility /// @author @jaredborders contract Flush { - /// @custom:plumber address public PLUMBER; @@ -35,5 +34,4 @@ contract Flush { require(msg.sender == PLUMBER, OnlyPlumber()); PLUMBER = _newPlumber; } - } diff --git a/src/utils/zap/utils/Reentrancy.sol b/src/utils/zap/utils/Reentrancy.sol index 504e7284..4250672c 100644 --- a/src/utils/zap/utils/Reentrancy.sol +++ b/src/utils/zap/utils/Reentrancy.sol @@ -5,7 +5,6 @@ pragma solidity 0.8.27; /// @author @moss-eth /// @author @jaredborders contract Reentrancy { - /// @notice enumerated stages of execution /// @dev each stage denotes a different level of protection enum Stage { @@ -35,5 +34,4 @@ contract Reentrancy { ReentrancyDetected({actual: stage, expected: _expected}) ); } - }