mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
getFinalPosition function in process
This commit is contained in:
parent
16fee374ed
commit
1d690337cd
|
@ -21,6 +21,10 @@ interface TubInterface {
|
|||
function per() external view returns (uint);
|
||||
}
|
||||
|
||||
interface oracleInterface {
|
||||
function read() external view returns (bytes32);
|
||||
}
|
||||
|
||||
interface IERC20 {
|
||||
function allowance(address, address) external view returns (uint);
|
||||
function balanceOf(address) external view returns (uint);
|
||||
|
@ -56,6 +60,10 @@ contract DSMath {
|
|||
require((z = x + y) >= x, "math-not-safe");
|
||||
}
|
||||
|
||||
function sub(uint x, uint y) internal pure returns (uint z) {
|
||||
require((z = x - y) <= x, "ds-math-sub-underflow");
|
||||
}
|
||||
|
||||
function mul(uint x, uint y) internal pure returns (uint z) {
|
||||
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
|
||||
}
|
||||
|
@ -71,6 +79,10 @@ contract DSMath {
|
|||
z = add(mul(x, RAY), y / 2) / y;
|
||||
}
|
||||
|
||||
function wmul(uint x, uint y) internal pure returns (uint z) {
|
||||
z = add(mul(x, y), WAD / 2) / WAD;
|
||||
}
|
||||
|
||||
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
||||
z = add(mul(x, WAD), y / 2) / y;
|
||||
}
|
||||
|
@ -87,6 +99,13 @@ contract Helpers is DSMath {
|
|||
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get MakerDAO Oracle for ETH price
|
||||
*/
|
||||
function getOracleAddress() public pure returns (address oracle) {
|
||||
oracle = 0x729D19f657BD0614b4985Cf1D82531c67569197B;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get uniswap MKR exchange
|
||||
*/
|
||||
|
@ -184,6 +203,18 @@ contract Helpers is DSMath {
|
|||
|
||||
contract Save is Helpers {
|
||||
|
||||
|
||||
function getFinalPosition(uint cdpID) public view returns (uint finalEthCol, uint finalDaiDebt) {
|
||||
bytes32 cdpToBytes = bytes32(cdpID);
|
||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||
uint usdPerEth = uint(oracleInterface(getOracleAddress()).read());
|
||||
(, uint pethCol, uint daiDebt,) = tub.cups(cdpToBytes);
|
||||
uint ethCol = rmul(pethCol, tub.per()); // get ETH col from PETH col
|
||||
uint colToUSD = wmul(ethCol, usdPerEth) - 10;
|
||||
uint ratio = rdiv(colToUSD, daiDebt);
|
||||
uint minRatio = 1500000000000000000;
|
||||
require(ratio > minRatio, "No-margin-to-leverage");
|
||||
uint minColNeeded = wmul(daiDebt, minRatio) + 10;
|
||||
uint colToFree = sub(colToUSD, minColNeeded);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user