From e69980d99ea759d29e8158d576759f4954b808d9 Mon Sep 17 00:00:00 2001 From: William Poulin Date: Thu, 21 Dec 2023 12:53:42 -0500 Subject: [PATCH] fix(maker): Update vault debt balances to account for the ilk rate --- .../ethereum/maker.vault.contract-position-fetcher.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts b/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts index 262a9d028..f60ff0b62 100644 --- a/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts +++ b/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts @@ -172,6 +172,8 @@ export class EthereumMakerVaultContractPositionFetcher extends CustomContractPos positions.map(async position => { const ilk = ethers.utils.formatBytes32String(position.dataProps.ilkName); const [ink, art] = await multicall.wrap(vatContract).read.urns([ilk, urn.toLowerCase()]); + const ilks = await multicall.wrap(vatContract).read.ilks([ilk]); + const rate = new BigNumber(ilks[1].toString()).div(10 ** 27); const collateralToken = position.tokens.find(isSupplied); const debtToken = position.tokens.find(isBorrowed); @@ -182,10 +184,10 @@ export class EthereumMakerVaultContractPositionFetcher extends CustomContractPos .div(10 ** 18) .times(10 ** collateralToken.decimals) .toFixed(0); - const debtRaw = new BigNumber(art.toString()) - .div(10 ** 18) - .times(10 ** debtToken.decimals) - .toFixed(0); + const artRaw = new BigNumber(art.toString()).div(10 ** 18).times(10 ** debtToken.decimals); + + const debtRaw = artRaw.times(rate).toFixed(0); + const collateral = drillBalance(collateralToken, collateralRaw); const debt = drillBalance(debtToken, debtRaw, { isDebt: true }); const tokens = [collateral, debt];