Skip to content

Commit

Permalink
feat: ✨ create karmahq_details model (#78)
Browse files Browse the repository at this point in the history
* create karmahq attestations asset

* create karmahq_details dbt model
  • Loading branch information
DistributedDoge authored Apr 15, 2024
1 parent 513b673 commit 901daca
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
16 changes: 16 additions & 0 deletions dbt/models/karmahq_details.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with source as (
select * from {{ source('public', 'raw_karmahq_attestations') }}
),

renamed as (
select
lower(attester) as attester,
lower(recipient) as recipient,
isOffchain as is_offchain,
decodedDataJson as json,
JSON_EXTRACT(decodedDataJson->>'$[0].value.value', '$.hash') as ipfs_cid,
JSON_EXTRACT(decodedDataJson->>'$[0].value.value', '$.title') as title
from source
)

select * from renamed
4 changes: 4 additions & 0 deletions dbt/models/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ sources:
meta:
dagster:
asset_key: ["raw_hypercert_claims"]
- name: raw_karmahq_attestations
meta:
dagster:
asset_key: ["raw_karmahq_attestations"]
65 changes: 55 additions & 10 deletions ggdp/assets/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dagster import Backoff, RetryPolicy, asset
from tenacity import retry, wait_exponential, stop_after_attempt

from ..resources import DuneResource, CovalentAPIResource
from ..resources import DuneResource


@asset(
Expand Down Expand Up @@ -150,16 +150,11 @@ def get_hypercerts(gql_endpoint, creator_addresses):
}
}
"""
payload = {
"query": query,
"variables": {
"creatorAddresses": creator_addresses
}
}
payload = {"query": query, "variables": {"creatorAddresses": creator_addresses}}

response = requests.post(gql_endpoint, json=payload)
response.raise_for_status()
return response.json()['data']['claims']
return response.json()["data"]["claims"]


@asset
Expand All @@ -176,13 +171,63 @@ def raw_hypercert_claims(raw_allo_projects) -> pd.DataFrame:

window_size = 1000
for start_index in range(0, len(grantees), window_size):
window_creators = grantees[start_index:start_index+window_size]
window_creators = grantees[start_index : start_index + window_size]
result = get_hypercerts(HYPERCERTS_ENDPOINT, window_creators)
all_certs.extend(result)

certs_df = pd.DataFrame(all_certs)
certs_df.uri = certs_df.uri.str.replace('ipfs://','')
certs_df.uri = certs_df.uri.str.replace("ipfs://", "")

certs_df = certs_df.convert_dtypes()

return certs_df


@retry(
stop=stop_after_attempt(8),
wait=wait_exponential(multiplier=1, min=4, max=10),
)
def get_attestations(endpoint, schema):
query = """
query ($schemaId: SchemaWhereUniqueInput!) {
schema(where: $schemaId) {
attestations(take:5000) {
attester
recipient
isOffchain
timeCreated
decodedDataJson
}
}
}
"""
payload = {
"query": query,
"variables": {"schemaId": {"id": schema}},
}

response = requests.post(endpoint, json=payload)
response.raise_for_status()

return response.json()["data"]["schema"]["attestations"]


@asset(compute_kind="EAS")
def raw_karmahq_attestations():
"""
Attestations made by KarmaHQ on Optimism. Some attesters are also Gitcoin grantees.
Source: EAS GraphQL api
"""
EAS_OP_ENDPOINT = "https://optimism.easscan.org/graphql"
EAS_OP_DETAILS_SCHEMA = (
"0x70a3f615f738fc6a4f56100692ada93d947c028b840940d97af7e7d6f0fa0577"
)
# List of schemas, most attestations don't carry data hance need for `DETAILS`
# https://github.com/show-karma/karma-gap-sdk/blob/4789422f1627fa7b575cc66cd0bf20c59ca1038a/core/consts.ts#L45

from_eas = pd.DataFrame(
get_attestations(EAS_OP_ENDPOINT, schema=EAS_OP_DETAILS_SCHEMA)
)
from_eas = from_eas.convert_dtypes()
return from_eas

0 comments on commit 901daca

Please sign in to comment.