From 76bc1f58ac84f6060e1a876703cedc58ff789ab5 Mon Sep 17 00:00:00 2001 From: domenicodev Date: Tue, 27 Feb 2024 11:40:56 +0100 Subject: [PATCH] feat: Initial Setup --- evm/src/etherfi/EtherfiAdapter.sol | 122 +++++++++++++++++++++++++++++ evm/src/etherfi/manifest.yaml | 36 +++++++++ 2 files changed, 158 insertions(+) create mode 100644 evm/src/etherfi/EtherfiAdapter.sol create mode 100644 evm/src/etherfi/manifest.yaml diff --git a/evm/src/etherfi/EtherfiAdapter.sol b/evm/src/etherfi/EtherfiAdapter.sol new file mode 100644 index 0000000..d2c6c4f --- /dev/null +++ b/evm/src/etherfi/EtherfiAdapter.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +pragma experimental ABIEncoderV2; +pragma solidity ^0.8.13; + +import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol"; + +/// @title Etherfi Adapter +/// @dev This contract supports the following swaps: eETH<->ETH, wETH<->eETH, wETH<->ETH +contract EtherfiAdapter is ISwapAdapter { + + IWeEth wEeth; + IeEth eEth; + ILiquidityPool liquidityPool; + + constructor(address _wEeth) { + wEeth = IWeEth(_wEeth); + eEth = wEeth.eETH(); + liquidityPool = eEth.liquidityPool(); + } + + /// @dev Check if tokens in input are supported by this adapter + modifier checkInputTokens(address sellToken, address buyToken) { + if(sellToken == buyToken) { + revert Unavailable("This pool only supports eETH, weEth and ETH"); + } + if(sellToken != address(wEeth) && sellToken != address(eEth) && sellToken && sellToken != address(0)) { + revert Unavailable("This pool only supports eETH, weEth and ETH"); + } + if(buyToken != address(wEeth) && buyToken != address(eEth) && buyToken != address(0)) { + revert Unavailable("This pool only supports eETH, weEth and ETH"); + } + _; + } + + function price( + bytes32 _poolId, + IERC20 _sellToken, + IERC20 _buyToken, + uint256[] memory _specifiedAmounts + ) external view override returns (Fraction[] memory _prices) { + revert NotImplemented("TemplateSwapAdapter.price"); + } + + function swap( + bytes32 poolId, + IERC20 sellToken, + IERC20 buyToken, + OrderSide side, + uint256 specifiedAmount + ) external returns (Trade memory trade) { + revert NotImplemented("TemplateSwapAdapter.swap"); + } + + function getLimits(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) + external + returns (uint256[] memory limits) + { + revert NotImplemented("TemplateSwapAdapter.getLimits"); + } + + function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) + external + returns (Capability[] memory capabilities) + { + revert NotImplemented("TemplateSwapAdapter.getCapabilities"); + } + + function getTokens(bytes32 poolId) + external + returns (IERC20[] memory tokens) + { + revert NotImplemented("TemplateSwapAdapter.getTokens"); + } + + function getPoolIds(uint256 offset, uint256 limit) + external + returns (bytes32[] memory ids) + { + revert NotImplemented("TemplateSwapAdapter.getPoolIds"); + } +} + +interface ILiquidityPool { + + function numPendingDeposits() external view returns (uint32); + function totalValueOutOfLp() external view returns (uint128); + function totalValueInLp() external view returns (uint128); + function getTotalEtherClaimOf(address _user) external view returns (uint256); + function getTotalPooledEther() external view returns (uint256); + function sharesForAmount(uint256 _amount) external view returns (uint256); + function sharesForWithdrawalAmount(uint256 _amount) external view returns (uint256); + function amountForShare(uint256 _share) external view returns (uint256); + + function deposit() external payable returns (uint256); + function deposit(address _referral) external payable returns (uint256); + function deposit(address _user, address _referral) external payable returns (uint256); + +} + +interface IeEth { + + function liquidityPool() external view returns (ILiquidityPool); + + function totalShares() external view returns (uint256); + + function shares(address _user) external view returns (uint256); + +} + +interface IWeEth { + + function eETH() external view returns (IeEth); + + function getWeETHByeETH(uint256 _eETHAmount) external view returns (uint256); + + function getEETHByWeETH(uint256 _weETHAmount) external view returns (uint256); + + function wrap(uint256 _eETHAmount) external returns (uint256); + + function unwrap(uint256 _weETHAmount) external returns (uint256); + +} diff --git a/evm/src/etherfi/manifest.yaml b/evm/src/etherfi/manifest.yaml new file mode 100644 index 0000000..c6cb262 --- /dev/null +++ b/evm/src/etherfi/manifest.yaml @@ -0,0 +1,36 @@ +# information about the author helps us reach out in case of issues. +author: + name: Propellerheads.xyz + email: alan@propellerheads.xyz + +# Protocol Constants +constants: + protocol_gas: 30000 + # minimum capabilities we can expect, individual pools may extend these + capabilities: + - SellSide + - BuySide + - PriceFunction + +# The file containing the adapter contract +contract: EtherfiAdapter.sol + +# Deployment instances used to generate chain specific bytecode. +instances: + - chain: + name: mainnet + id: 0 + arguments: + - "0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee" + +# Specify some automatic test cases in case getPoolIds and +# getTokens are not implemented. +tests: + instances: + - pool_id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" + sell_token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" + buy_token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" + block: 17000000 + chain: + id: 0 + name: mainnet