Skip to main content

latest_custom_metric_by_contract_and_address

Schema: lib

Description

This function retrieves the most recent value of a custom metric, grouped by contract and address. This function is best used when you want a single custom metric (e.g. borrowBalance) for all addresses that have interacted with any of the given contracts.

In addition to the latest_custom_metric_by_contract_and_address function, a variant named latest_custom_metrics_by_contract_and_address also exists. The only difference between these two functions is that latest_custom_metric_by_contract_and_address only returns data for one metric, where-as the latest_custom_metrics_by_contract_and_address allows a list of metrics (e.g. ['balance', 'borrowBalance']) to be searched for.

Usage

Signature

Single metric:

lib.latest_custom_metric_by_contract_and_address(contracts text[], metric_name text)

Multiple metrics:

lib.latest_custom_metrics_by_contract_and_address(contracts text[], metric_names text[])

Parameters

NameTypeDescription
contractstext[]An array of contract names to filter by.
metric_nametextThe name of the custom metric to retrieve.

Results

The function returns a table with the following columns:

Column NameTypeDescription
contracttextThe contract name.
addresstextThe address the custom metric is for. E.g. for borrowBalance, this would be the account that actually borrowed
metric_nametextThe name of the custom metric.
valnumericThe most recent value of the custom metric.
updated_timetimestamp with time zoneThe timestamp of the most recent update to the custom metric.

Examples

Retrieving the latest borrow balance for all contracts deployed by company XYZ
with lending_pools as (
select
lpm.account as lending_pool_contract,
lpm.symbol,
lpm.decimals,
lpm.underlying_token_decimals
from lib_lending.lending_pool_metadata_for_company('XYZ') as lpm
),
lending_pool_contracts as (
select array_agg(lp.lending_pool_contract) as contracts
from lending_pools lp
)
select *
from lib.latest_custom_metric_by_contract_and_address(
(select contracts from lending_pool_contracts),
'borrowBalance'
);