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