Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 866f1de

Browse files
authored
Merge pull request #52 from altruistNode/propdates
Propdates
2 parents 622c834 + 9d48c3c commit 866f1de

File tree

3 files changed

+127
-20123
lines changed

3 files changed

+127
-20123
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import axios from 'axios'
2+
import { checksumAddress, isAddress } from 'viem'
3+
4+
import { CHAIN_ID } from 'src/typings'
5+
6+
interface AttestationResponse {
7+
data: {
8+
attestations: Array<{
9+
attester: string
10+
recipient: string
11+
decodedDataJson: string
12+
}>
13+
}
14+
}
15+
16+
interface DecodedData {
17+
name: string
18+
type: string
19+
value: {
20+
type: string
21+
value: string
22+
}
23+
}
24+
25+
const ATTESTATION_SCHEMA_UID = `0x9ee9a1bfbf4f8f9b977c6b30600d6131d2a56d0be8100e2238a057ea8b18be7e`
26+
27+
const ATTESTATION_URL: Record<CHAIN_ID, string> = {
28+
[CHAIN_ID.ETHEREUM]: 'https://easscan.org/graphql',
29+
[CHAIN_ID.OPTIMISM]: 'https://optimism.easscan.org/graphql',
30+
[CHAIN_ID.SEPOLIA]: 'https://sepolia.easscan.org/graphql',
31+
[CHAIN_ID.OPTIMISM_SEPOLIA]: 'https://optimism-sepolia.easscan.org/graphql',
32+
[CHAIN_ID.BASE]: 'https://base.easscan.org/graphql',
33+
[CHAIN_ID.BASE_SEPOLIA]: 'https://base-sepolia.easscan.org/graphql',
34+
[CHAIN_ID.ZORA]: '',
35+
[CHAIN_ID.ZORA_SEPOLIA]: '',
36+
[CHAIN_ID.FOUNDRY]: '',
37+
}
38+
39+
export async function getPropDates(
40+
daoTreasuryAddress: string,
41+
chainId: CHAIN_ID,
42+
propId: string
43+
): Promise<Array<any>> {
44+
// Input validation
45+
if (!daoTreasuryAddress || !isAddress(daoTreasuryAddress)) {
46+
return []
47+
}
48+
49+
const attestationUrl = ATTESTATION_URL[chainId]
50+
if (!attestationUrl) {
51+
return []
52+
}
53+
54+
55+
const query = `
56+
query Attestations {
57+
attestations(
58+
where: {
59+
schemaId: { equals: "${ATTESTATION_SCHEMA_UID}" }
60+
recipient: { equals: "${checksumAddress(daoTreasuryAddress)}" }
61+
}
62+
) {
63+
attester
64+
recipient
65+
decodedDataJson
66+
}
67+
}
68+
`
69+
70+
try {
71+
const response = await axios.post<AttestationResponse>(
72+
attestationUrl,
73+
{ query },
74+
{
75+
headers: {
76+
'Content-Type': 'application/json',
77+
},
78+
}
79+
)
80+
81+
const attestations = response?.data?.data?.attestations
82+
83+
if (!attestations?.length) {
84+
return []
85+
}
86+
87+
try {
88+
// Get decoded data from each attestation
89+
const decodedData = attestations.map(attestation =>
90+
JSON.parse(attestation.decodedDataJson) as DecodedData[]
91+
)
92+
93+
const propDates = decodedData.map(decoded => ({
94+
propId: Number(decoded.find(d => d.name === 'propId')?.value.value),
95+
replyTo: decoded.find(d => d.name === 'replyTo')?.value.value,
96+
response: decoded.find(d => d.name === 'response')?.value.value,
97+
milestoneId: Number(decoded.find(d => d.name === 'milestoneId')?.value.value)
98+
}))
99+
100+
return propDates.filter(date => Number(date.propId) == Number(propId))
101+
} catch (parseError) {
102+
console.error('Error parsing attestation data:', parseError)
103+
return []
104+
}
105+
} catch (error) {
106+
console.error('Error fetching attestations:', error)
107+
return []
108+
}
109+
}

apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { CACHE_TIMES } from 'src/constants/cacheTimes'
1212
import { PUBLIC_DEFAULT_CHAINS } from 'src/constants/defaultChains'
1313
import SWR_KEYS from 'src/constants/swrKeys'
1414
import { getEscrowDelegate } from 'src/data/contract/requests/getEscrowDelegate'
15+
import { getPropDates } from 'src/data/contract/requests/getPropDates'
16+
1517
import { SDK } from 'src/data/subgraph/client'
1618
import {
1719
formatAndFetchState,
@@ -230,6 +232,21 @@ export const getServerSideProps: GetServerSideProps = async ({ params, req, res
230232
daoImage: contractImage,
231233
}
232234

235+
const propDates = (await getPropDates(
236+
treasuryAddress,
237+
chain.id,
238+
params?.id as string
239+
)) as Array<{
240+
propId: number
241+
replyTo: string
242+
response: string
243+
milestoneId: number
244+
}>
245+
246+
247+
console.log({propDates})
248+
249+
233250
const addresses: DaoContractAddresses = {
234251
token: tokenAddress,
235252
metadata: metadataAddress,
@@ -262,6 +279,7 @@ export const getServerSideProps: GetServerSideProps = async ({ params, req, res
262279
ogImageURL,
263280
proposalId: proposal.proposalId,
264281
addresses,
282+
propDates,
265283
},
266284
}
267285
}

0 commit comments

Comments
 (0)