From a6e9b79f4fdf1299eeb8ea06d64d5df3018d76da Mon Sep 17 00:00:00 2001 From: Nick Poulden Date: Wed, 29 Nov 2023 09:37:46 -0700 Subject: [PATCH 1/2] Start --- schema-oeth.graphql | 1 + schema.graphql | 1 + src/model/generated/oethDailyStat.model.ts | 3 +++ .../post-processors/daily-stats/daily-stats.ts | 14 ++++++++++++++ 4 files changed, 19 insertions(+) diff --git a/schema-oeth.graphql b/schema-oeth.graphql index 67ff0303..f413b5c8 100644 --- a/schema-oeth.graphql +++ b/schema-oeth.graphql @@ -176,6 +176,7 @@ type OETHDailyStat @entity { nonRebasingSupply: BigInt! amoSupply: BigInt! dripperWETH: BigInt! + wrappedSupply: BigInt! yield: BigInt! fees: BigInt! diff --git a/schema.graphql b/schema.graphql index d6e13c5a..38f82b95 100644 --- a/schema.graphql +++ b/schema.graphql @@ -271,6 +271,7 @@ type OETHDailyStat @entity { nonRebasingSupply: BigInt! amoSupply: BigInt! dripperWETH: BigInt! + wrappedSupply: BigInt! yield: BigInt! fees: BigInt! diff --git a/src/model/generated/oethDailyStat.model.ts b/src/model/generated/oethDailyStat.model.ts index 84233987..6cf65561 100644 --- a/src/model/generated/oethDailyStat.model.ts +++ b/src/model/generated/oethDailyStat.model.ts @@ -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 diff --git a/src/oeth/post-processors/daily-stats/daily-stats.ts b/src/oeth/post-processors/daily-stats/daily-stats.ts index 1196bf77..471ddc26 100644 --- a/src/oeth/post-processors/daily-stats/daily-stats.ts +++ b/src/oeth/post-processors/daily-stats/daily-stats.ts @@ -14,6 +14,7 @@ import { OETHDailyStat, OETHDripper, OETHFraxStaking, + OETHHistory, OETHMorphoAave, OETHStrategyDailyStat, OETHStrategyHoldingDailyStat, @@ -89,6 +90,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), @@ -106,6 +108,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? @@ -125,6 +134,10 @@ async function updateDailyStats(ctx: Context, date: Date) { return null } + console.log({ + lastWrappedOETHHistory + }) + // console.log({ // lastApy, // lastOeth, @@ -176,6 +189,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, From abbe6f412325e6af7324130df9987c7317c119e2 Mon Sep 17 00:00:00 2001 From: Nick Poulden Date: Wed, 29 Nov 2023 09:45:54 -0700 Subject: [PATCH 2/2] Migration. Cleanup --- ...86218500-Data.js => 1701276030021-Data.js} | 6 +- .../daily-stats/daily-stats.ts | 72 ------------------- .../exchange-rates/price-routing.ts | 2 +- 3 files changed, 4 insertions(+), 76 deletions(-) rename db/migrations/{1700586218500-Data.js => 1701276030021-Data.js} (99%) diff --git a/db/migrations/1700586218500-Data.js b/db/migrations/1701276030021-Data.js similarity index 99% rename from db/migrations/1700586218500-Data.js rename to db/migrations/1701276030021-Data.js index 3a49c4cf..e290900d 100644 --- a/db/migrations/1700586218500-Data.js +++ b/db/migrations/1701276030021-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1700586218500 { - name = 'Data1700586218500' +module.exports = class Data1701276030021 { + name = 'Data1701276030021' async up(db) { await db.query(`CREATE TABLE "exchange_rate" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "pair" text NOT NULL, "base" text NOT NULL, "quote" text NOT NULL, "rate" numeric NOT NULL, CONSTRAINT "PK_5c5d27d2b900ef6cdeef0398472" PRIMARY KEY ("id"))`) @@ -66,7 +66,7 @@ module.exports = class Data1700586218500 { await db.query(`CREATE INDEX "IDX_6c7096c96a000d8471256ca8fc" ON "oeth_strategy_daily_stat" ("daily_stat_id_id") `) await db.query(`CREATE TABLE "oeth_collateral_daily_stat" ("id" character varying NOT NULL, "symbol" text NOT NULL, "amount" numeric NOT NULL, "price" numeric NOT NULL, "value" numeric NOT NULL, "daily_stat_id_id" character varying, CONSTRAINT "PK_5fb23d7bae30dffe4543e7aa069" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_a90045de50406be7bd56efd3ea" ON "oeth_collateral_daily_stat" ("daily_stat_id_id") `) - await db.query(`CREATE TABLE "oeth_daily_stat" ("id" character varying NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "apr" numeric NOT NULL, "apy" numeric NOT NULL, "apy7_day_avg" numeric NOT NULL, "apy14_day_avg" numeric NOT NULL, "apy30_day_avg" numeric NOT NULL, "total_supply" numeric NOT NULL, "total_supply_usd" numeric NOT NULL, "rebasing_supply" numeric NOT NULL, "non_rebasing_supply" numeric NOT NULL, "amo_supply" numeric NOT NULL, "dripper_weth" numeric NOT NULL, "yield" numeric NOT NULL, "fees" numeric NOT NULL, "revenue" numeric NOT NULL, "revenue7_day_avg" numeric NOT NULL, "revenue7_day_total" numeric NOT NULL, "revenue_all_time" numeric NOT NULL, "peg_price" numeric NOT NULL, CONSTRAINT "PK_9144a02ab13b1baa818a7d5eae5" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "oeth_daily_stat" ("id" character varying NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "apr" numeric NOT NULL, "apy" numeric NOT NULL, "apy7_day_avg" numeric NOT NULL, "apy14_day_avg" numeric NOT NULL, "apy30_day_avg" numeric NOT NULL, "total_supply" numeric NOT NULL, "total_supply_usd" numeric NOT NULL, "rebasing_supply" numeric NOT NULL, "non_rebasing_supply" numeric NOT NULL, "amo_supply" numeric NOT NULL, "dripper_weth" numeric NOT NULL, "wrapped_supply" numeric NOT NULL, "yield" numeric NOT NULL, "fees" numeric NOT NULL, "revenue" numeric NOT NULL, "revenue7_day_avg" numeric NOT NULL, "revenue7_day_total" numeric NOT NULL, "revenue_all_time" numeric NOT NULL, "peg_price" numeric NOT NULL, CONSTRAINT "PK_9144a02ab13b1baa818a7d5eae5" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_98d9001013aa37425ca47b7126" ON "oeth_daily_stat" ("block_number") `) await db.query(`CREATE INDEX "IDX_c3e66051c7df4efd6a8fa8f9c1" ON "oeth_daily_stat" ("timestamp") `) await db.query(`CREATE TABLE "oeth_reward_token_collected" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "strategy" text NOT NULL, "recipient" text NOT NULL, "reward_token" text NOT NULL, "amount" numeric NOT NULL, CONSTRAINT "PK_47098cc5fbc7cb95c2374fa33cd" PRIMARY KEY ("id"))`) diff --git a/src/oeth/post-processors/daily-stats/daily-stats.ts b/src/oeth/post-processors/daily-stats/daily-stats.ts index 471ddc26..0040a966 100644 --- a/src/oeth/post-processors/daily-stats/daily-stats.ts +++ b/src/oeth/post-processors/daily-stats/daily-stats.ts @@ -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, @@ -134,20 +133,6 @@ async function updateDailyStats(ctx: Context, date: Date) { return null } - console.log({ - lastWrappedOETHHistory - }) - - // console.log({ - // lastApy, - // lastOeth, - // lastCurve, - // lastVault, - // lastBalancer, - // lastFrax, - // lastMorpho, - // }) - const entityManager = ( ctx.store as unknown as { em: () => EntityManager @@ -170,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, @@ -218,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 = @@ -409,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 @@ -448,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`) -} diff --git a/src/shared/post-processors/exchange-rates/price-routing.ts b/src/shared/post-processors/exchange-rates/price-routing.ts index de4d9060..60ccce07 100644 --- a/src/shared/post-processors/exchange-rates/price-routing.ts +++ b/src/shared/post-processors/exchange-rates/price-routing.ts @@ -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