From 1064fbf7eb0fb80463bcac9565a39a359722cb72 Mon Sep 17 00:00:00 2001 From: domenicodev Date: Wed, 28 Feb 2024 16:32:37 +0100 Subject: [PATCH] feat: Implemented swap --- evm/src/etherfi/EtherfiAdapter.sol | 11 +++++++-- evm/test/EtherfiAdapter.t.sol | 37 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 evm/test/EtherfiAdapter.t.sol diff --git a/evm/src/etherfi/EtherfiAdapter.sol b/evm/src/etherfi/EtherfiAdapter.sol index ee9ba0b..1ac19de 100644 --- a/evm/src/etherfi/EtherfiAdapter.sol +++ b/evm/src/etherfi/EtherfiAdapter.sol @@ -66,6 +66,7 @@ contract EtherfiAdapter is ISwapAdapter { } } + /// @inheritdoc ISwapAdapter function swap( bytes32, IERC20 sellToken, @@ -128,11 +129,17 @@ contract EtherfiAdapter is ISwapAdapter { limits[1] = limits[0]; } - function getCapabilities(bytes32 poolId, IERC20 sellToken, IERC20 buyToken) + /// @inheritdoc ISwapAdapter + function getCapabilities(bytes32, IERC20, IERC20) external + pure + override returns (Capability[] memory capabilities) { - revert NotImplemented("TemplateSwapAdapter.getCapabilities"); + capabilities = new Capability[](3); + capabilities[0] = Capability.SellOrder; + capabilities[1] = Capability.BuyOrder; + capabilities[2] = Capability.PriceFunction; } /// @inheritdoc ISwapAdapter diff --git a/evm/test/EtherfiAdapter.t.sol b/evm/test/EtherfiAdapter.t.sol new file mode 100644 index 0000000..2834ef6 --- /dev/null +++ b/evm/test/EtherfiAdapter.t.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import "openzeppelin-contracts/contracts/interfaces/IERC20.sol"; +import "src/interfaces/ISwapAdapterTypes.sol"; +import "src/libraries/FractionMath.sol"; +import "src/etherfi/EtherfiAdapter.sol"; + +contract EtherfiAdapterTest is Test, ISwapAdapterTypes { + EtherfiAdapter adapter; + IWeEth wEeth = IWeEth(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee); + IeEth eEth; + + function setUp() public { + uint256 forkBlock = 19218495; + vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock); + adapter = new EtherfiAdapter(address(wEeth)); + eEth = wEeth.eETH(); + + vm.label(address(wEeth), "WeETH"); + vm.label(address(eEth), "eETH"); + } + + receive() external payable {} + + function testMe() public { + // // uint256 requiredETH = adapter.getETHRequiredToMintEeth(1 ether); + // deal(address(adapter), 100 ether); + // // adapter.swapEthForEeth(1 ether, OrderSide.Buy); + // IERC20(address(eEth)).approve(address(adapter), type(uint256).max); + + // console.log(IERC20(address(eEth)).balanceOf(address(this))); + // console.log(adapter.swapEthForWeEth(1 ether, OrderSide.Buy)); + // console.log(IERC20(address(eEth)).balanceOf(address(this))); + } +}