mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
InstaMakerCompBridge with new liquidity
This commit is contained in:
parent
28479c78b6
commit
502ed12dca
|
@ -52,9 +52,9 @@ interface UniswapExchange {
|
||||||
) external returns (uint256 tokensSold);
|
) external returns (uint256 tokensSold);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LiquidityInterface {
|
interface PoolInterface {
|
||||||
function borrowTknAndTransfer(address ctknAddr, uint tknAmt) external;
|
function accessToken(address[] calldata ctknAddr, uint[] calldata tknAmt, bool isCompound) external;
|
||||||
function payBorrowBack(address ctknAddr, uint tknAmt) external;
|
function paybackToken(address[] calldata ctknAddr, bool isCompound) external payable;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CTokenInterface {
|
interface CTokenInterface {
|
||||||
|
@ -108,6 +108,10 @@ interface CompOracleInterface {
|
||||||
|
|
||||||
contract DSMath {
|
contract DSMath {
|
||||||
|
|
||||||
|
function sub(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = x - y <= x ? x - y : 0;
|
||||||
|
}
|
||||||
|
|
||||||
function add(uint x, uint y) internal pure returns (uint z) {
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||||||
require((z = x + y) >= x, "math-not-safe");
|
require((z = x + y) >= x, "math-not-safe");
|
||||||
}
|
}
|
||||||
|
@ -178,8 +182,8 @@ contract Helper is DSMath {
|
||||||
/**
|
/**
|
||||||
* @dev get InstaDApp Liquidity contract
|
* @dev get InstaDApp Liquidity contract
|
||||||
*/
|
*/
|
||||||
function getLiquidityAddr() public pure returns (address liquidity) {
|
function getPoolAddr() public pure returns (address poolAddr) {
|
||||||
liquidity = 0x7281Db02c62e2966d5Cd20504B7C4C6eF4bD48E1;
|
poolAddr = 0x1564D040EC290C743F67F5cB11f3C1958B39872A;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,7 +295,27 @@ contract CompoundHelper is MakerHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract MakerResolver is CompoundHelper {
|
contract InstaPoolResolver is CompoundHelper {
|
||||||
|
|
||||||
|
function accessDai(uint daiAmt) internal {
|
||||||
|
address[] memory borrowAddr = new address[](1);
|
||||||
|
uint[] memory borrowAmt = new uint[](1);
|
||||||
|
borrowAddr[0] = getCDAIAddress();
|
||||||
|
borrowAmt[0] = daiAmt;
|
||||||
|
PoolInterface(getPoolAddr()).accessToken(borrowAddr, borrowAmt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function returnDai(uint daiAmt) internal {
|
||||||
|
address[] memory borrowAddr = new address[](1);
|
||||||
|
borrowAddr[0] = getCDAIAddress();
|
||||||
|
require(TokenInterface(getDAIAddress()).transfer(getPoolAddr(), daiAmt), "Not-enough-DAI");
|
||||||
|
PoolInterface(getPoolAddr()).paybackToken(borrowAddr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract MakerResolver is InstaPoolResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Open new CDP
|
* @dev Open new CDP
|
||||||
|
@ -338,7 +362,7 @@ contract MakerResolver is CompoundHelper {
|
||||||
daiAmt = add(_wad, daiFeeAmt);
|
daiAmt = add(_wad, daiFeeAmt);
|
||||||
|
|
||||||
// Getting Liquidity from Liquidity Contract
|
// Getting Liquidity from Liquidity Contract
|
||||||
LiquidityInterface(getLiquidityAddr()).borrowTknAndTransfer(getCDAIAddress(), daiAmt);
|
accessDai(daiAmt);
|
||||||
|
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
daiEx.tokenToTokenSwapOutput(
|
daiEx.tokenToTokenSwapOutput(
|
||||||
|
@ -426,8 +450,7 @@ contract MakerResolver is CompoundHelper {
|
||||||
tub.draw(cup, _wad);
|
tub.draw(cup, _wad);
|
||||||
|
|
||||||
// Returning Liquidity To Liquidity Contract
|
// Returning Liquidity To Liquidity Contract
|
||||||
require(TokenInterface(getDAIAddress()).transfer(getLiquidityAddr(), _wad), "Not-enough-DAI");
|
returnDai(_wad);
|
||||||
LiquidityInterface(getLiquidityAddr()).payBorrowBack(getCDAIAddress(), _wad);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,8 +508,7 @@ contract CompoundResolver is MakerResolver {
|
||||||
enterMarket(getCDAIAddress());
|
enterMarket(getCDAIAddress());
|
||||||
require(CTokenInterface(getCDAIAddress()).borrow(daiAmt) == 0, "got collateral?");
|
require(CTokenInterface(getCDAIAddress()).borrow(daiAmt) == 0, "got collateral?");
|
||||||
// Returning Liquidity to Liquidity Contract
|
// Returning Liquidity to Liquidity Contract
|
||||||
require(TokenInterface(getDAIAddress()).transfer(getLiquidityAddr(), daiAmt), "Not-enough-DAI");
|
returnDai(daiAmt);
|
||||||
LiquidityInterface(getLiquidityAddr()).payBorrowBack(getCDAIAddress(), daiAmt);
|
|
||||||
emit LogBorrow(
|
emit LogBorrow(
|
||||||
getDAIAddress(),
|
getDAIAddress(),
|
||||||
getCDAIAddress(),
|
getCDAIAddress(),
|
||||||
|
@ -503,7 +525,7 @@ contract CompoundResolver is MakerResolver {
|
||||||
uint daiBorrowed = cToken.borrowBalanceCurrent(address(this));
|
uint daiBorrowed = cToken.borrowBalanceCurrent(address(this));
|
||||||
wipeAmt = tokenAmt < daiBorrowed ? tokenAmt : daiBorrowed;
|
wipeAmt = tokenAmt < daiBorrowed ? tokenAmt : daiBorrowed;
|
||||||
// Getting Liquidity from Liquidity Contract
|
// Getting Liquidity from Liquidity Contract
|
||||||
LiquidityInterface(getLiquidityAddr()).borrowTknAndTransfer(getCDAIAddress(), wipeAmt);
|
accessDai(wipeAmt);
|
||||||
setApproval(getDAIAddress(), wipeAmt, getCDAIAddress());
|
setApproval(getDAIAddress(), wipeAmt, getCDAIAddress());
|
||||||
require(cToken.repayBorrow(wipeAmt) == 0, "transfer approved?");
|
require(cToken.repayBorrow(wipeAmt) == 0, "transfer approved?");
|
||||||
emit LogRepay(
|
emit LogRepay(
|
||||||
|
@ -582,11 +604,18 @@ contract InstaMakerCompBridge is CompoundResolver {
|
||||||
* @dev convert Maker CDP into Compound Collateral
|
* @dev convert Maker CDP into Compound Collateral
|
||||||
*/
|
*/
|
||||||
function makerToCompound(uint cdpId, uint ethQty, uint daiQty) external {
|
function makerToCompound(uint cdpId, uint ethQty, uint daiQty) external {
|
||||||
|
// subtracting 0.00000001 ETH from initialPoolBal to solve Compound 8 decimal CETH error.
|
||||||
|
uint initialPoolBal = sub(getPoolAddr().balance, 10000000000);
|
||||||
|
|
||||||
(uint ethAmt, uint daiDebt) = checkCDP(bytes32(cdpId), ethQty, daiQty);
|
(uint ethAmt, uint daiDebt) = checkCDP(bytes32(cdpId), ethQty, daiQty);
|
||||||
uint daiAmt = wipeAndFreeMaker(cdpId, ethAmt, daiDebt); // Getting Liquidity inside Wipe function
|
uint daiAmt = wipeAndFreeMaker(cdpId, ethAmt, daiDebt); // Getting Liquidity inside Wipe function
|
||||||
enterMarket(getCETHAddress());
|
enterMarket(getCETHAddress());
|
||||||
enterMarket(getCDAIAddress());
|
enterMarket(getCDAIAddress());
|
||||||
mintAndBorrowComp(ethAmt, daiAmt); // Returning Liquidity inside Borrow function
|
mintAndBorrowComp(ethAmt, daiAmt); // Returning Liquidity inside Borrow function
|
||||||
|
|
||||||
|
uint finalPoolBal = getPoolAddr().balance;
|
||||||
|
assert(finalPoolBal >= initialPoolBal);
|
||||||
|
|
||||||
emit LogMakerToCompound(ethAmt, daiAmt);
|
emit LogMakerToCompound(ethAmt, daiAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,11 +624,18 @@ contract InstaMakerCompBridge is CompoundResolver {
|
||||||
* @param cdpId = 0, if user don't have any CDP
|
* @param cdpId = 0, if user don't have any CDP
|
||||||
*/
|
*/
|
||||||
function compoundToMaker(uint cdpId, uint ethQty, uint daiQty) external {
|
function compoundToMaker(uint cdpId, uint ethQty, uint daiQty) external {
|
||||||
|
// subtracting 0.00000001 ETH from initialPoolBal to solve Compound 8 decimal CETH error.
|
||||||
|
uint initialPoolBal = sub(getPoolAddr().balance, 10000000000);
|
||||||
|
|
||||||
uint cdpNum = cdpId > 0 ? cdpId : open();
|
uint cdpNum = cdpId > 0 ? cdpId : open();
|
||||||
(uint ethCol, uint daiDebt) = checkCompound(ethQty, daiQty);
|
(uint ethCol, uint daiDebt) = checkCompound(ethQty, daiQty);
|
||||||
(uint ethAmt, uint daiAmt) = paybackAndRedeemComp(ethCol, daiDebt); // Getting Liquidity inside Wipe function
|
(uint ethAmt, uint daiAmt) = paybackAndRedeemComp(ethCol, daiDebt); // Getting Liquidity inside Wipe function
|
||||||
ethAmt = ethAmt < address(this).balance ? ethAmt : address(this).balance;
|
ethAmt = ethAmt < address(this).balance ? ethAmt : address(this).balance;
|
||||||
lockAndDrawMaker(cdpNum, ethAmt, daiAmt); // Returning Liquidity inside Borrow function
|
lockAndDrawMaker(cdpNum, ethAmt, daiAmt); // Returning Liquidity inside Borrow function
|
||||||
|
|
||||||
|
uint finalPoolBal = getPoolAddr().balance;
|
||||||
|
assert(finalPoolBal >= initialPoolBal);
|
||||||
|
|
||||||
emit LogCompoundToMaker(ethAmt, daiAmt);
|
emit LogCompoundToMaker(ethAmt, daiAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user