Skip to content

Commit

Permalink
Merge pull request #54 from Gearbox-protocol/fix--zapper-weth-fix
Browse files Browse the repository at this point in the history
feat(zappers): `tokenOut` + approval fix
  • Loading branch information
0xmikko authored Sep 19, 2023
2 parents dc6420e + 5b70b95 commit 1fee3d7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
2 changes: 2 additions & 0 deletions contracts/interfaces/zappers/IZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.8.17;
interface IZapper {
function pool() external view returns (address);

function tokenOut() external view returns (address);

function unwrappedToken() external view returns (address);

function wrappedToken() external view returns (address);
Expand Down
44 changes: 44 additions & 0 deletions contracts/test/live/zappers/ZapperPlay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: UNLICENSED
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {WETHZapper} from "../../../zappers/WETHZapper.sol";
import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
import "@gearbox-protocol/core-v3/contracts/test/lib/constants.sol";

import {Test} from "forge-std/Test.sol";
import "forge-std/console.sol";

address constant ap = 0x0Bf1626d4925F8A872801968be11c052862AC2D3;

contract ZapperTest is Test {
uint256 chainId;
WETHZapper wethZapper;

address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

constructor() {
NetworkDetector nd = new NetworkDetector();
chainId = nd.chainId();
}

modifier liveTestOnly() {
if (chainId == 1) {
_;
}
}

function setUp() public liveTestOnly {
wethZapper = new WETHZapper(0x9357C9b42b9a555fCcF94cA5C702d72782865B71);
}

function test_weth_zapper() public liveTestOnly {
console.log("Allowance", IERC20(weth).allowance(address(wethZapper), wethZapper.pool()));
vm.prank(USER);
wethZapper.deposit{value: 10 ether}(USER);
}
}
2 changes: 1 addition & 1 deletion contracts/zappers/WATokenZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract WATokenZapper is WERC20ZapperBase {
/// @param pool_ Pool to connect this zapper to
constructor(address pool_) WERC20ZapperBase(pool_) {
_aToken = WrappedAToken(wrappedToken).aToken();
_resetWrapperAllowance();
super._resetWrapperAllowance();
}

/// @notice aToken address
Expand Down
4 changes: 2 additions & 2 deletions contracts/zappers/WERC20ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {ZapperBase} from "./ZapperBase.sol";
/// @notice Base contract for zappers allowing users to deposit/withdraw an ERC20 token
/// to/from a Gearbox pool with its wrapper as underlying in a single operation
/// @dev Default implementation assumes that unwrapped token has no transfer fees
/// @dev Derived zappers must call `_resetWrapperAllowance` in their constructor after
/// initializing `unwrappedToken()`
/// @dev Derived zappers must call `super._resetWrapperAllowance()` in their constructor
/// after initializing `unwrappedToken()`
abstract contract WERC20ZapperBase is ZapperBase, IWERC20Zapper {
using SafeERC20 for IERC20;

Expand Down
2 changes: 1 addition & 1 deletion contracts/zappers/WstETHZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract WstETHZapper is WERC20ZapperBase {
/// @param pool_ Pool to connect this zapper to
constructor(address pool_) WERC20ZapperBase(pool_) {
_stETH = IwstETH(wrappedToken).stETH();
_resetWrapperAllowance();
super._resetWrapperAllowance();
}

/// @notice stETH address
Expand Down
8 changes: 7 additions & 1 deletion contracts/zappers/ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract contract ZapperBase is IZapper {

/// @notice Pool this zapper is connected to
address public immutable override pool;

/// @notice Underlying token of the pool
address public immutable override wrappedToken;

Expand All @@ -26,7 +27,12 @@ abstract contract ZapperBase is IZapper {
constructor(address pool_) {
pool = pool_;
wrappedToken = IPoolV3(pool_).asset();
_resetPoolAllowance();
ZapperBase._resetPoolAllowance();
}

/// @notice Token that this zapper produces (might differ from the pool share token)
function tokenOut() public view virtual override returns (address) {
return pool;
}

/// @notice Returns number of pool shares one would receive for depositing `amount` of unwrapped token
Expand Down

0 comments on commit 1fee3d7

Please sign in to comment.