Skip to content
Merged
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
23 changes: 13 additions & 10 deletions src/processors/oeth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ export async function createRebaseAPY(

// get last APY to compare with current one
let lastApy =
apies.slice(apies.length - 2).find((apy) => apy.id < dateId) ??
apies.find((apy) => apy.id < dateId) ??
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want this change? If we have anything in the apies array it will definitely be recent and we wouldn't care about anything in there less than 2 instances past.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i might be wrong

(await ctx.store.findOne(APY, {
where: { id: LessThan(dateId) },
order: { id: 'DESC' },
}))

// check if there is already an APY for the current date
let apy =
apies.slice(apies.length - 1).find((apy) => apy.id === dateId) ??
(await ctx.store.findOne(APY, { where: { id: dateId } }))
let apy = apies.find((apy) => apy.id === dateId)
if (!apy) {
apy = await ctx.store.findOne(APY, { where: { id: dateId } })
if (apy) {
apies.push(apy)
}
}
// ctx.log.info(`APY: ${dateId} ${apy}, ${lastDateId} ${lastApy}`);
// create a new APY if it doesn't exist
if (!apy) {
Expand Down Expand Up @@ -106,16 +110,15 @@ export async function createRebaseAPY(
apy.rebasingCreditsPerToken = rebaseEvent.rebasingCreditsPerToken

// this should normally be 1 day but more secure to calculate it
const diffTime = Math.abs(Date.parse(apy.id) - Date.parse(lastApy.id))
const dayDiff = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
const diffTime = apy.timestamp.getTime() - lastApy.timestamp.getTime()
const dayDiff = diffTime / (1000 * 60 * 60 * 24)

apy.apr =
((Number(lastApy.rebasingCreditsPerToken) /
(Number(lastApy.rebasingCreditsPerToken) /
Number(apy.rebasingCreditsPerToken) -
1) *
365.25) /
dayDiff
const periods_per_year = 365.25 / dayDiff
(365.25 / dayDiff)
const periods_per_year = 365.25 / Number(dayDiff)
apy.apy = (1 + apy.apr / periods_per_year) ** periods_per_year - 1

const last7daysDateId = {
Expand Down