From a79a785fa7cfe8e2ee4b6fbbb3c3e6a8c1c4e672 Mon Sep 17 00:00:00 2001 From: Shivva Date: Tue, 17 Nov 2020 11:36:02 +0100 Subject: [PATCH] Deal with lack of precision during for some routes --- .../contracts/resolvers/MakerResolver.sol | 11 ++++++++- ...idge-ETHA-ETHB-With-Vault-Creation.test.js | 24 +++++++++++++++---- test/4_Full-Debt-Bridge-ETHA-ETHB.test.js | 24 +++++++++++++++---- ...ebt-Bridge-ETHA-ETHB-Gas-Cost-Mock.test.js | 22 +++++++++++++---- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/contracts/contracts/resolvers/MakerResolver.sol b/contracts/contracts/resolvers/MakerResolver.sol index c9f737b..db6bcc0 100644 --- a/contracts/contracts/resolvers/MakerResolver.sol +++ b/contracts/contracts/resolvers/MakerResolver.sol @@ -3,15 +3,24 @@ pragma solidity 0.7.4; import { _getMakerRawVaultDebt, + _getMakerVaultDebt, _getMakerVaultCollateralBalance } from "../../functions/dapps/FMaker.sol"; contract MakerResolver { /// @dev Return Debt in wad of the vault associated to the vaultId. - function getMakerVaultDebt(uint256 _vaultId) public view returns (uint256) { + function getMakerVaultRawDebt(uint256 _vaultId) + public + view + returns (uint256) + { return _getMakerRawVaultDebt(_vaultId); } + function getMakerVaultDebt(uint256 _vaultId) public view returns (uint256) { + return _getMakerVaultDebt(_vaultId); + } + /// @dev Return Collateral in wad of the vault associated to the vaultId. function getMakerVaultCollateralBalance(uint256 _vaultId) public diff --git a/test/3_Full-Debt-Bridge-ETHA-ETHB-With-Vault-Creation.test.js b/test/3_Full-Debt-Bridge-ETHA-ETHB-With-Vault-Creation.test.js index e5d67e1..58ea569 100644 --- a/test/3_Full-Debt-Bridge-ETHA-ETHB-With-Vault-Creation.test.js +++ b/test/3_Full-Debt-Bridge-ETHA-ETHB-With-Vault-Creation.test.js @@ -197,7 +197,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat // by a debt refinancing in compound. //#region EXPECTED OUTCOME - const debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + let debtOnMakerBefore = await contracts.makerResolver.getMakerVaultRawDebt( vaultAId ); @@ -207,6 +207,12 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat contracts.instaPoolResolver ); + if (route !== 1) { + debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + vaultAId + ); + } + const gasCost = await getGasCostForFullRefinance(route); const gasFeesPaidFromCol = ethers.BigNumber.from(gasCost).mul( @@ -253,9 +259,17 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat let vaultBId = String(cdps.ids[1]); expect(cdps.ids[1].isZero()).to.be.false; - const debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( - vaultBId - ); + let debtOnMakerVaultB; + if (route === 1) { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultRawDebt( + vaultBId + ); + } else { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( + vaultBId + ); + } + const pricedCollateralOnVaultB = await contracts.makerResolver.getMakerVaultCollateralBalance( vaultBId ); @@ -283,7 +297,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat const collateralOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultCollateralBalance( vaultAId ); // in Ether. - const debtOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultDebt( + const debtOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultRawDebt( vaultAId ); diff --git a/test/4_Full-Debt-Bridge-ETHA-ETHB.test.js b/test/4_Full-Debt-Bridge-ETHA-ETHB.test.js index 591ea0e..2355f9a 100644 --- a/test/4_Full-Debt-Bridge-ETHA-ETHB.test.js +++ b/test/4_Full-Debt-Bridge-ETHA-ETHB.test.js @@ -197,7 +197,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { // by a debt refinancing in compound. //#region EXPECTED OUTCOME - const debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + let debtOnMakerBefore = await contracts.makerResolver.getMakerVaultRawDebt( vaultAId ); @@ -207,6 +207,12 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { contracts.instaPoolResolver ); + if (route !== 1) { + debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + vaultAId + ); + } + const gasCost = await getGasCostForFullRefinance(route); const gasFeesPaidFromCol = ethers.BigNumber.from(gasCost).mul( @@ -253,9 +259,17 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { let vaultBId = String(cdps.ids[1]); expect(cdps.ids[1].isZero()).to.be.false; - const debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( - vaultBId - ); + let debtOnMakerVaultB; + if (route === 1) { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultRawDebt( + vaultBId + ); + } else { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( + vaultBId + ); + } + const pricedCollateralOnVaultB = await contracts.makerResolver.getMakerVaultCollateralBalance( vaultBId ); @@ -283,7 +297,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { const collateralOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultCollateralBalance( vaultAId ); // in Ether. - const debtOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultDebt( + const debtOnMakerOnVaultAAfter = await contracts.makerResolver.getMakerVaultRawDebt( vaultAId ); diff --git a/test/5_Full-Debt-Bridge-ETHA-ETHB-Gas-Cost-Mock.test.js b/test/5_Full-Debt-Bridge-ETHA-ETHB-Gas-Cost-Mock.test.js index 26c9853..5a05974 100644 --- a/test/5_Full-Debt-Bridge-ETHA-ETHB-Gas-Cost-Mock.test.js +++ b/test/5_Full-Debt-Bridge-ETHA-ETHB-Gas-Cost-Mock.test.js @@ -197,7 +197,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B For Gas Measurem // by a debt refinancing in compound. //#region EXPECTED OUTCOME - const debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + let debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( vaultAId ); @@ -207,6 +207,12 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B For Gas Measurem contracts.instaPoolResolver ); + if (route !== 1) { + debtOnMakerBefore = await contracts.makerResolver.getMakerVaultDebt( + vaultAId + ); + } + const gasCost = await getGasCostForFullRefinance(route); const gasFeesPaidFromCol = ethers.BigNumber.from(gasCost).mul( @@ -253,9 +259,17 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B For Gas Measurem let vaultBId = String(cdps.ids[1]); expect(cdps.ids[1].isZero()).to.be.false; - const debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( - vaultBId - ); + let debtOnMakerVaultB; + if (route === 1) { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultRawDebt( + vaultBId + ); + } else { + debtOnMakerVaultB = await contracts.makerResolver.getMakerVaultDebt( + vaultBId + ); + } + const pricedCollateralOnVaultB = await contracts.makerResolver.getMakerVaultCollateralBalance( vaultBId );