fix: Fixed getLimits and improved swap
This commit is contained in:
@@ -121,9 +121,13 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
{
|
{
|
||||||
limits = new uint256[](2);
|
limits = new uint256[](2);
|
||||||
|
|
||||||
/// @dev only limit on Etherfi is applied on deposits(eth->eETH), and is type(uint128).max
|
/// @dev Limits are underestimated to 90% of totalSupply as both weEth and eEth have no limits but revert in some cases
|
||||||
/// but we use the same amount for the others to underestimate
|
if(address(sellToken) == address(weEth) || address(buyToken) == address(weEth)) {
|
||||||
limits[0] = IERC20(address(eEth)).totalSupply();
|
limits[0] = IERC20(address(weEth)).totalSupply() * 90 / 100;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
limits[0] = IERC20(address(eEth)).totalSupply() * 90 / 100;
|
||||||
|
}
|
||||||
limits[1] = limits[0];
|
limits[1] = limits[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,13 +198,13 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
internal
|
internal
|
||||||
returns (uint256)
|
returns (uint256)
|
||||||
{
|
{
|
||||||
|
IERC20 eEth_ = IERC20(address(eEth));
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
IERC20(address(eEth)).safeTransferFrom(msg.sender, address(this), amount);
|
|
||||||
uint256 amountIn = getAmountIn(address(0), address(weEth), amount);
|
uint256 amountIn = getAmountIn(address(0), address(weEth), amount);
|
||||||
IERC20(address(eEth)).approve(address(weEth), amountIn);
|
|
||||||
|
|
||||||
uint256 receivedAmountEeth =
|
uint256 receivedAmountEeth =
|
||||||
liquidityPool.deposit{value: amountIn}();
|
liquidityPool.deposit{value: amountIn}();
|
||||||
|
eEth_.approve(address(weEth), receivedAmountEeth);
|
||||||
uint256 receivedAmount = weEth.wrap(receivedAmountEeth);
|
uint256 receivedAmount = weEth.wrap(receivedAmountEeth);
|
||||||
|
|
||||||
IERC20(address(weEth)).safeTransfer(
|
IERC20(address(weEth)).safeTransfer(
|
||||||
@@ -209,10 +213,8 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
|
|
||||||
return amountIn;
|
return amountIn;
|
||||||
} else {
|
} else {
|
||||||
IERC20(address(eEth)).safeTransferFrom(msg.sender, address(this), amount);
|
|
||||||
IERC20(address(eEth)).approve(address(weEth), amount);
|
|
||||||
|
|
||||||
uint256 receivedAmountEeth = liquidityPool.deposit{value: amount}();
|
uint256 receivedAmountEeth = liquidityPool.deposit{value: amount}();
|
||||||
|
eEth_.approve(address(weEth), receivedAmountEeth);
|
||||||
uint256 receivedAmount = weEth.wrap(receivedAmountEeth);
|
uint256 receivedAmount = weEth.wrap(receivedAmountEeth);
|
||||||
|
|
||||||
IERC20(address(weEth)).safeTransfer(
|
IERC20(address(weEth)).safeTransfer(
|
||||||
|
|||||||
Reference in New Issue
Block a user