|
1 | 1 | import dayjs from 'dayjs' |
2 | | -import { uniq } from 'lodash' |
| 2 | +import { compact, uniq } from 'lodash' |
3 | 3 | import { In, LessThanOrEqual } from 'typeorm' |
4 | 4 |
|
5 | 5 | import { |
@@ -145,9 +145,11 @@ const getOTokenDetails = async ( |
145 | 145 |
|
146 | 146 | // Since we depend on superOETHb and superOETHp, we need to continue updating |
147 | 147 | // our product's details until our dependencies are all caught up. |
| 148 | + const lastOETH = await getLatestProtocolDailyStatDetail(ctx, 'OETH') |
148 | 149 | const lastSuperOETHb = await getLatestProtocolDailyStatDetail(ctx, 'superOETHb') |
149 | 150 | const lastSuperOETHp = await getLatestProtocolDailyStatDetail(ctx, 'superOETHp') |
150 | | - const lastDates = [last?.date ?? startDate, lastSuperOETHb?.date, lastSuperOETHp?.date].filter(Boolean) as string[] |
| 151 | + const lastDates = compact([last?.date ?? startDate, lastOETH?.date, lastSuperOETHb?.date, lastSuperOETHp?.date]) |
| 152 | + |
151 | 153 | const oldestDate = lastDates.reduce((min, d) => (d < min ? d : min), lastDates[0]) |
152 | 154 |
|
153 | 155 | const status = await ctx.store.findOne(ProcessingStatus, { where: { id: processorId } }) |
@@ -208,19 +210,25 @@ const getOTokenDetails = async ( |
208 | 210 | detail.earningTvl !== 0n ? (detail.revenue * detail.inheritedTvl) / detail.earningTvl : 0n |
209 | 211 | detail.bridgedTvl = (superOETHbWrappedOETH?.balanceETH ?? 0n) + (superOETHpWrappedOETH?.balanceETH ?? 0n) |
210 | 212 | } else if (detail.product === 'superOETHb') { |
| 213 | + const detailOETH = await getProtocolDailyStatDetail(ctx, date, 'OETH') |
211 | 214 | const superOETHbWrappedOETH = await getLatestStrategyBalance( |
212 | 215 | ctx, |
213 | 216 | baseAddresses.superOETHb.strategies.bridgedWOETH, |
214 | 217 | date, |
215 | 218 | ) |
216 | | - detail.bridgedTvl = superOETHbWrappedOETH?.balanceETH ?? 0n |
| 219 | + const woethBalance = superOETHbWrappedOETH?.balanceETH ?? 0n |
| 220 | + detail.bridgedTvl = woethBalance |
| 221 | + detail.revenue += ((detailOETH?.revenue ?? 0n) * woethBalance) / detail.tvl |
217 | 222 | } else if (detail.product === 'superOETHp') { |
| 223 | + const detailOETH = await getProtocolDailyStatDetail(ctx, date, 'OETH') |
218 | 224 | const superOETHpWrappedOETH = await getLatestStrategyBalance( |
219 | 225 | ctx, |
220 | 226 | plumeAddresses.superOETHp.strategies.bridgedWOETH, |
221 | 227 | date, |
222 | 228 | ) |
223 | | - detail.bridgedTvl = superOETHpWrappedOETH?.balanceETH ?? 0n |
| 229 | + const woethBalance = superOETHpWrappedOETH?.balanceETH ?? 0n |
| 230 | + detail.bridgedTvl = woethBalance |
| 231 | + detail.revenue += ((detailOETH?.revenue ?? 0n) * woethBalance) / detail.tvl |
224 | 232 | } |
225 | 233 |
|
226 | 234 | details.push(detail) |
@@ -253,16 +261,14 @@ const getArmDetails = async ( |
253 | 261 | return details |
254 | 262 | } |
255 | 263 | const detail = await getProtocolDailyStatDetail(ctx, date, product) |
| 264 | + const eth = (value: bigint) => (value * BigInt(Math.round(armDailyStat.rateETH * 1e18))) / BigInt(10 ** 18) |
256 | 265 | detail.rateUSD = BigInt(Math.round(armDailyStat.rateUSD * 1e18)) |
257 | | - detail.earningTvl = armDailyStat.totalAssets |
258 | | - detail.tvl = armDailyStat.totalAssets |
259 | | - detail.supply = armDailyStat.totalSupply |
260 | | - detail.yield = armDailyStat.yield + armDailyStat.fees |
261 | | - detail.revenue = armDailyStat.fees |
| 266 | + detail.earningTvl = eth(armDailyStat.totalAssets) |
| 267 | + detail.tvl = eth(armDailyStat.totalAssets) |
| 268 | + detail.supply = eth(armDailyStat.totalSupply) |
| 269 | + detail.yield = eth(armDailyStat.yield + armDailyStat.fees) |
| 270 | + detail.revenue = eth(armDailyStat.fees) |
262 | 271 | detail.apy = armDailyStat.apy |
263 | | - detail.inheritedTvl = 0n |
264 | | - detail.inheritedYield = 0n |
265 | | - detail.inheritedRevenue = 0n |
266 | 272 | details.push(detail) |
267 | 273 | } |
268 | 274 | return details |
|
0 commit comments