From 1a41df3cc6d975976bb29a3cad9c18810e6b6463 Mon Sep 17 00:00:00 2001 From: itofarina Date: Fri, 2 Feb 2024 18:18:45 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20market:=20store=20`globalUtilizatio?= =?UTF-8?q?n`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema.graphql | 2 ++ src/Market.ts | 3 +++ src/utils/loadMarket.ts | 4 ++++ src/utils/saveMarketState.ts | 1 + 4 files changed, 10 insertions(+) diff --git a/schema.graphql b/schema.graphql index 3e3a8b2..56b8e72 100644 --- a/schema.graphql +++ b/schema.graphql @@ -274,6 +274,7 @@ type Market @entity { floatingDebt: BigInt! floatingBackupBorrowed: BigInt! earningsAccumulator: BigInt! + globalUtilization: BigInt! # FloatingDebtUpdate floatingUtilization: BigInt lastFloatingDebtUpdate: Int! @@ -393,6 +394,7 @@ type MarketState @entity { floatingBackupBorrowed: BigInt earningsAccumulator: BigInt floatingUtilization: BigInt + globalUtilization: BigInt floatingCurveA: BigInt floatingCurveB: BigInt floatingMaxUtilization: BigInt diff --git a/src/Market.ts b/src/Market.ts index c747531..79d84c4 100644 --- a/src/Market.ts +++ b/src/Market.ts @@ -372,6 +372,9 @@ export function handleMarketUpdate(event: MarketUpdateEvent): void { market.floatingDebt = entity.floatingDebt; market.floatingBackupBorrowed = entity.floatingBackupBorrowed; market.earningsAccumulator = entity.earningsAccumulator; + market.globalUtilization = entity.floatingAssets.gt(BigInt.zero()) + ? (entity.floatingDebt.plus(entity.floatingBackupBorrowed)).div(entity.floatingAssets) + : BigInt.zero(); market.symbol = contract.symbol(); market.save(); diff --git a/src/utils/loadMarket.ts b/src/utils/loadMarket.ts index 37f5f50..614f7fe 100644 --- a/src/utils/loadMarket.ts +++ b/src/utils/loadMarket.ts @@ -45,6 +45,10 @@ export default function loadMarket(market: Bytes, event: ethereum.Event): Market ? entity.floatingDebt.div(entity.floatingAssets) : BigInt.zero(); + entity.globalUtilization = entity.floatingAssets.gt(BigInt.zero()) + ? (entity.floatingDebt.plus(entity.floatingBackupBorrowed)).div(entity.floatingAssets) + : BigInt.zero(); + const asset = ERC20.bind(mkt.asset()); entity.assetSymbol = asset.symbol(); diff --git a/src/utils/saveMarketState.ts b/src/utils/saveMarketState.ts index 191cde4..4c31df9 100644 --- a/src/utils/saveMarketState.ts +++ b/src/utils/saveMarketState.ts @@ -16,6 +16,7 @@ export default function saveMarketState(event: ethereum.Event, market: Market): marketState.floatingBackupBorrowed = market.floatingBackupBorrowed; marketState.earningsAccumulator = market.earningsAccumulator; marketState.floatingUtilization = market.floatingUtilization; + marketState.globalUtilization = market.globalUtilization; marketState.floatingCurveA = market.floatingCurveA; marketState.floatingCurveB = market.floatingCurveB; marketState.floatingMaxUtilization = market.floatingMaxUtilization;