Skip to content

Commit

Permalink
feat: index liquidation state timings
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Apr 27, 2024
1 parent 77914d8 commit fd4dffa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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",
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

0 comments on commit fd4dffa

Please sign in to comment.