mirror of
https://github.com/Instadapp/Gelato-automations.git
synced 2024-07-29 22:28:07 +00:00
44 lines
1.2 KiB
Solidity
44 lines
1.2 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity 0.7.4;
|
|
|
|
import {MCD_MANAGER} from "../../constants/CMaker.sol";
|
|
import {IMcdManager} from "../../interfaces/dapps/Maker/IMcdManager.sol";
|
|
import {IVat} from "../../interfaces/dapps/Maker/IVat.sol";
|
|
import {RAY, sub, mul} from "../../vendor/DSMath.sol";
|
|
|
|
function _getMakerVaultDebt(uint256 _vaultId) view returns (uint256 wad) {
|
|
IMcdManager manager = IMcdManager(MCD_MANAGER);
|
|
|
|
(bytes32 ilk, address urn) = _getVaultData(manager, _vaultId);
|
|
IVat vat = IVat(manager.vat());
|
|
(, uint256 rate, , , ) = vat.ilks(ilk);
|
|
(, uint256 art) = vat.urns(ilk, urn);
|
|
uint256 dai = vat.dai(urn);
|
|
|
|
uint256 rad = sub(mul(art, rate), dai);
|
|
wad = rad / RAY;
|
|
|
|
wad = mul(wad, RAY) < rad ? wad + 1 : wad;
|
|
}
|
|
|
|
function _getMakerVaultCollateralBalance(uint256 _vaultId)
|
|
view
|
|
returns (uint256)
|
|
{
|
|
IMcdManager manager = IMcdManager(MCD_MANAGER);
|
|
|
|
IVat vat = IVat(manager.vat());
|
|
(bytes32 ilk, address urn) = _getVaultData(manager, _vaultId);
|
|
(uint256 ink, ) = vat.urns(ilk, urn);
|
|
|
|
return ink;
|
|
}
|
|
|
|
function _getVaultData(IMcdManager manager, uint256 vault)
|
|
view
|
|
returns (bytes32 ilk, address urn)
|
|
{
|
|
ilk = manager.ilks(vault);
|
|
urn = manager.urns(vault);
|
|
}
|