Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove key value pairs contract from use safe contracts #1649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/hooks/DAO/proposal/useCreateProposalTemplate.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -54,25 +58,23 @@ 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],
};

return proposal;
}
},
[proposalTemplates, keyValuePairsContract, client, signerOrProvider],
[client, keyValuePairs, proposalTemplates, signerOrProvider],
);

return { prepareProposalTemplateProposal };
Expand Down
29 changes: 16 additions & 13 deletions src/hooks/DAO/proposal/useRemoveProposalTemplate.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -28,24 +32,23 @@ 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],
};

return proposal;
}
},
[proposalTemplates, keyValuePairsContract, client],
[client, keyValuePairs, proposalTemplates],
);

return { prepareRemoveProposalTemplateProposal };
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/safe/useSafeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
LinearERC20Voting__factory,
Azorius__factory,
ERC20Claim__factory,
KeyValuePairs__factory,
LinearERC721Voting__factory,
ERC721FreezeVoting__factory,
} from '@fractal-framework/fractal-contracts';
Expand Down Expand Up @@ -42,7 +41,6 @@ export default function useSafeContracts() {
erc721FreezeVotingMasterCopy,
claimingMasterCopy,
linearVotingERC721MasterCopy,
keyValuePairs,
},
} = useNetworkConfig();

Expand Down Expand Up @@ -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,
Expand All @@ -151,7 +144,6 @@ export default function useSafeContracts() {
freezeERC721VotingMasterCopyContract,
claimingMasterCopyContract,
linearVotingERC721MasterCopyContract,
keyValuePairsContract,
};
}, [
safeFactory,
Expand All @@ -169,7 +161,6 @@ export default function useSafeContracts() {
claimingMasterCopy,
linearVotingERC721MasterCopy,
erc721FreezeVotingMasterCopy,
keyValuePairs,
signerOrProvider,
provider,
]);
Expand Down
Loading