From 3a2e6202466f67575100fe631379822acef3f988 Mon Sep 17 00:00:00 2001 From: domenicodev Date: Sat, 6 Jan 2024 17:27:36 +0100 Subject: [PATCH] fix: Fixed Fractions --- evm/lib/forge-std | 2 +- evm/src/integral/IntegralSwapAdapter.sol | 24 ++++++++++++------------ evm/test/IntegralSwapAdapter.t.sol | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/evm/lib/forge-std b/evm/lib/forge-std index f73c73d..155d547 160000 --- a/evm/lib/forge-std +++ b/evm/lib/forge-std @@ -1 +1 @@ -Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 +Subproject commit 155d547c449afa8715f538d69454b83944117811 diff --git a/evm/src/integral/IntegralSwapAdapter.sol b/evm/src/integral/IntegralSwapAdapter.sol index d5f7673..80e4446 100644 --- a/evm/src/integral/IntegralSwapAdapter.sol +++ b/evm/src/integral/IntegralSwapAdapter.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.13; import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol"; +import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; /// @dev Integral submitted deadline of 3600 seconds (1 hour) to Paraswap, but it is not strictly necessary to be this long /// as the contract allows less durations, we use 1000 seconds (15 minutes) as a deadline @@ -33,7 +34,10 @@ contract IntegralSwapAdapter is ISwapAdapter { uint256 price_ = relayer.getPriceByTokenAddresses(address(_sellToken), address(_buyToken)); for (uint256 i = 0; i < _specifiedAmounts.length; i++) { - _prices[i] = Fraction(price_, 1); + _prices[i] = Fraction( + relayer.getPriceByTokenAddresses(address(_sellToken), address(_buyToken)) * 10**(ERC20(address(_sellToken)).decimals()) / 10**18, + 10**(ERC20(address(_buyToken)).decimals()) + ); } } @@ -58,12 +62,10 @@ contract IntegralSwapAdapter is ISwapAdapter { buy(sellToken, buyToken, specifiedAmount); } trade.gasUsed = gasBefore - gasleft(); - /** - * @dev once we get reply from propeller about return values in price() function and in every Fraction - * Fraction[0] = relayer.getPriceByTokenAddresses(address(sellToken), address(buyToken)) * 10^(IERC20(sellToken).decimals) / 10^18 - * Fraction[1] = 10^(IERC20(buyToken).decimals) - */ - trade.price = Fraction(relayer.getPriceByTokenAddresses(address(sellToken), address(buyToken)), 1); + trade.price = Fraction( + relayer.getPriceByTokenAddresses(address(sellToken), address(buyToken)) * 10**(ERC20(address(sellToken)).decimals()) / 10**18, + 10**(ERC20(address(buyToken)).decimals()) + ); } /// @inheritdoc ISwapAdapter @@ -197,11 +199,9 @@ contract IntegralSwapAdapter is ISwapAdapter { uint256 limitMax1 ) = relayer.getPoolState(address(sellToken), address(buyToken)); - uint256[] memory limits_ = new uint256[](2); - limits_[0] = limitMax0; - limits_[1] = limitMax1; - - return limits_; + limits = new uint256[](2); + limits[0] = limitMax0; + limits[1] = limitMax1; } } diff --git a/evm/test/IntegralSwapAdapter.t.sol b/evm/test/IntegralSwapAdapter.t.sol index adb3893..0120198 100644 --- a/evm/test/IntegralSwapAdapter.t.sol +++ b/evm/test/IntegralSwapAdapter.t.sol @@ -42,9 +42,9 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { uint256 limitMax1 ) = relayer.getPoolState(address(sellToken), address(buyToken)); - uint256[] memory limits_ = new uint256[](2); - limits_[0] = limitMin0; - limits_[1] = limitMin1; + limits = new uint256[](2); + limits[0] = limitMin0; + limits[1] = limitMin1; } function testPriceFuzzIntegral(uint256 amount0, uint256 amount1) public {