Skip to content

Commit

Permalink
Added assets (ETH) to Zapper's Zap event
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed Oct 8, 2024
1 parent 164f6bb commit 75fbb57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/contracts/Interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface IOethARM {
function claimWithdrawals(uint256[] calldata requestIds) external;
}

interface ILiquidityProviderARM {
interface ILiquidityProviderARM is IERC20 {
function previewDeposit(uint256 assets) external returns (uint256 shares);
function deposit(uint256 assets) external returns (uint256 shares);

Expand Down Expand Up @@ -256,7 +256,3 @@ interface IStETHWithdrawal {
function getLastRequestId() external view returns (uint256);
}

interface ILidoARM {
function deposit(uint256 assets) external returns (uint256 shares);
function transfer(address to, uint256 shares) external returns (bool);
}
27 changes: 17 additions & 10 deletions src/contracts/ZapperLidoARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,47 @@ import {Ownable} from "./Ownable.sol";
// Interfaces
import {IWETH} from "./Interfaces.sol";
import {IERC20} from "./Interfaces.sol";
import {ILidoARM} from "./Interfaces.sol";
import {ILiquidityProviderARM} from "./Interfaces.sol";

/**
* @title Zapper contract for the Lido (stETH) Automated Redemption Manager (ARM)
* Converts ETH to WETH and deposits it to the Lido ARM to receive ARM LP shares.
* @author Origin Protocol Inc
*/
contract ZapperLidoARM is Ownable {
IWETH public immutable weth;
ILidoARM public immutable lidoArm;
/// @notice The address of the Lido ARM contract
ILiquidityProviderARM public immutable lidoArm;

event Zap(address indexed sender, uint256 shares);
event Zap(address indexed sender, uint256 assets, uint256 shares);

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

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

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

/// @notice Deposit ETH to LidoARM and receive shares
/// @return shares The amount of ARM LP shares sent to the depositor
function deposit() public payable returns (uint256 shares) {
// Wrap all ETH to WETH
uint256 balance = address(this).balance;
weth.deposit{value: balance}();
uint256 ethBalance = address(this).balance;
weth.deposit{value: ethBalance}();

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

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

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

/// @notice Rescue ERC20 tokens
Expand Down
4 changes: 2 additions & 2 deletions test/fork/Zapper/Deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract Fork_Concrete_ZapperLidoARM_Deposit_Test_ is Fork_Shared_Test_ {
uint256 expectedShares = lidoARM.previewDeposit(DEFAULT_AMOUNT);

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

Expand All @@ -32,7 +32,7 @@ contract Fork_Concrete_ZapperLidoARM_Deposit_Test_ is Fork_Shared_Test_ {
uint256 expectedShares = lidoARM.previewDeposit(DEFAULT_AMOUNT);

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

0 comments on commit 75fbb57

Please sign in to comment.