contract payable

This commit is contained in:
Samyak Jain 2019-06-12 13:49:25 +05:30
parent b9979795cb
commit b6430ee85a
2 changed files with 48 additions and 2 deletions

View File

@ -50,6 +50,7 @@ interface UniswapExchange {
interface BridgeInterface { interface BridgeInterface {
function transferDAI(uint) external; function transferDAI(uint) external;
function transferBackDAI(uint) external;
} }
interface CTokenInterface { interface CTokenInterface {
@ -313,7 +314,8 @@ contract MakerHelper is Helper {
TubInterface tub = TubInterface(getSaiTubAddress()); TubInterface tub = TubInterface(getSaiTubAddress());
tub.draw(cup, _wad); tub.draw(cup, _wad);
ERC20Interface(getDAIAddress()).transfer(getBridgeAddress(), _wad); setApproval(getDAIAddress(), _wad, getBridgeAddress());
BridgeInterface(getBridgeAddress()).transferBackDAI(_wad);
emit LogDraw(uint(cup), _wad, address(this)); emit LogDraw(uint(cup), _wad, address(this));
} }
@ -438,7 +440,8 @@ contract CompoundHelper is MakerHelper {
function borrowDAIComp(address erc20, address cErc20, uint tokenAmt) internal { function borrowDAIComp(address erc20, address cErc20, uint tokenAmt) internal {
enterMarket(cErc20); enterMarket(cErc20);
require(CTokenInterface(cErc20).borrow(tokenAmt) == 0, "got collateral?"); require(CTokenInterface(cErc20).borrow(tokenAmt) == 0, "got collateral?");
ERC20Interface(erc20).transfer(getBridgeAddress(), tokenAmt); setApproval(erc20, tokenAmt, getBridgeAddress());
BridgeInterface(getBridgeAddress()).transferBackDAI(tokenAmt);
emit LogBorrow( emit LogBorrow(
erc20, erc20,
cErc20, cErc20,
@ -507,6 +510,7 @@ contract Bridge is CompoundHelper {
/** /**
* @dev convert Compound Collateral into Maker CDP * @dev convert Compound Collateral into Maker CDP
* @param cdpId = 0, if user don't have any CDP
* @param toConvert ranges from 0 to 1 and has (18 decimals) * @param toConvert ranges from 0 to 1 and has (18 decimals)
*/ */
function compoundToMaker(uint cdpId, uint toConvert) public { function compoundToMaker(uint cdpId, uint toConvert) public {
@ -530,4 +534,21 @@ contract Bridge is CompoundHelper {
draw(cup, daiAmt); draw(cup, daiAmt);
} }
}
contract InstaBridge is Bridge {
uint public version;
/**
* @dev setting up variables on deployment
* 1...2...3 versioning in each subsequent deployments
*/
constructor(uint _version) public {
version = _version;
}
function() external payable {}
} }

View File

@ -118,4 +118,29 @@ contract Bridge is Helper {
ERC20Interface(daiAdd).transfer(msg.sender, amt); ERC20Interface(daiAdd).transfer(msg.sender, amt);
} }
function transferBackDAI(uint amt) public {
require(RegistryInterface(registryAdd).proxies(msg.sender) != address(0), "Not-User-Wallet");
ERC20Interface tokenContract = ERC20Interface(daiAdd);
tokenContract.transferFrom(msg.sender, address(this), amt);
CTokenInterface cToken = CTokenInterface(cDaiAdd);
assert(cToken.mint(amt) == 0);
}
}
contract MakerCompBridge is Bridge {
uint public version;
/**
* @dev setting up variables on deployment
* 1...2...3 versioning in each subsequent deployments
*/
constructor(uint _version) public {
version = _version;
}
function() external payable {}
} }