Skip to content

Commit

Permalink
Fix displaying TrueFi APY
Browse files Browse the repository at this point in the history
  • Loading branch information
HubertNastaly committed Aug 16, 2022
1 parent b01a135 commit bacd0c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
18 changes: 0 additions & 18 deletions src/adaptors/truefi/getPoolValue.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/adaptors/truefi/getPoolValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const poolAbi = require('./abis/pool.json')
const { web3 } = require('./connection')

const unitsMap = {
6: 'mwei',
18: 'ether'
}

async function getPoolValues(poolAddress: string, tokenDecimals: number) {
const pool = new web3.eth.Contract(poolAbi, poolAddress)

const poolValueRaw: string = await pool.methods.poolValue().call()
const poolValue = web3.utils.fromWei(poolValueRaw, unitsMap[tokenDecimals])

const liquidValueRaw: string = await pool.methods.liquidValue().call()
const liquidValue = web3.utils.fromWei(liquidValueRaw, unitsMap[tokenDecimals])

return { poolValue, liquidValue }
}

module.exports = {
getPoolValues
}
6 changes: 3 additions & 3 deletions src/adaptors/truefi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const BigNumber = require('bignumber.js')
const superagent = require('superagent')

const { web3 } = require('./connection')
const { getPoolValue } = require('./getPoolValue')
const { getPoolValues } = require('./getPoolValues')
const { getActiveLoans } = require('./getActiveLoans')
const { getPoolApyBase } = require('./getPoolApyBase')
const { getPoolApyRewards } = require('./getPoolApyRewards')
Expand Down Expand Up @@ -71,7 +71,7 @@ const buildPoolAdapter = async (
distributor: any
): Promise<PoolAdapter> => {
const poolActiveLoans = allActiveLoans.filter(({ poolAddress }) => poolAddress === address)
const poolValue = await getPoolValue(address, decimals)
const { poolValue, liquidValue } = await getPoolValues(address, decimals)
const poolApyBase = await getPoolApyBase(poolActiveLoans, poolValue, decimals)
const poolApyRewards = await getPoolApyRewards(address, decimals, truPrice, multifarm, distributor)

Expand All @@ -80,7 +80,7 @@ const buildPoolAdapter = async (
chain: utils.formatChain('ethereum'),
project: 'truefi',
symbol,
tvlUsd: poolValue * tokenPrice,
tvlUsd: liquidValue * tokenPrice,
apyBase: poolApyBase,
apyReward: poolApyRewards,
rewardTokens: [TRU_ADDRESS],
Expand Down

0 comments on commit bacd0c3

Please sign in to comment.