mirror of
https://github.com/Instadapp/InstaContract.git
synced 2024-07-29 22:47:45 +00:00
Added payTo & Claim external CDP feature.
This commit is contained in:
parent
7db7156ad7
commit
7a891eab62
|
@ -41,6 +41,7 @@ interface MakerCDP {
|
||||||
function draw(bytes32 cup, uint wad) external;
|
function draw(bytes32 cup, uint wad) external;
|
||||||
function wipe(bytes32 cup, uint wad) external;
|
function wipe(bytes32 cup, uint wad) external;
|
||||||
function per() external view returns (uint ray);
|
function per() external view returns (uint ray);
|
||||||
|
function lad(bytes32 cup) external view returns (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PriceInterface {
|
interface PriceInterface {
|
||||||
|
@ -104,7 +105,7 @@ contract GlobalVar is Registry {
|
||||||
contract IssueLoan is GlobalVar {
|
contract IssueLoan is GlobalVar {
|
||||||
|
|
||||||
event LockedETH(address borrower, uint lockETH, uint lockPETH, address lockedBy);
|
event LockedETH(address borrower, uint lockETH, uint lockPETH, address lockedBy);
|
||||||
event LoanedDAI(address borrower, uint loanDAI);
|
event LoanedDAI(address borrower, uint loanDAI, address payTo);
|
||||||
event NewCDP(address borrower, bytes32 cdpBytes);
|
event NewCDP(address borrower, bytes32 cdpBytes);
|
||||||
|
|
||||||
function pethPEReth(uint ethNum) public view returns (uint rPETH) {
|
function pethPEReth(uint ethNum) public view returns (uint rPETH) {
|
||||||
|
@ -112,9 +113,9 @@ contract IssueLoan is GlobalVar {
|
||||||
rPETH = (ethNum.mul(10 ** 27)).div(loanMaster.per());
|
rPETH = (ethNum.mul(10 ** 27)).div(loanMaster.per());
|
||||||
}
|
}
|
||||||
|
|
||||||
function borrow(uint daiDraw) public payable {
|
function borrow(uint daiDraw, address beneficiary) public payable {
|
||||||
if (msg.value > 0) {lockETH(msg.sender);}
|
if (msg.value > 0) {lockETH(msg.sender);}
|
||||||
if (daiDraw > 0) {drawDAI(daiDraw);}
|
if (daiDraw > 0) {drawDAI(daiDraw, beneficiary);}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lockETH(address borrower) public payable {
|
function lockETH(address borrower) public payable {
|
||||||
|
@ -134,13 +135,17 @@ contract IssueLoan is GlobalVar {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawDAI(uint daiDraw) public {
|
function drawDAI(uint daiDraw, address beneficiary) public {
|
||||||
require(!freezed, "Operation Disabled");
|
require(!freezed, "Operation Disabled");
|
||||||
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
||||||
loanMaster.draw(cdps[msg.sender], daiDraw);
|
loanMaster.draw(cdps[msg.sender], daiDraw);
|
||||||
IERC20 daiTkn = IERC20(getAddress("dai"));
|
IERC20 daiTkn = IERC20(getAddress("dai"));
|
||||||
daiTkn.transfer(msg.sender, daiDraw);
|
address payTo = msg.sender;
|
||||||
emit LoanedDAI(msg.sender, daiDraw);
|
if (payTo != address(0)) {
|
||||||
|
payTo = beneficiary;
|
||||||
|
}
|
||||||
|
daiTkn.transfer(payTo, daiDraw);
|
||||||
|
emit LoanedDAI(msg.sender, daiDraw, payTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -221,6 +226,7 @@ contract RepayLoan is IssueLoan {
|
||||||
contract BorrowTasks is RepayLoan {
|
contract BorrowTasks is RepayLoan {
|
||||||
|
|
||||||
event TranferCDP(bytes32 cdp, address owner, address nextOwner);
|
event TranferCDP(bytes32 cdp, address owner, address nextOwner);
|
||||||
|
event CDPClaimed(bytes32 cdp, address owner);
|
||||||
|
|
||||||
function transferCDP(address nextOwner) public {
|
function transferCDP(address nextOwner) public {
|
||||||
require(nextOwner != 0, "Invalid Address.");
|
require(nextOwner != 0, "Invalid Address.");
|
||||||
|
@ -230,6 +236,14 @@ contract BorrowTasks is RepayLoan {
|
||||||
emit TranferCDP(cdps[msg.sender], msg.sender, nextOwner);
|
emit TranferCDP(cdps[msg.sender], msg.sender, nextOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function claimCDP(uint cdpNum) public {
|
||||||
|
bytes32 cdpBytes = bytes32(cdpNum);
|
||||||
|
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
||||||
|
address cdpOwner = loanMaster.lad(cdpBytes);
|
||||||
|
cdps[cdpOwner] = cdpBytes;
|
||||||
|
emit CDPClaimed(cdpBytes, msg.sender);
|
||||||
|
}
|
||||||
|
|
||||||
function getETHRate() public view returns (uint) {
|
function getETHRate() public view returns (uint) {
|
||||||
PriceInterface ethRate = PriceInterface(getAddress("ethfeed"));
|
PriceInterface ethRate = PriceInterface(getAddress("ethfeed"));
|
||||||
bytes32 ethrate;
|
bytes32 ethrate;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user