Skip to content

Commit

Permalink
Merge pull request #1670 from decentdao/remove-fractalModule-typechain
Browse files Browse the repository at this point in the history
Remove FractalModule typechain imports from all files
  • Loading branch information
adamgall authored May 23, 2024
2 parents 34b242e + 6810626 commit ac62870
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 50 deletions.
8 changes: 6 additions & 2 deletions src/hooks/DAO/loaders/useFractalGuardContracts.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions src/hooks/DAO/loaders/useFractalModules.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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';

export const useFractalModules = () => {
const { baseContracts } = useFractal();
const { getZodiacModuleProxyMasterCopyData } = useMasterCopy();
const publicClient = usePublicClient();
const lookupModules = useCallback(
async (_moduleAddresses: string[]) => {
const modules = await Promise.all(
Expand 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,
};
Expand All @@ -44,7 +50,7 @@ export const useFractalModules = () => {
);
return modules;
},
[baseContracts, getZodiacModuleProxyMasterCopyData],
[baseContracts, getZodiacModuleProxyMasterCopyData, publicClient],
);
return lookupModules;
};
2 changes: 0 additions & 2 deletions src/hooks/DAO/useBuildDAOTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const useBuildDAOTx = () => {
}
const {
fractalAzoriusMasterCopyContract,
fractalModuleMasterCopyContract,
multisigFreezeGuardMasterCopyContract,
azoriusFreezeGuardMasterCopyContract,
freezeMultisigVotingMasterCopyContract,
Expand All @@ -79,7 +78,6 @@ const useBuildDAOTx = () => {
}

const buildrerBaseContracts: BaseContracts = {
fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asSigner,
multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asSigner,
freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asSigner,
freezeERC721VotingMasterCopyContract: freezeERC721VotingMasterCopyContract.asSigner,
Expand Down
35 changes: 15 additions & 20 deletions src/hooks/DAO/useClawBack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FractalModule } from '@fractal-framework/fractal-contracts';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import {
Expand All @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
};
Expand All @@ -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,
};
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const useDeployAzorius = () => {
}
const {
fractalAzoriusMasterCopyContract,
fractalModuleMasterCopyContract,
multisigFreezeGuardMasterCopyContract,
azoriusFreezeGuardMasterCopyContract,
freezeMultisigVotingMasterCopyContract,
Expand All @@ -77,7 +76,6 @@ const useDeployAzorius = () => {
};

const builderBaseContracts: BaseContracts = {
fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asProvider,
multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asProvider,
freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asProvider,
freezeERC721VotingMasterCopyContract: freezeERC721VotingMasterCopyContract.asProvider,
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/safe/useSafeContracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
FractalModule__factory,
AzoriusFreezeGuard__factory,
ERC20FreezeVoting__factory,
MultisigFreezeGuard__factory,
Expand All @@ -19,7 +18,6 @@ export default function useSafeContracts() {
const {
contracts: {
fractalAzoriusMasterCopy,
fractalModuleMasterCopy,
multisigFreezeGuardMasterCopy,
azoriusFreezeGuardMasterCopy,
multisigFreezeVotingMasterCopy,
Expand All @@ -38,11 +36,6 @@ export default function useSafeContracts() {
asProvider: Azorius__factory.connect(fractalAzoriusMasterCopy, provider),
};

const fractalModuleMasterCopyContract = {
asSigner: FractalModule__factory.connect(fractalModuleMasterCopy, signerOrProvider),
asProvider: FractalModule__factory.connect(fractalModuleMasterCopy, provider),
};

const multisigFreezeGuardMasterCopyContract = {
asSigner: MultisigFreezeGuard__factory.connect(
multisigFreezeGuardMasterCopy,
Expand Down Expand Up @@ -76,7 +69,6 @@ export default function useSafeContracts() {

return {
fractalAzoriusMasterCopyContract,
fractalModuleMasterCopyContract,
multisigFreezeGuardMasterCopyContract,
azoriusFreezeGuardMasterCopyContract,
freezeMultisigVotingMasterCopyContract,
Expand All @@ -85,7 +77,6 @@ export default function useSafeContracts() {
};
}, [
fractalAzoriusMasterCopy,
fractalModuleMasterCopy,
multisigFreezeGuardMasterCopy,
azoriusFreezeGuardMasterCopy,
multisigFreezeVotingMasterCopy,
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/utils/useMasterCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
FractalModule,
MultisigFreezeGuard,
MultisigFreezeVoting,
ERC20FreezeVoting,
Expand All @@ -16,7 +15,6 @@ export type ContractConnection<T> = {
};

export interface BaseContracts {
fractalModuleMasterCopyContract: FractalModule;
multisigFreezeGuardMasterCopyContract: MultisigFreezeGuard;
freezeERC20VotingMasterCopyContract: ERC20FreezeVoting;
freezeERC721VotingMasterCopyContract: ERC721FreezeVoting;
Expand Down
10 changes: 6 additions & 4 deletions src/types/fractal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
FractalModule,
Azorius,
AzoriusFreezeGuard,
ERC20FreezeVoting,
Expand All @@ -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';
Expand Down Expand Up @@ -235,7 +235,10 @@ export interface Node
extends Omit<FractalNode, 'safe' | 'fractalModules' | 'isModulesLoaded' | 'isHierarchyLoaded'> {}

export interface FractalModuleData {
moduleContract: Azorius | FractalModule | undefined;
moduleContract:
| Azorius
| GetContractReturnType<typeof FractalModuleAbi, PublicClient>
| undefined;
moduleAddress: string;
moduleType: FractalModuleType;
}
Expand Down Expand Up @@ -317,7 +320,6 @@ export interface NodeHierarchy {

export interface FractalContracts {
fractalAzoriusMasterCopyContract: ContractConnection<Azorius>;
fractalModuleMasterCopyContract: ContractConnection<FractalModule>;
multisigFreezeGuardMasterCopyContract: ContractConnection<MultisigFreezeGuard>;
azoriusFreezeGuardMasterCopyContract: ContractConnection<AzoriusFreezeGuard>;
freezeMultisigVotingMasterCopyContract: ContractConnection<MultisigFreezeVoting>;
Expand Down

0 comments on commit ac62870

Please sign in to comment.