Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix function name #53

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions contracts/interfaces/zappers/IWERC20Zapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

import {IZapper} from "./IZapper.sol";

interface IWERC20Zapper is IZapper {
function deposit(uint256 amount, address receiver) external returns (uint256 shares);

function depositWithReferral(uint256 amount, address receiver, uint16 referralCode)
external
returns (uint256 shares);
}
15 changes: 15 additions & 0 deletions contracts/interfaces/zappers/IWETHZapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

import {IZapper} from "./IZapper.sol";

/// @dev Special address that denotes pure ETH
address constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

interface IWETHZapper is IZapper {
function deposit(address receiver) external payable returns (uint256 shares);

function depositWithReferral(address receiver, uint16 referralCode) external payable returns (uint256 shares);
}
18 changes: 18 additions & 0 deletions contracts/interfaces/zappers/IZapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

interface IZapper {
function pool() external view returns (address);

function unwrappedToken() external view returns (address);

function wrappedToken() external view returns (address);

function previewDeposit(uint256 amount) external view returns (uint256 shares);

function previewRedeem(uint256 shares) external view returns (uint256 amount);

function redeem(uint256 shares, address receiver, address owner) external returns (uint256 amount);
}
12 changes: 7 additions & 5 deletions contracts/zappers/WERC20ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.17;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol";

import {IWERC20Zapper} from "../interfaces/zappers/IWERC20Zapper.sol";
import {ZapperBase} from "./ZapperBase.sol";

/// @title wERC20 zapper base
Expand All @@ -14,31 +15,32 @@ import {ZapperBase} from "./ZapperBase.sol";
/// @dev Default implementation assumes that unwrapped token has no transfer fees
/// @dev Derived zappers must call `_resetWrapperAllowance` in their constructor after
/// initializing `unwrappedToken()`
abstract contract WERC20ZapperBase is ZapperBase {
abstract contract WERC20ZapperBase is ZapperBase, IWERC20Zapper {
using SafeERC20 for IERC20;

/// @notice Constructor
/// @param pool_ Pool to connect this zapper to
constructor(address pool_) ZapperBase(pool_) {}

/// @dev Returns uwnrapped token, must be overriden by derived zappers
function unwrappedToken() public view virtual returns (address);
function unwrappedToken() public view virtual override returns (address);

/// @notice Zaps wrapping a token and depositing it to the pool into a single operation
function deposit(uint256 amount, address receiver) external returns (uint256 shares) {
function deposit(uint256 amount, address receiver) external override returns (uint256 shares) {
shares = _deposit(amount, receiver);
}

/// @notice Same as `deposit` but allows to specify the referral code
function depositWithUnderlying(uint256 amount, address receiver, uint16 referralCode)
function depositWithReferral(uint256 amount, address receiver, uint16 referralCode)
external
override
returns (uint256 shares)
{
shares = _depositWithReferral(amount, receiver, referralCode);
}

/// @notice Zaps redeeming token from the pool and unwrapping it into a single operation
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 amount) {
function redeem(uint256 shares, address receiver, address owner) external override returns (uint256 amount) {
amount = _redeem(shares, receiver, owner);
}

Expand Down
17 changes: 13 additions & 4 deletions contracts/zappers/WETHZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {IWETH} from "@gearbox-protocol/core-v2/contracts/interfaces/external/IWETH.sol";
import {ReceiveIsNotAllowedException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";

import {IWETHZapper, ETH_ADDRESS} from "../interfaces/zappers/IWETHZapper.sol";
import {ZapperBase} from "./ZapperBase.sol";

/// @title WETH zapper
/// @notice Allows users to deposit/withdraw pure ETH to/from a WETH pool in a single operation
contract WETHZapper is ZapperBase {
contract WETHZapper is ZapperBase, IWETHZapper {
using Address for address payable;

/// @notice Special address that corresponds to pure ETH
address public constant override unwrappedToken = ETH_ADDRESS;

/// @notice Constructor
/// @param pool_ Pool to connect this zapper to
constructor(address pool_) ZapperBase(pool_) {}
Expand All @@ -25,17 +29,22 @@ contract WETHZapper is ZapperBase {
}

/// @notice Zaps wrapping ETH and depositing it to the pool into a single operation
function deposit(address receiver) external payable returns (uint256 shares) {
function deposit(address receiver) external payable override returns (uint256 shares) {
shares = _deposit(msg.value, receiver);
}

/// @notice Same as `deposit` but allows to specify the referral code
function depositWithReferral(address receiver, uint16 referralCode) external payable returns (uint256 shares) {
function depositWithReferral(address receiver, uint16 referralCode)
external
payable
override
returns (uint256 shares)
{
shares = _depositWithReferral(msg.value, receiver, referralCode);
}

/// @notice Zaps redeeming WETH from the pool and unwrapping it into a single operation
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 amount) {
function redeem(uint256 shares, address receiver, address owner) external override returns (uint256 amount) {
amount = _redeem(shares, receiver, owner);
}

Expand Down
12 changes: 7 additions & 5 deletions contracts/zappers/ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import {SafeERC20} from "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol

import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";

import {IZapper} from "../interfaces/zappers/IZapper.sol";

/// @title Zapper base
/// @notice Base contract for zappers allowing users to deposit/withdraw an unwrapped token
/// to/from a Gearbox pool with wrapped token as underlying in a single operation
abstract contract ZapperBase {
abstract contract ZapperBase is IZapper {
using SafeERC20 for IERC20;

/// @notice Pool this zapper is connected to
address public immutable pool;
address public immutable override pool;
/// @notice Underlying token of the pool
address public immutable wrappedToken;
address public immutable override wrappedToken;

/// @notice Constructor
/// @param pool_ Pool to connect this zapper to
Expand All @@ -28,13 +30,13 @@ abstract contract ZapperBase {
}

/// @notice Returns number of pool shares one would receive for depositing `amount` of unwrapped token
function previewDeposit(uint256 amount) external view returns (uint256 shares) {
function previewDeposit(uint256 amount) external view override returns (uint256 shares) {
uint256 assets = _previewWrap(amount);
return IPoolV3(pool).previewDeposit(assets);
}

/// @notice Returns amount of unwrapped token one would receive for redeeming `shares` of pool shares
function previewRedeem(uint256 shares) external view returns (uint256 amount) {
function previewRedeem(uint256 shares) external view override returns (uint256 amount) {
uint256 assets = IPoolV3(pool).previewRedeem(shares);
return _previewUnwrap(assets);
}
Expand Down
Loading