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:
- Low liquidity on the given DEX
- 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
Name | Type | Description |
---|---|---|
router_contracts | text[] | An array of Uniswap V3 router contract addresses. |
token_address | text | The token address to analyze for price impacts. |
start_time | timestamptz | The 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_time | timestamptz | The endpoint for the data search. Only data points that occurred at or before this time will be included. Defaults to now. |
trading_token_address | text | (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:
Column | Type | Description |
---|---|---|
transaction_hash | text | The transaction hash of the swap. |
consensus_time | timestamptz | The consensus time of the swap. |
token_1 | text | The token being swapped from. |
token_2 | text | The token being swapped to. |
exchange_rate | numeric | The exchange rate of the swap. |
previous_exchange_rate | numeric | The previous exchange rate of the trading pair. |
price_impact | numeric | The price impact of the swap. |
token_1_val | numeric | The value of the token being swapped from. |
token_2_val | numeric | The value of the token being swapped to. |
raw_exchange_rate | numeric | The raw exchange rate of the swap. |
previous_raw_exchange_rate | numeric | The previous raw exchange rate of the trading pair. |
raw_price_impact | numeric | The raw price impact of the swap. |
raw_token_1_val | numeric | The raw value of the token being swapped from. |
raw_token_2_val | numeric | The raw value of the token being swapped to. |
token_1_address | text | The address of the token being swapped from. |
token_2_address | text | The 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;