From 033b141d17f908cc77883aa6a01df3fccfc9543d Mon Sep 17 00:00:00 2001 From: Jorge Galat Date: Wed, 10 Jan 2024 15:47:22 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20irm:=20new=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema.graphql | 42 ++++++++++++++++++++++++++++++------ src/Market.ts | 40 ++++++++++++++++++++++++++++------ src/utils/loadMarket.ts | 10 +++++++++ src/utils/orZero.ts | 6 ++++++ src/utils/saveMarketState.ts | 12 +++++++++++ 5 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 src/utils/orZero.ts diff --git a/schema.graphql b/schema.graphql index 3c59c29..451fb95 100644 --- a/schema.graphql +++ b/schema.graphql @@ -138,6 +138,7 @@ type MarketUpdate @entity { floatingAssets: BigInt! floatingBorrowShares: BigInt! floatingDebt: BigInt! + floatingBackupBorrowed: BigInt! earningsAccumulator: BigInt! } @@ -167,12 +168,20 @@ type InterestRateModelSet @entity { market: Bytes! timestamp: Int! interestRateModel: Bytes! - fixedCurveA: BigInt! - fixedCurveB: BigInt! - fixedMaxUtilization: BigInt! floatingCurveA: BigInt! floatingCurveB: BigInt! floatingMaxUtilization: BigInt! + naturalUtilization: BigInt! + sigmoidSpeed: BigInt! + growthSpeed: BigInt! + maxRate: BigInt! + spreadFactor: BigInt! + timePreference: BigInt! + fixedAllocation: BigInt! + maturitySpeed: BigInt! + fixedCurveA: BigInt! + fixedCurveB: BigInt! + fixedMaxUtilization: BigInt! } type Account @entity { @@ -261,18 +270,27 @@ type Market @entity { lastMarketUpdate: Int floatingAssets: BigInt! floatingDebt: BigInt! + floatingBackupBorrowed: BigInt! earningsAccumulator: BigInt! # FloatingDebtUpdate floatingUtilization: BigInt lastFloatingDebtUpdate: Int! # InterestRateModelSet interestRateModel: Bytes! - fixedCurveA: BigInt! - fixedCurveB: BigInt! - fixedMaxUtilization: BigInt! floatingCurveA: BigInt! floatingCurveB: BigInt! floatingMaxUtilization: BigInt! + naturalUtilization: BigInt! + sigmoidSpeed: BigInt! + growthSpeed: BigInt! + maxRate: BigInt! + spreadFactor: BigInt! + timePreference: BigInt! + fixedAllocation: BigInt! + maturitySpeed: BigInt! + fixedCurveA: BigInt! + fixedCurveB: BigInt! + fixedMaxUtilization: BigInt! # AccumulatorAccrual lastAccumulatorAccrual: Int! # EarningsAccumulatorSmoothFactorSet @@ -370,11 +388,23 @@ type MarketState @entity { totalFloatingBorrowShares: BigInt totalSupply: BigInt! floatingDebt: BigInt + floatingBackupBorrowed: BigInt earningsAccumulator: BigInt floatingUtilization: BigInt floatingCurveA: BigInt floatingCurveB: BigInt floatingMaxUtilization: BigInt + naturalUtilization: BigInt! + sigmoidSpeed: BigInt! + growthSpeed: BigInt! + maxRate: BigInt! + spreadFactor: BigInt! + timePreference: BigInt! + fixedAllocation: BigInt! + maturitySpeed: BigInt! + fixedCurveA: BigInt! + fixedCurveB: BigInt! + fixedMaxUtilization: BigInt! lastAccumulatorAccrual: Int! earningsAccumulatorSmoothFactor: BigInt treasuryFeeRate: BigInt diff --git a/src/Market.ts b/src/Market.ts index 4408b28..6e06bed 100644 --- a/src/Market.ts +++ b/src/Market.ts @@ -46,6 +46,7 @@ import savedAccount from './utils/savedAccount'; import loadAccount from './utils/loadAccount'; import loadMarket from './utils/loadMarket'; import fixedRate from './utils/fixedRate'; +import orZero from './utils/orZero'; import toId from './utils/toId'; export function handleDeposit(event: DepositEvent): void { @@ -289,23 +290,44 @@ export function handleInterestRateModelSet(event: InterestRateModelSetEvent): vo entity.interestRateModel = event.params.interestRateModel; const irm = InterestRateModelContract.bind(event.params.interestRateModel); - entity.fixedCurveA = irm.fixedCurveA(); - entity.fixedCurveB = irm.fixedCurveB(); - entity.fixedMaxUtilization = irm.fixedMaxUtilization(); entity.floatingCurveA = irm.floatingCurveA(); entity.floatingCurveB = irm.floatingCurveB(); entity.floatingMaxUtilization = irm.floatingMaxUtilization(); + entity.naturalUtilization = orZero(irm.try_naturalUtilization()); + entity.sigmoidSpeed = orZero(irm.try_sigmoidSpeed()); + entity.growthSpeed = orZero(irm.try_growthSpeed()); + entity.maxRate = orZero(irm.try_maxRate()); + entity.spreadFactor = orZero(irm.try_spreadFactor()); + entity.timePreference = orZero(irm.try_timePreference()); + entity.fixedAllocation = orZero(irm.try_fixedAllocation()); + entity.maturitySpeed = orZero(irm.try_maturitySpeed()); + + entity.fixedCurveA = irm.fixedCurveA(); + entity.fixedCurveB = irm.fixedCurveB(); + entity.fixedMaxUtilization = irm.fixedMaxUtilization(); + entity.save(); const market = loadMarket(entity.market, event); market.interestRateModel = entity.interestRateModel; - market.fixedCurveA = entity.fixedCurveA; - market.fixedCurveB = entity.fixedCurveB; - market.fixedMaxUtilization = entity.fixedMaxUtilization; market.floatingCurveA = entity.floatingCurveA; market.floatingCurveB = entity.floatingCurveB; market.floatingMaxUtilization = entity.floatingMaxUtilization; + + market.naturalUtilization = entity.naturalUtilization; + market.sigmoidSpeed = entity.sigmoidSpeed; + market.growthSpeed = entity.growthSpeed; + market.maxRate = entity.maxRate; + market.spreadFactor = entity.spreadFactor; + market.timePreference = entity.timePreference; + market.fixedAllocation = entity.fixedAllocation; + market.maturitySpeed = entity.maturitySpeed; + + market.fixedCurveA = entity.fixedCurveA; + market.fixedCurveB = entity.fixedCurveB; + market.fixedMaxUtilization = entity.fixedMaxUtilization; + market.save(); saveMarketState(event, market); @@ -328,6 +350,8 @@ export function handleTreasurySet(event: TreasurySetEvent): void { } export function handleMarketUpdate(event: MarketUpdateEvent): void { + const contract = Market.bind(event.address); + const entity = new MarketUpdate(toId(event)); entity.market = event.address; entity.timestamp = event.params.timestamp.toU32(); @@ -336,6 +360,7 @@ export function handleMarketUpdate(event: MarketUpdateEvent): void { entity.floatingBorrowShares = event.params.floatingBorrowShares; entity.floatingDebt = event.params.floatingDebt; entity.earningsAccumulator = event.params.earningsAccumulator; + entity.floatingBackupBorrowed = contract.floatingBackupBorrowed(); entity.save(); const market = loadMarket(entity.market, event); @@ -344,8 +369,9 @@ export function handleMarketUpdate(event: MarketUpdateEvent): void { market.floatingAssets = entity.floatingAssets; market.totalFloatingBorrowShares = entity.floatingBorrowShares; market.floatingDebt = entity.floatingDebt; + market.floatingBackupBorrowed = entity.floatingBackupBorrowed; market.earningsAccumulator = entity.earningsAccumulator; - market.symbol = Market.bind(Address.fromBytes(entity.market)).symbol(); + market.symbol = contract.symbol(); market.save(); saveMarketState(event, market); diff --git a/src/utils/loadMarket.ts b/src/utils/loadMarket.ts index 18bccfc..3fa1fa7 100644 --- a/src/utils/loadMarket.ts +++ b/src/utils/loadMarket.ts @@ -6,6 +6,7 @@ import { Market } from '../../generated/schema'; import { ERC20 } from '../../generated/Auditor/ERC20'; import { Market as MarketContract } from '../../generated/Auditor/Market'; import { InterestRateModel } from '../../generated/Auditor/InterestRateModel'; +import orZero from './orZero'; export default function loadMarket(market: Bytes, event: ethereum.Event): Market { const id = market.toHexString(); @@ -23,6 +24,7 @@ export default function loadMarket(market: Bytes, event: ethereum.Event): Market entity.lastAccumulatorAccrual = mkt.lastAccumulatorAccrual().toU32(); entity.floatingAssets = mkt.floatingAssets(); entity.floatingDebt = mkt.floatingDebt(); + entity.floatingBackupBorrowed = mkt.floatingBackupBorrowed(); entity.earningsAccumulator = mkt.earningsAccumulator(); entity.decimals = mkt.decimals(); entity.symbol = mkt.symbol(); @@ -53,5 +55,13 @@ export default function loadMarket(market: Bytes, event: ethereum.Event): Market ? entity.floatingDebt.div(entity.floatingAssets) : BigInt.zero(); + entity.floatingNaturalUtilization = orZero(irm.try_floatingNaturalUtilization()); + entity.sigmoidSpeed = orZero(irm.try_sigmoidSpeed()); + entity.growthSpeed = orZero(irm.try_growthSpeed()); + entity.maxRate = orZero(irm.try_maxRate()); + entity.spreadFactor = orZero(irm.try_spreadFactor()); + entity.timePreference = orZero(irm.try_timePreference()); + entity.maturitySpeed = orZero(irm.try_maturitySpeed()); + return entity; } diff --git a/src/utils/orZero.ts b/src/utils/orZero.ts new file mode 100644 index 0000000..5fe2a49 --- /dev/null +++ b/src/utils/orZero.ts @@ -0,0 +1,6 @@ +import { BigInt, ethereum } from '@graphprotocol/graph-ts'; + +export default function orZero(result: ethereum.CallResult): BigInt { + if (result.reverted) return BigInt.zero(); + return result.value; +} diff --git a/src/utils/saveMarketState.ts b/src/utils/saveMarketState.ts index 031e959..191cde4 100644 --- a/src/utils/saveMarketState.ts +++ b/src/utils/saveMarketState.ts @@ -13,11 +13,23 @@ export default function saveMarketState(event: ethereum.Event, market: Market): marketState.totalFloatingBorrowShares = market.totalFloatingBorrowShares; marketState.floatingAssets = market.floatingAssets; marketState.floatingDebt = market.floatingDebt; + marketState.floatingBackupBorrowed = market.floatingBackupBorrowed; marketState.earningsAccumulator = market.earningsAccumulator; marketState.floatingUtilization = market.floatingUtilization; marketState.floatingCurveA = market.floatingCurveA; marketState.floatingCurveB = market.floatingCurveB; marketState.floatingMaxUtilization = market.floatingMaxUtilization; + marketState.naturalUtilization = market.naturalUtilization; + marketState.sigmoidSpeed = market.sigmoidSpeed; + marketState.growthSpeed = market.growthSpeed; + marketState.maxRate = market.maxRate; + marketState.spreadFactor = market.spreadFactor; + marketState.timePreference = market.timePreference; + marketState.fixedAllocation = market.fixedAllocation; + marketState.maturitySpeed = market.maturitySpeed; + marketState.fixedCurveA = market.fixedCurveA; + marketState.fixedCurveB = market.fixedCurveB; + marketState.fixedMaxUtilization = market.fixedMaxUtilization; marketState.lastAccumulatorAccrual = market.lastAccumulatorAccrual; marketState.earningsAccumulatorSmoothFactor = market.earningsAccumulatorSmoothFactor; marketState.treasuryFeeRate = market.treasuryFeeRate;