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 azorius typechain #1671

Merged
merged 12 commits into from
May 29, 2024
878 changes: 878 additions & 0 deletions src/assets/abi/Azorius.ts

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions src/components/pages/DaoHierarchy/useFetchNodes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useQuery } from '@apollo/client';
import { useCallback, useEffect, useState } from 'react';
import { getAddress, zeroAddress } from 'viem';
import { getAddress, getContract, zeroAddress } from 'viem';
import { usePublicClient } from 'wagmi';
import { DAOQueryDocument } from '../../../../.graphclient';
import AzoriusAbi from '../../../assets/abi/Azorius';
import { logError } from '../../../helpers/errorLogging';
import { useFractalModules } from '../../../hooks/DAO/loaders/useFractalModules';
import { useAsyncRetry } from '../../../hooks/utils/useAsyncRetry';
Expand All @@ -23,6 +25,7 @@ export function useFetchNodes(address?: string) {
const { requestWithRetries } = useAsyncRetry();

const { subgraph } = useNetworkConfig();
const publicClient = usePublicClient();
const { data, error } = useQuery(DAOQueryDocument, {
variables: { daoAddress: address },
skip: address === safe?.address || !address, // If address === safe.address - we already have hierarchy obtained in the context
Expand All @@ -38,11 +41,8 @@ export function useFetchNodes(address?: string) {
const getDAOOwner = useCallback(
async (safeInfo?: Partial<SafeInfoResponseWithGuard>) => {
if (safeInfo && safeInfo.guard && baseContracts) {
const {
multisigFreezeGuardMasterCopyContract,
azoriusFreezeGuardMasterCopyContract,
fractalAzoriusMasterCopyContract,
} = baseContracts;
const { multisigFreezeGuardMasterCopyContract, azoriusFreezeGuardMasterCopyContract } =
baseContracts;
if (safeInfo.guard !== zeroAddress) {
const guard = multisigFreezeGuardMasterCopyContract.asProvider.attach(safeInfo.guard);
const guardOwner = await guard.owner();
Expand All @@ -53,15 +53,13 @@ export function useFetchNodes(address?: string) {
const modules = await lookupModules(safeInfo.modules || []);
if (!modules) return;
const azoriusModule = getAzoriusModuleFromModules(modules);
if (
azoriusModule &&
azoriusFreezeGuardMasterCopyContract &&
fractalAzoriusMasterCopyContract
) {
const azoriusContract = fractalAzoriusMasterCopyContract?.asProvider.attach(
azoriusModule.moduleAddress,
);
const azoriusGuardAddress = await azoriusContract.getGuard();
if (azoriusModule && azoriusFreezeGuardMasterCopyContract && publicClient) {
const azoriusContract = getContract({
abi: AzoriusAbi,
address: getAddress(azoriusModule.moduleAddress),
client: publicClient,
});
const azoriusGuardAddress = await azoriusContract.read.getGuard();
if (azoriusGuardAddress !== zeroAddress) {
const guard =
azoriusFreezeGuardMasterCopyContract.asProvider.attach(azoriusGuardAddress);
Expand All @@ -75,7 +73,7 @@ export function useFetchNodes(address?: string) {
}
return undefined;
},
[baseContracts, lookupModules],
[baseContracts, lookupModules, publicClient],
);

const fetchDAOInfo = useCallback(
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/cards/DAOInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function DAOInfoCard() {
{!!user.address && (
<ManageDAOMenu
parentAddress={parentAddress}
fractalNode={node}
freezeGuard={guard}
guardContracts={guardContracts}
/>
Expand Down
56 changes: 20 additions & 36 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ERC20FreezeVoting, MultisigFreezeVoting } from '@fractal-framework/frac
import { GearFine } from '@phosphor-icons/react';
import { useMemo, useCallback, useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { Address, getAddress } from 'viem';
import { SENTINEL_ADDRESS } from '../../../../constants/common';
import { Address } from 'viem';
import { DAO_ROUTES } from '../../../../constants/routes';
import {
isWithinFreezePeriod,
Expand All @@ -16,23 +15,21 @@ import useSafeContracts from '../../../../hooks/safe/useSafeContracts';
import useBlockTimestamp from '../../../../hooks/utils/useBlockTimestamp';
import { useCanUserCreateProposal } from '../../../../hooks/utils/useCanUserSubmitProposal';
import { useMasterCopy } from '../../../../hooks/utils/useMasterCopy';
import useVotingStrategyAddress from '../../../../hooks/utils/useVotingStrategyAddress';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import {
FractalGuardContracts,
FractalNode,
FreezeGuard,
GovernanceType,
FreezeVotingType,
} from '../../../../types';
import { getAzoriusModuleFromModules } from '../../../../utils';
import { ModalType } from '../../modals/ModalProvider';
import { useFractalModal } from '../../modals/useFractalModal';
import { OptionMenu } from '../OptionMenu';

interface IManageDAOMenu {
parentAddress: Address | null;
fractalNode: FractalNode;
freezeGuard: FreezeGuard;
guardContracts: FractalGuardContracts;
}
Expand All @@ -46,57 +43,37 @@ interface IManageDAOMenu {
*
* All info for this menu should be supplied in the constructor.
*/
export function ManageDAOMenu({
parentAddress,
freezeGuard,
guardContracts,
fractalNode,
}: IManageDAOMenu) {
export function ManageDAOMenu({ parentAddress, freezeGuard, guardContracts }: IManageDAOMenu) {
const [governanceType, setGovernanceType] = useState(GovernanceType.MULTISIG);
const {
node: { safe },
node,
governance: { type },
} = useFractal();
const baseContracts = useSafeContracts();
const currentTime = BigInt(useBlockTimestamp());
const navigate = useNavigate();
const safeAddress = fractalNode.daoAddress;
const safeAddress = node.daoAddress;
const { getZodiacModuleProxyMasterCopyData } = useMasterCopy();
const { canUserCreateProposal } = useCanUserCreateProposal();
const { getUserERC721VotingTokens } = useUserERC721VotingTokens(safeAddress, undefined, false);
const { handleClawBack } = useClawBack({
parentAddress,
childSafeInfo: fractalNode,
childSafeInfo: node,
});
const { getVotingStrategyAddress } = useVotingStrategyAddress();

useEffect(() => {
const loadGovernanceType = async () => {
if (safe && safe.address && safe.address === safeAddress && type) {
if (node.safe && node.safe.address && node.safe.address === safeAddress && type) {
// Since safe.address (global scope DAO address) and safeAddress(Node provided to this component via props)
// are the same - we can simply grab governance type from global scope and avoid double-fetching
setGovernanceType(type);
} else {
if (baseContracts) {
if (node?.fractalModules) {
let result = GovernanceType.MULTISIG;
const azoriusModule = getAzoriusModuleFromModules(fractalNode.fractalModules);
const { fractalAzoriusMasterCopyContract } = baseContracts;
if (!!azoriusModule) {
const azoriusContract = {
asProvider: fractalAzoriusMasterCopyContract.asProvider.attach(
azoriusModule.moduleAddress,
),
asSigner: fractalAzoriusMasterCopyContract.asSigner.attach(
azoriusModule.moduleAddress,
),
};

// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.asProvider.getStrategies(SENTINEL_ADDRESS, 0)
)[1];
const masterCopyData = await getZodiacModuleProxyMasterCopyData(
getAddress(votingContractAddress),
);
const votingContractAddress = await getVotingStrategyAddress();
if (votingContractAddress) {
const masterCopyData = await getZodiacModuleProxyMasterCopyData(votingContractAddress);

if (masterCopyData.isOzLinearVoting) {
result = GovernanceType.AZORIUS_ERC20;
Expand All @@ -111,7 +88,14 @@ export function ManageDAOMenu({
};

loadGovernanceType();
}, [fractalNode, safe, safeAddress, type, getZodiacModuleProxyMasterCopyData, baseContracts]);
}, [
getVotingStrategyAddress,
getZodiacModuleProxyMasterCopyData,
node?.fractalModules,
node.safe,
safeAddress,
type,
]);
const { addressPrefix } = useNetworkConfig();

const handleNavigateToSettings = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/proposal/useProposalCountdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function useProposalCountdown(proposal: FractalProposal) {
(async () => {
try {
if (dao?.isAzorius) {
await updateProposalState(BigInt(proposal.proposalId));
await updateProposalState(Number(proposal.proposalId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need casting here? Why can't we just pass number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal.proposalId is a string type here

} else {
await loadDAOProposals();
}
Expand Down
Loading
Loading