-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: uniV3 basic lp info #5635
Closed
Closed
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
18abbb9
feat: uniV3 basic lp info
0xrusowsky a08e5c4
fix: compilation errors
0xrusowsky f5522f5
fix: missing alias
0xrusowsky 35082a6
Fix mismatched alias
Hosuke d387800
fix: alias typo
0xrusowsky 6b93399
fix: aslias mismatch
0xrusowsky 98a591e
fix: missing alias
0xrusowsky bddfe41
fix: remove duplicates
0xrusowsky 60ee493
fix: remove duplicates
0xrusowsky f2eab4d
fix: position manager ids
0xrusowsky b297d22
fix: position mannager join
0xrusowsky 15cf396
fix: position manager id
0xrusowsky 8045149
fix: use variable properly
0xrusowsky 8ddaf97
fix: cast input address
0xrusowsky a276d4e
hardcode position manager address
0xrusowsky bd4757a
fix: burns
0xrusowsky 2001e4b
fix: wrong table
0xrusowsky 052caf6
Merge branch 'main' into feat/dex-lps
Hosuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
{% macro uniswap_compatible_v3_lps( | ||
blockchain = null | ||
, project = null | ||
, version = null | ||
, Pair_evt_Mint = null | ||
, Pair_evt_Burn = null | ||
, Factory_evt_PoolCreated = null | ||
, NonfungibleTokenPositionManager_evt_Transfer = null | ||
, NonfungibleTokenPositionManager_evt_IncreaseLiquidity = null | ||
, NonfungibleTokenPositionManager_evt_DecreaseLiquidity = null | ||
, position_manager_addr = null | ||
) | ||
%} | ||
WITH id_to_lp AS | ||
( | ||
SELECT | ||
distinct t.tokenId | ||
,t.to AS lp_address | ||
FROM | ||
{{ NonfungibleTokenPositionManager_evt_Transfer }} t | ||
WHERE | ||
t."from" = 0x0000000000000000000000000000000000000000 | ||
) | ||
|
||
, mints AS | ||
( | ||
SELECT | ||
'mint' AS event_type | ||
,m.evt_block_number AS block_number | ||
,m.evt_block_time AS block_time | ||
,m.evt_tx_hash AS tx_hash | ||
,m.evt_index | ||
, {% if position_manager_addr %} | ||
id.lp_address | ||
{% else %} | ||
m.owner | ||
{% endif %} AS lp_address | ||
, {% if position_manager_addr %} | ||
cast(pm.tokenId AS double) | ||
{% else %} | ||
0 | ||
{% endif %} AS position_id | ||
, m.tickLower AS tick_lower | ||
, m.tickUpper AS tick_upper | ||
, m.amount AS liquidity | ||
, m.amount0 AS amount0 | ||
, m.amount1 AS amount1 | ||
, f.token0 AS token0_address | ||
, f.token1 AS token1_address | ||
, m.contract_address AS pool_address | ||
FROM | ||
{{ Pair_evt_Mint }} m | ||
INNER JOIN | ||
{{ Factory_evt_PoolCreated }} f | ||
ON f.pool = m.contract_address | ||
LEFT JOIN | ||
{{ NonfungibleTokenPositionManager_evt_IncreaseLiquidity }} pm | ||
ON m.owner = pm.contract_address and m.evt_tx_hash = pm.evt_tx_hash | ||
LEFT JOIN id_to_lp AS id | ||
ON pm.tokenId = id.tokenId | ||
{% if is_incremental() %} | ||
WHERE | ||
{{ incremental_predicate('m.evt_block_time') }} | ||
{% endif %} | ||
) | ||
|
||
, burns AS | ||
( | ||
SELECT | ||
'burn' AS event_type | ||
,b.evt_block_number AS block_number | ||
,b.evt_block_time AS block_time | ||
,b.evt_tx_hash AS tx_hash | ||
,b.evt_index | ||
, {% if position_manager_addr %} | ||
id.lp_address | ||
{% else %} | ||
b.owner | ||
{% endif %} AS lp_address | ||
, {% if position_manager_addr %} | ||
cast(pm.tokenId AS double) | ||
{% else %} | ||
0 | ||
{% endif %} AS position_id | ||
, b.tickLower AS tick_lower | ||
, b.tickUpper AS tick_upper | ||
, b.amount AS liquidity | ||
, b.amount0 | ||
, b.amount1 | ||
, f.token0 AS token0_address | ||
, f.token1 AS token1_address | ||
, m.contract_address AS pool_address | ||
FROM | ||
{{ Pair_evt_Burn }} b | ||
INNER JOIN | ||
{{ Factory_evt_PoolCreated }} f | ||
ON f.pool = b.contract_address | ||
LEFT JOIN | ||
{{ NonfungibleTokenPositionManager_evt_IncreaseLiquidity }} pm | ||
ON b.owner = pm.contract_address and b.evt_tx_hash = pm.evt_tx_hash | ||
LEFT JOIN id_to_lp AS id | ||
ON pm.tokenId = id.tokenId | ||
{% if is_incremental() %} | ||
WHERE | ||
{{ incremental_predicate('b.evt_block_time') }} | ||
{% endif %} | ||
) | ||
|
||
SELECT | ||
'{{ blockchain }}' AS blockchain | ||
, '{{ project }}' AS project | ||
, '{{ version }}' AS version | ||
, lp_data.event_type | ||
, lp_data.block_number | ||
, lp_data.block_time | ||
, date_trunc('MONTH', lp_data.block_time) AS block_month | ||
, lp_data.tx_hash | ||
, lp_data.evt_index | ||
, lp_data.lp_address | ||
, lp_data.position_id | ||
, lp.tick_lower | ||
, lp.tick_upper | ||
, CAST(lp_data.liquidity AS UINT256) AS liquidity_raw | ||
, CAST(lp_data.amount0 AS UINT256) AS amount0_raw | ||
, CAST(lp_data.amount1 AS UINT256) AS amount1_raw | ||
, lp_data.token0_address | ||
, lp_data.token1_address | ||
, lp_data.pool_address | ||
FROM | ||
( | ||
select * from mints | ||
union all | ||
select * from burns | ||
) lp_data | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
version: 1 | ||
|
||
models: | ||
# - name: dex_lps | ||
# meta: | ||
# blockchain: ethereum | ||
# sector: dex | ||
# contributors: 0xrusowsky | ||
# config: | ||
# tags: [ 'dex', 'lps' ] | ||
# tests: | ||
# - dbt_utils.unique_combination_of_columns: | ||
# combination_of_columns: | ||
# - blockchain | ||
# - project | ||
# - version | ||
# - tx_hash | ||
# - evt_index | ||
# columns: | ||
# - &blockchain | ||
# name: blockchain | ||
# description: "Blockchain where the DEX is deployed" | ||
# - &project | ||
# name: project | ||
# description: "Project name of the DEX" | ||
# tests: | ||
# - relationships: | ||
# to: ref('dex_info') | ||
# field: project | ||
# - &version | ||
# name: version | ||
# description: "Version of the contract built and deployed by the DEX project" | ||
# - &block_month | ||
# name: block_month | ||
# description: "Month of the event block time" | ||
# - &block_time | ||
# name: block_time | ||
# description: "UTC event block time of each DEX trade" | ||
# - &block_number | ||
# name: block_number | ||
# description: "Block number of each DEX trade" | ||
# - &token0_symbol | ||
# name: token0_symbol | ||
# description: "Token symbol for token bought in the trade" | ||
# - &token1_symbol | ||
# name: token1_symbol | ||
# description: "Token symbol for token sold in the trade" | ||
# - &token_pair | ||
# name: token_pair | ||
# description: "Token symbol pair for each token involved in the trade" | ||
# - &token0_amount_raw | ||
# name: token0_amount_raw | ||
# description: "Raw amount of token0" | ||
# - &token1_amount_raw | ||
# name: token1_amount_raw | ||
# description: "Raw amount of token1" | ||
# - &liquidity_amount_raw | ||
# name: liquidity_amount_raw | ||
# description: "Raw amount of liquidity provided" | ||
# - &token0_amount_usd | ||
# name: token0_amount_usd | ||
# description: "USD value of amount token0 provided at time of execution" | ||
# - &token1_amount_usd | ||
# name: token1_amount_usd | ||
# description: "USD value of amount token1 provided at time of execution" | ||
# - &liquidity_usd | ||
# name: liquidity_usd | ||
# description: "USD value of the liquidity provided at time of execution" | ||
# tests: | ||
# - dbt_utils.accepted_range: | ||
# max_value: 1000000000 # $1b is an arbitrary number, intended to flag outlier amounts early | ||
# - &token0_address | ||
# name: token0_address | ||
# description: "Contract address of the token bought" | ||
# - &token1_address | ||
# name: token1_address | ||
# description: "Contract address of the token sold" | ||
# - &pool_address | ||
# name: pool_address | ||
# description: "Project contract address which executed the trade on the blockchain" | ||
# - &liquidity_provider | ||
# name: liquidity_provider | ||
# description: "Address of the liquidity provider (LP)" | ||
# - &position_id | ||
# name: position_id | ||
# description: "ID of the NFT that represents the liquidity position. Zero if they didn't use the NFTPositionManager." | ||
# - &tick_lower | ||
# name: tick_lower | ||
# description: "Lower tick of the position." | ||
# - &tick_upper | ||
# name: tick_upper | ||
# description: "Upper tick of the position." | ||
# - &tx_hash | ||
# name: tx_hash | ||
# description: "Unique transaction hash value tied to each transaction on the DEX" | ||
# - &evt_index | ||
# name: evt_index | ||
# description: "Index of the corresponding trade event" | ||
|
||
- name: dex_base_lps | ||
meta: | ||
blockchain: ethereum | ||
sector: dex | ||
contributors: 0xrusowsky | ||
config: | ||
tags: [ 'dex' ] | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- blockchain | ||
- project | ||
- version | ||
- tx_hash | ||
- evt_index | ||
# columns: | ||
# - blockchain | ||
# - project | ||
# - version | ||
# - block_time | ||
# - block_month | ||
# - block_number | ||
# - amount0_raw | ||
# - amount1_raw | ||
# - liquidity_amount_raw | ||
# - token0_address | ||
# - token1_address | ||
# - pool_address | ||
# - liquidity_provider | ||
# - position_id | ||
# - tick_lower | ||
# - tick_upper | ||
# - tx_hash | ||
# - evt_index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{{ config( | ||
schema = 'dex' | ||
, alias = 'base_lps' | ||
, partition_by = ['block_month', 'blockchain', 'project'] | ||
, materialized = 'incremental' | ||
, file_format = 'delta' | ||
, incremental_strategy = 'merge' | ||
, unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index'] | ||
, incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] | ||
) | ||
}} | ||
|
||
{% set models = [ | ||
ref('dex_ethereum_base_lps') | ||
] %} | ||
|
||
with base_union as ( | ||
SELECT * | ||
FROM | ||
( | ||
{% for model in models %} | ||
SELECT | ||
blockchain | ||
, project | ||
, version | ||
, block_time | ||
, block_month | ||
, block_number | ||
, token0_amount_raw | ||
, token1_amount_raw | ||
, liquidity_amount_raw | ||
, token0_address | ||
, token1_address | ||
, pool_address | ||
, liquidity_provider | ||
, position_id | ||
, tick_lower | ||
, tick_upper | ||
, tx_hash | ||
, evt_index | ||
, row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank | ||
FROM | ||
{{ model }} | ||
{% if is_incremental() %} | ||
WHERE | ||
{{ incremental_predicate('block_time') }} | ||
{% endif %} | ||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
{% endfor %} | ||
) | ||
WHERE | ||
duplicates_rank = 1 | ||
) | ||
|
||
select | ||
* | ||
from | ||
base_union |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: dex_ethereum_base_lps | ||
tests: | ||
- check_dex_info_relationship | ||
|
||
- name: uniswap_v3_ethereum_base_lps | ||
meta: | ||
blockchain: ethereum | ||
sector: dex | ||
project: uniswap | ||
contributors: 0xrusowsky | ||
config: | ||
tags: [ 'ethereum', 'dex', 'lps', 'uniswap', 'v3' ] | ||
description: "uniswap ethereum v3 base lps" | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- tx_hash | ||
- evt_index | ||
# - check_dex_base_lps_seed: | ||
# seed_file: ref('uniswap_ethereum_base_lps_seed') | ||
# filter: | ||
# version: 3 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
yesterday i had to do other stuff, but will continue working on this during this afternoon and next week
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, if you have any problem please feel free to tag me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, thanks for your support!