diff --git a/src/components/pages/DaoSettings/components/Metadata/index.tsx b/src/components/pages/DaoSettings/components/Metadata/index.tsx index 19c3853333..f7299d3379 100644 --- a/src/components/pages/DaoSettings/components/Metadata/index.tsx +++ b/src/components/pages/DaoSettings/components/Metadata/index.tsx @@ -3,8 +3,9 @@ import { Flex, Text, Button, Divider } from '@chakra-ui/react'; import { useState, useEffect, ChangeEventHandler } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; -import { isHex, getAddress, encodeFunctionData } from 'viem'; +import { encodeFunctionData } from 'viem'; import { SettingsSection } from '..'; +import FractalRegistryAbi from '../../../../../assets/abi/FractalRegistry'; import KeyValuePairsAbi from '../../../../../assets/abi/KeyValuePairs'; import { DAO_ROUTES } from '../../../../../constants/routes'; import useSubmitProposal from '../../../../../hooks/DAO/proposal/useSubmitProposal'; @@ -25,7 +26,6 @@ export default function MetadataContainer() { const { submitProposal } = useSubmitProposal(); const { canUserCreateProposal } = useCanUserCreateProposal(); const { - baseContracts, node: { daoName, daoSnapshotENS, daoAddress, safe }, readOnly: { user: { votingWeight }, @@ -33,7 +33,7 @@ export default function MetadataContainer() { } = useFractal(); const { addressPrefix, - contracts: { keyValuePairs }, + contracts: { keyValuePairs, fractalRegistry }, } = useNetworkConfig(); useEffect(() => { @@ -65,24 +65,19 @@ export default function MetadataContainer() { }; const handleEditDAOName = () => { - if (!baseContracts) { - return; - } - const { fractalRegistryContract } = baseContracts; - const encodedUpdateDAOName = fractalRegistryContract.asProvider.interface.encodeFunctionData( - 'updateDAOName', - [name], - ); - if (!isHex(encodedUpdateDAOName)) { - return; - } + const encodedUpdateDAOName = encodeFunctionData({ + abi: FractalRegistryAbi, + functionName: 'updateDAOName', + args: [name], + }); + const proposalData: ProposalExecuteData = { metaData: { title: t('Update Safe Name', { ns: 'proposalMetadata' }), description: '', documentationUrl: '', }, - targets: [getAddress(fractalRegistryContract.asProvider.address)], + targets: [fractalRegistry], values: [0n], calldatas: [encodedUpdateDAOName], }; diff --git a/src/components/ui/menus/FavoritesMenu/Favorite.tsx b/src/components/ui/menus/FavoritesMenu/Favorite.tsx index 6ccb8f0700..36489113e2 100644 --- a/src/components/ui/menus/FavoritesMenu/Favorite.tsx +++ b/src/components/ui/menus/FavoritesMenu/Favorite.tsx @@ -10,7 +10,7 @@ interface IFavorite { address: string; } export function Favorite({ network, address }: IFavorite) { - const { daoRegistryName } = useDAOName({ address }); + const { daoRegistryName } = useDAOName(address); const { action } = useFractal(); const navigate = useNavigate(); diff --git a/src/hooks/DAO/useCreateSubDAOProposal.ts b/src/hooks/DAO/useCreateSubDAOProposal.ts index b553ac1929..0d4ead1556 100644 --- a/src/hooks/DAO/useCreateSubDAOProposal.ts +++ b/src/hooks/DAO/useCreateSubDAOProposal.ts @@ -1,7 +1,9 @@ import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { isHex, getAddress } from 'viem'; +import { isHex, getAddress, encodeFunctionData } from 'viem'; +import FractalRegistryAbi from '../../assets/abi/FractalRegistry'; import { useFractal } from '../../providers/App/AppProvider'; +import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider'; import { SafeMultisigDAO, AzoriusGovernance, AzoriusERC20DAO, AzoriusERC721DAO } from '../../types'; import { ProposalExecuteData } from '../../types/daoProposal'; import { useCanUserCreateProposal } from '../utils/useCanUserSubmitProposal'; @@ -19,6 +21,9 @@ export const useCreateSubDAOProposal = () => { node: { daoAddress }, governance, } = useFractal(); + const { + contracts: { fractalRegistry }, + } = useNetworkConfig(); const azoriusGovernance = governance as AzoriusGovernance; const proposeDao = useCallback( ( @@ -30,7 +35,7 @@ export const useCreateSubDAOProposal = () => { if (!baseContracts || !daoAddress) { return; } - const { multiSendContract, fractalRegistryContract } = baseContracts; + const { multiSendContract } = baseContracts; const builtSafeTx = await build(daoData, daoAddress, azoriusGovernance.votesToken?.address); if (!builtSafeTx) { @@ -43,18 +48,19 @@ export const useCreateSubDAOProposal = () => { 'multiSend', [safeTx], ); - const encodedDeclareSubDAO = - fractalRegistryContract.asProvider.interface.encodeFunctionData('declareSubDAO', [ - predictedSafeAddress, - ]); - if (!isHex(encodedMultisend) || !isHex(encodedDeclareSubDAO)) { - return; + + if (!isHex(encodedMultisend)) { + throw new Error('encodedMultisend data is not hex??'); } + + const encodedDeclareSubDAO = encodeFunctionData({ + abi: FractalRegistryAbi, + functionName: 'declareSubDAO', + args: [getAddress(predictedSafeAddress)], + }); + const proposalData: ProposalExecuteData = { - targets: [ - getAddress(multiSendContract.asProvider.address), - getAddress(fractalRegistryContract.asProvider.address), - ], + targets: [getAddress(multiSendContract.asProvider.address), fractalRegistry], values: [0n, 0n], calldatas: [encodedMultisend, encodedDeclareSubDAO], metaData: { @@ -74,7 +80,15 @@ export const useCreateSubDAOProposal = () => { }; propose(); }, - [baseContracts, build, daoAddress, submitProposal, azoriusGovernance, t], + [ + azoriusGovernance.votesToken?.address, + baseContracts, + build, + daoAddress, + fractalRegistry, + submitProposal, + t, + ], ); return { proposeDao, pendingCreateTx, canUserCreateProposal } as const; diff --git a/src/hooks/DAO/useDAOName.ts b/src/hooks/DAO/useDAOName.ts index c53ccb34b8..87b0a5a989 100644 --- a/src/hooks/DAO/useDAOName.ts +++ b/src/hooks/DAO/useDAOName.ts @@ -1,38 +1,27 @@ -import { FractalRegistry } from '@fractal-framework/fractal-contracts'; import { useCallback, useEffect, useState } from 'react'; -import { Address } from 'viem'; -import { useEnsName } from 'wagmi'; -import { getEventRPC } from '../../helpers'; -import { useFractal } from '../../providers/App/AppProvider'; +import { getAddress, getContract } from 'viem'; +import { useEnsName, usePublicClient } from 'wagmi'; +import FractalRegistryAbi from '../../assets/abi/FractalRegistry'; import { useEthersProvider } from '../../providers/Ethers/hooks/useEthersProvider'; import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider'; import { createAccountSubstring } from '../utils/useDisplayName'; -/** - * Gets the 'display name' for a Fractal DAO, in the following order of preference: - * - * 1. Primary ENS Name (reverse record) - * 2. Fractal name registry name - * 3. Truncated Eth address in the form 0xbFC4...7551 - */ -export default function useDAOName({ - address, - registryName, -}: { - address?: string; - registryName?: string | null; -}) { - const { baseContracts } = useFractal(); +export default function useDAOName(address: string) { const [daoRegistryName, setDAORegistryName] = useState(''); const { chain } = useNetworkConfig(); + const publicClient = usePublicClient(); const { data: ensName } = useEnsName({ - address: address as Address, + address: getAddress(address), chainId: chain.id, }); + const { + contracts: { fractalRegistry }, + } = useNetworkConfig(); + const getDaoName = useCallback(async () => { - if (!address || !baseContracts) { + if (!address || !publicClient) { setDAORegistryName(''); return; } @@ -42,28 +31,30 @@ export default function useDAOName({ return; } - const { fractalRegistryContract } = baseContracts; - if (!fractalRegistryContract) { + const fractalRegistryContract = getContract({ + abi: FractalRegistryAbi, + address: fractalRegistry, + client: publicClient, + }); + + const events = await fractalRegistryContract.getEvents.FractalNameUpdated({ + daoAddress: getAddress(address), + }); + + const latestEvent = events.pop(); + if (!latestEvent) { setDAORegistryName(createAccountSubstring(address)); return; } - if (registryName) { - // Aka supplied from Subgraph - setDAORegistryName(registryName); - } else { - const rpc = getEventRPC(fractalRegistryContract); - const events = await rpc.queryFilter(rpc.filters.FractalNameUpdated(address)); - - const latestEvent = events.pop(); - if (!latestEvent) { - setDAORegistryName(createAccountSubstring(address)); - return; - } - const { daoName } = latestEvent.args; - setDAORegistryName(daoName); + const { daoName } = latestEvent.args; + if (!daoName) { + setDAORegistryName(createAccountSubstring(address)); + return; } - }, [address, ensName, baseContracts, registryName]); + + setDAORegistryName(daoName); + }, [address, ensName, fractalRegistry, publicClient]); useEffect(() => { (async () => { diff --git a/src/hooks/utils/useMasterCopy.ts b/src/hooks/utils/useMasterCopy.ts index 2fc8696587..6775ed0257 100644 --- a/src/hooks/utils/useMasterCopy.ts +++ b/src/hooks/utils/useMasterCopy.ts @@ -73,6 +73,7 @@ export function useMasterCopy() { let masterCopyAddress: Address = zeroAddress; let error; if (baseContracts) { + // TODO after removing this moduleproxyfactorycontract from basecontracts, kill getEventRPC const contract = getEventRPC( baseContracts?.zodiacModuleProxyFactoryContract, ); diff --git a/src/types/fractal.ts b/src/types/fractal.ts index 0e9446b64e..68edeac593 100644 --- a/src/types/fractal.ts +++ b/src/types/fractal.ts @@ -1,6 +1,5 @@ import { FractalModule, - FractalRegistry, GnosisSafeProxyFactory, ModuleProxyFactory, LinearERC20Voting, @@ -339,7 +338,6 @@ export interface FractalContracts { safeSingletonContract: ContractConnection; zodiacModuleProxyFactoryContract: ContractConnection; fractalModuleMasterCopyContract: ContractConnection; - fractalRegistryContract: ContractConnection; multisigFreezeGuardMasterCopyContract: ContractConnection; azoriusFreezeGuardMasterCopyContract: ContractConnection; freezeMultisigVotingMasterCopyContract: ContractConnection;