From a2d12223c617ae7e7930c5159ebdbe0b89809238 Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:34:03 -0500 Subject: [PATCH] Add oracle cardinality to Monitor tab (#853) --- .../components/markets/monitor/StatsTable.tsx | 10 ++++++++- earn/src/data/LendingPair.ts | 21 +++++++++++++++---- earn/src/data/Slot0.ts | 21 +++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 earn/src/data/Slot0.ts diff --git a/earn/src/components/markets/monitor/StatsTable.tsx b/earn/src/components/markets/monitor/StatsTable.tsx index 69298e95..f627fae4 100644 --- a/earn/src/components/markets/monitor/StatsTable.tsx +++ b/earn/src/components/markets/monitor/StatsTable.tsx @@ -216,6 +216,9 @@ function StatsTableRow(props: StatsTableRowProps) { {reserveFactorText} + + {pair.slot0Data.observationCardinality} +
@@ -320,6 +323,11 @@ export default function StatsTable(props: { rows: StatsTableRowProps[] }) { Reserve Factor + + + Cardinality + + requestSort('sortA')}> @@ -351,7 +359,7 @@ export default function StatsTable(props: { rows: StatsTableRowProps[] }) { - + { - const { basics: basicsResults, feeTier: feeTierResults, oracle: oracleResults, factory: factoryResults } = value; + const { + basics: basicsResults, + slot0AndFeeTier: poolResults, + oracle: oracleResults, + factory: factoryResults, + } = value; const basicsReturnContexts = convertBigNumbersForReturnContexts(basicsResults.callsReturnContext); - const feeTierReturnContexts = convertBigNumbersForReturnContexts(feeTierResults.callsReturnContext); + const poolReturnContexts = convertBigNumbersForReturnContexts(poolResults.callsReturnContext); const oracleReturnContexts = convertBigNumbersForReturnContexts(oracleResults.callsReturnContext); const factoryReturnContexts = convertBigNumbersForReturnContexts(factoryResults.callsReturnContext); const { kitty0Address, kitty1Address } = basicsResults.originalContractCallContext.context; const basics0 = basicsReturnContexts[0].returnValues; const basics1 = basicsReturnContexts[1].returnValues; - const feeTier = feeTierReturnContexts[0].returnValues; + const feeTier = poolReturnContexts[1].returnValues; const oracleResult = oracleReturnContexts[0].returnValues; const factoryResult = factoryReturnContexts[0].returnValues; const token0 = getToken(chainId, basics0[0]); @@ -291,6 +303,7 @@ export async function getAvailableLendingPairs( toImpreciseNumber(basics1[7], 18), // rewardsRate1 asFactoryData(factoryResult), asOracleData(oracleResult), + asSlot0Data(poolReturnContexts[0].returnValues), new Date(oracleReturnContexts[1].returnValues[1] * 1000) // lastWrite.time ) ); diff --git a/earn/src/data/Slot0.ts b/earn/src/data/Slot0.ts new file mode 100644 index 00000000..1537bba3 --- /dev/null +++ b/earn/src/data/Slot0.ts @@ -0,0 +1,21 @@ +import { GN } from 'shared/lib/data/GoodNumber'; + +export type Slot0Data = { + sqrtPriceX96: GN; + tick: number; + observationIndex: number; + observationCardinality: number; + observationCardinalityNext: number; + feeProtocol: number; +}; + +export function asSlot0Data(multicallResult: any[]): Slot0Data { + return { + sqrtPriceX96: GN.fromBigNumber(multicallResult[0], 96, 2), + tick: multicallResult[1], + observationIndex: multicallResult[2], + observationCardinality: multicallResult[3], + observationCardinalityNext: multicallResult[4], + feeProtocol: multicallResult[5], + }; +}