mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
bridge completed
This commit is contained in:
parent
17d0894bcc
commit
13d668e5c4
|
@ -174,11 +174,11 @@ contract CompoundHelper is MakerHelper {
|
||||||
/**
|
/**
|
||||||
* @dev borrow ETH/ERC20
|
* @dev borrow ETH/ERC20
|
||||||
*/
|
*/
|
||||||
function borrowDai(uint tokenAmt) internal {
|
function borrowDAI(uint tokenAmt) internal {
|
||||||
|
enterMarket(getCETHAddress());
|
||||||
enterMarket(getCDAIAddress());
|
enterMarket(getCDAIAddress());
|
||||||
CTokenInterface cDaiContract = CTokenInterface(getCDAIAddress());
|
CTokenInterface cDaiContract = CTokenInterface(getCDAIAddress());
|
||||||
require(cDaiContract.borrow(tokenAmt) == 0, "got collateral?");
|
require(cDaiContract.borrow(tokenAmt) == 0, "got collateral?");
|
||||||
cDaiContract.transfer(getBridgeAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,8 @@ contract InstaBridge is CompoundHelper {
|
||||||
give(cdpId, getBridgeAddress());
|
give(cdpId, getBridgeAddress());
|
||||||
BridgeInterface bridge = BridgeInterface(getBridgeAddress());
|
BridgeInterface bridge = BridgeInterface(getBridgeAddress());
|
||||||
uint daiAmt = bridge.makerToCompound(cdpId, ethCol, daiDebt);
|
uint daiAmt = bridge.makerToCompound(cdpId, ethCol, daiDebt);
|
||||||
// setApproval(getDaiAddress(), daiAmt, getBridgeAddress());
|
borrowDAI(daiAmt);
|
||||||
|
setApproval(getDaiAddress(), daiAmt, getBridgeAddress());
|
||||||
bridge.takeDebtBack(daiAmt);
|
bridge.takeDebtBack(daiAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +200,7 @@ contract InstaBridge is CompoundHelper {
|
||||||
give(cdpId, getBridgeAddress());
|
give(cdpId, getBridgeAddress());
|
||||||
}
|
}
|
||||||
BridgeInterface bridge = BridgeInterface(getBridgeAddress());
|
BridgeInterface bridge = BridgeInterface(getBridgeAddress());
|
||||||
// setApproval(getCEthAddress(), daiAmt, getBridgeAddress());
|
setApproval(getCEthAddress(), 2**150, getBridgeAddress());
|
||||||
uint daiAmt = bridge.compoundToMaker(cdpId, ethCol, daiDebt);
|
uint daiAmt = bridge.compoundToMaker(cdpId, ethCol, daiDebt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ contract Helper is DSMath {
|
||||||
|
|
||||||
address public ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
address public ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||||
address public daiAddr = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
|
address public daiAddr = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
|
||||||
address public cdaiAddr = 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC;
|
|
||||||
address public registryAddr = 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC;
|
address public registryAddr = 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC;
|
||||||
address public sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
address public sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
address public ume = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3; // Uniswap Maker Exchange
|
address public ume = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3; // Uniswap Maker Exchange
|
||||||
|
@ -132,6 +131,12 @@ contract Helper is DSMath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setAllowance(ERC20Interface _token, address _spender) internal {
|
||||||
|
if (_token.allowance(address(this), _spender) != uint(-1)) {
|
||||||
|
_token.approve(_spender, uint(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modifier isUserWallet {
|
modifier isUserWallet {
|
||||||
address userAdd = UserWalletInterface(msg.sender).owner();
|
address userAdd = UserWalletInterface(msg.sender).owner();
|
||||||
address walletAdd = RegistryInterface(registryAddr).proxies(userAdd);
|
address walletAdd = RegistryInterface(registryAddr).proxies(userAdd);
|
||||||
|
@ -140,6 +145,18 @@ contract Helper is DSMath {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Redeem ETH/ERC20 and mint Compound Tokens
|
||||||
|
* @param tokenAmt Amount of token To Redeem
|
||||||
|
*/
|
||||||
|
function redeemUnderlying(address cErc20, uint tokenAmt) internal {
|
||||||
|
CTokenInterface cToken = CTokenInterface(cErc20);
|
||||||
|
uint toBurn = cToken.balanceOf(address(this));
|
||||||
|
uint tokenToReturn = wmul(toBurn, cToken.exchangeRateCurrent());
|
||||||
|
tokenToReturn = tokenToReturn > tokenAmt ? tokenAmt : tokenToReturn;
|
||||||
|
require(cToken.redeemUnderlying(tokenToReturn) == 0, "something went wrong");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,7 +189,7 @@ contract MakerResolver is Helper {
|
||||||
TubInterface tub = TubInterface(sai);
|
TubInterface tub = TubInterface(sai);
|
||||||
UniswapExchange daiEx = UniswapExchange(ude);
|
UniswapExchange daiEx = UniswapExchange(ude);
|
||||||
UniswapExchange mkrEx = UniswapExchange(ume);
|
UniswapExchange mkrEx = UniswapExchange(ume);
|
||||||
// ERC20Interface dai = tub.sai();
|
ERC20Interface dai = tub.sai();
|
||||||
ERC20Interface mkr = tub.gov();
|
ERC20Interface mkr = tub.gov();
|
||||||
|
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
@ -180,9 +197,9 @@ contract MakerResolver is Helper {
|
||||||
(address lad,,,) = tub.cups(cup);
|
(address lad,,,) = tub.cups(cup);
|
||||||
require(lad == address(this), "cup-not-owned");
|
require(lad == address(this), "cup-not-owned");
|
||||||
|
|
||||||
// setAllowance(dai, sai);
|
setAllowance(dai, sai);
|
||||||
// setAllowance(mkr, sai);
|
setAllowance(mkr, sai);
|
||||||
// setAllowance(dai, ude);
|
setAllowance(dai, ude);
|
||||||
|
|
||||||
(bytes32 val, bool ok) = tub.pep().peek();
|
(bytes32 val, bool ok) = tub.pep().peek();
|
||||||
|
|
||||||
|
@ -191,7 +208,8 @@ contract MakerResolver is Helper {
|
||||||
|
|
||||||
uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
||||||
daiAmt = add(_wad, daiFeeAmt);
|
daiAmt = add(_wad, daiFeeAmt);
|
||||||
// require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
|
|
||||||
|
redeemUnderlying(cDai, daiAmt);
|
||||||
|
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
daiEx.tokenToTokenSwapOutput(
|
daiEx.tokenToTokenSwapOutput(
|
||||||
|
@ -222,21 +240,20 @@ contract MakerResolver is Helper {
|
||||||
address tubAddr = sai;
|
address tubAddr = sai;
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
// ERC20Interface peth = tub.skr();
|
ERC20Interface peth = tub.skr();
|
||||||
ERC20Interface weth = tub.gem();
|
ERC20Interface weth = tub.gem();
|
||||||
|
|
||||||
uint ink = rdiv(jam, tub.per());
|
uint ink = rdiv(jam, tub.per());
|
||||||
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
||||||
tub.free(cup, ink);
|
tub.free(cup, ink);
|
||||||
|
|
||||||
// setAllowance(peth, tubAddr);
|
setAllowance(peth, tubAddr);
|
||||||
|
|
||||||
|
|
||||||
tub.exit(ink);
|
tub.exit(ink);
|
||||||
uint freeJam = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
uint freeJam = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
||||||
weth.withdraw(freeJam);
|
weth.withdraw(freeJam);
|
||||||
|
|
||||||
// address(msg.sender).transfer(freeJam);
|
|
||||||
|
|
||||||
emit LogFree(
|
emit LogFree(
|
||||||
cdpNum,
|
cdpNum,
|
||||||
freeJam,
|
freeJam,
|
||||||
|
@ -253,7 +270,7 @@ contract MakerResolver is Helper {
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
ERC20Interface weth = tub.gem();
|
ERC20Interface weth = tub.gem();
|
||||||
// ERC20Interface peth = tub.skr();
|
ERC20Interface peth = tub.skr();
|
||||||
|
|
||||||
(address lad,,,) = tub.cups(cup);
|
(address lad,,,) = tub.cups(cup);
|
||||||
require(lad == address(this), "cup-not-owned");
|
require(lad == address(this), "cup-not-owned");
|
||||||
|
@ -263,10 +280,10 @@ contract MakerResolver is Helper {
|
||||||
uint ink = rdiv(ethAmt, tub.per());
|
uint ink = rdiv(ethAmt, tub.per());
|
||||||
ink = rmul(ink, tub.per()) <= ethAmt ? ink : ink - 1;
|
ink = rmul(ink, tub.per()) <= ethAmt ? ink : ink - 1;
|
||||||
|
|
||||||
// setAllowance(weth, tubAddr);
|
setAllowance(weth, tubAddr);
|
||||||
tub.join(ink);
|
tub.join(ink);
|
||||||
|
|
||||||
// setAllowance(peth, tubAddr);
|
setAllowance(peth, tubAddr);
|
||||||
tub.lock(cup, ink);
|
tub.lock(cup, ink);
|
||||||
|
|
||||||
emit LogLock(
|
emit LogLock(
|
||||||
|
@ -284,7 +301,6 @@ contract MakerResolver is Helper {
|
||||||
TubInterface tub = TubInterface(sai);
|
TubInterface tub = TubInterface(sai);
|
||||||
|
|
||||||
tub.draw(cup, _wad);
|
tub.draw(cup, _wad);
|
||||||
// tub.sai().transfer(msg.sender, _wad);
|
|
||||||
|
|
||||||
emit LogDraw(cdpNum, _wad, address(this));
|
emit LogDraw(cdpNum, _wad, address(this));
|
||||||
}
|
}
|
||||||
|
@ -335,7 +351,6 @@ contract CompoundResolver is MakerResolver {
|
||||||
toDeposit = toDeposit > tokenAmt ? tokenAmt : toDeposit;
|
toDeposit = toDeposit > tokenAmt ? tokenAmt : toDeposit;
|
||||||
token.transferFrom(msg.sender, address(this), toDeposit);
|
token.transferFrom(msg.sender, address(this), toDeposit);
|
||||||
CDAIInterface cToken = CDAIInterface(cDai);
|
CDAIInterface cToken = CDAIInterface(cDai);
|
||||||
// setApproval(erc20, toDeposit, cErc20);
|
|
||||||
assert(cToken.mint(toDeposit) == 0);
|
assert(cToken.mint(toDeposit) == 0);
|
||||||
emit LogMint(
|
emit LogMint(
|
||||||
daiAddr,
|
daiAddr,
|
||||||
|
@ -345,19 +360,6 @@ contract CompoundResolver is MakerResolver {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Redeem ETH/ERC20 and mint Compound Tokens
|
|
||||||
* @param tokenAmt Amount of token To Redeem
|
|
||||||
*/
|
|
||||||
function redeemUnderlying(address cErc20, uint tokenAmt) internal {
|
|
||||||
CTokenInterface cToken = CTokenInterface(cErc20);
|
|
||||||
// setApproval(cErc20, 10**50, cErc20);
|
|
||||||
uint toBurn = cToken.balanceOf(address(this));
|
|
||||||
uint tokenToReturn = wmul(toBurn, cToken.exchangeRateCurrent());
|
|
||||||
tokenToReturn = tokenToReturn > tokenAmt ? tokenAmt : tokenToReturn;
|
|
||||||
require(cToken.redeemUnderlying(tokenToReturn) == 0, "something went wrong");
|
|
||||||
}
|
|
||||||
|
|
||||||
function takeCETH(uint ethAmt) internal {
|
function takeCETH(uint ethAmt) internal {
|
||||||
CTokenInterface cToken = CTokenInterface(cEth);
|
CTokenInterface cToken = CTokenInterface(cEth);
|
||||||
uint cTokenAmt = wdiv(ethAmt, cToken.exchangeRateCurrent());
|
uint cTokenAmt = wdiv(ethAmt, cToken.exchangeRateCurrent());
|
||||||
|
@ -373,7 +375,6 @@ contract Bridge is CompoundResolver {
|
||||||
|
|
||||||
function payUsersDebt(uint daiDebt) internal {
|
function payUsersDebt(uint daiDebt) internal {
|
||||||
redeemUnderlying(cDai, daiDebt);
|
redeemUnderlying(cDai, daiDebt);
|
||||||
// setApproval(dai, daiDebt, cDai);
|
|
||||||
require(CDAIInterface(cDai).repayBorrowBehalf(msg.sender, daiDebt) == 0, "Enough DAI?");
|
require(CDAIInterface(cDai).repayBorrowBehalf(msg.sender, daiDebt) == 0, "Enough DAI?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +411,9 @@ contract MakerCompBridge is Bridge {
|
||||||
* 1...2...3 versioning in each subsequent deployments
|
* 1...2...3 versioning in each subsequent deployments
|
||||||
*/
|
*/
|
||||||
constructor(uint _version) public {
|
constructor(uint _version) public {
|
||||||
setApproval(daiAddr, 10**30, cdaiAddr);
|
setApproval(daiAddr, 10**30, cDai);
|
||||||
setApproval(cdaiAddr, 10**30, cdaiAddr);
|
setApproval(cDai, 10**30, cDai);
|
||||||
|
setApproval(cEth, 10**30, cEth);
|
||||||
version = _version;
|
version = _version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user