mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
updated pool connector
This commit is contained in:
parent
085c58dabb
commit
5eff9d5e02
|
@ -1,6 +1,8 @@
|
||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import "../../node_modules/@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
|
||||||
interface LiqudityInterface {
|
interface LiqudityInterface {
|
||||||
function deposit(address, uint) external payable;
|
function deposit(address, uint) external payable;
|
||||||
function withdraw(address, uint) external;
|
function withdraw(address, uint) external;
|
||||||
|
@ -11,6 +13,8 @@ interface LiqudityInterface {
|
||||||
function isTknAllowed(address) external view returns(bool);
|
function isTknAllowed(address) external view returns(bool);
|
||||||
function tknToCTkn(address) external view returns(address);
|
function tknToCTkn(address) external view returns(address);
|
||||||
function liquidityBalance(address, address) external view returns(uint);
|
function liquidityBalance(address, address) external view returns(uint);
|
||||||
|
|
||||||
|
function borrowedToken(address) external view returns(uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CTokenInterface {
|
interface CTokenInterface {
|
||||||
|
@ -66,6 +70,9 @@ contract DSMath {
|
||||||
|
|
||||||
|
|
||||||
contract Helpers is DSMath {
|
contract Helpers is DSMath {
|
||||||
|
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Return ethereum address
|
* @dev Return ethereum address
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +114,12 @@ contract Helpers is DSMath {
|
||||||
function connectorID() public pure returns(uint _type, uint _id) {
|
function connectorID() public pure returns(uint _type, uint _id) {
|
||||||
(_type, _id) = (1, 8);
|
(_type, _id) = (1, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _transfer(address payable to,address token, uint _amt) internal {
|
||||||
|
token == getAddressETH() ?
|
||||||
|
to.transfer(_amt) :
|
||||||
|
IERC20(token).safeTransfer(to, _amt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,18 +227,13 @@ contract LiquidityAccess is LiquidityManage {
|
||||||
*/
|
*/
|
||||||
function flashPayback(address token, uint getId, uint setId) external payable {
|
function flashPayback(address token, uint getId, uint setId) external payable {
|
||||||
LiqudityInterface liquidityContract = LiqudityInterface(getLiquidityAddress());
|
LiqudityInterface liquidityContract = LiqudityInterface(getLiquidityAddress());
|
||||||
uint _amt;
|
uint _amt = liquidityContract.borrowedToken(token);
|
||||||
|
|
||||||
if (token == getAddressETH()) {
|
address[] memory _tknAddrs = new address[](1);
|
||||||
CETHInterface cethContract = CETHInterface(liquidityContract.tknToCTkn(token));
|
_tknAddrs[0] = token;
|
||||||
_amt = cethContract.borrowBalanceCurrent(address(liquidityContract));
|
|
||||||
cethContract.repayBorrowBehalf.value(_amt)(address(liquidityContract));
|
_transfer(payable(address(liquidityContract)), token, _amt);
|
||||||
} else {
|
liquidityContract.returnLiquidity(_tknAddrs);
|
||||||
CTokenInterface ctokenContract = CTokenInterface(liquidityContract.tknToCTkn(token));
|
|
||||||
_amt = ctokenContract.borrowBalanceCurrent(address(liquidityContract));
|
|
||||||
TokenInterface(token).approve(address(ctokenContract), _amt);
|
|
||||||
require(ctokenContract.repayBorrowBehalf(address(liquidityContract), _amt) == 0, "repay-failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
@ -280,23 +288,9 @@ contract LiquidityAccess is LiquidityManage {
|
||||||
uint _length = tokens.length;
|
uint _length = tokens.length;
|
||||||
|
|
||||||
for (uint i = 0; i < _length; i++) {
|
for (uint i = 0; i < _length; i++) {
|
||||||
|
uint _amt = liquidityContract.borrowedToken(tokens[i]);
|
||||||
|
|
||||||
for (uint j = 0; j < _length; j++) {
|
_transfer(payable(address(liquidityContract)), tokens[i], _amt);
|
||||||
if (tokens[i] == tokens[j] && i != j) require(false, "tkn-repeated");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint _amt;
|
|
||||||
|
|
||||||
if (tokens[i] == getAddressETH()) {
|
|
||||||
CETHInterface cethContract = CETHInterface(liquidityContract.tknToCTkn(tokens[i]));
|
|
||||||
_amt = cethContract.borrowBalanceCurrent(address(liquidityContract));
|
|
||||||
cethContract.repayBorrowBehalf.value(_amt)(address(liquidityContract));
|
|
||||||
} else {
|
|
||||||
CTokenInterface ctokenContract = CTokenInterface(liquidityContract.tknToCTkn(tokens[i]));
|
|
||||||
_amt = ctokenContract.borrowBalanceCurrent(address(liquidityContract));
|
|
||||||
TokenInterface(tokens[i]).approve(address(ctokenContract), _amt);
|
|
||||||
require(ctokenContract.repayBorrowBehalf(address(liquidityContract), _amt) == 0, "repay-failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
setUint(setId[i], _amt);
|
setUint(setId[i], _amt);
|
||||||
|
|
||||||
|
@ -306,10 +300,12 @@ contract LiquidityAccess is LiquidityManage {
|
||||||
(uint _type, uint _id) = connectorID();
|
(uint _type, uint _id) = connectorID();
|
||||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
liquidityContract.returnLiquidity(tokens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract ConnectInstaPool is LiquidityAccess {
|
contract ConnectInstaPool is LiquidityAccess {
|
||||||
string public name = "InstaPool-v1.1";
|
string public name = "InstaPool-v2.1";
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user