fix one wei discrepency who appear during debt reading from insta maker resolver

This commit is contained in:
Shivva 2020-10-27 19:11:44 +01:00 committed by Luis Schliesske
parent d17a2acd97
commit 9fb2c4aaac
3 changed files with 65 additions and 43 deletions

View File

@ -20,22 +20,29 @@ interface GelatoGasPriceOracle {
function latestAnswer() external view returns (int256); function latestAnswer() external view returns (int256);
} }
interface IMakerResolver { interface ManagerLike {
struct VaultData { function ilks(uint256) external view returns (bytes32);
uint256 id;
address owner;
string colType;
uint256 collateral;
uint256 art;
uint256 debt;
uint256 liquidatedCol;
uint256 borrowRate;
uint256 colPrice;
uint256 liquidationRatio;
address vaultAddress;
}
function getVaultById(uint256 id) external view returns (VaultData memory); function urns(uint256) external view returns (address);
function vat() external view returns (address);
}
interface VatLike {
function ilks(bytes32)
external
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256
);
function dai(address) external view returns (uint256);
function urns(bytes32, address) external view returns (uint256, uint256);
} }
library GelatoBytes { library GelatoBytes {
@ -152,6 +159,13 @@ abstract contract DSMath {
abstract contract Helpers is ConnectorInterface, DSMath { abstract contract Helpers is ConnectorInterface, DSMath {
uint256 internal __id; uint256 internal __id;
/**
* @dev Return Maker MCD Manager Address.
*/
function getMcdManager() internal pure returns (address) {
return 0x5ef30b9986345249bc32d8928B7ee64DE9435E39;
}
/** /**
* @dev Return ethereum address * @dev Return ethereum address
*/ */
@ -226,16 +240,36 @@ abstract contract GelatoHelpers is Helpers {
} }
abstract contract MakerResolver is GelatoHelpers { abstract contract MakerResolver is GelatoHelpers {
function getMakerVault(uint256 _vaultId) function _getVaultData(ManagerLike cdpManager, uint256 vault)
public internal
view view
returns (IMakerResolver.VaultData memory) returns (bytes32 ilk, address urn)
{ {
return IMakerResolver(_getMakerResolver()).getVaultById(_vaultId); ilk = cdpManager.ilks(vault);
urn = cdpManager.urns(vault);
} }
function getMakerVaultDebt(uint256 _vaultId) public view returns (uint256) { function _getManager() internal pure returns (ManagerLike) {
return getMakerVault(_vaultId).debt; return ManagerLike(getMcdManager());
}
function getMakerVaultDebt(uint256 _vaultId)
public
view
returns (uint256 wad)
{
ManagerLike cdpManager = _getManager();
(bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId);
VatLike vat = VatLike(cdpManager.vat());
(, uint256 rate, , , ) = VatLike(vat).ilks(ilk);
(, uint256 art) = VatLike(vat).urns(ilk, urn);
uint256 dai = VatLike(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) function getMakerVaultCollateralBalance(uint256 _vaultId)
@ -243,19 +277,13 @@ abstract contract MakerResolver is GelatoHelpers {
view view
returns (uint256) returns (uint256)
{ {
return getMakerVault(_vaultId).collateral; ManagerLike cdpManager = _getManager();
}
function getMakerVaultCollateralType(uint256 _vaultId) VatLike vat = VatLike(cdpManager.vat());
public (bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId);
view (uint256 ink, ) = vat.urns(ilk, urn);
returns (string memory)
{
return getMakerVault(_vaultId).colType;
}
function _getMakerResolver() internal pure returns (address) { return ink;
return 0x0A7008B38E7015F8C36A49eEbc32513ECA8801E5;
} }
} }

View File

@ -263,10 +263,8 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
// DSA contain 1000 DAI // DSA contain 1000 DAI
expect( expect(
(await contracts.daiToken.balanceOf(contracts.dsa.address)).sub( await contracts.daiToken.balanceOf(contracts.dsa.address)
constants.MAKER_INITIAL_DEBT ).to.be.equal(constants.MAKER_INITIAL_DEBT);
)
).to.be.lte(ethers.utils.parseUnits("1", 0));
//#endregion //#endregion
}); });

View File

@ -241,9 +241,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
); );
// Estimated amount to borrowed token should be equal to the actual one read on compound contracts // Estimated amount to borrowed token should be equal to the actual one read on compound contracts
expect(debtOnMakerBefore.sub(debtOnMakerVaultB)).to.be.lte( expect(debtOnMakerBefore).to.be.equal(debtOnMakerVaultB);
ethers.utils.parseUnits("1", 0)
);
// Estimated amount of collateral should be equal to the actual one read on compound contracts // Estimated amount of collateral should be equal to the actual one read on compound contracts
expect(pricedCollateral).to.be.equal(pricedCollateralOnVaultB); expect(pricedCollateral).to.be.equal(pricedCollateralOnVaultB);
@ -261,10 +259,8 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
// DSA has maximum 2 wei DAI in it due to maths inaccuracies // DSA has maximum 2 wei DAI in it due to maths inaccuracies
expect( expect(
(await contracts.daiToken.balanceOf(contracts.dsa.address)).sub( await contracts.daiToken.balanceOf(contracts.dsa.address)
constants.MAKER_INITIAL_DEBT ).to.be.equal(constants.MAKER_INITIAL_DEBT);
)
).to.be.lte(ethers.utils.parseUnits("1", 0));
//#endregion //#endregion
}); });