From 69b457f16b59ce65a94cdb9f5ac91ce84a51a284 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 22 Feb 2024 22:31:56 -0500 Subject: [PATCH 1/6] remove param causing incorrect workflow, fixes create proposal hang on 429 rpc request - safeAddress param removed. --- app/daos/[daoAddress]/proposals/new/page.tsx | 1 - src/hooks/DAO/useDeployAzorius.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/app/daos/[daoAddress]/proposals/new/page.tsx b/app/daos/[daoAddress]/proposals/new/page.tsx index c8c7b0f7dc..dc79b44ba5 100644 --- a/app/daos/[daoAddress]/proposals/new/page.tsx +++ b/app/daos/[daoAddress]/proposals/new/page.tsx @@ -73,7 +73,6 @@ export default function ProposalCreatePage() { successToastMessage: t('proposalCreateSuccessToastMessage'), failedToastMessage: t('proposalCreateFailureToastMessage'), successCallback, - safeAddress: daoAddress, }); }} validateOnMount diff --git a/src/hooks/DAO/useDeployAzorius.ts b/src/hooks/DAO/useDeployAzorius.ts index 8a7967d8ec..92762aa5b6 100644 --- a/src/hooks/DAO/useDeployAzorius.ts +++ b/src/hooks/DAO/useDeployAzorius.ts @@ -116,7 +116,6 @@ const useDeployAzorius = () => { successToastMessage: t('proposalCreateSuccessToastMessage', { ns: 'proposal' }), failedToastMessage: t('proposalCreateFailureToastMessage', { ns: 'proposal' }), successCallback: () => push(DAO_ROUTES.proposals.relative(daoAddress)), - safeAddress: daoAddress, }); }, [ From 07048d32e1107c132f53b655a58bad6c6ed5c5ec Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 22 Feb 2024 22:34:35 -0500 Subject: [PATCH 2/6] replace event filter for EnabledStrategies(). - saves requests for events further in the past --- .../ui/menus/ManageDAO/ManageDAOMenu.tsx | 14 ++++++++------ .../DAO/loaders/useGovernanceContracts.ts | 11 ++++++----- src/hooks/DAO/proposal/useSubmitProposal.ts | 19 +++++++++---------- .../DAO/proposal/useUserERC721VotingTokens.ts | 8 +++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index 85c412425d..5dff5e1a05 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -2,7 +2,6 @@ import { VEllipsis } from '@decent-org/fractal-ui'; import { ERC20FreezeVoting, ERC721FreezeVoting, - Azorius, ModuleProxyFactory, MultisigFreezeVoting, } from '@fractal-framework/fractal-contracts'; @@ -107,11 +106,14 @@ export function ManageDAOMenu({ azoriusModule.moduleAddress ), }; - const votingContractAddress = await getEventRPC(azoriusContract) - .queryFilter((azoriusModule.moduleContract as Azorius).filters.EnabledStrategy()) - .then(strategiesEnabled => { - return strategiesEnabled[0].args.strategy; - }); + + // Get the voting contract address + const votingContractAddress = ( + await azoriusContract.asProvider.getStrategies( + '0x0000000000000000000000000000000000000001', + 1 + ) + )[0][0]; const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); const votingContractMasterCopyAddress = await rpc diff --git a/src/hooks/DAO/loaders/useGovernanceContracts.ts b/src/hooks/DAO/loaders/useGovernanceContracts.ts index c604727f9e..d0317f92f2 100644 --- a/src/hooks/DAO/loaders/useGovernanceContracts.ts +++ b/src/hooks/DAO/loaders/useGovernanceContracts.ts @@ -78,11 +78,12 @@ export const useGovernanceContracts = () => { let lockReleaseContract: ContractConnection | null = null; if (!votingContractAddress) { - votingContractAddress = await getEventRPC(azoriusContract) - .queryFilter(azoriusModuleContract.filters.EnabledStrategy()) - .then(strategiesEnabled => { - return strategiesEnabled[0].args.strategy; - }); + votingContractAddress = ( + await azoriusContract.asProvider.getStrategies( + '0x0000000000000000000000000000000000000001', + 1 + ) + )[0][0]; } if (!votingContractMasterCopyAddress) { diff --git a/src/hooks/DAO/proposal/useSubmitProposal.ts b/src/hooks/DAO/proposal/useSubmitProposal.ts index 0236623160..943f898184 100644 --- a/src/hooks/DAO/proposal/useSubmitProposal.ts +++ b/src/hooks/DAO/proposal/useSubmitProposal.ts @@ -115,11 +115,9 @@ export default function useSubmitProposal() { if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; - const votingContractAddress = await azoriusContract - .queryFilter(azoriusContract.filters.EnabledStrategy()) - .then(strategiesEnabled => { - return strategiesEnabled[0].args.strategy; - }); + const votingContractAddress = ( + await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 1) + )[0][0]; const votingContract = BaseStrategy__factory.connect( votingContractAddress, signerOrProvider @@ -377,11 +375,12 @@ export default function useSubmitProposal() { }); } else { const azoriusModuleContract = azoriusModule.moduleContract as Azorius; - const votingStrategyAddress = await azoriusModuleContract - .queryFilter(azoriusModuleContract.filters.EnabledStrategy()) - .then(strategiesEnabled => { - return strategiesEnabled[0].args.strategy; - }); + const votingStrategyAddress = ( + await azoriusModuleContract.getStrategies( + '0x0000000000000000000000000000000000000001', + 1 + ) + )[0][0]; submitAzoriusProposal({ proposalData, pendingToastMessage, diff --git a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts index 77d1994bec..b3d0c6c268 100644 --- a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts +++ b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts @@ -58,11 +58,9 @@ export default function useUserERC721VotingTokens( const azoriusModule = getAzoriusModuleFromModules(safeModules); if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; - const votingContractAddress = await azoriusContract - .queryFilter(azoriusContract.filters.EnabledStrategy()) - .then(strategiesEnabled => { - return strategiesEnabled[0].args.strategy; - }); + const votingContractAddress = ( + await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 1) + )[0][0]; votingContract = LinearERC721Voting__factory.connect( votingContractAddress, signerOrProvider From b3395d5eba2ac0e7e3ba73c0b68add8077554741 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:00:22 -0500 Subject: [PATCH 3/6] use local storage to save request for master copy --- .../ui/menus/ManageDAO/ManageDAOMenu.tsx | 24 +++++++++++++------ src/hooks/DAO/loaders/useFractalModules.ts | 7 ++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index 5dff5e1a05..ec468132b5 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -17,6 +17,7 @@ import { import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal'; import useUserERC721VotingTokens from '../../../../hooks/DAO/proposal/useUserERC721VotingTokens'; import useClawBack from '../../../../hooks/DAO/useClawBack'; +import { useLocalStorage } from '../../../../hooks/utils/cache/useLocalStorage'; import useBlockTimestamp from '../../../../hooks/utils/useBlockTimestamp'; import { useFractal } from '../../../../providers/App/AppProvider'; import { @@ -69,6 +70,7 @@ export function ManageDAOMenu({ const currentTime = BigNumber.from(useBlockTimestamp()); const { push } = useRouter(); const safeAddress = fractalNode?.daoAddress; + const { setValue, getValue } = useLocalStorage(); const { getCanUserCreateProposal } = useSubmitProposal(); const { getUserERC721VotingTokens } = useUserERC721VotingTokens(undefined, safeAddress, false); @@ -114,13 +116,19 @@ export function ManageDAOMenu({ 1 ) )[0][0]; - const rpc = getEventRPC(zodiacModuleProxyFactoryContract); - const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); - const votingContractMasterCopyAddress = await rpc - .queryFilter(filter) - .then(proxiesCreated => { - return proxiesCreated[0].args.masterCopy; - }); + const cachedMasterCopyAddress = getValue('master_copy_of' + votingContractAddress); + let votingContractMasterCopyAddress = cachedMasterCopyAddress; + if (!votingContractMasterCopyAddress) { + const rpc = getEventRPC(zodiacModuleProxyFactoryContract); + const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); + + votingContractMasterCopyAddress = await rpc + .queryFilter(filter) + .then(proxiesCreated => { + return proxiesCreated[0].args.masterCopy; + }); + setValue('master_copy_of' + votingContractAddress, votingContractMasterCopyAddress); + } if ( votingContractMasterCopyAddress === linearVotingMasterCopyContract.asProvider.address @@ -149,6 +157,8 @@ export function ManageDAOMenu({ safeAddress, type, zodiacModuleProxyFactoryContract, + getValue, + setValue, ]); const handleNavigateToSettings = useCallback( diff --git a/src/hooks/DAO/loaders/useFractalModules.ts b/src/hooks/DAO/loaders/useFractalModules.ts index c7153884a1..6e8e42df77 100644 --- a/src/hooks/DAO/loaders/useFractalModules.ts +++ b/src/hooks/DAO/loaders/useFractalModules.ts @@ -4,6 +4,7 @@ import { useCallback } from 'react'; import { getEventRPC } from '../../../helpers'; import { useFractal } from '../../../providers/App/AppProvider'; import { FractalModuleData, FractalModuleType } from '../../../types'; +import { useLocalStorage } from './../../utils/cache/useLocalStorage'; export const useFractalModules = () => { const { @@ -13,14 +14,18 @@ export const useFractalModules = () => { fractalModuleMasterCopyContract, }, } = useFractal(); + const { setValue, getValue } = useLocalStorage(); const lookupModules = useCallback( async (_moduleAddresses: string[]) => { const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const getMasterCopyAddress = async (proxyAddress: string): Promise => { + const cachedValue = getValue('master_copy_of' + proxyAddress); + if (cachedValue) return cachedValue; const filter = rpc.filters.ModuleProxyCreation(proxyAddress, null); return rpc.queryFilter(filter).then(proxiesCreated => { if (proxiesCreated.length === 0) return constants.AddressZero; + setValue('master_copy_of' + proxyAddress, proxiesCreated[0].args.masterCopy); return proxiesCreated[0].args.masterCopy; }); }; @@ -63,6 +68,8 @@ export const useFractalModules = () => { zodiacModuleProxyFactoryContract, fractalAzoriusMasterCopyContract, fractalModuleMasterCopyContract, + getValue, + setValue, ] ); return lookupModules; From 11ec233a9e86220e607392163a80b23e30792029 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:19:39 -0500 Subject: [PATCH 4/6] clean up getStrategies usage --- src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx | 9 ++++----- src/hooks/DAO/loaders/useFractalModules.ts | 4 ++-- src/hooks/DAO/loaders/useGovernanceContracts.ts | 4 ++-- src/hooks/DAO/proposal/useSubmitProposal.ts | 8 ++++---- src/hooks/DAO/proposal/useUserERC721VotingTokens.ts | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index ec468132b5..58f78dd72f 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -113,21 +113,20 @@ export function ManageDAOMenu({ const votingContractAddress = ( await azoriusContract.asProvider.getStrategies( '0x0000000000000000000000000000000000000001', - 1 + 0 ) - )[0][0]; - const cachedMasterCopyAddress = getValue('master_copy_of' + votingContractAddress); + )[1]; + const cachedMasterCopyAddress = getValue('master_copy_of_' + votingContractAddress); let votingContractMasterCopyAddress = cachedMasterCopyAddress; if (!votingContractMasterCopyAddress) { const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); - votingContractMasterCopyAddress = await rpc .queryFilter(filter) .then(proxiesCreated => { return proxiesCreated[0].args.masterCopy; }); - setValue('master_copy_of' + votingContractAddress, votingContractMasterCopyAddress); + setValue('master_copy_of_' + votingContractAddress, votingContractMasterCopyAddress); } if ( diff --git a/src/hooks/DAO/loaders/useFractalModules.ts b/src/hooks/DAO/loaders/useFractalModules.ts index 6e8e42df77..641fe9a175 100644 --- a/src/hooks/DAO/loaders/useFractalModules.ts +++ b/src/hooks/DAO/loaders/useFractalModules.ts @@ -20,12 +20,12 @@ export const useFractalModules = () => { async (_moduleAddresses: string[]) => { const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const getMasterCopyAddress = async (proxyAddress: string): Promise => { - const cachedValue = getValue('master_copy_of' + proxyAddress); + const cachedValue = getValue('master_copy_of_' + proxyAddress); if (cachedValue) return cachedValue; const filter = rpc.filters.ModuleProxyCreation(proxyAddress, null); return rpc.queryFilter(filter).then(proxiesCreated => { if (proxiesCreated.length === 0) return constants.AddressZero; - setValue('master_copy_of' + proxyAddress, proxiesCreated[0].args.masterCopy); + setValue('master_copy_of_' + proxyAddress, proxiesCreated[0].args.masterCopy); return proxiesCreated[0].args.masterCopy; }); }; diff --git a/src/hooks/DAO/loaders/useGovernanceContracts.ts b/src/hooks/DAO/loaders/useGovernanceContracts.ts index d0317f92f2..79a7344296 100644 --- a/src/hooks/DAO/loaders/useGovernanceContracts.ts +++ b/src/hooks/DAO/loaders/useGovernanceContracts.ts @@ -81,9 +81,9 @@ export const useGovernanceContracts = () => { votingContractAddress = ( await azoriusContract.asProvider.getStrategies( '0x0000000000000000000000000000000000000001', - 1 + 0 ) - )[0][0]; + )[1]; } if (!votingContractMasterCopyAddress) { diff --git a/src/hooks/DAO/proposal/useSubmitProposal.ts b/src/hooks/DAO/proposal/useSubmitProposal.ts index 943f898184..d181a9f684 100644 --- a/src/hooks/DAO/proposal/useSubmitProposal.ts +++ b/src/hooks/DAO/proposal/useSubmitProposal.ts @@ -116,8 +116,8 @@ export default function useSubmitProposal() { if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; const votingContractAddress = ( - await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 1) - )[0][0]; + await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0) + )[1]; const votingContract = BaseStrategy__factory.connect( votingContractAddress, signerOrProvider @@ -378,9 +378,9 @@ export default function useSubmitProposal() { const votingStrategyAddress = ( await azoriusModuleContract.getStrategies( '0x0000000000000000000000000000000000000001', - 1 + 0 ) - )[0][0]; + )[1]; submitAzoriusProposal({ proposalData, pendingToastMessage, diff --git a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts index b3d0c6c268..2c7d6cc6f0 100644 --- a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts +++ b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts @@ -59,8 +59,8 @@ export default function useUserERC721VotingTokens( if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; const votingContractAddress = ( - await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 1) - )[0][0]; + await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0) + )[1]; votingContract = LinearERC721Voting__factory.connect( votingContractAddress, signerOrProvider From 63a4f61d008b18da861bb187b0b7d68ff03fbe98 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:48:31 -0500 Subject: [PATCH 5/6] add assumption comment --- src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx | 2 +- src/hooks/DAO/loaders/useGovernanceContracts.ts | 1 + src/hooks/DAO/proposal/useSubmitProposal.ts | 2 ++ src/hooks/DAO/proposal/useUserERC721VotingTokens.ts | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index 58f78dd72f..5ce895a2e3 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -109,7 +109,7 @@ export function ManageDAOMenu({ ), }; - // Get the voting contract address + // @dev assumes the first strategy is the voting contract const votingContractAddress = ( await azoriusContract.asProvider.getStrategies( '0x0000000000000000000000000000000000000001', diff --git a/src/hooks/DAO/loaders/useGovernanceContracts.ts b/src/hooks/DAO/loaders/useGovernanceContracts.ts index 79a7344296..405694ffd7 100644 --- a/src/hooks/DAO/loaders/useGovernanceContracts.ts +++ b/src/hooks/DAO/loaders/useGovernanceContracts.ts @@ -78,6 +78,7 @@ export const useGovernanceContracts = () => { let lockReleaseContract: ContractConnection | null = null; if (!votingContractAddress) { + // @dev assumes the first strategy is the voting contract votingContractAddress = ( await azoriusContract.asProvider.getStrategies( '0x0000000000000000000000000000000000000001', diff --git a/src/hooks/DAO/proposal/useSubmitProposal.ts b/src/hooks/DAO/proposal/useSubmitProposal.ts index d181a9f684..3845892232 100644 --- a/src/hooks/DAO/proposal/useSubmitProposal.ts +++ b/src/hooks/DAO/proposal/useSubmitProposal.ts @@ -115,6 +115,7 @@ export default function useSubmitProposal() { if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; + // @dev assumes the first strategy is the voting contract const votingContractAddress = ( await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0) )[1]; @@ -375,6 +376,7 @@ export default function useSubmitProposal() { }); } else { const azoriusModuleContract = azoriusModule.moduleContract as Azorius; + // @dev assumes the first strategy is the voting contract const votingStrategyAddress = ( await azoriusModuleContract.getStrategies( '0x0000000000000000000000000000000000000001', diff --git a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts index 2c7d6cc6f0..a69365162e 100644 --- a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts +++ b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts @@ -58,6 +58,7 @@ export default function useUserERC721VotingTokens( const azoriusModule = getAzoriusModuleFromModules(safeModules); if (azoriusModule && azoriusModule.moduleContract) { const azoriusContract = azoriusModule.moduleContract as Azorius; + // @dev assumes the first strategy is the voting contract const votingContractAddress = ( await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0) )[1]; From 33256f46b56960cafc5a2a5c2476c9ce5f7cf9c1 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:45:13 -0500 Subject: [PATCH 6/6] add master copy caching to other parts of app --- .../ui/menus/ManageDAO/ManageDAOMenu.tsx | 10 +++- .../DAO/loaders/useFractalGuardContracts.ts | 9 +++- src/hooks/DAO/loaders/useFractalModules.ts | 5 +- .../DAO/loaders/useGovernanceContracts.ts | 47 +++++++++---------- src/hooks/utils/cache/cacheDefaults.ts | 1 + src/hooks/utils/useGetMasterCopyAddress.ts | 0 src/utils/azorius.ts | 2 +- 7 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 src/hooks/utils/useGetMasterCopyAddress.ts diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index 5ce895a2e3..3b51aa0d4d 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -17,6 +17,7 @@ import { import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal'; import useUserERC721VotingTokens from '../../../../hooks/DAO/proposal/useUserERC721VotingTokens'; import useClawBack from '../../../../hooks/DAO/useClawBack'; +import { CacheKeys } from '../../../../hooks/utils/cache/cacheDefaults'; import { useLocalStorage } from '../../../../hooks/utils/cache/useLocalStorage'; import useBlockTimestamp from '../../../../hooks/utils/useBlockTimestamp'; import { useFractal } from '../../../../providers/App/AppProvider'; @@ -116,7 +117,9 @@ export function ManageDAOMenu({ 0 ) )[1]; - const cachedMasterCopyAddress = getValue('master_copy_of_' + votingContractAddress); + const cachedMasterCopyAddress = getValue( + CacheKeys.MASTER_COPY_PREFIX + votingContractAddress + ); let votingContractMasterCopyAddress = cachedMasterCopyAddress; if (!votingContractMasterCopyAddress) { const rpc = getEventRPC(zodiacModuleProxyFactoryContract); @@ -126,7 +129,10 @@ export function ManageDAOMenu({ .then(proxiesCreated => { return proxiesCreated[0].args.masterCopy; }); - setValue('master_copy_of_' + votingContractAddress, votingContractMasterCopyAddress); + setValue( + CacheKeys.MASTER_COPY_PREFIX + votingContractAddress, + votingContractMasterCopyAddress + ); } if ( diff --git a/src/hooks/DAO/loaders/useFractalGuardContracts.ts b/src/hooks/DAO/loaders/useFractalGuardContracts.ts index bd18afe9e0..4bee36e77f 100644 --- a/src/hooks/DAO/loaders/useFractalGuardContracts.ts +++ b/src/hooks/DAO/loaders/useFractalGuardContracts.ts @@ -14,6 +14,8 @@ import { FreezeGuardType, FreezeVotingType, } from '../../../types'; +import { CacheKeys } from '../../utils/cache/cacheDefaults'; +import { useLocalStorage } from '../../utils/cache/useLocalStorage'; import { useEthersProvider } from '../../utils/useEthersProvider'; import { FractalModuleData, FractalModuleType } from './../../../types/fractal'; export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: boolean }) => { @@ -36,8 +38,12 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: network: { chainId }, } = useEthersProvider(); + const { setValue, getValue } = useLocalStorage(); + const getMasterCopyAddress = useCallback( async (proxyAddress: string): Promise => { + const cachedValue = getValue(CacheKeys.MASTER_COPY_PREFIX + proxyAddress); + if (cachedValue) return cachedValue; const filter = getEventRPC( zodiacModuleProxyFactoryContract ).filters.ModuleProxyCreation(proxyAddress, null); @@ -45,10 +51,11 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: .queryFilter(filter) .then(proxiesCreated => { if (proxiesCreated.length === 0) return constants.AddressZero; + setValue(CacheKeys.MASTER_COPY_PREFIX + proxyAddress, proxiesCreated[0].args.masterCopy); return proxiesCreated[0].args.masterCopy; }); }, - [zodiacModuleProxyFactoryContract] + [zodiacModuleProxyFactoryContract, getValue, setValue] ); const loadFractalGuardContracts = useCallback( diff --git a/src/hooks/DAO/loaders/useFractalModules.ts b/src/hooks/DAO/loaders/useFractalModules.ts index 641fe9a175..a68ba409e7 100644 --- a/src/hooks/DAO/loaders/useFractalModules.ts +++ b/src/hooks/DAO/loaders/useFractalModules.ts @@ -4,6 +4,7 @@ import { useCallback } from 'react'; import { getEventRPC } from '../../../helpers'; import { useFractal } from '../../../providers/App/AppProvider'; import { FractalModuleData, FractalModuleType } from '../../../types'; +import { CacheKeys } from '../../utils/cache/cacheDefaults'; import { useLocalStorage } from './../../utils/cache/useLocalStorage'; export const useFractalModules = () => { @@ -20,12 +21,12 @@ export const useFractalModules = () => { async (_moduleAddresses: string[]) => { const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const getMasterCopyAddress = async (proxyAddress: string): Promise => { - const cachedValue = getValue('master_copy_of_' + proxyAddress); + const cachedValue = getValue(CacheKeys.MASTER_COPY_PREFIX + proxyAddress); if (cachedValue) return cachedValue; const filter = rpc.filters.ModuleProxyCreation(proxyAddress, null); return rpc.queryFilter(filter).then(proxiesCreated => { if (proxiesCreated.length === 0) return constants.AddressZero; - setValue('master_copy_of_' + proxyAddress, proxiesCreated[0].args.masterCopy); + setValue(CacheKeys.MASTER_COPY_PREFIX + proxyAddress, proxiesCreated[0].args.masterCopy); return proxiesCreated[0].args.masterCopy; }); }; diff --git a/src/hooks/DAO/loaders/useGovernanceContracts.ts b/src/hooks/DAO/loaders/useGovernanceContracts.ts index 405694ffd7..e68eac73e3 100644 --- a/src/hooks/DAO/loaders/useGovernanceContracts.ts +++ b/src/hooks/DAO/loaders/useGovernanceContracts.ts @@ -14,6 +14,7 @@ import { useFractal } from '../../../providers/App/AppProvider'; import { GovernanceContractAction } from '../../../providers/App/governanceContracts/action'; import { ContractConnection } from '../../../types'; import { getAzoriusModuleFromModules } from '../../../utils'; +import { CacheKeys } from '../../utils/cache/cacheDefaults'; import { useLocalStorage } from '../../utils/cache/useLocalStorage'; import { useEthersProvider } from '../../utils/useEthersProvider'; import useSignerOrProvider from '../../utils/useSignerOrProvider'; @@ -59,17 +60,9 @@ export const useGovernanceContracts = () => { ), asSigner: fractalAzoriusMasterCopyContract.asSigner.attach(azoriusModuleContract.address), }; - const cachedContractAddresses = getValue( - 'azorius_module_gov_' + azoriusModuleContract.address - ); - // if existing cached addresses are found, use them - let votingContractAddress: string | undefined = - cachedContractAddresses?.votingContractAddress; - - let votingContractMasterCopyAddress: string | undefined = - cachedContractAddresses?.votingContractMasterCopyAddress; - let govTokenAddress: string | undefined = cachedContractAddresses?.govTokenContractAddress; + let votingContractMasterCopyAddress: string | undefined; + let govTokenAddress: string | undefined; let ozLinearVotingContract: ContractConnection | undefined; let erc721LinearVotingContract: ContractConnection | undefined; @@ -77,22 +70,28 @@ export const useGovernanceContracts = () => { let underlyingTokenAddress: string | undefined; let lockReleaseContract: ContractConnection | null = null; - if (!votingContractAddress) { - // @dev assumes the first strategy is the voting contract - votingContractAddress = ( - await azoriusContract.asProvider.getStrategies( - '0x0000000000000000000000000000000000000001', - 0 - ) - )[1]; - } + // @dev assumes the first strategy is the voting contract + const votingContractAddress = ( + await azoriusContract.asProvider.getStrategies( + '0x0000000000000000000000000000000000000001', + 0 + ) + )[1]; if (!votingContractMasterCopyAddress) { - const rpc = getEventRPC(zodiacModuleProxyFactoryContract); - const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); - votingContractMasterCopyAddress = await rpc.queryFilter(filter).then(proxiesCreated => { - return proxiesCreated[0].args.masterCopy; - }); + const cachedValue = getValue(CacheKeys.MASTER_COPY_PREFIX + votingContractAddress); + votingContractMasterCopyAddress = cachedValue; + if (!cachedValue) { + const rpc = getEventRPC(zodiacModuleProxyFactoryContract); + const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); + votingContractMasterCopyAddress = await rpc.queryFilter(filter).then(proxiesCreated => { + setValue( + CacheKeys.MASTER_COPY_PREFIX + votingContractAddress, + proxiesCreated[0].args.masterCopy + ); + return proxiesCreated[0].args.masterCopy; + }); + } } if (votingContractMasterCopyAddress === linearVotingMasterCopyContract.asProvider.address) { diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index 3b58991ee2..efd89ad7ed 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -29,6 +29,7 @@ export enum CacheKeys { DAO_NAME_PREFIX = 'dao_name_', DECODED_TRANSACTION_PREFIX = 'decode_trans_', MULTISIG_METADATA_PREFIX = 'm_m_', + MASTER_COPY_PREFIX = 'master_copy_of_', } interface IndexedObject { diff --git a/src/hooks/utils/useGetMasterCopyAddress.ts b/src/hooks/utils/useGetMasterCopyAddress.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/utils/azorius.ts b/src/utils/azorius.ts index ef6b95cfeb..13c2a43416 100644 --- a/src/utils/azorius.ts +++ b/src/utils/azorius.ts @@ -104,7 +104,7 @@ export const getProposalVotes = async ( ...rest, voter, choice: VOTE_CHOICES[voteType], - }; + } as ProposalVote; // This bypasses the type check, but it's fine }); };