Fix merge issues
This commit is contained in:
@@ -2,9 +2,12 @@
|
|||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
pragma solidity ^0.8.13;
|
pragma solidity ^0.8.13;
|
||||||
|
|
||||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
import {ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||||
|
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
||||||
import {IERC20Metadata} from
|
import {IERC20Metadata} from
|
||||||
"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
||||||
|
import {SafeERC20} from
|
||||||
|
"openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||||
|
|
||||||
/// @dev custom reserve limit factor to prevent revert errors in OrderSide.Buy
|
/// @dev custom reserve limit factor to prevent revert errors in OrderSide.Buy
|
||||||
uint256 constant RESERVE_LIMIT_FACTOR = 10;
|
uint256 constant RESERVE_LIMIT_FACTOR = 10;
|
||||||
@@ -16,6 +19,8 @@ uint256 constant STANDARD_TOKEN_DECIMALS = 10 ** 18;
|
|||||||
/// collateral, it will, because agEUR is minted, and this mechanism is used to
|
/// collateral, it will, because agEUR is minted, and this mechanism is used to
|
||||||
/// stabilize the agEUR price.
|
/// stabilize the agEUR price.
|
||||||
contract AngleAdapter is ISwapAdapter {
|
contract AngleAdapter is ISwapAdapter {
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
ITransmuter immutable transmuter;
|
ITransmuter immutable transmuter;
|
||||||
|
|
||||||
constructor(ITransmuter _transmuter) {
|
constructor(ITransmuter _transmuter) {
|
||||||
@@ -30,7 +35,7 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
* architecture of Angle, it's not possible to calculate the storage
|
* architecture of Angle, it's not possible to calculate the storage
|
||||||
* modifications of Angle inside the adapter.
|
* modifications of Angle inside the adapter.
|
||||||
*/
|
*/
|
||||||
function price(bytes32, IERC20, IERC20, uint256[] memory)
|
function price(bytes32, address, address, uint256[] memory)
|
||||||
external
|
external
|
||||||
pure
|
pure
|
||||||
override
|
override
|
||||||
@@ -48,8 +53,8 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
*/
|
*/
|
||||||
function swap(
|
function swap(
|
||||||
bytes32,
|
bytes32,
|
||||||
IERC20 sellToken,
|
address sellToken,
|
||||||
IERC20 buyToken,
|
address buyToken,
|
||||||
OrderSide side,
|
OrderSide side,
|
||||||
uint256 specifiedAmount
|
uint256 specifiedAmount
|
||||||
) external returns (Trade memory trade) {
|
) external returns (Trade memory trade) {
|
||||||
@@ -65,10 +70,10 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
}
|
}
|
||||||
trade.gasUsed = gasBefore - gasleft();
|
trade.gasUsed = gasBefore - gasleft();
|
||||||
uint8 decimals = side == OrderSide.Sell
|
uint8 decimals = side == OrderSide.Sell
|
||||||
? IERC20Metadata(address(sellToken)).decimals()
|
? IERC20Metadata(sellToken).decimals()
|
||||||
: IERC20Metadata(address(buyToken)).decimals();
|
: IERC20Metadata(buyToken).decimals();
|
||||||
trade.price =
|
trade.price =
|
||||||
getPriceAt(address(sellToken), address(buyToken), side, decimals);
|
getPriceAt(sellToken, buyToken, side, decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
@@ -79,50 +84,48 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
/// contract size, with an high complexity. In addition, we underestimate to
|
/// contract size, with an high complexity. In addition, we underestimate to
|
||||||
/// RESERVE_LIMIT_FACTOR to ensure swaps with OrderSide.Buy won't fail
|
/// RESERVE_LIMIT_FACTOR to ensure swaps with OrderSide.Buy won't fail
|
||||||
/// anyway.
|
/// anyway.
|
||||||
function getLimits(bytes32, IERC20 sellToken, IERC20 buyToken)
|
function getLimits(bytes32, address sellToken, address buyToken)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
returns (uint256[] memory limits)
|
returns (uint256[] memory limits)
|
||||||
{
|
{
|
||||||
limits = new uint256[](2);
|
limits = new uint256[](2);
|
||||||
address sellTokenAddress = address(sellToken);
|
|
||||||
address buyTokenAddress = address(buyToken);
|
|
||||||
address transmuterAddress = address(transmuter);
|
address transmuterAddress = address(transmuter);
|
||||||
|
|
||||||
if (buyTokenAddress == transmuter.agToken()) {
|
if (buyToken == transmuter.agToken()) {
|
||||||
// mint(buy agToken)
|
// mint(buy agToken)
|
||||||
Collateral memory collatInfo =
|
Collateral memory collatInfo =
|
||||||
transmuter.getCollateralInfo(sellTokenAddress);
|
transmuter.getCollateralInfo(sellToken);
|
||||||
if (collatInfo.isManaged > 0) {
|
if (collatInfo.isManaged > 0) {
|
||||||
limits[0] =
|
limits[0] =
|
||||||
LibManager.maxAvailable(collatInfo.managerData.config);
|
LibManager.maxAvailable(collatInfo.managerData.config);
|
||||||
} else {
|
} else {
|
||||||
limits[0] = sellToken.balanceOf(transmuterAddress);
|
limits[0] = IERC20(sellToken).balanceOf(transmuterAddress);
|
||||||
}
|
}
|
||||||
limits[1] =
|
limits[1] =
|
||||||
transmuter.quoteIn(limits[0], sellTokenAddress, buyTokenAddress);
|
transmuter.quoteIn(limits[0], sellToken, buyToken);
|
||||||
limits[1] = limits[1] / RESERVE_LIMIT_FACTOR;
|
limits[1] = limits[1] / RESERVE_LIMIT_FACTOR;
|
||||||
limits[0] = limits[0] / RESERVE_LIMIT_FACTOR;
|
limits[0] = limits[0] / RESERVE_LIMIT_FACTOR;
|
||||||
} else {
|
} else {
|
||||||
// burn(sell agToken)
|
// burn(sell agToken)
|
||||||
Collateral memory collatInfo =
|
Collateral memory collatInfo =
|
||||||
transmuter.getCollateralInfo(buyTokenAddress);
|
transmuter.getCollateralInfo(buyToken);
|
||||||
if (collatInfo.isManaged > 0) {
|
if (collatInfo.isManaged > 0) {
|
||||||
limits[1] =
|
limits[1] =
|
||||||
LibManager.maxAvailable(collatInfo.managerData.config);
|
LibManager.maxAvailable(collatInfo.managerData.config);
|
||||||
} else {
|
} else {
|
||||||
limits[1] = buyToken.balanceOf(transmuterAddress);
|
limits[1] = IERC20(buyToken).balanceOf(transmuterAddress);
|
||||||
}
|
}
|
||||||
limits[0] =
|
limits[0] =
|
||||||
transmuter.quoteIn(limits[1], buyTokenAddress, sellTokenAddress);
|
transmuter.quoteIn(limits[1], buyToken, sellToken);
|
||||||
limits[1] = limits[1] / RESERVE_LIMIT_FACTOR;
|
limits[1] = limits[1] / RESERVE_LIMIT_FACTOR;
|
||||||
limits[0] = limits[0] / RESERVE_LIMIT_FACTOR;
|
limits[0] = limits[0] / RESERVE_LIMIT_FACTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
function getCapabilities(bytes32, IERC20, IERC20)
|
function getCapabilities(bytes32, address, address)
|
||||||
external
|
external
|
||||||
pure
|
pure
|
||||||
override
|
override
|
||||||
@@ -141,14 +144,14 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
external
|
external
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
returns (IERC20[] memory tokens)
|
returns (address[] memory tokens)
|
||||||
{
|
{
|
||||||
address[] memory collateralsAddresses = transmuter.getCollateralList();
|
address[] memory collateralsAddresses = transmuter.getCollateralList();
|
||||||
tokens = new IERC20[](collateralsAddresses.length + 1);
|
tokens = new address[](collateralsAddresses.length + 1);
|
||||||
for (uint256 i = 0; i < collateralsAddresses.length; i++) {
|
for (uint256 i = 0; i < collateralsAddresses.length; i++) {
|
||||||
tokens[i] = IERC20(collateralsAddresses[i]);
|
tokens[i] = address(collateralsAddresses[i]);
|
||||||
}
|
}
|
||||||
tokens[collateralsAddresses.length] = IERC20(transmuter.agToken());
|
tokens[collateralsAddresses.length] = transmuter.agToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPoolIds(uint256, uint256)
|
function getPoolIds(uint256, uint256)
|
||||||
@@ -189,17 +192,14 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
/// @param buyToken The token being bought.
|
/// @param buyToken The token being bought.
|
||||||
/// @param amount The amount to be traded.
|
/// @param amount The amount to be traded.
|
||||||
/// @return calculatedAmount The amount of tokens received.
|
/// @return calculatedAmount The amount of tokens received.
|
||||||
function sell(IERC20 sellToken, IERC20 buyToken, uint256 amount)
|
function sell(address sellToken, address buyToken, uint256 amount)
|
||||||
internal
|
internal
|
||||||
returns (uint256 calculatedAmount)
|
returns (uint256 calculatedAmount)
|
||||||
{
|
{
|
||||||
address sellTokenAddress = address(sellToken);
|
IERC20(sellToken).safeTransferFrom(msg.sender, address(this), amount);
|
||||||
address buyTokenAddress = address(buyToken);
|
IERC20(sellToken).approve(address(transmuter), amount);
|
||||||
|
|
||||||
sellToken.transferFrom(msg.sender, address(this), amount);
|
|
||||||
sellToken.approve(address(transmuter), amount);
|
|
||||||
calculatedAmount = transmuter.swapExactInput(
|
calculatedAmount = transmuter.swapExactInput(
|
||||||
amount, 0, sellTokenAddress, buyTokenAddress, msg.sender, 0
|
amount, 0, sellToken, buyToken, msg.sender, 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,22 +208,20 @@ contract AngleAdapter is ISwapAdapter {
|
|||||||
/// @param buyToken The token being bought.
|
/// @param buyToken The token being bought.
|
||||||
/// @param amountOut The amount of buyToken to receive.
|
/// @param amountOut The amount of buyToken to receive.
|
||||||
/// @return calculatedAmount The amount of tokens received.
|
/// @return calculatedAmount The amount of tokens received.
|
||||||
function buy(IERC20 sellToken, IERC20 buyToken, uint256 amountOut)
|
function buy(address sellToken, address buyToken, uint256 amountOut)
|
||||||
internal
|
internal
|
||||||
returns (uint256 calculatedAmount)
|
returns (uint256 calculatedAmount)
|
||||||
{
|
{
|
||||||
address sellTokenAddress = address(sellToken);
|
|
||||||
address buyTokenAddress = address(buyToken);
|
|
||||||
calculatedAmount =
|
calculatedAmount =
|
||||||
transmuter.quoteOut(amountOut, sellTokenAddress, buyTokenAddress);
|
transmuter.quoteOut(amountOut, sellToken, buyToken);
|
||||||
|
|
||||||
sellToken.transferFrom(msg.sender, address(this), calculatedAmount);
|
IERC20(sellToken).safeTransferFrom(msg.sender, address(this), calculatedAmount);
|
||||||
sellToken.approve(address(transmuter), calculatedAmount);
|
IERC20(sellToken).approve(address(transmuter), calculatedAmount);
|
||||||
transmuter.swapExactOutput(
|
transmuter.swapExactOutput(
|
||||||
amountOut,
|
amountOut,
|
||||||
type(uint256).max,
|
type(uint256).max,
|
||||||
sellTokenAddress,
|
sellToken,
|
||||||
buyTokenAddress,
|
buyToken,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
pragma solidity ^0.8.13;
|
pragma solidity ^0.8.13;
|
||||||
|
|
||||||
import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
import {ISwapAdapter} from "src/interfaces/ISwapAdapter.sol";
|
||||||
|
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
||||||
import {SafeERC20} from
|
import {SafeERC20} from
|
||||||
"openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
|
"openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||||
|
|
||||||
@@ -54,39 +55,37 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
function price(
|
function price(
|
||||||
bytes32,
|
bytes32,
|
||||||
IERC20 _sellToken,
|
address sellToken,
|
||||||
IERC20 _buyToken,
|
address buyToken,
|
||||||
uint256[] memory _specifiedAmounts
|
uint256[] memory specifiedAmounts
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
checkInputTokens(address(_sellToken), address(_buyToken))
|
checkInputTokens(sellToken, buyToken)
|
||||||
returns (Fraction[] memory _prices)
|
returns (Fraction[] memory prices)
|
||||||
{
|
{
|
||||||
_prices = new Fraction[](_specifiedAmounts.length);
|
prices = new Fraction[](specifiedAmounts.length);
|
||||||
address sellTokenAddress = address(_sellToken);
|
|
||||||
address buyTokenAddress = address(_buyToken);
|
|
||||||
uint256 totalPooledEther = liquidityPool.getTotalPooledEther();
|
uint256 totalPooledEther = liquidityPool.getTotalPooledEther();
|
||||||
uint256 eEthTotalShares = eEth.totalShares();
|
uint256 eEthTotalShares = eEth.totalShares();
|
||||||
|
|
||||||
for (uint256 i = 0; i < _specifiedAmounts.length; i++) {
|
for (uint256 i = 0; i < specifiedAmounts.length; i++) {
|
||||||
if (sellTokenAddress == address(0)) {
|
if (sellToken == address(0)) {
|
||||||
uint256 sharesForDepositAmount = _sharesForDepositAmount(
|
uint256 sharesForDepositAmount = _sharesForDepositAmount(
|
||||||
_specifiedAmounts[i], totalPooledEther, eEthTotalShares
|
specifiedAmounts[i], totalPooledEther, eEthTotalShares
|
||||||
);
|
);
|
||||||
_prices[i] = getPriceAt(
|
prices[i] = getPriceAt(
|
||||||
sellTokenAddress,
|
sellToken,
|
||||||
buyTokenAddress,
|
buyToken,
|
||||||
_specifiedAmounts[i],
|
specifiedAmounts[i],
|
||||||
totalPooledEther + _specifiedAmounts[i],
|
totalPooledEther + specifiedAmounts[i],
|
||||||
eEthTotalShares + sharesForDepositAmount
|
eEthTotalShares + sharesForDepositAmount
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_prices[i] = getPriceAt(
|
prices[i] = getPriceAt(
|
||||||
sellTokenAddress,
|
sellToken,
|
||||||
buyTokenAddress,
|
buyToken,
|
||||||
_specifiedAmounts[i],
|
specifiedAmounts[i],
|
||||||
totalPooledEther,
|
totalPooledEther,
|
||||||
eEthTotalShares
|
eEthTotalShares
|
||||||
);
|
);
|
||||||
@@ -97,31 +96,28 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
function swap(
|
function swap(
|
||||||
bytes32,
|
bytes32,
|
||||||
IERC20 sellToken,
|
address sellToken,
|
||||||
IERC20 buyToken,
|
address buyToken,
|
||||||
OrderSide side,
|
OrderSide side,
|
||||||
uint256 specifiedAmount
|
uint256 specifiedAmount
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
checkInputTokens(address(sellToken), address(buyToken))
|
checkInputTokens(sellToken, buyToken)
|
||||||
returns (Trade memory trade)
|
returns (Trade memory trade)
|
||||||
{
|
{
|
||||||
if (specifiedAmount == 0) {
|
if (specifiedAmount == 0) {
|
||||||
return trade;
|
return trade;
|
||||||
}
|
}
|
||||||
|
|
||||||
address sellTokenAddress = address(sellToken);
|
|
||||||
address buyTokenAddress = address(buyToken);
|
|
||||||
uint256 gasBefore = gasleft();
|
uint256 gasBefore = gasleft();
|
||||||
if (sellTokenAddress == address(0)) {
|
if (sellToken == address(0)) {
|
||||||
if (buyTokenAddress == address(eEth)) {
|
if (buyToken == address(eEth)) {
|
||||||
trade.calculatedAmount = swapEthForEeth(specifiedAmount, side);
|
trade.calculatedAmount = swapEthForEeth(specifiedAmount, side);
|
||||||
} else {
|
} else {
|
||||||
trade.calculatedAmount = swapEthForWeEth(specifiedAmount, side);
|
trade.calculatedAmount = swapEthForWeEth(specifiedAmount, side);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sellTokenAddress == address(eEth)) {
|
if (sellToken == address(eEth)) {
|
||||||
trade.calculatedAmount = swapEethForWeEth(specifiedAmount, side);
|
trade.calculatedAmount = swapEethForWeEth(specifiedAmount, side);
|
||||||
} else {
|
} else {
|
||||||
trade.calculatedAmount = swapWeEthForEeth(specifiedAmount, side);
|
trade.calculatedAmount = swapWeEthForEeth(specifiedAmount, side);
|
||||||
@@ -134,8 +130,8 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
/// amount(PRECISE_UNIT) to render a well-formatted price without
|
/// amount(PRECISE_UNIT) to render a well-formatted price without
|
||||||
/// precisions loss
|
/// precisions loss
|
||||||
trade.price = getPriceAt(
|
trade.price = getPriceAt(
|
||||||
sellTokenAddress,
|
sellToken,
|
||||||
buyTokenAddress,
|
buyToken,
|
||||||
PRECISE_UNIT,
|
PRECISE_UNIT,
|
||||||
liquidityPool.getTotalPooledEther(),
|
liquidityPool.getTotalPooledEther(),
|
||||||
eEth.totalShares()
|
eEth.totalShares()
|
||||||
@@ -143,11 +139,11 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
function getLimits(bytes32, IERC20 sellToken, IERC20 buyToken)
|
function getLimits(bytes32, address sellToken, address buyToken)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
checkInputTokens(address(sellToken), address(buyToken))
|
checkInputTokens(sellToken, buyToken)
|
||||||
returns (uint256[] memory limits)
|
returns (uint256[] memory limits)
|
||||||
{
|
{
|
||||||
limits = new uint256[](2);
|
limits = new uint256[](2);
|
||||||
@@ -155,8 +151,8 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
/// @dev Limits are underestimated to 90% of totalSupply as both weEth
|
/// @dev Limits are underestimated to 90% of totalSupply as both weEth
|
||||||
/// and eEth have no limits but revert in some cases
|
/// and eEth have no limits but revert in some cases
|
||||||
if (
|
if (
|
||||||
address(sellToken) == address(weEth)
|
sellToken == address(weEth)
|
||||||
|| address(buyToken) == address(weEth)
|
|| buyToken == address(weEth)
|
||||||
) {
|
) {
|
||||||
limits[0] = IERC20(address(weEth)).totalSupply() * 90 / 100;
|
limits[0] = IERC20(address(weEth)).totalSupply() * 90 / 100;
|
||||||
} else {
|
} else {
|
||||||
@@ -166,7 +162,7 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
function getCapabilities(bytes32, IERC20, IERC20)
|
function getCapabilities(bytes32, address, address)
|
||||||
external
|
external
|
||||||
pure
|
pure
|
||||||
override
|
override
|
||||||
@@ -183,12 +179,12 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
external
|
external
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
returns (IERC20[] memory tokens)
|
returns (address[] memory tokens)
|
||||||
{
|
{
|
||||||
tokens = new IERC20[](3);
|
tokens = new address[](3);
|
||||||
tokens[0] = IERC20(address(0));
|
tokens[0] = address(0);
|
||||||
tokens[1] = IERC20(address(eEth));
|
tokens[1] = address(eEth);
|
||||||
tokens[2] = IERC20(address(weEth));
|
tokens[2] = address(weEth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @inheritdoc ISwapAdapter
|
/// @inheritdoc ISwapAdapter
|
||||||
@@ -217,7 +213,7 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
uint256 receivedAmount = liquidityPool.deposit{value: amount}();
|
uint256 receivedAmount = liquidityPool.deposit{value: amount}();
|
||||||
uint256 balBeforeUser =
|
uint256 balBeforeUser =
|
||||||
IERC20(address(eEth)).balanceOf(address(msg.sender));
|
IERC20(address(eEth)).balanceOf(address(msg.sender));
|
||||||
IERC20(address(eEth)).transfer(msg.sender, receivedAmount);
|
IERC20(address(eEth)).safeTransfer(msg.sender, receivedAmount);
|
||||||
return IERC20(address(eEth)).balanceOf(address(msg.sender))
|
return IERC20(address(eEth)).balanceOf(address(msg.sender))
|
||||||
- balBeforeUser;
|
- balBeforeUser;
|
||||||
}
|
}
|
||||||
@@ -317,7 +313,7 @@ contract EtherfiAdapter is ISwapAdapter {
|
|||||||
uint256 receivedAmount = weEth.unwrap(amount);
|
uint256 receivedAmount = weEth.unwrap(amount);
|
||||||
uint256 balBeforeUser =
|
uint256 balBeforeUser =
|
||||||
IERC20(address(eEth)).balanceOf(address(msg.sender));
|
IERC20(address(eEth)).balanceOf(address(msg.sender));
|
||||||
IERC20(address(eEth)).transfer(msg.sender, receivedAmount);
|
IERC20(address(eEth)).safeTransfer(msg.sender, receivedAmount);
|
||||||
return IERC20(address(eEth)).balanceOf(address(msg.sender))
|
return IERC20(address(eEth)).balanceOf(address(msg.sender))
|
||||||
- balBeforeUser;
|
- balBeforeUser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
||||||
|
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, EURC, agEUR);
|
uint256[] memory limits = adapter.getLimits(pair, address(EURC), address(agEUR));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 0);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 0);
|
||||||
@@ -54,7 +54,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 agEUR_balance = agEUR.balanceOf(address(this));
|
uint256 agEUR_balance = agEUR.balanceOf(address(this));
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, EURC, agEUR, side, specifiedAmount);
|
adapter.swap(pair, address(EURC), address(agEUR), side, specifiedAmount);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -85,7 +85,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
||||||
|
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, agEUR, EURC);
|
uint256[] memory limits = adapter.getLimits(pair, address(agEUR), address(EURC));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 0);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 0);
|
||||||
@@ -103,7 +103,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 agEUR_balance = agEUR.balanceOf(address(this));
|
uint256 agEUR_balance = agEUR.balanceOf(address(this));
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, agEUR, EURC, side, specifiedAmount);
|
adapter.swap(pair, address(agEUR), address(EURC), side, specifiedAmount);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -154,7 +154,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
deal(address(agEUR), address(this), type(uint256).max);
|
deal(address(agEUR), address(this), type(uint256).max);
|
||||||
agEUR.approve(address(adapter), type(uint256).max);
|
agEUR.approve(address(adapter), type(uint256).max);
|
||||||
}
|
}
|
||||||
trades[i] = adapter.swap(pair, agEUR, EURC, side, amounts[i]);
|
trades[i] = adapter.swap(pair, address(agEUR), address(EURC), side, amounts[i]);
|
||||||
vm.revertTo(beforeSwap);
|
vm.revertTo(beforeSwap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,20 +174,20 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
public
|
public
|
||||||
{
|
{
|
||||||
Capability[] memory res =
|
Capability[] memory res =
|
||||||
adapter.getCapabilities(pair, IERC20(t0), IERC20(t1));
|
adapter.getCapabilities(pair, t0, t1);
|
||||||
|
|
||||||
assertEq(res.length, 2);
|
assertEq(res.length, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetTokensAngle() public {
|
function testGetTokensAngle() public {
|
||||||
IERC20[] memory tokens = adapter.getTokens(bytes32(0));
|
address[] memory tokens = adapter.getTokens(bytes32(0));
|
||||||
|
|
||||||
assertGe(tokens.length, 2);
|
assertGe(tokens.length, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetLimitsAngle() public {
|
function testGetLimitsAngle() public {
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, agEUR, EURC);
|
uint256[] memory limits = adapter.getLimits(pair, address(agEUR), address(EURC));
|
||||||
|
|
||||||
assertEq(limits.length, 2);
|
assertEq(limits.length, 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
function testPriceFuzzEtherfi(uint256 amount0, uint256 amount1) public {
|
function testPriceFuzzEtherfi(uint256 amount0, uint256 amount1) public {
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(
|
uint256[] memory limits = adapter.getLimits(
|
||||||
pair, IERC20(address(weEth)), IERC20(address(eEth))
|
pair, address(address(weEth)), address(address(eEth))
|
||||||
);
|
);
|
||||||
vm.assume(amount0 < limits[0] && amount0 > 0);
|
vm.assume(amount0 < limits[0] && amount0 > 0);
|
||||||
vm.assume(amount1 < limits[1] && amount1 > 0);
|
vm.assume(amount1 < limits[1] && amount1 > 0);
|
||||||
@@ -41,7 +41,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
amounts[1] = amount1;
|
amounts[1] = amount1;
|
||||||
|
|
||||||
Fraction[] memory prices = adapter.price(
|
Fraction[] memory prices = adapter.price(
|
||||||
pair, IERC20(address(weEth)), IERC20(address(eEth)), amounts
|
pair, address(address(weEth)), address(address(eEth)), amounts
|
||||||
);
|
);
|
||||||
|
|
||||||
for (uint256 i = 0; i < prices.length; i++) {
|
for (uint256 i = 0; i < prices.length; i++) {
|
||||||
@@ -58,7 +58,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
IERC20 eEth_ = IERC20(address(eEth));
|
IERC20 eEth_ = IERC20(address(eEth));
|
||||||
IERC20 weEth_ = IERC20(address(weEth));
|
IERC20 weEth_ = IERC20(address(weEth));
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, eEth_, weEth_);
|
uint256[] memory limits = adapter.getLimits(pair, address(eEth_), address(weEth_));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 100);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 100);
|
||||||
@@ -67,7 +67,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
/// work(balance is shares)
|
/// work(balance is shares)
|
||||||
deal(address(adapter), type(uint256).max);
|
deal(address(adapter), type(uint256).max);
|
||||||
adapter.swap(
|
adapter.swap(
|
||||||
pair, IERC20(address(0)), eEth_, OrderSide.Buy, limits[0]
|
pair, address(address(0)), address(eEth_), OrderSide.Buy, limits[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
eEth_.approve(address(adapter), type(uint256).max);
|
eEth_.approve(address(adapter), type(uint256).max);
|
||||||
@@ -78,7 +78,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
/// work(balance is shares)
|
/// work(balance is shares)
|
||||||
deal(address(adapter), type(uint128).max);
|
deal(address(adapter), type(uint128).max);
|
||||||
adapter.swap(
|
adapter.swap(
|
||||||
pair, IERC20(address(0)), eEth_, OrderSide.Buy, specifiedAmount
|
pair, address(address(0)), address(eEth_), OrderSide.Buy, specifiedAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
eEth_.approve(address(adapter), specifiedAmount);
|
eEth_.approve(address(adapter), specifiedAmount);
|
||||||
@@ -88,7 +88,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 weEth_balance = weEth_.balanceOf(address(this));
|
uint256 weEth_balance = weEth_.balanceOf(address(this));
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, eEth_, weEth_, side, specifiedAmount);
|
adapter.swap(pair, address(eEth_), address(weEth_), side, specifiedAmount);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -140,7 +140,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
IERC20 weEth_ = IERC20(address(weEth));
|
IERC20 weEth_ = IERC20(address(weEth));
|
||||||
uint256 weEth_bal_before = weEth_.balanceOf(address(this));
|
uint256 weEth_bal_before = weEth_.balanceOf(address(this));
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, weEth_, eEth_);
|
uint256[] memory limits = adapter.getLimits(pair, address(weEth_), address(eEth_));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 100);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 100);
|
||||||
@@ -149,7 +149,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
/// work(balance is shares)
|
/// work(balance is shares)
|
||||||
deal(address(adapter), type(uint256).max);
|
deal(address(adapter), type(uint256).max);
|
||||||
adapter.swap(
|
adapter.swap(
|
||||||
pair, IERC20(address(0)), weEth_, OrderSide.Buy, limits[0]
|
pair, address(address(0)), address(weEth_), OrderSide.Buy, limits[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
weEth_.approve(address(adapter), type(uint256).max);
|
weEth_.approve(address(adapter), type(uint256).max);
|
||||||
@@ -160,7 +160,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
/// work(balance is shares)
|
/// work(balance is shares)
|
||||||
deal(address(adapter), type(uint128).max);
|
deal(address(adapter), type(uint128).max);
|
||||||
adapter.swap(
|
adapter.swap(
|
||||||
pair, IERC20(address(0)), weEth_, OrderSide.Buy, specifiedAmount
|
pair, address(address(0)), address(weEth_), OrderSide.Buy, specifiedAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
weEth_.approve(address(adapter), specifiedAmount);
|
weEth_.approve(address(adapter), specifiedAmount);
|
||||||
@@ -175,7 +175,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 realAmountWeEth_ = weEth_balance - weEth_bal_before;
|
uint256 realAmountWeEth_ = weEth_balance - weEth_bal_before;
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, weEth_, eEth_, side, realAmountWeEth_);
|
adapter.swap(pair, address(weEth_), address(eEth_), side, realAmountWeEth_);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -216,10 +216,10 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
{
|
{
|
||||||
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
||||||
|
|
||||||
IERC20 eth_ = IERC20(address(0));
|
address eth_ = address(0);
|
||||||
IERC20 eEth_ = IERC20(address(eEth));
|
IERC20 eEth_ = IERC20(address(eEth));
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, eth_, eEth_);
|
uint256[] memory limits = adapter.getLimits(pair, eth_, address(eEth_));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 10);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 10);
|
||||||
@@ -235,7 +235,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 eEth_balance = eEth_.balanceOf(address(this));
|
uint256 eEth_balance = eEth_.balanceOf(address(this));
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, eth_, eEth_, side, specifiedAmount);
|
adapter.swap(pair, eth_, address(eEth_), side, specifiedAmount);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -271,10 +271,10 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
{
|
{
|
||||||
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
OrderSide side = isBuy ? OrderSide.Buy : OrderSide.Sell;
|
||||||
|
|
||||||
IERC20 eth_ = IERC20(address(0));
|
address eth_ = address(0);
|
||||||
IERC20 weEth_ = IERC20(address(weEth));
|
IERC20 weEth_ = IERC20(address(weEth));
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(pair, eth_, weEth_);
|
uint256[] memory limits = adapter.getLimits(pair, eth_, address(weEth_));
|
||||||
|
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 10);
|
vm.assume(specifiedAmount < limits[1] && specifiedAmount > 10);
|
||||||
@@ -290,7 +290,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 weEth_balance = weEth_.balanceOf(address(this));
|
uint256 weEth_balance = weEth_.balanceOf(address(this));
|
||||||
|
|
||||||
Trade memory trade =
|
Trade memory trade =
|
||||||
adapter.swap(pair, eth_, weEth_, side, specifiedAmount);
|
adapter.swap(pair, eth_, address(weEth_), side, specifiedAmount);
|
||||||
|
|
||||||
if (trade.calculatedAmount > 0) {
|
if (trade.calculatedAmount > 0) {
|
||||||
if (side == OrderSide.Buy) {
|
if (side == OrderSide.Buy) {
|
||||||
@@ -350,8 +350,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
|
|
||||||
trades[i] = adapter.swap(
|
trades[i] = adapter.swap(
|
||||||
pair,
|
pair,
|
||||||
IERC20(address(weEth)),
|
address(address(weEth)),
|
||||||
IERC20(address(eEth)),
|
address(address(eEth)),
|
||||||
side,
|
side,
|
||||||
amounts[i]
|
amounts[i]
|
||||||
);
|
);
|
||||||
@@ -372,14 +372,14 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
public
|
public
|
||||||
{
|
{
|
||||||
Capability[] memory res =
|
Capability[] memory res =
|
||||||
adapter.getCapabilities(pair, IERC20(t0), IERC20(t1));
|
adapter.getCapabilities(pair, address(t0), address(t1));
|
||||||
|
|
||||||
assertEq(res.length, 3);
|
assertEq(res.length, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetTokensEtherfi() public {
|
function testGetTokensEtherfi() public {
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
IERC20[] memory tokens = adapter.getTokens(pair);
|
address[] memory tokens = adapter.getTokens(pair);
|
||||||
|
|
||||||
assertEq(tokens.length, 3);
|
assertEq(tokens.length, 3);
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
function testGetLimitsEtherfi() public {
|
function testGetLimitsEtherfi() public {
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
uint256[] memory limits = adapter.getLimits(
|
uint256[] memory limits = adapter.getLimits(
|
||||||
pair, IERC20(address(eEth)), IERC20(address(weEth))
|
pair, address(eEth), address(weEth)
|
||||||
);
|
);
|
||||||
|
|
||||||
assertEq(limits.length, 2);
|
assertEq(limits.length, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user