Skip to main content

price_impacts

Schema: lib_uniswap_v3

Description

The price_impacts function is used to determine the price impact of swaps involving a given token address on the Uniswap V3 router contracts between specified start and end times. It can also be filtered by a trading token address to limit the results to a single trading pair.

Why is this useful? Price impact can be used to understand how much each swap is impacting the relative price of a token. Drastic swings in price impact from swap to swap indicate:

  1. Low liquidity on the given DEX
  2. A volatile token that might change quickly compared to it's current price

Usage

Signature

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

Parameters

NameTypeDescription
router_contractstext[]An array of Uniswap V3 router contract addresses.
token_addresstextThe token address to analyze for price impacts.
start_timetimestamptzThe starting point for the data search. Only data points that occurred at or after this time will be considered. Defaults to 7 days ago.
end_timetimestamptzThe endpoint for the data search. Only data points that occurred at or before this time will be included. Defaults to now.
trading_token_addresstext(Optional) The token address of the other token in the trading pair. If specified, the price impact results will be limited to on the [token_address]/[trading_token_address] pool.

Results

The price_impacts function returns a table with the following columns:

ColumnTypeDescription
transaction_hashtextThe transaction hash of the swap.
consensus_timetimestamptzThe consensus time of the swap.
token_1textThe token being swapped from.
token_2textThe token being swapped to.
exchange_ratenumericThe exchange rate of the swap.
previous_exchange_ratenumericThe previous exchange rate of the trading pair.
price_impactnumericThe price impact of the swap.
token_1_valnumericThe value of the token being swapped from.
token_2_valnumericThe value of the token being swapped to.
raw_exchange_ratenumericThe raw exchange rate of the swap.
previous_raw_exchange_ratenumericThe previous raw exchange rate of the trading pair.
raw_price_impactnumericThe raw price impact of the swap.
raw_token_1_valnumericThe raw value of the token being swapped from.
raw_token_2_valnumericThe raw value of the token being swapped to.
token_1_addresstextThe address of the token being swapped from.
token_2_addresstextThe address of the token being swapped to.

Examples

Get price impacts for all swaps of ATOM on the WAGMI DEX on Kava

This example returns a subset of fields to make this dataset suitable for charting price impacts in a line chart

with wagmi_routers as (
select account, alias
from lib.address_metadata_for_company('WAGMI', 'AMM Router')
where context->>'chain' = 'kava'
),
wagmi_router_addresses as (
select array_agg(account) as addresses
from wagmi_routers
)
select
token_2 as metric_name,
consensus_time as time,
price_impact * 100 as val,
transaction_hash
from lib_uniswap_v3.price_impacts(
(select addresses from wagmi_router_addresses),
'0x15932e26f5bd4923d46a2b205191c4b5d5f43fe3', -- ATOM on Kava
now() - '7 days'::interval,
now()
)
order by time;