Skip to content

Commit f076cbb

Browse files
authored
Revert "fix: ens resolve" (#2894)
1 parent 8a63d9a commit f076cbb

File tree

8 files changed

+73
-64
lines changed

8 files changed

+73
-64
lines changed

src/components/WalletConnection/ReadOnlyModal.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ import { ModalType, useModalContext } from 'src/hooks/useModal';
1515
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
1616
import { useRootStore } from 'src/store/root';
1717
import { AUTH } from 'src/utils/events';
18-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
18+
import { getENSProvider } from 'src/utils/marketsAndNetworksConfig';
1919
import { normalize } from 'viem/ens';
2020
import { useAccount, useDisconnect } from 'wagmi';
2121

2222
import { BasicModal } from '../primitives/BasicModal';
2323
import { TxModalTitle } from '../transactions/FlowCommons/TxModalTitle';
2424

25-
const viemClient = getENSClient();
26-
2725
export const ReadOnlyModal = () => {
2826
const { disconnectAsync } = useDisconnect();
2927
const { isConnected } = useAccount();
@@ -33,6 +31,7 @@ export const ReadOnlyModal = () => {
3331
const { type, close } = useModalContext();
3432
const { breakpoints } = useTheme();
3533
const sm = useMediaQuery(breakpoints.down('sm'));
34+
const mainnetProvider = getENSProvider();
3635
const trackEvent = useRootStore((store) => store.trackEvent);
3736

3837
const handleReadAddress = async (inputMockWalletAddress: string): Promise<void> => {
@@ -44,7 +43,7 @@ export const ReadOnlyModal = () => {
4443
if (inputMockWalletAddress.slice(-4) === '.eth') {
4544
const normalizedENS = normalize(inputMockWalletAddress);
4645
// Attempt to resolve ENS name and use resolved address if valid
47-
const resolvedAddress = await viemClient.getEnsAddress({ name: normalizedENS });
46+
const resolvedAddress = await mainnetProvider.resolveName(normalizedENS);
4847
if (resolvedAddress && utils.isAddress(resolvedAddress)) {
4948
saveAndClose(resolvedAddress);
5049
} else {

src/components/transactions/Bridge/BridgeDestinationInput.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import {
1010
import { isAddress } from 'ethers/lib/utils';
1111
import { useEffect, useState } from 'react';
1212
import { useIsContractAddress } from 'src/hooks/useIsContractAddress';
13-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
14-
15-
const viemClient = getENSClient();
13+
import { getENSProvider } from 'src/utils/marketsAndNetworksConfig';
1614

1715
export const BridgeDestinationInput = ({
1816
connectedAccount,
@@ -51,7 +49,7 @@ export const BridgeDestinationInput = ({
5149
useEffect(() => {
5250
const checkENS = async () => {
5351
setValidatingENS(true);
54-
const resolvedAddress = await viemClient.getEnsAddress({ name: destinationAccount });
52+
const resolvedAddress = await getENSProvider().resolveName(destinationAccount);
5553
if (resolvedAddress) {
5654
setDestinationAccount(resolvedAddress.toLowerCase());
5755
}

src/hooks/governance/useGovernanceProposals.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChainId } from '@aave/contract-helpers';
22
import { normalizeBN } from '@aave/math-utils';
33
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
4-
import { constants } from 'ethers';
4+
import { constants, Contract } from 'ethers';
55
import { gql } from 'graphql-request';
66
import {
77
adaptCacheProposalToDetail,
@@ -26,7 +26,7 @@ import {
2626
import { useRootStore } from 'src/store/root';
2727
import { governanceV3Config } from 'src/ui-config/governanceConfig';
2828
import { useSharedDependencies } from 'src/ui-config/SharedDependenciesProvider';
29-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
29+
import { getProvider } from 'src/utils/marketsAndNetworksConfig';
3030
import { subgraphRequest } from 'src/utils/subgraphRequest';
3131

3232
import { getProposal } from './useProposal';
@@ -42,7 +42,7 @@ const USE_GOVERNANCE_CACHE = process.env.NEXT_PUBLIC_USE_GOVERNANCE_CACHE === 't
4242
const PAGE_SIZE = 10;
4343
const VOTES_PAGE_SIZE = 50;
4444
const 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+
8191
type 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];

src/hooks/governance/useProposalVotes.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { ChainId } from '@aave/contract-helpers';
22
import { normalizeBN } from '@aave/math-utils';
33
import { useQuery, UseQueryResult } from '@tanstack/react-query';
4+
import { Contract } from 'ethers';
45
import { gql } from 'graphql-request';
56
import { governanceV3Config } from 'src/ui-config/governanceConfig';
6-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
7+
import { getProvider } from 'src/utils/marketsAndNetworksConfig';
78
import { subgraphRequest } from 'src/utils/subgraphRequest';
89

10+
import { ENS_REVERSE_REGISTRAR } from './useGovernanceProposals';
11+
912
export type ProposalVote = {
1013
proposalId: string;
1114
support: boolean;
@@ -24,7 +27,20 @@ export interface ProposalVotes {
2427
isFetching: boolean;
2528
}
2629

27-
const viemClient = getENSClient();
30+
const abi = [
31+
{
32+
inputs: [{ internalType: 'contract ENS', name: '_ens', type: 'address' }],
33+
stateMutability: 'nonpayable',
34+
type: 'constructor',
35+
},
36+
{
37+
inputs: [{ internalType: 'address[]', name: 'addresses', type: 'address[]' }],
38+
name: 'getNames',
39+
outputs: [{ internalType: 'string[]', name: 'r', type: 'string[]' }],
40+
stateMutability: 'view',
41+
type: 'function',
42+
},
43+
];
2844

2945
const getProposalVotes = gql`
3046
query getProposalVotes($proposalId: Int!) {
@@ -55,13 +71,11 @@ const fetchProposalVotes = async (
5571
}));
5672
};
5773

58-
const fetchProposalVotesEnsNames = async (addresses: string[]): Promise<string[]> => {
59-
const names = await Promise.all(
60-
addresses.map((addr) =>
61-
viemClient.getEnsName({ address: addr as `0x${string}` }).catch(() => null)
62-
)
63-
);
64-
return names.map((name) => name ?? '');
74+
const fetchProposalVotesEnsNames = async (addresses: string[]) => {
75+
const provider = getProvider(governanceV3Config.coreChainId);
76+
const contract = new Contract(ENS_REVERSE_REGISTRAR, abi);
77+
const connectedContract = contract.connect(provider);
78+
return connectedContract.getNames(addresses) as Promise<string[]>;
6579
};
6680

6781
export const useProposalVotesQuery = ({

src/libs/hooks/use-get-ens.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { blo } from 'blo';
2+
import { utils } from 'ethers';
23
import { useEffect, useState } from 'react';
3-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
4+
import { getENSProvider } from 'src/utils/marketsAndNetworksConfig';
45

5-
const viemClient = getENSClient();
6+
const mainnetProvider = getENSProvider();
67

78
interface EnsResponse {
89
name?: string;
@@ -12,20 +13,26 @@ interface EnsResponse {
1213
const useGetEns = (address: string): EnsResponse => {
1314
const [ensName, setEnsName] = useState<string | undefined>(undefined);
1415
const [ensAvatar, setEnsAvatar] = useState<string | undefined>(undefined);
15-
1616
const getName = async (address: string) => {
1717
try {
18-
const name = await viemClient.getEnsName({ address: address as `0x${string}` });
19-
setEnsName(name ?? undefined);
18+
const name = await mainnetProvider.lookupAddress(address);
19+
setEnsName(name ? name : undefined);
2020
} catch (error) {
2121
console.error('ENS name lookup error', error);
2222
}
2323
};
2424

2525
const getAvatar = async (name: string) => {
2626
try {
27-
const avatar = await viemClient.getEnsAvatar({ name });
28-
setEnsAvatar(avatar ?? blo(address as `0x${string}`));
27+
const labelHash = utils.keccak256(utils.toUtf8Bytes(name?.replace('.eth', '')));
28+
const result: { background_image: string } = await (
29+
await fetch(
30+
`https://metadata.ens.domains/mainnet/0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85/${labelHash}/`
31+
)
32+
).json();
33+
setEnsAvatar(
34+
result && result.background_image ? result.background_image : blo(address as `0x${string}`)
35+
);
2936
} catch (error) {
3037
console.error('ENS avatar lookup error', error);
3138
}

src/modules/governance/proposal/VotersListItem.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ExternalLinkIcon } from '@heroicons/react/solid';
22
import { Avatar, Box, SvgIcon, Typography } from '@mui/material';
33
import { blo } from 'blo';
4-
import React, { useEffect, useState } from 'react';
54
import { FormattedNumber } from 'src/components/primitives/FormattedNumber';
65
import { Link } from 'src/components/primitives/Link';
76
import { VoteDisplay } from 'src/modules/governance/types';
@@ -22,13 +21,6 @@ type VotersListItemProps = {
2221
export const VotersListItem = ({ compact, voter }: VotersListItemProps): JSX.Element | null => {
2322
const { voter: address, ensName } = voter;
2423
const blockieAvatar = blo(address !== '' ? (address as `0x${string}`) : '0x');
25-
const [avatar, setAvatar] = useState(blockieAvatar);
26-
27-
useEffect(() => {
28-
if (ensName) {
29-
setAvatar(`https://metadata.ens.domains/mainnet/avatar/${ensName}`);
30-
}
31-
}, [ensName]);
3224
const trackEvent = useRootStore((store) => store.trackEvent);
3325

3426
const displayName = (name?: string) => {
@@ -63,11 +55,7 @@ export const VotersListItem = ({ compact, voter }: VotersListItemProps): JSX.Ele
6355
<Box sx={{ my: 6, '&:first-of-type': { mt: 0 }, '&:last-of-type': { mb: 0 } }}>
6456
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
6557
<Box sx={{ display: 'flex', justifyContent: 'flex-start', alignItems: 'center' }}>
66-
<Avatar
67-
src={avatar}
68-
sx={{ width: 24, height: 24, mr: 2 }}
69-
slotProps={{ img: { onError: () => setAvatar(blockieAvatar) } }}
70-
/>
58+
<Avatar src={blockieAvatar} sx={{ width: 24, height: 24, mr: 2 }} />
7159
<Link
7260
href={`https://etherscan.io/address/${address}`}
7361
onClick={() =>

src/store/utils/domain-fetchers/ens.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { DomainType, WalletDomain } from 'src/store/walletDomains';
2-
import { getENSClient } from 'src/utils/marketsAndNetworksConfig';
2+
import { getENSProvider } from 'src/utils/marketsAndNetworksConfig';
33
import { tFetch } from 'src/utils/tFetch';
44

5-
const viemClient = getENSClient();
5+
const mainnetProvider = getENSProvider();
66

77
const getEnsName = async (address: string): Promise<string | null> => {
88
try {
9-
const name = await viemClient.getEnsName({ address: address as `0x${string}` });
10-
return name ?? null;
9+
const name = await mainnetProvider.lookupAddress(address);
10+
return name;
1111
} catch (error) {
1212
console.error('ENS name lookup error', error);
1313
}

src/utils/marketsAndNetworksConfig.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { ChainId, ChainIdToNetwork } from '@aave/contract-helpers';
22
import { StaticJsonRpcProvider } from '@ethersproject/providers';
33
import { ProviderWithSend } from 'src/components/transactions/GovVote/temporary/VotingMachineService';
4-
import { createPublicClient, http, PublicClient } from 'viem';
5-
import { mainnet } from 'viem/chains';
64

75
import {
86
CustomMarket,
@@ -190,13 +188,10 @@ export const getProvider = (chainId: ChainId): ProviderWithSend => {
190188
return providers[chainId];
191189
};
192190

193-
export const getENSClient = (): PublicClient => {
194-
const config = getNetworkConfig(ChainId.mainnet);
195-
return createPublicClient({
196-
chain: mainnet,
197-
transport: http(config.publicJsonRPCUrl[0]),
198-
batch: { multicall: true },
199-
});
191+
export const getENSProvider = () => {
192+
const chainId = 1;
193+
const config = getNetworkConfig(chainId);
194+
return new StaticJsonRpcProvider(config.publicJsonRPCUrl[0], chainId);
200195
};
201196

202197
const ammDisableProposal = 'https://governance-v2.aave.com/governance/proposal/44';

0 commit comments

Comments
 (0)