Skip to content

Commit

Permalink
feat: oraclePrice added to liquidated vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
frazarshad committed May 14, 2024
1 parent 8dcbfba commit 1cb5e76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ type VaultManagerGovernanceJson @jsonField {
liquidationMarginNumerator: BigInt
}

type OraclePriceJson @jsonField {
typeInAmount: BigInt
typeOutAmount: BigInt
}

type VaultLiquidation @entity {
id: ID!
blockHeight: BigInt!
Expand All @@ -158,6 +163,7 @@ type VaultLiquidation @entity {
currentState: Vault!
liquidatingState: VaultLiquidation!
vaultManagerGovernance: VaultManagerGovernanceJson
oraclePrice: OraclePriceJson
}

type VaultManagerMetrics @entity {
Expand Down
28 changes: 21 additions & 7 deletions src/mappings/events/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Wallet,
Vault,
VaultLiquidation,
OraclePrice,
} from '../../types';
import { VAULT_STATES } from '../constants';
import { dateToDayKey, extractBrand } from '../utils';
Expand Down Expand Up @@ -77,6 +78,9 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
async function saveVaultsLiquidation(payload: any): Promise<any> {
const id = `${path}-${payload?.vaultState}`;
const liquidatingId = `${path}-${VAULT_STATES.LIQUIDATING}`;

const denom = payload?.locked?.__brand;

let vault = await VaultLiquidation.get(id);
if (!vault) {
vault = new VaultLiquidation(
Expand All @@ -92,15 +96,25 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
const vaultGovernanceId = id.split('.').slice(0, 4).join('.') + '.governance';
const vaultManagerGovernance = await VaultManagerGovernance.get(vaultGovernanceId);

if (vaultManagerGovernance && payload?.vaultState === 'liquidated' && vault.vaultManagerGovernance === undefined) {
vault.vaultManagerGovernance = {
liquidationMarginNumerator: vaultManagerGovernance?.liquidationMarginNumerator,
liquidationMarginDenominator: vaultManagerGovernance?.liquidationMarginDenominator,
};
const oraclPriceId = `${denom}-USD`;
const oraclePrice = await OraclePrice.get(oraclPriceId);

if (payload?.vaultState === 'liquidated') {
if (vaultManagerGovernance && vault.vaultManagerGovernance === undefined)
vault.vaultManagerGovernance = {
liquidationMarginNumerator: vaultManagerGovernance.liquidationMarginNumerator,
liquidationMarginDenominator: vaultManagerGovernance.liquidationMarginDenominator,
};

if (oraclePrice && vault.oraclePrice === undefined)
vault.oraclePrice = {
typeInAmount: oraclePrice.typeInAmount,
typeOutAmount: oraclePrice.typeOutAmount,
};
}

vault.coin = payload?.locked?.__brand;
vault.denom = payload?.locked?.__brand;
vault.coin = denom;
vault.denom = denom;
vault.debt = payload?.debtSnapshot?.debt?.__value;
vault.balance = payload?.locked?.__value;
vault.lockedValue = payload?.locked?.__value;
Expand Down

0 comments on commit 1cb5e76

Please sign in to comment.