From 0c58b26fb8b47223781c153039c8dd69baaf1abe Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Mon, 12 Feb 2024 11:03:42 +0100 Subject: [PATCH] Modify getEventRPC to always return asProvider connection, swap most of the usages of asSigner contract reads whenever applicable --- src/components/Proposals/ProposalSummary.tsx | 2 +- .../ProposalVotes/context/VoteContext.tsx | 2 +- .../DaoDashboard/Info/InfoGovernance.tsx | 2 +- .../pages/DaoHierarchy/useFetchNodes.tsx | 6 +-- .../Signers/hooks/useRemoveSigner.ts | 4 +- .../ui/menus/ManageDAO/ManageDAOMenu.tsx | 9 +--- .../ui/proposal/useProposalCountdown.tsx | 4 +- src/helpers/crypto.ts | 29 ++---------- .../loaders/governance/useAzoriusProposals.ts | 39 +++++++--------- .../DAO/loaders/governance/useERC20Claim.ts | 11 +++-- .../governance/useERC20LinearStrategy.ts | 23 +++++----- .../loaders/governance/useERC20LinearToken.ts | 44 +++++++++---------- .../governance/useERC721LinearStrategy.ts | 21 ++++----- .../DAO/loaders/governance/useLockRelease.ts | 29 +++++------- src/hooks/DAO/loaders/useFractalFreeze.ts | 42 ++++++++---------- .../DAO/loaders/useFractalGuardContracts.ts | 15 +++---- src/hooks/DAO/loaders/useFractalModules.ts | 16 +++---- .../DAO/loaders/useGovernanceContracts.ts | 9 ++-- src/hooks/DAO/proposal/useSubmitProposal.ts | 14 +++--- .../DAO/proposal/useUpdateProposalState.ts | 2 +- .../DAO/proposal/useUserERC721VotingTokens.ts | 2 +- src/hooks/DAO/useBuildDAOTx.ts | 2 +- src/hooks/DAO/useCreateSubDAOProposal.ts | 9 ++-- src/hooks/DAO/useDAOName.ts | 4 +- src/hooks/DAO/useDeployAzorius.ts | 40 ++++++++--------- src/hooks/utils/useSafeTransactions.ts | 2 +- src/utils/azorius.ts | 6 +-- 27 files changed, 167 insertions(+), 221 deletions(-) diff --git a/src/components/Proposals/ProposalSummary.tsx b/src/components/Proposals/ProposalSummary.tsx index 3357332046..bfc3dff82f 100644 --- a/src/components/Proposals/ProposalSummary.tsx +++ b/src/components/Proposals/ProposalSummary.tsx @@ -62,7 +62,7 @@ export default function ProposalSummary({ useEffect(() => { async function loadProposalVotingWeight() { if (tokenContract && address) { - const pastVotingWeight = await tokenContract.asSigner.getPastVotes(address, startBlock); + const pastVotingWeight = await tokenContract.asProvider.getPastVotes(address, startBlock); setProposalsERC20VotingWeight( pastVotingWeight.div(votesTokenDecimalsDenominator).toString() ); diff --git a/src/components/Proposals/ProposalVotes/context/VoteContext.tsx b/src/components/Proposals/ProposalVotes/context/VoteContext.tsx index bf199e312c..2acb83b1c1 100644 --- a/src/components/Proposals/ProposalVotes/context/VoteContext.tsx +++ b/src/components/Proposals/ProposalVotes/context/VoteContext.tsx @@ -94,7 +94,7 @@ export function VoteContextProvider({ } else if (type === GovernanceType.AZORIUS_ERC20) { newCanVote = ( - await ozLinearVotingContract!.asSigner.getVotingWeight( + await ozLinearVotingContract!.asProvider.getVotingWeight( user.address, proposal.proposalId ) diff --git a/src/components/pages/DaoDashboard/Info/InfoGovernance.tsx b/src/components/pages/DaoDashboard/Info/InfoGovernance.tsx index a4b344918c..95a7e8471c 100644 --- a/src/components/pages/DaoDashboard/Info/InfoGovernance.tsx +++ b/src/components/pages/DaoDashboard/Info/InfoGovernance.tsx @@ -31,7 +31,7 @@ export function InfoGovernance() { }; if (freezeGuardType == FreezeGuardType.MULTISIG) { if (freezeGuardContract) { - const freezeGuard = freezeGuardContract.asSigner as MultisigFreezeGuard; + const freezeGuard = freezeGuardContract.asProvider as MultisigFreezeGuard; setTimelockPeriod(await formatBlocks(await freezeGuard.timelockPeriod())); setExecutionPeriod(await formatBlocks(await freezeGuard.executionPeriod())); } diff --git a/src/components/pages/DaoHierarchy/useFetchNodes.tsx b/src/components/pages/DaoHierarchy/useFetchNodes.tsx index 788554cbbc..2e93232e74 100644 --- a/src/components/pages/DaoHierarchy/useFetchNodes.tsx +++ b/src/components/pages/DaoHierarchy/useFetchNodes.tsx @@ -39,7 +39,7 @@ export function useFetchNodes(address?: string) { async (safeInfo?: Partial) => { if (safeInfo && safeInfo.guard && multisigFreezeGuardMasterCopyContract) { if (safeInfo.guard !== ethers.constants.AddressZero) { - const guard = multisigFreezeGuardMasterCopyContract.asSigner.attach(safeInfo.guard); + const guard = multisigFreezeGuardMasterCopyContract.asProvider.attach(safeInfo.guard); const guardOwner = await guard.owner(); if (guardOwner !== safeInfo.address) { return guardOwner; @@ -53,13 +53,13 @@ export function useFetchNodes(address?: string) { azoriusFreezeGuardMasterCopyContract && fractalAzoriusMasterCopyContract ) { - const azoriusContract = fractalAzoriusMasterCopyContract?.asSigner.attach( + const azoriusContract = fractalAzoriusMasterCopyContract?.asProvider.attach( azoriusModule.moduleAddress ); const azoriusGuardAddress = await azoriusContract.getGuard(); if (azoriusGuardAddress !== ethers.constants.AddressZero) { const guard = - azoriusFreezeGuardMasterCopyContract.asSigner.attach(azoriusGuardAddress); + azoriusFreezeGuardMasterCopyContract.asProvider.attach(azoriusGuardAddress); const guardOwner = await guard.owner(); if (guardOwner !== safeInfo.address) { return guardOwner; diff --git a/src/components/pages/DaoSettings/components/Signers/hooks/useRemoveSigner.ts b/src/components/pages/DaoSettings/components/Signers/hooks/useRemoveSigner.ts index 85fdfc5833..da247c3edd 100644 --- a/src/components/pages/DaoSettings/components/Signers/hooks/useRemoveSigner.ts +++ b/src/components/pages/DaoSettings/components/Signers/hooks/useRemoveSigner.ts @@ -28,7 +28,7 @@ const useRemoveSigner = ({ const description = 'Remove Signers'; const calldatas = [ - safeSingletonContract.asSigner.interface.encodeFunctionData('removeOwner', [ + safeSingletonContract.asProvider.interface.encodeFunctionData('removeOwner', [ prevSigner, signerToRemove, BigNumber.from(threshold), @@ -54,7 +54,7 @@ const useRemoveSigner = ({ failedToastMessage: t('removeSignerFailureToastMessage'), }); }, [ - safeSingletonContract.asSigner.interface, + safeSingletonContract.asProvider.interface, prevSigner, signerToRemove, threshold, diff --git a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx index 6f4304e10d..85c412425d 100644 --- a/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx +++ b/src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx @@ -19,7 +19,6 @@ import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal' import useUserERC721VotingTokens from '../../../../hooks/DAO/proposal/useUserERC721VotingTokens'; import useClawBack from '../../../../hooks/DAO/useClawBack'; import useBlockTimestamp from '../../../../hooks/utils/useBlockTimestamp'; -import { useEthersProvider } from '../../../../hooks/utils/useEthersProvider'; import { useFractal } from '../../../../providers/App/AppProvider'; import { FractalGuardContracts, @@ -70,9 +69,6 @@ export function ManageDAOMenu({ } = useFractal(); const currentTime = BigNumber.from(useBlockTimestamp()); const { push } = useRouter(); - const { - network: { chainId }, - } = useEthersProvider(); const safeAddress = fractalNode?.daoAddress; const { getCanUserCreateProposal } = useSubmitProposal(); @@ -111,12 +107,12 @@ export function ManageDAOMenu({ azoriusModule.moduleAddress ), }; - const votingContractAddress = await getEventRPC(azoriusContract, chainId) + const votingContractAddress = await getEventRPC(azoriusContract) .queryFilter((azoriusModule.moduleContract as Azorius).filters.EnabledStrategy()) .then(strategiesEnabled => { return strategiesEnabled[0].args.strategy; }); - const rpc = getEventRPC(zodiacModuleProxyFactoryContract, chainId); + const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); const votingContractMasterCopyAddress = await rpc .queryFilter(filter) @@ -143,7 +139,6 @@ export function ManageDAOMenu({ loadGovernanceType(); }, [ - chainId, fractalAzoriusMasterCopyContract, linearVotingERC721MasterCopyContract, linearVotingMasterCopyContract, diff --git a/src/components/ui/proposal/useProposalCountdown.tsx b/src/components/ui/proposal/useProposalCountdown.tsx index 0a335c676b..32759d4227 100644 --- a/src/components/ui/proposal/useProposalCountdown.tsx +++ b/src/components/ui/proposal/useProposalCountdown.tsx @@ -97,9 +97,9 @@ export function useProposalCountdown(proposal: FractalProposal) { async function getCountdown() { const freezeGuard = freezeGuardType === FreezeGuardType.MULTISIG - ? (freezeGuardContract?.asSigner as MultisigFreezeGuard) + ? (freezeGuardContract?.asProvider as MultisigFreezeGuard) : freezeGuardType === FreezeGuardType.AZORIUS - ? (freezeGuardContract?.asSigner as AzoriusFreezeGuard) + ? (freezeGuardContract?.asProvider as AzoriusFreezeGuard) : undefined; const isSafeGuard = freezeGuardType === FreezeGuardType.MULTISIG; diff --git a/src/helpers/crypto.ts b/src/helpers/crypto.ts index 66b9238171..7ce6b98168 100644 --- a/src/helpers/crypto.ts +++ b/src/helpers/crypto.ts @@ -1,6 +1,6 @@ import { TypedDataSigner } from '@ethersproject/abstract-signer'; import { BigNumber, Contract, constants, utils, BigNumberish, Signer } from 'ethers'; -import { sepolia, mainnet, polygon } from 'wagmi/chains'; +import { sepolia, mainnet } from 'wagmi/chains'; import { ContractConnection } from '../types'; import { MetaTransaction, SafePostTransaction, SafeTransaction } from '../types/transaction'; @@ -183,31 +183,10 @@ export const encodeMultiSend = (txs: MetaTransaction[]): string => { }; /** - * Explained by our future overlord, ChatGPT: - * - * On networks like Polygon where block times are very short, events cannot be - * looked up without specifying a starting block number. If a user connects their - * Metamask wallet to Polygon as a public provider, attempting to load events in - * this way would cause it to fail, resulting in reduced performance and a high - * probability of failure. - * - * While power users can swap out the remote procedure call (RPC) in their - * Metamask for a custom one, this option is not feasible for most users. As a - * solution, the contract can be used as a provider with our own keys, allowing - * us to use our own rate limits. - * - * This gave rise to the idea of updating the useSafeContracts hook to enable - * connections as signers (using a connected wallet) or using our own keys as - * providers. The asSigner option is essentially connecting as a signer or provider, - * making it the ideal choice for most normal use cases. + * TODO: Remove getEventRPC usage as whole */ -export function getEventRPC(connection: ContractConnection, chainId: number): T { - switch (chainId) { - case polygon.id: - return connection.asProvider; - default: - return connection.asSigner; - } +export function getEventRPC(connection: ContractConnection): T { + return connection.asProvider; } export function supportsENS(chainId: number): boolean { diff --git a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts index fe3a29c88f..3f8c43390a 100644 --- a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts +++ b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts @@ -34,9 +34,6 @@ export const useAzoriusProposals = () => { } }, [ozLinearVotingContract, erc721LinearVotingContract]); const provider = useEthersProvider(); - const { - network: { chainId }, - } = provider; const decode = useSafeDecoder(); const decodeTransactions = useCallback( async (transactions: MetaTransaction[]) => { @@ -58,14 +55,13 @@ export const useAzoriusProposals = () => { ) { return []; } - const rpc = getEventRPC(azoriusContract, chainId); + const rpc = getEventRPC(azoriusContract); const proposalCreatedFilter = rpc.filters.ProposalCreated(); const proposalCreatedEvents = await rpc.queryFilter(proposalCreatedFilter); const strategyContract = getEventRPC( - ozLinearVotingContract ?? erc721LinearVotingContract!, - chainId + ozLinearVotingContract ?? erc721LinearVotingContract! ); const proposals = await Promise.all( @@ -97,7 +93,6 @@ export const useAzoriusProposals = () => { ); return proposals; }, [ - chainId, decodeTransactions, ozLinearVotingContract, erc721LinearVotingContract, @@ -132,8 +127,7 @@ export const useAzoriusProposals = () => { }; } const strategyContract = getEventRPC( - ozLinearVotingContract ?? erc721LinearVotingContract!, - chainId + ozLinearVotingContract ?? erc721LinearVotingContract! ).attach(strategyAddress); const func = async () => { return mapProposalCreatedEventToProposal( @@ -157,7 +151,6 @@ export const useAzoriusProposals = () => { erc721LinearVotingContract, azoriusContract, provider, - chainId, decodeTransactions, action, requestWithRetries, @@ -170,7 +163,7 @@ export const useAzoriusProposals = () => { if (!ozLinearVotingContract || !strategyType) { return; } - const strategyContract = getEventRPC(ozLinearVotingContract, chainId); + const strategyContract = getEventRPC(ozLinearVotingContract); const votesSummary = await getProposalVotesSummary( strategyContract, strategyType, @@ -188,7 +181,7 @@ export const useAzoriusProposals = () => { }, }); }, - [ozLinearVotingContract, chainId, action, strategyType] + [ozLinearVotingContract, action, strategyType] ); const erc721ProposalVotedEventListener: TypedListener = useCallback( @@ -196,7 +189,7 @@ export const useAzoriusProposals = () => { if (!erc721LinearVotingContract || !strategyType) { return; } - const strategyContract = getEventRPC(erc721LinearVotingContract, chainId); + const strategyContract = getEventRPC(erc721LinearVotingContract); const votesSummary = await getProposalVotesSummary( strategyContract, strategyType, @@ -215,38 +208,38 @@ export const useAzoriusProposals = () => { }, }); }, - [erc721LinearVotingContract, chainId, action, strategyType] + [erc721LinearVotingContract, action, strategyType] ); useEffect(() => { if (!azoriusContract) { return; } - const proposalCreatedFilter = azoriusContract.asSigner.filters.ProposalCreated(); + const proposalCreatedFilter = azoriusContract.asProvider.filters.ProposalCreated(); - azoriusContract.asSigner.on(proposalCreatedFilter, proposalCreatedListener); + azoriusContract.asProvider.on(proposalCreatedFilter, proposalCreatedListener); return () => { - azoriusContract.asSigner.off(proposalCreatedFilter, proposalCreatedListener); + azoriusContract.asProvider.off(proposalCreatedFilter, proposalCreatedListener); }; }, [azoriusContract, proposalCreatedListener]); useEffect(() => { if (ozLinearVotingContract) { - const votedEvent = ozLinearVotingContract.asSigner.filters.Voted(); + const votedEvent = ozLinearVotingContract.asProvider.filters.Voted(); - ozLinearVotingContract.asSigner.on(votedEvent, erc20ProposalVotedEventListener); + ozLinearVotingContract.asProvider.on(votedEvent, erc20ProposalVotedEventListener); return () => { - ozLinearVotingContract.asSigner.off(votedEvent, erc20ProposalVotedEventListener); + ozLinearVotingContract.asProvider.off(votedEvent, erc20ProposalVotedEventListener); }; } else if (erc721LinearVotingContract) { - const votedEvent = erc721LinearVotingContract.asSigner.filters.Voted(); + const votedEvent = erc721LinearVotingContract.asProvider.filters.Voted(); - erc721LinearVotingContract.asSigner.on(votedEvent, erc721ProposalVotedEventListener); + erc721LinearVotingContract.asProvider.on(votedEvent, erc721ProposalVotedEventListener); return () => { - erc721LinearVotingContract.asSigner.off(votedEvent, erc721ProposalVotedEventListener); + erc721LinearVotingContract.asProvider.off(votedEvent, erc721ProposalVotedEventListener); }; } }, [ diff --git a/src/hooks/DAO/loaders/governance/useERC20Claim.ts b/src/hooks/DAO/loaders/governance/useERC20Claim.ts index bc9272cc0c..a9fc4e0424 100644 --- a/src/hooks/DAO/loaders/governance/useERC20Claim.ts +++ b/src/hooks/DAO/loaders/governance/useERC20Claim.ts @@ -16,10 +16,10 @@ export function useERC20Claim() { const loadTokenClaimContract = useCallback(async () => { if (!claimingMasterCopyContract || !tokenContract) return; - const approvalFilter = tokenContract.asSigner.filters.Approval(); - const approvals = await tokenContract.asSigner.queryFilter(approvalFilter); + const approvalFilter = tokenContract.asProvider.filters.Approval(); + const approvals = await tokenContract.asProvider.queryFilter(approvalFilter); if (!approvals.length) return; - const possibleTokenClaimContract = claimingMasterCopyContract.asSigner.attach( + const possibleTokenClaimContract = claimingMasterCopyContract.asProvider.attach( approvals[0].args[1] ); const tokenClaimFilter = possibleTokenClaimContract.filters.ERC20ClaimCreated(); @@ -27,7 +27,10 @@ export function useERC20Claim() { .queryFilter(tokenClaimFilter) .catch(() => []); - if (!tokenClaimArray.length || tokenClaimArray[0].args[1] === tokenContract.asSigner.address) { + if ( + !tokenClaimArray.length || + tokenClaimArray[0].args[1] === tokenContract.asProvider.address + ) { return; } // action to governance diff --git a/src/hooks/DAO/loaders/governance/useERC20LinearStrategy.ts b/src/hooks/DAO/loaders/governance/useERC20LinearStrategy.ts index b57fce3cd3..4909d9e6df 100644 --- a/src/hooks/DAO/loaders/governance/useERC20LinearStrategy.ts +++ b/src/hooks/DAO/loaders/governance/useERC20LinearStrategy.ts @@ -19,9 +19,6 @@ export const useERC20LinearStrategy = () => { action, } = useFractal(); const provider = useEthersProvider(); - const { - network: { chainId }, - } = provider; const { getTimeDuration } = useTimeHelpers(); const loadERC20Strategy = useCallback(async () => { @@ -30,10 +27,10 @@ export const useERC20LinearStrategy = () => { } const [votingPeriodBlocks, quorumNumerator, quorumDenominator, timeLockPeriod] = await Promise.all([ - ozLinearVotingContract.asSigner.votingPeriod(), - ozLinearVotingContract.asSigner.quorumNumerator(), - ozLinearVotingContract.asSigner.QUORUM_DENOMINATOR(), - azoriusContract.asSigner.timelockPeriod(), + ozLinearVotingContract.asProvider.votingPeriod(), + ozLinearVotingContract.asProvider.quorumNumerator(), + ozLinearVotingContract.asProvider.QUORUM_DENOMINATOR(), + azoriusContract.asProvider.timelockPeriod(), ]); const quorumPercentage = quorumNumerator.mul(100).div(quorumDenominator); @@ -61,7 +58,7 @@ export const useERC20LinearStrategy = () => { if (!ozLinearVotingContract) { return; } - const rpc = getEventRPC(ozLinearVotingContract, chainId); + const rpc = getEventRPC(ozLinearVotingContract); const votingPeriodfilter = rpc.filters.VotingPeriodUpdated(); const listener: TypedListener = votingPeriod => { action.dispatch({ @@ -73,13 +70,13 @@ export const useERC20LinearStrategy = () => { return () => { rpc.off(votingPeriodfilter, listener); }; - }, [ozLinearVotingContract, chainId, action]); + }, [ozLinearVotingContract, action]); useEffect(() => { if (!ozLinearVotingContract) { return; } - const rpc = getEventRPC(ozLinearVotingContract, chainId); + const rpc = getEventRPC(ozLinearVotingContract); const quorumNumeratorUpdatedFilter = rpc.filters.QuorumNumeratorUpdated(); const quorumNumeratorUpdatedListener: TypedListener< QuorumNumeratorUpdatedEvent @@ -93,13 +90,13 @@ export const useERC20LinearStrategy = () => { return () => { rpc.off(quorumNumeratorUpdatedFilter, quorumNumeratorUpdatedListener); }; - }, [ozLinearVotingContract, chainId, action]); + }, [ozLinearVotingContract, action]); useEffect(() => { if (!azoriusContract) { return; } - const rpc = getEventRPC(azoriusContract, chainId); + const rpc = getEventRPC(azoriusContract); const timeLockPeriodFilter = rpc.filters.TimelockPeriodUpdated(); const timelockPeriodListener: TypedListener = timelockPeriod => { action.dispatch({ @@ -111,7 +108,7 @@ export const useERC20LinearStrategy = () => { return () => { rpc.off(timeLockPeriodFilter, timelockPeriodListener); }; - }, [azoriusContract, chainId, action]); + }, [azoriusContract, action]); return loadERC20Strategy; }; diff --git a/src/hooks/DAO/loaders/governance/useERC20LinearToken.ts b/src/hooks/DAO/loaders/governance/useERC20LinearToken.ts index 95a1695c94..c254ff9d04 100644 --- a/src/hooks/DAO/loaders/governance/useERC20LinearToken.ts +++ b/src/hooks/DAO/loaders/governance/useERC20LinearToken.ts @@ -4,7 +4,7 @@ import { useCallback, useEffect, useRef } from 'react'; import { getEventRPC } from '../../../../helpers'; import { useFractal } from '../../../../providers/App/AppProvider'; import { FractalGovernanceAction } from '../../../../providers/App/governance/action'; -import { useEthersProvider } from '../../../utils/useEthersProvider'; + export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) => { const isTokenLoaded = useRef(false); const tokenAccount = useRef(); @@ -16,20 +16,16 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = } = useFractal(); const account = user.address; - const { - network: { chainId }, - } = useEthersProvider(); - const loadERC20Token = useCallback(async () => { if (!tokenContract) { return; } - const tokenAddress = tokenContract.asSigner.address; + const tokenAddress = tokenContract.asProvider.address; const [tokenName, tokenSymbol, tokenDecimals, totalSupply] = await Promise.all([ - tokenContract.asSigner.name(), - tokenContract.asSigner.symbol(), - tokenContract.asSigner.decimals(), - tokenContract.asSigner.totalSupply(), + tokenContract.asProvider.name(), + tokenContract.asProvider.symbol(), + tokenContract.asProvider.decimals(), + tokenContract.asProvider.totalSupply(), ]); const tokenData = { name: tokenName, @@ -47,7 +43,7 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = return; } - const erc20WrapperContract = tokenContract.asSigner.attach(underlyingTokenAddress); + const erc20WrapperContract = tokenContract.asProvider.attach(underlyingTokenAddress); const [tokenName, tokenSymbol] = await Promise.all([ erc20WrapperContract.name(), @@ -71,15 +67,15 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = } // @todo We could probably save on some requests here. const [tokenBalance, tokenDelegatee, tokenVotingWeight] = await Promise.all([ - tokenContract.asSigner.balanceOf(account), - tokenContract.asSigner.delegates(account), - tokenContract.asSigner.getVotes(account), + tokenContract.asProvider.balanceOf(account), + tokenContract.asProvider.delegates(account), + tokenContract.asProvider.getVotes(account), ]); let delegateChangeEvents: DelegateChangedEvent[]; try { - delegateChangeEvents = await tokenContract.asSigner.queryFilter( - tokenContract.asSigner.filters.DelegateChanged() + delegateChangeEvents = await tokenContract.asProvider.queryFilter( + tokenContract.asProvider.filters.DelegateChanged() ); } catch (e) { delegateChangeEvents = []; @@ -102,10 +98,10 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = if ( tokenContract && isTokenLoaded.current && - tokenAccount.current !== account + tokenContract.asSigner.address && + tokenAccount.current !== account + tokenContract.asProvider.address && onMount ) { - tokenAccount.current = account + tokenContract.asSigner.address; + tokenAccount.current = account + tokenContract.asProvider.address; loadERC20TokenAccountData(); } }, [account, tokenContract, onMount, loadERC20TokenAccountData]); @@ -114,33 +110,33 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = if (!tokenContract || !onMount) { return; } - const rpc = getEventRPC(tokenContract, chainId); + const rpc = getEventRPC(tokenContract); const delegateVotesChangedfilter = rpc.filters.DelegateVotesChanged(); rpc.on(delegateVotesChangedfilter, loadERC20TokenAccountData); return () => { rpc.off(delegateVotesChangedfilter, loadERC20TokenAccountData); }; - }, [tokenContract, chainId, loadERC20TokenAccountData, onMount]); + }, [tokenContract, loadERC20TokenAccountData, onMount]); useEffect(() => { if (!tokenContract || !onMount) { return; } - const rpc = getEventRPC(tokenContract, chainId); + const rpc = getEventRPC(tokenContract); const delegateChangedfilter = rpc.filters.DelegateChanged(); rpc.on(delegateChangedfilter, loadERC20TokenAccountData); return () => { rpc.off(delegateChangedfilter, loadERC20TokenAccountData); }; - }, [tokenContract, chainId, loadERC20TokenAccountData, onMount]); + }, [tokenContract, loadERC20TokenAccountData, onMount]); useEffect(() => { if (!tokenContract || !account || !onMount) { return; } - const rpc = getEventRPC(tokenContract, chainId); + const rpc = getEventRPC(tokenContract); const filterTo = rpc.filters.Transfer(null, account); const filterFrom = rpc.filters.Transfer(account, null); rpc.on(filterTo, loadERC20TokenAccountData); @@ -149,7 +145,7 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) = rpc.off(filterTo, loadERC20TokenAccountData); rpc.off(filterFrom, loadERC20TokenAccountData); }; - }, [tokenContract, chainId, account, onMount, loadERC20TokenAccountData]); + }, [tokenContract, account, onMount, loadERC20TokenAccountData]); return { loadERC20Token, loadUnderlyingERC20Token, loadERC20TokenAccountData }; }; diff --git a/src/hooks/DAO/loaders/governance/useERC721LinearStrategy.ts b/src/hooks/DAO/loaders/governance/useERC721LinearStrategy.ts index 23fa183506..aac113ee03 100644 --- a/src/hooks/DAO/loaders/governance/useERC721LinearStrategy.ts +++ b/src/hooks/DAO/loaders/governance/useERC721LinearStrategy.ts @@ -21,9 +21,6 @@ export const useERC721LinearStrategy = () => { action, } = useFractal(); const provider = useEthersProvider(); - const { - network: { chainId }, - } = provider; const { getTimeDuration } = useTimeHelpers(); const loadERC721Strategy = useCallback(async () => { @@ -31,9 +28,9 @@ export const useERC721LinearStrategy = () => { return {}; } const [votingPeriodBlocks, quorumThreshold, timeLockPeriod] = await Promise.all([ - erc721LinearVotingContract.asSigner.votingPeriod(), - erc721LinearVotingContract.asSigner.quorumThreshold(), - azoriusContract.asSigner.timelockPeriod(), + erc721LinearVotingContract.asProvider.votingPeriod(), + erc721LinearVotingContract.asProvider.quorumThreshold(), + azoriusContract.asProvider.timelockPeriod(), ]); const votingPeriodValue = await blocksToSeconds(votingPeriodBlocks, provider); @@ -60,7 +57,7 @@ export const useERC721LinearStrategy = () => { if (!erc721LinearVotingContract) { return; } - const rpc = getEventRPC(erc721LinearVotingContract, chainId); + const rpc = getEventRPC(erc721LinearVotingContract); const votingPeriodfilter = rpc.filters.VotingPeriodUpdated(); const listener: TypedListener = votingPeriod => { action.dispatch({ @@ -72,13 +69,13 @@ export const useERC721LinearStrategy = () => { return () => { rpc.off(votingPeriodfilter, listener); }; - }, [erc721LinearVotingContract, chainId, action]); + }, [erc721LinearVotingContract, action]); useEffect(() => { if (!erc721LinearVotingContract) { return; } - const rpc = getEventRPC(erc721LinearVotingContract, chainId); + const rpc = getEventRPC(erc721LinearVotingContract); const quorumThresholdUpdatedFilter = rpc.filters.QuorumThresholdUpdated(); const quorumThresholdUpdatedListener: TypedListener< QuorumThresholdUpdatedEvent @@ -92,13 +89,13 @@ export const useERC721LinearStrategy = () => { return () => { rpc.off(quorumThresholdUpdatedFilter, quorumThresholdUpdatedListener); }; - }, [erc721LinearVotingContract, chainId, action]); + }, [erc721LinearVotingContract, action]); useEffect(() => { if (!azoriusContract) { return; } - const rpc = getEventRPC(azoriusContract, chainId); + const rpc = getEventRPC(azoriusContract); const timeLockPeriodFilter = rpc.filters.TimelockPeriodUpdated(); const timelockPeriodListener: TypedListener = timelockPeriod => { action.dispatch({ @@ -110,7 +107,7 @@ export const useERC721LinearStrategy = () => { return () => { rpc.off(timeLockPeriodFilter, timelockPeriodListener); }; - }, [azoriusContract, chainId, action]); + }, [azoriusContract, action]); return loadERC721Strategy; }; diff --git a/src/hooks/DAO/loaders/governance/useLockRelease.ts b/src/hooks/DAO/loaders/governance/useLockRelease.ts index 439eba7247..546f959b89 100644 --- a/src/hooks/DAO/loaders/governance/useLockRelease.ts +++ b/src/hooks/DAO/loaders/governance/useLockRelease.ts @@ -4,7 +4,6 @@ import { LockRelease } from '../../../../assets/typechain-types/dcnt'; import { getEventRPC } from '../../../../helpers'; import { useFractal } from '../../../../providers/App/AppProvider'; import { DecentGovernanceAction } from '../../../../providers/App/governance/action'; -import { useEthersProvider } from '../../../utils/useEthersProvider'; /** * @link https://github.com/decent-dao/dcnt/blob/master/contracts/LockRelease.sol @@ -21,10 +20,6 @@ export const useLockRelease = ({ onMount = true }: { onMount?: boolean }) => { } = useFractal(); const account = user.address; - const { - network: { chainId }, - } = useEthersProvider(); - const loadLockedVotesToken = useCallback(async () => { if (!lockReleaseContract || !account) { action.dispatch({ type: DecentGovernanceAction.RESET_LOCKED_TOKEN_ACCOUNT_DATA }); @@ -32,16 +27,16 @@ export const useLockRelease = ({ onMount = true }: { onMount?: boolean }) => { } const [tokenAmountTotal, tokenAmountReleased, tokenDelegatee, tokenVotingWeight] = await Promise.all([ - lockReleaseContract.asSigner.getTotal(account), - lockReleaseContract.asSigner.getReleased(account), - lockReleaseContract.asSigner.delegates(account), - lockReleaseContract.asSigner.getVotes(account), + lockReleaseContract.asProvider.getTotal(account), + lockReleaseContract.asProvider.getReleased(account), + lockReleaseContract.asProvider.delegates(account), + lockReleaseContract.asProvider.getVotes(account), ]); let delegateChangeEvents: DelegateChangedEvent[]; try { - delegateChangeEvents = await lockReleaseContract.asSigner.queryFilter( - lockReleaseContract.asSigner.filters.DelegateChanged() + delegateChangeEvents = await lockReleaseContract.asProvider.queryFilter( + lockReleaseContract.asProvider.filters.DelegateChanged() ); } catch (e) { delegateChangeEvents = []; @@ -63,10 +58,10 @@ export const useLockRelease = ({ onMount = true }: { onMount?: boolean }) => { if ( lockReleaseContract && isTokenLoaded.current && - tokenAccount.current !== account + lockReleaseContract.asSigner.address && + tokenAccount.current !== account + lockReleaseContract.asProvider.address && onMount ) { - tokenAccount.current = account + lockReleaseContract.asSigner.address; + tokenAccount.current = account + lockReleaseContract.asProvider.address; loadLockedVotesToken(); } }, [account, lockReleaseContract, onMount, loadLockedVotesToken]); @@ -75,27 +70,27 @@ export const useLockRelease = ({ onMount = true }: { onMount?: boolean }) => { if (!lockReleaseContract || !onMount) { return; } - const rpc = getEventRPC(lockReleaseContract, chainId); + const rpc = getEventRPC(lockReleaseContract); const delegateVotesChangedfilter = rpc.filters.DelegateVotesChanged(); rpc.on(delegateVotesChangedfilter, loadLockedVotesToken); return () => { rpc.off(delegateVotesChangedfilter, loadLockedVotesToken); }; - }, [lockReleaseContract, chainId, loadLockedVotesToken, onMount]); + }, [lockReleaseContract, loadLockedVotesToken, onMount]); useEffect(() => { if (!lockReleaseContract || !onMount) { return; } - const rpc = getEventRPC(lockReleaseContract, chainId); + const rpc = getEventRPC(lockReleaseContract); const delegateChangedfilter = rpc.filters.DelegateChanged(); rpc.on(delegateChangedfilter, loadLockedVotesToken); return () => { rpc.off(delegateChangedfilter, loadLockedVotesToken); }; - }, [lockReleaseContract, chainId, loadLockedVotesToken, onMount]); + }, [lockReleaseContract, loadLockedVotesToken, onMount]); return { loadLockedVotesToken }; }; diff --git a/src/hooks/DAO/loaders/useFractalFreeze.ts b/src/hooks/DAO/loaders/useFractalFreeze.ts index 56c1a70974..4f8bdff7a9 100644 --- a/src/hooks/DAO/loaders/useFractalFreeze.ts +++ b/src/hooks/DAO/loaders/useFractalFreeze.ts @@ -46,39 +46,36 @@ export const useFractalFreeze = ({ ); const provider = useEthersProvider(); - const { - network: { chainId }, - } = provider; const loadFractalFreezeGuard = useCallback( async ({ freezeVotingContract, freezeVotingType: freezeVotingType }: FractalGuardContracts) => { if (freezeVotingType == null || !freezeVotingContract || !account) return; let userHasVotes: boolean = false; const freezeCreatedBlock = await ( - freezeVotingContract!.asSigner as + freezeVotingContract!.asProvider as | ERC20FreezeVoting | ERC721FreezeVoting | MultisigFreezeVoting ).freezeProposalCreatedBlock(); - const freezeVotesThreshold = await freezeVotingContract!.asSigner.freezeVotesThreshold(); + const freezeVotesThreshold = await freezeVotingContract!.asProvider.freezeVotesThreshold(); const freezeProposalCreatedBlock = - await freezeVotingContract!.asSigner.freezeProposalCreatedBlock(); + await freezeVotingContract!.asProvider.freezeProposalCreatedBlock(); const freezeProposalCreatedTime = await getTimeStamp(freezeProposalCreatedBlock, provider); const freezeProposalVoteCount = - await freezeVotingContract!.asSigner.freezeProposalVoteCount(); - const freezeProposalBlock = await freezeVotingContract!.asSigner.freezeProposalPeriod(); + await freezeVotingContract!.asProvider.freezeProposalVoteCount(); + const freezeProposalBlock = await freezeVotingContract!.asProvider.freezeProposalPeriod(); // length of time to vote on freeze const freezeProposalPeriod = await blocksToSeconds(freezeProposalBlock, provider); - const freezePeriodBlock = await freezeVotingContract!.asSigner.freezePeriod(); + const freezePeriodBlock = await freezeVotingContract!.asProvider.freezePeriod(); // length of time frozen for in seconds const freezePeriod = await blocksToSeconds(freezePeriodBlock, provider); - const userHasFreezeVoted = await freezeVotingContract!.asSigner.userHasFreezeVoted( + const userHasFreezeVoted = await freezeVotingContract!.asProvider.userHasFreezeVoted( account || constants.AddressZero, freezeCreatedBlock ); - const isFrozen = await freezeVotingContract!.asSigner.isFrozen(); + const isFrozen = await freezeVotingContract!.asProvider.isFrozen(); const freezeGuard = { freezeVotesThreshold, @@ -91,14 +88,14 @@ export const useFractalFreeze = ({ }; if (freezeVotingType === FreezeVotingType.MULTISIG) { - const safeContract = safeSingletonContract!.asSigner.attach( - await (freezeVotingContract!.asSigner as MultisigFreezeVoting).parentGnosisSafe() + const safeContract = safeSingletonContract!.asProvider.attach( + await (freezeVotingContract!.asProvider as MultisigFreezeVoting).parentGnosisSafe() ); const owners = await safeContract.getOwners(); userHasVotes = owners.find(owner => owner === account) !== undefined; } else if (freezeVotingType === FreezeVotingType.ERC20) { - const votesTokenContract = votesTokenMasterCopyContract!.asSigner.attach( - await (freezeVotingContract!.asSigner as ERC20FreezeVoting).votesERC20() + const votesTokenContract = votesTokenMasterCopyContract!.asProvider.attach( + await (freezeVotingContract!.asProvider as ERC20FreezeVoting).votesERC20() ); const currentTimestamp = await getTimeStamp('latest', provider); const isFreezeActive = @@ -159,9 +156,9 @@ export const useFractalFreeze = ({ guardContracts.freezeVotingType !== null && !!guardContracts.freezeVotingContract && loadOnMount && - guardContracts.freezeVotingContract.asSigner.address !== loadKey.current + guardContracts.freezeVotingContract.asProvider.address !== loadKey.current ) { - loadKey.current = guardContracts.freezeVotingContract.asSigner.address; + loadKey.current = guardContracts.freezeVotingContract.asProvider.address; setFractalFreezeGuard(guardContracts); } }, [setFractalFreezeGuard, guardContracts, daoAddress, loadOnMount]); @@ -190,27 +187,24 @@ export const useFractalFreeze = ({ if (isFreezeSet.current && freezeVotingType !== null && freezeVotingContract) { if (freezeVotingType === FreezeVotingType.MULTISIG) { votingRPC = getEventRPC( - freezeVotingContract as ContractConnection, - chainId + freezeVotingContract as ContractConnection ); const filter = votingRPC.filters.FreezeVoteCast(); votingRPC.on(filter, listenerCallback); } else if (freezeVotingType === FreezeVotingType.ERC20) { votingRPC = getEventRPC( - freezeVotingContract as ContractConnection, - chainId + freezeVotingContract as ContractConnection ); const filter = votingRPC.filters.FreezeVoteCast(); votingRPC.on(filter, listenerCallback); } else if (freezeVotingType === FreezeVotingType.ERC721) { votingRPC = getEventRPC( - freezeVotingContract as ContractConnection, - chainId + freezeVotingContract as ContractConnection ); const filter = votingRPC.filters.FreezeVoteCast(); votingRPC.on(filter, listenerCallback); } } - }, [guardContracts, chainId, account, action, loadOnMount, provider]); + }, [guardContracts, account, action, loadOnMount, provider]); return loadFractalFreezeGuard; }; diff --git a/src/hooks/DAO/loaders/useFractalGuardContracts.ts b/src/hooks/DAO/loaders/useFractalGuardContracts.ts index 1dc5c21749..bd18afe9e0 100644 --- a/src/hooks/DAO/loaders/useFractalGuardContracts.ts +++ b/src/hooks/DAO/loaders/useFractalGuardContracts.ts @@ -39,17 +39,16 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: const getMasterCopyAddress = useCallback( async (proxyAddress: string): Promise => { const filter = getEventRPC( - zodiacModuleProxyFactoryContract, - chainId + zodiacModuleProxyFactoryContract ).filters.ModuleProxyCreation(proxyAddress, null); - return getEventRPC(zodiacModuleProxyFactoryContract, chainId) + return getEventRPC(zodiacModuleProxyFactoryContract) .queryFilter(filter) .then(proxiesCreated => { if (proxiesCreated.length === 0) return constants.AddressZero; return proxiesCreated[0].args.masterCopy; }); }, - [zodiacModuleProxyFactoryContract, chainId] + [zodiacModuleProxyFactoryContract] ); const loadFractalGuardContracts = useCallback( @@ -80,7 +79,7 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: const hasNoGuard = _safe.guard === constants.AddressZero; const guardMasterCopyAddress = await getMasterCopyAddress(guard!); const isSafeGuard = - guardMasterCopyAddress === multisigFreezeGuardMasterCopyContract.asSigner.address; + guardMasterCopyAddress === multisigFreezeGuardMasterCopyContract.asProvider.address; if (isSafeGuard && !hasNoGuard) { freezeGuardContract = { asSigner: multisigFreezeGuardMasterCopyContract.asSigner.attach(guard!), @@ -91,12 +90,12 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: } if (!!freezeGuardContract) { - const votingAddress = await freezeGuardContract.asSigner.freezeVoting(); + const votingAddress = await freezeGuardContract.asProvider.freezeVoting(); const votingMasterCopyAddress = await getMasterCopyAddress(votingAddress); const freezeVotingType = - votingMasterCopyAddress === freezeMultisigVotingMasterCopyContract.asSigner.address + votingMasterCopyAddress === freezeMultisigVotingMasterCopyContract.asProvider.address ? FreezeVotingType.MULTISIG - : votingMasterCopyAddress === freezeERC721VotingMasterCopyContract.asSigner.address + : votingMasterCopyAddress === freezeERC721VotingMasterCopyContract.asProvider.address ? FreezeVotingType.ERC721 : FreezeVotingType.ERC20; diff --git a/src/hooks/DAO/loaders/useFractalModules.ts b/src/hooks/DAO/loaders/useFractalModules.ts index 4d91dffadb..3059db4ae2 100644 --- a/src/hooks/DAO/loaders/useFractalModules.ts +++ b/src/hooks/DAO/loaders/useFractalModules.ts @@ -4,11 +4,8 @@ import { useCallback } from 'react'; import { getEventRPC } from '../../../helpers'; import { useFractal } from '../../../providers/App/AppProvider'; import { FractalModuleData, FractalModuleType } from '../../../types'; -import { useEthersProvider } from '../../utils/useEthersProvider'; + export const useFractalModules = () => { - const { - network: { chainId }, - } = useEthersProvider(); const { baseContracts: { zodiacModuleProxyFactoryContract, @@ -19,7 +16,7 @@ export const useFractalModules = () => { const lookupModules = useCallback( async (_moduleAddresses: string[]) => { - const rpc = getEventRPC(zodiacModuleProxyFactoryContract, chainId); + const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const getMasterCopyAddress = async (proxyAddress: string): Promise => { const filter = rpc.filters.ModuleProxyCreation(proxyAddress, null); return rpc.queryFilter(filter).then(proxiesCreated => { @@ -36,16 +33,16 @@ export const useFractalModules = () => { if ( utils.getAddress(masterCopyAddress) === - fractalAzoriusMasterCopyContract.asSigner.address + fractalAzoriusMasterCopyContract.asProvider.address ) { safeModule = { - moduleContract: fractalAzoriusMasterCopyContract.asSigner.attach(moduleAddress), + moduleContract: fractalAzoriusMasterCopyContract.asProvider.attach(moduleAddress), moduleAddress: moduleAddress, moduleType: FractalModuleType.AZORIUS, }; - } else if (masterCopyAddress === fractalModuleMasterCopyContract.asSigner.address) { + } else if (masterCopyAddress === fractalModuleMasterCopyContract.asProvider.address) { safeModule = { - moduleContract: fractalModuleMasterCopyContract.asSigner.attach(moduleAddress), + moduleContract: fractalModuleMasterCopyContract.asProvider.attach(moduleAddress), moduleAddress: moduleAddress, moduleType: FractalModuleType.FRACTAL, }; @@ -66,7 +63,6 @@ export const useFractalModules = () => { zodiacModuleProxyFactoryContract, fractalAzoriusMasterCopyContract, fractalModuleMasterCopyContract, - chainId, ] ); return lookupModules; diff --git a/src/hooks/DAO/loaders/useGovernanceContracts.ts b/src/hooks/DAO/loaders/useGovernanceContracts.ts index c8ca17b366..c604727f9e 100644 --- a/src/hooks/DAO/loaders/useGovernanceContracts.ts +++ b/src/hooks/DAO/loaders/useGovernanceContracts.ts @@ -78,7 +78,7 @@ export const useGovernanceContracts = () => { let lockReleaseContract: ContractConnection | null = null; if (!votingContractAddress) { - votingContractAddress = await getEventRPC(azoriusContract, chainId) + votingContractAddress = await getEventRPC(azoriusContract) .queryFilter(azoriusModuleContract.filters.EnabledStrategy()) .then(strategiesEnabled => { return strategiesEnabled[0].args.strategy; @@ -86,7 +86,7 @@ export const useGovernanceContracts = () => { } if (!votingContractMasterCopyAddress) { - const rpc = getEventRPC(zodiacModuleProxyFactoryContract, chainId); + const rpc = getEventRPC(zodiacModuleProxyFactoryContract); const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null); votingContractMasterCopyAddress = await rpc.queryFilter(filter).then(proxiesCreated => { return proxiesCreated[0].args.masterCopy; @@ -111,10 +111,10 @@ export const useGovernanceContracts = () => { } if (ozLinearVotingContract) { if (!govTokenAddress) { - govTokenAddress = await ozLinearVotingContract.asSigner.governanceToken(); + govTokenAddress = await ozLinearVotingContract.asProvider.governanceToken(); } const possibleERC20Wrapper = - votesERC20WrapperMasterCopyContract.asSigner.attach(govTokenAddress); + votesERC20WrapperMasterCopyContract.asProvider.attach(govTokenAddress); underlyingTokenAddress = await possibleERC20Wrapper.underlying().catch(() => { // if the underlying token is not an ERC20Wrapper, this will throw an error, // so we catch it and return undefined @@ -235,7 +235,6 @@ export const useGovernanceContracts = () => { } } }, [ - chainId, action, getValue, setValue, diff --git a/src/hooks/DAO/proposal/useSubmitProposal.ts b/src/hooks/DAO/proposal/useSubmitProposal.ts index 5793e71533..0236623160 100644 --- a/src/hooks/DAO/proposal/useSubmitProposal.ts +++ b/src/hooks/DAO/proposal/useSubmitProposal.ts @@ -135,11 +135,11 @@ export default function useSubmitProposal() { return checkIsMultisigOwner(owners); } else if (type === GovernanceType.AZORIUS_ERC20) { if (ozLinearVotingContract && user.address) { - return ozLinearVotingContract.asSigner.isProposer(user.address); + return ozLinearVotingContract.asProvider.isProposer(user.address); } } else if (type === GovernanceType.AZORIUS_ERC721) { if (erc721LinearVotingContract) { - return erc721LinearVotingContract.asSigner.isProposer(user.address); + return erc721LinearVotingContract.asProvider.isProposer(user.address); } } else { return false; @@ -217,7 +217,7 @@ export default function useSubmitProposal() { return; } // Need to wrap it in Multisend function call - to = multiSendContract.asSigner.address; + to = multiSendContract.asProvider.address; const tempData = proposalData.targets.map((target, index) => { return { @@ -228,7 +228,7 @@ export default function useSubmitProposal() { } as MetaTransaction; }); - data = multiSendContract.asSigner.interface.encodeFunctionData('multiSend', [ + data = multiSendContract.asProvider.interface.encodeFunctionData('multiSend', [ encodeMultiSend(tempData), ]); @@ -396,9 +396,9 @@ export default function useSubmitProposal() { } } else { const votingStrategyAddress = - ozLinearVotingContract?.asSigner.address || - erc721LinearVotingContract?.asSigner.address || - freezeVotingContract?.asSigner.address; + ozLinearVotingContract?.asProvider.address || + erc721LinearVotingContract?.asProvider.address || + freezeVotingContract?.asProvider.address; if (!globalAzoriusContract || !votingStrategyAddress) { await submitMultisigProposal({ diff --git a/src/hooks/DAO/proposal/useUpdateProposalState.ts b/src/hooks/DAO/proposal/useUpdateProposalState.ts index 7b95857760..be4d199208 100644 --- a/src/hooks/DAO/proposal/useUpdateProposalState.ts +++ b/src/hooks/DAO/proposal/useUpdateProposalState.ts @@ -21,7 +21,7 @@ export default function useUpdateProposalState({ if (!azoriusContract) { return; } - const newState = await getAzoriusProposalState(azoriusContract.asSigner, proposalId); + const newState = await getAzoriusProposalState(azoriusContract.asProvider, proposalId); governanceDispatch({ type: FractalGovernanceAction.UPDATE_PROPOSAL_STATE, payload: { proposalId: proposalId.toString(), state: newState }, diff --git a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts index 45f6fb44e3..77d1994bec 100644 --- a/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts +++ b/src/hooks/DAO/proposal/useUserERC721VotingTokens.ts @@ -49,7 +49,7 @@ export default function useUserERC721VotingTokens( const getUserERC721VotingTokens = useCallback( async (_proposalId?: string, _safeAddress?: string | null) => { let govTokens = erc721Tokens; - let votingContract = erc721LinearVotingContract?.asSigner; + let votingContract = erc721LinearVotingContract?.asProvider; if (_safeAddress && daoAddress !== _safeAddress) { // Means getting these for any safe, primary use case - calculating user voting weight for freeze voting diff --git a/src/hooks/DAO/useBuildDAOTx.ts b/src/hooks/DAO/useBuildDAOTx.ts index 86543d992a..20cc8380ff 100644 --- a/src/hooks/DAO/useBuildDAOTx.ts +++ b/src/hooks/DAO/useBuildDAOTx.ts @@ -136,7 +136,7 @@ const useBuildDAOTx = () => { parentVotingStrategyType === VotingStrategyType.LINEAR_ERC721 && erc721LinearVotingContract ) { - parentVotingStrategyAddress = erc721LinearVotingContract.asSigner.address; + parentVotingStrategyAddress = erc721LinearVotingContract.asProvider.address; } } diff --git a/src/hooks/DAO/useCreateSubDAOProposal.ts b/src/hooks/DAO/useCreateSubDAOProposal.ts index 3bc0a18000..e0ea6c89ad 100644 --- a/src/hooks/DAO/useCreateSubDAOProposal.ts +++ b/src/hooks/DAO/useCreateSubDAOProposal.ts @@ -39,11 +39,14 @@ export const useCreateSubDAOProposal = () => { const { safeTx, predictedSafeAddress } = builtSafeTx; const proposalData: ProposalExecuteData = { - targets: [multiSendContract.asSigner.address, fractalRegistryContract.asSigner.address], + targets: [ + multiSendContract.asProvider.address, + fractalRegistryContract.asProvider.address, + ], values: [BigNumber.from('0'), BigNumber.from('0')], calldatas: [ - multiSendContract.asSigner.interface.encodeFunctionData('multiSend', [safeTx]), - fractalRegistryContract.asSigner.interface.encodeFunctionData('declareSubDAO', [ + multiSendContract.asProvider.interface.encodeFunctionData('multiSend', [safeTx]), + fractalRegistryContract.asProvider.interface.encodeFunctionData('declareSubDAO', [ predictedSafeAddress, ]), ], diff --git a/src/hooks/DAO/useDAOName.ts b/src/hooks/DAO/useDAOName.ts index ef86b3c08b..8b22092a6e 100644 --- a/src/hooks/DAO/useDAOName.ts +++ b/src/hooks/DAO/useDAOName.ts @@ -60,7 +60,7 @@ export default function useDAOName({ // Aka supplied from Subgraph setDAORegistryName(registryName); } else { - const rpc = getEventRPC(fractalRegistryContract, networkId); + const rpc = getEventRPC(fractalRegistryContract); const events = await rpc.queryFilter(rpc.filters.FractalNameUpdated(address)); const latestEvent = events.pop(); @@ -73,7 +73,7 @@ export default function useDAOName({ setValue(CacheKeys.DAO_NAME_PREFIX + address, daoName, 60); setDAORegistryName(daoName); } - }, [address, ensName, fractalRegistryContract, getValue, networkId, setValue, registryName]); + }, [address, ensName, fractalRegistryContract, getValue, setValue, registryName]); useEffect(() => { (async () => { diff --git a/src/hooks/DAO/useDeployAzorius.ts b/src/hooks/DAO/useDeployAzorius.ts index abbb5b03cc..8a7967d8ec 100644 --- a/src/hooks/DAO/useDeployAzorius.ts +++ b/src/hooks/DAO/useDeployAzorius.ts @@ -55,25 +55,25 @@ const useDeployAzorius = () => { let azoriusContracts; azoriusContracts = { - fractalAzoriusMasterCopyContract: fractalAzoriusMasterCopyContract.asSigner, - linearVotingMasterCopyContract: linearVotingMasterCopyContract.asSigner, - azoriusFreezeGuardMasterCopyContract: azoriusFreezeGuardMasterCopyContract.asSigner, - votesTokenMasterCopyContract: votesTokenMasterCopyContract.asSigner, - claimingMasterCopyContract: claimingMasterCopyContract.asSigner, - votesERC20WrapperMasterCopyContract: votesERC20WrapperMasterCopyContract.asSigner, + fractalAzoriusMasterCopyContract: fractalAzoriusMasterCopyContract.asProvider, + linearVotingMasterCopyContract: linearVotingMasterCopyContract.asProvider, + azoriusFreezeGuardMasterCopyContract: azoriusFreezeGuardMasterCopyContract.asProvider, + votesTokenMasterCopyContract: votesTokenMasterCopyContract.asProvider, + claimingMasterCopyContract: claimingMasterCopyContract.asProvider, + votesERC20WrapperMasterCopyContract: votesERC20WrapperMasterCopyContract.asProvider, } as AzoriusContracts; const baseContracts = { - fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asSigner, - fractalRegistryContract: fractalRegistryContract.asSigner, - safeFactoryContract: safeFactoryContract.asSigner, - safeSingletonContract: safeSingletonContract.asSigner, - multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asSigner, - multiSendContract: multiSendContract.asSigner, - freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asSigner, - freezeMultisigVotingMasterCopyContract: freezeMultisigVotingMasterCopyContract.asSigner, - zodiacModuleProxyFactoryContract: zodiacModuleProxyFactoryContract.asSigner, - keyValuePairsContract: keyValuePairsContract.asSigner, + fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asProvider, + fractalRegistryContract: fractalRegistryContract.asProvider, + safeFactoryContract: safeFactoryContract.asProvider, + safeSingletonContract: safeSingletonContract.asProvider, + multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asProvider, + multiSendContract: multiSendContract.asProvider, + freezeERC20VotingMasterCopyContract: freezeERC20VotingMasterCopyContract.asProvider, + freezeMultisigVotingMasterCopyContract: freezeMultisigVotingMasterCopyContract.asProvider, + zodiacModuleProxyFactoryContract: zodiacModuleProxyFactoryContract.asProvider, + keyValuePairsContract: keyValuePairsContract.asProvider, } as BaseContracts; const txBuilderFactory = new TxBuilderFactory( @@ -93,14 +93,14 @@ const useDeployAzorius = () => { }); const proposalData: ProposalExecuteData = { - targets: [daoAddress, multiSendContract.asSigner.address], + targets: [daoAddress, multiSendContract.asProvider.address], values: [BigNumber.from('0'), BigNumber.from('0')], calldatas: [ - safeSingletonContract.asSigner.interface.encodeFunctionData('addOwnerWithThreshold', [ - multiSendContract.asSigner.address, + safeSingletonContract.asProvider.interface.encodeFunctionData('addOwnerWithThreshold', [ + multiSendContract.asProvider.address, 1, ]), - multiSendContract.asSigner.interface.encodeFunctionData('multiSend', [safeTx]), + multiSendContract.asProvider.interface.encodeFunctionData('multiSend', [safeTx]), ], metaData: { title: '', diff --git a/src/hooks/utils/useSafeTransactions.ts b/src/hooks/utils/useSafeTransactions.ts index cdf42f3f5a..657f9b663e 100644 --- a/src/hooks/utils/useSafeTransactions.ts +++ b/src/hooks/utils/useSafeTransactions.ts @@ -321,7 +321,7 @@ export const useSafeTransactions = () => { if (guardContracts.freezeGuardContract) { const blockNumber = await provider.getBlockNumber(); const averageBlockTime = await getAverageBlockTime(provider); - freezeGuard = guardContracts.freezeGuardContract.asSigner as MultisigFreezeGuard; + freezeGuard = guardContracts.freezeGuardContract.asProvider as MultisigFreezeGuard; freezeGuardData = { guardTimelockPeriodMs: BigNumber.from( (await freezeGuard.timelockPeriod()) * averageBlockTime * 1000 diff --git a/src/utils/azorius.ts b/src/utils/azorius.ts index 0c84da11ad..ef6b95cfeb 100644 --- a/src/utils/azorius.ts +++ b/src/utils/azorius.ts @@ -122,7 +122,7 @@ export const mapProposalCreatedEventToProposal = async ( const quorum = await getQuorum(strategyContract, strategyType, proposalId); const deadlineSeconds = await getTimeStamp(endBlock, provider); - const state = await getAzoriusProposalState(azoriusContract.asSigner, proposalId); + const state = await getAzoriusProposalState(azoriusContract.asProvider, proposalId); const votes = await getProposalVotes(strategyContract, proposalId); const block = await provider.getBlock(startBlock); const votesSummary = { @@ -136,8 +136,8 @@ export const mapProposalCreatedEventToProposal = async ( let transactionHash: string | undefined; if (state === FractalProposalState.EXECUTED) { - const proposalExecutedFilter = azoriusContract.asSigner.filters.ProposalExecuted(); - const proposalExecutedEvents = await azoriusContract.asSigner.queryFilter( + const proposalExecutedFilter = azoriusContract.asProvider.filters.ProposalExecuted(); + const proposalExecutedEvents = await azoriusContract.asProvider.queryFilter( proposalExecutedFilter ); const executedEvent = proposalExecutedEvents.find(event =>