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 13e11ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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
8 changes: 7 additions & 1 deletion src/mappings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ export const EVENT_TYPES = {
STATE_CHANGE: "state_change",
STORAGE: "storage",
SUBMIT_PROPOSAL: "submit_proposal",
TRANSFER: "transfer",
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 13e11ee

Please sign in to comment.