mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
enter market bug fix
This commit is contained in:
parent
aa06ba9743
commit
98b9a64423
|
@ -101,6 +101,7 @@ contract Helpers is DSMath {
|
||||||
function getComptrollerAddress() public pure returns (address troller) {
|
function getComptrollerAddress() public pure returns (address troller) {
|
||||||
troller = 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B;
|
troller = 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B;
|
||||||
// troller = 0x2EAa9D77AE4D8f9cdD9FAAcd44016E746485bddb; // Rinkeby
|
// troller = 0x2EAa9D77AE4D8f9cdD9FAAcd44016E746485bddb; // Rinkeby
|
||||||
|
// troller = 0x3CA5a0E85aD80305c2d2c4982B2f2756f1e747a5; // Kovan
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,6 +119,22 @@ contract Helpers is DSMath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enterMarket(address cErc20) internal {
|
||||||
|
ComptrollerInterface troller = ComptrollerInterface(getComptrollerAddress());
|
||||||
|
address[] memory markets = troller.getAssetsIn(address(this));
|
||||||
|
bool isEntered = false;
|
||||||
|
for (uint i = 0; i < markets.length; i++) {
|
||||||
|
if (markets[i] == cErc20) {
|
||||||
|
isEntered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isEntered) {
|
||||||
|
address[] memory toEnter = new address[](1);
|
||||||
|
toEnter[0] = cErc20;
|
||||||
|
troller.enterMarkets(toEnter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,6 +149,7 @@ contract CompoundResolver is Helpers {
|
||||||
* @dev Deposit ETH/ERC20 and mint Compound Tokens
|
* @dev Deposit ETH/ERC20 and mint Compound Tokens
|
||||||
*/
|
*/
|
||||||
function mintCToken(address erc20, address cErc20, uint tokenAmt) external payable {
|
function mintCToken(address erc20, address cErc20, uint tokenAmt) external payable {
|
||||||
|
enterMarket(cErc20);
|
||||||
if (erc20 == getAddressETH()) {
|
if (erc20 == getAddressETH()) {
|
||||||
CETHInterface cToken = CETHInterface(cErc20);
|
CETHInterface cToken = CETHInterface(cErc20);
|
||||||
cToken.mint.value(msg.value)();
|
cToken.mint.value(msg.value)();
|
||||||
|
@ -202,19 +220,7 @@ contract CompoundResolver is Helpers {
|
||||||
* @dev borrow ETH/ERC20
|
* @dev borrow ETH/ERC20
|
||||||
*/
|
*/
|
||||||
function borrow(address erc20, address cErc20, uint tokenAmt) external {
|
function borrow(address erc20, address cErc20, uint tokenAmt) external {
|
||||||
ComptrollerInterface troller = ComptrollerInterface(getComptrollerAddress());
|
enterMarket(cErc20);
|
||||||
address[] memory markets = troller.getAssetsIn(address(this));
|
|
||||||
bool isEntered = false;
|
|
||||||
for (uint i = 0; i < markets.length; i++) {
|
|
||||||
if (markets[i] == cErc20) {
|
|
||||||
isEntered = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isEntered) {
|
|
||||||
address[] memory toEnter = new address[](1);
|
|
||||||
toEnter[0] = cErc20;
|
|
||||||
troller.enterMarkets(toEnter);
|
|
||||||
}
|
|
||||||
require(CTokenInterface(cErc20).borrow(tokenAmt) == 0, "got collateral?");
|
require(CTokenInterface(cErc20).borrow(tokenAmt) == 0, "got collateral?");
|
||||||
transferToken(erc20);
|
transferToken(erc20);
|
||||||
emit LogBorrow(
|
emit LogBorrow(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user