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: index liquidation state timings #5

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type Vault @entity {
debt: BigInt
state: String
wallet: Wallet!
liquidatingAt: Date
liquidatedAt: Date
}

type VaultManagerMetrics @entity {
Expand Down
5 changes: 5 additions & 0 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const EVENT_TYPES = {
TRANSFER: "transfer",
};

export const VAULT_STATES = {
LIQUIDATING: "liquidating",
Copy link
Contributor

Choose a reason for hiding this comment

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

EVENT_TYPES are used for different purposes. These are states of Vaults, so a new enum called VAULT_STATES will be better.

LIQUIDATED: "liquidated"
}

export const VALUE_KEY = b64encode("value");
export const STORE_KEY = b64encode("store");
export const VSTORAGE_VALUE = b64encode("vstorage");
Expand Down
9 changes: 9 additions & 0 deletions src/mappings/events/vaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VaultManagerMetrics, VaultManagerMetricsDaily, VaultManagerGovernance, Wallet, Vault } from "../../types";
import { VAULT_STATES } from "../constants";
import { dateToDayKey, extractBrand } from "../utils";

export const vaultsEventKit = (block: any, data: any, module: string, path: string) => {
Expand Down Expand Up @@ -55,6 +56,14 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
vault.debt = payload?.debtSnapshot?.debt?.__value;
vault.balance = payload?.locked?.__value;
vault.state = payload?.vaultState;

if (vault.state === VAULT_STATES.LIQUIDATING && !vault.liquidatingAt) {
vault.liquidatingAt = block.block.header.time;
}

if (vault.state === VAULT_STATES.LIQUIDATED && !vault.liquidatedAt) {
vault.liquidatedAt = block.block.header.time;
}
return [vault.save()];
}

Expand Down
Loading