fix: Fixed getPriceAt to obtain the correct prices

This commit is contained in:
domenicodev
2024-01-24 11:52:47 +01:00
parent 42ac2b1b60
commit 69eeec4385

View File

@@ -29,7 +29,7 @@ contract AngleAdapter is ISwapAdapter {
address buyTokenAddress = address(_buyToken); address buyTokenAddress = address(_buyToken);
for (uint256 i = 0; i < _specifiedAmounts.length; i++) { for (uint256 i = 0; i < _specifiedAmounts.length; i++) {
_prices[i] = getPriceAt(_specifiedAmounts[i], sellTokenAddress, buyTokenAddress); _prices[i] = getPriceAt(_specifiedAmounts[i], sellTokenAddress, buyTokenAddress, OrderSide.Sell);
} }
} }
@@ -49,12 +49,11 @@ contract AngleAdapter is ISwapAdapter {
if (side == OrderSide.Sell) { if (side == OrderSide.Sell) {
trade.calculatedAmount = trade.calculatedAmount =
sell(sellToken, buyToken, specifiedAmount); sell(sellToken, buyToken, specifiedAmount);
trade.price = getPriceAt(specifiedAmount, address(sellToken), address(buyToken));
} else { } else {
trade.calculatedAmount = trade.calculatedAmount =
buy(sellToken, buyToken, specifiedAmount); buy(sellToken, buyToken, specifiedAmount);
trade.price = getPriceAt(specifiedAmount, address(buyToken), address(sellToken));
} }
trade.price = getPriceAt(specifiedAmount, address(sellToken), address(buyToken), side);
trade.gasUsed = gasBefore - gasleft(); trade.gasUsed = gasBefore - gasleft();
} }
@@ -135,16 +134,26 @@ contract AngleAdapter is ISwapAdapter {
} }
/// @notice Calculates pool prices for specified amounts /// @notice Calculates pool prices for specified amounts
/// @param amountIn The amount of the token being sold /// @param amount The amount of the token being sold(if side == Sell) or bought(if side == Buy)
/// @param tokenIn The token being sold /// @param tokenIn The token being sold
/// @param tokenOut The token being bought /// @param tokenOut The token being bought
/// @param side Order side
/// @return The price as a fraction corresponding to the provided amount. /// @return The price as a fraction corresponding to the provided amount.
function getPriceAt(uint256 amountIn, address tokenIn, address tokenOut) function getPriceAt(uint256 amount, address tokenIn, address tokenOut, OrderSide side)
internal internal
view view
returns (Fraction memory) returns (Fraction memory)
{ {
uint256 amountOut = transmuter.quoteIn(amountIn, tokenIn, tokenOut); uint256 amountOut;
uint256 amountIn;
if(side == OrderSide.Sell) {
amountIn = amount;
amountOut = transmuter.quoteIn(amountIn, tokenIn, tokenOut);
}
else {
amountOut = amount;
amountIn = transmuter.quoteOut(amount, tokenIn, tokenOut);
}
return Fraction( return Fraction(
amountOut, amountOut,
amountIn amountIn