Skip to content

Commit

Permalink
OP RPGF Migration and Grants Funding Migration (duneanalytics#4179)
Browse files Browse the repository at this point in the history
* update addrs

* add addresses

* migration to dunesql

* migration to dunesql

* migration to dunesql

* migration to dunesql

* migration to dunesql

* migration to dunesql

* update op_token_distributions_optimism_all_distributions_labels

* update op_token_distributions_optimism_all_distributions_labels

* update

* update to dunesql

* syntax

* syntax

* migration to dunesql

* migration to dunesql

* add dunesql tag

* update attestation_events

* update token_distributions

* fix missing ')' and cast

* test uint256 data type for overflow

* Revert "test uint256 data type for overflow"

This reverts commit 8d584fc.

* update logic

* extra line

* fix overflow error

* add missing bracket

* update logic

* update from week to day

* update from week to day

---------

Co-authored-by: jeff <[email protected]>
Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 032a1b7 commit 7f1d6d4
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 274 deletions.
87 changes: 86 additions & 1 deletion models/addresses/optimism/addresses_optimism_grants_funding.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
post_hook='{{ expose_spells(\'["optimism"]\',
"sector",
"addresses",
\'["msilb7"]\') }}')}}
\'["msilb7", "chuxin"]\') }}')}}

WITH entries AS (
SELECT
Expand Down Expand Up @@ -145,6 +145,90 @@ FROM (VALUES
,('Project', 0x6268d07327f4fb7380732dc6d63d95F88c0E083b, 'ShapeShift', 'Season 3')
,('Project', 0x7fB50BBabeDEE52b8760Ba15c0c199aF33Fc2EfA, 'Threshold', 'Season 3')
,('Project', 0x76d266dfd3754f090488ae12f6bd115cd7e77ebd, 'Vesper', 'Season 3')

,('Project', 0xec1C77AC05915F099C7c56900D63823Fa4308800, 'Tally' ,'Season 4')
,('Project', 0x9D31e30003f253563Ff108BC60B16Fdf2c93abb5, 'SCRY' ,'Season 4')
,('Project', 0x6eDf76FD16Bb290A544fDc14fBB4b403D1DEeD9f, 'LimeChain' ,'Season 4')
,('Project', 0x2A5b95c0770BD74B66D7214E60ea6619FD233687, 'Dappnode' ,'Season 4')
,('Project', 0xb074ec6c37659525eef2fb44478077901f878012, 'Velodrome' ,'Season 4')
,('Project', 0xe3a9ad8a2b39ff6983f1582abd26c06afa6cce96, 'Bankless DAO' ,'Season 4')
,('Project', 0x66D071A20d7942767739BBca130E08e4848D12Bc, 'Latruite.eth' ,'Season 4')
,('Project', 0x2948A68525287fB8252032a300D50d3fd63d9C22, 'H.E.R., LatAm' ,'Season 4')
,('Project', 0x929e1b374fb07486c9a64570e5bda99383f48785, 'Solow' ,'Season 4')
,('Project', 0x1d4d44Bca3F094A64db1f5C2AAdc636B8e557772, 'Espacio Cripto' ,'Season 4')
,('Project', 0xb6d60c8D85609846D4e1a40B409Ac08ec413D27F, 'Cryptoversidad Team' ,'Season 4')
,('Project', 0x376229C26a903647B0bd0411530cbD5787AcF50d, 'Web3xplorer' ,'Season 4')
,('Project', 0x7674D60760918Ae89cA71F2ce1Af2b2E740E2c8E, 'Ethereum Mexico' ,'Season 4')
,('Project', 0x60529042d2ff2e82d5140e60dbccf8242cd114ae, 'Bankless Academy' ,'Season 4')
,('Project', 0xc8F8C7634e12C45266FC1110640BB318cdbF2373, 'Delegate Corner' ,'Season 4')
,('Project', 0xeCd54dB84c80f451b8dbC91ac31f6b7b900b61C0, 'Trusted Seed' ,'Season 4')
,('Project', 0x0B7246eF74Ca7b37Fdc3D15be4f0b49876622F95, 'Praise' ,'Season 4')
,('Project', 0xc8D65E1Bd67f16522e3117B980E1c9D2CaeB9dC3, 'Pairwise' ,'Season 4')
,('Project', 0x17296956b4e07ff8931e4ff4ea06709fab70b879, 'Governance Analytics Dashboard' ,'Season 4')
,('Project', 0x75536CF4f01c2bFa528F5c74DdC1232Db3aF3Ee5, 'Katie Garcia' ,'Season 4')
,('Project', 0xa6e8772af29b29B9202a073f8E36f447689BEef6, 'GFX (PaperImperium)' ,'Season 4')
,('Project', 0xdcf7be2ff93e1a7671724598b1526f3a33b1ec25, 'Dhannte' ,'Season 4')
,('Project', 0x6EdA5aCafF7F5964E1EcC3FD61C62570C186cA0C, 'Michael Vander Meiden, The RetroPGF Podcast, OPdelegate.com' ,'Season 4')
,('Project', 0x7302bC5b47F5588174A148C90747a88CB528A8c1, 'jackanorak.eth' ,'Season 4')
,('Project', 0x3193A6c36B342A02a119Db2C6547225D594182c8, 'Matt L' ,'Season 4')
,('Project', 0xd23199F1222C418ffC74c385171330B21B16e452, 'Sugma.eth' ,'Season 4')
,('Project', 0xeA78912803bE5E356EaC2b8e127D4BA87230A48e, 'Krzysztof Urbański' ,'Season 4')
,('Project', 0x73e3C41C2017D7f72B1c6EAdD010718C0bac59Ab, 'Dane Lund' ,'Season 4')
,('Project', 0xB25fEF9755dD6e3635FBC7770b1f6c588f379689, 'Aragon' ,'Season 4')
,('Project', 0x036C545Ae4f68059b4C83f7E3814429d4c73c089, 'Atlantis World' ,'Season 4')
,('Project', 0x07Aeeb7E544A070a2553e142828fb30c214a1F86, 'Cannon','Season 4')
,('Project', 0x5b71c4B33a871f32A402cE243195a727D1775512, 'Concrete' ,'Season 4')
,('Project', 0xd39D6d3F7433A0caBD90c0Ea74d76dA29b718314, 'DAOStar' ,'Season 4')
,('Project', 0xBAC78374F87D02d3b0d6FAf82d8794201D40b35B, 'DeSci World' ,'Season 4')
,('Project', 0xB646C68578835F44d7C5b3F44ed51174FD1A89DE, 'DPRC.ORG' ,'Season 4')
,('Project', 0xC63caBe93bB29c61E337a87B2E3d4D7C5F5556c0, 'EAS: Supercharged' ,'Season 4')
,('Project', 0x72e41a80b0a952590d2e9edc16ba9464b7b9e312, 'evm-runners' ,'Season 4')
,('Project', 0x56EdF679B0C80D528E17c5Ffe514dc9a1b254b9c, 'Hildr' ,'Season 4')
,('Project', 0xC98786D5A7a03C1e74AffCb97fF7eF8a710DA09B, 'Karma Grantee Accountability Platform' ,'Season 4')
,('Project', 0xC5BFCe27e0e7A7d7731bC23B92eBC62B9Ed63B83, 'Opensource Observer' ,'Season 4')
,('Project', 0xf238BfB8C323123439B3C811eB7223f4fa84Cc18, 'Pyth Network' ,'Season 4')
,('Project', 0xe6B210F1299a3B0D74BfA24D678A9dC1e2a27e34, 'Redstone' ,'Season 4')
,('Project', 0x3a1fE8c10796Dbb03007cFf324bc904d4aa031b8, 'simple-op-stack-rollup' ,'Season 4')
,('Project', 0x8b1f85a93Ac6E4F62695Ea8EF2410d248605FEff, 'Unruggable Names' ,'Season 4')
,('Project', 0x57ACb721FcF3d900B480A90A55191CF8F37ad478, 'Aura Finance' ,'Season 4')
,('Project', 0xbd4C65cd759D79074D5E87022Fb369b4DAC6b485, 'Debridge' ,'Season 4')
,('Project', 0xb04a484387a7242339da615a63d2d49d8968aada, 'Extra Finance' ,'Season 4')
,('Project', 0xB9228e60fb71aB886950eCbc196d0dEc58ff8e11, 'Layerswap' ,'Season 4')
,('Project', 0xE01Df4ac1E1e57266900E62C37F12C986495A618, 'Metronome' ,'Season 4')
,('Project', 0xC8a3ae7aC306Df0Ba9F0fC90406367AC6C31765b, 'OmniBTC' ,'Season 4')
,('Project', 0xEB40A065854bd90126A4E697aeA0976BA51b2eE7, 'Op Podcast NFTs' ,'Season 4')
,('Project', 0xa06C863fcf17cA6f24AA81aeA75E23953193fF6A, 'Pendle' ,'Season 4')
,('Project', 0xf40CBa950163941BEf7733F5958a00E5458325fb, 'Tide Protocol' ,'Season 4')
,('Project', 0xab4f5A7fcd1Bb66C8c5f01bB77F6142759f46107, 'WakeUp Labs' ,'Season 4')
,('Project', 0x70ad50958312814e7370A52BDa2b5DA797ab64Bc, 'Clearpool Finance' ,'Season 4')
,('Project', 0xC17A59dC5Fc0Df4853Ee71e6Dd7640e5E4954F0F, 'Clique' ,'Season 4')
,('Project', 0xFDbB4d606C199F091143BD604C85c191a526fbd0, 'Idle' ,'Season 4')
,('Project', 0x193a6a37F99D18b0F262985DBfC5E22e43cc36Be, 'Invest in Music' ,'Season 4')
,('Project', 0x7Cb4a147A54e1406AEA3C8BE623A26bdd554322B, 'Lets Get Hai' ,'Season 4')
,('Project', 0x2f593f151aF4bb9A71bcA6cAce1d3c56C2844117, 'Liquity' ,'Season 4')
,('Project', 0xEfFE6b3DBA2E39aA1085f88a93AB8563Ba45bAa6, 'Mutual' ,'Season 4')
,('Project', 0xA5d26Ce9eC851B6Ec473fac0630D5A087221Cd34, 'Octav' ,'Season 4')
,('Project', 0xD91dEf14811407aa73C47d8683755526df07C44F, 'Qubit Wallet' ,'Season 4')
,('Project', 0x9A104004ef083b0980F19Aa5D0Cfaaf2b5FFe388, 'Wombat Exchange' ,'Season 4')
,('Project', 0xabeEb05bA4764F45e5c0e8Acb02059d7164aD35d, 'Culture Blocks' ,'Season 4')
,('Project', 0x65671615f3B0b0a08FCbea7248c5f886f10003C9, 'DappyKit' ,'Season 4')
,('Project', 0xa1ED69e92025B65100779A4774410409049a1d6e, 'DeCommas' ,'Season 4')
,('Project', 0xF15722C5f90A8e104b284098254b3949d212672c, 'EUROe' ,'Season 4')
,('Project', 0x44F00C29a0b8514D017ac20fBDb0AA5078b860cE, 'GasHawk' ,'Season 4')
,('Project', 0xF7Dda96007Bcf22C6e42e90C8d94737172Fb754f, 'Grindery Delight' ,'Season 4')
,('Project', 0x700E73d289DE10b6143465E02E6931E6e6a0CA15, 'growthepie' ,'Season 4')
,('Project', 0x402118B500e37E9a948195fd55822fC393CB215F, 'Hamster' ,'Season 4')
,('Project', 0xD0DA14f46595850627bcDB19060bdFb0F4Cc5E8f, 'Launchcaster' ,'Season 4')
,('Project', 0x0FF67acA2B2fD18C7caa5fC0B0a6d2e057898afD, 'Liquid Resilience' ,'Season 4')
,('Project', 0xb66f8eb1682589F9dFa3cFC3da9FAECEfCd7E525, 'Locksmith' ,'Season 4')
,('Project', 0x0003603F7a929c304be73661C254312647a5E4BA, 'NFTScan' ,'Season 4')
,('Project', 0xdf43d4C93c600EA8dd7ba469E5A05AB57E9867c9, 'Meta Game' ,'Season 4')
,('Project', 0x51f190B6A9CC76BF76BC56C730149604731D4d29, 'OnlyDust' ,'Season 4')
,('Project', 0xF5B286151558ffEdaE80CcE3a98246EedA34FA08, 'SafeSwap' ,'Season 4')
,('Project', 0x7AAF799516404A8d69Ef3F0b55746D15613ae04e, 'Solid Grinder' ,'Season 4')
,('Project', 0x0E73F03b5B553CD295842Cb5f9A04768B6225aAc, 'Solidity Survivor' ,'Season 4')
,('Project', 0xc26E6125B3ec9255fF2b576258742d448e941635, 'Upnode' ,'Season 4')

-- Announced Partner Fund
,('Project', 0xfb0dadb835fade151abf6780beafb12fc5ba0e1f, 'PoolTogether', 'Partner Fund')
,('Project', 0x30688fcd63d0f2d067a7fe264b3367c348e9b031, 'Velodrome', 'Partner Fund')
Expand Down Expand Up @@ -173,3 +257,4 @@ SELECT
FROM entries
LEFT JOIN {{ ref('op_token_distributions_optimism_project_name_mapping') }} pnm
ON pnm.proposal_name = entries.proposal_name
GROUP BY 1, 2, 3, 4, 5 -- remove duplicates if any
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{ config(
schema = 'op_retropgf_optimism'
,tags = ['dunesql']
, alias = alias('recipients')
, post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"op_retropgf",
\'["msilb7"]\') }}'
\'["msilb7", "chuxin"]\') }}'
)
}}
{% set sources = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
schema = 'op_retropgf_optimism'
, alias = alias('round2_recipients')
, materialized='table'
, tags=['static']
, tags=['static', 'dunesql']
)
}}

