mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
added connector on polygon and arbitrum
This commit is contained in:
parent
cb56f23f49
commit
d1e4b028d6
|
@ -10,7 +10,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
* @dev ISushiSwapRouter
|
* @dev ISushiSwapRouter
|
||||||
*/
|
*/
|
||||||
ISushiSwapRouter internal constant router =
|
ISushiSwapRouter internal constant router =
|
||||||
ISushiSwapRouter(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
|
ISushiSwapRouter(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506);
|
||||||
|
|
||||||
function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt)
|
function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt)
|
||||||
internal
|
internal
|
||||||
|
|
|
@ -191,6 +191,6 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2Sushiswap is SushipswapResolver {
|
contract ConnectV2SushiswapArbitrum is SushipswapResolver {
|
||||||
string public constant name = "Sushipswap-v1.1";
|
string public constant name = "Sushiswap-v1.1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
* @dev ISushiSwapRouter
|
* @dev ISushiSwapRouter
|
||||||
*/
|
*/
|
||||||
ISushiSwapRouter internal constant router =
|
ISushiSwapRouter internal constant router =
|
||||||
ISushiSwapRouter(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
|
ISushiSwapRouter(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506);
|
||||||
|
|
||||||
function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt)
|
function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt)
|
||||||
internal
|
internal
|
||||||
|
@ -72,7 +72,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
uint256 _liquidity
|
uint256 _liquidity
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(TokenInterface _tokenA, TokenInterface _tokenB) = changeEthAddress(
|
(TokenInterface _tokenA, TokenInterface _tokenB) = changeMaticAddress(
|
||||||
tokenA,
|
tokenA,
|
||||||
tokenB
|
tokenB
|
||||||
);
|
);
|
||||||
|
@ -85,11 +85,11 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
wmul(unitAmt, convertTo18(_tokenA.decimals(), _amtA))
|
wmul(unitAmt, convertTo18(_tokenA.decimals(), _amtA))
|
||||||
);
|
);
|
||||||
|
|
||||||
bool isEth = address(_tokenA) == wethAddr;
|
bool isMatic = address(_tokenA) == wmaticAddr;
|
||||||
convertEthToWeth(isEth, _tokenA, _amtA);
|
convertMaticToWmatic(isMatic, _tokenA, _amtA);
|
||||||
|
|
||||||
isEth = address(_tokenB) == wethAddr;
|
isMatic = address(_tokenB) == wmaticAddr;
|
||||||
convertEthToWeth(isEth, _tokenB, _amtB);
|
convertMaticToWmatic(isMatic, _tokenB, _amtB);
|
||||||
|
|
||||||
approve(_tokenA, address(router), _amtA);
|
approve(_tokenA, address(router), _amtA);
|
||||||
approve(_tokenB, address(router), _amtB);
|
approve(_tokenB, address(router), _amtB);
|
||||||
|
@ -149,11 +149,11 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEth = address(_tokenA) == wethAddr;
|
bool isMatic = address(_tokenA) == wmaticAddr;
|
||||||
convertWethToEth(isEth, _tokenA, _amtA);
|
convertWmaticToMatic(isMatic, _tokenA, _amtA);
|
||||||
|
|
||||||
isEth = address(_tokenB) == wethAddr;
|
isMatic = address(_tokenB) == wmaticAddr;
|
||||||
convertWethToEth(isEth, _tokenB, _amtB);
|
convertWmaticToMatic(isMatic, _tokenB, _amtB);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getRemoveLiquidityData(
|
function _getRemoveLiquidityData(
|
||||||
|
@ -168,7 +168,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
uint256 _uniAmt
|
uint256 _uniAmt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(_tokenA, _tokenB) = changeEthAddress(tokenA, tokenB);
|
(_tokenA, _tokenB) = changeMaticAddress(tokenA, tokenB);
|
||||||
address exchangeAddr = ISushiSwapFactory(router.factory()).getPair(
|
address exchangeAddr = ISushiSwapFactory(router.factory()).getPair(
|
||||||
address(_tokenA),
|
address(_tokenA),
|
||||||
address(_tokenB)
|
address(_tokenB)
|
||||||
|
|
|
@ -13,8 +13,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
/**
|
/**
|
||||||
* @dev Deposit Liquidity.
|
* @dev Deposit Liquidity.
|
||||||
* @notice Deposit Liquidity to a SushiSwap pool.
|
* @notice Deposit Liquidity to a SushiSwap pool.
|
||||||
* @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenA The address of token A.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenB The address of token B.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param amtA The amount of A tokens to deposit.
|
* @param amtA The amount of A tokens to deposit.
|
||||||
* @param unitAmt The unit amount of of amtB/amtA with slippage.
|
* @param unitAmt The unit amount of of amtB/amtA with slippage.
|
||||||
* @param slippage Slippage amount.
|
* @param slippage Slippage amount.
|
||||||
|
@ -48,8 +48,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw Liquidity.
|
* @dev Withdraw Liquidity.
|
||||||
* @notice Withdraw Liquidity from a SushiSwap pool.
|
* @notice Withdraw Liquidity from a SushiSwap pool.
|
||||||
* @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenA The address of token A.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenB The address of token B.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param uniAmt The amount of pool tokens to withdraw.
|
* @param uniAmt The amount of pool tokens to withdraw.
|
||||||
* @param unitAmtA The unit amount of amtA/uniAmt with slippage.
|
* @param unitAmtA The unit amount of amtA/uniAmt with slippage.
|
||||||
* @param unitAmtB The unit amount of amtB/uniAmt with slippage.
|
* @param unitAmtB The unit amount of amtB/uniAmt with slippage.
|
||||||
|
@ -83,10 +83,10 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Buy ETH/ERC20_Token.
|
* @dev Buy Matic/ERC20_Token.
|
||||||
* @notice Buy a token using a SushiSwap
|
* @notice Buy a token using a SushiSwap
|
||||||
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param buyAddr The address of the token to buy.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param sellAddr The address of the token to sell.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param buyAmt The amount of tokens to buy.
|
* @param buyAmt The amount of tokens to buy.
|
||||||
* @param unitAmt The unit amount of sellAmt/buyAmt with slippage.
|
* @param unitAmt The unit amount of sellAmt/buyAmt with slippage.
|
||||||
* @param getId ID to retrieve buyAmt.
|
* @param getId ID to retrieve buyAmt.
|
||||||
|
@ -101,7 +101,7 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
uint _buyAmt = getUint(getId, buyAmt);
|
uint _buyAmt = getUint(getId, buyAmt);
|
||||||
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeMaticAddress(buyAddr, sellAddr);
|
||||||
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
||||||
|
|
||||||
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(),
|
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(),
|
||||||
|
@ -112,8 +112,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
uint _expectedAmt = getExpectedSellAmt(paths, _buyAmt);
|
uint _expectedAmt = getExpectedSellAmt(paths, _buyAmt);
|
||||||
require(_slippageAmt >= _expectedAmt, "Too much slippage");
|
require(_slippageAmt >= _expectedAmt, "Too much slippage");
|
||||||
|
|
||||||
bool isEth = address(_sellAddr) == wethAddr;
|
bool isMatic = address(_sellAddr) == wmaticAddr;
|
||||||
convertEthToWeth(isEth, _sellAddr, _expectedAmt);
|
convertMaticToWmatic(isMatic, _sellAddr, _expectedAmt);
|
||||||
approve(_sellAddr, address(router), _expectedAmt);
|
approve(_sellAddr, address(router), _expectedAmt);
|
||||||
|
|
||||||
uint _sellAmt = router.swapTokensForExactTokens(
|
uint _sellAmt = router.swapTokensForExactTokens(
|
||||||
|
@ -124,8 +124,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
block.timestamp + 1
|
block.timestamp + 1
|
||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
isEth = address(_buyAddr) == wethAddr;
|
isMatic = address(_buyAddr) == wmaticAddr;
|
||||||
convertWethToEth(isEth, _buyAddr, _buyAmt);
|
convertWmaticToMatic(isMatic, _buyAddr, _buyAmt);
|
||||||
|
|
||||||
setUint(setId, _sellAmt);
|
setUint(setId, _sellAmt);
|
||||||
|
|
||||||
|
@ -134,10 +134,10 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sell ETH/ERC20_Token.
|
* @dev Sell Matic/ERC20_Token.
|
||||||
* @notice Sell a token using a SushiSwap
|
* @notice Sell a token using a SushiSwap
|
||||||
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param buyAddr The address of the token to buy.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param sellAddr The address of the token to sell.(For Matic: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param sellAmt The amount of the token to sell.
|
* @param sellAmt The amount of the token to sell.
|
||||||
* @param unitAmt The unit amount of buyAmt/sellAmt with slippage.
|
* @param unitAmt The unit amount of buyAmt/sellAmt with slippage.
|
||||||
* @param getId ID to retrieve sellAmt.
|
* @param getId ID to retrieve sellAmt.
|
||||||
|
@ -152,11 +152,11 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
uint _sellAmt = getUint(getId, sellAmt);
|
uint _sellAmt = getUint(getId, sellAmt);
|
||||||
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeMaticAddress(buyAddr, sellAddr);
|
||||||
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
||||||
|
|
||||||
if (_sellAmt == uint(-1)) {
|
if (_sellAmt == uint(-1)) {
|
||||||
_sellAmt = sellAddr == ethAddr ?
|
_sellAmt = sellAddr == maticAddr ?
|
||||||
address(this).balance :
|
address(this).balance :
|
||||||
_sellAddr.balanceOf(address(this));
|
_sellAddr.balanceOf(address(this));
|
||||||
}
|
}
|
||||||
|
@ -169,8 +169,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
uint _expectedAmt = getExpectedBuyAmt(paths, _sellAmt);
|
uint _expectedAmt = getExpectedBuyAmt(paths, _sellAmt);
|
||||||
require(_slippageAmt <= _expectedAmt, "Too much slippage");
|
require(_slippageAmt <= _expectedAmt, "Too much slippage");
|
||||||
|
|
||||||
bool isEth = address(_sellAddr) == wethAddr;
|
bool isMatic = address(_sellAddr) == wmaticAddr;
|
||||||
convertEthToWeth(isEth, _sellAddr, _sellAmt);
|
convertMaticToWmatic(isMatic, _sellAddr, _sellAmt);
|
||||||
approve(_sellAddr, address(router), _sellAmt);
|
approve(_sellAddr, address(router), _sellAmt);
|
||||||
|
|
||||||
uint _buyAmt = router.swapExactTokensForTokens(
|
uint _buyAmt = router.swapExactTokensForTokens(
|
||||||
|
@ -181,8 +181,8 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
block.timestamp + 1
|
block.timestamp + 1
|
||||||
)[1];
|
)[1];
|
||||||
|
|
||||||
isEth = address(_buyAddr) == wethAddr;
|
isMatic = address(_buyAddr) == wmaticAddr;
|
||||||
convertWethToEth(isEth, _buyAddr, _buyAmt);
|
convertWmaticToMatic(isMatic, _buyAddr, _buyAmt);
|
||||||
|
|
||||||
setUint(setId, _buyAmt);
|
setUint(setId, _buyAmt);
|
||||||
|
|
||||||
|
@ -191,6 +191,6 @@ abstract contract SushipswapResolver is Helpers, Events {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2Sushiswap is SushipswapResolver {
|
contract ConnectV2SushiswapPolygon is SushipswapResolver {
|
||||||
string public constant name = "Sushipswap-v1.1";
|
string public constant name = "Sushiswap-v1.1";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user