forked from davidgasquez/gitcoin-grants-data-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allo.py
226 lines (200 loc) · 5.58 KB
/
allo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import json
import pandas as pd
from dagster import Backoff, RetryPolicy, asset
from ..resources import GrantsStackIndexerGraphQL
import requests
import io
@asset
def raw_allo_applications(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
applications {
anchorAddress
chainId
createdAtBlock
createdByAddress
id
metadata
metadataCid
nodeId
projectId
roundId
status
statusSnapshots
statusUpdatedAtBlock
tags
totalAmountDonatedInUsd
totalDonationsCount
uniqueDonorsCount
}
}
"""
response = indexer_graphql.query(query)
df = pd.DataFrame(response["data"]["applications"]).convert_dtypes()
df["metadata"] = df["metadata"].apply(lambda x: json.dumps(x))
return df
@asset
def raw_allo_rounds(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
rounds {
adminRole
applicationMetadata
applicationMetadataCid
applicationsEndTime
applicationsStartTime
chainId
createdAtBlock
createdByAddress
donationsEndTime
donationsStartTime
fundedAmount
fundedAmountInUsd
id
managerRole
matchAmount
matchAmountInUsd
matchingDistribution
matchTokenAddress
nodeId
projectId
readyForPayoutTransaction
roundMetadata
roundMetadataCid
strategyAddress
strategyId
strategyName
tags
totalAmountDonatedInUsd
totalDonationsCount
uniqueDonorsCount
updatedAtBlock
}
}
"""
response = indexer_graphql.query(query)
df = pd.DataFrame(response["data"]["rounds"])
df["roundMetadata"] = df["roundMetadata"].apply(lambda x: json.dumps(x))
df["applicationMetadata"] = df["applicationMetadata"].apply(lambda x: json.dumps(x))
df["tags"] = df["tags"].apply(lambda x: json.dumps(x))
df = df.convert_dtypes()
return df
@asset
def raw_allo_donations(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
query($first: Int, $offset: Int) {
donations(first: $first, offset: $offset) {
amountInUsd
amount
amountInRoundMatchToken
applicationId
blockNumber
chainId
id
donorAddress
nodeId
projectId
recipientAddress
roundId
tokenAddress
transactionHash
}
}
"""
response = indexer_graphql.paginated_query(query, size=10000)
df = pd.DataFrame(response).convert_dtypes()
return df
@asset
def raw_allo_prices(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
prices {
blockNumber
chainId
id
nodeId
priceInUsd
timestamp
tokenAddress
}
}
"""
response = indexer_graphql.query(query)
return pd.DataFrame(response["data"]["prices"])
@asset
def raw_allo_projects(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
projects {
anchorAddress
chainId
createdAtBlock
createdByAddress
id
metadata
metadataCid
name
nodeId
nonce
projectNumber
projectType
registryAddress
tags
updatedAtBlock
}
}
"""
response = indexer_graphql.query(query)
df = pd.DataFrame(response["data"]["projects"])
df["metadata"] = df["metadata"].apply(lambda x: json.dumps(x))
df = df.convert_dtypes()
return df
@asset
def raw_allo_round_roles(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
roundRoles {
address
chainId
createdAtBlock
nodeId
role
roundId
}
}
"""
response = indexer_graphql.query(query)
return pd.DataFrame(response["data"]["roundRoles"])
@asset
def raw_allo_subscriptions(indexer_graphql: GrantsStackIndexerGraphQL) -> pd.DataFrame:
query = """
{
subscriptions {
chainId
contractAddress
contractName
createdAt
fromBlock
id
indexedToBlock
indexedToLogIndex
nodeId
toBlock
updatedAt
}
}
"""
response = indexer_graphql.query(query)
return pd.DataFrame(response["data"]["subscriptions"])
@asset(retry_policy=RetryPolicy(max_retries=3, delay=0.2, backoff=Backoff.EXPONENTIAL))
def raw_allo_deployments() -> pd.DataFrame:
"""
Deployment address for all official allo contract deployments by Allo team, collected 07.01.24
Canonical source: https://github.com/allo-protocol/allo-contracts/blob/main/docs/CHAINS.md
Ingestion logic: https://gist.github.com/DistributedDoge/57e39c3e5cc207fcafdf4d377562ec33
"""
response = requests.get(
"https://ipfs.io/ipfs/QmWpnErRwVRLqdGsBC2J9NMngwzJtWErDZvf6wDqJ1ZVis"
)
response.raise_for_status()
return pd.read_parquet(io.BytesIO(response.content))