Skip to content

Commit 23a3d8f

Browse files
committed
move away from urates in favor of a single peg field
1 parent 6a6b48c commit 23a3d8f

8 files changed

Lines changed: 44 additions & 34 deletions

File tree

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema.graphql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,10 @@ type OTokenDailyStat @entity {
527527
apy14: Float!
528528
apy30: Float!
529529

530+
peg: BigInt!
530531
rateUSD: BigInt!
531532
rateETH: BigInt!
532533
rateNative: BigInt!
533-
urateUSD: BigInt!
534-
urateETH: BigInt!
535534

536535
totalSupply: BigInt!
537536
rebasingSupply: BigInt!

scripts/create-db-dump.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ async function waitForDbReady({
181181
type RunCmdOptions = { env?: NodeJS.ProcessEnv; capture?: boolean }
182182

183183
async function runCmd(cmd: string, opts: RunCmdOptions = {}) {
184+
console.log(`Running command: ${cmd}`)
184185
const { env, capture = false } = opts
185186
return await new Promise<{ stdout: string }>((resolve, reject) => {
186187
const child = spawn(cmd, {
@@ -321,7 +322,6 @@ async function main() {
321322
await runCmd(`${awsCmd}`)
322323

323324
console.log('Done.')
324-
} finally {
325325
if (startedCompose) {
326326
console.log('Shutting down docker compose project...')
327327
try {
@@ -332,6 +332,14 @@ async function main() {
332332
} else {
333333
console.log('Leaving existing docker compose project running.')
334334
}
335+
} catch (err) {
336+
console.error('Error during processing/upload:', err)
337+
if (startedCompose) {
338+
console.warn(`\nDocker compose project "${composeProject}" left running to preserve data.`)
339+
console.warn(`Re-run with --continue to retry, or manually tear down with:`)
340+
console.warn(` DB_PORT=${DB_PORT} docker-compose -p ${composeProject} down --volumes`)
341+
}
342+
throw err
335343
}
336344
}
337345

src/mainnet/processors/protocol/protocol-sql-simple.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const upsertProtocolDailyStatDetails = async (ctx: Context, fromDate: string) =>
3636
o.date,
3737
'${product.product}' as product,
3838
(o.date::date + interval '1 day' - interval '1 second')::timestamp as timestamp,
39-
COALESCE(o.urate_usd, 0) as rate_usd,
40-
COALESCE(o.rebasing_supply * o.urate_eth / 1e18, 0) as earning_tvl,
41-
COALESCE((o.total_supply - COALESCE(o.amo_supply, 0)) * o.urate_eth / 1e18, 0) as tvl,
42-
COALESCE(o.total_supply * o.urate_eth / 1e18, 0) as supply,
43-
COALESCE((o.yield + o.fees) * o.urate_eth / 1e18, 0) as yield,
44-
COALESCE(o.fees * o.urate_eth / 1e18, 0) as revenue,
39+
COALESCE(o.rate_usd, 0) as rate_usd,
40+
COALESCE(o.rebasing_supply * o.rate_eth / 1e18, 0) as earning_tvl,
41+
COALESCE((o.total_supply - COALESCE(o.amo_supply, 0)) * o.rate_eth / 1e18, 0) as tvl,
42+
COALESCE(o.total_supply * o.rate_eth / 1e18, 0) as supply,
43+
COALESCE((o.yield + o.fees) * o.rate_eth / 1e18, 0) as yield,
44+
COALESCE(o.fees * o.rate_eth / 1e18, 0) as revenue,
4545
COALESCE(o.apy, 0) as apy,
4646
0 as inherited_tvl,
4747
0 as inherited_yield,

src/model/generated/oTokenDailyStat.model.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export class OTokenDailyStat {
4444
@FloatColumn_({nullable: false})
4545
apy30!: number
4646

47+
@BigIntColumn_({nullable: false})
48+
peg!: bigint
49+
4750
@BigIntColumn_({nullable: false})
4851
rateUSD!: bigint
4952

@@ -53,12 +56,6 @@ export class OTokenDailyStat {
5356
@BigIntColumn_({nullable: false})
5457
rateNative!: bigint
5558

56-
@BigIntColumn_({nullable: false})
57-
urateUSD!: bigint
58-
59-
@BigIntColumn_({nullable: false})
60-
urateETH!: bigint
61-
6259
@BigIntColumn_({nullable: false})
6360
totalSupply!: bigint
6461

src/templates/otoken/otoken-daily-stats.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ export const processOTokenDailyStats = async (
9999
otokenObject,
100100
apy,
101101
rebases,
102+
peg,
102103
rateETH,
103104
rateUSD,
105+
rateNative,
104106
dripperWETH,
105107
amoSupply,
106108
wrappedSupply,
107109
wrappedRate,
108-
rateNative,
109-
urateETH,
110-
urateUSD,
111110
] = await Promise.all([
112111
(async () => {
113112
let otokenObject = findLast(params.otokens, (o) => o.timestamp <= blockDate)
@@ -150,28 +149,37 @@ export const processOTokenDailyStats = async (
150149
)
151150
return rebases
152151
})(),
153-
ensureExchangeRate(ctx, block, params.otokenAddress as CurrencyAddress, 'ETH').then((a) => a?.rate ?? 0n),
154-
ensureExchangeRate(ctx, block, params.otokenAddress as CurrencyAddress, 'USD').then((a) => a?.rate ?? 0n),
155-
getDripperAvailableFunds(),
156-
params.getAmoSupply(ctx, block.header.height),
157-
wotokenContract ? wotokenContract.totalSupply() : 0n,
158-
wotokenContract ? wotokenContract.previewRedeem(10n ** 18n) : 0n,
152+
// peg: OToken → underlying (e.g., OETH→ETH, OUSD→USD, OS→S)
159153
ensureExchangeRate(
160154
ctx,
161155
block,
162156
params.otokenAddress as CurrencyAddress,
163-
ctx.chain.nativeCurrency.symbol as Currency,
157+
(underlyingSymbol === 'ETH' || underlyingSymbol === 'USD')
158+
? underlyingSymbol as Currency
159+
: ctx.chain.nativeCurrency.symbol as Currency,
164160
).then((a) => a?.rate ?? 0n),
161+
// rateETH: underlying → ETH
165162
underlyingSymbol === 'ETH'
166163
? 10n ** 18n
167164
: ensureExchangeRate(ctx, block, underlyingSymbol as CurrencyAddress, 'ETH').then(
168165
(a) => (a ? a.rate * 10n ** BigInt(18 - a.decimals) : 0n),
169166
),
167+
// rateUSD: underlying → USD
170168
underlyingSymbol === 'USD'
171169
? 10n ** 18n
172170
: ensureExchangeRate(ctx, block, underlyingSymbol as CurrencyAddress, 'USD').then(
173171
(a) => (a ? a.rate * 10n ** BigInt(18 - a.decimals) : 0n),
174172
),
173+
// rateNative: underlying → chain native currency
174+
underlyingSymbol === ctx.chain.nativeCurrency.symbol
175+
? 10n ** 18n
176+
: ensureExchangeRate(ctx, block, underlyingSymbol as CurrencyAddress, ctx.chain.nativeCurrency.symbol as Currency).then(
177+
(a) => (a ? a.rate * 10n ** BigInt(18 - a.decimals) : 0n),
178+
),
179+
getDripperAvailableFunds(),
180+
params.getAmoSupply(ctx, block.header.height),
181+
wotokenContract ? wotokenContract.totalSupply() : 0n,
182+
wotokenContract ? wotokenContract.previewRedeem(10n ** 18n) : 0n,
175183
])
176184
if (process.env.DEBUG_PERF === 'true') {
177185
ctx.log.info(`getOTokenDailyStat async calls took ${Date.now() - asyncStartTime}ms`)
@@ -218,11 +226,10 @@ export const processOTokenDailyStats = async (
218226
entity.cumulativeYield = (last?.cumulativeYield ?? 0n) + entity.yield
219227
entity.cumulativeFees = (last?.cumulativeFees ?? 0n) + entity.fees
220228

229+
entity.peg = peg
221230
entity.rateETH = rateETH
222231
entity.rateUSD = rateUSD
223232
entity.rateNative = rateNative
224-
entity.urateETH = urateETH
225-
entity.urateUSD = urateUSD
226233
entity.amoSupply = amoSupply
227234

228235
entity.dripperWETH = dripperWETH
@@ -263,11 +270,10 @@ export const getOTokenDailyStat = async (
263270
apy14: 0,
264271
apy30: 0,
265272

273+
peg: 0n,
266274
rateUSD: 0n,
267275
rateETH: 0n,
268276
rateNative: 0n,
269-
urateUSD: 0n,
270-
urateETH: 0n,
271277

272278
totalSupply: 0n,
273279
rebasingSupply: 0n,

src/templates/otoken/otoken.graphql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ type OTokenDailyStat @entity {
175175
apy14: Float!
176176
apy30: Float!
177177

178+
peg: BigInt!
178179
rateUSD: BigInt!
179180
rateETH: BigInt!
180181
rateNative: BigInt!
181-
urateUSD: BigInt!
182-
urateETH: BigInt!
183182

184183
totalSupply: BigInt!
185184
rebasingSupply: BigInt!

src/test-utils/context-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const createMockOTokenDailyStat = (overrides: Partial<OTokenDailyStat> =
6161
otoken: OETH_ADDRESS,
6262
timestamp: new Date('2023-10-01T23:59:59Z'),
6363
blockNumber: 18000000,
64+
peg: BigInt(10 ** 18), // 1:1 peg to underlying
6465
rateETH: BigInt(10 ** 18), // 1:1 rate
6566
rateUSD: BigInt(1800 * 10 ** 18), // $1800 ETH
6667
totalSupply: BigInt(100000 * 10 ** 18), // 100k tokens

0 commit comments

Comments
 (0)