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 { getENSClient } from 'src/utils/marketsAndNetworksConfig' ;
29+ import { getProvider } from 'src/utils/marketsAndNetworksConfig' ;
3030import { subgraphRequest } from 'src/utils/subgraphRequest' ;
3131
3232import { getProposal } from './useProposal' ;
@@ -42,7 +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- const viemClient = getENSClient ( ) ;
45+ export const ENS_REVERSE_REGISTRAR = '0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C' ;
4646
4747// ============================================
4848// Subgraph search query
@@ -78,6 +78,16 @@ const getProposalVotesQuery = gql`
7878 }
7979` ;
8080
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+
8191type SubgraphVote = {
8292 proposalId : string ;
8393 support : boolean ;
@@ -325,14 +335,13 @@ export const useGovernanceVotersSplit = (
325335 queryFn : async ( ) => {
326336 const votes = await fetchSubgraphVotes ( proposalId , votingChainId as ChainId ) ;
327337 try {
328- const ensNames = await Promise . all (
329- votes . map ( ( v ) =>
330- viemClient . getEnsName ( { address : v . voter as `0x${string } ` } ) . catch ( ( ) => null )
331- )
332- ) ;
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 ) ) ;
333342 return votes . map ( ( vote , i ) => ( {
334343 ...vote ,
335- ensName : ensNames [ i ] ?? undefined ,
344+ ensName : ensNames [ i ] || undefined ,
336345 } ) ) ;
337346 } catch {
338347 return votes ;
@@ -355,11 +364,10 @@ export const useGovernanceVotersSplit = (
355364
356365 const { data : cacheEnsNames } = useQuery ( {
357366 queryFn : async ( ) => {
358- const names = await Promise . all (
359- cacheVoterAddresses . map ( ( addr ) =>
360- viemClient . getEnsName ( { address : addr as `0x${string } ` } ) . catch ( ( ) => null )
361- )
362- ) ;
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 ) ;
363371 const map : Record < string , string > = { } ;
364372 cacheVoterAddresses . forEach ( ( addr , i ) => {
365373 if ( names [ i ] ) map [ addr . toLowerCase ( ) ] = names [ i ] ;
0 commit comments