Skip to content
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

. #1

Merged
merged 19 commits into from
Jun 6, 2023
Merged

. #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ If you fail to run `dbt compile`, here are some common error messages:

- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
- Find [dbt events](https://events.getdbt.com) near you
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
- Join the [chat](https://getdbt.com/community/join-the-community/) on Slack for live discussions and support
- Find [dbt events](https://getdbt.com/events/) near you
- Check out [the blog](https://getdbt.com/blog/) for the latest news on dbt's development and best practices
143 changes: 141 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ models:

ens:
+schema: ens
ethereum:
+schema: ens_ethereum

staking:
+schema: staking
Expand Down Expand Up @@ -175,6 +177,21 @@ models:
polygon:
+schema: gitcoin_polygon

blur:
+schema: blur
ethereum:
+schema: blur_ethereum

looksrare:
+schema: looksrare
ethereum:
+schema: looksrare_ethereum

x2y2:
+schema: x2y2
ethereum:
+schema: x2y2_ethereum

uniswap:
+schema: uniswap
arbitrum:
Expand Down Expand Up @@ -204,6 +221,8 @@ models:

paraswap:
+schema: paraswap
ethereum:
+schema: paraswap_ethereum
avalanche_c:
+schema: paraswap_avalanche_c
fantom:
Expand Down Expand Up @@ -811,6 +830,126 @@ models:
+schema: zeroex_bnb


ampleforth:
+schema: ampleforth
ethereum:
+schema: ampleforth_ethereum

apecoin:
+schema: apecoin
ethereum:
+schema: apecoin_ethereum

pangolin:
+schema: pangolin
avalanche_c:
+schema: pangolin_avalanche_c

giveth:
+schema: giveth
gnosis:
+schema: giveth_gnosis

genie:
+schema: genie
ethereum:
+schema: genie_ethereum

forta_network:
+schema: forta_network
ethereum:
+schema: forta_network_ethereum

gas_dao:
+schema: gas_dao
ethereum:
+schema: gas_dao_ethereum

ribbon:
+schema: ribbon
ethereum:
+schema: ribbon_ethereum

galxe:
+schema: galxe
ethereum:
+schema: galxe_ethereum

gearbox:
+schema: gearbox
ethereum:
+schema: gearbox_ethereum

snowswap:
+schema: snowswap
ethereum:
+schema: snowswap_ethereum

arbitrum:
+schema: arbitrum
arbitrum:
+schema: arbitrum_arbitrum

forefront:
+schema: forefront
ethereum:
+schema: forefront_ethereum

component:
+schema: component
ethereum:
+schema: component_ethereum

alchemydao:
+schema: alchemydao
ethereum:
+schema: alchemydao_ethereum

tokenfy:
+schema: tokenfy
ethereum:
+schema: tokenfy_ethereum

thales:
+schema: thales
ethereum:
+schema: thales_ethereum

shapeshift:
+schema: shapeshift
ethereum:
+schema: shapeshift_ethereum

value_defi:
+schema: value_defi
ethereum:
+schema: value_defi_ethereum

botto:
+schema: botto
ethereum:
+schema: botto_ethereum

notional:
+schema: notional
ethereum:
+schema: notional_ethereum

dydx:
+schema: dydx
ethereum:
+schema: dydx_ethereum

dappradar:
+schema: dappradar
ethereum:
+schema: dappradar_ethereum

paladin:
+schema: paladin
ethereum:
+schema: paladin_ethereum

wombat:
+schema: wombat
bnb:
Expand All @@ -830,8 +969,8 @@ models:
+schema: hop_protocol
optimism:
+schema: hop_protocol_optimism
# ethereum:
# +schema: hop_protocol_ethereum
ethereum:
+schema: hop_protocol_ethereum
# polygon:
# +schema: hop_protocol_polygon
# polygon2:
Expand Down
1 change: 1 addition & 0 deletions models/_sector/nft/trades/old/nft_events_old.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ref('aavegotchi_polygon_events')
,ref('element_bnb_events')
,ref('element_avalanche_c_events')
,ref('element_polygon_events')
,ref('fractal_polygon_events')
,ref('liquidifty_bnb_events')
,ref('liquidifty_ethereum_events')
Expand Down
175 changes: 175 additions & 0 deletions models/_sector/nft/trades/old/platforms/element_polygon_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{{ config(
schema = 'element_polygon',
alias = 'events',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_time', 'unique_trade_id']
)
}}

WITH element_txs AS (
-- polygon ERC721 Sells
SELECT 'polygon' AS blockchain
, 'element' AS project
, 'v1' AS version
, ee.evt_block_time AS block_time
, ee.erc721TokenId AS token_id
, 'erc721' AS token_standard
, 'Single Item Trade' AS trade_type
, 1 AS number_of_items
, 'Offer Accepted' AS trade_category
, ee.maker AS seller
, ee.taker AS buyer
, ee.erc20TokenAmount AS amount_raw
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'
ELSE ee.erc20Token END AS currency_contract
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN 'WMATIC' END AS currency_symbol
, ee.erc721Token AS nft_contract_address
, ee.contract_address AS project_contract_address
, ee.evt_tx_hash AS tx_hash
, ee.evt_block_number AS block_number
, ee.evt_index
FROM {{ source('element_ex_polygon','OrdersFeature_evt_ERC721SellOrderFilled') }} ee
{% if is_incremental() %}
WHERE ee.evt_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}

UNION ALL

-- polygon ERC721 Buys
SELECT 'polygon' AS blockchain
, 'element' AS project
, 'v1' AS version
, ee.evt_block_time AS block_time
, ee.erc721TokenId AS token_id
, 'erc721' AS token_standard
, 'Single Item Trade' AS trade_type
, 1 AS number_of_items
, 'Buy' AS trade_category
, ee.taker AS seller
, ee.maker AS buyer
, ee.erc20TokenAmount AS amount_raw
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'
ELSE ee.erc20Token END AS currency_contract
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN 'WMATIC' END AS currency_symbol
, ee.erc721Token AS nft_contract_address
, ee.contract_address AS project_contract_address
, ee.evt_tx_hash AS tx_hash
, ee.evt_block_number AS block_number
, ee.evt_index
FROM {{ source('element_ex_polygon','OrdersFeature_evt_ERC721BuyOrderFilled') }} ee
{% if is_incremental() %}
WHERE ee.evt_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}

UNION ALL

-- polygon ERC1155 Sells
SELECT 'polygon' AS blockchain
, 'element' AS project
, 'v1' AS version
, ee.evt_block_time AS block_time
, ee.erc1155TokenId AS token_id
, 'erc1155' AS token_standard
, 'Single Item Trade' AS trade_type
, 1 AS number_of_items
, 'Offer Accepted' AS trade_category
, ee.maker AS seller
, ee.taker AS buyer
, ee.erc20FillAmount AS amount_raw
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'
ELSE ee.erc20Token END AS currency_contract
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN 'WMATIC' END AS currency_symbol
, ee.erc1155Token AS nft_contract_address
, ee.contract_address AS project_contract_address
, ee.evt_tx_hash AS tx_hash
, ee.evt_block_number AS block_number
, ee.evt_index
FROM {{ source('element_ex_polygon','OrdersFeature_evt_ERC1155SellOrderFilled') }} ee
{% if is_incremental() %}
WHERE ee.evt_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}

UNION ALL

-- polygon ERC1155 Buys
SELECT 'polygon' AS blockchain
, 'element' AS project
, 'v1' AS version
, ee.evt_block_time AS block_time
, ee.erc1155TokenId AS token_id
, 'erc1155' AS token_standard
, 'Single Item Trade' AS trade_type
, 1 AS number_of_items
, 'Buy' AS trade_category
, ee.taker AS seller
, ee.maker AS buyer
, ee.erc20FillAmount AS amount_raw
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'
ELSE ee.erc20Token END AS currency_contract
, CASE WHEN ee.erc20Token='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN 'WMATIC' END AS currency_symbol
, ee.erc1155Token AS nft_contract_address
, ee.contract_address AS project_contract_address
, ee.evt_tx_hash AS tx_hash
, ee.evt_block_number AS block_number
, ee.evt_index
FROM {{ source('element_ex_polygon','OrdersFeature_evt_ERC1155BuyOrderFilled') }} ee
{% if is_incremental() %}
WHERE ee.evt_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
)

SELECT alet.blockchain
, alet.project
, alet.version
, alet.block_time
, date_trunc('day', alet.block_time) AS block_date
, alet.token_id
, polygon_nft_tokens.name AS collection
, alet.amount_raw/POWER(10, polygon_bep20_tokens.decimals)*prices.price AS amount_usd
, alet.token_standard
, CASE WHEN agg.name IS NOT NULL THEN 'Bundle Trade' ELSE 'Single Item Trade' END AS trade_type
, CAST(alet.number_of_items AS DECIMAL(38,0)) AS number_of_items
, alet.trade_category
, 'Trade' AS evt_type
, alet.seller
, alet.buyer
, alet.amount_raw/POWER(10, polygon_bep20_tokens.decimals) AS amount_original
, CAST(alet.amount_raw AS DECIMAL(38,0)) AS amount_raw
, COALESCE(alet.currency_symbol, polygon_bep20_tokens.symbol) AS currency_symbol
, alet.currency_contract
, alet.nft_contract_address
, alet.project_contract_address
, agg.name AS aggregator_name
, CASE WHEN agg.name IS NOT NULL THEN agg.contract_address END AS aggregator_address
, alet.tx_hash
, alet.block_number
, bt.from AS tx_from
, bt.to AS tx_to
, CAST(0 AS DOUBLE) AS platform_fee_amount_raw
, CAST(0 AS DOUBLE) AS platform_fee_amount
, CAST(0 AS DOUBLE) AS platform_fee_amount_usd
, CAST(0 AS DOUBLE) AS platform_fee_percentage
, CAST(0 AS DOUBLE) AS royalty_fee_amount_raw
, CAST(0 AS DOUBLE) AS royalty_fee_amount
, CAST(0 AS DOUBLE) AS royalty_fee_amount_usd
, CAST(0 AS DOUBLE) AS royalty_fee_percentage
, CAST('0' AS VARCHAR(5)) AS royalty_fee_receive_address
, CAST('0' AS VARCHAR(5)) AS royalty_fee_currency_symbol
, alet.blockchain || alet.project || alet.version || alet.tx_hash || alet.seller || alet.buyer || alet.nft_contract_address || alet.token_id || alet.evt_index AS unique_trade_id
FROM element_txs alet
LEFT JOIN {{ ref('nft_aggregators') }} agg ON alet.buyer=agg.contract_address AND agg.blockchain='polygon'
LEFT JOIN {{ ref('tokens_erc20') }} polygon_bep20_tokens ON polygon_bep20_tokens.contract_address=alet.currency_contract AND polygon_bep20_tokens.blockchain='polygon'
LEFT JOIN {{ ref('tokens_nft') }} polygon_nft_tokens ON polygon_nft_tokens.contract_address=alet.currency_contract AND polygon_nft_tokens.blockchain='polygon'
LEFT JOIN {{ source('prices', 'usd') }} prices ON prices.minute=date_trunc('minute', alet.block_time)
AND (prices.contract_address=alet.currency_contract AND prices.blockchain=alet.blockchain)
{% if is_incremental() %}
AND prices.minute >= date_trunc("day", now() - interval '1 week')
{% endif %}
LEFT JOIN {{ source('polygon','transactions') }} bt ON bt.hash=alet.tx_hash
AND bt.block_time=alet.block_time
{% if is_incremental() %}
AND bt.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}