Expand All @@ -13,7 +13,7 @@ with attestations as (
REGEXP_REPLACE(key, '[[:cntrl:]]', '') AS key_mapped
FROM {{ ref('optimism_attestationstation_optimism_events') }}

WHERE issuer = '0x60c5c9c98bcbd0b0f2fd89b24c16e533baa8cda3'
WHERE issuer = 0x60c5c9c98bcbd0b0f2fd89b24c16e533baa8cda3
AND REGEXP_REPLACE(key, '[[:cntrl:]]', '') IN ('retropgf.round-2.name','retropgf.round-2.award','retropgf.round-2.category')
AND block_date BETWEEN cast('2023-03-30' as date) AND cast('2023-05-01' as date)
)
Expand All @@ -23,7 +23,7 @@ SELECT
nm.block_date, nm.recipient as submitter_address, nm.issuer
, trim(nm.val_string) AS recipient_name, trim(ca.val_string) AS recipient_category
, cast( regexp_replace(aw.val_string, '[^0-9\\.]+', '') AS double ) AS award_amount
, '{{op_token}}' AS award_token
, {{op_token}} AS award_token

FROM (SELECT * FROM attestations where key_mapped = 'retropgf.round-2.name') nm
LEFT JOIN (SELECT * FROM attestations where key_mapped = 'retropgf.round-2.award') aw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
schema = 'op_retropgf_optimism'
, alias = alias('round2_voters')
, materialized='table'
, tags=['static']
, tags=['static', 'dunesql']
)
}}

