Skip to content

Commit

Permalink
Add oracle cardinality to Monitor tab (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively authored Apr 21, 2024
1 parent 56fde94 commit a2d1222
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 9 additions & 1 deletion earn/src/components/markets/monitor/StatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ function StatsTableRow(props: StatsTableRowProps) {
<td className='px-4 py-2 text-start whitespace-nowrap'>
<Display size='XS'>{reserveFactorText}</Display>
</td>
<td className='px-4 py-2 text-start whitespace-nowrap'>
<Display size='XS'>{pair.slot0Data.observationCardinality}</Display>
</td>
<td className='px-4 py-2 text-start whitespace-nowrap'>
<div className='flex gap-5 justify-between'>
<div>
Expand Down Expand Up @@ -320,6 +323,11 @@ export default function StatsTable(props: { rows: StatsTableRowProps[] }) {
Reserve Factor
</Text>
</th>
<th className='px-4 py-2 text-start whitespace-nowrap'>
<Text size='M' weight='bold'>
Cardinality
</Text>
</th>
<th className='px-4 py-2 text-start whitespace-nowrap'>
<SortButton onClick={() => requestSort('sortA')}>
<Text size='M' weight='bold'>
Expand Down Expand Up @@ -351,7 +359,7 @@ export default function StatsTable(props: { rows: StatsTableRowProps[] }) {
</tbody>
<tfoot>
<tr>
<td className='px-4 py-2' colSpan={7}>
<td className='px-4 py-2' colSpan={8}>
<Pagination
currentPage={currentPage}
itemsPerPage={PAGE_SIZE}
Expand Down
21 changes: 17 additions & 4 deletions earn/src/data/LendingPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { TOPIC0_CREATE_MARKET_EVENT } from './constants/Signatures';
import { asFactoryData, FactoryData } from './FactoryData';
import { asOracleData, OracleData } from './OracleData';
import { borrowAPRToLendAPY, RateModel, yieldPerSecondToAPR } from './RateModel';
import { asSlot0Data, Slot0Data } from './Slot0';

class KittyInfo {
public readonly availableAssets: GN;
Expand Down Expand Up @@ -71,6 +72,7 @@ export class LendingPair {
public rewardsRate1: number,
public factoryData: FactoryData,
public oracleData: OracleData,
public slot0Data: Slot0Data,
public lastWrite: Date
) {}

Expand Down Expand Up @@ -166,10 +168,15 @@ export async function getAvailableLendingPairs(
});

contractCallContexts.push({
reference: `${market.pool}-feeTier`,
reference: `${market.pool}-slot0AndFeeTier`,
contractAddress: market.pool,
abi: uniswapV3PoolAbi as any,
calls: [
{
reference: `${market.pool}-slot0`,
methodName: 'slot0',
methodParameters: [],
},
{
reference: `${market.pool}-feeTier`,
methodName: 'fee',
Expand Down Expand Up @@ -229,16 +236,21 @@ export async function getAvailableLendingPairs(
const lendingPairs: LendingPair[] = [];

Array.from(correspondingLendingPairResults.entries()).forEach(([uniswapPool, value]) => {
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]);
Expand Down Expand Up @@ -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
)
);
Expand Down
21 changes: 21 additions & 0 deletions earn/src/data/Slot0.ts
Original file line number Diff line number Diff line change
@@ -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],
};
}

0 comments on commit a2d1222

Please sign in to comment.