mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #248 from Instadapp/uniswap-swap-fix
uniswap v3 swap fix
This commit is contained in:
commit
c62c31a62f
contracts
arbitrum/connectors/uniswap/v3_swap
mainnet/connectors/uniswap/v3_swap
optimism/connectors/uniswap/v3_swap
polygon/connectors/uniswap/v3_swap
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -90,4 +90,4 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
|
||||
contract ConnectV2UniswapV3SwapPolygon is UniswapResolver {
|
||||
string public constant name = "UniswapV3-Swap-v1";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user