Merge pull request from Instadapp/uniswap-swap-fix

uniswap v3 swap fix
This commit is contained in:
Thrilok kumar 2022-08-03 01:35:18 +05:30 committed by GitHub
commit c62c31a62f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 17 deletions
contracts
arbitrum/connectors/uniswap/v3_swap
mainnet/connectors/uniswap/v3_swap
optimism/connectors/uniswap/v3_swap
polygon/connectors/uniswap/v3_swap

View File

@ -53,7 +53,7 @@ abstract contract Helpers is DSMath, Basic {
_sellAddr.decimals(),
wmul(buyData.unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(buyData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _slippageAmt);
approve(_sellAddr, address(swapRouter), _slippageAmt);
@ -70,7 +70,11 @@ abstract contract Helpers is DSMath, Basic {
uint256 _sellAmt = swapRouter.exactOutputSingle(params);
require(_slippageAmt >= _sellAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
if (_slippageAmt > _sellAmt) {
convertEthToWeth(isEth, _sellAddr, _slippageAmt - _sellAmt);
approve(_sellAddr, address(swapRouter), 0);
}
isEth = address(buyData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _sellAmt);
@ -115,7 +119,7 @@ abstract contract Helpers is DSMath, Basic {
wmul(sellData.unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(sellData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _sellAmt);
approve(_sellAddr, address(swapRouter), _sellAmt);
ExactInputSingleParams memory params = ExactInputSingleParams({
@ -131,7 +135,7 @@ abstract contract Helpers is DSMath, Basic {
uint256 _buyAmt = swapRouter.exactInputSingle(params);
require(_slippageAmt <= _buyAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
isEth = address(sellData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _buyAmt);

View File

@ -53,7 +53,7 @@ abstract contract Helpers is DSMath, Basic {
_sellAddr.decimals(),
wmul(buyData.unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(buyData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _slippageAmt);
approve(_sellAddr, address(swapRouter), _slippageAmt);
@ -69,7 +69,11 @@ abstract contract Helpers is DSMath, Basic {
uint256 _sellAmt = swapRouter.exactOutputSingle(params);
require(_slippageAmt >= _sellAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
if (_slippageAmt > _sellAmt) {
convertEthToWeth(isEth, _sellAddr, _slippageAmt - _sellAmt);
approve(_sellAddr, address(swapRouter), 0);
}
isEth = address(buyData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _sellAmt);
@ -114,7 +118,7 @@ abstract contract Helpers is DSMath, Basic {
wmul(sellData.unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(sellData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _sellAmt);
approve(_sellAddr, address(swapRouter), _sellAmt);
ExactInputSingleParams memory params = ExactInputSingleParams({
@ -129,7 +133,7 @@ abstract contract Helpers is DSMath, Basic {
uint256 _buyAmt = swapRouter.exactInputSingle(params);
require(_slippageAmt <= _buyAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
isEth = address(sellData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _buyAmt);

View File

@ -53,7 +53,7 @@ abstract contract Helpers is DSMath, Basic {
_sellAddr.decimals(),
wmul(buyData.unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(buyData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _slippageAmt);
approve(_sellAddr, address(swapRouter), _slippageAmt);
@ -70,7 +70,11 @@ abstract contract Helpers is DSMath, Basic {
uint256 _sellAmt = swapRouter.exactOutputSingle(params);
require(_slippageAmt >= _sellAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
if (_slippageAmt > _sellAmt) {
convertEthToWeth(isEth, _sellAddr, _slippageAmt - _sellAmt);
approve(_sellAddr, address(swapRouter), 0);
}
isEth = address(buyData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _sellAmt);
@ -115,7 +119,7 @@ abstract contract Helpers is DSMath, Basic {
wmul(sellData.unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
);
bool isEth = address(_sellAddr) == wethAddr;
bool isEth = address(sellData.sellAddr) == ethAddr;
convertEthToWeth(isEth, _sellAddr, _sellAmt);
approve(_sellAddr, address(swapRouter), _sellAmt);
ExactInputSingleParams memory params = ExactInputSingleParams({
@ -131,7 +135,7 @@ abstract contract Helpers is DSMath, Basic {
uint256 _buyAmt = swapRouter.exactInputSingle(params);
require(_slippageAmt <= _buyAmt, "Too much slippage");
isEth = address(_buyAddr) == wethAddr;
isEth = address(sellData.buyAddr) == ethAddr;
convertWethToEth(isEth, _buyAddr, _buyAmt);
setUint(setId, _buyAmt);

View File

@ -53,7 +53,7 @@ abstract contract Helpers is DSMath, Basic {
wmul(buyData.unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
);
bool isMatic = address(_sellAddr) == wmaticAddr;
bool isMatic = address(buyData.sellAddr) == maticAddr;
convertMaticToWmatic(isMatic, _sellAddr, _slippageAmt);
approve(_sellAddr, address(swapRouter), _slippageAmt);
ExactOutputSingleParams memory params = ExactOutputSingleParams({
@ -69,7 +69,12 @@ abstract contract Helpers is DSMath, Basic {
uint256 _sellAmt = swapRouter.exactOutputSingle(params);
require(_slippageAmt >= _sellAmt, "Too much slippage");
isMatic = address(_buyAddr) == wmaticAddr;
if (_slippageAmt > _sellAmt) {
convertMaticToWmatic(isMatic, _sellAddr, _slippageAmt - _sellAmt);
approve(_sellAddr, address(swapRouter), 0);
}
isMatic = address(buyData.buyAddr) == maticAddr;
convertWmaticToMatic(isMatic, _buyAddr, _buyAmt);
setUint(setId, _sellAmt);
@ -114,7 +119,7 @@ abstract contract Helpers is DSMath, Basic {
wmul(sellData.unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
);
bool isMatic = address(_sellAddr) == wmaticAddr;
bool isMatic = address(sellData.sellAddr) == maticAddr;
convertMaticToWmatic(isMatic, _sellAddr, _sellAmt);
approve(_sellAddr, address(swapRouter), _sellAmt);
ExactInputSingleParams memory params = ExactInputSingleParams({
@ -130,7 +135,7 @@ abstract contract Helpers is DSMath, Basic {
uint256 _buyAmt = swapRouter.exactInputSingle(params);
require(_slippageAmt <= _buyAmt, "Too much slippage");
isMatic = address(_buyAddr) == wmaticAddr;
isMatic = address(sellData.buyAddr) == maticAddr;
convertWmaticToMatic(isMatic, _buyAddr, _buyAmt);
setUint(setId, _buyAmt);

View File

@ -90,4 +90,4 @@ abstract contract UniswapResolver is Helpers, Events {
contract ConnectV2UniswapV3SwapPolygon is UniswapResolver {
string public constant name = "UniswapV3-Swap-v1";
}
}