mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
code structure & some small error
This commit is contained in:
parent
08c0f86432
commit
d160b758c9
|
@ -309,8 +309,8 @@ contract MakerHelpers is Helpers {
|
||||||
|
|
||||||
(bytes32 val, bool ok) = tub.pep().peek();
|
(bytes32 val, bool ok) = tub.pep().peek();
|
||||||
|
|
||||||
// MKR required for wipe = Stability fees accrued in Dai / MKRUSD value
|
// tub.rap(cup) = stability fee in $, tub.tab(cup) = total DAI debt
|
||||||
uint mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val));
|
uint mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), add(tub.rap(cup), tub.tab(cup)))), uint(val));
|
||||||
|
|
||||||
uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
||||||
uint daiAmt = sub(_wad, daiFeeAmt);
|
uint daiAmt = sub(_wad, daiFeeAmt);
|
||||||
|
@ -318,7 +318,7 @@ contract MakerHelpers is Helpers {
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
daiEx.tokenToTokenSwapOutput(
|
daiEx.tokenToTokenSwapOutput(
|
||||||
mkrFee,
|
mkrFee,
|
||||||
daiAmt,
|
daiFeeAmt,
|
||||||
uint(999000000000000000000),
|
uint(999000000000000000000),
|
||||||
uint(1899063809), // 6th March 2030 GMT // no logic
|
uint(1899063809), // 6th March 2030 GMT // no logic
|
||||||
address(mkr)
|
address(mkr)
|
||||||
|
@ -329,7 +329,7 @@ contract MakerHelpers is Helpers {
|
||||||
|
|
||||||
emit LogWipe(
|
emit LogWipe(
|
||||||
cdpNum,
|
cdpNum,
|
||||||
daiAmt,
|
_wad,
|
||||||
mkrFee,
|
mkrFee,
|
||||||
daiFeeAmt,
|
daiFeeAmt,
|
||||||
address(this)
|
address(this)
|
||||||
|
@ -463,16 +463,21 @@ contract Save is GetDetails {
|
||||||
address affiliate
|
address affiliate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function getColToFree(uint ethCol, uint daiDebt, uint usdPerEth) internal pure returns (uint colToFree) {
|
||||||
|
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
|
||||||
|
uint minColNeeded = add(wmul(daiDebt, 1500000000000000000), 10);
|
||||||
|
colToFree = sub(wdiv(sub(colToUSD, minColNeeded), usdPerEth), 10);
|
||||||
|
}
|
||||||
|
|
||||||
function save(uint cdpID, uint colToSwap) public {
|
function save(uint cdpID, uint colToSwap) public {
|
||||||
bytes32 cup = bytes32(cdpID);
|
bytes32 cup = bytes32(cdpID);
|
||||||
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
||||||
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
|
uint colToFree = getColToFree(ethCol, daiDebt, usdPerEth);
|
||||||
uint minColNeeded = add(wmul(daiDebt, 1500000000000000000), 10);
|
|
||||||
uint colToFree = sub(wdiv(sub(colToUSD, minColNeeded), usdPerEth), 10);
|
|
||||||
require(colToFree != 0, "No-collatral-to-free");
|
require(colToFree != 0, "No-collatral-to-free");
|
||||||
if (colToSwap < colToFree) {
|
if (colToSwap < colToFree) {
|
||||||
colToFree = colToSwap;
|
colToFree = colToSwap;
|
||||||
}
|
}
|
||||||
|
uint thisBalance = address(this).balance;
|
||||||
free(cdpID, colToFree);
|
free(cdpID, colToFree);
|
||||||
uint ethToSwap = wdiv(wmul(colToFree, 99750000000000000000), 100000000000000000000);
|
uint ethToSwap = wdiv(wmul(colToFree, 99750000000000000000), 100000000000000000000);
|
||||||
getAddressAdmin().transfer(sub(colToFree, ethToSwap));
|
getAddressAdmin().transfer(sub(colToFree, ethToSwap));
|
||||||
|
@ -481,12 +486,17 @@ contract Save is GetDetails {
|
||||||
colToFree,
|
colToFree,
|
||||||
getAddressDAI(),
|
getAddressDAI(),
|
||||||
address(this),
|
address(this),
|
||||||
2**255,
|
daiDebt,
|
||||||
0,
|
0,
|
||||||
getAddressAdmin()
|
getAddressAdmin()
|
||||||
);
|
);
|
||||||
wipe(cdpID, destAmt);
|
wipe(cdpID, destAmt);
|
||||||
|
|
||||||
|
if (thisBalance < address(this).balance) {
|
||||||
|
uint balToLock = address(this).balance - thisBalance;
|
||||||
|
lock(cdpID, balToLock);
|
||||||
|
}
|
||||||
|
|
||||||
emit LogTrade(
|
emit LogTrade(
|
||||||
2,
|
2,
|
||||||
getAddressETH(),
|
getAddressETH(),
|
||||||
|
@ -499,12 +509,16 @@ contract Save is GetDetails {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDebtToBorrow(uint ethCol, uint daiDebt, uint usdPerEth) internal pure returns (uint debtToBorrow) {
|
||||||
|
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
|
||||||
|
uint maxDebtLimit = sub(wdiv(colToUSD, 1500000000000000000), 10);
|
||||||
|
debtToBorrow = sub(maxDebtLimit, daiDebt);
|
||||||
|
}
|
||||||
|
|
||||||
function leverage(uint cdpID, uint daiToSwap) public {
|
function leverage(uint cdpID, uint daiToSwap) public {
|
||||||
bytes32 cup = bytes32(cdpID);
|
bytes32 cup = bytes32(cdpID);
|
||||||
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
(uint ethCol, uint daiDebt, uint usdPerEth) = getCDPStats(cup);
|
||||||
uint colToUSD = sub(wmul(ethCol, usdPerEth), 10);
|
uint debtToBorrow = getDebtToBorrow(ethCol, daiDebt, usdPerEth);
|
||||||
uint maxDebtLimit = sub(wdiv(colToUSD, 1500000000000000000), 10);
|
|
||||||
uint debtToBorrow = sub(maxDebtLimit, daiDebt);
|
|
||||||
require(debtToBorrow != 0, "No-debt-to-borrow");
|
require(debtToBorrow != 0, "No-debt-to-borrow");
|
||||||
if (daiToSwap < debtToBorrow) {
|
if (daiToSwap < debtToBorrow) {
|
||||||
debtToBorrow = daiToSwap;
|
debtToBorrow = daiToSwap;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user