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

Merged
merged 2 commits into from
May 15, 2024

Conversation

frazarshad
Copy link
Collaborator

image

if (!vaultState) {
const yesterdayDate = new Date(blockTime);
yesterdayDate.setDate(yesterdayDate.getDate() - 1);
const yesterdayDateKey = dateToDayKey(yesterdayDate).toString();
Copy link
Collaborator

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?

Copy link
Collaborator Author

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',
};

Copy link
Collaborator

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?

Copy link
Collaborator Author

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');
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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)) ?

Copy link
Collaborator Author

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()];
}
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@frazarshad frazarshad merged commit 694d8b1 into main May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants