11import { ChainId } from '@aave/contract-helpers' ;
22import { normalizeBN } from '@aave/math-utils' ;
33import { useInfiniteQuery , useQuery } from '@tanstack/react-query' ;
4- import { constants , Contract } from 'ethers' ;
4+ import { constants } 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 { getProvider } from 'src/utils/marketsAndNetworksConfig' ;
29+ import { getENSClient } 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- export const ENS_REVERSE_REGISTRAR = '0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C' ;
45+ const viemClient = getENSClient ( ) ;
4646
4747// ============================================
4848// Subgraph search query
@@ -78,16 +78,6 @@ 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-
9181type SubgraphVote = {
9282 proposalId : string ;
9383 support : boolean ;
@@ -335,13 +325,14 @@ export const useGovernanceVotersSplit = (
335325 queryFn : async ( ) => {
336326 const votes = await fetchSubgraphVotes ( proposalId , votingChainId as ChainId ) ;
337327 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 ) ) ;
328+ const ensNames = await Promise . all (
329+ votes . map ( ( v ) =>
330+ viemClient . getEnsName ( { address : v . voter as `0x${string } ` } ) . catch ( ( ) => null )
331+ )
332+ ) ;
342333 return votes . map ( ( vote , i ) => ( {
343334 ...vote ,
344- ensName : ensNames [ i ] || undefined ,
335+ ensName : ensNames [ i ] ?? undefined ,
345336 } ) ) ;
346337 } catch {
347338 return votes ;
@@ -364,10 +355,11 @@ export const useGovernanceVotersSplit = (
364355
365356 const { data : cacheEnsNames } = useQuery ( {
366357 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 ) ;
358+ const names = await Promise . all (
359+ cacheVoterAddresses . map ( ( addr ) =>
360+ viemClient . getEnsName ( { address : addr as `0x${string } ` } ) . catch ( ( ) => null )
361+ )
362+ ) ;
371363 const map : Record < string , string > = { } ;
372364 cacheVoterAddresses . forEach ( ( addr , i ) => {
373365 if ( names [ i ] ) map [ addr . toLowerCase ( ) ] = names [ i ] ;
0 commit comments