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

Add Zapper for LidoARM #31

Merged
merged 7 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions src/contracts/Interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,8 @@ interface IStETHWithdrawal {
function getWithdrawalRequests(address _owner) external view returns (uint256[] memory requestsIds);
function getLastRequestId() external view returns (uint256);
}

interface ILidoARM {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a ILiquidityProviderARM interface that already has deposit. We can extend IERC20 so we also get transfer.

function deposit(uint256 assets) external returns (uint256 shares);
function transfer(address to, uint256 shares) external returns (bool);
}
51 changes: 51 additions & 0 deletions src/contracts/ZapperLidoARM.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

// Contracts
import {Ownable} from "./Ownable.sol";

// Interfaces
import {IWETH} from "./Interfaces.sol";
import {IERC20} from "./Interfaces.sol";
import {ILidoARM} from "./Interfaces.sol";

contract ZapperLidoARM is Ownable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the Zapper to be Ownable. I see that is used for rescueERC20 but there shouldn't be any tokens in this contract. I see the OETH Zapper doesn't have this.

If we do want the Zapper to be Ownerable, we need to decide who the owner should be. Options are:

  1. 5/8 multisig
  2. Strategist 2/9 multisig
  3. ARM Defender Relayer
    My preference would be the Strategist

@DanielVF what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree, it was just in case someone mistakenly send token to it (like people sending wETH to wETH contract).
I have no problem removing it.

However if we want to keep it, I think Strategist or Relayer is enough.

IWETH public immutable weth;
ILidoARM public immutable lidoArm;

event Zap(address indexed sender, uint256 shares);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also include the amount of ETH (assets) deposited

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the change to add the amount of assets (WETH) deposited


constructor(address _weth, address _lidoArm) {
weth = IWETH(_weth);
lidoArm = ILidoARM(_lidoArm);

weth.approve(_lidoArm, type(uint256).max);
}

/// @notice Deposit ETH to LidoARM and receive shares
receive() external payable {
deposit();
}

/// @notice Deposit ETH to LidoARM and receive shares
function deposit() public payable returns (uint256 shares) {
// Wrap all ETH to WETH
uint256 balance = address(this).balance;
weth.deposit{value: balance}();

// Deposit all WETH to LidoARM
shares = lidoArm.deposit(balance);

// Transfer received shares to msg.sender
lidoArm.transfer(msg.sender, shares);

// Emit event
emit Zap(msg.sender, shares);
}

/// @notice Rescue ERC20 tokens
/// @param token The address of the ERC20 token
function rescueERC20(address token, uint256 amount) external onlyOwner {
IERC20(token).transfer(msg.sender, amount);
}
}
2 changes: 2 additions & 0 deletions test/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Proxy} from "contracts/Proxy.sol";
import {OethARM} from "contracts/OethARM.sol";
import {LidoARM} from "contracts/LidoARM.sol";
import {CapManager} from "contracts/CapManager.sol";
import {ZapperLidoARM} from "contracts/ZapperLidoARM.sol";

// Interfaces
import {IERC20} from "contracts/Interfaces.sol";
Expand Down Expand Up @@ -37,6 +38,7 @@ abstract contract Base_Test_ is Test {
OethARM public oethARM;
LidoARM public lidoARM;
CapManager public capManager;
ZapperLidoARM public zapperLidoARM;

IERC20 public oeth;
IERC20 public weth;
Expand Down
43 changes: 43 additions & 0 deletions test/fork/Zapper/Deposit.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

// Contracts
import {ZapperLidoARM} from "contracts/ZapperLidoARM.sol";

contract Fork_Concrete_ZapperLidoARM_Deposit_Test_ is Fork_Shared_Test_ {
function setUp() public override {
super.setUp();

vm.deal(address(this), DEFAULT_AMOUNT);
}

function test_Deposit_ViaFunction() public setLiquidityProviderCap(address(zapperLidoARM), DEFAULT_AMOUNT) {
assertEq(lidoARM.balanceOf(address(this)), 0);
uint256 expectedShares = lidoARM.previewDeposit(DEFAULT_AMOUNT);

vm.expectEmit({emitter: address(zapperLidoARM)});
emit ZapperLidoARM.Zap(address(this), expectedShares);
// Deposit
zapperLidoARM.deposit{value: DEFAULT_AMOUNT}();

// Check balance
assertEq(lidoARM.balanceOf(address(this)), DEFAULT_AMOUNT);
}

function test_Deposit_ViaCall() public setLiquidityProviderCap(address(zapperLidoARM), DEFAULT_AMOUNT) {
assertEq(lidoARM.balanceOf(address(this)), 0);
uint256 expectedShares = lidoARM.previewDeposit(DEFAULT_AMOUNT);

vm.expectEmit({emitter: address(zapperLidoARM)});
emit ZapperLidoARM.Zap(address(this), expectedShares);
// Deposit
(bool success,) = address(zapperLidoARM).call{value: DEFAULT_AMOUNT}("");
assertTrue(success);

// Check balance
assertEq(lidoARM.balanceOf(address(this)), DEFAULT_AMOUNT);
}
}
29 changes: 29 additions & 0 deletions test/fork/Zapper/RescueToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

// Contracts
import {ZapperLidoARM} from "contracts/ZapperLidoARM.sol";

contract Fork_Concrete_ZapperLidoARM_RescueToken_Test_ is Fork_Shared_Test_ {
function test_RevertWhen_RescueToken_CalledByNonOwner() public asRandomAddress {
vm.expectRevert("ARM: Only owner can call this function.");
zapperLidoARM.rescueERC20(address(badToken), DEFAULT_AMOUNT);
}

function test_RescueToken() public {
deal(address(weth), address(zapperLidoARM), DEFAULT_AMOUNT);
assertEq(weth.balanceOf(address(zapperLidoARM)), DEFAULT_AMOUNT);
assertEq(weth.balanceOf(address(this)), 0);

// Rescue the tokens
vm.prank(zapperLidoARM.owner());
zapperLidoARM.rescueERC20(address(weth), DEFAULT_AMOUNT);

// Check balance
assertEq(weth.balanceOf(address(zapperLidoARM)), 0);
assertEq(weth.balanceOf(address(this)), DEFAULT_AMOUNT);
}
}
5 changes: 5 additions & 0 deletions test/fork/shared/Shared.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Proxy} from "contracts/Proxy.sol";
import {OethARM} from "contracts/OethARM.sol";
import {LidoARM} from "contracts/LidoARM.sol";
import {CapManager} from "contracts/CapManager.sol";
import {ZapperLidoARM} from "contracts/ZapperLidoARM.sol";

// Interfaces
import {IERC20} from "contracts/Interfaces.sol";
Expand Down Expand Up @@ -165,6 +166,9 @@ abstract contract Fork_Shared_Test_ is Modifiers {

// set prices
lidoARM.setPrices(992 * 1e33, 1001 * 1e33);

// --- Deploy ZapperLidoARM ---
zapperLidoARM = new ZapperLidoARM(address(weth), address(lidoProxy));
}

function _label() internal {
Expand All @@ -178,6 +182,7 @@ abstract contract Fork_Shared_Test_ is Modifiers {
vm.label(address(lidoARM), "LIDO ARM");
vm.label(address(lidoProxy), "LIDO ARM PROXY");
vm.label(address(capManager), "LIQUIDITY PROVIDER CONTROLLER");
vm.label(address(zapperLidoARM), "ZAPPER LIDO ARM");
vm.label(operator, "OPERATOR");
vm.label(oethWhale, "WHALE OETH");
vm.label(governor, "GOVERNOR");
Expand Down