From f2fadc1a3defa4fbf95350e8e9a3fba34bc1dd82 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Tue, 27 Jul 2021 19:59:46 -0400 Subject: [PATCH 01/86] terraswap tables --- models/terra/terraswap__lp_actions.sql | 43 +++++++++++++++ models/terra/terraswap__lp_stake.sql | 75 +++++++++++++++++++++++++ models/terra/terraswap__swaps.sql | 76 ++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 models/terra/terraswap__lp_actions.sql create mode 100644 models/terra/terraswap__lp_stake.sql create mode 100644 models/terra/terraswap__swaps.sql diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql new file mode 100644 index 00000000..fee5c975 --- /dev/null +++ b/models/terra/terraswap__lp_actions.sql @@ -0,0 +1,43 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'terraswap', 'lp'] + ) +}} + +with msgs as ( +SELECT + m.block_id, + m.block_timestamp, + m.tx_id, + msg_value:sender::string as sender, + 'provide_liquidity' as action, + msg_value:execute_msg:provide_liquidity:assets[0]:amount / POW(10,6) as token_0_amount, + coalesce(msg_value:execute_msg:provide_liquidity:assets[0]:info:token:contract_addr::string, + msg_value:execute_msg:provide_liquidity:assets[0]:info:native_token:denom::string) as token_0_address, + msg_value:execute_msg:provide_liquidity:assets[1]:amount / POW(10,6) as token_1_amount, + coalesce(msg_value:execute_msg:provide_liquidity:assets[1]:info:token:contract_addr::string, + msg_value:execute_msg:provide_liquidity:assets[1]:info:native_token:denom::string) as token_1_address, + msg_value:contract::string as pool_address +FROM {{source('silver_terra', 'msgs')}} m + +WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL --Ensures we only look for adding liquidity events +), + +events as ( +SELECT + tx_id, + event_attributes:share/POW(10,6) as lp_share_amount + event_attributes:"2_contract_address"::string as lp_pool_address +FROM {{source('silver_terra', 'msgs')}} + +WHERE tx_id IN(SELECT DISTINCT tx_id + FROM msgs) + AND event_type = 'from_contract' + AND event_attributes:"0_action"::string = 'provide_liquidity' + +) \ No newline at end of file diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql new file mode 100644 index 00000000..146bdd69 --- /dev/null +++ b/models/terra/terraswap__lp_stake.sql @@ -0,0 +1,75 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'terraswap', 'lp'] + ) +}} + +-- LP Un-staking +WITH msgs AS( +SELECT + chain_id, + block_id, + block_timestamp, + tx_id, + 'unstake_lp' as event_type, + msg_value:sender::string as sender, + msg_value:execute_msg:unbond:amount / POW(10,6) as amount +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:unbond IS NOT NULL + AND block_timestamp >= current_date - 3 +order by block_timestamp desc +limit 100 +), + +events AS ( +SELECT + tx_id, + event_attributes:"0_contract_address"::string as contract_address +FROM {{source('silver_terra', 'msg_events')}} +where tx_id IN(SELECT distinct tx_id from msgs) + and event_type = 'execute_contract' + and msg_index = 0 +) + +SELECT + chain_id, + block_id, + block_timestamp, + m.tx_id, + event_type, + sender, + amount, + contract_address, + address_name as contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} + ON contract_address = address + +UNION + +-- LP Staking +SELECT + chain_id, + block_id, + block_timestamp, + tx_id, + 'stake_lp' as event_type, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + msg_value:contract::string as contract_address, + address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} + ON msg_value:contract::string = address + +WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL \ No newline at end of file diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql new file mode 100644 index 00000000..f937d817 --- /dev/null +++ b/models/terra/terraswap__swaps.sql @@ -0,0 +1,76 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'terraswap', 'swap'] + ) +}} + + +WITH msgs as ( +-- native to non-native/native +SELECT + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:contract::string as pool_address +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:swap IS NOT NULL + AND tx_status = 'SUCCEEDED' + + + UNION + +-- non-native to native +SELECT + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:contract::string as pool_address +FROM {{source('silver_terra', 'msgs')}} + +WHERE msg_value:execute_msg:send:msg:swap IS NOT NULL + AND tx_status = 'SUCCEEDED' +), + +events as ( +SELECT + tx_id, + as_number(event_attributes:tax_amount)/POW(10,6) as tax_amount, + event_attributes:commission_amount::numeric/POW(10,6) as commission_amount, + event_attributes:offer_amount::numeric/POW(10,6) as offer_amount, + event_attributes:offer_asset::string as offer_currency, + event_attributes:return_amount::numeric/POW(10,6) as return_amount, + event_attributes:ask_asset::string as return_currency +FROM {{source('silver_terra', 'msg_events')}} + +WHERE event_type = 'from_contract' + AND tx_id IN(SELECT DISTINCT tx_id + FROM msgs ) +) + + +SELECT + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + tax_amount, + commission_amount, + offer_amount, + offer_currency, + return_amount, + return_currency, + pool_address +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file From cf55911f55c2e5a05c1890fcac1b19701a1f88d9 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 22 Aug 2021 14:39:58 -0400 Subject: [PATCH 02/86] All of Mirror --- models/terra/mirror__close_collateral.sql | 126 ++++++++++++ models/terra/mirror__close_short_farm.sql | 165 ++++++++++++++++ models/terra/mirror__gov_staking.sql | 110 +++++++++++ models/terra/mirror__gov_submit_proposal.sql | 64 ++++++ models/terra/mirror__gov_vote.sql | 31 +++ models/terra/mirror__open_collateral.sql | 94 +++++++++ models/terra/mirror__open_short_farm.sql | 117 +++++++++++ models/terra/terraswap__lp_actions.sql | 195 ++++++++++++++++--- models/terra/terraswap__lp_stake.sql | 20 +- models/terra/terraswap__swaps.sql | 12 +- 10 files changed, 901 insertions(+), 33 deletions(-) create mode 100644 models/terra/mirror__close_collateral.sql create mode 100644 models/terra/mirror__close_short_farm.sql create mode 100644 models/terra/mirror__gov_staking.sql create mode 100644 models/terra/mirror__gov_submit_proposal.sql create mode 100644 models/terra/mirror__gov_vote.sql create mode 100644 models/terra/mirror__open_collateral.sql create mode 100644 models/terra/mirror__open_short_farm.sql diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql new file mode 100644 index 00000000..d4db1d07 --- /dev/null +++ b/models/terra/mirror__close_collateral.sql @@ -0,0 +1,126 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'collateral'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price_usd + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:execute_msg:send:msg:burn:position_idx as collateral_id, + msg_value:sender::string as sender, + msg_value:contract::string as contract_address, + l.address_name AS contract_label +FROM terra.msgs + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL + AND tx_status = 'SUCCEEDED' +), + +burns AS ( +SELECT + tx_id, + + event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, + event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, + protocol_fee_amount * o.price AS procotol_fee_amount_usd, + + event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, + burn_amount * i.price AS burn_amount_usd, + event_attributes:burn_amount[0]:denom::string AS burn_currency +FROM terra.msg_events t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.protocol_fee_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.burn_currency = i.currency + +WHERE event_attributes:burn_amount IS NOT NULL + AND tx_id IN(SELECT DISTINCT tx_id + FROM msgs) + AND tx_status = 'SUCCEEDED' +), + +withdraw as ( +SELECT + tx_id, + + event_attributes:tax_amount[0]:amount /POW(10,6) AS tax_amount, + tax_amount * o.price AS tax_amount_usd, + event_attributes:tax_amount[0]:denom::string AS tax_currency, + + event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, + withdraw_amount * i.price AS withdraw_amount_usd, + event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency +FROM terra.msg_events t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.tax_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.withdraw_currency = i.currency + +WHERE event_attributes:withdraw_amount IS NOT NULL + AND tx_id IN(SELECT DISTINCT tx_id + FROM msgs) + AND tx_status = 'SUCCEEDED' +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + collateral_id, + sender, + protocol_fee_amount, + procotol_fee_amount_usd, + protocol_fee_currency, + tax_amount, + tax_amount_usd, + tax_currency, + burn_amount, + burn_amount_usd, + burn_currency, + withdraw_amount, + withdraw_amount_usd, + withdraw_currency, + contract_address, + contract_label +FROM msgs m + +JOIN burns b + ON m.tx_id = b.tx_id + +JOIN withdraw w + ON m.tx_id = w.tx_id \ No newline at end of file diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql new file mode 100644 index 00000000..1a7bca7f --- /dev/null +++ b/models/terra/mirror__close_short_farm.sql @@ -0,0 +1,165 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'short_farm'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price_usd + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +tx AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value +FROM terra.msgs +WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' + AND tx_status = = 'SUCCEEDED' + +), + +event_tx AS ( + +SELECT + block_timestamp, + tx_id, + event_attributes +FROM terra.msg_events +WHERE tx_id IN(select tx_id from tx) + AND event_type = 'from_contract' + +), + +msgs as ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:execute_msg:send:msg:burn:position_idx as collateral_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM tx + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +), + +withdraw_events AS ( + +SELECT + tx_id, + + event_attributes:withdraw_amount[0]:amount / POW(10,6) AS withdraw_amount, + withdraw_amount * o.price AS withdraw_amount_usd, + event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency, + + event_attributes:unlocked_amount[0]:amount / POW(10,6) AS unlocked_amount, + unlocked_amount * i.price AS unlocked_amount_usd, + event_attributes:unlocked_amount[0]:denom::string AS unlocked_currency, + + (event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount) / POW(10,6) AS tax, + tax * a.price AS tax_usd, + event_attributes:"0_tax_amount"[0]:denom::string AS tax_currency + +FROM event_tx t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.withdraw_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.unlocked_currency = i.currency + +LEFT OUTER JOIN prices a + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.tax_currency = i.currency + +WHERE event_attributes:withdraw_amount IS NOT NULL + +), + +burn_events AS ( + +SELECT + tx_id, + + event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, + burn_amount * o.price AS burn_amount_usd, + event_attributes:burn_amount[0]:denom::string AS burn_currency, + + event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee, + protocol_fee * i.price AS protocol_fee_usd, + event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency +FROM event_tx t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.burn_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.protocol_fee_currency = i.currency + +WHERE event_attributes:burn_amount IS NOT NULL + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + collateral_id, + sender, + withdraw_amount, + withdraw_amount_usd, + withdraw_currency, + burn_amount, + burn_amount_usd, + burn_currency, + unlocked_amount, + unlocked_amount_usd, + unlocked_currency, + tax, + tax_usd, + tax_currency, + protocol_fee, + protocol_fee_usd, + protocol_fee_currency, + contract_address, + contract_label +FROM msgs m + +JOIN withdraw_events w + ON m.tx_id = w.tx_id + +JOIN burn_events b + ON m.tx_id = b.tx_id + +WHERE unlocked_amount IS NOT NULL \ No newline at end of file diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql new file mode 100644 index 00000000..02d6a0bd --- /dev/null +++ b/models/terra/mirror__gov_staking.sql @@ -0,0 +1,110 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'gov'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price_usd + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +stake_msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as event_amount, + event_amount * o.price AS event_amount_usd, + msg_value:contract::string as event_currency, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM terra.msgs t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.event_currency = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' + AND tx_status = = 'SUCCEEDED' + +), + +stake_events AS ( +SELECT + tx_id, + event_attributes:share as shares +FROM terra.msg_events +WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) + AND event_type = 'from_contract' +) + +-- Staking +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + 'stake' as event_type, + sender, + event_amount, + event_amount_usd, + event_currency, + shares, + contract_address, + contract_label +FROM stake_msgs m + +JOIN stake_events e + ON m.tx_id = e.tx_id + +UNION + +-- Unstaking + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'unstake' as event_type, + msg_value:sender::string as sender, + msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, + event_amount * o.price AS event_amount_usd, + 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' as event_currency, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM terra.msgs t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.event_currency = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL + AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' + AND tx_status = = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql new file mode 100644 index 00000000..d47877a8 --- /dev/null +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -0,0 +1,64 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'gov'] + ) +}} + +WITH msgs AS ( +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as creator, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + msg_value:execute_msg:send:msg:create_poll:title::string as title, + msg_value:execute_msg:send:msg:create_poll:link::string as link, + msg_value:execute_msg:send:msg:create_poll:description::string as description, + msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, + msg_value:execute_msg:send:contract::string as contract_address +FROM terra.msgs +WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance + AND tx_status = = 'SUCCEEDED' +), + +events AS ( +SELECT + tx_id, + to_timestamp(event_attributes:end_time) as end_time, + event_attributes:poll_id as poll_id +FROM terra.msg_events +WHERE tx_id IN(select tx_id from msgs) + AND event_type = 'from_contract' +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + poll_id, + end_time, + creator, + amount, + title, + link, + description, + msg, + contract_address, + l.address_name AS contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address \ No newline at end of file diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql new file mode 100644 index 00000000..7262bba4 --- /dev/null +++ b/models/terra/mirror__gov_vote.sql @@ -0,0 +1,31 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'gov'] + ) +}} + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as voter, + msg_value:execute_msg:cast_vote:poll_id as poll_id, + msg_value:execute_msg:cast_vote:vote::string as vote, + msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, + msg_value:contract::string as contract_address, + l.addres_name as contract_label +FROM terra.msgs + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance + AND msg_value:execute_msg:cast_vote IS NOT NULL + AND tx_status = = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql new file mode 100644 index 00000000..88941aa6 --- /dev/null +++ b/models/terra/mirror__open_collateral.sql @@ -0,0 +1,94 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'collateral'] + ) +}} + + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price_usd + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:execute_msg:open_position:collateral_ratio as collateral_ratio, + msg_value:sender::string as sender, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM terra.msgs + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' -- Mirror Mint Contract + AND msg_value:execute_msg:open_position IS NOT NULL + AND tx_status = 'SUCCEEDED' + +), + +events AS( + +SELECT + tx_id, + event_attributes:position_idx as collateral_id, + event_attributes:collateral_amount[0]:amount/ POW(10,6) as collateral_amount, + collateral_amount * o.price AS collateral_amount_usd, + event_attributes:collateral_amount[0]:denom::string as collateral_currency, + event_attributes:mint_amount[0]:amount/ POW(10,6) as mint_amount, + mint_amount * i.price AS mint_amount_usd, + event_attributes:mint_amount[0]:denom::string as mint_currency +FROM terra.msg_events t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.collateral_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.mint_currency = i.currency + +WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) + AND event_type = 'from_contract' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + collateral_id, + collateral_ratio, + sender, + collateral_amount, + collateral_amount_usd, + collateral_currency, + mint_amount, + mint_amount_usd, + mint_currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql new file mode 100644 index 00000000..91c9dcf2 --- /dev/null +++ b/models/terra/mirror__open_short_farm.sql @@ -0,0 +1,117 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'short_farm'] + ) +}} + +WITH msgs as( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string AS sender, + msg_value:execute_msg:open_position:collateral_ratio AS collateral_ratio, + msg_value:contract::string AS contract_address, + l.address_name AS contract_label +FROM terra.msgs + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' --Mirror Mint + AND msg_value:execute_msg:open_position IS NOT NULL + AND tx_status = = 'SUCCEEDED' + +), + +events as ( + +SELECT + tx_id, + event_attributes:"0_position_idx" as collateral_id, + + event_attributes:collateral_amount[0]:amount / POW(10,6) AS collateral_amount, + collateral_amount * o.price AS collateral_amount_usd, + event_attributes:collateral_amount[0]:denom::string AS collateral_currency, + + event_attributes:mint_amount[0]:amount / POW(10,6) AS mint_amount, + mint_amount * i.price AS mint_amount_usd, + event_attributes:mint_amount[0]:denom::string AS mint_currency, + + event_attributes:return_amount / POW(10,6) AS return_amount, + return_amount * r.price AS return_amount_usd, + 'uusd' AS return_currency, + + event_attributes:locked_amount[0]:amount / POW(10,6) AS locked_amount, + locked_amount * l.price AS locked_amount_usd, + event_attributes:locked_amount[0]:denom::string AS locked_currency, + + event_attributes:tax_amount / POW(10,6) AS tax, + event_attributes:commission_amount / POW(10,6) AS commission, + event_attributes:spread_amount / POW(10,6) AS spread, + + to_timestamp(event_attributes:unlock_time) AS unlock_time +FROM terra.msg_events t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.collateral_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.mint_currency = i.currency + +LEFT OUTER JOIN prices r + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.return_amount = o.currency + +LEFT OUTER JOIN prices l + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.locked_currency = i.currency + +WHERE event_type = 'from_contract' + AND event_attributes:is_short::string = 'true' + AND event_attributes:from::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' -- Mirror Mint + AND tx_status = = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + collateral_ratio, + collateral_id, + sender, + collateral_amount, + collateral_amount_usd, + collateral_currency, + mint_amount, + mint_amount_usd, + mint_currency, + return_amount, + return_amount_usd, + return_currency, + locked_amount, + locked_amount_usd, + locked_currency, + tax, + commission, + spread, + unlock_time, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index fee5c975..7571e52c 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -9,35 +9,182 @@ ) }} -with msgs as ( -SELECT - m.block_id, - m.block_timestamp, - m.tx_id, +WITH prices as ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price_usd + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +provide_msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'provide_liquidity' as event_type, msg_value:sender::string as sender, - 'provide_liquidity' as action, - msg_value:execute_msg:provide_liquidity:assets[0]:amount / POW(10,6) as token_0_amount, - coalesce(msg_value:execute_msg:provide_liquidity:assets[0]:info:token:contract_addr::string, - msg_value:execute_msg:provide_liquidity:assets[0]:info:native_token:denom::string) as token_0_address, - msg_value:execute_msg:provide_liquidity:assets[1]:amount / POW(10,6) as token_1_amount, - coalesce(msg_value:execute_msg:provide_liquidity:assets[1]:info:token:contract_addr::string, - msg_value:execute_msg:provide_liquidity:assets[1]:info:native_token:denom::string) as token_1_address, - msg_value:contract::string as pool_address -FROM {{source('silver_terra', 'msgs')}} m - -WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL --Ensures we only look for adding liquidity events + msg_value:contract::string as pool_address, + l.address_name AS pool_name +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON pool_address = l.address + +WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL + AND tx_status = 'SUCCEEDED' + ), -events as ( -SELECT +provide_events AS ( +SELECT + tx_id, + + event_attributes:assets[0]:amount / POW(10,6) AS token_0_amount, + token_0_amount * o.price AS token_0_amount_usd, + event_attributes:assets[0]:denom::string AS token_0_currency, + + event_attributes:assets[1]:amount / POW(10,6) AS token_1_amount, + token_1_amount * i.price AS token_1_amount_usd, + event_attributes:assets[1]:denom::string AS token_1_currency, + + event_attributes:share / POW(10,6) AS lp_share_amount, + CASE + WHEN event_attributes:"2_contract_address"::string = 'terra17yap3mhph35pcwvhza38c2lkj7gzywzy05h7l0' THEN event_attributes:"4_contract_address"::string + ELSE event_attributes:"2_contract_address"::string + END AS lp_pool_address, + l.address_name AS lp_pool_name +FROM {{source('silver_terra', 'msg_events')}} t + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON lp_pool_address = l.address + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.token_0_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.token_1_currency = i.currency + +WHERE msg_index = 1 + AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) + AND event_type = 'from_contract' + +), + +withdraw_msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, tx_id, - event_attributes:share/POW(10,6) as lp_share_amount - event_attributes:"2_contract_address"::string as lp_pool_address + 'withdraw_liquidity' as event_type, + msg_value:sender::string as sender, + msg_value:contract::string as lp_pool_address, + l.address_name AS lp_pool_name, + msg_value:execute_msg:send:contract::string as pool_address, + p.address_name AS pool_name FROM {{source('silver_terra', 'msgs')}} -WHERE tx_id IN(SELECT DISTINCT tx_id - FROM msgs) +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as p +ON pool_address = p.address + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON lp_pool_address = l.address + +WHERE msg_value:execute_msg:send:msg:withdraw_liquidity IS NOT NULL + AND tx_status = 'SUCCEEDED' + +), + +withdraw_events AS ( + +SELECT + tx_id, + + event_attributes:refund_assets[0]:amount / POW(10,6) AS token_0_amount, + token_0_amount * o.price AS token_0_amount_usd, + event_attributes:refund_assets[0]:denom::string AS token_0_currency, + + event_attributes:refund_assets[1]:amount / POW(10,6) AS token_1_amount, + token_1_amount * i.price AS token_1_amount_usd, + event_attributes:refund_assets[1]:denom::string AS token_1_currency, + + event_attributes:withdrawn_share / POW(10,6) as lp_share_amount +FROM {{source('silver_terra', 'msg_events')}} t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND t.token_0_currency = o.currency + +LEFT OUTER JOIN prices i + ON date_trunc('hour', t.block_timestamp) = i.hour + AND t.token_1_currency = i.currency + +WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' - AND event_attributes:"0_action"::string = 'provide_liquidity' + AND event_attributes:refund_assets IS NOT NULL + +) + +-- Provide Liquidity +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + event_type, + sender, + token_0_amount, + token_0_amount_usd, + token_0_currency, + token_1_amount, + token_1_amount_usd, + token_1_currency, + pool_address, + pool_name, + lp_share_amount, + lp_pool_address, + lp_pool_name +FROM provide_msgs m + +JOIN provide_events e + ON m.tx_id = e.tx_id + +UNION + +-- Remove Liquidity +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + event_type, + sender, + token_0_amount, + token_0_amount_usd, + token_0_currency, + token_1_amount, + token_1_amount_usd, + token_1_currency, + pool_address, + pool_name, + lp_share_amount, + lp_pool_address, + lp_pool_name +FROM withdraw_msgs m -) \ No newline at end of file +JOIN withdraw_events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql index 146bdd69..253902e0 100644 --- a/models/terra/terraswap__lp_stake.sql +++ b/models/terra/terraswap__lp_stake.sql @@ -10,7 +10,8 @@ }} -- LP Un-staking -WITH msgs AS( +WITH msgs AS ( + SELECT chain_id, block_id, @@ -21,21 +22,23 @@ SELECT msg_value:execute_msg:unbond:amount / POW(10,6) as amount FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:unbond IS NOT NULL - AND block_timestamp >= current_date - 3 -order by block_timestamp desc -limit 100 + AND tx_status = 'SUCCEEDED' + ), events AS ( + SELECT tx_id, event_attributes:"0_contract_address"::string as contract_address FROM {{source('silver_terra', 'msg_events')}} where tx_id IN(SELECT distinct tx_id from msgs) - and event_type = 'execute_contract' - and msg_index = 0 + AND event_type = 'execute_contract' + AND msg_index = 0 + ) +-- unstake SELECT chain_id, block_id, @@ -56,7 +59,7 @@ LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} UNION --- LP Staking +-- stake SELECT chain_id, block_id, @@ -72,4 +75,5 @@ FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} ON msg_value:contract::string = address -WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL \ No newline at end of file +WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index f937d817..56adc340 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -66,11 +66,21 @@ SELECT tax_amount, commission_amount, offer_amount, + offer_amount * o.price AS offer_amount_usd, offer_currency, return_amount, + return_amount * r.price AS return_amount_usd, return_currency, pool_address FROM msgs m JOIN events e - ON m.tx_id = e.tx_id \ No newline at end of file + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND m.offer_currency = o.currency + +LEFT OUTER JOIN prices r + ON date_trunc('hour', t.block_timestamp) = r.hour + AND m.return_currency = r.currency \ No newline at end of file From e42dc03ddc056c82799a0f58d5b63e9e594fdfdb Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 22 Aug 2021 14:42:01 -0400 Subject: [PATCH 03/86] added pool_name to swap file --- models/terra/terraswap__swaps.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index 56adc340..849cc5ab 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -71,7 +71,8 @@ SELECT return_amount, return_amount * r.price AS return_amount_usd, return_currency, - pool_address + pool_address, + l.address_name AS pool_name FROM msgs m JOIN events e @@ -83,4 +84,7 @@ LEFT OUTER JOIN prices o LEFT OUTER JOIN prices r ON date_trunc('hour', t.block_timestamp) = r.hour - AND m.return_currency = r.currency \ No newline at end of file + AND m.return_currency = r.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} l + ON pool_address = address \ No newline at end of file From 25766919da7be7309224ba865ad375fd3a1d9af7 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 5 Sep 2021 16:12:41 -0400 Subject: [PATCH 04/86] anchor + updated mirror --- models/terra/anchor__bonds.sql | 91 ++++++++++++++ models/terra/anchor__borrows.sql | 47 +++++++ models/terra/anchor__burns.sql | 46 +++++++ models/terra/anchor__claim_reward.sql | 122 +++++++++++++++++++ models/terra/anchor__collateral.sql | 110 +++++++++++++++++ models/terra/anchor__deposits.sql | 90 ++++++++++++++ models/terra/anchor__liquidations.sql | 94 ++++++++++++++ models/terra/anchor__redeem.sql | 46 +++++++ models/terra/anchor__repay.sql | 46 +++++++ models/terra/anchor__stake.sql | 111 +++++++++++++++++ models/terra/mirror__close_collateral.sql | 6 +- models/terra/mirror__close_short_farm.sql | 4 +- models/terra/mirror__gov_staking.sql | 6 +- models/terra/mirror__gov_submit_proposal.sql | 4 +- models/terra/mirror__gov_vote.sql | 2 +- models/terra/mirror__open_collateral.sql | 4 +- models/terra/mirror__open_short_farm.sql | 4 +- 17 files changed, 818 insertions(+), 15 deletions(-) create mode 100644 models/terra/anchor__bonds.sql create mode 100644 models/terra/anchor__borrows.sql create mode 100644 models/terra/anchor__burns.sql create mode 100644 models/terra/anchor__claim_reward.sql create mode 100644 models/terra/anchor__collateral.sql create mode 100644 models/terra/anchor__deposits.sql create mode 100644 models/terra/anchor__liquidations.sql create mode 100644 models/terra/anchor__redeem.sql create mode 100644 models/terra/anchor__repay.sql create mode 100644 models/terra/anchor__stake.sql diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql new file mode 100644 index 00000000..68f8699a --- /dev/null +++ b/models/terra/anchor__bonds.sql @@ -0,0 +1,91 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'bonds'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string AS sender, + msg_value:coins[0]:amount / POW(10,6) AS bonded_amount, + bonded_amount * price AS bonded_amount_usd, + msg_value:coins[0]:denom::string as bonded_currency, + msg_value:execute_msg:bond:validator::string AS validator, + msg_value:contract::string AS contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND bonded_currency = o.currency + +WHERE msg_value:execute_msg:bond IS NOT NULL + AND tx_status = 'SUCCEEDED' + +), + +events AS ( + +SELECT + tx_id, + event_attributes:minted / POW(10,6) AS minted_amount, + minted_amount * price AS minted_amount_usd, + event_attributes:"1_contract_address"::string as minted_currency +FROM {{source('silver_terra', 'msg_events')}} + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND minted_currency = o.currency + +WHERE tx_id IN(SELECT tx_id FROM msgs) + AND event_type = 'from_contract' + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + bonded_amount, + bonded_amount_usd, + bonded_currency, + validator, + minted_amount, + minted_amount_usd, + minted_currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql new file mode 100644 index 00000000..79d53596 --- /dev/null +++ b/models/terra/anchor__borrows.sql @@ -0,0 +1,47 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'borrows'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:borrow_stable:borrow_amount / POW(10,6) as amount, + amount * price AS amount_usd, + 'uusd' as currency, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND m.currency = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:borrow_stable IS NOT NULL -- Anchor Borrow + AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' -- Anchor Market Contract + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql new file mode 100644 index 00000000..b5c7a0cf --- /dev/null +++ b/models/terra/anchor__burns.sql @@ -0,0 +1,46 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'collateral'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + amount * price AS amount_usd, + msg_value:contract::string as currency, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND m.currency = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:send:msg:unbond IS NOT NULL + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__claim_reward.sql b/models/terra/anchor__claim_reward.sql new file mode 100644 index 00000000..b6977fdf --- /dev/null +++ b/models/terra/anchor__claim_reward.sql @@ -0,0 +1,122 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'reward'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +withdraw_msgs AS ( + +SELECT + tx_id, + msg_index, + msg_value:contract::string as claim_0_contract +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:withdraw IS NOT NULL + AND msg_index = 0 + AND msg_value:contract::string = 'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3' + AND tx_status = 'SUCCEEDED' + +), + +claim_msgs AS ( + +SELECT + tx_id, + msg_index, + msg_value:sender::string as sender, + msg_value:contract::string as claim_1_contract +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:claim_rewards IS NOT NULL + AND msg_index = 1 + AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' + AND tx_status = 'SUCCEEDED' + +), + +withdraw AS ( + +SELECT + m.tx_id, + claim_0_contract, + event_attributes:"0_amount" / POW(10,6) as claim_0_amount, + claim_0_amount * price AS claim_0_amount_usd, + event_attributes:"1_contract_address"::string as claim_0_currency +FROM {{source('silver_terra', 'msg_events')}} e + +JOIN withdraw_msgs m + ON m.tx_id = e.tx_id + AND m.msg_index = e.msg_index + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND claim_0_currency = o.currency + +WHERE event_type = 'from_contract' + AND tx_status = 'SUCCEEDED' + +), + +claim AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + claim_1_contract, + event_attributes:claim_amount / POW(10,6) as claim_1_amount, + claim_1_amount * price AS claim_1_amount_usd, + event_attributes:"2_contract_address"::string as claim_1_currency +FROM {{source('silver_terra', 'msg_events')}} e + +JOIN claim_msgs m + ON m.tx_id = e.tx_id + AND m.msg_index = e.msg_index + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND claim_1_currency = o.currency + +WHERE event_type = 'from_contract' + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + c.tx_id, + sender, + claim_0_amount, + claim_0_amount_usd, + claim_0_currency, + claim_0_contract, + claim_1_amount, + claim_1_amount_usd, + claim_1_currency, + claim_1_contract +FROM claim c + +JOIN withdraw w + ON c.tx_id = w.tx_id \ No newline at end of file diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql new file mode 100644 index 00000000..80cbb61f --- /dev/null +++ b/models/terra/anchor__collateral.sql @@ -0,0 +1,110 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'collateral'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'withdraw' as action, + msg_value:sender::string AS sender, + msg_value:execute_msg:send:contract::string AS contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:withdraw_collateral IS NOT NULL + AND tx_status = 'SUCCEEDED' + +), + +events AS ( + + SELECT + tx_id, + event_attributes:collaterals[0]:amount / POW(10,6) as amount, + amount * price AS amount_usd, + event_attributes:collaterals[0]:denom::string as currency +FROM {{source('silver_terra', 'msg_events')}} m + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND m.currency = o.currency + +WHERE tx_id IN(SELECT tx_id FROM msgs) + AND event_type = 'from_contract' + AND msg_index = 0 + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + action, + sender, + amount, + amount_usd, + currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + + +UNION + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'provide' as action, + msg_value:sender::string AS sender, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + amount * price AS amount_usd, + msg_value:contract::string as currency, + msg_value:execute_msg:send:contract::string AS contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND m.currency = o.currency + +WHERE msg_value:execute_msg:send:msg:deposit_collateral IS NOT NULL + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql new file mode 100644 index 00000000..fc9506ac --- /dev/null +++ b/models/terra/anchor__deposits.sql @@ -0,0 +1,90 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'deposits'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:coins[0]:amount / POW(10,6) as deposit_amount, + deposit_amount * price AS deposit_amount_usd, + msg_value:coins[0]:denom::string as deposit_currency, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND deposit_currency = o.currency + +WHERE msg_value:execute_msg:deposit_stable IS NOT NULL + AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' + AND tx_status = 'SUCCEEDED' + +), + +events AS ( + +SELECT + tx_id, + event_attributes:mint_amount / POW(10,6) as mint_amount, + mint_amount * price AS mint_amount_usd, + event_attributes:"1_contract_address"::string as mint_currency +FROM {{source('silver_terra', 'msg_events')}} + +LEFT OUTER JOIN prices o + ON date_trunc('hour', block_timestamp) = o.hour + AND mint_currency = o.currency + +WHERE event_type = 'from_contract' + AND tx_id IN(SELECT tx_id FROM msgs) + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + deposit_amount, + deposit_amount_usd, + deposit_currency, + mint_amount, + mint_amount_usd, + mint_currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql new file mode 100644 index 00000000..09e63a64 --- /dev/null +++ b/models/terra/anchor__liquidations.sql @@ -0,0 +1,94 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'liquidations'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:execute_msg:liquidate_collateral:borrower::string AS borrower, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:contract::string = 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8' + AND msg_value:execute_msg:liquidate_collateral IS NOT NULL + AND tx_status = 'SUCCEEDED' + +), + +events AS ( + +SELECT + tx_id, + event_attributes:liquidator::string AS liquidator, + event_attributes:collateral_amount / POW(10,6) AS liquidated_amount, + liquidated_amount * l.price AS liquidated_amount_usd, + event_attributes:collateral_token::string as liquidated_currency, + event_attributes:"1_repay_amount" as repay_amount, + repay_amount * r.price as repay_amount_usd, + event_attributes:stable_denom::string as repay_currency, + event_attributes:bid_fee / POW(10,6) AS bid_fee +FROM {{source('silver_terra', 'msg_events')}} + +LEFT OUTER JOIN prices l + ON date_trunc('hour', block_timestamp) = hour + AND liquidated_currency = currency + +LEFT OUTER JOIN prices r + ON date_trunc('hour', block_timestamp) = hour + AND repay_currency = currency + +WHERE event_type = 'from_contract' + AND tx_id IN(SELECT tx_id FROM msgs) + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + bid_fee, + borrower, + liquidator, + liquidated_amount, + liquidated_amount_usd, + liquidated_currency, + repay_amount, + repay_amount_usd, + repay_currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id \ No newline at end of file diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql new file mode 100644 index 00000000..f1f4031b --- /dev/null +++ b/models/terra/anchor__redeem.sql @@ -0,0 +1,46 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'redeem'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + amount * price AS amount_usd, + msg_value:contract::string as currency, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices r + ON date_trunc('hour', block_timestamp) = hour + AND m.currency = r.currency + +WHERE msg_value:execute_msg:send:msg:redeem_stable IS NOT NULL + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql new file mode 100644 index 00000000..a4c042cf --- /dev/null +++ b/models/terra/anchor__repay.sql @@ -0,0 +1,46 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'repay'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:coins[0]:amount / POW(10,6) as amount, + amount * price AS amount_usd, + msg_value:coins[0]:denom::string as currency, + msg_value:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices r + ON date_trunc('hour', block_timestamp) = hour + AND m.currency = r.currency + +WHERE msg_value:execute_msg:repay_stable IS NOT NULL + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__stake.sql b/models/terra/anchor__stake.sql new file mode 100644 index 00000000..b82edd0e --- /dev/null +++ b/models/terra/anchor__stake.sql @@ -0,0 +1,111 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'stake'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'unstake' as action, + msg_value:sender::string as sender, + msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as amount, + msg_value:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL + AND msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' + AND tx_status = 'SUCCEEDED' + +), + +events AS ( + +SELECT + tx_id, + price, + event_attributes:"0_contract_address"::string as currency +FROM {{source('silver_terra', 'msg_events')}} + +LEFT OUTER JOIN prices r + ON date_trunc('hour', block_timestamp) = hour + AND m.currency = r.currency + +WHERE event_type = 'execute_contract' + AND tx_id IN(SELECT tx_id FROM msgs) + AND msg_index = 0 + AND tx_status = 'SUCCEEDED' + +) + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + action, + sender, + amount, + amount * price AS amount_usd, + currency, + contract_address, + contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +UNION + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'stake' as action, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + amount * price AS amount_usd, + msg_value:contract::string as currency, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices r + ON date_trunc('hour', block_timestamp) = hour + AND m.currency = r.currency + +WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index d4db1d07..74b16ad7 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -32,7 +32,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON contract_address = l.address @@ -52,7 +52,7 @@ SELECT event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, burn_amount * i.price AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency -FROM terra.msg_events t +FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -79,7 +79,7 @@ SELECT event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, withdraw_amount * i.price AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency -FROM terra.msg_events t +FROM {{source('silver_terra', 'msg)_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 1a7bca7f..2cea45eb 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -30,7 +30,7 @@ SELECT block_timestamp, tx_id, msg_value -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' AND tx_status = = 'SUCCEEDED' @@ -43,7 +43,7 @@ SELECT block_timestamp, tx_id, event_attributes -FROM terra.msg_events +FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from tx) AND event_type = 'from_contract' diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index 02d6a0bd..a0786cde 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -35,7 +35,7 @@ SELECT msg_value:contract::string as event_currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM terra.msgs t +FROM {{source('silver_terra', 'msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -54,7 +54,7 @@ stake_events AS ( SELECT tx_id, event_attributes:share as shares -FROM terra.msg_events +FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' ) @@ -96,7 +96,7 @@ SELECT 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' as event_currency, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM terra.msgs t +FROM {{source('silver_terra', 'msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index d47877a8..954ae634 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -23,7 +23,7 @@ SELECT msg_value:execute_msg:send:msg:create_poll:description::string as description, msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, msg_value:execute_msg:send:contract::string as contract_address -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND tx_status = = 'SUCCEEDED' @@ -34,7 +34,7 @@ SELECT tx_id, to_timestamp(event_attributes:end_time) as end_time, event_attributes:poll_id as poll_id -FROM terra.msg_events +FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' ) diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 7262bba4..36b59afb 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -21,7 +21,7 @@ SELECT msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, l.addres_name as contract_label -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON contract_address = l.address diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index 88941aa6..391dcccc 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -34,7 +34,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON contract_address = l.address @@ -56,7 +56,7 @@ SELECT event_attributes:mint_amount[0]:amount/ POW(10,6) as mint_amount, mint_amount * i.price AS mint_amount_usd, event_attributes:mint_amount[0]:denom::string as mint_currency -FROM terra.msg_events t +FROM t{{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 91c9dcf2..133b6ffe 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -21,7 +21,7 @@ SELECT msg_value:execute_msg:open_position:collateral_ratio AS collateral_ratio, msg_value:contract::string AS contract_address, l.address_name AS contract_label -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON contract_address = l.address @@ -59,7 +59,7 @@ SELECT event_attributes:spread_amount / POW(10,6) AS spread, to_timestamp(event_attributes:unlock_time) AS unlock_time -FROM terra.msg_events t +FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour From 061869b6086aed8330b26ab4ed4190f516faf1e1 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 5 Sep 2021 16:33:47 -0400 Subject: [PATCH 05/86] Anchor Asset oracle prices (bETH, bLUNA) --- models/terra/terra__oracle_prices.sql | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/models/terra/terra__oracle_prices.sql b/models/terra/terra__oracle_prices.sql index 3b548f39..6097e6d4 100644 --- a/models/terra/terra__oracle_prices.sql +++ b/models/terra/terra__oracle_prices.sql @@ -149,4 +149,25 @@ SELECT FROM massets ma LEFT OUTER JOIN prices pp - ON date_trunc('hour', ma.block_timestamp) = pp.block_timestamp \ No newline at end of file + ON date_trunc('hour', ma.block_timestamp) = pp.block_timestamp + +UNION + +SELECT + blockchain, + block_timestamp, + event_attributes:asset::string as currency, + l.address_name as symbol, + event_attributes:price AS price_usd, + 'oracle' as source +FROM terra.msg_events + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON currency = l.address + +WHERE event_type = 'from_contract' + AND tx_id IN(SELECT tx_id + FROM terra.msgs + WHERE msg_value:contract::string = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t' + AND msg_value:execute_msg:feed_price IS NOT NULL + ) \ No newline at end of file From 1bb820d8f66d80396cc7e3d322bca4e0316c2bf5 Mon Sep 17 00:00:00 2001 From: Krane Date: Mon, 6 Sep 2021 04:10:02 +0530 Subject: [PATCH 06/86] fix: typo in dependency --- models/terra/mirror__close_collateral.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 74b16ad7..6824e707 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -79,7 +79,7 @@ SELECT event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, withdraw_amount * i.price AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency -FROM {{source('silver_terra', 'msg)_events')}} t +FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -123,4 +123,4 @@ JOIN burns b ON m.tx_id = b.tx_id JOIN withdraw w - ON m.tx_id = w.tx_id \ No newline at end of file + ON m.tx_id = w.tx_id From 2e42859c56d03802f82fbe04f6524fca6f379a29 Mon Sep 17 00:00:00 2001 From: Krane Date: Mon, 6 Sep 2021 10:07:47 +0530 Subject: [PATCH 07/86] fix: = = mistake --- models/terra/mirror__gov_submit_proposal.sql | 4 ++-- models/terra/mirror__gov_vote.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 954ae634..8e620b9b 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -26,7 +26,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance - AND tx_status = = 'SUCCEEDED' + AND tx_status = 'SUCCEEDED' ), events AS ( @@ -61,4 +61,4 @@ JOIN events e ON m.tx_id = e.tx_id LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address \ No newline at end of file +ON contract_address = l.address diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 36b59afb..07e6d8bb 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -28,4 +28,4 @@ ON contract_address = l.address WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND msg_value:execute_msg:cast_vote IS NOT NULL - AND tx_status = = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' From 3962340be672a7a4230d923cb5a16fde17b1e776 Mon Sep 17 00:00:00 2001 From: Krane Date: Mon, 6 Sep 2021 10:16:47 +0530 Subject: [PATCH 08/86] fix: = = mistake --- models/terra/mirror__open_short_farm.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 133b6ffe..2e5562b0 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -28,7 +28,7 @@ ON contract_address = l.address WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' --Mirror Mint AND msg_value:execute_msg:open_position IS NOT NULL - AND tx_status = = 'SUCCEEDED' + AND tx_status = 'SUCCEEDED' ), @@ -114,4 +114,4 @@ SELECT FROM msgs m JOIN events e - ON m.tx_id = e.tx_id \ No newline at end of file + ON m.tx_id = e.tx_id From 7f813c3c572806129f31e6b1d0da5ca85bc475a6 Mon Sep 17 00:00:00 2001 From: Krane Date: Fri, 10 Sep 2021 11:16:05 +0530 Subject: [PATCH 09/86] fix: = = mistake --- models/terra/mirror__open_short_farm.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 2e5562b0..405676d7 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -80,7 +80,7 @@ LEFT OUTER JOIN prices l WHERE event_type = 'from_contract' AND event_attributes:is_short::string = 'true' AND event_attributes:from::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' -- Mirror Mint - AND tx_status = = 'SUCCEEDED' + AND tx_status = 'SUCCEEDED' ) From 335807572008dca0645a349587096a12d10f319b Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Fri, 17 Sep 2021 16:11:18 -0400 Subject: [PATCH 10/86] minor improvements --- models/terra/anchor__bonds.sql | 2 +- models/terra/anchor__borrows.sql | 2 +- models/terra/anchor__burns.sql | 2 +- models/terra/anchor__claim_reward.sql | 12 ++++++++++-- models/terra/anchor__collateral.sql | 4 ++-- models/terra/anchor__deposits.sql | 2 +- models/terra/anchor__liquidations.sql | 2 +- models/terra/anchor__redeem.sql | 2 +- models/terra/anchor__repay.sql | 2 +- models/terra/anchor__stake.sql | 4 ++-- models/terra/mirror__close_collateral.sql | 2 +- models/terra/mirror__close_short_farm.sql | 12 ++++++------ models/terra/mirror__gov_staking.sql | 2 +- models/terra/mirror__gov_vote.sql | 2 +- models/terra/mirror__open_collateral.sql | 4 ++-- models/terra/mirror__open_short_farm.sql | 8 ++++---- models/terra/terra__oracle_prices.sql | 18 +++++++++++------- models/terra/terraswap__lp_actions.sql | 2 +- 18 files changed, 48 insertions(+), 36 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index 68f8699a..c7b79ef8 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -39,7 +39,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql index 79d53596..d256c675 100644 --- a/models/terra/anchor__borrows.sql +++ b/models/terra/anchor__borrows.sql @@ -40,7 +40,7 @@ LEFT OUTER JOIN prices o AND m.currency = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:borrow_stable IS NOT NULL -- Anchor Borrow AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' -- Anchor Market Contract diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql index b5c7a0cf..316c4963 100644 --- a/models/terra/anchor__burns.sql +++ b/models/terra/anchor__burns.sql @@ -40,7 +40,7 @@ LEFT OUTER JOIN prices o AND m.currency = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:send:msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__claim_reward.sql b/models/terra/anchor__claim_reward.sql index b6977fdf..180159bb 100644 --- a/models/terra/anchor__claim_reward.sql +++ b/models/terra/anchor__claim_reward.sql @@ -112,11 +112,19 @@ SELECT claim_0_amount_usd, claim_0_currency, claim_0_contract, + l0.address_name AS claim_0_contract_label, claim_1_amount, claim_1_amount_usd, claim_1_currency, - claim_1_contract + claim_1_contract, + l1.address_name AS claim_1_contract_label FROM claim c JOIN withdraw w - ON c.tx_id = w.tx_id \ No newline at end of file + ON c.tx_id = w.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l0 +ON claim_0_contract = l0.address + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l1 +ON claim_1_contract = l1.address \ No newline at end of file diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index 80cbb61f..e8c732e7 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -36,7 +36,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:withdraw_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' @@ -100,7 +100,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql index fc9506ac..1300f118 100644 --- a/models/terra/anchor__deposits.sql +++ b/models/terra/anchor__deposits.sql @@ -38,7 +38,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index 09e63a64..d0e9715e 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -35,7 +35,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8' AND msg_value:execute_msg:liquidate_collateral IS NOT NULL diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql index f1f4031b..d328efe1 100644 --- a/models/terra/anchor__redeem.sql +++ b/models/terra/anchor__redeem.sql @@ -36,7 +36,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql index a4c042cf..50d2c33d 100644 --- a/models/terra/anchor__repay.sql +++ b/models/terra/anchor__repay.sql @@ -36,7 +36,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour diff --git a/models/terra/anchor__stake.sql b/models/terra/anchor__stake.sql index b82edd0e..cb0a4536 100644 --- a/models/terra/anchor__stake.sql +++ b/models/terra/anchor__stake.sql @@ -37,7 +37,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' @@ -100,7 +100,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 6824e707..775374eb 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -35,7 +35,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND tx_status = 'SUCCEEDED' diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 2cea45eb..d76a6b05 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -64,7 +64,7 @@ SELECT FROM tx LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address ), @@ -89,15 +89,15 @@ FROM event_tx t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.withdraw_currency = o.currency + AND t.event_attributes:withdraw_amount[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.unlocked_currency = i.currency + AND t.event_attributes:unlocked_amount[0]:amount / POW(10,6) = i.currency LEFT OUTER JOIN prices a ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.tax_currency = i.currency + AND t.event_attributes:"0_tax_amount"[0]:denom::string = i.currency WHERE event_attributes:withdraw_amount IS NOT NULL @@ -119,11 +119,11 @@ FROM event_tx t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.burn_currency = o.currency + AND t.event_attributes:burn_amount[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.protocol_fee_currency = i.currency + AND t.event_attributes:protocol_fee[0]:denom::string = i.currency WHERE event_attributes:burn_amount IS NOT NULL diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index a0786cde..ec52f31e 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -103,7 +103,7 @@ LEFT OUTER JOIN prices o AND t.event_currency = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 07e6d8bb..300b8346 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -24,7 +24,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND msg_value:execute_msg:cast_vote IS NOT NULL diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index 391dcccc..d13e796d 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -60,11 +60,11 @@ FROM t{{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.collateral_currency = o.currency + AND t.event_attributes:collateral_amount[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.mint_currency = i.currency + AND t.event_attributes:mint_amount[0]:denom::string = i.currency WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND event_type = 'from_contract' diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 405676d7..43ebae5c 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -24,7 +24,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' --Mirror Mint AND msg_value:execute_msg:open_position IS NOT NULL @@ -63,11 +63,11 @@ FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.collateral_currency = o.currency + AND t.event_attributes:collateral_amount[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.mint_currency = i.currency + AND t.event_attributes:mint_amount[0]:denom::string = i.currency LEFT OUTER JOIN prices r ON date_trunc('hour', t.block_timestamp) = o.hour @@ -75,7 +75,7 @@ LEFT OUTER JOIN prices r LEFT OUTER JOIN prices l ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.locked_currency = i.currency + AND t.event_attributes:locked_amount[0]:denom::string = i.currency WHERE event_type = 'from_contract' AND event_attributes:is_short::string = 'true' diff --git a/models/terra/terra__oracle_prices.sql b/models/terra/terra__oracle_prices.sql index 6097e6d4..62a773be 100644 --- a/models/terra/terra__oracle_prices.sql +++ b/models/terra/terra__oracle_prices.sql @@ -154,20 +154,24 @@ LEFT OUTER JOIN prices pp UNION SELECT - blockchain, - block_timestamp, - event_attributes:asset::string as currency, + me.blockchain, + me.block_timestamp, + me.event_attributes:asset::string as currency, l.address_name as symbol, - event_attributes:price AS price_usd, + me.event_attributes:price / pe.price as luna_exchange_rate, + me.event_attributes:price AS price_usd, 'oracle' as source -FROM terra.msg_events +FROM {{source('silver_terra', 'msg_events')}} me LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON currency = l.address +ON event_attributes:asset::string = l.address + +LEFT OUTER JOIN prices pe + ON date_trunc('hour', me.block_timestamp) = pe.block_timestamp WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id - FROM terra.msgs + FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:contract::string = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t' AND msg_value:execute_msg:feed_price IS NOT NULL ) \ No newline at end of file diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 7571e52c..46823e5d 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -36,7 +36,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON pool_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' From bd4a9238040ffc8c76cd8152a27197330d016794 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Fri, 17 Sep 2021 16:14:17 -0400 Subject: [PATCH 11/86] change table name --- .../terra/{anchor__claim_reward.sql => anchor__reward_claims.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename models/terra/{anchor__claim_reward.sql => anchor__reward_claims.sql} (100%) diff --git a/models/terra/anchor__claim_reward.sql b/models/terra/anchor__reward_claims.sql similarity index 100% rename from models/terra/anchor__claim_reward.sql rename to models/terra/anchor__reward_claims.sql From 3862fdcae8fc881b9bf6bd5d7c5bac82584bb50d Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Fri, 17 Sep 2021 18:55:05 -0400 Subject: [PATCH 12/86] fixed all Anchor bugs, prod ready --- models/terra/anchor__bonds.sql | 8 +++--- models/terra/anchor__borrows.sql | 4 +-- models/terra/anchor__burns.sql | 6 ++--- models/terra/anchor__collateral.sql | 10 ++++---- models/terra/anchor__deposits.sql | 11 ++++++--- models/terra/anchor__liquidations.sql | 13 +++++----- models/terra/anchor__redeem.sql | 4 +-- models/terra/anchor__repay.sql | 4 +-- models/terra/anchor__reward_claims.sql | 30 +++++++++++------------ models/terra/anchor__stake.sql | 12 ++++----- models/terra/mirror__close_collateral.sql | 8 +++--- 11 files changed, 57 insertions(+), 53 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index c7b79ef8..3e9ecc79 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -24,7 +24,7 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -36,14 +36,14 @@ SELECT msg_value:execute_msg:bond:validator::string AS validator, msg_value:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND bonded_currency = o.currency + AND msg_value:coins[0]:denom::string = o.currency WHERE msg_value:execute_msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' @@ -61,7 +61,7 @@ FROM {{source('silver_terra', 'msg_events')}} LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND minted_currency = o.currency + AND event_attributes:"1_contract_address"::string = o.currency WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql index d256c675..1f176d7e 100644 --- a/models/terra/anchor__borrows.sql +++ b/models/terra/anchor__borrows.sql @@ -22,7 +22,7 @@ WITH prices AS ( ) SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -37,7 +37,7 @@ FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND m.currency = o.currency + AND 'uusd' = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql index 316c4963..6ddc948a 100644 --- a/models/terra/anchor__burns.sql +++ b/models/terra/anchor__burns.sql @@ -5,7 +5,7 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'anchor', 'collateral'] + tags=['snowflake', 'terra', 'anchor', 'burns'] ) }} @@ -22,7 +22,7 @@ WITH prices AS ( ) SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -37,7 +37,7 @@ FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND m.currency = o.currency + AND msg_value:contract::string = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index e8c732e7..e9d8193e 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -24,7 +24,7 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -33,7 +33,7 @@ SELECT msg_value:sender::string AS sender, msg_value:execute_msg:send:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -54,7 +54,7 @@ FROM {{source('silver_terra', 'msg_events')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND m.currency = o.currency + AND event_attributes:collaterals[0]:denom::string = o.currency WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' @@ -85,7 +85,7 @@ JOIN events e UNION SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -104,7 +104,7 @@ ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND m.currency = o.currency + AND msg_value:contract::string = o.currency WHERE msg_value:execute_msg:send:msg:deposit_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql index 1300f118..369e99ce 100644 --- a/models/terra/anchor__deposits.sql +++ b/models/terra/anchor__deposits.sql @@ -24,25 +24,26 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, tx_id, + msg_index, msg_value:sender::string as sender, msg_value:coins[0]:amount / POW(10,6) as deposit_amount, deposit_amount * price AS deposit_amount_usd, msg_value:coins[0]:denom::string as deposit_currency, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND deposit_currency = o.currency + AND msg_value:coins[0]:denom::string = o.currency WHERE msg_value:execute_msg:deposit_stable IS NOT NULL AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' @@ -54,6 +55,7 @@ events AS ( SELECT tx_id, + msg_index, event_attributes:mint_amount / POW(10,6) as mint_amount, mint_amount * price AS mint_amount_usd, event_attributes:"1_contract_address"::string as mint_currency @@ -61,10 +63,11 @@ FROM {{source('silver_terra', 'msg_events')}} LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour - AND mint_currency = o.currency + AND event_attributes:"1_contract_address"::string = o.currency WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id FROM msgs) + AND event_attributes:"0_action"::string = 'deposit_stable' AND tx_status = 'SUCCEEDED' ) diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index d0e9715e..cff4995c 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -24,7 +24,7 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -32,7 +32,7 @@ SELECT msg_value:execute_msg:liquidate_collateral:borrower::string AS borrower, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -58,16 +58,17 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} LEFT OUTER JOIN prices l - ON date_trunc('hour', block_timestamp) = hour - AND liquidated_currency = currency + ON date_trunc('hour', block_timestamp) = l.hour + AND event_attributes:collateral_token::string = l.currency LEFT OUTER JOIN prices r - ON date_trunc('hour', block_timestamp) = hour - AND repay_currency = currency + ON date_trunc('hour', block_timestamp) = r.hour + AND event_attributes:stable_denom::string = r.currency WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' + AND event_attributes:"0_action"::string = 'liquidate_collateral' ) diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql index d328efe1..6bfb0138 100644 --- a/models/terra/anchor__redeem.sql +++ b/models/terra/anchor__redeem.sql @@ -22,7 +22,7 @@ WITH prices AS ( ) SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -40,7 +40,7 @@ ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour - AND m.currency = r.currency + AND msg_value:contract::string = r.currency WHERE msg_value:execute_msg:send:msg:redeem_stable IS NOT NULL AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql index 50d2c33d..1165bf08 100644 --- a/models/terra/anchor__repay.sql +++ b/models/terra/anchor__repay.sql @@ -22,7 +22,7 @@ WITH prices AS ( ) SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -40,7 +40,7 @@ ON msg_value:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour - AND m.currency = r.currency + AND msg_value:coins[0]:denom::string = r.currency WHERE msg_value:execute_msg:repay_stable IS NOT NULL AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.sql b/models/terra/anchor__reward_claims.sql index 180159bb..31fd08f6 100644 --- a/models/terra/anchor__reward_claims.sql +++ b/models/terra/anchor__reward_claims.sql @@ -5,7 +5,7 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'anchor', 'reward'] + tags=['snowflake', 'terra', 'anchor', 'reward_claims'] ) }} @@ -56,7 +56,6 @@ SELECT m.tx_id, claim_0_contract, event_attributes:"0_amount" / POW(10,6) as claim_0_amount, - claim_0_amount * price AS claim_0_amount_usd, event_attributes:"1_contract_address"::string as claim_0_currency FROM {{source('silver_terra', 'msg_events')}} e @@ -64,12 +63,9 @@ JOIN withdraw_msgs m ON m.tx_id = e.tx_id AND m.msg_index = e.msg_index -LEFT OUTER JOIN prices o - ON date_trunc('hour', block_timestamp) = o.hour - AND claim_0_currency = o.currency - WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' + AND event_attributes:"0_action"::string = 'withdraw' ), @@ -84,37 +80,33 @@ SELECT sender, claim_1_contract, event_attributes:claim_amount / POW(10,6) as claim_1_amount, - claim_1_amount * price AS claim_1_amount_usd, event_attributes:"2_contract_address"::string as claim_1_currency FROM {{source('silver_terra', 'msg_events')}} e JOIN claim_msgs m ON m.tx_id = e.tx_id AND m.msg_index = e.msg_index - -LEFT OUTER JOIN prices o - ON date_trunc('hour', block_timestamp) = o.hour - AND claim_1_currency = o.currency WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' + AND event_attributes:"0_action"::string = 'claim_rewards' ) SELECT - blockchain, + c.blockchain, chain_id, block_id, block_timestamp, c.tx_id, sender, claim_0_amount, - claim_0_amount_usd, + claim_0_amount * p0.price AS claim_0_amount_usd, claim_0_currency, claim_0_contract, l0.address_name AS claim_0_contract_label, claim_1_amount, - claim_1_amount_usd, + claim_1_amount * p1.price AS claim_1_amount_usd, claim_1_currency, claim_1_contract, l1.address_name AS claim_1_contract_label @@ -127,4 +119,12 @@ LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l0 ON claim_0_contract = l0.address LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l1 -ON claim_1_contract = l1.address \ No newline at end of file +ON claim_1_contract = l1.address + +LEFT OUTER JOIN prices p0 + ON date_trunc('hour', block_timestamp) = p0.hour + AND claim_0_currency = p0.currency + + LEFT OUTER JOIN prices p1 + ON date_trunc('hour', block_timestamp) = p1.hour + AND claim_1_currency = p1.currency \ No newline at end of file diff --git a/models/terra/anchor__stake.sql b/models/terra/anchor__stake.sql index cb0a4536..fae92f0e 100644 --- a/models/terra/anchor__stake.sql +++ b/models/terra/anchor__stake.sql @@ -24,7 +24,7 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -34,7 +34,7 @@ SELECT msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -55,7 +55,7 @@ FROM {{source('silver_terra', 'msg_events')}} LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour - AND m.currency = r.currency + AND event_attributes:"0_contract_address"::string = r.currency WHERE event_type = 'execute_contract' AND tx_id IN(SELECT tx_id FROM msgs) @@ -85,7 +85,7 @@ JOIN events e UNION SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -97,14 +97,14 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour - AND m.currency = r.currency + AND msg_value:contract::string = r.currency WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 775374eb..72fa911c 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -56,11 +56,11 @@ FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.protocol_fee_currency = o.currency + AND t.event_attributes:protocol_fee[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.burn_currency = i.currency + AND t.event_attributes:burn_amount[0]:denom::string = i.currency WHERE event_attributes:burn_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id @@ -83,11 +83,11 @@ FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.tax_currency = o.currency + AND t.event_attributes:tax_amount[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.withdraw_currency = i.currency + AND t.event_attributes:withdraw_amount[0]:denom::string = i.currency WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id From 591961883d0ddc712e4e38374c5a2c6ef83ceb46 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sat, 18 Sep 2021 09:00:59 -0400 Subject: [PATCH 13/86] got terraswap + mirror prod ready --- models/terra/mirror__close_collateral.sql | 6 ++-- models/terra/mirror__close_short_farm.sql | 10 +++--- models/terra/mirror__gov_staking.sql | 19 +++++------ models/terra/mirror__gov_submit_proposal.sql | 4 +-- models/terra/mirror__gov_vote.sql | 8 ++--- models/terra/mirror__open_collateral.sql | 10 +++--- models/terra/mirror__open_short_farm.sql | 28 ++++++++++++----- models/terra/terraswap__lp_actions.sql | 22 ++++++------- models/terra/terraswap__lp_stake.sql | 5 ++- models/terra/terraswap__swaps.sql | 33 ++++++++++++++------ 10 files changed, 88 insertions(+), 57 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 72fa911c..ab8b7bc9 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -15,7 +15,7 @@ WITH prices AS ( date_trunc('hour', block_timestamp) as hour, currency, symbol, - avg(price_usd) as price_usd + avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} GROUP BY 1,2,3 @@ -23,7 +23,7 @@ WITH prices AS ( msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -32,7 +32,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index d76a6b05..c352fdc5 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -15,7 +15,7 @@ WITH prices AS ( date_trunc('hour', block_timestamp) as hour, currency, symbol, - avg(price_usd) as price_usd + avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} GROUP BY 1,2,3 @@ -33,7 +33,7 @@ SELECT FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' - AND tx_status = = 'SUCCEEDED' + AND tx_status = 'SUCCEEDED' ), @@ -52,7 +52,7 @@ WHERE tx_id IN(select tx_id from tx) msgs as ( SELECT - blockchain, + t.blockchain, chain_id, block_id, block_timestamp, @@ -61,7 +61,7 @@ SELECT msg_value:sender::string as sender, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM tx +FROM tx t LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -93,7 +93,7 @@ LEFT OUTER JOIN prices o LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.event_attributes:unlocked_amount[0]:amount / POW(10,6) = i.currency + AND t.event_attributes:unlocked_amount[0]:denom::string = i.currency LEFT OUTER JOIN prices a ON date_trunc('hour', t.block_timestamp) = i.hour diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index ec52f31e..a904ddb5 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -5,7 +5,7 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'mirror', 'gov'] + tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] ) }} @@ -15,7 +15,7 @@ WITH prices AS ( date_trunc('hour', block_timestamp) as hour, currency, symbol, - avg(price_usd) as price_usd + avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} GROUP BY 1,2,3 @@ -24,7 +24,7 @@ WITH prices AS ( stake_msgs AS ( SELECT - blockchain, + t.blockchain, chain_id, block_id, block_timestamp, @@ -39,14 +39,14 @@ FROM {{source('silver_terra', 'msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.event_currency = o.currency + AND msg_value:contract::string = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' - AND tx_status = = 'SUCCEEDED' + AND tx_status = 'SUCCEEDED' ), @@ -84,7 +84,7 @@ UNION -- Unstaking SELECT - blockchain, + t.blockchain, chain_id, block_id, block_timestamp, @@ -94,17 +94,18 @@ SELECT msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, event_amount * o.price AS event_amount_usd, 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' as event_currency, + NULL as shares, msg_value:contract::string as contract_address, l.address_name as contract_label FROM {{source('silver_terra', 'msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.event_currency = o.currency + AND 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' = o.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' - AND tx_status = = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 8e620b9b..9a5c2473 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -5,7 +5,7 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'mirror', 'gov'] + tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] ) }} @@ -40,7 +40,7 @@ WHERE tx_id IN(select tx_id from msgs) ) SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 300b8346..b2c0f0fd 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -5,12 +5,12 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'mirror', 'gov'] + tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] ) }} SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -20,8 +20,8 @@ SELECT msg_value:execute_msg:cast_vote:vote::string as vote, msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, - l.addres_name as contract_label -FROM {{source('silver_terra', 'msgs')}} + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index d13e796d..43e8ac24 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -16,7 +16,7 @@ WITH prices AS ( date_trunc('hour', block_timestamp) as hour, currency, symbol, - avg(price_usd) as price_usd + avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} GROUP BY 1,2,3 @@ -25,7 +25,7 @@ WITH prices AS ( msgs AS( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -34,10 +34,10 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON contract_address = l.address +ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' -- Mirror Mint Contract AND msg_value:execute_msg:open_position IS NOT NULL @@ -56,7 +56,7 @@ SELECT event_attributes:mint_amount[0]:amount/ POW(10,6) as mint_amount, mint_amount * i.price AS mint_amount_usd, event_attributes:mint_amount[0]:denom::string as mint_currency -FROM t{{source('silver_terra', 'msg_events')}} t +FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 43ebae5c..eb1e4084 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -9,10 +9,22 @@ ) }} -WITH msgs as( +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs as( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -21,7 +33,7 @@ SELECT msg_value:execute_msg:open_position:collateral_ratio AS collateral_ratio, msg_value:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -58,7 +70,7 @@ SELECT event_attributes:commission_amount / POW(10,6) AS commission, event_attributes:spread_amount / POW(10,6) AS spread, - to_timestamp(event_attributes:unlock_time) AS unlock_time + to_timestamp(event_attributes:unlock_time::numeric) AS unlock_time FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o @@ -70,12 +82,12 @@ LEFT OUTER JOIN prices i AND t.event_attributes:mint_amount[0]:denom::string = i.currency LEFT OUTER JOIN prices r - ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.return_amount = o.currency + ON date_trunc('hour', t.block_timestamp) = r.hour + AND 'uusd' = r.currency LEFT OUTER JOIN prices l - ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.event_attributes:locked_amount[0]:denom::string = i.currency + ON date_trunc('hour', t.block_timestamp) = l.hour + AND t.event_attributes:locked_amount[0]:denom::string = l.currency WHERE event_type = 'from_contract' AND event_attributes:is_short::string = 'true' diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 46823e5d..35fefb21 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -15,7 +15,7 @@ WITH prices as ( date_trunc('hour', block_timestamp) as hour, currency, symbol, - avg(price_usd) as price_usd + avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} GROUP BY 1,2,3 @@ -24,7 +24,7 @@ WITH prices as ( provide_msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -33,7 +33,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as pool_address, l.address_name AS pool_name -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -68,11 +68,11 @@ ON lp_pool_address = l.address LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.token_0_currency = o.currency + AND t.event_attributes:assets[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.token_1_currency = i.currency + AND t.event_attributes:assets[1]:denom::string = i.currency WHERE msg_index = 1 AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) @@ -83,7 +83,7 @@ WHERE msg_index = 1 withdraw_msgs AS ( SELECT - blockchain, + m.blockchain, chain_id, block_id, block_timestamp, @@ -94,13 +94,13 @@ SELECT l.address_name AS lp_pool_name, msg_value:execute_msg:send:contract::string as pool_address, p.address_name AS pool_name -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as p -ON pool_address = p.address +ON msg_value:contract::string = p.address LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON lp_pool_address = l.address +ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:send:msg:withdraw_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' @@ -125,11 +125,11 @@ FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.token_0_currency = o.currency + AND t.event_attributes:refund_assets[0]:denom::string = o.currency LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.token_1_currency = i.currency + AND t.event_attributes:refund_assets[1]:denom::string = i.currency WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql index 253902e0..279f6f45 100644 --- a/models/terra/terraswap__lp_stake.sql +++ b/models/terra/terraswap__lp_stake.sql @@ -13,6 +13,7 @@ WITH msgs AS ( SELECT + blockchain, chain_id, block_id, block_timestamp, @@ -40,6 +41,7 @@ where tx_id IN(SELECT distinct tx_id from msgs) -- unstake SELECT + m.blockchain, chain_id, block_id, block_timestamp, @@ -61,6 +63,7 @@ UNION -- stake SELECT + m.blockchain, chain_id, block_id, block_timestamp, @@ -70,7 +73,7 @@ SELECT msg_value:execute_msg:send:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} ON msg_value:contract::string = address diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index 849cc5ab..b2a9a5bb 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -10,9 +10,22 @@ }} -WITH msgs as ( +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs as ( -- native to non-native/native SELECT + blockchain, chain_id, block_id, block_timestamp, @@ -28,6 +41,7 @@ WHERE msg_value:execute_msg:swap IS NOT NULL -- non-native to native SELECT + blockchain, chain_id, block_id, block_timestamp, @@ -43,11 +57,11 @@ WHERE msg_value:execute_msg:send:msg:swap IS NOT NULL events as ( SELECT tx_id, - as_number(event_attributes:tax_amount)/POW(10,6) as tax_amount, - event_attributes:commission_amount::numeric/POW(10,6) as commission_amount, - event_attributes:offer_amount::numeric/POW(10,6) as offer_amount, + as_number(event_attributes:tax_amount) / POW(10,6) as tax_amount, + event_attributes:commission_amount::numeric / POW(10,6) as commission_amount, + event_attributes:offer_amount::numeric / POW(10,6) as offer_amount, event_attributes:offer_asset::string as offer_currency, - event_attributes:return_amount::numeric/POW(10,6) as return_amount, + event_attributes:return_amount::numeric / POW(10,6) as return_amount, event_attributes:ask_asset::string as return_currency FROM {{source('silver_terra', 'msg_events')}} @@ -58,6 +72,7 @@ WHERE event_type = 'from_contract' SELECT + m.blockchain, chain_id, block_id, block_timestamp, @@ -79,12 +94,12 @@ JOIN events e ON m.tx_id = e.tx_id LEFT OUTER JOIN prices o - ON date_trunc('hour', t.block_timestamp) = o.hour - AND m.offer_currency = o.currency + ON date_trunc('hour', m.block_timestamp) = o.hour + AND e.offer_currency = o.currency LEFT OUTER JOIN prices r - ON date_trunc('hour', t.block_timestamp) = r.hour - AND m.return_currency = r.currency + ON date_trunc('hour', m.block_timestamp) = r.hour + AND e.return_currency = r.currency LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} l ON pool_address = address \ No newline at end of file From 809ca3bedb8baac43d418f2db60382b182cd3b42 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sat, 18 Sep 2021 09:06:38 -0400 Subject: [PATCH 14/86] anchor governance --- models/terra/anchor__gov_staking.sql | 111 +++++++++++++++++++ models/terra/anchor__gov_submit_proposal.sql | 64 +++++++++++ models/terra/anchor__gov_vote.sql | 31 ++++++ 3 files changed, 206 insertions(+) create mode 100644 models/terra/anchor__gov_staking.sql create mode 100644 models/terra/anchor__gov_submit_proposal.sql create mode 100644 models/terra/anchor__gov_vote.sql diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql new file mode 100644 index 00000000..00274bc9 --- /dev/null +++ b/models/terra/anchor__gov_staking.sql @@ -0,0 +1,111 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +stake_msgs AS ( + +SELECT + t.blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:amount / POW(10,6) as event_amount, + event_amount * o.price AS event_amount_usd, + msg_value:contract::string as event_currency, + msg_value:execute_msg:send:contract::string as contract_address, + l.address_name AS contract_label +FROM {{source('silver_terra', 'msgs')}} t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND msg_value:contract::string = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON msg_value:execute_msg:send:contract::string = l.address + +WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' + AND tx_status = 'SUCCEEDED' + +), + +stake_events AS ( +SELECT + tx_id, + event_attributes:share as shares +FROM {{source('silver_terra', 'msg_events')}} +WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) + AND event_type = 'from_contract' +) + +-- Staking +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + 'stake' as event_type, + sender, + event_amount, + event_amount_usd, + event_currency, + shares, + contract_address, + contract_label +FROM stake_msgs m + +JOIN stake_events e + ON m.tx_id = e.tx_id + +UNION + +-- Unstaking + +SELECT + t.blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + 'unstake' as event_type, + msg_value:sender::string as sender, + msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, + event_amount * o.price AS event_amount_usd, + 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as event_currency, + NULL as shares, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} t + +LEFT OUTER JOIN prices o + ON date_trunc('hour', t.block_timestamp) = o.hour + AND 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' = o.currency + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON msg_value:contract::string = l.address + +WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL + AND msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' + AND tx_status = 'SUCCEEDED' \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.sql b/models/terra/anchor__gov_submit_proposal.sql new file mode 100644 index 00000000..a221b9e6 --- /dev/null +++ b/models/terra/anchor__gov_submit_proposal.sql @@ -0,0 +1,64 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] + ) +}} + +WITH msgs AS ( +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as creator, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + msg_value:execute_msg:send:msg:create_poll:title::string as title, + msg_value:execute_msg:send:msg:create_poll:link::string as link, + msg_value:execute_msg:send:msg:create_poll:description::string as description, + msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, + msg_value:execute_msg:send:contract::string as contract_address +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL + AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance + AND tx_status = 'SUCCEEDED' +), + +events AS ( +SELECT + tx_id, + to_timestamp(event_attributes:end_time) as end_time, + event_attributes:poll_id as poll_id +FROM {{source('silver_terra', 'msg_events')}} +WHERE tx_id IN(select tx_id from msgs) + AND event_type = 'from_contract' +) + +SELECT + m.blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + poll_id, + end_time, + creator, + amount, + title, + link, + description, + msg, + contract_address, + l.address_name AS contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address diff --git a/models/terra/anchor__gov_vote.sql b/models/terra/anchor__gov_vote.sql new file mode 100644 index 00000000..8342209e --- /dev/null +++ b/models/terra/anchor__gov_vote.sql @@ -0,0 +1,31 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] + ) +}} + +SELECT + m.blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as voter, + msg_value:execute_msg:cast_vote:poll_id as poll_id, + msg_value:execute_msg:cast_vote:vote::string as vote, + msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} m + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON msg_value:contract::string = l.address + +WHERE msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance + AND msg_value:execute_msg:cast_vote IS NOT NULL + AND tx_status = 'SUCCEEDED' From 4b4f0762089ce7cf124ff747ff7a878e2a7c2821 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 08:44:17 -0400 Subject: [PATCH 15/86] Added Mirror Liquidations --- models/terra/mirror__liquidations.sql | 120 ++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 models/terra/mirror__liquidations.sql diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql new file mode 100644 index 00000000..e5f63813 --- /dev/null +++ b/models/terra/mirror__liquidations.sql @@ -0,0 +1,120 @@ +{{ + config( + materialized='incremental', + sort='block_timestamp', + unique_key='block_id', + incremental_strategy='delete+insert', + cluster_by=['block_timestamp'], + tags=['snowflake', 'terra', 'mirror', 'liquidations'] + ) +}} + +WITH prices AS ( + + SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:execute_msg:send:msg:auction:position_idx as collateral_id, + msg_value:execute_msg:send:contract::string as contract_address +FROM terra.msgs +WHERE msg_value:execute_msg:send:msg:auction IS NOT NULL + AND tx_status = 'SUCCEEDED' +), + +events AS ( + +SELECT + tx_id, + COALESCE((event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount), event_attributes:tax_amount[0]:amount) / POW(10,6) AS tax, + COALESCE(event_attributes:"1_tax_amount"[0]:denom::string,event_attributes:tax_amount[0]:denom::string) AS tax_currency, + + event_attributes:protocol_fee[0]:amount / POW(10,6) as protocol_fee, + event_attributes:protocol_fee[0]:denom::string as protocol_fee_currency, + + event_attributes:liquidated_amount[0]:amount / POW(10,6) as liquidated_amount, + event_attributes:liquidated_amount[0]:denom::string as liquidated_currency, + + event_attributes:return_collateral_amount[0]:amount / POW(10,6) as return_collateral_amount, + event_attributes:return_collateral_amount[0]:denom::string as return_collateral_currency, + + event_attributes:unlocked_amount[0]:amount / POW(10,6) as unlocked_amount, + event_attributes:unlocked_amount[0]:denom::string as unlocked_curency, + + event_attributes:owner::string as owner +FROM terra.msg_events +WHERE event_type = 'from_contract' + AND tx_id IN(SELECT tx_id FROM msgs) + AND event_attributes:return_collateral_amount IS NOT NULL + AND tx_status = 'SUCCEEDED' + +) + +SELECT + m.blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + owner, + tax, + tax * t.price as tax_usd, + tax_currency, + protocol_fee, + protocol_fee * p.price as protocol_fee_usd + protocol_fee_currency, + liquidated_amount, + liquidated_amount * l.price as liquidated_amount_usd, + liquidated_currency, + return_collateral_amount, + return_collateral_amount * r.price as return_collateral_amount_usd, + return_collateral_currency, + unlocked_amount, + unlocked_amount * u.price as unlocked_amount_usd + unlocked_curency, + collateral_id, + contract_address, + l.address_name AS contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON m.contract_address = l.address + +LEFT OUTER JOIN prices t + ON date_trunc('hour', m.block_timestamp) = t.hour + AND tax = t.currency + +LEFT OUTER JOIN prices p + ON date_trunc('hour', m.block_timestamp) = p.hour + AND protocool_fee = p.currency + +LEFT OUTER JOIN prices l + ON date_trunc('hour', m.block_timestamp) = l.hour + AND liquidated_amount = l.currency + +LEFT OUTER JOIN prices r + ON date_trunc('hour', m.block_timestamp) = r.hour + AND return_collateral_amount = r.currency + +LEFT OUTER JOIN prices u + ON date_trunc('hour', m.block_timestamp) = u.hour + AND unlocked_amount = u.currency \ No newline at end of file From 7b2e37de05fdc9f98f08c6b2a73c2cf5c0b5be1f Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 12:13:37 -0400 Subject: [PATCH 16/86] prod ready - mirror liquidations --- models/terra/mirror__liquidations.sql | 22 +++++++++++----------- models/terra/terraswap__lp_actions.sql | 9 ++++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index e5f63813..bb29e3ba 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -71,13 +71,13 @@ SELECT block_id, block_timestamp, m.tx_id, - sender, + sender as buyer, owner, tax, tax * t.price as tax_usd, tax_currency, protocol_fee, - protocol_fee * p.price as protocol_fee_usd + protocol_fee * p.price as protocol_fee_usd, protocol_fee_currency, liquidated_amount, liquidated_amount * l.price as liquidated_amount_usd, @@ -86,35 +86,35 @@ SELECT return_collateral_amount * r.price as return_collateral_amount_usd, return_collateral_currency, unlocked_amount, - unlocked_amount * u.price as unlocked_amount_usd + unlocked_amount * u.price as unlocked_amount_usd, unlocked_curency, collateral_id, contract_address, - l.address_name AS contract_label + g.address_name AS contract_label FROM msgs m JOIN events e ON m.tx_id = e.tx_id -LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON m.contract_address = l.address +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as g +ON m.contract_address = g.address LEFT OUTER JOIN prices t ON date_trunc('hour', m.block_timestamp) = t.hour - AND tax = t.currency + AND tax_currency = t.currency LEFT OUTER JOIN prices p ON date_trunc('hour', m.block_timestamp) = p.hour - AND protocool_fee = p.currency + AND protocol_fee_currency = p.currency LEFT OUTER JOIN prices l ON date_trunc('hour', m.block_timestamp) = l.hour - AND liquidated_amount = l.currency + AND liquidated_currency = l.currency LEFT OUTER JOIN prices r ON date_trunc('hour', m.block_timestamp) = r.hour - AND return_collateral_amount = r.currency + AND return_collateral_currency = r.currency LEFT OUTER JOIN prices u ON date_trunc('hour', m.block_timestamp) = u.hour - AND unlocked_amount = u.currency \ No newline at end of file + AND unlocked_curency = u.currency \ No newline at end of file diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 35fefb21..5d7e9777 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -64,7 +64,10 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l -ON lp_pool_address = l.address +ON event_attributes:"2_contract_address"::string = l.address + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as r +ON event_attributes:"4_contract_address"::string = r.address LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -75,7 +78,7 @@ LEFT OUTER JOIN prices i AND t.event_attributes:assets[1]:denom::string = i.currency WHERE msg_index = 1 - AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) + AND tx_id IN(SELECT DISTINCT tx_id FROM provide_msgs) AND event_type = 'from_contract' ), @@ -131,7 +134,7 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:refund_assets[1]:denom::string = i.currency -WHERE tx_id IN(SELECT tx_id FROM msgs) +WHERE tx_id IN(SELECT tx_id FROM provide_msgs) AND event_type = 'from_contract' AND event_attributes:refund_assets IS NOT NULL From b4c46ca46525203ab44340a44cf3fb4cb08070da Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 13:38:49 -0400 Subject: [PATCH 17/86] standardizing naming & column order --- models/terra/anchor__collateral.sql | 4 ++-- models/terra/anchor__gov_staking.sql | 12 ++++++------ ...anchor__stake.sql => anchor_dbt__stake.sql} | 0 models/terra/mirror__close_collateral.sql | 6 +++--- models/terra/mirror__close_short_farm.sql | 18 +++++++++--------- models/terra/mirror__open_short_farm.sql | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) rename models/terra/{anchor__stake.sql => anchor_dbt__stake.sql} (100%) diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index e9d8193e..7af936e7 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -69,7 +69,7 @@ SELECT block_id, block_timestamp, m.tx_id, - action, + action as event_type, sender, amount, amount_usd, @@ -90,7 +90,7 @@ SELECT block_id, block_timestamp, tx_id, - 'provide' as action, + 'provide' as event_type, msg_value:sender::string AS sender, msg_value:execute_msg:send:amount / POW(10,6) as amount, amount * price AS amount_usd, diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index 00274bc9..62d83b42 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -68,9 +68,9 @@ SELECT m.tx_id, 'stake' as event_type, sender, - event_amount, - event_amount_usd, - event_currency, + amount, + amount_usd, + currency, shares, contract_address, contract_label @@ -91,9 +91,9 @@ SELECT tx_id, 'unstake' as event_type, msg_value:sender::string as sender, - msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, - event_amount * o.price AS event_amount_usd, - 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as event_currency, + msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as amount, + event_amount * o.price AS amount_usd, + 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as currency, NULL as shares, msg_value:contract::string as contract_address, l.address_name as contract_label diff --git a/models/terra/anchor__stake.sql b/models/terra/anchor_dbt__stake.sql similarity index 100% rename from models/terra/anchor__stake.sql rename to models/terra/anchor_dbt__stake.sql diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index ab8b7bc9..fb3a9459 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -103,12 +103,12 @@ SELECT m.tx_id, collateral_id, sender, - protocol_fee_amount, - procotol_fee_amount_usd, - protocol_fee_currency, tax_amount, tax_amount_usd, tax_currency, + protocol_fee_amount, + procotol_fee_amount_usd, + protocol_fee_currency, burn_amount, burn_amount_usd, burn_currency, diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index c352fdc5..96767c97 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -137,21 +137,21 @@ SELECT m.tx_id, collateral_id, sender, - withdraw_amount, - withdraw_amount_usd, - withdraw_currency, - burn_amount, - burn_amount_usd, - burn_currency, - unlocked_amount, - unlocked_amount_usd, - unlocked_currency, tax, tax_usd, tax_currency, protocol_fee, protocol_fee_usd, protocol_fee_currency, + burn_amount, + burn_amount_usd, + burn_currency, + withdraw_amount, + withdraw_amount_usd, + withdraw_currency, + unlocked_amount, + unlocked_amount_usd, + unlocked_currency, contract_address, contract_label FROM msgs m diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index eb1e4084..ae4193db 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -102,9 +102,12 @@ SELECT block_id, block_timestamp, m.tx_id, - collateral_ratio, collateral_id, + collateral_ratio, sender, + tax, + commission, + spread, collateral_amount, collateral_amount_usd, collateral_currency, @@ -117,9 +120,6 @@ SELECT locked_amount, locked_amount_usd, locked_currency, - tax, - commission, - spread, unlock_time, contract_address, contract_label From 74fc107ef4164bc1d479b93be782f8cdca38872a Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 13:44:24 -0400 Subject: [PATCH 18/86] minor --- models/terra/mirror__liquidations.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index bb29e3ba..ec161347 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -71,6 +71,7 @@ SELECT block_id, block_timestamp, m.tx_id, + collateral_id, sender as buyer, owner, tax, @@ -88,7 +89,6 @@ SELECT unlocked_amount, unlocked_amount * u.price as unlocked_amount_usd, unlocked_curency, - collateral_id, contract_address, g.address_name AS contract_label FROM msgs m From b1f29af5997966c49453678bd21b6a855cbe7d87 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:07:18 -0400 Subject: [PATCH 19/86] added incremental blob --- models/terra/anchor__bonds.sql | 30 ++++++++++----- models/terra/anchor__borrows.sql | 28 +++++++++----- models/terra/anchor__burns.sql | 28 +++++++++----- models/terra/anchor__collateral.sql | 36 +++++++++++++----- models/terra/anchor__deposits.sql | 30 ++++++++++----- models/terra/anchor__gov_staking.sql | 36 +++++++++++++----- models/terra/anchor__gov_submit_proposal.sql | 23 +++++++----- models/terra/anchor__gov_vote.sql | 19 +++++----- models/terra/anchor__liquidations.sql | 30 ++++++++++----- models/terra/anchor__redeem.sql | 28 +++++++++----- models/terra/anchor__repay.sql | 28 +++++++++----- models/terra/anchor__reward_claims.sql | 39 +++++++++++++++----- models/terra/anchor_dbt__stake.sql | 23 +++++++++++- models/terra/mirror__close_collateral.sql | 34 ++++++++++++----- models/terra/mirror__close_short_farm.sql | 30 ++++++++++----- models/terra/mirror__gov_staking.sql | 36 +++++++++++++----- models/terra/mirror__gov_submit_proposal.sql | 23 +++++++----- models/terra/mirror__gov_vote.sql | 19 +++++----- models/terra/mirror__liquidations.sql | 34 +++++++++++------ models/terra/mirror__open_collateral.sql | 30 ++++++++++----- models/terra/mirror__open_short_farm.sql | 30 ++++++++++----- models/terra/terraswap__lp_actions.sql | 38 ++++++++++++++----- models/terra/terraswap__lp_stake.sql | 29 ++++++++++----- models/terra/terraswap__swaps.sql | 34 ++++++++++++----- 24 files changed, 495 insertions(+), 220 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index 3e9ecc79..7c8a6996 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'bonds'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -48,6 +52,10 @@ LEFT OUTER JOIN prices o WHERE msg_value:execute_msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS ( @@ -67,6 +75,10 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql index 1f176d7e..79cb65e9 100644 --- a/models/terra/anchor__borrows.sql +++ b/models/terra/anchor__borrows.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'borrows'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ) @@ -44,4 +48,8 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:borrow_stable IS NOT NULL -- Anchor Borrow AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' -- Anchor Market Contract - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql index 6ddc948a..10bd595b 100644 --- a/models/terra/anchor__burns.sql +++ b/models/terra/anchor__burns.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'burns'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ) @@ -43,4 +47,8 @@ LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:send:msg:unbond IS NOT NULL - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index 7af936e7..b0f7ec51 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'collateral'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -41,6 +45,10 @@ ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:withdraw_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS ( @@ -60,6 +68,10 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' AND msg_index = 0 AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) @@ -107,4 +119,8 @@ LEFT OUTER JOIN prices o AND msg_value:contract::string = o.currency WHERE msg_value:execute_msg:send:msg:deposit_collateral IS NOT NULL - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql index 369e99ce..6331d5e3 100644 --- a/models/terra/anchor__deposits.sql +++ b/models/terra/anchor__deposits.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'deposits'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -49,6 +53,10 @@ WHERE msg_value:execute_msg:deposit_stable IS NOT NULL AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS ( @@ -70,6 +78,10 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'deposit_stable' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index 62d83b42..1340ea7d 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -48,6 +52,10 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), stake_events AS ( @@ -57,6 +65,10 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) -- Staking @@ -108,4 +120,8 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.sql b/models/terra/anchor__gov_submit_proposal.sql index a221b9e6..a034a347 100644 --- a/models/terra/anchor__gov_submit_proposal.sql +++ b/models/terra/anchor__gov_submit_proposal.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] - ) -}} +) }} WITH msgs AS ( SELECT @@ -27,6 +24,10 @@ FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), events AS ( @@ -37,6 +38,10 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) SELECT diff --git a/models/terra/anchor__gov_vote.sql b/models/terra/anchor__gov_vote.sql index 8342209e..bcff3a63 100644 --- a/models/terra/anchor__gov_vote.sql +++ b/models/terra/anchor__gov_vote.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'anchor_gov'] - ) -}} +) }} SELECT m.blockchain, @@ -29,3 +26,7 @@ ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance AND msg_value:execute_msg:cast_vote IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index cff4995c..b2daea3e 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'liquidations'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -41,6 +45,10 @@ WHERE msg_value:contract::string = 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8 AND msg_value:execute_msg:liquidate_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS ( @@ -70,6 +78,10 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' AND event_attributes:"0_action"::string = 'liquidate_collateral' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql index 6bfb0138..df0993de 100644 --- a/models/terra/anchor__redeem.sql +++ b/models/terra/anchor__redeem.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'redeem'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ) @@ -43,4 +47,8 @@ LEFT OUTER JOIN prices r AND msg_value:contract::string = r.currency WHERE msg_value:execute_msg:send:msg:redeem_stable IS NOT NULL - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql index 1165bf08..f8a53de2 100644 --- a/models/terra/anchor__repay.sql +++ b/models/terra/anchor__repay.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'repay'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ) @@ -43,4 +47,8 @@ LEFT OUTER JOIN prices r AND msg_value:coins[0]:denom::string = r.currency WHERE msg_value:execute_msg:repay_stable IS NOT NULL - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.sql b/models/terra/anchor__reward_claims.sql index 31fd08f6..6b7a9b62 100644 --- a/models/terra/anchor__reward_claims.sql +++ b/models/terra/anchor__reward_claims.sql @@ -1,14 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'anchor', 'reward_claims'] - ) -}} - +) }} WITH prices AS ( SELECT @@ -17,6 +13,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -33,6 +36,10 @@ WHERE msg_value:execute_msg:withdraw IS NOT NULL AND msg_value:contract::string = 'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), claim_msgs AS ( @@ -47,6 +54,10 @@ WHERE msg_value:execute_msg:claim_rewards IS NOT NULL AND msg_index = 1 AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), @@ -66,6 +77,10 @@ JOIN withdraw_msgs m WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' AND event_attributes:"0_action"::string = 'withdraw' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), @@ -90,6 +105,10 @@ JOIN claim_msgs m WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' AND event_attributes:"0_action"::string = 'claim_rewards' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) diff --git a/models/terra/anchor_dbt__stake.sql b/models/terra/anchor_dbt__stake.sql index fae92f0e..4f2118e8 100644 --- a/models/terra/anchor_dbt__stake.sql +++ b/models/terra/anchor_dbt__stake.sql @@ -5,7 +5,7 @@ unique_key='block_id', incremental_strategy='delete+insert', cluster_by=['block_timestamp'], - tags=['snowflake', 'terra', 'anchor', 'stake'] + tags=['snowflake', 'terra', 'anchor_dbt', 'stake'] ) }} @@ -17,6 +17,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -42,6 +49,10 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), @@ -62,6 +73,10 @@ WHERE event_type = 'execute_contract' AND msg_index = 0 AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT @@ -108,4 +123,8 @@ LEFT OUTER JOIN prices r WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index fb3a9459..48a3276f 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'collateral'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -39,6 +43,10 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), burns AS ( @@ -66,6 +74,10 @@ WHERE event_attributes:burn_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), withdraw as ( @@ -93,6 +105,10 @@ WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) SELECT diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 96767c97..194c6624 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'short_farm'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -35,6 +39,10 @@ WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), event_tx AS ( @@ -47,6 +55,10 @@ FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from tx) AND event_type = 'from_contract' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), msgs as ( diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index a904ddb5..1847effb 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -48,6 +52,10 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), stake_events AS ( @@ -57,6 +65,10 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) -- Staking @@ -108,4 +120,8 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 9a5c2473..b8663ca1 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] - ) -}} +) }} WITH msgs AS ( SELECT @@ -27,6 +24,10 @@ FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), events AS ( @@ -37,6 +38,10 @@ SELECT FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) SELECT diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index b2c0f0fd..23d00f72 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] - ) -}} +) }} SELECT m.blockchain, @@ -29,3 +26,7 @@ ON msg_value:contract::string = l.address WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND msg_value:execute_msg:cast_vote IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index ec161347..ece3cf9d 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'liquidations'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -32,9 +36,13 @@ SELECT msg_value:sender::string as sender, msg_value:execute_msg:send:msg:auction:position_idx as collateral_id, msg_value:execute_msg:send:contract::string as contract_address -FROM terra.msgs +FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:auction IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), events AS ( @@ -57,12 +65,16 @@ SELECT event_attributes:unlocked_amount[0]:denom::string as unlocked_curency, event_attributes:owner::string as owner -FROM terra.msg_events +FROM {{source('silver_terra', 'msg_events')}} WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id FROM msgs) AND event_attributes:return_collateral_amount IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index 43e8ac24..28d191fc 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'collateral'] - ) -}} +) }} WITH prices AS ( @@ -18,6 +15,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -43,6 +47,10 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND msg_value:execute_msg:open_position IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS( @@ -69,6 +77,10 @@ LEFT OUTER JOIN prices i WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND event_type = 'from_contract' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index ae4193db..9d6104ae 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'mirror', 'short_farm'] - ) -}} +) }} WITH prices AS ( @@ -17,6 +14,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -42,6 +46,10 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND msg_value:execute_msg:open_position IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events as ( @@ -94,6 +102,10 @@ WHERE event_type = 'from_contract' AND event_attributes:from::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' -- Mirror Mint AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) SELECT diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 5d7e9777..65ff23b6 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'terraswap', 'lp'] - ) -}} +) }} WITH prices as ( @@ -17,6 +14,13 @@ WITH prices as ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -41,6 +45,10 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), provide_events AS ( @@ -81,6 +89,10 @@ WHERE msg_index = 1 AND tx_id IN(SELECT DISTINCT tx_id FROM provide_msgs) AND event_type = 'from_contract' + {% if is_incremental() %} + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), withdraw_msgs AS ( @@ -107,6 +119,10 @@ ON msg_value:execute_msg:send:contract::string = l.address WHERE msg_value:execute_msg:send:msg:withdraw_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND m.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), @@ -138,6 +154,10 @@ WHERE tx_id IN(SELECT tx_id FROM provide_msgs) AND event_type = 'from_contract' AND event_attributes:refund_assets IS NOT NULL + {% if is_incremental() %} + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) -- Provide Liquidity diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql index 279f6f45..fd0a6635 100644 --- a/models/terra/terraswap__lp_stake.sql +++ b/models/terra/terraswap__lp_stake.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'terraswap', 'lp'] - ) -}} +) }} -- LP Un-staking WITH msgs AS ( @@ -25,6 +22,10 @@ FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ), events AS ( @@ -37,6 +38,10 @@ where tx_id IN(SELECT distinct tx_id from msgs) AND event_type = 'execute_contract' AND msg_index = 0 + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + ) -- unstake @@ -79,4 +84,8 @@ LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} ON msg_value:contract::string = address WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL - AND tx_status = 'SUCCEEDED' \ No newline at end of file + AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} \ No newline at end of file diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index b2a9a5bb..386207dc 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -1,13 +1,10 @@ -{{ - config( - materialized='incremental', - sort='block_timestamp', - unique_key='block_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp'], +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], tags=['snowflake', 'terra', 'terraswap', 'swap'] - ) -}} +) }} WITH prices AS ( @@ -18,6 +15,13 @@ WITH prices AS ( symbol, avg(price_usd) as price FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} + GROUP BY 1,2,3 ), @@ -35,6 +39,10 @@ SELECT FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} UNION @@ -52,6 +60,10 @@ FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:send:msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ), events as ( @@ -68,6 +80,10 @@ FROM {{source('silver_terra', 'msg_events')}} WHERE event_type = 'from_contract' AND tx_id IN(SELECT DISTINCT tx_id FROM msgs ) + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + {% endif %} ) From c541f60164d7fbb48f3c1fa0570bb2bfde6f66db Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:37:44 -0400 Subject: [PATCH 20/86] fixed incremental name --- models/terra/anchor__bonds.sql | 6 +++--- models/terra/anchor__borrows.sql | 4 ++-- models/terra/anchor__burns.sql | 4 ++-- models/terra/anchor__collateral.sql | 8 ++++---- models/terra/anchor__deposits.sql | 6 +++--- models/terra/anchor__gov_staking.sql | 8 ++++---- models/terra/anchor__gov_submit_proposal.sql | 4 ++-- models/terra/anchor__gov_vote.sql | 2 +- models/terra/anchor__liquidations.sql | 6 +++--- models/terra/anchor__redeem.sql | 4 ++-- models/terra/anchor__repay.sql | 4 ++-- models/terra/anchor__reward_claims.sql | 10 +++++----- models/terra/anchor_dbt__stake.sql | 8 ++++---- models/terra/mirror__close_collateral.sql | 8 ++++---- models/terra/mirror__close_short_farm.sql | 6 +++--- models/terra/mirror__gov_staking.sql | 8 ++++---- models/terra/mirror__gov_submit_proposal.sql | 4 ++-- models/terra/mirror__gov_vote.sql | 2 +- models/terra/mirror__liquidations.sql | 6 +++--- models/terra/mirror__open_collateral.sql | 6 +++--- models/terra/mirror__open_short_farm.sql | 6 +++--- models/terra/terraswap__lp_actions.sql | 10 +++++----- models/terra/terraswap__lp_stake.sql | 6 +++--- models/terra/terraswap__swaps.sql | 8 ++++---- 24 files changed, 72 insertions(+), 72 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index 7c8a6996..b9be0273 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -76,7 +76,7 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql index 79cb65e9..4fa0e5f2 100644 --- a/models/terra/anchor__borrows.sql +++ b/models/terra/anchor__borrows.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -51,5 +51,5 @@ WHERE msg_value:execute_msg:borrow_stable IS NOT NULL -- Anchor Borrow AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql index 10bd595b..0408edc5 100644 --- a/models/terra/anchor__burns.sql +++ b/models/terra/anchor__burns.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:send:msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index b0f7ec51..28d4f390 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -46,7 +46,7 @@ WHERE msg_value:execute_msg:withdraw_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -70,7 +70,7 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) @@ -122,5 +122,5 @@ WHERE msg_value:execute_msg:send:msg:deposit_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql index 6331d5e3..6c3f281d 100644 --- a/models/terra/anchor__deposits.sql +++ b/models/terra/anchor__deposits.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -54,7 +54,7 @@ WHERE msg_value:execute_msg:deposit_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index 1340ea7d..4ef5b4cb 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -67,7 +67,7 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) @@ -123,5 +123,5 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.sql b/models/terra/anchor__gov_submit_proposal.sql index a034a347..8db84ed5 100644 --- a/models/terra/anchor__gov_submit_proposal.sql +++ b/models/terra/anchor__gov_submit_proposal.sql @@ -26,7 +26,7 @@ WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -40,7 +40,7 @@ WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__gov_vote.sql b/models/terra/anchor__gov_vote.sql index bcff3a63..ed8fcda0 100644 --- a/models/terra/anchor__gov_vote.sql +++ b/models/terra/anchor__gov_vote.sql @@ -28,5 +28,5 @@ WHERE msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5 AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index b2daea3e..44e3e98c 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -46,7 +46,7 @@ WHERE msg_value:contract::string = 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8 AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'liquidate_collateral' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql index df0993de..cfc71977 100644 --- a/models/terra/anchor__redeem.sql +++ b/models/terra/anchor__redeem.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:send:msg:redeem_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql index f8a53de2..66bc10f9 100644 --- a/models/terra/anchor__repay.sql +++ b/models/terra/anchor__repay.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:repay_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.sql b/models/terra/anchor__reward_claims.sql index 6b7a9b62..38cbf2c7 100644 --- a/models/terra/anchor__reward_claims.sql +++ b/models/terra/anchor__reward_claims.sql @@ -17,7 +17,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ WHERE msg_value:execute_msg:withdraw IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -56,7 +56,7 @@ WHERE msg_value:execute_msg:claim_rewards IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'withdraw' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -107,7 +107,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'claim_rewards' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/anchor_dbt__stake.sql b/models/terra/anchor_dbt__stake.sql index 4f2118e8..6c97bc46 100644 --- a/models/terra/anchor_dbt__stake.sql +++ b/models/terra/anchor_dbt__stake.sql @@ -21,7 +21,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -51,7 +51,7 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -74,7 +74,7 @@ WHERE event_type = 'execute_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) @@ -126,5 +126,5 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 48a3276f..5cb55aa0 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -45,7 +45,7 @@ WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -76,7 +76,7 @@ WHERE event_attributes:burn_amount IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -107,7 +107,7 @@ WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 194c6624..e89ef841 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -40,7 +40,7 @@ WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -56,7 +56,7 @@ WHERE tx_id IN(select tx_id from tx) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index 1847effb..fde8b9b1 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -67,7 +67,7 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) @@ -123,5 +123,5 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index b8663ca1..6349afc6 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -26,7 +26,7 @@ WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -40,7 +40,7 @@ WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 23d00f72..75402b26 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -28,5 +28,5 @@ WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index ece3cf9d..c10dfd71 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -41,7 +41,7 @@ WHERE msg_value:execute_msg:send:msg:auction IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -72,7 +72,7 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index 28d191fc..cfe616f4 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -19,7 +19,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -48,7 +48,7 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -78,7 +78,7 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 9d6104ae..86680983 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -47,7 +47,7 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -103,7 +103,7 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 65ff23b6..b4cf5967 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -18,7 +18,7 @@ WITH prices as ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -46,7 +46,7 @@ WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -90,7 +90,7 @@ WHERE msg_index = 1 AND event_type = 'from_contract' {% if is_incremental() %} - AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -121,7 +121,7 @@ WHERE msg_value:execute_msg:send:msg:withdraw_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND m.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND m.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -155,7 +155,7 @@ WHERE tx_id IN(SELECT tx_id FROM provide_msgs) AND event_attributes:refund_assets IS NOT NULL {% if is_incremental() %} - AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql index fd0a6635..45b5d1c3 100644 --- a/models/terra/terraswap__lp_stake.sql +++ b/models/terra/terraswap__lp_stake.sql @@ -23,7 +23,7 @@ WHERE msg_value:execute_msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -39,7 +39,7 @@ where tx_id IN(SELECT distinct tx_id from msgs) AND msg_index = 0 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) @@ -87,5 +87,5 @@ WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index 386207dc..cd3c9a59 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -19,7 +19,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -41,7 +41,7 @@ WHERE msg_value:execute_msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} @@ -62,7 +62,7 @@ WHERE msg_value:execute_msg:send:msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -82,7 +82,7 @@ WHERE event_type = 'from_contract' FROM msgs ) {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'terra_msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) From 39ca8dbb78304f665621ea3e3d257ea2ba93ac8c Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:42:14 -0400 Subject: [PATCH 21/86] naing convention --- models/terra/anchor__gov_staking.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index 4ef5b4cb..f056651e 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -34,9 +34,9 @@ SELECT block_timestamp, tx_id, msg_value:sender::string as sender, - msg_value:execute_msg:send:amount / POW(10,6) as event_amount, - event_amount * o.price AS event_amount_usd, - msg_value:contract::string as event_currency, + msg_value:execute_msg:send:amount / POW(10,6) as amount, + event_amount * o.price AS amount_usd, + msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label FROM {{source('silver_terra', 'msgs')}} t From 7147ff463a96d8402946468beda32988fffbdd73 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:43:35 -0400 Subject: [PATCH 22/86] minor --- models/terra/anchor__gov_staking.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index f056651e..d7914ec9 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -35,7 +35,7 @@ SELECT tx_id, msg_value:sender::string as sender, msg_value:execute_msg:send:amount / POW(10,6) as amount, - event_amount * o.price AS amount_usd, + amount * o.price AS amount_usd, msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label From e6fd252a004d997aeda54acb1fc60dc750b81670 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:45:36 -0400 Subject: [PATCH 23/86] minor v2 --- models/terra/anchor__gov_staking.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index d7914ec9..0ca6db62 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -104,7 +104,7 @@ SELECT 'unstake' as event_type, msg_value:sender::string as sender, msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as amount, - event_amount * o.price AS amount_usd, + amount * o.price AS amount_usd, 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as currency, NULL as shares, msg_value:contract::string as contract_address, From 21a28dca22892e4285f9d88c8547b5f5456a8de9 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:58:43 -0400 Subject: [PATCH 24/86] decimal adjustments --- models/terra/anchor__liquidations.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index 44e3e98c..cf47fc5c 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -59,7 +59,7 @@ SELECT event_attributes:collateral_amount / POW(10,6) AS liquidated_amount, liquidated_amount * l.price AS liquidated_amount_usd, event_attributes:collateral_token::string as liquidated_currency, - event_attributes:"1_repay_amount" as repay_amount, + event_attributes:"1_repay_amount" / POW(10,6) as repay_amount, repay_amount * r.price as repay_amount_usd, event_attributes:stable_denom::string as repay_currency, event_attributes:bid_fee / POW(10,6) AS bid_fee From 14725437d2fdd60cbae272ed2d6bc4fdb3cbdce0 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:10:51 -0400 Subject: [PATCH 25/86] close colalteral fix --- models/terra/mirror__close_collateral.sql | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 5cb55aa0..c2b03ed9 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -3,7 +3,7 @@ unique_key = 'block_id || tx_id', incremental_strategy = 'delete+insert', cluster_by = ['block_timestamp', 'block_id'], - tags=['snowflake', 'terra', 'mirror', 'collateral'] + tags=['snowflake', 'terra', 'mirror', 'mirror_close_collateral'] ) }} WITH prices AS ( @@ -52,20 +52,11 @@ WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL burns AS ( SELECT tx_id, - - event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, - protocol_fee_amount * o.price AS procotol_fee_amount_usd, - event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, burn_amount * i.price AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency FROM {{source('silver_terra', 'msg_events')}} t -LEFT OUTER JOIN prices o - ON date_trunc('hour', t.block_timestamp) = o.hour - AND t.event_attributes:protocol_fee[0]:denom::string = o.currency - LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:burn_amount[0]:denom::string = i.currency @@ -87,6 +78,10 @@ SELECT event_attributes:tax_amount[0]:amount /POW(10,6) AS tax_amount, tax_amount * o.price AS tax_amount_usd, event_attributes:tax_amount[0]:denom::string AS tax_currency, + + event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, + protocol_fee_amount * f.price AS procotol_fee_amount_usd, + event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, withdraw_amount * i.price AS withdraw_amount_usd, @@ -101,6 +96,10 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:withdraw_amount[0]:denom::string = i.currency +LEFT OUTER JOIN prices f + ON date_trunc('hour', t.block_timestamp) = f.hour + AND t.event_attributes:protocol_fee[0]:denom::string = f.currency + WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) From 29ffa2e4963afcc074ca8efefdc07521f3318d5e Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:16:05 -0400 Subject: [PATCH 26/86] fix --- models/terra/mirror__close_short_farm.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index e89ef841..9e588718 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -108,8 +108,8 @@ LEFT OUTER JOIN prices i AND t.event_attributes:unlocked_amount[0]:denom::string = i.currency LEFT OUTER JOIN prices a - ON date_trunc('hour', t.block_timestamp) = i.hour - AND t.event_attributes:"0_tax_amount"[0]:denom::string = i.currency + ON date_trunc('hour', t.block_timestamp) = a.hour + AND t.event_attributes:"0_tax_amount"[0]:denom::string = a.currency WHERE event_attributes:withdraw_amount IS NOT NULL From 4a733fdc6ba10a298cb1ad5bb7af75f27bb8a0ed Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:18:57 -0400 Subject: [PATCH 27/86] added end_height --- models/terra/mirror__gov_submit_proposal.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 6349afc6..b4653e06 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -33,7 +33,7 @@ WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL events AS ( SELECT tx_id, - to_timestamp(event_attributes:end_time) as end_time, + COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, event_attributes:poll_id as poll_id FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) From 0b93ed352e61763a2a9f587367dfe7959e4e7daf Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:20:00 -0400 Subject: [PATCH 28/86] added eng_height to anchor too --- models/terra/anchor__gov_submit_proposal.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor__gov_submit_proposal.sql b/models/terra/anchor__gov_submit_proposal.sql index 8db84ed5..db032ae9 100644 --- a/models/terra/anchor__gov_submit_proposal.sql +++ b/models/terra/anchor__gov_submit_proposal.sql @@ -33,7 +33,7 @@ WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL events AS ( SELECT tx_id, - to_timestamp(event_attributes:end_time) as end_time, + COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, event_attributes:poll_id as poll_id FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) From fb9a2d09d21451d62a79c99d3c12865fffd38943 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:23:02 -0400 Subject: [PATCH 29/86] changed protocol fee again --- models/terra/mirror__close_collateral.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index c2b03ed9..3fb27823 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -54,13 +54,21 @@ SELECT tx_id, event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, burn_amount * i.price AS burn_amount_usd, - event_attributes:burn_amount[0]:denom::string AS burn_currency + event_attributes:burn_amount[0]:denom::string AS burn_currency, + + event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, + protocol_fee_amount * f.price AS procotol_fee_amount_usd, + event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:burn_amount[0]:denom::string = i.currency +LEFT OUTER JOIN prices f + ON date_trunc('hour', t.block_timestamp) = f.hour + AND t.event_attributes:protocol_fee[0]:denom::string = f.currency + WHERE event_attributes:burn_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) From 0dc782eb857251ba2b93853a541bd34bbb6f7298 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 16:45:54 -0400 Subject: [PATCH 30/86] fix --- models/terra/terraswap__lp_actions.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index b4cf5967..10db241c 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -3,7 +3,7 @@ unique_key = 'block_id || tx_id', incremental_strategy = 'delete+insert', cluster_by = ['block_timestamp', 'block_id'], - tags=['snowflake', 'terra', 'terraswap', 'lp'] + tags=['snowflake', 'terra', 'terraswap', 'terraswap_lp_actions'] ) }} WITH prices as ( @@ -150,7 +150,7 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:refund_assets[1]:denom::string = i.currency -WHERE tx_id IN(SELECT tx_id FROM provide_msgs) +WHERE tx_id IN(SELECT tx_id FROM withdraw_msgs) AND event_type = 'from_contract' AND event_attributes:refund_assets IS NOT NULL @@ -193,7 +193,7 @@ SELECT chain_id, block_id, block_timestamp, - m.tx_id, + w.tx_id, event_type, sender, token_0_amount, @@ -207,7 +207,7 @@ SELECT lp_share_amount, lp_pool_address, lp_pool_name -FROM withdraw_msgs m +FROM withdraw_msgs w -JOIN withdraw_events e - ON m.tx_id = e.tx_id \ No newline at end of file +JOIN withdraw_events we + ON w.tx_id = we.tx_id \ No newline at end of file From 38df73f845304d70386c0247ed35e2d280e2f140 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 19:54:33 -0400 Subject: [PATCH 31/86] transfers --- models/terra/terra__transfers.sql | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/models/terra/terra__transfers.sql b/models/terra/terra__transfers.sql index c7c8c871..11beb424 100644 --- a/models/terra/terra__transfers.sql +++ b/models/terra/terra__transfers.sql @@ -113,6 +113,30 @@ WHERE msg_module = 'bank' -- {% else %} -- AND block_timestamp >= getdate() - interval '9 months' {% endif %} + +UNION + +SELECT + blockchain, + chain_id, + tx_status, + block_id, + block_timestamp, + tx_id, + msg_type, + msg_value:sender::string as event_from, + msg_value:execute_msg:transfer:recipient::string as event_to, + msg_value:execute_msg:transfer:amount / pow(10,6) as event_amount, + msg_value:contract::string as event_currency +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:transfer IS NOT NULL + +{% if is_incremental() %} + AND block_timestamp >= getdate() - interval '1 days' +-- {% else %} +-- AND block_timestamp >= getdate() - interval '9 months' +{% endif %} + ) From 6fcf9a8255b54cb81b94cc0269a921d2e2a36696 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 20:01:14 -0400 Subject: [PATCH 32/86] airdrops for terra --- models/terra/terra__airdrop_claims.sql | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 models/terra/terra__airdrop_claims.sql diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql new file mode 100644 index 00000000..faeb9b70 --- /dev/null +++ b/models/terra/terra__airdrop_claims.sql @@ -0,0 +1,27 @@ +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], + tags=['snowflake', 'terra', 'airdrops', 'claims'] +) }} + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as claimer, + msg_value:execute_msg:claim:amount / POW(10,6) as amount, + msg_value:contract::string as contract_address, + l.address_name as contract_label +FROM {{source('silver_terra', 'msgs')}} +WHERE msg_value:execute_msg:claim IS NOT NULL + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON msg_value:contract::string = l.address + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} \ No newline at end of file From f336363206cc710c5a4a736b56ed7f45a36732a2 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 19 Sep 2021 20:09:37 -0400 Subject: [PATCH 33/86] fix --- models/terra/terra__airdrop_claims.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql index faeb9b70..4dcaff33 100644 --- a/models/terra/terra__airdrop_claims.sql +++ b/models/terra/terra__airdrop_claims.sql @@ -17,11 +17,12 @@ SELECT msg_value:contract::string as contract_address, l.address_name as contract_label FROM {{source('silver_terra', 'msgs')}} -WHERE msg_value:execute_msg:claim IS NOT NULL LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address +WHERE msg_value:execute_msg:claim IS NOT NULL + {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} \ No newline at end of file From 4fdb3703524041d1efb3e77fbc0faef34416d7b4 Mon Sep 17 00:00:00 2001 From: yulike Date: Thu, 30 Sep 2021 23:21:43 -0400 Subject: [PATCH 34/86] updated anchor test --- dbt_project.yml | 3 - models/terra/anchor__bonds.yml | 70 ++++++++++++++++++++ models/terra/anchor__borrows.yml | 56 ++++++++++++++++ models/terra/anchor__burns.yml | 56 ++++++++++++++++ models/terra/anchor__collateral.yml | 56 ++++++++++++++++ models/terra/anchor__deposits.yml | 62 +++++++++++++++++ models/terra/anchor__gov_staking.yml | 62 +++++++++++++++++ models/terra/anchor__gov_submit_proposal.yml | 50 ++++++++++++++ models/terra/anchor__gov_vote.yml | 50 ++++++++++++++ models/terra/anchor__liquidations.yml | 42 ++++++++++++ models/terra/anchor__redeem.yml | 62 +++++++++++++++++ models/terra/anchor__repay.yml | 62 +++++++++++++++++ models/terra/anchor__reward_claims.yml | 62 +++++++++++++++++ models/terra/anchor_dbt__stake.yml | 50 ++++++++++++++ 14 files changed, 740 insertions(+), 3 deletions(-) create mode 100644 models/terra/anchor__bonds.yml create mode 100644 models/terra/anchor__borrows.yml create mode 100644 models/terra/anchor__burns.yml create mode 100644 models/terra/anchor__collateral.yml create mode 100644 models/terra/anchor__deposits.yml create mode 100644 models/terra/anchor__gov_staking.yml create mode 100644 models/terra/anchor__gov_submit_proposal.yml create mode 100644 models/terra/anchor__gov_vote.yml create mode 100644 models/terra/anchor__liquidations.yml create mode 100644 models/terra/anchor__redeem.yml create mode 100644 models/terra/anchor__repay.yml create mode 100644 models/terra/anchor__reward_claims.yml create mode 100644 models/terra/anchor_dbt__stake.yml diff --git a/dbt_project.yml b/dbt_project.yml index 4654188d..b760b1f4 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -43,6 +43,3 @@ models: vars: "dbt_date:time_zone": America/Los_Angeles - -tests: - +severity: warn # all tests diff --git a/models/terra/anchor__bonds.yml b/models/terra/anchor__bonds.yml new file mode 100644 index 00000000..b9ae35b6 --- /dev/null +++ b/models/terra/anchor__bonds.yml @@ -0,0 +1,70 @@ +version: 2 +models: + - name: anchor__bonds + description: Anchor Bonds + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: BONDED_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BONDED_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BONDED_CURRENCY + description: "" + tests: + - not_null + - name: MINTED_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINTED_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINTED_CURRENCY + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/anchor__borrows.yml b/models/terra/anchor__borrows.yml new file mode 100644 index 00000000..4533f186 --- /dev/null +++ b/models/terra/anchor__borrows.yml @@ -0,0 +1,56 @@ +version: 2 +models: + - name: anchor__borrows + description: Anchor Borrows + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__burns.yml b/models/terra/anchor__burns.yml new file mode 100644 index 00000000..d9dae58f --- /dev/null +++ b/models/terra/anchor__burns.yml @@ -0,0 +1,56 @@ +version: 2 +models: + - name: anchor__burns + description: Anchor Burns + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml new file mode 100644 index 00000000..d9dae58f --- /dev/null +++ b/models/terra/anchor__collateral.yml @@ -0,0 +1,56 @@ +version: 2 +models: + - name: anchor__burns + description: Anchor Burns + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__deposits.yml b/models/terra/anchor__deposits.yml new file mode 100644 index 00000000..6f383620 --- /dev/null +++ b/models/terra/anchor__deposits.yml @@ -0,0 +1,62 @@ +version: 2 +models: + - name: anchor__deposits + description: Anchor Deposits + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: DEPOSIT_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: DEPOSIT_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: DEPOSIT_CURRENCY + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml new file mode 100644 index 00000000..e3507964 --- /dev/null +++ b/models/terra/anchor__gov_staking.yml @@ -0,0 +1,62 @@ +version: 2 +models: + - name: anchor__gov_staking + description: Anchor GOV STAKING + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.yml b/models/terra/anchor__gov_submit_proposal.yml new file mode 100644 index 00000000..161270a4 --- /dev/null +++ b/models/terra/anchor__gov_submit_proposal.yml @@ -0,0 +1,50 @@ +version: 2 +models: + - name: anchor__gov_submit_proposal + description: Anchor GOV SUBMIT PROPOSAL + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CREATOR + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml new file mode 100644 index 00000000..819b5e7f --- /dev/null +++ b/models/terra/anchor__gov_vote.yml @@ -0,0 +1,50 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: BALANCE + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: VOTER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml new file mode 100644 index 00000000..102bae3e --- /dev/null +++ b/models/terra/anchor__liquidations.yml @@ -0,0 +1,42 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: BORROWER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml new file mode 100644 index 00000000..ed13f7d8 --- /dev/null +++ b/models/terra/anchor__redeem.yml @@ -0,0 +1,62 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml new file mode 100644 index 00000000..ed13f7d8 --- /dev/null +++ b/models/terra/anchor__repay.yml @@ -0,0 +1,62 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml new file mode 100644 index 00000000..ed13f7d8 --- /dev/null +++ b/models/terra/anchor__reward_claims.yml @@ -0,0 +1,62 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CURRENCY + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml new file mode 100644 index 00000000..59a8efff --- /dev/null +++ b/models/terra/anchor_dbt__stake.yml @@ -0,0 +1,50 @@ +version: 2 +models: + - name: anchor__gov_vote + description: Anchor GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file From c39dcb99276bda8e36e8c9621fa86dbac8eb1907 Mon Sep 17 00:00:00 2001 From: yulike Date: Fri, 1 Oct 2021 14:34:04 -0400 Subject: [PATCH 35/86] updated model names --- models/terra/anchor__collateral.yml | 4 ++-- models/terra/anchor__liquidations.yml | 4 ++-- models/terra/anchor__redeem.yml | 4 ++-- models/terra/anchor__repay.yml | 4 ++-- models/terra/anchor__reward_claims.yml | 4 ++-- models/terra/anchor_dbt__stake.yml | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml index d9dae58f..685c67cc 100644 --- a/models/terra/anchor__collateral.yml +++ b/models/terra/anchor__collateral.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__burns - description: Anchor Burns + - name: anchor__collateral + description: Anchor COLLATERAL tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml index 102bae3e..aa30ea2f 100644 --- a/models/terra/anchor__liquidations.yml +++ b/models/terra/anchor__liquidations.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__gov_vote - description: Anchor GOV VOTE + - name: anchor__liquidations + description: Anchor LIQUIDATIONS tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml index ed13f7d8..e05a3fd6 100644 --- a/models/terra/anchor__redeem.yml +++ b/models/terra/anchor__redeem.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__gov_vote - description: Anchor GOV VOTE + - name: anchor__redeem + description: Anchor REDEEM tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml index ed13f7d8..1a4cef4d 100644 --- a/models/terra/anchor__repay.yml +++ b/models/terra/anchor__repay.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__gov_vote - description: Anchor GOV VOTE + - name: anchor__repay + description: Anchor REPAY tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml index ed13f7d8..cb543273 100644 --- a/models/terra/anchor__reward_claims.yml +++ b/models/terra/anchor__reward_claims.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__gov_vote - description: Anchor GOV VOTE + - name: anchor__reward_claims + description: Anchor REWARD CLAIMS tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 59a8efff..9885734f 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__gov_vote - description: Anchor GOV VOTE + - name: anchor__stake + description: Anchor STAKE tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: From a8ac3953ba978329096fb58662d2ed69cc04c3e3 Mon Sep 17 00:00:00 2001 From: Julius Remigio <14811322+juls858@users.noreply.github.com> Date: Fri, 1 Oct 2021 12:00:27 -0700 Subject: [PATCH 36/86] - fixed packages.yml --- packages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages.yml b/packages.yml index 1c4f8e44..bffcceea 100644 --- a/packages.yml +++ b/packages.yml @@ -1,3 +1,3 @@ packages: - - git: "https://github.com/calogica/dbt-expectations.git" - revision: 0.4.2 + - package: calogica/dbt_expectations + version: [">=0.4.0", "<0.5.0"] From aeb6b47929221f21e697f4829d36f5ac83d4cee7 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Mon, 4 Oct 2021 12:32:10 -0400 Subject: [PATCH 37/86] fixed mirror close collateral --- models/terra/mirror__close_collateral.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 3fb27823..c69047d9 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -129,9 +129,9 @@ SELECT tax_amount, tax_amount_usd, tax_currency, - protocol_fee_amount, - procotol_fee_amount_usd, - protocol_fee_currency, + coalesce(b.protocol_fee_amount, w.protocol_fee_amount) as protocol_fee_amount, + coalesce(b.procotol_fee_amount_usd, w.procotol_fee_amount_usd) as procotol_fee_amount_usd, + coalesce(b.protocol_fee_currency, w.protocol_fee_currency) as protocol_fee_currency, burn_amount, burn_amount_usd, burn_currency, From 65c9994e2c9b0296b2c5daf883b11fdca6d9f7a8 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 12:37:04 -0400 Subject: [PATCH 38/86] adding updated version of models/terra/mirror__close_collateral.sql --- models/terra/mirror__close_collateral.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 3fb27823..c69047d9 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -129,9 +129,9 @@ SELECT tax_amount, tax_amount_usd, tax_currency, - protocol_fee_amount, - procotol_fee_amount_usd, - protocol_fee_currency, + coalesce(b.protocol_fee_amount, w.protocol_fee_amount) as protocol_fee_amount, + coalesce(b.procotol_fee_amount_usd, w.procotol_fee_amount_usd) as procotol_fee_amount_usd, + coalesce(b.protocol_fee_currency, w.protocol_fee_currency) as protocol_fee_currency, burn_amount, burn_amount_usd, burn_currency, From 4edcc63b850deccb9f61931beec08f76f5911417 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 14:49:15 -0400 Subject: [PATCH 39/86] fixed sql in mirror__close_collateral, writing tests in .yml --- models/terra/mirror__close_collateral.sql | 2 +- models/terra/mirror__close_collateral.yml | 109 ++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 models/terra/mirror__close_collateral.yml diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index c69047d9..58a7186c 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -58,7 +58,7 @@ SELECT event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, protocol_fee_amount * f.price AS procotol_fee_amount_usd, - event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, + event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM {{source('silver_terra', 'msg_events')}} t LEFT OUTER JOIN prices i diff --git a/models/terra/mirror__close_collateral.yml b/models/terra/mirror__close_collateral.yml new file mode 100644 index 00000000..1c311aea --- /dev/null +++ b/models/terra/mirror__close_collateral.yml @@ -0,0 +1,109 @@ +version: 2 +models: + - name: mirror__close_collateral + description: Mirror CLOSE COLLATERAL + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: COLLATERAL_ID + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: TAX_AMOUNT + tests: + - not_null + - name: TAX_AMOUNT_USD + tests: + - not_null + - name: TAX_CURRENCY + tests: + - not_null + - name: PROTOCOL_FEE_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_CURRENCY + tests: + - not_null + - name: BURN_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_CURRENCY + tests: + - not_null + - name: WITHDRAW_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_CURRENCY + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file From c71fddb7f0dc4dbf17bd5ef6a697cb685a9b9bfb Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 15:13:27 -0400 Subject: [PATCH 40/86] fixing typo in mirror__close_collateral.sql --- models/terra/mirror__close_collateral.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 58a7186c..558b80d0 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -57,7 +57,7 @@ SELECT event_attributes:burn_amount[0]:denom::string AS burn_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * f.price AS procotol_fee_amount_usd, + protocol_fee_amount * f.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM {{source('silver_terra', 'msg_events')}} t @@ -88,7 +88,7 @@ SELECT event_attributes:tax_amount[0]:denom::string AS tax_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * f.price AS procotol_fee_amount_usd, + protocol_fee_amount * f.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, @@ -130,7 +130,7 @@ SELECT tax_amount_usd, tax_currency, coalesce(b.protocol_fee_amount, w.protocol_fee_amount) as protocol_fee_amount, - coalesce(b.procotol_fee_amount_usd, w.procotol_fee_amount_usd) as procotol_fee_amount_usd, + coalesce(b.protocol_fee_amount_usd, w.protocol_fee_amount_usd) as protocol_fee_amount_usd, coalesce(b.protocol_fee_currency, w.protocol_fee_currency) as protocol_fee_currency, burn_amount, burn_amount_usd, From 1699db998ddd55f6886614dbe94e6d2cecd51aab Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 16:58:55 -0400 Subject: [PATCH 41/86] updating mirror__close_short_farm.sql for consistency, added .yml and inital tests --- models/terra/mirror__close_short_farm.sql | 12 +-- models/terra/mirror__close_short_farm.yml | 126 ++++++++++++++++++++++ 2 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 models/terra/mirror__close_short_farm.yml diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 9e588718..b6cd2803 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -93,8 +93,8 @@ SELECT unlocked_amount * i.price AS unlocked_amount_usd, event_attributes:unlocked_amount[0]:denom::string AS unlocked_currency, - (event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount) / POW(10,6) AS tax, - tax * a.price AS tax_usd, + (event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount) / POW(10,6) AS tax_amount, + tax * a.price AS tax_amount_usd, event_attributes:"0_tax_amount"[0]:denom::string AS tax_currency FROM event_tx t @@ -125,7 +125,7 @@ SELECT event_attributes:burn_amount[0]:denom::string AS burn_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee, - protocol_fee * i.price AS protocol_fee_usd, + protocol_fee * i.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM event_tx t @@ -149,11 +149,11 @@ SELECT m.tx_id, collateral_id, sender, - tax, - tax_usd, + tax_amount, + tax_amount_usd, tax_currency, protocol_fee, - protocol_fee_usd, + protocol_fee_amount_usd, protocol_fee_currency, burn_amount, burn_amount_usd, diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml new file mode 100644 index 00000000..92218505 --- /dev/null +++ b/models/terra/mirror__close_short_farm.yml @@ -0,0 +1,126 @@ +version: 2 +models: + - name: mirror__close_short_farm + description: Mirror CLOSE SHORT FARM + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: COLLATERAL_ID + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: TAX_AMOUNT + tests: + - not_null + - name: TAX_AMOUNT_USD + tests: + - not_null + - name: TAX_CURRENCY + tests: + - not_null + - name: PROTOCOL_FEE_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_CURRENCY + tests: + - not_null + - name: BURN_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_CURRENCY + tests: + - not_null + - name: WITHDRAW_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_CURRENCY + tests: + - not_null + - name: UNLOCKED_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_CURRENCY + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file From dea2490b298149d3bb44baabc1758c61738ca200 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 17:13:41 -0400 Subject: [PATCH 42/86] typo in mirror__close_short_farm.sql --- models/terra/mirror__close_short_farm.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index b6cd2803..a3228e7f 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -94,7 +94,7 @@ SELECT event_attributes:unlocked_amount[0]:denom::string AS unlocked_currency, (event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount) / POW(10,6) AS tax_amount, - tax * a.price AS tax_amount_usd, + tax_amount * a.price AS tax_amount_usd, event_attributes:"0_tax_amount"[0]:denom::string AS tax_currency FROM event_tx t From f55b9a598010506540d9892d319636f5a9fece75 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Mon, 4 Oct 2021 17:19:20 -0400 Subject: [PATCH 43/86] another typo in mirror__close_short_farm.sql --- models/terra/mirror__close_short_farm.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index a3228e7f..36bdce67 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -124,8 +124,8 @@ SELECT burn_amount * o.price AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency, - event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee, - protocol_fee * i.price AS protocol_fee_amount_usd, + event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, + protocol_fee_amount * i.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM event_tx t @@ -152,7 +152,7 @@ SELECT tax_amount, tax_amount_usd, tax_currency, - protocol_fee, + protocol_fee_amount, protocol_fee_amount_usd, protocol_fee_currency, burn_amount, From de36bf3caf5dc16f93cb594bb64cd0b2d6e131f5 Mon Sep 17 00:00:00 2001 From: amasucci13 Date: Mon, 4 Oct 2021 17:01:32 -0700 Subject: [PATCH 44/86] Updated mirror liquidations,open short farm, and terra.airdrop --- models/terra/mirror__liquidations.sql | 18 +-- models/terra/mirror__liquidations.yml | 159 ++++++++++++++++++++++ models/terra/mirror__open_collateral.yml | 98 +++++++++++++ models/terra/mirror__open_short_farm.sql | 12 +- models/terra/mirror__open_short_farm.yml | 166 +++++++++++++++++++++++ models/terra/terra__airdrop_claims.sql | 4 +- models/terra/terra__airdrop_claims.yml | 46 +++++++ 7 files changed, 486 insertions(+), 17 deletions(-) create mode 100644 models/terra/mirror__liquidations.yml create mode 100644 models/terra/mirror__open_collateral.yml create mode 100644 models/terra/mirror__open_short_farm.yml create mode 100644 models/terra/terra__airdrop_claims.yml diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index c10dfd71..5ab6c234 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -49,10 +49,10 @@ events AS ( SELECT tx_id, - COALESCE((event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount), event_attributes:tax_amount[0]:amount) / POW(10,6) AS tax, + COALESCE((event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount), event_attributes:tax_amount[0]:amount) / POW(10,6) AS tax_amount, COALESCE(event_attributes:"1_tax_amount"[0]:denom::string,event_attributes:tax_amount[0]:denom::string) AS tax_currency, - event_attributes:protocol_fee[0]:amount / POW(10,6) as protocol_fee, + event_attributes:protocol_fee[0]:amount / POW(10,6) as protocol_fee_amount, event_attributes:protocol_fee[0]:denom::string as protocol_fee_currency, event_attributes:liquidated_amount[0]:amount / POW(10,6) as liquidated_amount, @@ -62,7 +62,7 @@ SELECT event_attributes:return_collateral_amount[0]:denom::string as return_collateral_currency, event_attributes:unlocked_amount[0]:amount / POW(10,6) as unlocked_amount, - event_attributes:unlocked_amount[0]:denom::string as unlocked_curency, + event_attributes:unlocked_amount[0]:denom::string as unlocked_currency, event_attributes:owner::string as owner FROM {{source('silver_terra', 'msg_events')}} @@ -86,11 +86,11 @@ SELECT collateral_id, sender as buyer, owner, - tax, - tax * t.price as tax_usd, + tax_amount, + tax_amount * t.price as tax_amount_usd, tax_currency, - protocol_fee, - protocol_fee * p.price as protocol_fee_usd, + protocol_fee_amount, + protocol_fee_amount * p.price as protocol_fee_amount_usd, protocol_fee_currency, liquidated_amount, liquidated_amount * l.price as liquidated_amount_usd, @@ -100,7 +100,7 @@ SELECT return_collateral_currency, unlocked_amount, unlocked_amount * u.price as unlocked_amount_usd, - unlocked_curency, + unlocked_currency, contract_address, g.address_name AS contract_label FROM msgs m @@ -129,4 +129,4 @@ LEFT OUTER JOIN prices r LEFT OUTER JOIN prices u ON date_trunc('hour', m.block_timestamp) = u.hour - AND unlocked_curency = u.currency \ No newline at end of file + AND unlocked_currency = u.currency \ No newline at end of file diff --git a/models/terra/mirror__liquidations.yml b/models/terra/mirror__liquidations.yml new file mode 100644 index 00000000..07096a87 --- /dev/null +++ b/models/terra/mirror__liquidations.yml @@ -0,0 +1,159 @@ +version: 2 +models: + - name: mirror__liquidations + description: Mirror LIQUIDATIONS + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - BLOCK_ID + - TX_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - name: TX_ID + description: "" + tests: + - not_null + - name: COLLATERAL_ID + description: "" + tests: + - not_null + - name: BUYER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: OWNER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: TAX_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TAX_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TAX_CURRENCY + description: "" + tests: + - not_null + - name: PROTOCOL_FEE_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_CURRENCY + description: "" + tests: + - not_null + - name: LIQUIDATED_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: LIQUIDATED_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: LIQUIDATED_CURRENCY + description: "" + tests: + - not_null + - name: RETURN_COLLATERAL_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_COLLATERAL_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_COLLATERAL_CURRENCY + description: "" + tests: + - not_null + - name: UNLOCKED_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_CURRENCY + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/mirror__open_collateral.yml b/models/terra/mirror__open_collateral.yml new file mode 100644 index 00000000..70badda0 --- /dev/null +++ b/models/terra/mirror__open_collateral.yml @@ -0,0 +1,98 @@ +version: 2 +models: + - name: mirror__open_collateral + description: Mirror OPEN COLLATERAL + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - BLOCK_ID + - TX_ID + - COLLATERAL_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - name: TX_ID + description: "" + tests: + - not_null + - name: COLLATERAL_ID + description: "" + tests: + - not_null + - name: COLLATERAL_RATIO + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: COLLATERAL_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COLLATERAL_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COLLATERAL_CURRENCY + description: "" + tests: + - not_null + - name: MINT_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINT_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINT_CURRENCY + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 86680983..5bab764f 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -74,9 +74,9 @@ SELECT locked_amount * l.price AS locked_amount_usd, event_attributes:locked_amount[0]:denom::string AS locked_currency, - event_attributes:tax_amount / POW(10,6) AS tax, - event_attributes:commission_amount / POW(10,6) AS commission, - event_attributes:spread_amount / POW(10,6) AS spread, + event_attributes:tax_amount / POW(10,6) AS tax_amount, + event_attributes:commission_amount / POW(10,6) AS commission_amount, + event_attributes:spread_amount / POW(10,6) AS spread_amount, to_timestamp(event_attributes:unlock_time::numeric) AS unlock_time FROM {{source('silver_terra', 'msg_events')}} t @@ -117,9 +117,9 @@ SELECT collateral_id, collateral_ratio, sender, - tax, - commission, - spread, + tax_amount, + commission_amount, + spread_amount, collateral_amount, collateral_amount_usd, collateral_currency, diff --git a/models/terra/mirror__open_short_farm.yml b/models/terra/mirror__open_short_farm.yml new file mode 100644 index 00000000..3e3c2b85 --- /dev/null +++ b/models/terra/mirror__open_short_farm.yml @@ -0,0 +1,166 @@ +version: 2 +models: + - name: mirror__open_short_farm + description: Mirror OPEN SHORT FARM + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - BLOCK_ID + - TX_ID + - COLLATERAL_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - name: TX_ID + description: "" + tests: + - not_null + - name: COLLATERAL_ID + description: "" + tests: + - not_null + - name: COLLATERAL_RATIO + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: TAX_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COMMISSION_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: SPREAD_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COLLATERAL_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COLLATERAL_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COLLATERAL_CURRENCY + description: "" + tests: + - not_null + - name: MINT_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINT_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: MINT_CURRENCY + description: "" + tests: + - not_null + - name: RETURN_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_CURRENCY + description: "" + tests: + - not_null + - name: LOCKED_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: LOCKED_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: LOCKED_CURRENCY + description: "" + tests: + - not_null + - name: UNLOCK_TIME + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql index 4dcaff33..8117a024 100644 --- a/models/terra/terra__airdrop_claims.sql +++ b/models/terra/terra__airdrop_claims.sql @@ -7,7 +7,7 @@ ) }} SELECT - blockchain, + t.blockchain, chain_id, block_id, block_timestamp, @@ -16,7 +16,7 @@ SELECT msg_value:execute_msg:claim:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} as t LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address diff --git a/models/terra/terra__airdrop_claims.yml b/models/terra/terra__airdrop_claims.yml new file mode 100644 index 00000000..0b4c231d --- /dev/null +++ b/models/terra/terra__airdrop_claims.yml @@ -0,0 +1,46 @@ +version: 2 +models: + - name: terra__airdrop_claims + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - BLOCK_ID + - TX_ID + - CONTRACT_ADDRESS + columns: + - name: BLOCKCHAIN + tests: + - not_null + - name: BLOCK_ID + tests: + - not_null + - name: BLOCK_TIMESTAMP + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - name: CHAIN_ID + tests: + - not_null + - name: CLAIMER + tests: + - not_null + - name: AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CONTRACT_ADDRESS + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + tests: + - not_null + - name: TX_ID + tests: + - not_null From 298b54ea38fa66d633a91326ecabb64aab64ea3a Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Mon, 4 Oct 2021 20:27:33 -0400 Subject: [PATCH 45/86] Mirror reward claims --- models/terra/mirror__reward_claims.sql | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 models/terra/mirror__reward_claims.sql diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql new file mode 100644 index 00000000..6fb2b03d --- /dev/null +++ b/models/terra/mirror__reward_claims.sql @@ -0,0 +1,88 @@ +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], + tags=['snowflake', 'terra', 'mirror', 'reward_claims'] +) }} + +WITH prices AS ( + +SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price +FROM {{ ref('terra__oracle_prices')}} + +WHERE 1=1 + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:contract::string as contract_address +FROM terra.msgs +WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +), + +events AS ( + +SELECT + m.tx_id, + event_attributes:"1_amount" / POW(10,6) as claim_amount, + event_attributes:"1_contract_address"::string as claim_currency +FROM terra.msg_events e + +JOIN msgs m + ON m.tx_id = e.tx_id + +WHERE event_attributes:"0_action" = 'withdraw' + +{% if is_incremental() %} + AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +) + +SELECT + m.blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + claim_amount, + claim_amount * p.price AS claim_amount_usd, + claim_currency, + contract_address, + l.address_name AS contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices p + ON date_trunc('hour', m.block_timestamp) = p.hour + AND claim_currency = p.currency From b8ff9696d937513810ccc53caf774f9265a490c5 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Tue, 5 Oct 2021 09:55:37 -0400 Subject: [PATCH 46/86] adding models/terra/mirror__reward_claims.sql --- models/terra/mirror__reward_claims.sql | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 models/terra/mirror__reward_claims.sql diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql new file mode 100644 index 00000000..6fb2b03d --- /dev/null +++ b/models/terra/mirror__reward_claims.sql @@ -0,0 +1,88 @@ +{{ config( + materialized = 'incremental', + unique_key = 'block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], + tags=['snowflake', 'terra', 'mirror', 'reward_claims'] +) }} + +WITH prices AS ( + +SELECT + date_trunc('hour', block_timestamp) as hour, + currency, + symbol, + avg(price_usd) as price +FROM {{ ref('terra__oracle_prices')}} + +WHERE 1=1 + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +GROUP BY 1,2,3 + +), + +msgs AS ( + +SELECT + blockchain, + chain_id, + block_id, + block_timestamp, + tx_id, + msg_value:sender::string as sender, + msg_value:contract::string as contract_address +FROM terra.msgs +WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +), + +events AS ( + +SELECT + m.tx_id, + event_attributes:"1_amount" / POW(10,6) as claim_amount, + event_attributes:"1_contract_address"::string as claim_currency +FROM terra.msg_events e + +JOIN msgs m + ON m.tx_id = e.tx_id + +WHERE event_attributes:"0_action" = 'withdraw' + +{% if is_incremental() %} + AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +) + +SELECT + m.blockchain, + chain_id, + block_id, + block_timestamp, + m.tx_id, + sender, + claim_amount, + claim_amount * p.price AS claim_amount_usd, + claim_currency, + contract_address, + l.address_name AS contract_label +FROM msgs m + +JOIN events e + ON m.tx_id = e.tx_id + +LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l +ON contract_address = l.address + +LEFT OUTER JOIN prices p + ON date_trunc('hour', m.block_timestamp) = p.hour + AND claim_currency = p.currency From 8656025b49ff1a2d8f67b5bf9f9c8bca2583605a Mon Sep 17 00:00:00 2001 From: drakedanner Date: Tue, 5 Oct 2021 09:59:38 -0400 Subject: [PATCH 47/86] added mirror__reward_claims.yml for testing --- models/terra/mirror__close_short_farm.yml | 81 ++--------------------- 1 file changed, 5 insertions(+), 76 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 92218505..062bd039 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: mirror__close_short_farm - description: Mirror CLOSE SHORT FARM + - name: mirror__reward_claims + description: Mirror REWARD CLAIMS tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -28,90 +28,19 @@ models: description: "" tests: - not_null - - name: COLLATERAL_ID - tests: - - not_null - name: SENDER description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: terra[0-9a-zA-Z]{39,40} - - name: TAX_AMOUNT - tests: - - not_null - - name: TAX_AMOUNT_USD - tests: - - not_null - - name: TAX_CURRENCY - tests: - - not_null - - name: PROTOCOL_FEE_AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: PROTOCOL_FEE_AMOUNT_USD - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: PROTOCOL_FEE_CURRENCY - tests: - - not_null - - name: BURN_AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: BURN_AMOUNT_USD - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: BURN_CURRENCY - tests: - - not_null - - name: WITHDRAW_AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: WITHDRAW_AMOUNT_USD - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: WITHDRAW_CURRENCY - tests: - - not_null - - name: UNLOCKED_AMOUNT + - name: CLAIM_AMOUNT tests: - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: UNLOCKED_AMOUNT_USD + - name: CLAIM_AMOUNT_USD tests: - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: UNLOCKED_CURRENCY + - name: CLAIM_CURRENCY tests: - not_null - name: CONTRACT_ADDRESS From 6721dd3cd6b346367e2352728dd889f2acc31862 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Tue, 5 Oct 2021 11:21:38 -0400 Subject: [PATCH 48/86] adjusting tests --- models/terra/mirror__close_short_farm.yml | 81 +++++++++++++++++++++-- models/terra/mirror__reward_claims.yml | 55 +++++++++++++++ 2 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 models/terra/mirror__reward_claims.yml diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 062bd039..92218505 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: mirror__reward_claims - description: Mirror REWARD CLAIMS + - name: mirror__close_short_farm + description: Mirror CLOSE SHORT FARM tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -28,19 +28,90 @@ models: description: "" tests: - not_null + - name: COLLATERAL_ID + tests: + - not_null - name: SENDER description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: terra[0-9a-zA-Z]{39,40} - - name: CLAIM_AMOUNT + - name: TAX_AMOUNT + tests: + - not_null + - name: TAX_AMOUNT_USD + tests: + - not_null + - name: TAX_CURRENCY + tests: + - not_null + - name: PROTOCOL_FEE_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: PROTOCOL_FEE_CURRENCY + tests: + - not_null + - name: BURN_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: BURN_CURRENCY + tests: + - not_null + - name: WITHDRAW_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: WITHDRAW_CURRENCY + tests: + - not_null + - name: UNLOCKED_AMOUNT tests: - not_null - - name: CLAIM_AMOUNT_USD + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_AMOUNT_USD tests: - not_null - - name: CLAIM_CURRENCY + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: UNLOCKED_CURRENCY tests: - not_null - name: CONTRACT_ADDRESS diff --git a/models/terra/mirror__reward_claims.yml b/models/terra/mirror__reward_claims.yml new file mode 100644 index 00000000..062bd039 --- /dev/null +++ b/models/terra/mirror__reward_claims.yml @@ -0,0 +1,55 @@ +version: 2 +models: + - name: mirror__reward_claims + description: Mirror REWARD CLAIMS + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CLAIM_AMOUNT + tests: + - not_null + - name: CLAIM_AMOUNT_USD + tests: + - not_null + - name: CLAIM_CURRENCY + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file From 5a175f59ef8e81c05dae86213f9df97d3811923e Mon Sep 17 00:00:00 2001 From: amasucci13 Date: Tue, 5 Oct 2021 08:41:34 -0700 Subject: [PATCH 49/86] Added bespoke tests for Mirror --- .../mirror/mirror__liquidations__collateral_id-assert_no_gap.sql | 1 + .../mirror__open_collateral__collateral_id-assert_no_gap.sql | 1 + .../mirror__open_short_farm__collateral_id-assert_no_gap.sql | 1 + 3 files changed, 3 insertions(+) create mode 100644 tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql create mode 100644 tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql create mode 100644 tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql diff --git a/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql new file mode 100644 index 00000000..c7b24c7b --- /dev/null +++ b/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql @@ -0,0 +1 @@ +{{ sequence_gaps(ref("mirror__liquidations"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file diff --git a/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql new file mode 100644 index 00000000..44a34251 --- /dev/null +++ b/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql @@ -0,0 +1 @@ +{{ sequence_gaps(ref("mirror__open_collateral"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file diff --git a/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql new file mode 100644 index 00000000..9c1cb837 --- /dev/null +++ b/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql @@ -0,0 +1 @@ +{{ sequence_gaps(ref("mirror__open_short_farm"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file From 44e599c4e556c7a03400c3317b8ccb74e282090c Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Tue, 5 Oct 2021 19:58:40 -0400 Subject: [PATCH 50/86] changed table name --- models/terra/mirror__reward_claims.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql index 6fb2b03d..b8146ba6 100644 --- a/models/terra/mirror__reward_claims.sql +++ b/models/terra/mirror__reward_claims.sql @@ -18,7 +18,7 @@ FROM {{ ref('terra__oracle_prices')}} WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -35,11 +35,11 @@ SELECT tx_id, msg_value:sender::string as sender, msg_value:contract::string as contract_address -FROM terra.msgs +FROM {{ref('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) {% endif %} ), @@ -50,7 +50,7 @@ SELECT m.tx_id, event_attributes:"1_amount" / POW(10,6) as claim_amount, event_attributes:"1_contract_address"::string as claim_currency -FROM terra.msg_events e +FROM {{ref('silver_terra', 'msg_events')}} e JOIN msgs m ON m.tx_id = e.tx_id @@ -58,7 +58,7 @@ JOIN msgs m WHERE event_attributes:"0_action" = 'withdraw' {% if is_incremental() %} - AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) {% endif %} ) From f9d8ccb53b243f697f1fb343344ba9b3ce21710a Mon Sep 17 00:00:00 2001 From: drakedanner Date: Wed, 6 Oct 2021 11:28:19 -0400 Subject: [PATCH 51/86] added daily price avg as backup to handle missing hourly data --- models/terra/mirror__reward_claims.sql | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql index 6fb2b03d..accacd64 100644 --- a/models/terra/mirror__reward_claims.sql +++ b/models/terra/mirror__reward_claims.sql @@ -25,6 +25,25 @@ GROUP BY 1,2,3 ), +prices_backup AS ( + +SELECT + date_trunc('day', block_timestamp) as day, + currency, + symbol, + avg(price_usd) as price +FROM {{ ref('terra__oracle_prices')}} + +WHERE 1=1 + +{% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) +{% endif %} + +GROUP BY 1,2,3 + +), + msgs AS ( SELECT @@ -71,7 +90,7 @@ SELECT m.tx_id, sender, claim_amount, - claim_amount * p.price AS claim_amount_usd, + claim_amount * coalesce(p.price,pb.price) AS claim_amount_usd, claim_currency, contract_address, l.address_name AS contract_label @@ -86,3 +105,7 @@ ON contract_address = l.address LEFT OUTER JOIN prices p ON date_trunc('hour', m.block_timestamp) = p.hour AND claim_currency = p.currency + +LEFT OUTER JOIN prices_backup pb + ON date_trunc('day', m.block_timestamp) = pb.day + AND claim_currency = pb.currency From f9cf04606a06348967803daad1a9286b757988bb Mon Sep 17 00:00:00 2001 From: drakedanner Date: Wed, 6 Oct 2021 14:57:13 -0400 Subject: [PATCH 52/86] adding prices_backup to mirror__close_collateral using daily avg --- models/terra/mirror__close_collateral.sql | 49 ++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 558b80d0..93a1bd15 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -25,6 +25,25 @@ WITH prices AS ( ), +prices_backup AS ( + + SELECT + date_trunc('day', block_timestamp) as day, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + {% endif %} + + GROUP BY 1,2,3 + +), + msgs AS ( SELECT m.blockchain, @@ -53,11 +72,11 @@ burns AS ( SELECT tx_id, event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, - burn_amount * i.price AS burn_amount_usd, + burn_amount * coalesce(i.price,i_b.price) AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * f.price AS protocol_fee_amount_usd, + protocol_fee_amount * coalesce(f.price,f_b.price) AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM {{source('silver_terra', 'msg_events')}} t @@ -69,6 +88,14 @@ LEFT OUTER JOIN prices f ON date_trunc('hour', t.block_timestamp) = f.hour AND t.event_attributes:protocol_fee[0]:denom::string = f.currency +LEFT OUTER JOIN prices_backup i_b + ON date_trunc('day', t.block_timestamp) = i_b.day + AND t.event_attributes:burn_amount[0]:denom::string = i_b.currency + +LEFT OUTER JOIN prices_backup f_b + ON date_trunc('day', t.block_timestamp) = f_b.day + AND t.event_attributes:protocol_fee[0]:denom::string = f_b.currency + WHERE event_attributes:burn_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) @@ -84,15 +111,15 @@ SELECT tx_id, event_attributes:tax_amount[0]:amount /POW(10,6) AS tax_amount, - tax_amount * o.price AS tax_amount_usd, + tax_amount * coalesce(o.price,o_b.price) AS tax_amount_usd, event_attributes:tax_amount[0]:denom::string AS tax_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * f.price AS protocol_fee_amount_usd, + protocol_fee_amount * coalesce(f.price,f_b.price) AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, - withdraw_amount * i.price AS withdraw_amount_usd, + withdraw_amount * coalesce(i.price,i_b.price) AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency FROM {{source('silver_terra', 'msg_events')}} t @@ -108,6 +135,18 @@ LEFT OUTER JOIN prices f ON date_trunc('hour', t.block_timestamp) = f.hour AND t.event_attributes:protocol_fee[0]:denom::string = f.currency +LEFT OUTER JOIN prices_backup o_b + ON date_trunc('day', t.block_timestamp) = o_b.day + AND t.event_attributes:tax_amount[0]:denom::string = o_b.currency + +LEFT OUTER JOIN prices_backup i_b + ON date_trunc('day', t.block_timestamp) = i_b.day + AND t.event_attributes:withdraw_amount[0]:denom::string = i_b.currency + +LEFT OUTER JOIN prices_backup f_b + ON date_trunc('day', t.block_timestamp) = f_b.day + AND t.event_attributes:protocol_fee[0]:denom::string = f_b.currency + WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) From 0068498adc12b6c02a12ed33147f7856c35f16f4 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Wed, 6 Oct 2021 16:58:31 -0400 Subject: [PATCH 53/86] added daily fill for usd prices in mirror__close_short_farm.sql --- models/terra/mirror__close_short_farm.sql | 49 ++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 36bdce67..5df2f132 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -25,6 +25,25 @@ WITH prices AS ( ), +prices_backup AS ( + + SELECT + date_trunc('day', block_timestamp) as day, + currency, + symbol, + avg(price_usd) as price + FROM {{ ref('terra__oracle_prices')}} + + WHERE 1=1 + + {% if is_incremental() %} + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + {% endif %} + + GROUP BY 1,2,3 + +), + tx AS ( SELECT @@ -86,15 +105,15 @@ SELECT tx_id, event_attributes:withdraw_amount[0]:amount / POW(10,6) AS withdraw_amount, - withdraw_amount * o.price AS withdraw_amount_usd, + withdraw_amount * coalesce(o.price,o_b.price) AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency, event_attributes:unlocked_amount[0]:amount / POW(10,6) AS unlocked_amount, - unlocked_amount * i.price AS unlocked_amount_usd, + unlocked_amount * coalesce(i.price,i_b.price) AS unlocked_amount_usd, event_attributes:unlocked_amount[0]:denom::string AS unlocked_currency, (event_attributes:"0_tax_amount"[0]:amount + event_attributes:"1_tax_amount"[0]:amount) / POW(10,6) AS tax_amount, - tax_amount * a.price AS tax_amount_usd, + tax_amount * coalesce(a.price,a_b.price) AS tax_amount_usd, event_attributes:"0_tax_amount"[0]:denom::string AS tax_currency FROM event_tx t @@ -111,6 +130,18 @@ LEFT OUTER JOIN prices a ON date_trunc('hour', t.block_timestamp) = a.hour AND t.event_attributes:"0_tax_amount"[0]:denom::string = a.currency +LEFT OUTER JOIN prices_backup o_b + ON date_trunc('day', t.block_timestamp) = o_b.day + AND t.event_attributes:withdraw_amount[0]:denom::string = o_b.currency + +LEFT OUTER JOIN prices_backup i_b + ON date_trunc('day', t.block_timestamp) = i_b.day + AND t.event_attributes:unlocked_amount[0]:denom::string = i_b.currency + +LEFT OUTER JOIN prices_backup a_b + ON date_trunc('day', t.block_timestamp) = a_b.day + AND t.event_attributes:"0_tax_amount"[0]:denom::string = a_b.currency + WHERE event_attributes:withdraw_amount IS NOT NULL ), @@ -121,11 +152,11 @@ SELECT tx_id, event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, - burn_amount * o.price AS burn_amount_usd, + burn_amount * coalesce(o.price,o_b.price) AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * i.price AS protocol_fee_amount_usd, + protocol_fee_amount * coalesce(i.price,i_b.price) AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM event_tx t @@ -137,6 +168,14 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:protocol_fee[0]:denom::string = i.currency +LEFT OUTER JOIN prices_backup o_b + ON date_trunc('day', t.block_timestamp) = o_b.day + AND t.event_attributes:burn_amount[0]:denom::string = o_b.currency + +LEFT OUTER JOIN prices_backup i_b + ON date_trunc('day', t.block_timestamp) = i_b.day + AND t.event_attributes:protocol_fee[0]:denom::string = i_b.currency + WHERE event_attributes:burn_amount IS NOT NULL ) From 1f3b4a39e3d3d699053d30a0b94115316ae2a90a Mon Sep 17 00:00:00 2001 From: amasucci13 Date: Wed, 6 Oct 2021 14:10:34 -0700 Subject: [PATCH 54/86] changed source to ref in terra_dbt__msgs --- models/terra/terra_dbt__msgs.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/terra_dbt__msgs.sql b/models/terra/terra_dbt__msgs.sql index 8417f5bf..8a317098 100644 --- a/models/terra/terra_dbt__msgs.sql +++ b/models/terra/terra_dbt__msgs.sql @@ -12,7 +12,7 @@ with base_tables as ( from {{source('bronze', 'prod_terra_sink_645110886')}} where record_content:model:name::string = 'terra_msg_model' {% if is_incremental() %} - AND (record_metadata:CreateTime::int/1000)::timestamp::date >= (select dateadd('day',-1,max(system_created_at::date)) from {{source('terra_dbt', 'msgs')}}) + AND (record_metadata:CreateTime::int/1000)::timestamp::date >= (select dateadd('day',-1,max(system_created_at::date)) from {{ref('terra_dbt', 'msgs')}}) {% endif %} ) From 1adaac64a5060ac7eadc7bc2002c6f5bcb69214a Mon Sep 17 00:00:00 2001 From: yulike Date: Wed, 6 Oct 2021 23:34:26 -0400 Subject: [PATCH 55/86] Updated the dbt test again for Anchor --- models/terra/anchor__bonds.yml | 12 ------------ models/terra/anchor__borrows.yml | 10 ---------- models/terra/anchor__burns.yml | 10 ---------- models/terra/anchor__collateral.yml | 10 ---------- models/terra/anchor__deposits.yml | 11 ----------- models/terra/anchor__gov_staking.yml | 11 ----------- models/terra/anchor__gov_submit_proposal.yml | 9 --------- models/terra/anchor__gov_vote.yml | 9 --------- models/terra/anchor__liquidations.yml | 8 -------- models/terra/anchor__redeem.yml | 11 ----------- models/terra/anchor__repay.yml | 11 ----------- models/terra/anchor__reward_claims.yml | 11 ----------- models/terra/anchor_dbt__stake.yml | 11 +---------- models/terra/mirror__reward_claims.sql | 10 +++++----- models/terra/terra__staking.sql | 2 +- 15 files changed, 7 insertions(+), 139 deletions(-) diff --git a/models/terra/anchor__bonds.yml b/models/terra/anchor__bonds.yml index b9ae35b6..a1e6c506 100644 --- a/models/terra/anchor__bonds.yml +++ b/models/terra/anchor__bonds.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__bonds - description: Anchor Bonds tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: BONDED_AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: BONDED_AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,11 +37,9 @@ models: - decimal - float - name: BONDED_CURRENCY - description: "" tests: - not_null - name: MINTED_AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -57,7 +47,6 @@ models: - decimal - float - name: MINTED_AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -65,6 +54,5 @@ models: - decimal - float - name: MINTED_CURRENCY - description: "" tests: - not_null \ No newline at end of file diff --git a/models/terra/anchor__borrows.yml b/models/terra/anchor__borrows.yml index 4533f186..f677ddf5 100644 --- a/models/terra/anchor__borrows.yml +++ b/models/terra/anchor__borrows.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__borrows - description: Anchor Borrows tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,11 +37,9 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__burns.yml b/models/terra/anchor__burns.yml index d9dae58f..6a7d9e96 100644 --- a/models/terra/anchor__burns.yml +++ b/models/terra/anchor__burns.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__burns - description: Anchor Burns tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,11 +37,9 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml index 685c67cc..ccf5cbf2 100644 --- a/models/terra/anchor__collateral.yml +++ b/models/terra/anchor__collateral.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__collateral - description: Anchor COLLATERAL tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,11 +37,9 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__deposits.yml b/models/terra/anchor__deposits.yml index 6f383620..e3787c5a 100644 --- a/models/terra/anchor__deposits.yml +++ b/models/terra/anchor__deposits.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__deposits - description: Anchor Deposits tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: DEPOSIT_AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: DEPOSIT_AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,17 +37,14 @@ models: - decimal - float - name: DEPOSIT_CURRENCY - description: "" tests: - not_null - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml index e3507964..6ed28bbd 100644 --- a/models/terra/anchor__gov_staking.yml +++ b/models/terra/anchor__gov_staking.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__gov_staking - description: Anchor GOV STAKING tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,17 +37,14 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__gov_submit_proposal.yml b/models/terra/anchor__gov_submit_proposal.yml index 161270a4..fd3271a7 100644 --- a/models/terra/anchor__gov_submit_proposal.yml +++ b/models/terra/anchor__gov_submit_proposal.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__gov_submit_proposal - description: Anchor GOV SUBMIT PROPOSAL tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,13 +30,11 @@ models: - decimal - float - name: CREATOR - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml index 819b5e7f..8bd7fcf9 100644 --- a/models/terra/anchor__gov_vote.yml +++ b/models/terra/anchor__gov_vote.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__gov_vote - description: Anchor GOV VOTE tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: BALANCE - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,13 +30,11 @@ models: - decimal - float - name: VOTER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml index aa30ea2f..89cca49a 100644 --- a/models/terra/anchor__liquidations.yml +++ b/models/terra/anchor__liquidations.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__liquidations - description: Anchor LIQUIDATIONS tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,33 +8,26 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: BORROWER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml index e05a3fd6..12f10bfd 100644 --- a/models/terra/anchor__redeem.yml +++ b/models/terra/anchor__redeem.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__redeem - description: Anchor REDEEM tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,17 +37,14 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml index 1a4cef4d..82f0c643 100644 --- a/models/terra/anchor__repay.yml +++ b/models/terra/anchor__repay.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__repay - description: Anchor REPAY tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,17 +37,14 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml index cb543273..68b2acfb 100644 --- a/models/terra/anchor__reward_claims.yml +++ b/models/terra/anchor__reward_claims.yml @@ -1,7 +1,6 @@ version: 2 models: - name: anchor__reward_claims - description: Anchor REWARD CLAIMS tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,7 +30,6 @@ models: - decimal - float - name: AMOUNT_USD - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -45,17 +37,14 @@ models: - decimal - float - name: CURRENCY - description: "" tests: - not_null - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 9885734f..fa789f80 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,7 +1,6 @@ version: 2 models: - - name: anchor__stake - description: Anchor STAKE + - name: anchor stake tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -9,27 +8,21 @@ models: - BLOCK_ID columns: - name: BLOCKCHAIN - description: "" tests: - not_null - name: CHAIN_ID - description: "" tests: - not_null - name: BLOCK_ID - description: "" tests: - not_null - name: BLOCK_TIMESTAMP - description: "" tests: - not_null - name: TX_ID - description: "" tests: - not_null - name: AMOUNT - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: @@ -37,13 +30,11 @@ models: - decimal - float - name: SENDER - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS - description: "" tests: - not_null - dbt_expectations.expect_column_values_to_match_regex: diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql index b8146ba6..0e6f77aa 100644 --- a/models/terra/mirror__reward_claims.sql +++ b/models/terra/mirror__reward_claims.sql @@ -18,7 +18,7 @@ FROM {{ ref('terra__oracle_prices')}} WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -35,11 +35,11 @@ SELECT tx_id, msg_value:sender::string as sender, msg_value:contract::string as contract_address -FROM {{ref('silver_terra', 'msgs')}} +FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ), @@ -50,7 +50,7 @@ SELECT m.tx_id, event_attributes:"1_amount" / POW(10,6) as claim_amount, event_attributes:"1_contract_address"::string as claim_currency -FROM {{ref('silver_terra', 'msg_events')}} e +FROM {{source('silver_terra', 'msg_events')}} e JOIN msgs m ON m.tx_id = e.tx_id @@ -58,7 +58,7 @@ JOIN msgs m WHERE event_attributes:"0_action" = 'withdraw' {% if is_incremental() %} - AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra', 'msgs')}}) + AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) {% endif %} ) diff --git a/models/terra/terra__staking.sql b/models/terra/terra__staking.sql index c4105d06..3d96bcb3 100644 --- a/models/terra/terra__staking.sql +++ b/models/terra/terra__staking.sql @@ -57,7 +57,7 @@ redelegate AS ( prices AS ( SELECT date_trunc('hour', block_timestamp) as hour, - currency, + currency,1 symbol, avg(price_usd) as price_usd FROM {{ ref('terra__oracle_prices')}} From 39971b4599d7d02ccbc5e6fd3f2ba500218c76e4 Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Thu, 7 Oct 2021 01:19:13 -0400 Subject: [PATCH 56/86] fix for mirror_close_collateral --- models/terra/mirror__close_collateral.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index c69047d9..96d4a591 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -70,6 +70,7 @@ LEFT OUTER JOIN prices f AND t.event_attributes:protocol_fee[0]:denom::string = f.currency WHERE event_attributes:burn_amount IS NOT NULL + AND event_attributes:protocol_fee IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' From d577ef4c03dbc0a76f77178777dd5cdb214f350e Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Thu, 7 Oct 2021 01:31:19 -0400 Subject: [PATCH 57/86] fixed another issue with close_collateral --- models/terra/mirror__close_collateral.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 96d4a591..01c43c21 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -110,6 +110,7 @@ LEFT OUTER JOIN prices f AND t.event_attributes:protocol_fee[0]:denom::string = f.currency WHERE event_attributes:withdraw_amount IS NOT NULL + AND event_attributes:"2_action" != 'release_shorting_funds' AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' From a7c21752e8cd2a7066c735e988f70d9e78477dfb Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 02:01:05 -0400 Subject: [PATCH 58/86] joan fixed ./models/terra/mirror__close_collateral.sql --- models/terra/mirror__close_collateral.sql | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 93a1bd15..71d0ab69 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -72,11 +72,11 @@ burns AS ( SELECT tx_id, event_attributes:burn_amount[0]:amount / POW(10,6) AS burn_amount, - burn_amount * coalesce(i.price,i_b.price) AS burn_amount_usd, + burn_amount * i.price AS burn_amount_usd, event_attributes:burn_amount[0]:denom::string AS burn_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * coalesce(f.price,f_b.price) AS protocol_fee_amount_usd, + protocol_fee_amount * f.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency FROM {{source('silver_terra', 'msg_events')}} t @@ -97,6 +97,7 @@ LEFT OUTER JOIN prices_backup f_b AND t.event_attributes:protocol_fee[0]:denom::string = f_b.currency WHERE event_attributes:burn_amount IS NOT NULL + AND event_attributes:protocol_fee IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' @@ -111,15 +112,15 @@ SELECT tx_id, event_attributes:tax_amount[0]:amount /POW(10,6) AS tax_amount, - tax_amount * coalesce(o.price,o_b.price) AS tax_amount_usd, + tax_amount * o.price AS tax_amount_usd, event_attributes:tax_amount[0]:denom::string AS tax_currency, event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, - protocol_fee_amount * coalesce(f.price,f_b.price) AS protocol_fee_amount_usd, + protocol_fee_amount * f.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency, event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, - withdraw_amount * coalesce(i.price,i_b.price) AS withdraw_amount_usd, + withdraw_amount * i.price AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency FROM {{source('silver_terra', 'msg_events')}} t @@ -148,6 +149,7 @@ LEFT OUTER JOIN prices_backup f_b AND t.event_attributes:protocol_fee[0]:denom::string = f_b.currency WHERE event_attributes:withdraw_amount IS NOT NULL + AND event_attributes:"2_action" != 'release_shorting_funds' AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' From e472857c9656b96552dc9f59e6083f5bdf173557 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 03:11:12 -0400 Subject: [PATCH 59/86] adding TO DOs to models/terra/mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 92218505..1dbe3918 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -43,6 +43,10 @@ models: - name: TAX_AMOUNT_USD tests: - not_null + ## TO DO: ADD WHERE CONDITION FOR aUST + # config: + # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + - name: TAX_CURRENCY tests: - not_null @@ -56,6 +60,9 @@ models: - name: PROTOCOL_FEE_AMOUNT_USD tests: - not_null + ## TO DO: ADD WHERE CONDITION FOR aUST + # config: + # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -73,6 +80,9 @@ models: - name: BURN_AMOUNT_USD tests: - not_null + ## TO DO: ADD WHERE CONDITION FOR aUST + # config: + # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -83,6 +93,9 @@ models: - name: WITHDRAW_AMOUNT tests: - not_null + ## TO DO: ADD WHERE CONDITION FOR aUST + # config: + # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 37bd72eaffe5b37e94fcb3fc7466278812c01c34 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 11:41:40 -0400 Subject: [PATCH 60/86] working on where clauses in mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 1dbe3918..2b310f5b 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -44,8 +44,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - # config: - # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - name: TAX_CURRENCY tests: @@ -61,8 +60,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - # config: - # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -81,8 +79,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - # config: - # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -94,8 +91,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - # config: - # where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 8e084378eb0523733e963695deb8bfe0fed42edd Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 11:47:28 -0400 Subject: [PATCH 61/86] working on where clauses in mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 2b310f5b..6f5c5f7f 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -44,7 +44,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - name: TAX_CURRENCY tests: @@ -60,7 +60,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -79,7 +79,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -91,7 +91,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: "BURN_CURRENCY != 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu'" + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From c2aa6f9ffaf79e6230032141a429a38956bba55b Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 11:52:59 -0400 Subject: [PATCH 62/86] working on where clauses in mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 6f5c5f7f..353afc62 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -60,7 +60,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -79,7 +79,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -91,7 +91,7 @@ models: tests: - not_null ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From c52b9f11e7f9e7396e99f7b296e4750141671d29 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Oct 2021 16:27:15 -0400 Subject: [PATCH 63/86] mirror changes --- models/terra/anchor_dbt__stake.yml | 2 +- models/terra/mirror__gov_staking.sql | 22 ++-- models/terra/mirror__gov_staking.yml | 81 +++++++++++++ models/terra/mirror__gov_submit_proposal.sql | 2 +- models/terra/mirror__gov_submit_proposal.yml | 82 +++++++++++++ models/terra/mirror__gov_vote.sql | 2 +- models/terra/mirror__gov_vote.yml | 67 +++++++++++ models/terra/terraswap__lp_actions.yml | 108 ++++++++++++++++++ models/terra/terraswap__lp_stake.yml | 58 ++++++++++ models/terra/terraswap__swaps.yml | 102 +++++++++++++++++ ...submit_proposal__poll_id-assert_no_gap.sql | 1 + 11 files changed, 517 insertions(+), 10 deletions(-) create mode 100644 models/terra/mirror__gov_staking.yml create mode 100644 models/terra/mirror__gov_submit_proposal.yml create mode 100644 models/terra/mirror__gov_vote.yml create mode 100644 models/terra/terraswap__lp_actions.yml create mode 100644 models/terra/terraswap__lp_stake.yml create mode 100644 models/terra/terraswap__swaps.yml create mode 100644 tests/terra/mirror__gov_submit_proposal__poll_id-assert_no_gap.sql diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 9885734f..b72a364f 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,6 +1,6 @@ version: 2 models: - - name: anchor__stake + - name: anchor_dbt__stake description: Anchor STAKE tests: - dbt_utils.unique_combination_of_columns: diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index fde8b9b1..3f23f651 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -1,8 +1,8 @@ {{ config( materialized = 'incremental', - unique_key = 'block_id || tx_id', + unique_key = 'block_id || tx_id || msg_index ', incremental_strategy = 'delete+insert', - cluster_by = ['block_timestamp', 'block_id'], + cluster_by = ['block_timestamp', 'block_id','msg_index'], tags=['snowflake', 'terra', 'mirror', 'mirror_gov'] ) }} @@ -32,7 +32,8 @@ SELECT chain_id, block_id, block_timestamp, - tx_id, + t.tx_id, + t.msg_index, msg_value:sender::string as sender, msg_value:execute_msg:send:amount / POW(10,6) as event_amount, event_amount * o.price AS event_amount_usd, @@ -60,8 +61,9 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL stake_events AS ( SELECT - tx_id, - event_attributes:share as shares + tx_id, + msg_index, + event_attributes:share::float as shares FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' @@ -78,6 +80,7 @@ SELECT block_id, block_timestamp, m.tx_id, + e.msg_index, 'stake' as event_type, sender, event_amount, @@ -89,7 +92,8 @@ SELECT FROM stake_msgs m JOIN stake_events e - ON m.tx_id = e.tx_id +ON m.tx_id = e.tx_id +and m.msg_index = e.msg_index UNION @@ -100,7 +104,9 @@ SELECT chain_id, block_id, block_timestamp, - tx_id, + t.tx_id, + t.msg_index, + 'unstake' as event_type, msg_value:sender::string as sender, msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, @@ -111,6 +117,7 @@ SELECT l.address_name as contract_label FROM {{source('silver_terra', 'msgs')}} t + LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour AND 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' = o.currency @@ -118,6 +125,7 @@ LEFT OUTER JOIN prices o LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address + WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' AND tx_status = 'SUCCEEDED' diff --git a/models/terra/mirror__gov_staking.yml b/models/terra/mirror__gov_staking.yml new file mode 100644 index 00000000..175997f6 --- /dev/null +++ b/models/terra/mirror__gov_staking.yml @@ -0,0 +1,81 @@ +version: 2 +models: + - name: mirror__gov_staking + description: Mirror GOV STAKING + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - MSG_INDEX + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: EVENT_TYPE + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: EVENT_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: EVENT_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: EVENT_CURRENCY + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: SHARES + description: "" + tests: + - not_null: + where: EVENT_TYPE = 'STAKE' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index b4653e06..18f257d3 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -34,7 +34,7 @@ events AS ( SELECT tx_id, COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, - event_attributes:poll_id as poll_id + event_attributes:poll_id::number as poll_id FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' diff --git a/models/terra/mirror__gov_submit_proposal.yml b/models/terra/mirror__gov_submit_proposal.yml new file mode 100644 index 00000000..79908c41 --- /dev/null +++ b/models/terra/mirror__gov_submit_proposal.yml @@ -0,0 +1,82 @@ +version: 2 +models: + - name: mirror__gov_submit_proposal + description: Mirror GOV SUBMIT PROPOSAL + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: POLL_ID + description: "" + tests: + - unique + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - name: END_TIME + description: "" + tests: + - not_null + - name: CREATOR + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TITLE + description: "" + tests: + - not_null + - name: LINK + description: "" + tests: + - not_null + - name: DESCRIPTION + description: "" + tests: + - not_null + - name: MSG + description: "" + tests: + - not_null + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 75402b26..e8947a62 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -13,7 +13,7 @@ SELECT block_timestamp, tx_id, msg_value:sender::string as voter, - msg_value:execute_msg:cast_vote:poll_id as poll_id, + msg_value:execute_msg:cast_vote:poll_id::number as poll_id, msg_value:execute_msg:cast_vote:vote::string as vote, msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, diff --git a/models/terra/mirror__gov_vote.yml b/models/terra/mirror__gov_vote.yml new file mode 100644 index 00000000..66dd09a8 --- /dev/null +++ b/models/terra/mirror__gov_vote.yml @@ -0,0 +1,67 @@ +version: 2 +models: + - name: mirror__gov_vote + description: Mirror GOV VOTE + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: VOTER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: POLL_ID + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number + - name: VOTE + description: "" + tests: + - not_null + - accepted_values: + values: ['yes','no','abstain'] + - name: BALANCE + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CONTRACT_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} + - name: CONTRACT_LABEL + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/terraswap__lp_actions.yml b/models/terra/terraswap__lp_actions.yml new file mode 100644 index 00000000..72c7f6e3 --- /dev/null +++ b/models/terra/terraswap__lp_actions.yml @@ -0,0 +1,108 @@ +version: 2 +models: + - name: terraswap__lp_actions + description: Terraswap LP Actions + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: EVENT_TYPE + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: TOKEN_0_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TOKEN_0_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TOKEN_0_CURRENCY + description: "" + tests: + - not_null + - name: TOKEN_1_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TOKEN_1_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: TOKEN_1_CURRENCY + description: "" + tests: + - not_null + - name: POOL_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: POOL_NAME + description: "" + tests: + - not_null + - name: LP_SHARE_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: LP_POOL_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: LP_POOL_NAME + description: "" + tests: + - not_null \ No newline at end of file diff --git a/models/terra/terraswap__lp_stake.yml b/models/terra/terraswap__lp_stake.yml new file mode 100644 index 00000000..54b30662 --- /dev/null +++ b/models/terra/terraswap__lp_stake.yml @@ -0,0 +1,58 @@ +version: 2 +models: + - name: terraswap__lp_stake + description: Terraswap LP Stake + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: EVENT_TYPE + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: Contract_Address + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: Contract_Label + description: "" + tests: + - not_null diff --git a/models/terra/terraswap__swaps.yml b/models/terra/terraswap__swaps.yml new file mode 100644 index 00000000..eaf302b0 --- /dev/null +++ b/models/terra/terraswap__swaps.yml @@ -0,0 +1,102 @@ +version: 2 +models: + - name: terraswap__swaps + description: Terraswap Swaps + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - BLOCK_ID + columns: + - name: BLOCKCHAIN + description: "" + tests: + - not_null + - name: CHAIN_ID + description: "" + tests: + - not_null + - name: BLOCK_ID + description: "" + tests: + - not_null + - name: BLOCK_TIMESTAMP + description: "" + tests: + - not_null + - name: TX_ID + description: "" + tests: + - not_null + - name: SENDER + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: TAX_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: COMMISSION_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: OFFER_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: OFFER_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: OFFER_CURRENCY + description: "" + tests: + - not_null + - name: RETURN_AMOUNT + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_AMOUNT_USD + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: RETURN_CURRENCY + description: "" + tests: + - not_null + - name: POOL_ADDRESS + description: "" + tests: + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: 0[xX][0-9a-fA-F]+ + - name: POOL_NAME + description: "" + tests: + - not_null \ No newline at end of file diff --git a/tests/terra/mirror__gov_submit_proposal__poll_id-assert_no_gap.sql b/tests/terra/mirror__gov_submit_proposal__poll_id-assert_no_gap.sql new file mode 100644 index 00000000..fefeeed0 --- /dev/null +++ b/tests/terra/mirror__gov_submit_proposal__poll_id-assert_no_gap.sql @@ -0,0 +1 @@ +{{ sequence_gaps(ref("mirror__gov_submit_proposal"), [], "poll_id") }} From febd90f4d2f1c42a2f00a8f72ac1d56831a72ba7 Mon Sep 17 00:00:00 2001 From: Julius Remigio <14811322+juls858@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:33:44 -0700 Subject: [PATCH 64/86] - fixed issue when no partitions are passed. --- macros/tests/sequential_gaps.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/tests/sequential_gaps.sql b/macros/tests/sequential_gaps.sql index e9f2dc17..650b335f 100644 --- a/macros/tests/sequential_gaps.sql +++ b/macros/tests/sequential_gaps.sql @@ -21,7 +21,7 @@ {{ table }} ) SELECT - {{ partition_sql }}, + {{ partition_sql + "," if partition_sql }} {{ previous_column }}, {{ column }}, {{ column }} - {{ previous_column }} From f9a641d5b887669bb40107e49361d4d040c3e0bd Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 17:17:27 -0400 Subject: [PATCH 65/86] fixing where clauses in mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index 353afc62..aad52b4a 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -42,10 +42,8 @@ models: - not_null - name: TAX_AMOUNT_USD tests: - - not_null - ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') - + - not_null: + where: TAX_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - name: TAX_CURRENCY tests: - not_null @@ -58,13 +56,13 @@ models: - float - name: PROTOCOL_FEE_AMOUNT_USD tests: - - not_null - ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + - not_null: + where: PROTOCOL_FEE_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float + - name: PROTOCOL_FEE_CURRENCY tests: - not_null @@ -77,9 +75,8 @@ models: - float - name: BURN_AMOUNT_USD tests: - - not_null - ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + - not_null: + where: BURN_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -89,9 +86,8 @@ models: - not_null - name: WITHDRAW_AMOUNT tests: - - not_null - ## TO DO: ADD WHERE CONDITION FOR aUST - where: BURN_CURRENCY NOT IN ('terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu') + - not_null: + where: WITHDRAW_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From fb425363833983d564df3e7ecb5eb973d00b1450 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 17:30:01 -0400 Subject: [PATCH 66/86] fixing anchor_dbt__stake.yml to ref right sql --- models/terra/anchor_dbt__stake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 9885734f..b72a364f 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,6 +1,6 @@ version: 2 models: - - name: anchor__stake + - name: anchor_dbt__stake description: Anchor STAKE tests: - dbt_utils.unique_combination_of_columns: From c66dd99c792a35f75051ec09b9af38e613eac7c0 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 17:46:25 -0400 Subject: [PATCH 67/86] changing source to ref on non-shared refrenced models --- models/terra/mirror__close_collateral.sql | 16 ++++++++-------- models/terra/mirror__close_short_farm.sql | 12 ++++++------ models/terra/mirror__reward_claims.sql | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/models/terra/mirror__close_collateral.sql b/models/terra/mirror__close_collateral.sql index 71d0ab69..4467f09b 100644 --- a/models/terra/mirror__close_collateral.sql +++ b/models/terra/mirror__close_collateral.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ prices_backup AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -55,7 +55,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -64,7 +64,7 @@ WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -78,7 +78,7 @@ SELECT event_attributes:protocol_fee[0]:amount / POW(10,6) AS protocol_fee_amount, protocol_fee_amount * f.price AS protocol_fee_amount_usd, event_attributes:protocol_fee[0]:denom::string AS protocol_fee_currency -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour @@ -103,7 +103,7 @@ WHERE event_attributes:burn_amount IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -122,7 +122,7 @@ SELECT event_attributes:withdraw_amount[0]:amount /POW(10,6) AS withdraw_amount, withdraw_amount * i.price AS withdraw_amount_usd, event_attributes:withdraw_amount[0]:denom::string AS withdraw_currency -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -155,7 +155,7 @@ WHERE event_attributes:withdraw_amount IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__close_short_farm.sql b/models/terra/mirror__close_short_farm.sql index 5df2f132..17713e1a 100644 --- a/models/terra/mirror__close_short_farm.sql +++ b/models/terra/mirror__close_short_farm.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ prices_backup AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -53,13 +53,13 @@ SELECT block_timestamp, tx_id, msg_value -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:send:msg:burn IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -70,12 +70,12 @@ SELECT block_timestamp, tx_id, event_attributes -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(select tx_id from tx) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql index accacd64..ac5288dd 100644 --- a/models/terra/mirror__reward_claims.sql +++ b/models/terra/mirror__reward_claims.sql @@ -18,7 +18,7 @@ FROM {{ ref('terra__oracle_prices')}} WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ FROM {{ ref('terra__oracle_prices')}} WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -58,7 +58,7 @@ FROM terra.msgs WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -77,7 +77,7 @@ JOIN msgs m WHERE event_attributes:"0_action" = 'withdraw' {% if is_incremental() %} - AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND e.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) From 90f610ed95f9da4cee58a5328d16a695e45eef23 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Thu, 7 Oct 2021 18:13:27 -0400 Subject: [PATCH 68/86] changing source to ref in terra__prices_oracle.sql --- models/terra/terra__oracle_prices.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/terra/terra__oracle_prices.sql b/models/terra/terra__oracle_prices.sql index c0fbe35e..ea60f308 100644 --- a/models/terra/terra__oracle_prices.sql +++ b/models/terra/terra__oracle_prices.sql @@ -188,7 +188,7 @@ SELECT me.event_attributes:price / pe.price as luna_exchange_rate, me.event_attributes:price AS price_usd, 'oracle' as source -FROM {{source('silver_terra', 'msg_events')}} me +FROM {{ref('silver_terra__msg_events')}} me LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON event_attributes:asset::string = l.address @@ -198,7 +198,7 @@ LEFT OUTER JOIN prices pe WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id - FROM {{source('silver_terra', 'msgs')}} + FROM {{ref('silver_terra__msgs')}} WHERE msg_value:contract::string = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t' AND msg_value:execute_msg:feed_price IS NOT NULL ) From c3440e7870866f144d3af57772d9a58e759e3b1e Mon Sep 17 00:00:00 2001 From: drakedanner Date: Fri, 8 Oct 2021 00:10:02 -0400 Subject: [PATCH 69/86] correcting source to ref in many files --- models/terra/anchor__bonds.sql | 10 +++++----- models/terra/anchor__borrows.sql | 6 +++--- models/terra/anchor__burns.sql | 6 +++--- models/terra/anchor__collateral.sql | 14 +++++++------- models/terra/anchor__deposits.sql | 10 +++++----- models/terra/anchor__gov_staking.sql | 14 +++++++------- models/terra/anchor__gov_submit_proposal.sql | 8 ++++---- models/terra/anchor__gov_vote.sql | 4 ++-- models/terra/anchor__liquidations.sql | 10 +++++----- models/terra/anchor__redeem.sql | 6 +++--- models/terra/anchor__repay.sql | 6 +++--- models/terra/anchor__reward_claims.sql | 18 +++++++++--------- models/terra/anchor_dbt__stake.sql | 14 +++++++------- models/terra/mirror__gov_staking.sql | 14 +++++++------- models/terra/mirror__gov_submit_proposal.sql | 8 ++++---- models/terra/mirror__gov_vote.sql | 4 ++-- models/terra/mirror__liquidations.sql | 10 +++++----- models/terra/mirror__open_collateral.sql | 10 +++++----- models/terra/mirror__open_short_farm.sql | 10 +++++----- models/terra/terra__airdrop_claims.sql | 4 ++-- models/terra/terra__transfers.sql | 2 +- models/terra/terraswap__lp_actions.sql | 18 +++++++++--------- models/terra/terraswap__lp_stake.sql | 12 ++++++------ models/terra/terraswap__swaps.sql | 14 +++++++------- 24 files changed, 116 insertions(+), 116 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index b9be0273..a7791f43 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -40,7 +40,7 @@ SELECT msg_value:execute_msg:bond:validator::string AS validator, msg_value:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -65,7 +65,7 @@ SELECT event_attributes:minted / POW(10,6) AS minted_amount, minted_amount * price AS minted_amount_usd, event_attributes:"1_contract_address"::string as minted_currency -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour @@ -76,7 +76,7 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__borrows.sql b/models/terra/anchor__borrows.sql index 4fa0e5f2..595c72c3 100644 --- a/models/terra/anchor__borrows.sql +++ b/models/terra/anchor__borrows.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT 'uusd' as currency, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour @@ -51,5 +51,5 @@ WHERE msg_value:execute_msg:borrow_stable IS NOT NULL -- Anchor Borrow AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__burns.sql b/models/terra/anchor__burns.sql index 0408edc5..9b09737a 100644 --- a/models/terra/anchor__burns.sql +++ b/models/terra/anchor__burns.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:send:msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__collateral.sql b/models/terra/anchor__collateral.sql index 28d4f390..11032db9 100644 --- a/models/terra/anchor__collateral.sql +++ b/models/terra/anchor__collateral.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:sender::string AS sender, msg_value:execute_msg:send:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -46,7 +46,7 @@ WHERE msg_value:execute_msg:withdraw_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -58,7 +58,7 @@ events AS ( event_attributes:collaterals[0]:amount / POW(10,6) as amount, amount * price AS amount_usd, event_attributes:collaterals[0]:denom::string as currency -FROM {{source('silver_terra', 'msg_events')}} m +FROM {{ref('silver_terra__msg_events')}} m LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour @@ -70,7 +70,7 @@ WHERE tx_id IN(SELECT tx_id FROM msgs) AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -109,7 +109,7 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -122,5 +122,5 @@ WHERE msg_value:execute_msg:send:msg:deposit_collateral IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__deposits.sql b/models/terra/anchor__deposits.sql index 6c3f281d..d85228c4 100644 --- a/models/terra/anchor__deposits.sql +++ b/models/terra/anchor__deposits.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -40,7 +40,7 @@ SELECT msg_value:coins[0]:denom::string as deposit_currency, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -54,7 +54,7 @@ WHERE msg_value:execute_msg:deposit_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -67,7 +67,7 @@ SELECT event_attributes:mint_amount / POW(10,6) as mint_amount, mint_amount * price AS mint_amount_usd, event_attributes:"1_contract_address"::string as mint_currency -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} LEFT OUTER JOIN prices o ON date_trunc('hour', block_timestamp) = o.hour @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__gov_staking.sql b/models/terra/anchor__gov_staking.sql index 0ca6db62..6541ab53 100644 --- a/models/terra/anchor__gov_staking.sql +++ b/models/terra/anchor__gov_staking.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -39,7 +39,7 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -62,12 +62,12 @@ stake_events AS ( SELECT tx_id, event_attributes:share as shares -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -109,7 +109,7 @@ SELECT NULL as shares, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -123,5 +123,5 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.sql b/models/terra/anchor__gov_submit_proposal.sql index db032ae9..f0f3beff 100644 --- a/models/terra/anchor__gov_submit_proposal.sql +++ b/models/terra/anchor__gov_submit_proposal.sql @@ -20,13 +20,13 @@ SELECT msg_value:execute_msg:send:msg:create_poll:description::string as description, msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, msg_value:execute_msg:send:contract::string as contract_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -35,12 +35,12 @@ SELECT tx_id, COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, event_attributes:poll_id as poll_id -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__gov_vote.sql b/models/terra/anchor__gov_vote.sql index ed8fcda0..5ed25822 100644 --- a/models/terra/anchor__gov_vote.sql +++ b/models/terra/anchor__gov_vote.sql @@ -18,7 +18,7 @@ SELECT msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -28,5 +28,5 @@ WHERE msg_value:contract::string = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5 AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index cf47fc5c..309279ea 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -36,7 +36,7 @@ SELECT msg_value:execute_msg:liquidate_collateral:borrower::string AS borrower, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -46,7 +46,7 @@ WHERE msg_value:contract::string = 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8 AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -63,7 +63,7 @@ SELECT repay_amount * r.price as repay_amount_usd, event_attributes:stable_denom::string as repay_currency, event_attributes:bid_fee / POW(10,6) AS bid_fee -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} LEFT OUTER JOIN prices l ON date_trunc('hour', block_timestamp) = l.hour @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'liquidate_collateral' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/anchor__redeem.sql b/models/terra/anchor__redeem.sql index cfc71977..b51cd761 100644 --- a/models/terra/anchor__redeem.sql +++ b/models/terra/anchor__redeem.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:send:msg:redeem_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__repay.sql b/models/terra/anchor__repay.sql index 66bc10f9..abb4ca93 100644 --- a/models/terra/anchor__repay.sql +++ b/models/terra/anchor__repay.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:coins[0]:denom::string as currency, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -50,5 +50,5 @@ WHERE msg_value:execute_msg:repay_stable IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.sql b/models/terra/anchor__reward_claims.sql index 38cbf2c7..ecf7c76b 100644 --- a/models/terra/anchor__reward_claims.sql +++ b/models/terra/anchor__reward_claims.sql @@ -17,7 +17,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -30,14 +30,14 @@ SELECT tx_id, msg_index, msg_value:contract::string as claim_0_contract -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:withdraw IS NOT NULL AND msg_index = 0 AND msg_value:contract::string = 'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -49,14 +49,14 @@ SELECT msg_index, msg_value:sender::string as sender, msg_value:contract::string as claim_1_contract -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:claim_rewards IS NOT NULL AND msg_index = 1 AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -68,7 +68,7 @@ SELECT claim_0_contract, event_attributes:"0_amount" / POW(10,6) as claim_0_amount, event_attributes:"1_contract_address"::string as claim_0_currency -FROM {{source('silver_terra', 'msg_events')}} e +FROM {{ref('silver_terra__msg_events')}} e JOIN withdraw_msgs m ON m.tx_id = e.tx_id @@ -79,7 +79,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'withdraw' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -96,7 +96,7 @@ SELECT claim_1_contract, event_attributes:claim_amount / POW(10,6) as claim_1_amount, event_attributes:"2_contract_address"::string as claim_1_currency -FROM {{source('silver_terra', 'msg_events')}} e +FROM {{ref('silver_terra__msg_events')}} e JOIN claim_msgs m ON m.tx_id = e.tx_id @@ -107,7 +107,7 @@ WHERE event_type = 'from_contract' AND event_attributes:"0_action"::string = 'claim_rewards' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/anchor_dbt__stake.sql b/models/terra/anchor_dbt__stake.sql index 6c97bc46..985a4f4b 100644 --- a/models/terra/anchor_dbt__stake.sql +++ b/models/terra/anchor_dbt__stake.sql @@ -21,7 +21,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -41,7 +41,7 @@ SELECT msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -51,7 +51,7 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -62,7 +62,7 @@ SELECT tx_id, price, event_attributes:"0_contract_address"::string as currency -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} LEFT OUTER JOIN prices r ON date_trunc('hour', block_timestamp) = hour @@ -74,7 +74,7 @@ WHERE event_type = 'execute_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -112,7 +112,7 @@ SELECT msg_value:contract::string as currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:execute_msg:send:contract::string = l.address @@ -126,5 +126,5 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index fde8b9b1..3d987f49 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -39,7 +39,7 @@ SELECT msg_value:contract::string as event_currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -53,7 +53,7 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -62,12 +62,12 @@ stake_events AS ( SELECT tx_id, event_attributes:share as shares -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -109,7 +109,7 @@ SELECT NULL as shares, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -123,5 +123,5 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index b4653e06..21bb052a 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -20,13 +20,13 @@ SELECT msg_value:execute_msg:send:msg:create_poll:description::string as description, msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, msg_value:execute_msg:send:contract::string as contract_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -35,12 +35,12 @@ SELECT tx_id, COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, event_attributes:poll_id as poll_id -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(select tx_id from msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index 75402b26..2a639195 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -18,7 +18,7 @@ SELECT msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -28,5 +28,5 @@ WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} diff --git a/models/terra/mirror__liquidations.sql b/models/terra/mirror__liquidations.sql index c10dfd71..3c64d5c1 100644 --- a/models/terra/mirror__liquidations.sql +++ b/models/terra/mirror__liquidations.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -36,12 +36,12 @@ SELECT msg_value:sender::string as sender, msg_value:execute_msg:send:msg:auction:position_idx as collateral_id, msg_value:execute_msg:send:contract::string as contract_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:send:msg:auction IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -65,14 +65,14 @@ SELECT event_attributes:unlocked_amount[0]:denom::string as unlocked_curency, event_attributes:owner::string as owner -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE event_type = 'from_contract' AND tx_id IN(SELECT tx_id FROM msgs) AND event_attributes:return_collateral_amount IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index cfe616f4..0847fc0e 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -19,7 +19,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -38,7 +38,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -48,7 +48,7 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -64,7 +64,7 @@ SELECT event_attributes:mint_amount[0]:amount/ POW(10,6) as mint_amount, mint_amount * i.price AS mint_amount_usd, event_attributes:mint_amount[0]:denom::string as mint_currency -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -78,7 +78,7 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/mirror__open_short_farm.sql b/models/terra/mirror__open_short_farm.sql index 86680983..d329b928 100644 --- a/models/terra/mirror__open_short_farm.sql +++ b/models/terra/mirror__open_short_farm.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:execute_msg:open_position:collateral_ratio AS collateral_ratio, msg_value:contract::string AS contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -47,7 +47,7 @@ WHERE msg_value:contract::string = 'terra1wfz7h3aqf4cjmjcvc6s8lxdhh7k30nkczyf0mj AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -79,7 +79,7 @@ SELECT event_attributes:spread_amount / POW(10,6) AS spread, to_timestamp(event_attributes:unlock_time::numeric) AS unlock_time -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -103,7 +103,7 @@ WHERE event_type = 'from_contract' AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql index 4dcaff33..1ad8b07c 100644 --- a/models/terra/terra__airdrop_claims.sql +++ b/models/terra/terra__airdrop_claims.sql @@ -16,7 +16,7 @@ SELECT msg_value:execute_msg:claim:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -24,5 +24,5 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:claim IS NOT NULL {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/terra__transfers.sql b/models/terra/terra__transfers.sql index 8a5c7bca..6554c641 100644 --- a/models/terra/terra__transfers.sql +++ b/models/terra/terra__transfers.sql @@ -144,7 +144,7 @@ SELECT msg_value:execute_msg:transfer:recipient::string as event_to, msg_value:execute_msg:transfer:amount / pow(10,6) as event_amount, msg_value:contract::string as event_currency -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:transfer IS NOT NULL {% if is_incremental() %} diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 10db241c..242167f9 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -18,7 +18,7 @@ WITH prices as ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -37,7 +37,7 @@ SELECT msg_value:sender::string as sender, msg_value:contract::string as pool_address, l.address_name AS pool_name -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -46,7 +46,7 @@ WHERE msg_value:execute_msg:provide_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -69,7 +69,7 @@ SELECT ELSE event_attributes:"2_contract_address"::string END AS lp_pool_address, l.address_name AS lp_pool_name -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON event_attributes:"2_contract_address"::string = l.address @@ -90,7 +90,7 @@ WHERE msg_index = 1 AND event_type = 'from_contract' {% if is_incremental() %} - AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -109,7 +109,7 @@ SELECT l.address_name AS lp_pool_name, msg_value:execute_msg:send:contract::string as pool_address, p.address_name AS pool_name -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as p ON msg_value:contract::string = p.address @@ -121,7 +121,7 @@ WHERE msg_value:execute_msg:send:msg:withdraw_liquidity IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND m.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND m.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -140,7 +140,7 @@ SELECT event_attributes:refund_assets[1]:denom::string AS token_1_currency, event_attributes:withdrawn_share / POW(10,6) as lp_share_amount -FROM {{source('silver_terra', 'msg_events')}} t +FROM {{ref('silver_terra__msg_events')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -155,7 +155,7 @@ WHERE tx_id IN(SELECT tx_id FROM withdraw_msgs) AND event_attributes:refund_assets IS NOT NULL {% if is_incremental() %} - AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND t.block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) diff --git a/models/terra/terraswap__lp_stake.sql b/models/terra/terraswap__lp_stake.sql index 45b5d1c3..37e6806a 100644 --- a/models/terra/terraswap__lp_stake.sql +++ b/models/terra/terraswap__lp_stake.sql @@ -18,12 +18,12 @@ SELECT 'unstake_lp' as event_type, msg_value:sender::string as sender, msg_value:execute_msg:unbond:amount / POW(10,6) as amount -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:unbond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -33,13 +33,13 @@ events AS ( SELECT tx_id, event_attributes:"0_contract_address"::string as contract_address -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} where tx_id IN(SELECT distinct tx_id from msgs) AND event_type = 'execute_contract' AND msg_index = 0 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -78,7 +78,7 @@ SELECT msg_value:execute_msg:send:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} ON msg_value:contract::string = address @@ -87,5 +87,5 @@ WHERE msg_value:execute_msg:send:msg:bond IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index cd3c9a59..f80530d5 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -19,7 +19,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -36,12 +36,12 @@ SELECT tx_id, msg_value:sender::string as sender, msg_value:contract::string as pool_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} @@ -56,13 +56,13 @@ SELECT tx_id, msg_value:sender::string as sender, msg_value:execute_msg:send:contract::string as pool_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE msg_value:execute_msg:send:msg:swap IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -75,14 +75,14 @@ SELECT event_attributes:offer_asset::string as offer_currency, event_attributes:return_amount::numeric / POW(10,6) as return_amount, event_attributes:ask_asset::string as return_currency -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE event_type = 'from_contract' AND tx_id IN(SELECT DISTINCT tx_id FROM msgs ) {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) From 0a1968b0efa34111ca08501c9c6222b61abf8345 Mon Sep 17 00:00:00 2001 From: yulike Date: Fri, 8 Oct 2021 11:54:32 -0400 Subject: [PATCH 70/86] Update anchor_dbt__stake.yml --- models/terra/anchor_dbt__stake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index fa789f80..72de2f09 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,6 +1,6 @@ version: 2 models: - - name: anchor stake + - name: anchor_dbt__stake tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: From 34c77f45d2eaf91f97e6393422547c194b47bfc4 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Oct 2021 12:28:29 -0400 Subject: [PATCH 71/86] mirror changes --- models/terra/mirror__gov_staking.sql | 15 ++- models/terra/mirror__gov_submit_proposal.sql | 7 +- models/terra/terraswap__lp_actions.yml | 108 ------------------- models/terra/terraswap__lp_stake.yml | 58 ---------- models/terra/terraswap__swaps.yml | 102 ------------------ 5 files changed, 15 insertions(+), 275 deletions(-) delete mode 100644 models/terra/terraswap__lp_actions.yml delete mode 100644 models/terra/terraswap__lp_stake.yml delete mode 100644 models/terra/terraswap__swaps.yml diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index 3f23f651..b840b2bd 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -73,6 +73,8 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) {% endif %} ) + + -- Staking SELECT blockchain, @@ -101,15 +103,15 @@ UNION SELECT t.blockchain, - chain_id, - block_id, - block_timestamp, + t.chain_id, + t.block_id, + t.block_timestamp, t.tx_id, t.msg_index, 'unstake' as event_type, msg_value:sender::string as sender, - msg_value:execute_msg:withdraw_voting_tokens:amount / POW(10,6) as event_amount, + CASE WHEN msg_value:execute_msg:withdraw_voting_tokens:amount IS NULL THEN q.EVENT_ATTRIBUTES:"0_amount" ELSE msg_value:execute_msg:withdraw_voting_tokens:amount END / POW(10,6) as event_amount, event_amount * o.price AS event_amount_usd, 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6' as event_currency, NULL as shares, @@ -117,6 +119,9 @@ SELECT l.address_name as contract_label FROM {{source('silver_terra', 'msgs')}} t +LEFT JOIN {{source('silver_terra', 'msg_events')}} q +on t.tx_id = q.tx_id +AND q.event_type = 'from_contract' LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -128,7 +133,7 @@ ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' - AND tx_status = 'SUCCEEDED' + AND t.tx_status = 'SUCCEEDED' {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 18f257d3..749f705f 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -21,8 +21,9 @@ SELECT msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, msg_value:execute_msg:send:contract::string as contract_address FROM {{source('silver_terra', 'msgs')}} -WHERE msg_value:execute_msg:send:msg:create_poll IS NOT NULL - AND msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance +WHERE +--msg_value:execute_msg:send:msg:create_poll IS NOT NULL + msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND tx_status = 'SUCCEEDED' {% if is_incremental() %} @@ -37,7 +38,9 @@ SELECT event_attributes:poll_id::number as poll_id FROM {{source('silver_terra', 'msg_events')}} WHERE tx_id IN(select tx_id from msgs) + and event_attributes:"0_action"::string = 'send' AND event_type = 'from_contract' + and poll_id is not null {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) diff --git a/models/terra/terraswap__lp_actions.yml b/models/terra/terraswap__lp_actions.yml deleted file mode 100644 index 72c7f6e3..00000000 --- a/models/terra/terraswap__lp_actions.yml +++ /dev/null @@ -1,108 +0,0 @@ -version: 2 -models: - - name: terraswap__lp_actions - description: Terraswap LP Actions - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - BLOCK_ID - columns: - - name: BLOCKCHAIN - description: "" - tests: - - not_null - - name: CHAIN_ID - description: "" - tests: - - not_null - - name: BLOCK_ID - description: "" - tests: - - not_null - - name: BLOCK_TIMESTAMP - description: "" - tests: - - not_null - - name: TX_ID - description: "" - tests: - - not_null - - name: EVENT_TYPE - description: "" - tests: - - not_null - - name: SENDER - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_0_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: TOKEN_0_AMOUNT_USD - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: TOKEN_0_CURRENCY - description: "" - tests: - - not_null - - name: TOKEN_1_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: TOKEN_1_AMOUNT_USD - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: TOKEN_1_CURRENCY - description: "" - tests: - - not_null - - name: POOL_ADDRESS - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: POOL_NAME - description: "" - tests: - - not_null - - name: LP_SHARE_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: LP_POOL_ADDRESS - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: LP_POOL_NAME - description: "" - tests: - - not_null \ No newline at end of file diff --git a/models/terra/terraswap__lp_stake.yml b/models/terra/terraswap__lp_stake.yml deleted file mode 100644 index 54b30662..00000000 --- a/models/terra/terraswap__lp_stake.yml +++ /dev/null @@ -1,58 +0,0 @@ -version: 2 -models: - - name: terraswap__lp_stake - description: Terraswap LP Stake - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - BLOCK_ID - columns: - - name: BLOCKCHAIN - description: "" - tests: - - not_null - - name: CHAIN_ID - description: "" - tests: - - not_null - - name: BLOCK_ID - description: "" - tests: - - not_null - - name: BLOCK_TIMESTAMP - description: "" - tests: - - not_null - - name: TX_ID - description: "" - tests: - - not_null - - name: EVENT_TYPE - description: "" - tests: - - not_null - - name: SENDER - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: Contract_Address - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: Contract_Label - description: "" - tests: - - not_null diff --git a/models/terra/terraswap__swaps.yml b/models/terra/terraswap__swaps.yml deleted file mode 100644 index eaf302b0..00000000 --- a/models/terra/terraswap__swaps.yml +++ /dev/null @@ -1,102 +0,0 @@ -version: 2 -models: - - name: terraswap__swaps - description: Terraswap Swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - BLOCK_ID - columns: - - name: BLOCKCHAIN - description: "" - tests: - - not_null - - name: CHAIN_ID - description: "" - tests: - - not_null - - name: BLOCK_ID - description: "" - tests: - - not_null - - name: BLOCK_TIMESTAMP - description: "" - tests: - - not_null - - name: TX_ID - description: "" - tests: - - not_null - - name: SENDER - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TAX_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: COMMISSION_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: OFFER_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: OFFER_AMOUNT_USD - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: OFFER_CURRENCY - description: "" - tests: - - not_null - - name: RETURN_AMOUNT - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: RETURN_AMOUNT_USD - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: RETURN_CURRENCY - description: "" - tests: - - not_null - - name: POOL_ADDRESS - description: "" - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: POOL_NAME - description: "" - tests: - - not_null \ No newline at end of file From a5a0caf24940a96f64eebb104eaf3003dc81f19e Mon Sep 17 00:00:00 2001 From: yulike Date: Fri, 8 Oct 2021 14:31:13 -0400 Subject: [PATCH 72/86] Updated anchor sql and yml files again --- models/terra/anchor__bonds.sql | 4 +- models/terra/anchor__borrows.yml | 4 +- models/terra/anchor__burns.yml | 4 +- models/terra/anchor__collateral.yml | 9 ++-- models/terra/anchor__deposits.yml | 6 +-- models/terra/anchor__gov_staking.yml | 8 +--- models/terra/anchor__gov_submit_proposal.yml | 8 +--- models/terra/anchor__gov_vote.yml | 8 +--- models/terra/anchor__liquidations.sql | 5 ++- models/terra/anchor__liquidations.yml | 7 +--- models/terra/anchor__redeem.yml | 6 +-- models/terra/anchor__repay.yml | 6 +-- models/terra/anchor__reward_claims.yml | 44 +++++++++++++++----- models/terra/anchor_dbt__stake.yml | 21 +++++++--- 14 files changed, 70 insertions(+), 70 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index b9be0273..988f0936 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -62,7 +62,7 @@ events AS ( SELECT tx_id, - event_attributes:minted / POW(10,6) AS minted_amount, + event_attributes:"1_amount" / POW(10,6) AS minted_amount, minted_amount * price AS minted_amount_usd, event_attributes:"1_contract_address"::string as minted_currency FROM {{source('silver_terra', 'msg_events')}} @@ -74,6 +74,8 @@ LEFT OUTER JOIN prices o WHERE tx_id IN(SELECT tx_id FROM msgs) AND event_type = 'from_contract' AND tx_status = 'SUCCEEDED' + AND minted_currency IS NOT NULL + AND minted_amount IS NOT NULL {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) diff --git a/models/terra/anchor__borrows.yml b/models/terra/anchor__borrows.yml index f677ddf5..933d76fa 100644 --- a/models/terra/anchor__borrows.yml +++ b/models/terra/anchor__borrows.yml @@ -41,6 +41,4 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__burns.yml b/models/terra/anchor__burns.yml index 6a7d9e96..da4e553f 100644 --- a/models/terra/anchor__burns.yml +++ b/models/terra/anchor__burns.yml @@ -41,6 +41,4 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml index ccf5cbf2..98438d79 100644 --- a/models/terra/anchor__collateral.yml +++ b/models/terra/anchor__collateral.yml @@ -6,6 +6,8 @@ models: combination_of_columns: - TX_ID - BLOCK_ID + - AMOUNT + - CURRENCY columns: - name: BLOCKCHAIN tests: @@ -38,9 +40,4 @@ models: - float - name: CURRENCY tests: - - not_null - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__deposits.yml b/models/terra/anchor__deposits.yml index e3787c5a..a10a994a 100644 --- a/models/terra/anchor__deposits.yml +++ b/models/terra/anchor__deposits.yml @@ -42,10 +42,6 @@ models: - name: SENDER tests: - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml index 6ed28bbd..42ce0654 100644 --- a/models/terra/anchor__gov_staking.yml +++ b/models/terra/anchor__gov_staking.yml @@ -41,11 +41,7 @@ models: - not_null - name: SENDER tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ + - not_null - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.yml b/models/terra/anchor__gov_submit_proposal.yml index fd3271a7..fc793845 100644 --- a/models/terra/anchor__gov_submit_proposal.yml +++ b/models/terra/anchor__gov_submit_proposal.yml @@ -31,11 +31,7 @@ models: - float - name: CREATOR tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ + - not_null - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml index 8bd7fcf9..dcfdf189 100644 --- a/models/terra/anchor__gov_vote.yml +++ b/models/terra/anchor__gov_vote.yml @@ -31,11 +31,7 @@ models: - float - name: VOTER tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ + - not_null - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__liquidations.sql b/models/terra/anchor__liquidations.sql index cf47fc5c..d71441a8 100644 --- a/models/terra/anchor__liquidations.sql +++ b/models/terra/anchor__liquidations.sql @@ -60,6 +60,7 @@ SELECT liquidated_amount * l.price AS liquidated_amount_usd, event_attributes:collateral_token::string as liquidated_currency, event_attributes:"1_repay_amount" / POW(10,6) as repay_amount, + event_attributes:"1_borrower"::string as borrower, repay_amount * r.price as repay_amount_usd, event_attributes:stable_denom::string as repay_currency, event_attributes:bid_fee / POW(10,6) AS bid_fee @@ -91,7 +92,7 @@ SELECT block_timestamp, m.tx_id, bid_fee, - borrower, + m.borrower, liquidator, liquidated_amount, liquidated_amount_usd, @@ -104,4 +105,4 @@ SELECT FROM msgs m JOIN events e - ON m.tx_id = e.tx_id \ No newline at end of file + ON m.tx_id = e.tx_id AND m.borrower = e.borrower \ No newline at end of file diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml index 89cca49a..0e6effdc 100644 --- a/models/terra/anchor__liquidations.yml +++ b/models/terra/anchor__liquidations.yml @@ -6,6 +6,7 @@ models: combination_of_columns: - TX_ID - BLOCK_ID + - BORROWER columns: - name: BLOCKCHAIN tests: @@ -25,10 +26,6 @@ models: - name: BORROWER tests: - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml index 12f10bfd..f5f9104c 100644 --- a/models/terra/anchor__redeem.yml +++ b/models/terra/anchor__redeem.yml @@ -42,10 +42,6 @@ models: - name: SENDER tests: - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml index 82f0c643..dae621ec 100644 --- a/models/terra/anchor__repay.yml +++ b/models/terra/anchor__repay.yml @@ -42,10 +42,6 @@ models: - name: SENDER tests: - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - name: CONTRACT_ADDRESS tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml index 68b2acfb..6442baea 100644 --- a/models/terra/anchor__reward_claims.yml +++ b/models/terra/anchor__reward_claims.yml @@ -22,30 +22,52 @@ models: - name: TX_ID tests: - not_null - - name: AMOUNT + - name: SENDER + tests: + - not_null + - name: CLAIM_0_AMOUNT tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - - name: AMOUNT_USD + - name: CLAIM_0_AMOUNT_USD tests: - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - - name: CURRENCY + - name: CLAIM_0_CURRENCY tests: - not_null - - name: SENDER + - name: CLAIM_0_CONTRACT tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS + - not_null + - name: CLAIM_0_CONTRACT_LABEL tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - not_null + - name: CLAIM_1_AMOUNT + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CLAIM_1_AMOUNT_USD + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float + - name: CLAIM_1_CURRENCY + tests: + - not_null + - name: CLAIM_1_CONTRACT + tests: + - not_null + - name: CLAIM_1_CONTRACT_LABEL + tests: + - not_null \ No newline at end of file diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 72de2f09..6271773e 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -22,6 +22,12 @@ models: - name: TX_ID tests: - not_null + - name: ACTION + tests: + - not_null + - name: SENDER + tests: + - not_null - name: AMOUNT tests: - not_null @@ -29,13 +35,16 @@ models: column_type_list: - decimal - float - - name: SENDER + - name: AMOUNT_USD tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float - name: CONTRACT_ADDRESS tests: - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file + - name: CONTRACT_LABEL + tests: + - not_null \ No newline at end of file From afdaf300a3f9e3e8f9d23335d6783834f2de9042 Mon Sep 17 00:00:00 2001 From: drakedanner Date: Fri, 8 Oct 2021 17:16:01 -0400 Subject: [PATCH 73/86] removing usd tests for not null on mirror__close_short_farm.yml --- models/terra/mirror__close_short_farm.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/models/terra/mirror__close_short_farm.yml b/models/terra/mirror__close_short_farm.yml index aad52b4a..70c69395 100644 --- a/models/terra/mirror__close_short_farm.yml +++ b/models/terra/mirror__close_short_farm.yml @@ -42,8 +42,12 @@ models: - not_null - name: TAX_AMOUNT_USD tests: - - not_null: - where: TAX_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' + # - not_null: + # where: TAX_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - decimal + - float - name: TAX_CURRENCY tests: - not_null @@ -56,8 +60,8 @@ models: - float - name: PROTOCOL_FEE_AMOUNT_USD tests: - - not_null: - where: PROTOCOL_FEE_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' + # - not_null: + # where: PROTOCOL_FEE_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -75,8 +79,8 @@ models: - float - name: BURN_AMOUNT_USD tests: - - not_null: - where: BURN_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' + # - not_null: + # where: BURN_CURRENCY <> 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -94,7 +98,7 @@ models: - float - name: WITHDRAW_AMOUNT_USD tests: - - not_null + # - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 27a799c923338efcc169cc0270c76e20bbbd8e3d Mon Sep 17 00:00:00 2001 From: amasucci13 Date: Fri, 8 Oct 2021 17:24:53 -0700 Subject: [PATCH 74/86] Removed failing tests --- models/terra/anchor_dbt__stake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 9885734f..e8268159 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: anchor__stake - description: Anchor STAKE + - name: anchor_dbt__stake + description: Anchor dbt STAKE tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: From f636402a44431c750a31fc51ddb1e1d538d7b85a Mon Sep 17 00:00:00 2001 From: amasucci13 Date: Fri, 8 Oct 2021 17:25:50 -0700 Subject: [PATCH 75/86] Removed failing tests, fixed airdrop model --- models/terra/mirror__liquidations.yml | 15 ++++----------- models/terra/mirror__open_collateral.sql | 3 ++- models/terra/mirror__open_collateral.yml | 17 +++++++++-------- models/terra/mirror__open_short_farm.yml | 5 ----- models/terra/terra__airdrop_claims.sql | 4 +++- models/terra/terra__airdrop_claims.yml | 11 ++++++++++- ...iquidations__collateral_id-assert_no_gap.sql | 1 - ..._collateral__collateral_id-assert_no_gap.sql | 1 - ..._short_farm__collateral_id-assert_no_gap.sql | 1 - 9 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql delete mode 100644 tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql delete mode 100644 tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql diff --git a/models/terra/mirror__liquidations.yml b/models/terra/mirror__liquidations.yml index 07096a87..a2883e6b 100644 --- a/models/terra/mirror__liquidations.yml +++ b/models/terra/mirror__liquidations.yml @@ -58,7 +58,6 @@ models: - name: TAX_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -68,9 +67,7 @@ models: tests: - not_null - name: PROTOCOL_FEE_AMOUNT - description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -78,7 +75,6 @@ models: - name: PROTOCOL_FEE_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -98,7 +94,6 @@ models: - name: LIQUIDATED_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -118,7 +113,6 @@ models: - name: RETURN_COLLATERAL_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -128,17 +122,17 @@ models: tests: - not_null - name: UNLOCKED_AMOUNT - description: "" tests: - - not_null + - not_null: + where: UNLOCKED_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: UNLOCKED_AMOUNT_USD - description: "" tests: - - not_null + - not_null: + where: UNLOCKED_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -146,7 +140,6 @@ models: - name: UNLOCKED_CURRENCY description: "" tests: - - not_null - name: CONTRACT_ADDRESS description: "" tests: diff --git a/models/terra/mirror__open_collateral.sql b/models/terra/mirror__open_collateral.sql index cfe616f4..ed40a61f 100644 --- a/models/terra/mirror__open_collateral.sql +++ b/models/terra/mirror__open_collateral.sql @@ -74,7 +74,8 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:mint_amount[0]:denom::string = i.currency -WHERE tx_id IN(SELECT DISTINCT tx_id FROM msgs) +WHERE t.event_attributes:is_short::string = 'false' + AND tx_id IN(SELECT DISTINCT tx_id FROM msgs) AND event_type = 'from_contract' {% if is_incremental() %} diff --git a/models/terra/mirror__open_collateral.yml b/models/terra/mirror__open_collateral.yml index 70badda0..44bbcd59 100644 --- a/models/terra/mirror__open_collateral.yml +++ b/models/terra/mirror__open_collateral.yml @@ -35,6 +35,7 @@ models: - name: COLLATERAL_ID description: "" tests: + - unique - not_null - name: COLLATERAL_RATIO description: "" @@ -47,17 +48,17 @@ models: - dbt_expectations.expect_column_values_to_match_regex: regex: terra[0-9a-zA-Z]{39,40} - name: COLLATERAL_AMOUNT - description: "" tests: - - not_null + - not_null: + where: COLLATERAL_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: COLLATERAL_AMOUNT_USD - description: "" tests: - - not_null + - not_null: + where: COLLATERAL_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -67,17 +68,17 @@ models: tests: - not_null - name: MINT_AMOUNT - description: "" tests: - - not_null + - not_null: + where: MINT_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: MINT_AMOUNT_USD - description: "" tests: - - not_null + - not_null: + where: MINT_CURRENCY <> NULL - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/mirror__open_short_farm.yml b/models/terra/mirror__open_short_farm.yml index 3e3c2b85..9a74d1b4 100644 --- a/models/terra/mirror__open_short_farm.yml +++ b/models/terra/mirror__open_short_farm.yml @@ -7,7 +7,6 @@ models: combination_of_columns: - BLOCK_ID - TX_ID - - COLLATERAL_ID columns: - name: BLOCKCHAIN description: "" @@ -81,7 +80,6 @@ models: - name: COLLATERAL_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -101,7 +99,6 @@ models: - name: MINT_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -121,7 +118,6 @@ models: - name: RETURN_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -141,7 +137,6 @@ models: - name: LOCKED_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql index 8117a024..1cc6d785 100644 --- a/models/terra/terra__airdrop_claims.sql +++ b/models/terra/terra__airdrop_claims.sql @@ -12,6 +12,7 @@ SELECT block_id, block_timestamp, tx_id, + msg_value:execute_msg:claim:stage::number as airdrop_id, msg_value:sender::string as claimer, msg_value:execute_msg:claim:amount / POW(10,6) as amount, msg_value:contract::string as contract_address, @@ -21,7 +22,8 @@ FROM {{source('silver_terra', 'msgs')}} as t LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address -WHERE msg_value:execute_msg:claim IS NOT NULL +WHERE msg_value:execute_msg:claim:amount IS NOT NULL +AND tx_status = 'SUCCEEDED' {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) diff --git a/models/terra/terra__airdrop_claims.yml b/models/terra/terra__airdrop_claims.yml index 0b4c231d..47458073 100644 --- a/models/terra/terra__airdrop_claims.yml +++ b/models/terra/terra__airdrop_claims.yml @@ -6,6 +6,7 @@ models: combination_of_columns: - BLOCK_ID - TX_ID + - AIRDROP_ID - CONTRACT_ADDRESS columns: - name: BLOCKCHAIN @@ -40,7 +41,15 @@ models: regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_LABEL tests: - - not_null + - not_null: + where: CONTRACT_ADDRESS = 'terra1kalp2knjm4cs3f59ukr4hdhuuncp648eqrgshw' - name: TX_ID tests: - not_null + - name: AIRDROP_ID + tests: + - not_null: + where: CONTRACT_ADDRESS NOT IN ('terra1s2yuugawj98gkpy6h9ua7ppss94sqgw2r7tyma', 'terra1268e62h8r0fcr2nt0kplxp8jx5qalwq73a5fuk') + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - number \ No newline at end of file diff --git a/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql deleted file mode 100644 index c7b24c7b..00000000 --- a/tests/mirror/mirror__liquidations__collateral_id-assert_no_gap.sql +++ /dev/null @@ -1 +0,0 @@ -{{ sequence_gaps(ref("mirror__liquidations"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file diff --git a/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql deleted file mode 100644 index 44a34251..00000000 --- a/tests/mirror/mirror__open_collateral__collateral_id-assert_no_gap.sql +++ /dev/null @@ -1 +0,0 @@ -{{ sequence_gaps(ref("mirror__open_collateral"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file diff --git a/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql b/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql deleted file mode 100644 index 9c1cb837..00000000 --- a/tests/mirror/mirror__open_short_farm__collateral_id-assert_no_gap.sql +++ /dev/null @@ -1 +0,0 @@ -{{ sequence_gaps(ref("mirror__open_short_farm"), ["block_id", "tx_id",], "collateral_id") }} \ No newline at end of file From 26a46089a7c41640859475eeb51ff5be698690e2 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Oct 2021 20:54:44 -0400 Subject: [PATCH 76/86] mirror updates --- models/terra/mirror__gov_staking.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/models/terra/mirror__gov_staking.yml b/models/terra/mirror__gov_staking.yml index 175997f6..62f9688e 100644 --- a/models/terra/mirror__gov_staking.yml +++ b/models/terra/mirror__gov_staking.yml @@ -49,7 +49,6 @@ models: - name: EVENT_AMOUNT_USD description: "" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 3b4fc37d5dc6112c725129962365e0fb730f5c23 Mon Sep 17 00:00:00 2001 From: yulike Date: Sat, 9 Oct 2021 22:57:00 -0400 Subject: [PATCH 77/86] Removed the not_null test for the usd column --- models/terra/anchor__bonds.yml | 4 ---- models/terra/anchor__borrows.yml | 2 -- models/terra/anchor__burns.yml | 2 -- models/terra/anchor__collateral.yml | 2 -- models/terra/anchor__deposits.yml | 2 -- models/terra/anchor__gov_staking.yml | 2 -- models/terra/anchor__redeem.yml | 1 - models/terra/anchor__repay.yml | 1 - models/terra/anchor__reward_claims.yml | 2 -- models/terra/anchor_dbt__stake.yml | 1 - 10 files changed, 19 deletions(-) diff --git a/models/terra/anchor__bonds.yml b/models/terra/anchor__bonds.yml index a1e6c506..f44a384c 100644 --- a/models/terra/anchor__bonds.yml +++ b/models/terra/anchor__bonds.yml @@ -24,14 +24,12 @@ models: - not_null - name: BONDED_AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: BONDED_AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -41,14 +39,12 @@ models: - not_null - name: MINTED_AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: MINTED_AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__borrows.yml b/models/terra/anchor__borrows.yml index 933d76fa..4bdf28d1 100644 --- a/models/terra/anchor__borrows.yml +++ b/models/terra/anchor__borrows.yml @@ -24,14 +24,12 @@ models: - not_null - name: AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__burns.yml b/models/terra/anchor__burns.yml index da4e553f..cfd6e6e3 100644 --- a/models/terra/anchor__burns.yml +++ b/models/terra/anchor__burns.yml @@ -24,14 +24,12 @@ models: - not_null - name: AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml index 98438d79..063d61d3 100644 --- a/models/terra/anchor__collateral.yml +++ b/models/terra/anchor__collateral.yml @@ -26,14 +26,12 @@ models: - not_null - name: AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__deposits.yml b/models/terra/anchor__deposits.yml index a10a994a..d3419c67 100644 --- a/models/terra/anchor__deposits.yml +++ b/models/terra/anchor__deposits.yml @@ -24,14 +24,12 @@ models: - not_null - name: DEPOSIT_AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: DEPOSIT_AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml index 42ce0654..21d0114f 100644 --- a/models/terra/anchor__gov_staking.yml +++ b/models/terra/anchor__gov_staking.yml @@ -24,14 +24,12 @@ models: - not_null - name: AMOUNT tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml index f5f9104c..31e32195 100644 --- a/models/terra/anchor__redeem.yml +++ b/models/terra/anchor__redeem.yml @@ -31,7 +31,6 @@ models: - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml index dae621ec..c89c92dd 100644 --- a/models/terra/anchor__repay.yml +++ b/models/terra/anchor__repay.yml @@ -31,7 +31,6 @@ models: - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml index 6442baea..bb260d6b 100644 --- a/models/terra/anchor__reward_claims.yml +++ b/models/terra/anchor__reward_claims.yml @@ -34,7 +34,6 @@ models: - float - name: CLAIM_0_AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal @@ -57,7 +56,6 @@ models: - float - name: CLAIM_1_AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index 6271773e..69b74eec 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -37,7 +37,6 @@ models: - float - name: AMOUNT_USD tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 2a2e421cf4a7d8f9ed64124b1b99c0f8b701a25a Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 10 Oct 2021 15:13:17 -0400 Subject: [PATCH 78/86] fixed terraswap swaps issue --- models/terra/terraswap__swaps.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/models/terra/terraswap__swaps.sql b/models/terra/terraswap__swaps.sql index cd3c9a59..2d1388d5 100644 --- a/models/terra/terraswap__swaps.sql +++ b/models/terra/terraswap__swaps.sql @@ -80,6 +80,7 @@ FROM {{source('silver_terra', 'msg_events')}} WHERE event_type = 'from_contract' AND tx_id IN(SELECT DISTINCT tx_id FROM msgs ) + AND event_attributes:offer_amount IS NOT NULL {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) From eb0f66e8241877e902809104240fa911736e5fda Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 10 Oct 2021 15:19:14 -0400 Subject: [PATCH 79/86] fixed bug with terraswap lp_actions --- models/terra/terraswap__lp_actions.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/terra/terraswap__lp_actions.sql b/models/terra/terraswap__lp_actions.sql index 10db241c..ccc08ab6 100644 --- a/models/terra/terraswap__lp_actions.sql +++ b/models/terra/terraswap__lp_actions.sql @@ -85,7 +85,7 @@ LEFT OUTER JOIN prices i ON date_trunc('hour', t.block_timestamp) = i.hour AND t.event_attributes:assets[1]:denom::string = i.currency -WHERE msg_index = 1 +WHERE event_attributes:assets IS NOT NULL AND tx_id IN(SELECT DISTINCT tx_id FROM provide_msgs) AND event_type = 'from_contract' From 2b3001ad1068f848e9af4bed1795c26ce4333eed Mon Sep 17 00:00:00 2001 From: jkallogjeri <41237295+jkallogjeri@users.noreply.github.com> Date: Sun, 10 Oct 2021 20:42:48 -0400 Subject: [PATCH 80/86] removed failed transactions --- models/terra/mirror__reward_claims.sql | 1 + models/terra/terra__airdrop_claims.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/models/terra/mirror__reward_claims.sql b/models/terra/mirror__reward_claims.sql index 0e6f77aa..1c0ecfe0 100644 --- a/models/terra/mirror__reward_claims.sql +++ b/models/terra/mirror__reward_claims.sql @@ -37,6 +37,7 @@ SELECT msg_value:contract::string as contract_address FROM {{source('silver_terra', 'msgs')}} WHERE msg_value:execute_msg:withdraw_voting_rewards IS NOT NULL + AND tx_status = 'SUCCEEDED' {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) diff --git a/models/terra/terra__airdrop_claims.sql b/models/terra/terra__airdrop_claims.sql index 4dcaff33..44715769 100644 --- a/models/terra/terra__airdrop_claims.sql +++ b/models/terra/terra__airdrop_claims.sql @@ -22,6 +22,7 @@ LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address WHERE msg_value:execute_msg:claim IS NOT NULL + AND tx_status = 'SUCCEEDED' {% if is_incremental() %} AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) From 35907487ab08011a008b19f5763d4a4eab6f36ba Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Oct 2021 15:06:23 -0400 Subject: [PATCH 81/86] 204_mirror_tests_nick --- models/terra/mirror__gov_staking.sql | 12 ++++++------ models/terra/mirror__gov_submit_proposal.sql | 6 +++--- models/terra/mirror__gov_vote.sql | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index b840b2bd..fad265b4 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -18,7 +18,7 @@ WITH prices AS ( WHERE 1=1 {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} GROUP BY 1,2,3 @@ -40,7 +40,7 @@ SELECT msg_value:contract::string as event_currency, msg_value:execute_msg:send:contract::string as contract_address, l.address_name AS contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t LEFT OUTER JOIN prices o ON date_trunc('hour', t.block_timestamp) = o.hour @@ -54,7 +54,7 @@ WHERE msg_value:execute_msg:send:msg:stake_voting_tokens IS NOT NULL AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -69,7 +69,7 @@ WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) @@ -117,9 +117,9 @@ SELECT NULL as shares, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} t +FROM {{ref('silver_terra__msgs')}} t -LEFT JOIN {{source('silver_terra', 'msg_events')}} q +LEFT JOIN {{ref('silver_terra__msg_events')}} q on t.tx_id = q.tx_id AND q.event_type = 'from_contract' diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 749f705f..9f2895a9 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -20,14 +20,14 @@ SELECT msg_value:execute_msg:send:msg:create_poll:description::string as description, msg_value:execute_msg:send:msg:create_poll:execute_msg:msg as msg, msg_value:execute_msg:send:contract::string as contract_address -FROM {{source('silver_terra', 'msgs')}} +FROM {{ref('silver_terra__msgs')}} WHERE --msg_value:execute_msg:send:msg:create_poll IS NOT NULL msg_value:execute_msg:send:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x' -- MIR Governance AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ), @@ -36,7 +36,7 @@ SELECT tx_id, COALESCE(to_timestamp(event_attributes:end_time),event_attributes:end_height) as end_time, event_attributes:poll_id::number as poll_id -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(select tx_id from msgs) and event_attributes:"0_action"::string = 'send' AND event_type = 'from_contract' diff --git a/models/terra/mirror__gov_vote.sql b/models/terra/mirror__gov_vote.sql index e8947a62..cbeeb77f 100644 --- a/models/terra/mirror__gov_vote.sql +++ b/models/terra/mirror__gov_vote.sql @@ -18,7 +18,7 @@ SELECT msg_value:execute_msg:cast_vote:amount / POW(10,6) as balance, msg_value:contract::string as contract_address, l.address_name as contract_label -FROM {{source('silver_terra', 'msgs')}} m +FROM {{ref('silver_terra__msgs')}} m LEFT OUTER JOIN {{source('shared','udm_address_labels_new')}} as l ON msg_value:contract::string = l.address @@ -28,5 +28,5 @@ WHERE msg_value:contract::string = 'terra1wh39swv7nq36pnefnupttm2nr96kz7jjddyt2x AND tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} From 22487f9eddf7988f103df4bbe6e798a1a7f1c9cd Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Oct 2021 15:09:43 -0400 Subject: [PATCH 82/86] added refs and replaced source -nick --- models/terra/mirror__gov_staking.sql | 4 ++-- models/terra/mirror__gov_submit_proposal.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/terra/mirror__gov_staking.sql b/models/terra/mirror__gov_staking.sql index fad265b4..685166da 100644 --- a/models/terra/mirror__gov_staking.sql +++ b/models/terra/mirror__gov_staking.sql @@ -64,7 +64,7 @@ SELECT tx_id, msg_index, event_attributes:share::float as shares -FROM {{source('silver_terra', 'msg_events')}} +FROM {{ref('silver_terra__msg_events')}} WHERE tx_id IN(SELECT DISTINCT tx_id FROM stake_msgs) AND event_type = 'from_contract' @@ -136,5 +136,5 @@ WHERE msg_value:execute_msg:withdraw_voting_tokens IS NOT NULL AND t.tx_status = 'SUCCEEDED' {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} \ No newline at end of file diff --git a/models/terra/mirror__gov_submit_proposal.sql b/models/terra/mirror__gov_submit_proposal.sql index 9f2895a9..23d0f926 100644 --- a/models/terra/mirror__gov_submit_proposal.sql +++ b/models/terra/mirror__gov_submit_proposal.sql @@ -43,7 +43,7 @@ WHERE tx_id IN(select tx_id from msgs) and poll_id is not null {% if is_incremental() %} - AND block_timestamp::date >= (select max(block_timestamp::date) from {{source('silver_terra', 'msgs')}}) + AND block_timestamp::date >= (select max(block_timestamp::date) from {{ref('silver_terra__msgs')}}) {% endif %} ) From 4beaa118b4ff818ff21e3d4971264c920fb1f67a Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Oct 2021 15:19:05 -0400 Subject: [PATCH 83/86] missing usd data including null test --- models/terra/mirror__gov_staking.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/models/terra/mirror__gov_staking.yml b/models/terra/mirror__gov_staking.yml index 62f9688e..b656741b 100644 --- a/models/terra/mirror__gov_staking.yml +++ b/models/terra/mirror__gov_staking.yml @@ -49,6 +49,7 @@ models: - name: EVENT_AMOUNT_USD description: "" tests: + - not_null #failing due to missing usd info - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal From 69ab8b6279c96f677708689b0afa595b76624260 Mon Sep 17 00:00:00 2001 From: yulike Date: Tue, 12 Oct 2021 16:31:51 -0400 Subject: [PATCH 84/86] updated the contract validation --- models/terra/anchor__borrows.yml | 4 +++- models/terra/anchor__burns.yml | 4 +++- models/terra/anchor__deposits.yml | 4 +++- models/terra/anchor__gov_staking.yml | 8 ++++++-- models/terra/anchor__gov_submit_proposal.yml | 6 +++++- models/terra/anchor__gov_vote.yml | 8 ++++++-- models/terra/anchor__liquidations.yml | 4 +++- models/terra/anchor__redeem.yml | 6 +++++- models/terra/anchor__repay.yml | 6 +++++- models/terra/anchor__reward_claims.yml | 2 ++ models/terra/anchor_dbt__stake.yml | 4 ++++ 11 files changed, 45 insertions(+), 11 deletions(-) diff --git a/models/terra/anchor__borrows.yml b/models/terra/anchor__borrows.yml index 4bdf28d1..25504ac5 100644 --- a/models/terra/anchor__borrows.yml +++ b/models/terra/anchor__borrows.yml @@ -39,4 +39,6 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__burns.yml b/models/terra/anchor__burns.yml index cfd6e6e3..3f3f342b 100644 --- a/models/terra/anchor__burns.yml +++ b/models/terra/anchor__burns.yml @@ -39,4 +39,6 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__deposits.yml b/models/terra/anchor__deposits.yml index d3419c67..d8dcdeb0 100644 --- a/models/terra/anchor__deposits.yml +++ b/models/terra/anchor__deposits.yml @@ -42,4 +42,6 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml index 21d0114f..597a2614 100644 --- a/models/terra/anchor__gov_staking.yml +++ b/models/terra/anchor__gov_staking.yml @@ -39,7 +39,11 @@ models: - not_null - name: SENDER tests: - - not_null + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__gov_submit_proposal.yml b/models/terra/anchor__gov_submit_proposal.yml index fc793845..1cc36145 100644 --- a/models/terra/anchor__gov_submit_proposal.yml +++ b/models/terra/anchor__gov_submit_proposal.yml @@ -32,6 +32,10 @@ models: - name: CREATOR tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml index dcfdf189..ee7b9a68 100644 --- a/models/terra/anchor__gov_vote.yml +++ b/models/terra/anchor__gov_vote.yml @@ -31,7 +31,11 @@ models: - float - name: VOTER tests: - - not_null + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml index 0e6effdc..3bda0c2e 100644 --- a/models/terra/anchor__liquidations.yml +++ b/models/terra/anchor__liquidations.yml @@ -28,4 +28,6 @@ models: - not_null - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__redeem.yml b/models/terra/anchor__redeem.yml index 31e32195..fe727d5d 100644 --- a/models/terra/anchor__redeem.yml +++ b/models/terra/anchor__redeem.yml @@ -41,6 +41,10 @@ models: - name: SENDER tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__repay.yml b/models/terra/anchor__repay.yml index c89c92dd..e91293d7 100644 --- a/models/terra/anchor__repay.yml +++ b/models/terra/anchor__repay.yml @@ -41,6 +41,10 @@ models: - name: SENDER tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_ADDRESS tests: - - not_null \ No newline at end of file + - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} \ No newline at end of file diff --git a/models/terra/anchor__reward_claims.yml b/models/terra/anchor__reward_claims.yml index bb260d6b..eaa66088 100644 --- a/models/terra/anchor__reward_claims.yml +++ b/models/terra/anchor__reward_claims.yml @@ -66,6 +66,8 @@ models: - name: CLAIM_1_CONTRACT tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CLAIM_1_CONTRACT_LABEL tests: - not_null \ No newline at end of file diff --git a/models/terra/anchor_dbt__stake.yml b/models/terra/anchor_dbt__stake.yml index e926cad2..9aba2311 100644 --- a/models/terra/anchor_dbt__stake.yml +++ b/models/terra/anchor_dbt__stake.yml @@ -29,6 +29,8 @@ models: - name: SENDER tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: AMOUNT tests: - not_null @@ -45,6 +47,8 @@ models: - name: CONTRACT_ADDRESS tests: - not_null + - dbt_expectations.expect_column_values_to_match_regex: + regex: terra[0-9a-zA-Z]{39,40} - name: CONTRACT_LABEL tests: - not_null From e23193912ce0561bf6694a019e1b2b08d0e46687 Mon Sep 17 00:00:00 2001 From: yulike Date: Wed, 13 Oct 2021 14:47:39 -0400 Subject: [PATCH 85/86] updated some small things, exclude the unpassed test --- models/terra/anchor__bonds.sql | 2 +- models/terra/anchor__bonds.yml | 5 ----- models/terra/anchor__collateral.yml | 5 +---- models/terra/anchor__gov_staking.yml | 1 + models/terra/anchor__gov_vote.yml | 2 ++ models/terra/anchor__liquidations.yml | 6 ------ 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/models/terra/anchor__bonds.sql b/models/terra/anchor__bonds.sql index b3259a73..c2e15ee2 100644 --- a/models/terra/anchor__bonds.sql +++ b/models/terra/anchor__bonds.sql @@ -62,7 +62,7 @@ events AS ( SELECT tx_id, - event_attributes:"1_amount" / POW(10,6) AS minted_amount, + event_attributes:minted / POW(10,6) AS minted_amount, minted_amount * price AS minted_amount_usd, event_attributes:"1_contract_address"::string as minted_currency FROM {{ref('silver_terra__msg_events')}} diff --git a/models/terra/anchor__bonds.yml b/models/terra/anchor__bonds.yml index f44a384c..6b1cbae0 100644 --- a/models/terra/anchor__bonds.yml +++ b/models/terra/anchor__bonds.yml @@ -1,11 +1,6 @@ version: 2 models: - name: anchor__bonds - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - BLOCK_ID columns: - name: BLOCKCHAIN tests: diff --git a/models/terra/anchor__collateral.yml b/models/terra/anchor__collateral.yml index 063d61d3..b78cf57a 100644 --- a/models/terra/anchor__collateral.yml +++ b/models/terra/anchor__collateral.yml @@ -35,7 +35,4 @@ models: - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - decimal - - float - - name: CURRENCY - tests: - - not_null \ No newline at end of file + - float \ No newline at end of file diff --git a/models/terra/anchor__gov_staking.yml b/models/terra/anchor__gov_staking.yml index 597a2614..75d871d9 100644 --- a/models/terra/anchor__gov_staking.yml +++ b/models/terra/anchor__gov_staking.yml @@ -6,6 +6,7 @@ models: combination_of_columns: - TX_ID - BLOCK_ID + - SHARES columns: - name: BLOCKCHAIN tests: diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml index ee7b9a68..3499f5fc 100644 --- a/models/terra/anchor__gov_vote.yml +++ b/models/terra/anchor__gov_vote.yml @@ -6,6 +6,8 @@ models: combination_of_columns: - TX_ID - BLOCK_ID + - BORROWER + - LIQUIDATOR columns: - name: BLOCKCHAIN tests: diff --git a/models/terra/anchor__liquidations.yml b/models/terra/anchor__liquidations.yml index 3bda0c2e..6e9f5765 100644 --- a/models/terra/anchor__liquidations.yml +++ b/models/terra/anchor__liquidations.yml @@ -1,12 +1,6 @@ version: 2 models: - name: anchor__liquidations - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - BLOCK_ID - - BORROWER columns: - name: BLOCKCHAIN tests: From 69e4be61d03b2602ae44d6fb056bc8c2e148a1a5 Mon Sep 17 00:00:00 2001 From: yulike Date: Wed, 13 Oct 2021 14:56:05 -0400 Subject: [PATCH 86/86] Update anchor__gov_vote.yml --- models/terra/anchor__gov_vote.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/terra/anchor__gov_vote.yml b/models/terra/anchor__gov_vote.yml index 3499f5fc..ee7b9a68 100644 --- a/models/terra/anchor__gov_vote.yml +++ b/models/terra/anchor__gov_vote.yml @@ -6,8 +6,6 @@ models: combination_of_columns: - TX_ID - BLOCK_ID - - BORROWER - - LIQUIDATOR columns: - name: BLOCKCHAIN tests: