Skip to content
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schema-oeth.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ type OETHDailyStat @entity {
nonRebasingSupply: BigInt!
amoSupply: BigInt!
dripperWETH: BigInt!
wrappedSupply: BigInt!

yield: BigInt!
fees: BigInt!
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ type OETHDailyStat @entity {
nonRebasingSupply: BigInt!
amoSupply: BigInt!
dripperWETH: BigInt!
wrappedSupply: BigInt!

yield: BigInt!
fees: BigInt!
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/oethDailyStat.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export class OETHDailyStat {
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
dripperWETH!: bigint

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
wrappedSupply!: bigint

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
yield!: bigint

Expand Down
78 changes: 10 additions & 68 deletions src/oeth/post-processors/daily-stats/daily-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EvmBatchProcessor } from '@subsquid/evm-processor'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import { EntityManager, FindOptionsOrderValue, LessThanOrEqual } from 'typeorm'
import { formatEther } from 'viem'

import {
ExchangeRate,
Expand All @@ -14,6 +13,7 @@ import {
OETHDailyStat,
OETHDripper,
OETHFraxStaking,
OETHHistory,
OETHMorphoAave,
OETHStrategyDailyStat,
OETHStrategyHoldingDailyStat,
Expand Down Expand Up @@ -89,6 +89,7 @@ async function updateDailyStats(ctx: Context, date: Date) {
lastDripper,
lastRethRate,
lastSfrxEthRate,
lastWrappedOETHHistory,
] = await Promise.all([
ctx.store.findOne(OETHAPY, queryParams),
ctx.store.findOne(OETH, queryParams),
Expand All @@ -106,6 +107,13 @@ async function updateDailyStats(ctx: Context, date: Date) {
where: { timestamp: LessThanOrEqual(date), pair: 'ETH_sfrxETH' },
order: { timestamp: 'desc' as FindOptionsOrderValue },
}),
ctx.store.findOne(OETHHistory, {
where: {
timestamp: LessThanOrEqual(date),
address: { id: '0xdcee70654261af21c44c093c300ed3bb97b78192' },
},
order: { timestamp: 'desc' as FindOptionsOrderValue },
}),
])

// Do we have any useful data yet?
Expand All @@ -125,16 +133,6 @@ async function updateDailyStats(ctx: Context, date: Date) {
return null
}

// console.log({
// lastApy,
// lastOeth,
// lastCurve,
// lastVault,
// lastBalancer,
// lastFrax,
// lastMorpho,
// })

const entityManager = (
ctx.store as unknown as {
em: () => EntityManager
Expand All @@ -157,7 +155,6 @@ async function updateDailyStats(ctx: Context, date: Date) {
})

const id = date.toISOString().substring(0, 10)
// ctx.log.info({ date, id })

const dailyStat = new OETHDailyStat({
id,
Expand All @@ -176,6 +173,7 @@ async function updateDailyStats(ctx: Context, date: Date) {
nonRebasingSupply: lastOeth?.nonRebasingSupply || 0n,
amoSupply: lastCurve?.oethOwned || 0n,
dripperWETH: lastDripper?.weth || 0n,
wrappedSupply: lastWrappedOETHHistory?.balance || 0n,

yield: yieldStats[0].total_yield || 0n,
fees: yieldStats[0].total_fees || 0n,
Expand Down Expand Up @@ -204,25 +202,6 @@ async function updateDailyStats(ctx: Context, date: Date) {
const sfrxETH = lastFrax?.sfrxETH || 0n
const convertedSfrxEth =
(sfrxETH * sfrxEthExchangeRate) / 1000000000000000000n
const frxETH = (lastVault?.frxETH || 0n) + convertedSfrxEth

const totalCollateral = ETH + WETH + frxETH + stETH + rETH

// console.log(`Day: ${date}`)
// log([
// ['Total Supply', dailyStat.totalSupply],
// ['Circulating Supply', dailyStat.totalSupply - OETHOwned],
// ['Total Collateral', totalCollateral],
// ['Difference', dailyStat.totalSupply - OETHOwned - totalCollateral],
// ['Total ETH', ETH],
// ['Total WETH', WETH],
// ['Total stETH', stETH],
// ['Total rETH', rETH],
// ['Total frxETH', frxETH],
// ['', null],
// ['Vault frxETH', lastVault?.frxETH || 0n],
// ['Total sfrxETH', sfrxETH],
// ])

// Strategy totals
const vaultTotal =
Expand Down Expand Up @@ -395,25 +374,6 @@ async function updateDailyStats(ctx: Context, date: Date) {
}
}

function getStartOfDays(startTimestamp: number, endTimestamp: number): Date[] {
const dayMilliseconds = 24 * 60 * 60 * 1000 // Number of milliseconds in a day
let startTimestampStart = new Date(startTimestamp)
startTimestampStart.setUTCHours(0, 0, 0, 0)

let currentTimestamp = startTimestampStart.getTime()
let dates: Date[] = []

while (currentTimestamp <= endTimestamp) {
let date = new Date(currentTimestamp)
date.setUTCHours(0, 0, 0, 0) // Set to start of the day
dates.push(date)

currentTimestamp += dayMilliseconds // Move to the next day
}

return dates
}

const yieldStatsQuery = `
-- Results for 1 day
SELECT '1 day' as period, SUM(fee) as total_fees, SUM(yield - fee) as total_yield, SUM(yield) as total_revenue
Expand All @@ -434,21 +394,3 @@ SELECT 'all time' as period, SUM(fee) as total_fees, SUM(yield - fee) as total_y
FROM oeth_rebase
WHERE timestamp <= $1::timestamp
`

function log(entries: [string, bigint | null][]): void {
if (!entries) {
console.log('')
return
}
// Find the longest label for alignment
const maxLength = Math.max(...entries.map((entry) => entry[0].length))

const lines = entries.map(([label, value]) => {
// Format the value
const formattedValue = value ? Number(formatEther(value)).toFixed(3) : ''
// Right-align the label and value
return `${label.padEnd(maxLength)} ${formattedValue.padStart(10)}`
})

console.log(`${lines.join('\n')}\n`)
}
2 changes: 1 addition & 1 deletion src/shared/post-processors/exchange-rates/price-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const getChainlinkPrice = async (
currencies[quote as CurrencySymbol] ?? quote,
)
} catch (err: any) {
if (err.message === 'execution reverted: Feed not found') {
if (err.message.match(/: Feed not found/)) {
return 0n
}
throw err
Expand Down