Merge pull request #335 from blockworks-foundation/lou/bank-stats
include recent bank data in tokenStats charts
This commit is contained in:
commit
7c0c1ec682
|
@ -1,4 +1,4 @@
|
|||
import { Group } from '@blockworks-foundation/mango-v4'
|
||||
import { Group, I64_MAX_BN } from '@blockworks-foundation/mango-v4'
|
||||
import { MangoTokenStatsItem, TokenStatsItem } from 'types'
|
||||
import { MANGO_DATA_API_URL } from 'utils/constants'
|
||||
|
||||
|
@ -39,10 +39,40 @@ export const processTokenStatsData = (
|
|||
mangoStatsMap[date].feesCollected += c.collected_fees * uiPrice
|
||||
})
|
||||
|
||||
// add most recent value, using most recent datapoint to patch difficult to compute stats
|
||||
for (const banks of group.banksMapByTokenIndex.values()) {
|
||||
const bank = banks[0]
|
||||
const now = new Date().toISOString()
|
||||
const filtered = data.filter(
|
||||
(x: TokenStatsItem) => bank.tokenIndex === x?.token_index,
|
||||
)
|
||||
if (!filtered || filtered.length === 0) {
|
||||
continue
|
||||
}
|
||||
const previous = filtered.reduce((max, cur) =>
|
||||
max.date_hour > cur.date_hour ? max : cur,
|
||||
)
|
||||
let tokenStatsItem: TokenStatsItem = {
|
||||
borrow_apr: previous.borrow_apr,
|
||||
borrow_rate: bank.getBorrowRateUi() / 100,
|
||||
collected_fees: previous.collected_fees,
|
||||
date_hour: now,
|
||||
deposit_apr: previous.deposit_apr,
|
||||
deposit_rate: bank.getDepositRateUi() / 100,
|
||||
mango_group: bank.group.toBase58(),
|
||||
price: bank.uiPrice,
|
||||
symbol: bank.name,
|
||||
token_index: bank.tokenIndex,
|
||||
total_borrows: bank.uiBorrows(),
|
||||
total_deposits: bank.uiDeposits(),
|
||||
}
|
||||
data.push(tokenStatsItem)
|
||||
}
|
||||
|
||||
const mangoStats: MangoTokenStatsItem[] = Object.values(mangoStatsMap)
|
||||
mangoStats.sort(
|
||||
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(),
|
||||
)
|
||||
|
||||
return mangoStats
|
||||
return [data, mangoStats]
|
||||
}
|
||||
|
|
|
@ -788,12 +788,13 @@ const mangoStore = create<MangoStore>()(
|
|||
state.perpStats.data = data
|
||||
state.perpStats.loading = false
|
||||
})
|
||||
} catch {
|
||||
} catch (error) {
|
||||
set((state) => {
|
||||
state.perpStats.loading = false
|
||||
})
|
||||
console.log('Failed to fetch perp stats data', error)
|
||||
notify({
|
||||
title: 'Failed to fetch token stats data',
|
||||
title: 'Failed to fetch perp stats data',
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
@ -913,8 +914,8 @@ const mangoStore = create<MangoStore>()(
|
|||
})
|
||||
|
||||
try {
|
||||
const data = await fetchTokenStatsData(group)
|
||||
const mangoStats = processTokenStatsData(data, group)
|
||||
const rawData = await fetchTokenStatsData(group)
|
||||
const [data, mangoStats] = processTokenStatsData(rawData, group)
|
||||
|
||||
set((state) => {
|
||||
state.tokenStats.data = data
|
||||
|
@ -926,7 +927,7 @@ const mangoStore = create<MangoStore>()(
|
|||
set((state) => {
|
||||
state.tokenStats.loading = false
|
||||
})
|
||||
|
||||
console.log('Failed to fetch token stats data', error)
|
||||
notify({
|
||||
title: 'Failed to fetch token stats data',
|
||||
type: 'error',
|
||||
|
|
Loading…
Reference in New Issue