diff --git a/contracts/interfaces/zappers/IZapper.sol b/contracts/interfaces/zappers/IZapper.sol index 9cd60b87..85c62948 100644 --- a/contracts/interfaces/zappers/IZapper.sol +++ b/contracts/interfaces/zappers/IZapper.sol @@ -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); diff --git a/contracts/test/live/zappers/ZapperPlay.sol b/contracts/test/live/zappers/ZapperPlay.sol new file mode 100644 index 00000000..137d61dc --- /dev/null +++ b/contracts/test/live/zappers/ZapperPlay.sol @@ -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); + } +} diff --git a/contracts/zappers/WATokenZapper.sol b/contracts/zappers/WATokenZapper.sol index 48c461cd..6a473ceb 100644 --- a/contracts/zappers/WATokenZapper.sol +++ b/contracts/zappers/WATokenZapper.sol @@ -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 diff --git a/contracts/zappers/WERC20ZapperBase.sol b/contracts/zappers/WERC20ZapperBase.sol index 9c5ade05..84cf4ad7 100644 --- a/contracts/zappers/WERC20ZapperBase.sol +++ b/contracts/zappers/WERC20ZapperBase.sol @@ -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; diff --git a/contracts/zappers/WstETHZapper.sol b/contracts/zappers/WstETHZapper.sol index bebf0acd..3434b014 100644 --- a/contracts/zappers/WstETHZapper.sol +++ b/contracts/zappers/WstETHZapper.sol @@ -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 diff --git a/contracts/zappers/ZapperBase.sol b/contracts/zappers/ZapperBase.sol index a7e69bbc..e3587603 100644 --- a/contracts/zappers/ZapperBase.sol +++ b/contracts/zappers/ZapperBase.sol @@ -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; @@ -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 diff --git a/lib/forge-std b/lib/forge-std index 2b58ecbc..e8a047e3 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 2b58ecbcf3dfde7a75959dc7b4eb3d0670278de6 +Subproject commit e8a047e3f40f13fa37af6fe14e6e06283d9a060e