Skip to content

Commit

Permalink
✨ market: store globalUtilization
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina committed Feb 2, 2024
1 parent 63bb0f0 commit 1a41df3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ type Market @entity {
floatingDebt: BigInt!
floatingBackupBorrowed: BigInt!
earningsAccumulator: BigInt!
globalUtilization: BigInt!
# FloatingDebtUpdate
floatingUtilization: BigInt
lastFloatingDebtUpdate: Int!
Expand Down Expand Up @@ -393,6 +394,7 @@ type MarketState @entity {
floatingBackupBorrowed: BigInt
earningsAccumulator: BigInt
floatingUtilization: BigInt
globalUtilization: BigInt
floatingCurveA: BigInt
floatingCurveB: BigInt
floatingMaxUtilization: BigInt
Expand Down
3 changes: 3 additions & 0 deletions src/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions src/utils/loadMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/utils/saveMarketState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a41df3

Please sign in to comment.