mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Fixed minor bugs
This commit is contained in:
parent
cbc7a2e782
commit
489fc8b69a
|
@ -5,7 +5,7 @@ import { TokenInterface , MemoryInterface, EventInterface} from "../common/inter
|
||||||
import { Stores } from "../common/stores.sol";
|
import { Stores } from "../common/stores.sol";
|
||||||
import { DSMath } from "../common/math.sol";
|
import { DSMath } from "../common/math.sol";
|
||||||
|
|
||||||
interface IUniswapV2Router01 {
|
interface IUniswapV2Router02 {
|
||||||
function factory() external pure returns (address);
|
function factory() external pure returns (address);
|
||||||
function WETH() external pure returns (address);
|
function WETH() external pure returns (address);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ contract UniswapHelpers is Stores, DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Return uniswap v2 router Address
|
* @dev Return uniswap v2 router02 Address
|
||||||
*/
|
*/
|
||||||
function getUniswapAddr() internal pure returns (address) {
|
function getUniswapAddr() internal pure returns (address) {
|
||||||
return 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
|
return 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
|
||||||
|
@ -105,7 +105,7 @@ contract UniswapHelpers is Stores, DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExpectedBuyAmt(
|
function getExpectedBuyAmt(
|
||||||
IUniswapV2Router01 router,
|
IUniswapV2Router02 router,
|
||||||
address[] memory paths,
|
address[] memory paths,
|
||||||
uint sellAmt
|
uint sellAmt
|
||||||
) internal view returns(uint buyAmt) {
|
) internal view returns(uint buyAmt) {
|
||||||
|
@ -117,19 +117,19 @@ contract UniswapHelpers is Stores, DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExpectedSellAmt(
|
function getExpectedSellAmt(
|
||||||
IUniswapV2Router01 router,
|
IUniswapV2Router02 router,
|
||||||
address[] memory paths,
|
address[] memory paths,
|
||||||
uint buyAmt
|
uint buyAmt
|
||||||
) internal view returns(uint sellAmt) {
|
) internal view returns(uint sellAmt) {
|
||||||
uint[] memory amts = router.getAmountsOut(
|
uint[] memory amts = router.getAmountsIn(
|
||||||
buyAmt,
|
buyAmt,
|
||||||
paths
|
paths
|
||||||
);
|
);
|
||||||
sellAmt = amts[1];
|
sellAmt = amts[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPair(
|
function checkPair(
|
||||||
IUniswapV2Router01 router,
|
IUniswapV2Router02 router,
|
||||||
address[] memory paths
|
address[] memory paths
|
||||||
) internal view {
|
) internal view {
|
||||||
address pair = IUniswapV2Factory(router.factory()).getPair(paths[0], paths[1]);
|
address pair = IUniswapV2Factory(router.factory()).getPair(paths[0], paths[1]);
|
||||||
|
@ -137,8 +137,8 @@ contract UniswapHelpers is Stores, DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPaths(
|
function getPaths(
|
||||||
address sellAddr,
|
address buyAddr,
|
||||||
address buyAddr
|
address sellAddr
|
||||||
) internal pure returns(address[] memory paths) {
|
) internal pure returns(address[] memory paths) {
|
||||||
paths = new address[](2);
|
paths = new address[](2);
|
||||||
paths[0] = address(sellAddr);
|
paths[0] = address(sellAddr);
|
||||||
|
@ -174,7 +174,7 @@ contract LiquidityHelpers is UniswapHelpers {
|
||||||
uint slippage,
|
uint slippage,
|
||||||
uint deadline
|
uint deadline
|
||||||
) internal returns (uint _amtA, uint _amtB, uint _liquidity) {
|
) internal returns (uint _amtA, uint _amtB, uint _liquidity) {
|
||||||
IUniswapV2Router01 router = IUniswapV2Router01(getUniswapAddr());
|
IUniswapV2Router02 router = IUniswapV2Router02(getUniswapAddr());
|
||||||
(TokenInterface _tokenA, TokenInterface _tokenB) = changeEthAddress(tokenA, tokenB);
|
(TokenInterface _tokenA, TokenInterface _tokenB) = changeEthAddress(tokenA, tokenB);
|
||||||
|
|
||||||
_amtA = _amt == uint(-1) ? getTokenBalace(tokenA) : _amt;
|
_amtA = _amt == uint(-1) ? getTokenBalace(tokenA) : _amt;
|
||||||
|
@ -206,7 +206,7 @@ contract LiquidityHelpers is UniswapHelpers {
|
||||||
uint unitAmtB,
|
uint unitAmtB,
|
||||||
uint deadline
|
uint deadline
|
||||||
) internal returns (uint _amtA, uint _amtB, uint _uniAmt) {
|
) internal returns (uint _amtA, uint _amtB, uint _uniAmt) {
|
||||||
IUniswapV2Router01 router = IUniswapV2Router01(getUniswapAddr());
|
IUniswapV2Router02 router = IUniswapV2Router02(getUniswapAddr());
|
||||||
(TokenInterface _tokenA, TokenInterface _tokenB) = changeEthAddress(tokenA, tokenB);
|
(TokenInterface _tokenA, TokenInterface _tokenB) = changeEthAddress(tokenA, tokenB);
|
||||||
address exchangeAddr = IUniswapV2Factory(router.factory()).getPair(address(_tokenA), address(_tokenB));
|
address exchangeAddr = IUniswapV2Factory(router.factory()).getPair(address(_tokenA), address(_tokenB));
|
||||||
require(exchangeAddr != address(0), "pair-not-found.");
|
require(exchangeAddr != address(0), "pair-not-found.");
|
||||||
|
@ -408,10 +408,10 @@ contract UniswapResolver is UniswapLiquidity {
|
||||||
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
||||||
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
||||||
|
|
||||||
uint _buyAmt18 = convertTo18(_buyAddr.decimals(), _buyAmt);
|
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(),
|
||||||
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(), wmul(unitAmt, _buyAmt18));
|
wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt)));
|
||||||
|
|
||||||
IUniswapV2Router01 router = IUniswapV2Router01(getUniswapAddr());
|
IUniswapV2Router02 router = IUniswapV2Router02(getUniswapAddr());
|
||||||
|
|
||||||
checkPair(router, paths);
|
checkPair(router, paths);
|
||||||
uint _expectedAmt = getExpectedSellAmt(router, paths, _buyAmt);
|
uint _expectedAmt = getExpectedSellAmt(router, paths, _buyAmt);
|
||||||
|
@ -466,10 +466,10 @@ contract UniswapResolver is UniswapLiquidity {
|
||||||
_sellAmt = sellAddr == getEthAddr() ? address(this).balance : _sellAddr.balanceOf(address(this));
|
_sellAmt = sellAddr == getEthAddr() ? address(this).balance : _sellAddr.balanceOf(address(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint _sellAmt18 = convertTo18(_sellAddr.decimals(), _sellAmt);
|
uint _slippageAmt = convert18ToDec(_buyAddr.decimals(),
|
||||||
uint _slippageAmt = convert18ToDec(_buyAddr.decimals(), wmul(unitAmt, _sellAmt18));
|
wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt)));
|
||||||
|
|
||||||
IUniswapV2Router01 router = IUniswapV2Router01(getUniswapAddr());
|
IUniswapV2Router02 router = IUniswapV2Router02(getUniswapAddr());
|
||||||
|
|
||||||
checkPair(router, paths);
|
checkPair(router, paths);
|
||||||
uint _expectedAmt = getExpectedBuyAmt(router, paths, _sellAmt);
|
uint _expectedAmt = getExpectedBuyAmt(router, paths, _sellAmt);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user