Skip to content

Commit

Permalink
feat: add redeemWithPermit to zappers
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed Sep 24, 2023
1 parent 1fee3d7 commit f45b5b5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 420 deletions.
10 changes: 10 additions & 0 deletions contracts/interfaces/zappers/IZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ interface IZapper {
function previewRedeem(uint256 shares) external view returns (uint256 amount);

function redeem(uint256 shares, address receiver, address owner) external returns (uint256 amount);

function redeemWithPermit(
uint256 shares,
address receiver,
address owner,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amount);
}
5 changes: 0 additions & 5 deletions contracts/zappers/WERC20ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ abstract contract WERC20ZapperBase is ZapperBase, IWERC20Zapper {
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 override returns (uint256 amount) {
amount = _redeem(shares, receiver, owner);
}

/// @dev Receives unwrapped token from `msg.sender` and wraps it
function _receiveAndWrap(uint256 amount) internal virtual override returns (uint256 wrappedAmount) {
IERC20(unwrappedToken()).safeTransferFrom(msg.sender, address(this), amount);
Expand Down
5 changes: 0 additions & 5 deletions contracts/zappers/WETHZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ contract WETHZapper is ZapperBase, IWETHZapper {
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 override returns (uint256 amount) {
amount = _redeem(shares, receiver, owner);
}

/// @dev Wraps ETH
function _receiveAndWrap(uint256 amount) internal override returns (uint256 wrappedAmount) {
IWETH(wrappedToken).deposit{value: amount}();
Expand Down
23 changes: 22 additions & 1 deletion contracts/zappers/ZapperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ abstract contract ZapperBase is IZapper {
return _previewUnwrap(assets);
}

/// @notice Zaps redeeming underlying from the pool and unwrapping it into a single operation
/// @dev Requires `owner`'s approval for pool shares to this contract
function redeem(uint256 shares, address receiver, address owner) external override returns (uint256 amount) {
amount = _redeem(shares, receiver, owner);
}

/// @notice Zaps redeeming underlying from the pool and unwrapping it into a single operation
/// @dev `v`, `r`, `s` must be a valid signature of the permit message for pool shares from `owner` to this contract
function redeemWithPermit(
uint256 shares,
address receiver,
address owner,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override returns (uint256 amount) {
try IPoolV3(pool).permit(owner, address(this), shares, deadline, v, r, s) {} catch {}
amount = _redeem(shares, receiver, owner);
}

/// @dev Implementation of deposit zap
/// - Receives `amount` of unwrapped token from `msg.sender` and wraps it
/// - Deposits wrapped token into the pool and mints pool shares to `receiver`
Expand All @@ -68,7 +89,7 @@ abstract contract ZapperBase is IZapper {
}

/// @dev Implementation of redeem zap
/// - Burns `owner`'s pool shares and redeems wrapped token (requires `owner`'s approval)
/// - Burns `owner`'s pool shares and redeems wrapped token
/// - Unwraps redeemed token and sends `amount` of unwrapped token to `receiver`
function _redeem(uint256 shares, address receiver, address owner) internal virtual returns (uint256 amount) {
uint256 assets = IPoolV3(pool).redeem(shares, address(this), owner);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@gearbox-protocol/core-v2": "1.19.0-base.10",
"@gearbox-protocol/core-v3": "^1.36.4",
"@gearbox-protocol/core-v3": "^1.40.0",
"@gearbox-protocol/eslint-config": "^1.6.1",
"@gearbox-protocol/oracles-v3": "^1.7.2",
"@gearbox-protocol/oracles-v3": "^1.7.6",
"@gearbox-protocol/prettier-config": "^1.5.0",
"@gearbox-protocol/sdk-gov": "^1.5.9",
"@gearbox-protocol/sdk-gov": "^1.5.28",
"@openzeppelin/contracts": "4.9.3",
"@redstone-finance/evm-connector": "0.2.5",
"@typechain/ethers-v5": "^10.1.0",
Expand Down
Loading

0 comments on commit f45b5b5

Please sign in to comment.