Skip to content

Commit

Permalink
✨ prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Oct 10, 2024
1 parent 69e95e2 commit 441af23
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 160 deletions.
131 changes: 23 additions & 108 deletions src/utils/zap/Zap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -749,22 +680,15 @@ 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);
}

/// @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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -839,5 +755,4 @@ contract Zap is Reentrancy, Errors {
revert PushFailed(bytes(reason));
}
}

}
5 changes: 1 addition & 4 deletions src/utils/zap/interfaces/IAave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 2 additions & 11 deletions src/utils/zap/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

}
Loading

0 comments on commit 441af23

Please sign in to comment.