diff --git a/src/hooks/DAO/loaders/useFractalGuardContracts.ts b/src/hooks/DAO/loaders/useFractalGuardContracts.ts index 4d569ec340..b8b6be1438 100644 --- a/src/hooks/DAO/loaders/useFractalGuardContracts.ts +++ b/src/hooks/DAO/loaders/useFractalGuardContracts.ts @@ -1,4 +1,8 @@ -import { AzoriusFreezeGuard, MultisigFreezeGuard } from '@fractal-framework/fractal-contracts'; +import { + Azorius, + AzoriusFreezeGuard, + MultisigFreezeGuard, +} from '@fractal-framework/fractal-contracts'; import { useCallback, useEffect, useRef } from 'react'; import { getAddress, zeroAddress } from 'viem'; import { useFractal } from '../../../providers/App/AppProvider'; @@ -49,7 +53,7 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: module => module.moduleType === FractalModuleType.AZORIUS, ); if (!!azoriusModule && azoriusModule.moduleContract) { - const azoriusGuardAddress = await azoriusModule.moduleContract.getGuard(); + const azoriusGuardAddress = await (azoriusModule.moduleContract as Azorius).getGuard(); if (azoriusGuardAddress === zeroAddress) { return { diff --git a/src/hooks/DAO/loaders/useFractalModules.ts b/src/hooks/DAO/loaders/useFractalModules.ts index 5839b7e4d9..a278a4a62f 100644 --- a/src/hooks/DAO/loaders/useFractalModules.ts +++ b/src/hooks/DAO/loaders/useFractalModules.ts @@ -1,5 +1,7 @@ import { useCallback } from 'react'; -import { getAddress } from 'viem'; +import { getAddress, getContract } from 'viem'; +import { usePublicClient } from 'wagmi'; +import FractalModuleAbi from '../../../assets/abi/FractalModule'; import { useFractal } from '../../../providers/App/AppProvider'; import { FractalModuleData, FractalModuleType } from '../../../types'; import { useMasterCopy } from '../../utils/useMasterCopy'; @@ -7,6 +9,7 @@ import { useMasterCopy } from '../../utils/useMasterCopy'; export const useFractalModules = () => { const { baseContracts } = useFractal(); const { getZodiacModuleProxyMasterCopyData } = useMasterCopy(); + const publicClient = usePublicClient(); const lookupModules = useCallback( async (_moduleAddresses: string[]) => { const modules = await Promise.all( @@ -24,10 +27,13 @@ export const useFractalModules = () => { moduleAddress: moduleAddress, moduleType: FractalModuleType.AZORIUS, }; - } else if (masterCopyData.isFractalModule && baseContracts) { + } else if (masterCopyData.isFractalModule && publicClient) { safeModule = { - moduleContract: - baseContracts.fractalModuleMasterCopyContract.asSigner.attach(moduleAddress), + moduleContract: getContract({ + abi: FractalModuleAbi, + address: getAddress(moduleAddress), + client: publicClient, + }), moduleAddress: moduleAddress, moduleType: FractalModuleType.FRACTAL, }; @@ -44,7 +50,7 @@ export const useFractalModules = () => { ); return modules; }, - [baseContracts, getZodiacModuleProxyMasterCopyData], + [baseContracts, getZodiacModuleProxyMasterCopyData, publicClient], ); return lookupModules; }; diff --git a/src/hooks/DAO/useBuildDAOTx.ts b/src/hooks/DAO/useBuildDAOTx.ts index ee4aed99db..f4d317e33c 100644 --- a/src/hooks/DAO/useBuildDAOTx.ts +++ b/src/hooks/DAO/useBuildDAOTx.ts @@ -56,7 +56,6 @@ const useBuildDAOTx = () => { } const { fractalAzoriusMasterCopyContract, - fractalModuleMasterCopyContract, multisigFreezeGuardMasterCopyContract, azoriusFreezeGuardMasterCopyContract, freezeMultisigVotingMasterCopyContract, @@ -79,7 +78,6 @@ const useBuildDAOTx = () => { } const buildrerBaseContracts: BaseContracts = { - fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asSigner, multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asSigner, freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asSigner, freezeERC721VotingMasterCopyContract: freezeERC721VotingMasterCopyContract.asSigner, diff --git a/src/hooks/DAO/useClawBack.ts b/src/hooks/DAO/useClawBack.ts index a4d29c3542..298d9f84f3 100644 --- a/src/hooks/DAO/useClawBack.ts +++ b/src/hooks/DAO/useClawBack.ts @@ -1,4 +1,3 @@ -import { FractalModule } from '@fractal-framework/fractal-contracts'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -7,9 +6,9 @@ import { encodeFunctionData, erc20Abi, getAddress, - isHex, parseAbiParameters, } from 'viem'; +import FractalModuleAbi from '../../assets/abi/FractalModule'; import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI'; import { useEthersProvider } from '../../providers/Ethers/hooks/useEthersProvider'; import { FractalModuleType, FractalNode } from '../../types'; @@ -39,7 +38,7 @@ export default function useClawBack({ childSafeInfo, parentAddress }: IUseClawBa const fractalModule = childSafeInfo.fractalModules!.find( module => module.moduleType === FractalModuleType.FRACTAL, ); - const fractalModuleContract = fractalModule?.moduleContract as FractalModule; + if (fractalModule) { const transactions = childSafeBalance.map(asset => { if (!asset.tokenAddress) { @@ -49,15 +48,14 @@ export default function useClawBack({ childSafeInfo, parentAddress }: IUseClawBa [parentAddress, BigInt(asset.balance), '0x', 0], ); - const fractalModuleCalldata = fractalModuleContract.interface.encodeFunctionData( - 'execTx', - [txData], - ); - if (!isHex(fractalModuleCalldata)) { - throw new Error('Error encoding clawback call data'); - } + const fractalModuleCalldata = encodeFunctionData({ + abi: FractalModuleAbi, + functionName: 'execTx', + args: [txData], + }); + return { - target: getAddress(fractalModuleContract.address), + target: getAddress(fractalModule.moduleAddress), value: 0, calldata: fractalModuleCalldata, }; @@ -72,17 +70,14 @@ export default function useClawBack({ childSafeInfo, parentAddress }: IUseClawBa [getAddress(asset.tokenAddress), 0n, clawBackCalldata, 0], ); - const fractalModuleCalldata = fractalModuleContract.interface.encodeFunctionData( - 'execTx', - [txData], - ); - - if (!isHex(fractalModuleCalldata)) { - throw new Error('Error encoding clawback call data'); - } + const fractalModuleCalldata = encodeFunctionData({ + abi: FractalModuleAbi, + functionName: 'execTx', + args: [txData], + }); return { - target: getAddress(fractalModuleContract.address), + target: getAddress(fractalModule.moduleAddress), value: 0, calldata: fractalModuleCalldata, }; diff --git a/src/hooks/DAO/useDeployAzorius.ts b/src/hooks/DAO/useDeployAzorius.ts index f762d0eba5..420fed011b 100644 --- a/src/hooks/DAO/useDeployAzorius.ts +++ b/src/hooks/DAO/useDeployAzorius.ts @@ -62,7 +62,6 @@ const useDeployAzorius = () => { } const { fractalAzoriusMasterCopyContract, - fractalModuleMasterCopyContract, multisigFreezeGuardMasterCopyContract, azoriusFreezeGuardMasterCopyContract, freezeMultisigVotingMasterCopyContract, @@ -77,7 +76,6 @@ const useDeployAzorius = () => { }; const builderBaseContracts: BaseContracts = { - fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asProvider, multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asProvider, freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asProvider, freezeERC721VotingMasterCopyContract: freezeERC721VotingMasterCopyContract.asProvider, diff --git a/src/hooks/utils/useMasterCopy.ts b/src/hooks/utils/useMasterCopy.ts index 4e761e6fc5..b1dcc8cbf7 100644 --- a/src/hooks/utils/useMasterCopy.ts +++ b/src/hooks/utils/useMasterCopy.ts @@ -11,7 +11,12 @@ export function useMasterCopy() { const { getValue, setValue } = useLocalStorage(); const { baseContracts } = useFractal(); const { - contracts: { zodiacModuleProxyFactory, linearVotingMasterCopy, linearVotingERC721MasterCopy }, + contracts: { + zodiacModuleProxyFactory, + linearVotingMasterCopy, + linearVotingERC721MasterCopy, + fractalModuleMasterCopy, + }, } = useNetworkConfig(); const publicClient = usePublicClient(); @@ -45,9 +50,8 @@ export function useMasterCopy() { [baseContracts], ); const isFractalModule = useCallback( - (masterCopyAddress: Address) => - masterCopyAddress === baseContracts?.fractalModuleMasterCopyContract.asProvider.address, - [baseContracts], + (masterCopyAddress: Address) => masterCopyAddress === fractalModuleMasterCopy, + [fractalModuleMasterCopy], ); const getMasterCopyAddress = useCallback( diff --git a/src/types/contract.ts b/src/types/contract.ts index f79e2534e5..c198122d4f 100644 --- a/src/types/contract.ts +++ b/src/types/contract.ts @@ -1,5 +1,4 @@ import { - FractalModule, MultisigFreezeGuard, MultisigFreezeVoting, ERC20FreezeVoting, @@ -16,7 +15,6 @@ export type ContractConnection = { }; export interface BaseContracts { - fractalModuleMasterCopyContract: FractalModule; multisigFreezeGuardMasterCopyContract: MultisigFreezeGuard; freezeERC20VotingMasterCopyContract: ERC20FreezeVoting; freezeERC721VotingMasterCopyContract: ERC721FreezeVoting; diff --git a/src/types/fractal.ts b/src/types/fractal.ts index 625610acca..b1d2841f0b 100644 --- a/src/types/fractal.ts +++ b/src/types/fractal.ts @@ -1,5 +1,4 @@ import { - FractalModule, Azorius, AzoriusFreezeGuard, ERC20FreezeVoting, @@ -15,7 +14,8 @@ import { SafeCollectibleResponse, } from '@safe-global/safe-service-client'; import { Dispatch } from 'react'; -import { Address } from 'viem'; +import { Address, GetContractReturnType, PublicClient } from 'viem'; +import FractalModuleAbi from '../assets/abi/FractalModule'; import { FractalGovernanceActions } from '../providers/App/governance/action'; import { GovernanceContractActions } from '../providers/App/governanceContracts/action'; import { FractalGuardActions } from '../providers/App/guard/action'; @@ -235,7 +235,10 @@ export interface Node extends Omit {} export interface FractalModuleData { - moduleContract: Azorius | FractalModule | undefined; + moduleContract: + | Azorius + | GetContractReturnType + | undefined; moduleAddress: string; moduleType: FractalModuleType; } @@ -317,7 +320,6 @@ export interface NodeHierarchy { export interface FractalContracts { fractalAzoriusMasterCopyContract: ContractConnection; - fractalModuleMasterCopyContract: ContractConnection; multisigFreezeGuardMasterCopyContract: ContractConnection; azoriusFreezeGuardMasterCopyContract: ContractConnection; freezeMultisigVotingMasterCopyContract: ContractConnection;