Expand All @@ -12,7 +12,7 @@ with attestations as (
, REGEXP_REPLACE(key, '[[:cntrl:]]', '') AS key_mapped
FROM {{ ref('optimism_attestationstation_optimism_events') }}

WHERE issuer = '0x60c5c9c98bcbd0b0f2fd89b24c16e533baa8cda3'
WHERE issuer = 0x60c5c9c98bcbd0b0f2fd89b24c16e533baa8cda3
AND REGEXP_REPLACE(key, '[[:cntrl:]]', '') = 'retropgf.round-2.can-vote'
AND block_date BETWEEN cast('2023-02-01' as date) AND cast('2023-04-01' as date)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
schema = 'op_retropgf_optimism'
, alias = alias('voters')
, tags = ['dunesql']
, post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"op_retropgf",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ config(
alias = alias('all_distributions_labels'),
tags = ['dunesql'],
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"op_token_distributions",
Expand Down Expand Up @@ -38,4 +39,10 @@ WITH all_labels AS (
WHERE address NOT IN (SELECT address FROM {{ ref('op_token_distributions_optimism_project_wallets') }})
)

SELECT * FROM all_labels
SELECT
cast(address as varbinary) as address
,label
,proposal_name
,address_descriptor
,project_name
FROM all_labels
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ config(
alias = alias('foundation_wallet_approvals'),
tags = ['dunesql'],
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -8,7 +9,7 @@
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"op_token_distributions",
\'["msilb7"]\') }}'
\'["msilb7", "chuxin"]\') }}'
)
}}

