-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added vaultStateDaily entity to save data for daily stats #21
Conversation
frazarshad
commented
May 15, 2024
if (!vaultState) { | ||
const yesterdayDate = new Date(blockTime); | ||
yesterdayDate.setDate(yesterdayDate.getDate() - 1); | ||
const yesterdayDateKey = dateToDayKey(yesterdayDate).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is yesterday's date? Is it the one we have on line 66? or does it become yesterday's date on line 67?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it becomes yesterdays date after line 67. unfortunately i dont have a better way of conveying this info
[VAULT_STATES.ACTIVE]: 'closed', | ||
[VAULT_STATES.LIQUIDATED]: 'liquidatedClosed', | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should add propertyMap
and closedPropertyMap
in constants.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its very specific to this function and i dont think it will be reused anywhere
if (oldState) { | ||
const oldProperty = propertyMap[oldState]; | ||
if ((vaultState as any)[oldProperty] === BigInt(0)) { | ||
throw Error(oldState + ' vaults are 0. cannot subtract more'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why as
assertion? Why not convert oldProperty
to big int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue here is that typescript warns me about indexing a class object with a string. which is physically possible but the type wont allow it.
therefore i have to convert the objects type to any before indexing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal is to compare big int with big int? this doesn't work? if (BigInt(oldProperty) === BigInt(0))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oldProperty is the name of the propert e.g "active", "liquidated" etc
we index it from "vaultState" to get the actual BigInt value
@@ -71,7 +147,7 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri | |||
liquidation = await saveVaultsLiquidation(payload); | |||
} | |||
|
|||
return [liquidation, vault.save()]; | |||
return [liquidation, vault.save(), dailyVaultState.save()]; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but will it wait for .save()
calls to complete? or should we use await
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the returned array is awaited in the Calling function. so we dont have to handle it here