Skip to content

Commit

Permalink
Merge branch 'develop' into fix/#1361-deploy-safe-up-to-spec-with-saf…
Browse files Browse the repository at this point in the history
…e-dapp
  • Loading branch information
mudrila committed Feb 26, 2024
2 parents 50339dc + efde997 commit 787557a
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 54 deletions.
1 change: 0 additions & 1 deletion app/daos/[daoAddress]/proposals/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default function ProposalCreatePage() {
successToastMessage: t('proposalCreateSuccessToastMessage'),
failedToastMessage: t('proposalCreateFailureToastMessage'),
successCallback,
safeAddress: daoAddress,
});
}}
validateOnMount
Expand Down
43 changes: 30 additions & 13 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { VEllipsis } from '@decent-org/fractal-ui';
import {
ERC20FreezeVoting,
ERC721FreezeVoting,
Azorius,
ModuleProxyFactory,
MultisigFreezeVoting,
} from '@fractal-framework/fractal-contracts';
Expand All @@ -18,6 +17,8 @@ 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';
import {
Expand Down Expand Up @@ -70,6 +71,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);
Expand Down Expand Up @@ -107,18 +109,31 @@ export function ManageDAOMenu({
azoriusModule.moduleAddress
),
};
const votingContractAddress = await getEventRPC<Azorius>(azoriusContract)
.queryFilter((azoriusModule.moduleContract as Azorius).filters.EnabledStrategy())
.then(strategiesEnabled => {
return strategiesEnabled[0].args.strategy;
});
const rpc = getEventRPC<ModuleProxyFactory>(zodiacModuleProxyFactoryContract);
const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null);
const votingContractMasterCopyAddress = await rpc
.queryFilter(filter)
.then(proxiesCreated => {
return proxiesCreated[0].args.masterCopy;
});

// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.asProvider.getStrategies(
'0x0000000000000000000000000000000000000001',
0
)
)[1];
const cachedMasterCopyAddress = getValue(
CacheKeys.MASTER_COPY_PREFIX + votingContractAddress
);
let votingContractMasterCopyAddress = cachedMasterCopyAddress;
if (!votingContractMasterCopyAddress) {
const rpc = getEventRPC<ModuleProxyFactory>(zodiacModuleProxyFactoryContract);
const filter = rpc.filters.ModuleProxyCreation(votingContractAddress, null);
votingContractMasterCopyAddress = await rpc
.queryFilter(filter)
.then(proxiesCreated => {
return proxiesCreated[0].args.masterCopy;
});
setValue(
CacheKeys.MASTER_COPY_PREFIX + votingContractAddress,
votingContractMasterCopyAddress
);
}

if (
votingContractMasterCopyAddress === linearVotingMasterCopyContract.asProvider.address
Expand Down Expand Up @@ -147,6 +162,8 @@ export function ManageDAOMenu({
safeAddress,
type,
zodiacModuleProxyFactoryContract,
getValue,
setValue,
]);

const handleNavigateToSettings = useCallback(
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/DAO/loaders/useFractalGuardContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -36,19 +38,24 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?:
network: { chainId },
} = useEthersProvider();

const { setValue, getValue } = useLocalStorage();

const getMasterCopyAddress = useCallback(
async (proxyAddress: string): Promise<string> => {
const cachedValue = getValue(CacheKeys.MASTER_COPY_PREFIX + proxyAddress);
if (cachedValue) return cachedValue;
const filter = getEventRPC<ModuleProxyFactory>(
zodiacModuleProxyFactoryContract
).filters.ModuleProxyCreation(proxyAddress, null);
return getEventRPC<ModuleProxyFactory>(zodiacModuleProxyFactoryContract)
.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(
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/DAO/loaders/useFractalModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 = () => {
const {
Expand All @@ -13,14 +15,18 @@ export const useFractalModules = () => {
fractalModuleMasterCopyContract,
},
} = useFractal();
const { setValue, getValue } = useLocalStorage();

const lookupModules = useCallback(
async (_moduleAddresses: string[]) => {
const rpc = getEventRPC<ModuleProxyFactory>(zodiacModuleProxyFactoryContract);
const getMasterCopyAddress = async (proxyAddress: string): Promise<string> => {
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(CacheKeys.MASTER_COPY_PREFIX + proxyAddress, proxiesCreated[0].args.masterCopy);
return proxiesCreated[0].args.masterCopy;
});
};
Expand Down Expand Up @@ -63,6 +69,8 @@ export const useFractalModules = () => {
zodiacModuleProxyFactoryContract,
fractalAzoriusMasterCopyContract,
fractalModuleMasterCopyContract,
getValue,
setValue,
]
);
return lookupModules;
Expand Down
45 changes: 23 additions & 22 deletions src/hooks/DAO/loaders/useGovernanceContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -59,38 +60,38 @@ 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<LinearERC20Voting> | undefined;
let erc721LinearVotingContract: ContractConnection<LinearERC721Voting> | undefined;
let tokenContract: ContractConnection<VotesERC20 | VotesERC20Wrapper> | undefined;
let underlyingTokenAddress: string | undefined;
let lockReleaseContract: ContractConnection<LockRelease> | null = null;

if (!votingContractAddress) {
votingContractAddress = await getEventRPC<Azorius>(azoriusContract)
.queryFilter(azoriusModuleContract.filters.EnabledStrategy())
.then(strategiesEnabled => {
return strategiesEnabled[0].args.strategy;
});
}
// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.asProvider.getStrategies(
'0x0000000000000000000000000000000000000001',
0
)
)[1];

if (!votingContractMasterCopyAddress) {
const rpc = getEventRPC<ModuleProxyFactory>(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<ModuleProxyFactory>(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) {
Expand Down
21 changes: 11 additions & 10 deletions src/hooks/DAO/proposal/useSubmitProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ 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;
});
// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0)
)[1];
const votingContract = BaseStrategy__factory.connect(
votingContractAddress,
signerOrProvider
Expand Down Expand Up @@ -374,11 +373,13 @@ 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;
});
// @dev assumes the first strategy is the voting contract
const votingStrategyAddress = (
await azoriusModuleContract.getStrategies(
'0x0000000000000000000000000000000000000001',
0
)
)[1];
submitAzoriusProposal({
proposalData,
pendingToastMessage,
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/DAO/proposal/useUserERC721VotingTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ 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;
});
// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.getStrategies('0x0000000000000000000000000000000000000001', 0)
)[1];
votingContract = LinearERC721Voting__factory.connect(
votingContractAddress,
signerOrProvider
Expand Down
1 change: 0 additions & 1 deletion src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const useDeployAzorius = () => {
successToastMessage: t('proposalCreateSuccessToastMessage', { ns: 'proposal' }),
failedToastMessage: t('proposalCreateFailureToastMessage', { ns: 'proposal' }),
successCallback: () => push(DAO_ROUTES.proposals.relative(daoAddress)),
safeAddress: daoAddress,
});
},
[
Expand Down
1 change: 1 addition & 0 deletions src/hooks/utils/cache/cacheDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/utils/azorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
};

Expand Down

0 comments on commit 787557a

Please sign in to comment.