11import { ChainId } from '@aave/contract-helpers' ;
22import { normalizeBN } from '@aave/math-utils' ;
33import { useInfiniteQuery , useQuery } from '@tanstack/react-query' ;
4- import { constants } from 'ethers' ;
4+ import { constants , Contract } from 'ethers' ;
55import { gql } from 'graphql-request' ;
66import {
77 adaptCacheProposalToDetail ,
@@ -26,7 +26,7 @@ import {
2626import { useRootStore } from 'src/store/root' ;
2727import { governanceV3Config } from 'src/ui-config/governanceConfig' ;
2828import { useSharedDependencies } from 'src/ui-config/SharedDependenciesProvider' ;
29- import { getEnsProfilesMap } from 'src/utils/ens ' ;
29+ import { getProvider } from 'src/utils/marketsAndNetworksConfig ' ;
3030import { subgraphRequest } from 'src/utils/subgraphRequest' ;
3131
3232import { getProposal } from './useProposal' ;
@@ -42,6 +42,7 @@ const USE_GOVERNANCE_CACHE = process.env.NEXT_PUBLIC_USE_GOVERNANCE_CACHE === 't
4242const PAGE_SIZE = 10 ;
4343const VOTES_PAGE_SIZE = 50 ;
4444const SEARCH_RESULTS_LIMIT = 10 ;
45+ export const ENS_REVERSE_REGISTRAR = '0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C' ;
4546
4647// ============================================
4748// Subgraph search query
@@ -77,6 +78,16 @@ const getProposalVotesQuery = gql`
7778 }
7879` ;
7980
81+ const ensAbi = [
82+ {
83+ inputs : [ { internalType : 'address[]' , name : 'addresses' , type : 'address[]' } ] ,
84+ name : 'getNames' ,
85+ outputs : [ { internalType : 'string[]' , name : 'r' , type : 'string[]' } ] ,
86+ stateMutability : 'view' ,
87+ type : 'function' ,
88+ } ,
89+ ] ;
90+
8091type SubgraphVote = {
8192 proposalId : string ;
8293 support : boolean ;
@@ -323,13 +334,18 @@ export const useGovernanceVotersSplit = (
323334 const { data : graphVotes , isFetching : graphFetching } = useQuery ( {
324335 queryFn : async ( ) => {
325336 const votes = await fetchSubgraphVotes ( proposalId , votingChainId as ChainId ) ;
326- const ensProfiles = await getEnsProfilesMap ( votes . map ( ( vote ) => vote . voter ) ) ;
327-
328- return votes . map ( ( vote ) => ( {
329- ...vote ,
330- ensName : ensProfiles [ vote . voter . toLowerCase ( ) ] ?. name ,
331- ensAvatar : ensProfiles [ vote . voter . toLowerCase ( ) ] ?. avatar ,
332- } ) ) ;
337+ try {
338+ const provider = getProvider ( governanceV3Config . coreChainId ) ;
339+ const contract = new Contract ( ENS_REVERSE_REGISTRAR , ensAbi ) ;
340+ const connectedContract = contract . connect ( provider ) ;
341+ const ensNames : string [ ] = await connectedContract . getNames ( votes . map ( ( v ) => v . voter ) ) ;
342+ return votes . map ( ( vote , i ) => ( {
343+ ...vote ,
344+ ensName : ensNames [ i ] || undefined ,
345+ } ) ) ;
346+ } catch {
347+ return votes ;
348+ }
333349 } ,
334350 queryKey : [ 'governance-voters-graph' , proposalId ] ,
335351 enabled : ! USE_GOVERNANCE_CACHE && votingChainId !== undefined && ! isNaN ( proposalId ) ,
@@ -346,8 +362,18 @@ export const useGovernanceVotersSplit = (
346362 ]
347363 : [ ] ;
348364
349- const { data : cacheEnsProfiles } = useQuery ( {
350- queryFn : ( ) => getEnsProfilesMap ( cacheVoterAddresses ) ,
365+ const { data : cacheEnsNames } = useQuery ( {
366+ queryFn : async ( ) => {
367+ const provider = getProvider ( governanceV3Config . coreChainId ) ;
368+ const contract = new Contract ( ENS_REVERSE_REGISTRAR , ensAbi ) ;
369+ const connectedContract = contract . connect ( provider ) ;
370+ const names : string [ ] = await connectedContract . getNames ( cacheVoterAddresses ) ;
371+ const map : Record < string , string > = { } ;
372+ cacheVoterAddresses . forEach ( ( addr , i ) => {
373+ if ( names [ i ] ) map [ addr . toLowerCase ( ) ] = names [ i ] ;
374+ } ) ;
375+ return map ;
376+ } ,
351377 queryKey : [ 'governance-voters-ens' , proposalId , cacheVoterAddresses ] ,
352378 enabled : USE_GOVERNANCE_CACHE && cacheVoterAddresses . length > 0 ,
353379 refetchOnMount : false ,
@@ -358,8 +384,7 @@ export const useGovernanceVotersSplit = (
358384 if ( USE_GOVERNANCE_CACHE ) {
359385 const withEns = ( vote : VoteDisplay ) : VoteDisplay => ( {
360386 ...vote ,
361- ensName : cacheEnsProfiles ?. [ vote . voter . toLowerCase ( ) ] ?. name ,
362- ensAvatar : cacheEnsProfiles ?. [ vote . voter . toLowerCase ( ) ] ?. avatar ,
387+ ensName : cacheEnsNames ?. [ vote . voter . toLowerCase ( ) ] ,
363388 } ) ;
364389 const yaeVotes = ( cacheForData ?. pages . flatMap ( ( p ) => p . votes . map ( adaptCacheVote ) ) || [ ] ) . map (
365390 withEns
@@ -386,13 +411,11 @@ export const useGovernanceVotersSplit = (
386411 support : boolean ;
387412 votingPower : string ;
388413 ensName ?: string ;
389- ensAvatar ?: string ;
390414 } ) : VoteDisplay => ( {
391415 voter : v . voter ,
392416 support : v . support ,
393417 votingPower : v . votingPower ,
394418 ensName : v . ensName ,
395- ensAvatar : v . ensAvatar ,
396419 } ) ;
397420
398421 const yaeVotes =
0 commit comments