From 188f633a79ed09d7d4ab22238d0bc33134839e49 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Mon, 6 May 2024 15:05:41 -0400 Subject: [PATCH] Remove keyValuePairsContract from useSafeContracts and resolve downstream issues --- .../DAO/proposal/useCreateProposalTemplate.ts | 28 +++++++++--------- .../DAO/proposal/useRemoveProposalTemplate.ts | 29 ++++++++++--------- src/hooks/safe/useSafeContracts.ts | 9 ------ 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/hooks/DAO/proposal/useCreateProposalTemplate.ts b/src/hooks/DAO/proposal/useCreateProposalTemplate.ts index 508a1b5837..3f19065cbe 100644 --- a/src/hooks/DAO/proposal/useCreateProposalTemplate.ts +++ b/src/hooks/DAO/proposal/useCreateProposalTemplate.ts @@ -1,25 +1,29 @@ import { useCallback } from 'react'; -import { isHex, getAddress } from 'viem'; +import { encodeFunctionData } from 'viem'; +import KeyValuePairsAbi from '../../../assets/abi/KeyValuePairs'; import { useFractal } from '../../../providers/App/AppProvider'; import useIPFSClient from '../../../providers/App/hooks/useIPFSClient'; +import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider'; import { ProposalExecuteData } from '../../../types'; import { CreateProposalForm } from '../../../types/proposalBuilder'; import { couldBeENS } from '../../../utils/url'; -import useSafeContracts from '../../safe/useSafeContracts'; import useSignerOrProvider from '../../utils/useSignerOrProvider'; export default function useCreateProposalTemplate() { const signerOrProvider = useSignerOrProvider(); - const keyValuePairsContract = useSafeContracts()?.keyValuePairsContract; const client = useIPFSClient(); const { governance: { proposalTemplates }, } = useFractal(); + const { + contracts: { keyValuePairs }, + } = useNetworkConfig(); + const prepareProposalTemplateProposal = useCallback( async (values: CreateProposalForm) => { - if (proposalTemplates && signerOrProvider && keyValuePairsContract) { + if (proposalTemplates && signerOrProvider) { const proposalMetadata = { title: 'Create Proposal Template', description: @@ -54,17 +58,15 @@ export default function useCreateProposalTemplate() { const { Hash } = await client.add(JSON.stringify(updatedTemplatesList)); - const encodedUpdateValues = keyValuePairsContract.asProvider.interface.encodeFunctionData( - 'updateValues', - [['proposalTemplates'], [Hash]], - ); - if (!isHex(encodedUpdateValues)) { - return; - } + const encodedUpdateValues = encodeFunctionData({ + abi: KeyValuePairsAbi, + functionName: 'updateValues', + args: [['proposalTemplates'], [Hash]], + }); const proposal: ProposalExecuteData = { metaData: proposalMetadata, - targets: [getAddress(keyValuePairsContract.asProvider.address)], + targets: [keyValuePairs], values: [0n], calldatas: [encodedUpdateValues], }; @@ -72,7 +74,7 @@ export default function useCreateProposalTemplate() { return proposal; } }, - [proposalTemplates, keyValuePairsContract, client, signerOrProvider], + [client, keyValuePairs, proposalTemplates, signerOrProvider], ); return { prepareProposalTemplateProposal }; diff --git a/src/hooks/DAO/proposal/useRemoveProposalTemplate.ts b/src/hooks/DAO/proposal/useRemoveProposalTemplate.ts index f50e3f0420..6e7da52182 100644 --- a/src/hooks/DAO/proposal/useRemoveProposalTemplate.ts +++ b/src/hooks/DAO/proposal/useRemoveProposalTemplate.ts @@ -1,20 +1,24 @@ import { useCallback } from 'react'; -import { isHex, getAddress } from 'viem'; +import { encodeFunctionData } from 'viem'; +import KeyValuePairsAbi from '../../../assets/abi/KeyValuePairs'; import { useFractal } from '../../../providers/App/AppProvider'; import useIPFSClient from '../../../providers/App/hooks/useIPFSClient'; +import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider'; import { ProposalExecuteData } from '../../../types'; -import useSafeContracts from '../../safe/useSafeContracts'; export default function useRemoveProposalTemplate() { - const keyValuePairsContract = useSafeContracts()?.keyValuePairsContract; const client = useIPFSClient(); const { governance: { proposalTemplates }, } = useFractal(); + const { + contracts: { keyValuePairs }, + } = useNetworkConfig(); + const prepareRemoveProposalTemplateProposal = useCallback( async (templateIndex: number) => { - if (proposalTemplates && keyValuePairsContract) { + if (proposalTemplates) { const proposalMetadata = { title: 'Remove Proposal Template', description: @@ -28,16 +32,15 @@ export default function useRemoveProposalTemplate() { const { Hash } = await client.add(JSON.stringify(updatedTemplatesList)); - const encodedUpdateValues = keyValuePairsContract.asProvider.interface.encodeFunctionData( - 'updateValues', - [['proposalTemplates'], [Hash]], - ); - if (!isHex(encodedUpdateValues)) { - return; - } + const encodedUpdateValues = encodeFunctionData({ + abi: KeyValuePairsAbi, + functionName: 'updateValues', + args: [['proposalTemplates'], [Hash]], + }); + const proposal: ProposalExecuteData = { metaData: proposalMetadata, - targets: [getAddress(keyValuePairsContract.asProvider.address)], + targets: [keyValuePairs], values: [0n], calldatas: [encodedUpdateValues], }; @@ -45,7 +48,7 @@ export default function useRemoveProposalTemplate() { return proposal; } }, - [proposalTemplates, keyValuePairsContract, client], + [client, keyValuePairs, proposalTemplates], ); return { prepareRemoveProposalTemplateProposal }; diff --git a/src/hooks/safe/useSafeContracts.ts b/src/hooks/safe/useSafeContracts.ts index 439d9944ca..faf4c394c9 100644 --- a/src/hooks/safe/useSafeContracts.ts +++ b/src/hooks/safe/useSafeContracts.ts @@ -10,7 +10,6 @@ import { LinearERC20Voting__factory, Azorius__factory, ERC20Claim__factory, - KeyValuePairs__factory, LinearERC721Voting__factory, ERC721FreezeVoting__factory, } from '@fractal-framework/fractal-contracts'; @@ -42,7 +41,6 @@ export default function useSafeContracts() { erc721FreezeVotingMasterCopy, claimingMasterCopy, linearVotingERC721MasterCopy, - keyValuePairs, }, } = useNetworkConfig(); @@ -130,11 +128,6 @@ export default function useSafeContracts() { asProvider: ERC20Claim__factory.connect(claimingMasterCopy, provider), }; - const keyValuePairsContract = { - asSigner: KeyValuePairs__factory.connect(keyValuePairs, signerOrProvider), - asProvider: KeyValuePairs__factory.connect(keyValuePairs, provider), - }; - return { multiSendContract, safeFactoryContract, @@ -151,7 +144,6 @@ export default function useSafeContracts() { freezeERC721VotingMasterCopyContract, claimingMasterCopyContract, linearVotingERC721MasterCopyContract, - keyValuePairsContract, }; }, [ safeFactory, @@ -169,7 +161,6 @@ export default function useSafeContracts() { claimingMasterCopy, linearVotingERC721MasterCopy, erc721FreezeVotingMasterCopy, - keyValuePairs, signerOrProvider, provider, ]);