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
Name | Type | Description |
---|---|---|
router_contracts | text[] | An array of Uniswap-v3-compatible router contracts to filter transfers by. |
token_address | text | The address of the token to retrieve transfers for. |
start_time | timestamptz | The 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_time | timestamptz | The 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:
Column | Description |
---|---|
consensus_time | The timestamp of the transfer. |
aliased_router | The alias of the router contract, if available. Otherwise, the original router contract address. |
aliased_token | The alias of the token, if available. Otherwise, the original token address. |
aliased_sender | The alias of the sender, if available. Otherwise, the original sender address. |
aliased_recipient | The alias of the recipient, if available. Otherwise, the original recipient address. |
val | The amount of tokens transferred. |
decimaled_val | The amount of tokens transferred, converted to the appropriate decimal value based on the token's decimals context. |
transaction_hash | The hash of the transaction that initiated the transfer. |
log_index | The index of the transfer within the transaction's logs. |
router | The original router contract address. |
token | The original token address. |
sender | The original sender address. |
recipient | The 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