Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapter, benqi-lending #772

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading