Skip to content

Commit

Permalink
feat: fix on qiAvax token+ explain exchangeRate (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche authored Aug 21, 2023
1 parent 65af397 commit 7209e05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/adapters/benqi-lending/avalanche/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import type { BaseContext, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'
import type { BalanceWithExtraProps } from '@lib/compound/v2/lending'
import { getHealthFactor, getMarketsBalances, getMarketsContracts } from '@lib/compound/v2/lending'
import { ADDRESS_ZERO } from '@lib/contract'

export const getContracts = async (ctx: BaseContext) => {
const markets = await getMarketsContracts(ctx, {
// Benqi Comptroller
comptrollerAddress: '0x486Af39519B4Dc9a7fCcd318217352830E8AD9b4',
underlyingAddressByMarketAddress: {
// qiAVAX -> AVAX
'0x5c0401e81bc07ca70fad469b451682c0d747ef1c': ADDRESS_ZERO,
'0x5c0401e81bc07ca70fad469b451682c0d747ef1c': '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
},
})
return {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/compound/v2/lending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const abi = {
},
} as const

const cTOKENS_DECIMALS = 8

export interface GetMarketsContractsProps {
comptrollerAddress: `0x${string}`
/**
Expand Down Expand Up @@ -164,7 +166,8 @@ export async function getMarketsBalances(ctx: BalancesContext, contracts: Contra
return
}

const amount = (bal.amount * exchangeRateCurrentBycTokenAddress[bal.address]) / 10n ** 10n
const amount =
(bal.amount * exchangeRateCurrentBycTokenAddress[bal.address]) / 10n ** BigInt(cTOKENS_DECIMALS + 2) // cTokens are always 8 decimals and its a percentage so 10 ** 8 * 100 -> 10 ** (8 + 2)

return {
...bal,
Expand Down

0 comments on commit 7209e05

Please sign in to comment.