Expand All @@ -23,26 +24,32 @@


WITH project_labels AS (
SELECT * FROM {{ ref('op_token_distributions_optimism_project_wallets') }}
SELECT
address,
project_name,
label,
address_descriptor
FROM {{ ref('op_token_distributions_optimism_project_wallets') }}
WHERE label IS NOT NULL
GROUP BY 1, 2, 3, 4
)


SELECT
DATE_TRUNC('day',evt_block_time) AS block_date,
a.evt_block_time, a.evt_block_number, a.evt_tx_hash, a.evt_index,
a.spender AS project_address, al.project_name,
CAST(DATE_TRUNC('day',evt_block_time) as date) AS block_date,
a.evt_block_time, a.evt_block_number, a.evt_tx_hash, a.evt_index,
a.spender AS project_address, al.project_name,

t.`from` AS tx_from_address, t.to AS tx_to_address,
t."from" AS tx_from_address, t.to AS tx_to_address,

cast(a.value as double)/cast(1e18 as double) AS op_approved_to_project
cast(a.value as double)/cast(1e18 as double) AS op_approved_to_project

FROM {{ source('erc20_optimism', 'evt_Approval') }} a
INNER JOIN {{ source('optimism', 'transactions') }} t
ON t.hash = a.evt_tx_hash
AND t.block_number = a.evt_block_number
{% if is_incremental() %}
AND t.block_time >= date_trunc('day', now() - interval '1 week')
AND t.block_time >= date_trunc('day', now() - interval '7' day)
{% else %}
AND t.block_time >= cast( '{{approvals_start_date}}' as date )
{% endif %}
Expand All @@ -51,10 +58,10 @@ FROM {{ source('erc20_optimism', 'evt_Approval') }} a
LEFT JOIN project_labels al
ON a.spender = al.address
WHERE
a.contract_address = '{{op_token_address}}' --OP Token
a.contract_address = {{op_token_address}} --OP Token
AND owner in (SELECT address FROM project_labels WHERE label = '{{foundation_label}}' AND address_descriptor = '{{grants_descriptor}}')
{% if is_incremental() %}
AND a.evt_block_time >= date_trunc('day', now() - interval '1 week')
AND a.evt_block_time >= date_trunc('day', now() - interval '7' day)
{% else %}
AND a.evt_block_time >= cast( '{{approvals_start_date}}' as date )
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ config(
alias = alias('other_distributions_claims'),
tags = ['dunesql'],
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -8,7 +9,7 @@
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"op_token_distributions",
\'["msilb7"]\') }}'
\'["msilb7", "chuxin"]\') }}'
)
}}

