mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
5574467be5
|
@ -27,6 +27,15 @@ abstract contract Basic is DSMath, Stores {
|
|||
return abi.encode(eventName, eventParam);
|
||||
}
|
||||
|
||||
function approve(TokenInterface token, address spender, uint256 amount) internal {
|
||||
try token.approve(spender, amount) {
|
||||
|
||||
} catch {
|
||||
token.approve(spender, 0);
|
||||
token.approve(spender, amount);
|
||||
}
|
||||
}
|
||||
|
||||
function changeEthAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){
|
||||
_buy = buy == ethAddr ? TokenInterface(wethAddr) : TokenInterface(buy);
|
||||
_sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell);
|
||||
|
@ -38,7 +47,7 @@ abstract contract Basic is DSMath, Stores {
|
|||
|
||||
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
|
||||
if(isEth) {
|
||||
token.approve(address(token), amount);
|
||||
approve(token, address(token), amount);
|
||||
token.withdraw(amount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,15 @@ abstract contract Helpers is DSMath, Basic {
|
|||
/**
|
||||
* @dev 1Inch Address
|
||||
*/
|
||||
address internal constant oneInchAddr = 0x111111125434b319222CdBf8C261674aDB56F3ae;
|
||||
address internal constant oneInchAddr = 0x11111112542D85B3EF69AE05771c2dCCff4fAa26;
|
||||
|
||||
/**
|
||||
* @dev 1inch swap function sig
|
||||
*/
|
||||
bytes4 internal constant oneInchSig = 0x90411a32;
|
||||
bytes4 internal constant oneInchSwapSig = 0x7c025200;
|
||||
|
||||
/**
|
||||
* @dev 1inch swap function sig
|
||||
*/
|
||||
bytes4 internal constant oneInchUnoswapSig = 0x2e95b6c8;
|
||||
}
|
|
@ -25,7 +25,7 @@ abstract contract OneInchResolver is Helpers, Events {
|
|||
assembly {
|
||||
sig := mload(add(_data, 32))
|
||||
}
|
||||
isOk = sig == oneInchSig;
|
||||
isOk = sig == oneInchSwapSig || sig == oneInchUnoswapSig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ abstract contract OneInchResolverHelpers is OneInchResolver {
|
|||
if (address(_sellAddr) == ethAddr) {
|
||||
ethAmt = oneInchData._sellAmt;
|
||||
} else {
|
||||
TokenInterface(_sellAddr).approve(oneInchAddr, oneInchData._sellAmt);
|
||||
approve(TokenInterface(_sellAddr), oneInchAddr, oneInchData._sellAmt);
|
||||
}
|
||||
|
||||
require(checkOneInchSig(oneInchData.callData), "Not-swap-function");
|
||||
|
@ -124,5 +124,5 @@ abstract contract OneInch is OneInchResolverHelpers {
|
|||
}
|
||||
|
||||
contract ConnectV2OneInch is OneInch {
|
||||
string public name = "1Inch-v1";
|
||||
string public name = "1Inch-v1.2";
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ pragma solidity ^0.7.0;
|
|||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title 1Proto.
|
||||
* @title 1Inch(On-chain).
|
||||
* @dev On-chain and off-chian DEX Aggregator.
|
||||
*/
|
||||
|
||||
|
@ -30,7 +30,7 @@ abstract contract OneProtoResolver is Helpers, Events {
|
|||
if (address(_sellAddr) == ethAddr) {
|
||||
ethAmt = _sellAmt;
|
||||
} else {
|
||||
_sellAddr.approve(address(oneProto), _sellAmt);
|
||||
approve(_sellAddr, address(oneProto), _sellAmt);
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ abstract contract OneProtoResolver is Helpers, Events {
|
|||
if (address(_sellAddr) == ethAddr) {
|
||||
ethAmt = _sellAmt;
|
||||
} else {
|
||||
_sellAddr.approve(address(oneProto), _sellAmt);
|
||||
approve(_sellAddr, address(oneProto), _sellAmt);
|
||||
}
|
||||
|
||||
uint initalBal = getTokenBal(_buyAddr);
|
||||
|
@ -221,5 +221,5 @@ abstract contract OneProto is OneProtoResolverHelpers {
|
|||
}
|
||||
|
||||
contract ConnectV2OneProto is OneProto {
|
||||
string public name = "1proto-v1";
|
||||
string public name = "1Proto-v1.1";
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(aaveProvider.getLendingPoolCore(), _amt);
|
||||
approve(tokenContract, aaveProvider.getLendingPoolCore(), _amt);
|
||||
}
|
||||
|
||||
aave.deposit{value: ethAmt}(token, _amt, referralCode);
|
||||
|
@ -129,7 +129,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
if (token == ethAddr) {
|
||||
ethAmt = _amt;
|
||||
} else {
|
||||
TokenInterface(token).approve(aaveProvider.getLendingPoolCore(), _amt);
|
||||
approve(TokenInterface(token), aaveProvider.getLendingPoolCore(), _amt);
|
||||
}
|
||||
|
||||
aave.repay{value: ethAmt}(token, _amt, payable(address(this)));
|
||||
|
@ -166,5 +166,5 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2AaveV1 is AaveResolver {
|
||||
string constant public name = "AaveV1-v1";
|
||||
string constant public name = "AaveV1-v1.1";
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.deposit(_token, _amt, address(this), referralCode);
|
||||
|
||||
|
@ -153,7 +153,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
|
||||
if (isEth) convertEthToWeth(isEth, tokenContract, _amt);
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.repay(_token, _amt, rateMode, address(this));
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.deposit(_token, _amt, address(this), referralCode);
|
||||
|
||||
|
@ -153,7 +153,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
|
||||
if (isEth) convertEthToWeth(isEth, tokenContract, _amt);
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.repay(_token, _amt, rateMode, address(this));
|
||||
|
||||
|
@ -211,5 +211,5 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2AaveV2 is AaveResolver {
|
||||
string constant public name = "AaveV2-v1";
|
||||
string constant public name = "AaveV2-v1.1";
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
@ -196,7 +196,7 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(cTokenContract.repayBorrow(_amt) == 0, "repay-failed.");
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
@ -254,7 +254,7 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(ctokenContract.mint(_amt) == 0, "deposit-ctoken-failed.");
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(tokenToPay);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(cTokenPay, _amt);
|
||||
approve(tokenContract, cTokenPay, _amt);
|
||||
require(cTokenContract.liquidateBorrow(borrower, _amt, cTokenColl) == 0, "liquidate-failed");
|
||||
}
|
||||
|
||||
|
@ -437,5 +437,5 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2Compound is CompoundResolver {
|
||||
string public name = "Compound-v1";
|
||||
string public name = "Compound-v1.1";
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract contract CreamResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
@ -196,7 +196,7 @@ abstract contract CreamResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(cTokenContract.repayBorrow(_amt) == 0, "repay-failed.");
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
@ -254,7 +254,7 @@ abstract contract CreamResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(cToken, _amt);
|
||||
approve(tokenContract, cToken, _amt);
|
||||
require(ctokenContract.mint(_amt) == 0, "deposit-ctoken-failed.");
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ abstract contract CreamResolver is Events, Helpers {
|
|||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(tokenToPay);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(cTokenPay, _amt);
|
||||
approve(tokenContract, cTokenPay, _amt);
|
||||
require(cTokenContract.liquidateBorrow(borrower, _amt, cTokenColl) == 0, "liquidate-failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,11 @@ abstract contract DyDxResolver is Events, Helpers {
|
|||
TokenInterface tokenContract = TokenInterface(wethAddr);
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
tokenContract.deposit{value: _amt}();
|
||||
tokenContract.approve(address(solo), _amt);
|
||||
approve(tokenContract, address(solo), _amt);
|
||||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(address(solo), _amt);
|
||||
approve(tokenContract, address(solo), _amt);
|
||||
}
|
||||
|
||||
solo.operate(getAccountArgs(), getActionsArgs(_marketId, _amt, true));
|
||||
|
@ -77,7 +77,7 @@ abstract contract DyDxResolver is Events, Helpers {
|
|||
|
||||
if (token == ethAddr) {
|
||||
TokenInterface tokenContract = TokenInterface(wethAddr);
|
||||
tokenContract.approve(address(tokenContract), _amt);
|
||||
approve(tokenContract, address(tokenContract), _amt);
|
||||
tokenContract.withdraw(_amt);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ abstract contract DyDxResolver is Events, Helpers {
|
|||
|
||||
if (token == ethAddr) {
|
||||
TokenInterface tokenContract = TokenInterface(wethAddr);
|
||||
tokenContract.approve(address(tokenContract), _amt);
|
||||
approve(tokenContract, address(tokenContract), _amt);
|
||||
tokenContract.withdraw(_amt);
|
||||
}
|
||||
|
||||
|
@ -148,11 +148,11 @@ abstract contract DyDxResolver is Events, Helpers {
|
|||
TokenInterface tokenContract = TokenInterface(wethAddr);
|
||||
require(address(this).balance >= _amt, "not-enough-eth");
|
||||
tokenContract.deposit{value: _amt}();
|
||||
tokenContract.approve(address(solo), _amt);
|
||||
approve(tokenContract, address(solo), _amt);
|
||||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(address(solo), _amt);
|
||||
approve(tokenContract, address(solo), _amt);
|
||||
}
|
||||
|
||||
solo.operate(getAccountArgs(), getActionsArgs(_marketId, _amt, true));
|
||||
|
|
|
@ -38,7 +38,7 @@ contract Main is Helpers, Events {
|
|||
|
||||
_amt = _amt == uint(-1) ? stakingToken.balanceOf(address(this)) : _amt;
|
||||
|
||||
stakingToken.approve(address(stakingContract), _amt);
|
||||
approve(stakingToken, address(stakingContract), _amt);
|
||||
stakingContract.stake(_amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
|
|
@ -54,12 +54,12 @@ abstract contract UniswapV3Resolver is Events, Helpers {
|
|||
if (depositData.amount0In > 0) {
|
||||
IERC20 _token0 = depositData.poolContract.token0();
|
||||
convertEthToWeth(address(_token0) == wethAddr, TokenInterface(address(_token0)), depositData.amount0In);
|
||||
_token0.safeApprove(address(pool), depositData.amount0In);
|
||||
approve(TokenInterface(address(_token0)), address(pool), depositData.amount0In);
|
||||
}
|
||||
if (depositData.amount1In > 0) {
|
||||
IERC20 _token1 = depositData.poolContract.token1();
|
||||
convertEthToWeth(address(_token1) == wethAddr, TokenInterface(address(_token1)), depositData.amount1In);
|
||||
_token1.safeApprove(address(pool), depositData.amount1In);
|
||||
approve(TokenInterface(address(_token1)), address(pool), depositData.amount1In);
|
||||
}
|
||||
|
||||
(uint amount0, uint amount1,) = depositData.poolContract.mint(depositData.mintAmount, address(this));
|
||||
|
@ -151,7 +151,7 @@ abstract contract UniswapV3Resolver is Events, Helpers {
|
|||
depositAndSwap.mintAmount;
|
||||
|
||||
if (address(depositAndSwap._token0) == wethAddr) {
|
||||
depositAndSwap._token1.approve(address(gUniRouter), amount1In);
|
||||
approve(TokenInterface(address(depositAndSwap._token1)), address(gUniRouter), amount1In);
|
||||
|
||||
(depositAndSwap.amount0, depositAndSwap.amount1, depositAndSwap.mintAmount) =
|
||||
gUniRouter.rebalanceAndAddLiquidityETH{value: amount0In}(
|
||||
|
@ -166,7 +166,7 @@ abstract contract UniswapV3Resolver is Events, Helpers {
|
|||
address(this)
|
||||
);
|
||||
} else if (address(depositAndSwap._token1) == wethAddr) {
|
||||
depositAndSwap._token0.approve(address(gUniRouter), amount0In);
|
||||
approve(TokenInterface(address(depositAndSwap._token0)), address(gUniRouter), amount0In);
|
||||
|
||||
(depositAndSwap.amount0, depositAndSwap.amount1,depositAndSwap. mintAmount) =
|
||||
gUniRouter.rebalanceAndAddLiquidityETH{value: amount1In}(
|
||||
|
@ -181,8 +181,8 @@ abstract contract UniswapV3Resolver is Events, Helpers {
|
|||
address(this)
|
||||
);
|
||||
} else {
|
||||
depositAndSwap._token0.approve(address(gUniRouter), amount0In);
|
||||
depositAndSwap._token1.approve(address(gUniRouter), amount1In);
|
||||
approve(TokenInterface(address(depositAndSwap._token0)), address(gUniRouter), amount0In);
|
||||
approve(TokenInterface(address(depositAndSwap._token1)), address(gUniRouter), amount1In);
|
||||
(depositAndSwap.amount0, depositAndSwap.amount1, depositAndSwap.mintAmount) =
|
||||
gUniRouter.rebalanceAndAddLiquidity(
|
||||
depositAndSwap.poolContract,
|
||||
|
|
|
@ -35,7 +35,7 @@ contract Main is Helpers, Events {
|
|||
|
||||
_amt = _amt == uint(-1) ? stakingTokenContract.balanceOf(address(this)) : _amt;
|
||||
|
||||
stakingTokenContract.approve(address(stakingContract), _amt);
|
||||
approve(stakingTokenContract, address(stakingContract), _amt);
|
||||
stakingContract.stake(_amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
|
|
@ -3,10 +3,11 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
/**
|
||||
* @title Instapool.
|
||||
* @dev Flash Loan in DSA.
|
||||
* @dev Inbuilt Flash Loan in DSA
|
||||
*/
|
||||
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { AccountInterface } from "./interfaces.sol";
|
||||
|
@ -20,10 +21,8 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
|
||||
/**
|
||||
* @dev Borrow Flashloan and Cast spells.
|
||||
* @notice Borrows flashloan and cast the spells.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param route Route to borrow.
|
||||
* @param data targets & data for cast.
|
||||
*/
|
||||
function flashBorrowAndCast(
|
||||
|
@ -31,25 +30,20 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
uint amt,
|
||||
uint route,
|
||||
bytes memory data
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
) external payable {
|
||||
AccountInterface(address(this)).enable(address(instaPool));
|
||||
(string[] memory _targets, bytes[] memory callDatas) = abi.decode(data, (string[], bytes[]));
|
||||
|
||||
address[] memory tokens = new address[](1);
|
||||
uint[] memory amts = new uint[](1);
|
||||
tokens[0] = token;
|
||||
amts[0] = amt;
|
||||
bytes memory callData = abi.encodeWithSignature("cast(string[],bytes[],address)", _targets, callDatas, address(instaPool));
|
||||
|
||||
instaPool.initiateFlashLoan(tokens, amts, route, data);
|
||||
instaPool.initiateFlashLoan(token, amt, route, callData);
|
||||
|
||||
emit LogFlashBorrow(token, amt);
|
||||
AccountInterface(address(this)).disable(address(instaPool));
|
||||
|
||||
_eventName = "LogFlashBorrow(address,uint256)";
|
||||
_eventParam = abi.encode(token, amt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return token to InstaPool.
|
||||
* @notice Payback borrowed flashloan.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
|
@ -60,78 +54,24 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
|
||||
tokenContract.safeTransfer(address(instaPool), _amt);
|
||||
if (token == ethAddr) {
|
||||
Address.sendValue(payable(address(instaPool)), _amt);
|
||||
} else {
|
||||
tokenContract.safeTransfer(address(instaPool), _amt);
|
||||
}
|
||||
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogFlashPayback(address,uint256)";
|
||||
_eventParam = abi.encode(token, _amt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Borrow Flashloan and Cast spells.
|
||||
* @notice Borrows multiple flashloan tokens and cast the spells.
|
||||
* @param tokens Array of token Addresses.
|
||||
* @param amts Array of token Amounts.
|
||||
* @param route Route to borrow.
|
||||
* @param data targets & data for cast.
|
||||
*/
|
||||
function flashMultiBorrowAndCast(
|
||||
address[] calldata tokens,
|
||||
uint[] calldata amts,
|
||||
uint route,
|
||||
bytes calldata data
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
AccountInterface(address(this)).enable(address(instaPool));
|
||||
|
||||
instaPool.initiateFlashLoan(tokens, amts, route, data);
|
||||
|
||||
AccountInterface(address(this)).disable(address(instaPool));
|
||||
|
||||
_eventName = "LogFlashMultiBorrow(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return Multiple token liquidity to InstaPool.
|
||||
* @notice Payback borrowed multiple flashloan tokens.
|
||||
* @param tokens Array of token addresses.
|
||||
* @param amts Array of token amounts.
|
||||
* @param getId get token amounts at this IDs from `InstaMemory` Contract.
|
||||
* @param setId set token amounts at this IDs in `InstaMemory` Contract.
|
||||
*/
|
||||
function flashMultiPayback(
|
||||
address[] calldata tokens,
|
||||
uint[] calldata amts,
|
||||
uint[] calldata getId,
|
||||
uint[] calldata setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _length = tokens.length;
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint i = 0; i < _length; i++) {
|
||||
uint _amt = getUint(getId[i], amts[i]);
|
||||
|
||||
_amts[i] = _amt;
|
||||
|
||||
IERC20 tokenContract = IERC20(tokens[i]);
|
||||
|
||||
tokenContract.safeTransfer(address(instaPool), _amt);
|
||||
|
||||
setUint(setId[i], _amt);
|
||||
}
|
||||
|
||||
_eventName = "LogFlashMultiPayback(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, _amts);
|
||||
emit LogFlashPayback(token, _amt);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2InstaPool is LiquidityResolver {
|
||||
string public name = "Instapool-v1";
|
||||
string public name = "Instapool-v1.1";
|
||||
}
|
|
@ -6,7 +6,7 @@ import { InstaFlashV2Interface } from "./interfaces.sol";
|
|||
contract Variables {
|
||||
|
||||
/**
|
||||
* @dev Instapool / Receiver contract proxy
|
||||
* @dev Instapool contract proxy
|
||||
*/
|
||||
InstaFlashV2Interface public constant instaPool = InstaFlashV2Interface(0x691d4172331a11912c6D0e6D1A002E3d7CED6a66);
|
||||
InstaFlashV2Interface public constant instaPool = InstaFlashV2Interface(0x2a1739D7F07d40e76852Ca8f0D82275Aa087992F);
|
||||
}
|
|
@ -37,7 +37,7 @@ abstract contract KyberResolver is Helpers, Events {
|
|||
} else {
|
||||
TokenInterface sellContract = TokenInterface(sellAddr);
|
||||
_sellAmt = _sellAmt == uint(-1) ? sellContract.balanceOf(address(this)) : _sellAmt;
|
||||
sellContract.approve(address(kyber), _sellAmt);
|
||||
approve(sellContract, address(kyber), _sellAmt);
|
||||
}
|
||||
|
||||
uint _buyAmt = kyber.trade{value: ethAmt}(
|
||||
|
|
|
@ -96,7 +96,7 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(colAddr), _amt);
|
||||
approve(tokenContract, address(colAddr), _amt);
|
||||
tokenJoinContract.join(address(this), _amt);
|
||||
|
||||
VatLike(managerContract.vat()).frob(
|
||||
|
@ -245,7 +245,7 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
|
||||
require(_maxDebt >= _amt, "paying-excess-debt");
|
||||
|
||||
daiJoinContract.dai().approve(address(daiJoinContract), _amt);
|
||||
approve(daiJoinContract.dai(), address(daiJoinContract), _amt);
|
||||
daiJoinContract.join(urn, _amt);
|
||||
|
||||
managerContract.frob(
|
||||
|
@ -357,7 +357,7 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
_amtDeposit = _amtDeposit == uint(-1) ? makerData.tokenContract.balanceOf(address(this)) : _amtDeposit;
|
||||
}
|
||||
|
||||
makerData.tokenContract.approve(address(makerData.colAddr), _amtDeposit);
|
||||
approve(makerData.tokenContract, address(makerData.colAddr), _amtDeposit);
|
||||
makerData.tokenJoinContract.join(urn, _amtDeposit);
|
||||
|
||||
managerContract.frob(
|
||||
|
@ -462,7 +462,7 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
VatLike vat = daiJoinContract.vat();
|
||||
uint chi = potContract.drip();
|
||||
|
||||
daiJoinContract.dai().approve(address(daiJoinContract), _amt);
|
||||
approve(daiJoinContract.dai(), address(daiJoinContract), _amt);
|
||||
daiJoinContract.join(address(this), _amt);
|
||||
if (vat.can(address(this), address(potContract)) == 0) {
|
||||
vat.hope(address(potContract));
|
||||
|
@ -519,5 +519,5 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
}
|
||||
|
||||
contract ConnectV2MakerDAO is MakerResolver {
|
||||
string public constant name = "MakerDAO-v1.1";
|
||||
string public constant name = "MakerDAO-v1.2";
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ contract OasisResolver is DSMath, Basic, Events {
|
|||
bool isEth = address(_sellAddr) == wethAddr;
|
||||
|
||||
convertEthToWeth(isEth, _sellAddr, _expectedAmt);
|
||||
_sellAddr.approve(address(oasis), _expectedAmt);
|
||||
approve(_sellAddr, address(oasis), _expectedAmt);
|
||||
|
||||
uint _sellAmt = oasis.buyAllAmount(
|
||||
address(_buyAddr),
|
||||
|
@ -104,7 +104,7 @@ contract OasisResolver is DSMath, Basic, Events {
|
|||
bool isEth = address(_sellAddr) == wethAddr;
|
||||
|
||||
convertEthToWeth(isEth, _sellAddr, _sellAmt);
|
||||
_sellAddr.approve(address(oasis), _sellAmt);
|
||||
approve(_sellAddr, address(oasis), _sellAmt);
|
||||
|
||||
uint _buyAmt = oasis.sellAllAmount(
|
||||
address(_sellAddr),
|
||||
|
|
|
@ -36,10 +36,10 @@ abstract contract PolygonBridgeResolver is Events, Helpers {
|
|||
TokenInterface _token = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? _token.balanceOf(address(this)) : _amt;
|
||||
if (migrator.rootToChildToken(token) != address(0)) {
|
||||
_token.approve(erc20Predicate, _amt);
|
||||
approve(_token, erc20Predicate, _amt);
|
||||
migrator.depositFor(targetDsa, token, abi.encode(_amt));
|
||||
} else {
|
||||
_token.approve(address(migratorPlasma), _amt);
|
||||
approve(_token, address(migratorPlasma), _amt);
|
||||
migratorPlasma.depositERC20ForUser(token, targetDsa, _amt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ contract AaveV1Helpers is protocolHelpers {
|
|||
if (isEth) {
|
||||
ethAmt = _amt;
|
||||
} else {
|
||||
token.approve(address(aaveCore), _amt);
|
||||
approve(token, address(aaveCore), _amt);
|
||||
}
|
||||
|
||||
transferFees(_token, feeAmt);
|
||||
|
@ -180,7 +180,7 @@ contract AaveV1Helpers is protocolHelpers {
|
|||
if (isEth) {
|
||||
ethAmt = amt;
|
||||
} else {
|
||||
token.approve(address(aaveCore), amt);
|
||||
approve(token, address(aaveCore), amt);
|
||||
}
|
||||
|
||||
aave.repay{value:ethAmt}(_token, amt, payable(address(this)));
|
||||
|
|
|
@ -109,7 +109,7 @@ contract AaveV2Helpers is protocolHelpers {
|
|||
|
||||
convertEthToWeth(isEth, token, _amt);
|
||||
|
||||
token.approve(address(aave), _amt);
|
||||
approve(token, address(aave), _amt);
|
||||
|
||||
aave.deposit(address(token), _amt, address(this), getReferralCode);
|
||||
|
||||
|
@ -178,7 +178,7 @@ contract AaveV2Helpers is protocolHelpers {
|
|||
|
||||
convertEthToWeth(isEth, token, _amt);
|
||||
|
||||
token.approve(address(aave), _amt);
|
||||
approve(token, address(aave), _amt);
|
||||
|
||||
aave.repay(address(token), _amt, rateMode, address(this));
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ contract CompoundHelpers is protocolHelpers {
|
|||
(uint feeAmt, uint _amt) = calculateFee(amt, fee, false);
|
||||
|
||||
if (_token != ethAddr) {
|
||||
token.approve(address(ctoken), _amt);
|
||||
approve(token, address(ctoken), _amt);
|
||||
require(ctoken.mint(_amt) == 0, "deposit-failed");
|
||||
} else {
|
||||
CETHInterface(address(ctoken)).mint{value:_amt}();
|
||||
|
@ -138,7 +138,7 @@ contract CompoundHelpers is protocolHelpers {
|
|||
amt = ctoken.borrowBalanceCurrent(address(this));
|
||||
}
|
||||
if (address(token) != wethAddr) {
|
||||
token.approve(address(ctoken), amt);
|
||||
approve(token, address(ctoken), amt);
|
||||
require(ctoken.repayBorrow(amt) == 0, "repay-failed.");
|
||||
} else {
|
||||
CETHInterface(address(ctoken)).repayBorrow{value:amt}();
|
||||
|
|
|
@ -73,7 +73,7 @@ abstract contract GebResolver is Helpers, Events {
|
|||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(colAddr), _amt);
|
||||
approve(tokenContract, address(colAddr), _amt);
|
||||
tokenJoinContract.join(address(this), _amt);
|
||||
|
||||
SafeEngineLike(managerContract.safeEngine()).modifySAFECollateralization(
|
||||
|
@ -222,7 +222,7 @@ abstract contract GebResolver is Helpers, Events {
|
|||
|
||||
require(_maxDebt >= _amt, "paying-excess-debt");
|
||||
|
||||
coinJoinContract.systemCoin().approve(address(coinJoinContract), _amt);
|
||||
approve(coinJoinContract.systemCoin(), address(coinJoinContract), _amt);
|
||||
coinJoinContract.join(handler, _amt);
|
||||
|
||||
managerContract.modifySAFECollateralization(
|
||||
|
@ -335,7 +335,7 @@ abstract contract GebResolver is Helpers, Events {
|
|||
_amtDeposit = _amtDeposit == uint(-1) ? gebData.tokenContract.balanceOf(address(this)) : _amtDeposit;
|
||||
}
|
||||
|
||||
gebData.tokenContract.approve(address(gebData.colAddr), _amtDeposit);
|
||||
approve(gebData.tokenContract, address(gebData.colAddr), _amtDeposit);
|
||||
gebData.tokenJoinContract.join(handler, _amtDeposit);
|
||||
|
||||
managerContract.modifySAFECollateralization(
|
||||
|
|
|
@ -78,8 +78,8 @@ abstract contract Helpers is DSMath, Basic {
|
|||
isEth = address(_tokenB) == wethAddr;
|
||||
convertEthToWeth(isEth, _tokenB, _amtB);
|
||||
|
||||
_tokenA.approve(address(router), _amtA);
|
||||
_tokenB.approve(address(router), _amtB);
|
||||
approve(_tokenA, address(router), _amtA);
|
||||
approve(_tokenB, address(router), _amtB);
|
||||
|
||||
uint minAmtA = getMinAmount(_tokenA, _amtA, slippage);
|
||||
uint minAmtB = getMinAmount(_tokenB, _amtB, slippage);
|
||||
|
@ -141,6 +141,6 @@ abstract contract Helpers is DSMath, Basic {
|
|||
|
||||
TokenInterface uniToken = TokenInterface(exchangeAddr);
|
||||
_uniAmt = _amt == uint(-1) ? uniToken.balanceOf(address(this)) : _amt;
|
||||
uniToken.approve(address(router), _uniAmt);
|
||||
approve(uniToken, address(router), _uniAmt);
|
||||
}
|
||||
}
|
|
@ -114,7 +114,7 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
|
||||
bool isEth = address(_sellAddr) == wethAddr;
|
||||
convertEthToWeth(isEth, _sellAddr, _expectedAmt);
|
||||
_sellAddr.approve(address(router), _expectedAmt);
|
||||
approve(_sellAddr, address(router), _expectedAmt);
|
||||
|
||||
uint _sellAmt = router.swapTokensForExactTokens(
|
||||
_buyAmt,
|
||||
|
@ -171,7 +171,7 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
|
||||
bool isEth = address(_sellAddr) == wethAddr;
|
||||
convertEthToWeth(isEth, _sellAddr, _sellAmt);
|
||||
_sellAddr.approve(address(router), _sellAmt);
|
||||
approve(_sellAddr, address(router), _sellAmt);
|
||||
|
||||
uint _buyAmt = router.swapExactTokensForTokens(
|
||||
_sellAmt,
|
||||
|
@ -192,5 +192,5 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
}
|
||||
|
||||
contract ConnectV2UniswapV2 is UniswapResolver {
|
||||
string public constant name = "UniswapV2-v1";
|
||||
string public constant name = "UniswapV2-v1.1";
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers {
|
|||
uint _amt = getUint(getId, amt);
|
||||
|
||||
_amt = _amt == uint(-1) ? wethContract.balanceOf(address(this)) : _amt;
|
||||
wethContract.approve(wethAddr, _amt);
|
||||
approve(wethContract, wethAddr, _amt);
|
||||
wethContract.withdraw(_amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
|
|
@ -82,14 +82,21 @@ abstract contract OneHelpers is Stores, DSMath {
|
|||
* @dev Return 1Inch Address
|
||||
*/
|
||||
function getOneInchAddress() internal pure returns (address) {
|
||||
return 0x111111125434b319222CdBf8C261674aDB56F3ae;
|
||||
return 0x11111112542D85B3EF69AE05771c2dCCff4fAa26;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return 1inch swap function sig
|
||||
*/
|
||||
function getOneInchSig() internal pure returns (bytes4) {
|
||||
return 0x90411a32;
|
||||
function getOneInchSwapSig() internal pure returns (bytes4) {
|
||||
return 0x7c025200;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return 1inch swap function sig
|
||||
*/
|
||||
function getOneInchUnoswapSig() internal pure returns (bytes4) {
|
||||
return 0x2e95b6c8;
|
||||
}
|
||||
|
||||
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||||
|
@ -224,7 +231,7 @@ abstract contract OneInchResolver is OneProtoResolver {
|
|||
assembly {
|
||||
sig := mload(add(_data, 32))
|
||||
}
|
||||
isOk = sig == getOneInchSig();
|
||||
isOk = sig == getOneInchSwapSig() || sig == getOneInchUnoswapSig();
|
||||
}
|
||||
|
||||
struct OneInchData {
|
||||
|
@ -585,5 +592,12 @@ abstract contract OneInch is OneProto {
|
|||
}
|
||||
|
||||
contract ConnectOne is OneInch {
|
||||
string public name = "1inch-1proto-v1";
|
||||
string public name = "1inch-1proto-v1.2";
|
||||
|
||||
/**
|
||||
* @dev Connector Details
|
||||
*/
|
||||
function connectorID() public pure returns(uint _type, uint _id) {
|
||||
(_type, _id) = (1, 98);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,22 @@ abstract contract Basic is DSMath, Stores {
|
|||
_sell = sell == maticAddr ? TokenInterface(wmaticAddr) : TokenInterface(sell);
|
||||
}
|
||||
|
||||
function approve(TokenInterface token, address spender, uint256 amount) internal {
|
||||
try token.approve(spender, amount) {
|
||||
|
||||
} catch {
|
||||
token.approve(spender, 0);
|
||||
token.approve(spender, amount);
|
||||
}
|
||||
}
|
||||
|
||||
function convertMaticToWmatic(bool isMatic, TokenInterface token, uint amount) internal {
|
||||
if(isMatic) token.deposit{value: amount}();
|
||||
}
|
||||
|
||||
function convertWmaticToMatic(bool isMatic, TokenInterface token, uint amount) internal {
|
||||
if(isMatic) {
|
||||
token.approve(address(token), amount);
|
||||
approve(token, address(token), amount);
|
||||
token.withdraw(amount);
|
||||
}
|
||||
}
|
||||
|
|
12
contracts/polygon/connectors/1inch/events.sol
Normal file
12
contracts/polygon/connectors/1inch/events.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogSell(
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
23
contracts/polygon/connectors/1inch/helpers.sol
Normal file
23
contracts/polygon/connectors/1inch/helpers.sol
Normal file
|
@ -0,0 +1,23 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev 1Inch Address
|
||||
*/
|
||||
address internal constant oneInchAddr = 0x11111112542D85B3EF69AE05771c2dCCff4fAa26;
|
||||
|
||||
/**
|
||||
* @dev 1inch swap function sig
|
||||
*/
|
||||
bytes4 internal constant oneInchSwapSig = 0x7c025200;
|
||||
|
||||
/**
|
||||
* @dev 1inch swap function sig
|
||||
*/
|
||||
bytes4 internal constant oneInchUnoswapSig = 0x2e95b6c8;
|
||||
}
|
30
contracts/polygon/connectors/1inch/interface.sol
Normal file
30
contracts/polygon/connectors/1inch/interface.sol
Normal file
|
@ -0,0 +1,30 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
interface OneInchInterace {
|
||||
function swap(
|
||||
TokenInterface fromToken,
|
||||
TokenInterface toToken,
|
||||
uint256 fromTokenAmount,
|
||||
uint256 minReturnAmount,
|
||||
uint256 guaranteedAmount,
|
||||
address payable referrer,
|
||||
address[] calldata callAddresses,
|
||||
bytes calldata callDataConcat,
|
||||
uint256[] calldata starts,
|
||||
uint256[] calldata gasLimitsAndValues
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (uint256 returnAmount);
|
||||
}
|
||||
|
||||
struct OneInchData {
|
||||
TokenInterface sellToken;
|
||||
TokenInterface buyToken;
|
||||
uint _sellAmt;
|
||||
uint _buyAmt;
|
||||
uint unitAmt;
|
||||
bytes callData;
|
||||
}
|
128
contracts/polygon/connectors/1inch/main.sol
Normal file
128
contracts/polygon/connectors/1inch/main.sol
Normal file
|
@ -0,0 +1,128 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title 1Inch.
|
||||
* @dev On-chain DEX Aggregator.
|
||||
*/
|
||||
|
||||
// import files from common directory
|
||||
import { TokenInterface , MemoryInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { OneInchInterace, OneInchData } from "./interface.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract OneInchResolver is Helpers, Events {
|
||||
/**
|
||||
* @dev 1inch swap uses `.call()`. This function restrict it to call only swap/trade functionality
|
||||
* @param callData - calldata to extract the first 4 bytes for checking function signature
|
||||
*/
|
||||
function checkOneInchSig(bytes memory callData) internal pure returns(bool isOk) {
|
||||
bytes memory _data = callData;
|
||||
bytes4 sig;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
sig := mload(add(_data, 32))
|
||||
}
|
||||
isOk = sig == oneInchSwapSig || sig == oneInchUnoswapSig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 1inch API swap handler
|
||||
* @param oneInchData - contains data returned from 1inch API. Struct defined in interfaces.sol
|
||||
* @param ethAmt - Eth to swap for .value()
|
||||
*/
|
||||
function oneInchSwap(
|
||||
OneInchData memory oneInchData,
|
||||
uint ethAmt
|
||||
) internal returns (uint buyAmt) {
|
||||
TokenInterface buyToken = oneInchData.buyToken;
|
||||
(uint _buyDec, uint _sellDec) = getTokensDec(buyToken, oneInchData.sellToken);
|
||||
uint _sellAmt18 = convertTo18(_sellDec, oneInchData._sellAmt);
|
||||
uint _slippageAmt = convert18ToDec(_buyDec, wmul(oneInchData.unitAmt, _sellAmt18));
|
||||
|
||||
uint initalBal = getTokenBal(buyToken);
|
||||
|
||||
// solium-disable-next-line security/no-call-value
|
||||
(bool success, ) = oneInchAddr.call{value: ethAmt}(oneInchData.callData);
|
||||
if (!success) revert("1Inch-swap-failed");
|
||||
|
||||
uint finalBal = getTokenBal(buyToken);
|
||||
|
||||
buyAmt = sub(finalBal, initalBal);
|
||||
|
||||
require(_slippageAmt <= buyAmt, "Too much slippage");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract contract OneInchResolverHelpers is OneInchResolver {
|
||||
|
||||
/**
|
||||
* @dev Gets the swapping data from 1inch's API.
|
||||
* @param oneInchData Struct with multiple swap data defined in interfaces.sol
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function _sell(
|
||||
OneInchData memory oneInchData,
|
||||
uint setId
|
||||
) internal returns (OneInchData memory) {
|
||||
TokenInterface _sellAddr = oneInchData.sellToken;
|
||||
|
||||
uint ethAmt;
|
||||
if (address(_sellAddr) == maticAddr) {
|
||||
ethAmt = oneInchData._sellAmt;
|
||||
} else {
|
||||
approve(TokenInterface(_sellAddr), oneInchAddr, oneInchData._sellAmt);
|
||||
}
|
||||
|
||||
require(checkOneInchSig(oneInchData.callData), "Not-swap-function");
|
||||
|
||||
oneInchData._buyAmt = oneInchSwap(oneInchData, ethAmt);
|
||||
setUint(setId, oneInchData._buyAmt);
|
||||
|
||||
return oneInchData;
|
||||
|
||||
// emitLogSellThree(oneInchData, setId);
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract OneInch is OneInchResolverHelpers {
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1Inch.
|
||||
* @notice Swap tokens from exchanges like kyber, 0x etc, with calculation done off-chain.
|
||||
* @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 sellAmt The amount of the token to sell.
|
||||
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
|
||||
* @param callData Data from 1inch API.
|
||||
* @param setId ID stores the amount of token brought.
|
||||
*/
|
||||
function sell(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
bytes calldata callData,
|
||||
uint setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
OneInchData memory oneInchData = OneInchData({
|
||||
buyToken: TokenInterface(buyAddr),
|
||||
sellToken: TokenInterface(sellAddr),
|
||||
unitAmt: unitAmt,
|
||||
callData: callData,
|
||||
_sellAmt: sellAmt,
|
||||
_buyAmt: 0
|
||||
});
|
||||
|
||||
oneInchData = _sell(oneInchData, setId);
|
||||
|
||||
_eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(buyAddr, sellAddr, oneInchData._buyAmt, oneInchData._sellAmt, 0, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2OneInchPolygon is OneInch {
|
||||
string public name = "1Inch-v1";
|
||||
}
|
|
@ -43,7 +43,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.deposit(_token, _amt, address(this), referralCode);
|
||||
|
||||
|
@ -154,7 +154,7 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
|
||||
if (isEth) convertMaticToWmatic(isEth, tokenContract, _amt);
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
approve(tokenContract, address(aave), _amt);
|
||||
|
||||
aave.repay(_token, _amt, rateMode, address(this));
|
||||
|
||||
|
@ -211,6 +211,6 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
}
|
||||
}
|
||||
|
||||
contract ConnectV2AaveV2 is AaveResolver {
|
||||
contract ConnectV2AaveV2Polygon is AaveResolver {
|
||||
string constant public name = "AaveV2-v1";
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ abstract contract Helpers is DSMath, Basic {
|
|||
maticAmt = swapData._sellAmt;
|
||||
} else {
|
||||
address tokenProxy = AugustusSwapperInterface(paraswap).getTokenTransferProxy();
|
||||
TokenInterface(_sellAddr).approve(tokenProxy, swapData._sellAmt);
|
||||
approve(TokenInterface(_sellAddr), tokenProxy, swapData._sellAmt);
|
||||
}
|
||||
|
||||
swapData._buyAmt = _swapHelper(swapData, maticAmt);
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
{
|
||||
"1" : {
|
||||
"1INCH-A": "0x2A6d6d4EE84015F7D64B4d1F66a409bA3f2BAC00",
|
||||
"1INCH-B": "0x36880391afb430e99d43fe94217446b56d4f2c5b",
|
||||
"AAVE-V1-A": "0x127d8cD0E2b2E0366D522DeA53A787bfE9002C14",
|
||||
"AAVE-V2-A": "0x497Bc53507DF17e60F731e9534cff74E8BC9DBb8",
|
||||
"AUTHORITY-A": "0x351Bb32e90C35647Df7a584f3c1a3A0c38F31c68",
|
||||
"BASIC-A": "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687",
|
||||
"1INCH-A": "0x235fca310ac7be45c7ad45f111203468743e4b7c",
|
||||
"1INCH-B": "0xaBac3dCf164eD827EAfda8e05eCc8208D6bc5E04",
|
||||
"COMPOUND-A": "0xbb153cf09a123746e0eb3b3a436c544a7eeb24b6",
|
||||
"AAVE-V1-A": "0x612c5CA43230D9F97a0ac87E4420F66b8DF97e9D",
|
||||
"AAVE-V2-A": "0x68b27A84101ac5120bBAb7Ce8d6b096C961df52C",
|
||||
"MAKERDAO-A": "0x4049db23c605b197f764072569b8db2464653ef6",
|
||||
"UNISWAP-V2-A": "0x1E5CE41BdB653734445FeC3553b61FebDdaFC43c",
|
||||
"COMP-A": "0xB446e325D44C52b93eC122Bf76301f235f90B9c9",
|
||||
"COMPOUND-A": "0x911F4e4e762AeFA6F2Fc1b24e6B1A928200a88a8",
|
||||
"MAKERDAO-A": "0x29AA7b765008b5dDbD687413B7F0D6E9d349F765",
|
||||
"UNISWAP-A": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB",
|
||||
"POLYGON-BRIDGE-A": "0x1b79B302132370B434fb7807b36CB72FB0510aD5",
|
||||
"AAVE-CLAIM-A": "0x611C1FA59Aa1d6352c4C8bD44882063c6aEE85E0",
|
||||
|
@ -20,10 +21,11 @@
|
|||
"INSTAPOOL-A": "0x5806Af7AB22E2916fA582Ff05731Bf7C682387B2",
|
||||
"MAKERDAO-CLAIM-A": "0x2f8cBE650af98602a215b6482F2aD60893C5A4E8",
|
||||
"WETH-A": "0x22075fa719eFb02Ca3cF298AFa9C974B7465E5D3",
|
||||
"REFINANCE-A": "0x9eA34bE6dA51aa9F6408FeA79c946FDCFA424442"
|
||||
"REFINANCE-A": "0x9eA34bE6dA51aa9F6408FeA79c946FDCFA424442",
|
||||
"INST-A": "0x52C2C4a0db049255fF345EB9D3Fb1f555b7a924A"
|
||||
},
|
||||
"137" : {
|
||||
"1INCH-A": "0xC0d9210496afE9763F5d8cEb8deFfBa817232A9e",
|
||||
"AAVE-V2-A": "0xE84d8010Afc3663919F44685cB53ED88866da3eE",
|
||||
"AUTHORITY-A": "0xf73C94402BC24148b744083eD02654EEc2C37D5B",
|
||||
"BASIC-A": "0x1cAF5EC802ca602E98139AD96A8f2B7BC524264E",
|
||||
|
|
|
@ -24,6 +24,12 @@ module.exports = {
|
|||
compilers: [
|
||||
{
|
||||
version: "0.7.6",
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: false,
|
||||
runs: 200,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
version: "0.6.0",
|
||||
|
@ -46,7 +52,7 @@ module.exports = {
|
|||
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
|
||||
accounts: [`0x${PRIVATE_KEY}`],
|
||||
timeout: 150000,
|
||||
gasPrice: parseInt(utils.parseUnits("34", "gwei")),
|
||||
gasPrice: parseInt(utils.parseUnits("30", "gwei")),
|
||||
},
|
||||
hardhat: {
|
||||
forking: {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-etherscan": "^2.1.2",
|
||||
"@nomiclabs/hardhat-etherscan": "^2.1.3",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@nomiclabs/hardhat-web3": "^2.0.0",
|
||||
"@openzeppelin/test-helpers": "^0.5.6",
|
||||
|
|
|
@ -9,6 +9,7 @@ async function main() {
|
|||
|
||||
const connectMapping = {
|
||||
'1INCH-A': 'ConnectV2OneInch',
|
||||
'1INCH-B': 'ConnectV2OneProto',
|
||||
'AAVE-V1-A': 'ConnectV2AaveV1',
|
||||
'AAVE-V2-A': 'ConnectV2AaveV2',
|
||||
'AUTHORITY-A': 'ConnectV2Auth',
|
||||
|
@ -27,15 +28,6 @@ async function main() {
|
|||
for (const key in connectMapping) {
|
||||
addressMapping[key] = await deployConnector(connectMapping[key])
|
||||
}
|
||||
|
||||
const connectorsAbi = [
|
||||
"function addConnectors(string[] _connectorNames, address[] _connectors)"
|
||||
]
|
||||
|
||||
// Replace the address with correct v2 connectors registry address
|
||||
const connectorsContract = new ethers.Contract("0x84b457c6D31025d56449D5A01F0c34bF78636f67", connectorsAbi, wallet)
|
||||
|
||||
await connectorsContract.addConnectors(Object.keys(addressMapping), Object.values(addressMapping))
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user