Skip to main content

token_transfers

Schema: lib_uniswap_v3

Description

The token_transfers function is used to retrieve all transfers of a given token that were run through Uniswap-v3-compatible routers. This function is useful for tracking the movement of tokens through a DEX and can provide valuable insights for analysis and monitoring purposes. These values can be aggregated into time buckets to understand volume and activity over time within a given DEX for a token.

Usage

Signature

lib_uniswap_v3.token_transfers(
router_contracts text[],
token_address text,
start_time timestamptz,
end_time timestamptz
)

Parameters

NameTypeDescription
router_contractstext[]An array of Uniswap-v3-compatible router contracts to filter transfers by.
token_addresstextThe address of the token to retrieve transfers for.
start_timetimestamptzThe starting point for the data search. Only transfers that occurred at or after this time will be included. Default value is 7 days prior to the current time.
end_timetimestamptzThe endpoint for the data search. Only transfers that occurred at or before this time will be included. Default value is the current time.

Results

The token_transfers function returns a table with the following columns:

ColumnDescription
consensus_timeThe timestamp of the transfer.
aliased_routerThe alias of the router contract, if available. Otherwise, the original router contract address.
aliased_tokenThe alias of the token, if available. Otherwise, the original token address.
aliased_senderThe alias of the sender, if available. Otherwise, the original sender address.
aliased_recipientThe alias of the recipient, if available. Otherwise, the original recipient address.
valThe amount of tokens transferred.
decimaled_valThe amount of tokens transferred, converted to the appropriate decimal value based on the token's decimals context.
transaction_hashThe hash of the transaction that initiated the transfer.
log_indexThe index of the transfer within the transaction's logs.
routerThe original router contract address.
tokenThe original token address.
senderThe original sender address.
recipientThe original recipient address.

Examples

Retrieve all transfers of ATOM on the WAGMI DEX on Kava
with wagmi_routers as (
select account, alias
from lib.address_metadata_for_company('WAGMI', 'AMM Router')
where context->>'chain' = 'kava'
),
wagmi_addresses as (
select array_agg(account) as addresses
from wagmi_routers
)
select tt.*
from lib_uniswap_v3.token_transfers(
(select addresses from wagmi_addresses),
'0x15932e26f5bd4923d46a2b205191c4b5d5f43fe3', -- ATOM on KAVA
now() - '7 days'::interval,
now()
) tt
order by tt.consensus_time;
Retrieve volume of ATOM transferred on the WAGMI DEX on Kava
with wagmi_routers as (
select account, alias
from lib.address_metadata_for_company('WAGMI', 'AMM Router')
where context->>'chain' = 'kava'
),
wagmi_addresses as (
select array_agg(account) as addresses
from wagmi_routers
),
matching_transfers as (
select
time_bucket('1 day'::interval, tt.consensus_time) as bucket,
tt.decimaled_val,
tt.transaction_hash
from lib_uniswap_v3.token_transfers(
(select addresses from wagmi_addresses),
'0x15932e26f5bd4923d46a2b205191c4b5d5f43fe3', -- ATOM on KAVA
now() - '7 days'::interval,
now()
) tt
)
select
bucket as time,
sum(decimaled_val) as val
from matching_transfers
group by time;x