Expand All @@ -25,7 +26,7 @@ WITH all_labels AS (

, aave_lm_claims AS (
SELECT
DATE_TRUNC('day',evt_block_time) AS block_date,
CAST(DATE_TRUNC('day',evt_block_time) as date) AS block_date,
evt_block_time, evt_block_number, evt_index,
tx_to_address, tx_from_address,
evt_tx_hash, from_label, from_type, from_name,
Expand All @@ -47,7 +48,7 @@ FROM (
SELECT
DATE_TRUNC('day',r.evt_block_time) AS block_date,
r.evt_block_time, r.evt_block_number, r.evt_index,
tf.`from` AS from_address, tf.to AS to_address, tx.to AS tx_to_address, tx.`from` AS tx_from_address, r.evt_tx_hash,
tf."from" AS from_address, tf.to AS to_address, tx.to AS tx_to_address, tx."from" AS tx_from_address, r.evt_tx_hash,
'Project' as from_label, 'Parter Fund' AS from_type, 'Aave' AS from_name,
tf.to as user_address
,'Aave - Liquidity Mining' AS to_type
Expand All @@ -58,7 +59,7 @@ FROM (
'Other' AS to_name, cast(amount as double) / cast(1e18 as double) AS op_amount_decimal
--get last
, tf.evt_index AS evt_tfer_index
, substring(tx.data,1,10) AS tx_method --bytearray_substring(tx.data, 1, 4) AS tx_method
, bytearray_substring(tx.data, 1, 4) AS tx_method

,ROW_NUMBER() OVER (PARTITION BY r.evt_tx_hash, r.evt_index ORDER BY tf.evt_index DESC) AS claim_rank_desc
,ROW_NUMBER() OVER (PARTITION BY r.evt_tx_hash, r.evt_index ORDER BY tf.evt_index ASC) AS claim_rank_asc
Expand All @@ -70,12 +71,12 @@ FROM (
AND tf.contract_address = r.reward
AND value = amount
{% if is_incremental() %}
and tf.evt_block_time >= date_trunc('day', now() - interval '1 week')
and tf.evt_block_time >= date_trunc('day', now() - interval '7' day)
{% else %}
and tf.evt_block_time >= cast('{{op_token_launch_date}}' as date)
{% endif %}
left JOIN all_labels lbl_from
ON lbl_from.address = tf.`from`
ON lbl_from.address = tf."from"
-- if the recipient is in this list to, then we track it
LEFT JOIN all_labels lbl_to
ON lbl_to.address = tf.to
Expand All @@ -84,17 +85,17 @@ FROM (
AND tx.block_number = tf.evt_block_number
AND lbl_to.label IS NULL -- don't try if we have a label on the to transfer
{% if is_incremental() %}
AND tx.block_time >= date_trunc('day', now() - interval '1 week')
AND tx.block_time >= date_trunc('day', now() - interval '7' day)
{% else %}
AND tx.block_time >= cast('{{op_token_launch_date}}' as date)
{% endif %}


WHERE reward = '{{op_token_address}}' --OP Token
WHERE reward = {{op_token_address}} --OP Token
and cast(amount as double)/cast(1e18 as double) > 0
AND lbl_from.label = '{{foundation_label}}'
{% if is_incremental() %}
and r.evt_block_time >= date_trunc('day', now() - interval '1 week')
and r.evt_block_time >= date_trunc('day', now() - interval '7' day)
{% endif %}

) a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ config(
alias = alias('other_tags')
alias = alias('other_tags'),
tags = ['dunesql', 'static']
)
}}

Expand All @@ -8,7 +9,7 @@
WITH tagged_wallets AS (
SELECT distinct address, address_name
FROM (
SELECT LOWER(address) AS address, cast(address_name as varchar(250)) AS address_name
SELECT CAST(address as varbinary) AS address, cast(address_name as varchar) AS address_name
, ROW_NUMBER() OVER (PARTITION BY address ORDER BY cast(address_name as varchar(250)) ) AS rnk
FROM (values
('0x030058ac851ba6f282ec0e717a7ed577d09dff0b','Perp Foundation')
Expand Down
Loading

0 comments on commit 7f1d6d4

Please sign in to comment.