Skip to content

Commit

Permalink
Merge pull request #1639 from decentdao/remove-non-fractal-type-imports
Browse files Browse the repository at this point in the history
Remove non fractal type imports
  • Loading branch information
adamgall committed May 8, 2024
1 parent b4e1d56 commit 0ae57da
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 147 deletions.
186 changes: 186 additions & 0 deletions src/assets/abi/IVotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
const IVotesAbi = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'delegator',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'fromDelegate',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'toDelegate',
type: 'address',
},
],
name: 'DelegateChanged',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'delegate',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'previousBalance',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'newBalance',
type: 'uint256',
},
],
name: 'DelegateVotesChanged',
type: 'event',
},
{
inputs: [
{
internalType: 'address',
name: 'delegatee',
type: 'address',
},
],
name: 'delegate',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'delegatee',
type: 'address',
},
{
internalType: 'uint256',
name: 'nonce',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'expiry',
type: 'uint256',
},
{
internalType: 'uint8',
name: 'v',
type: 'uint8',
},
{
internalType: 'bytes32',
name: 'r',
type: 'bytes32',
},
{
internalType: 'bytes32',
name: 's',
type: 'bytes32',
},
],
name: 'delegateBySig',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'account',
type: 'address',
},
],
name: 'delegates',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'blockNumber',
type: 'uint256',
},
],
name: 'getPastTotalSupply',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'account',
type: 'address',
},
{
internalType: 'uint256',
name: 'blockNumber',
type: 'uint256',
},
],
name: 'getPastVotes',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'account',
type: 'address',
},
],
name: 'getVotes',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
] as const;

export default IVotesAbi;
24 changes: 17 additions & 7 deletions src/components/DaoCreator/hooks/usePrepareFormData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IVotes__factory } from '@fractal-framework/fractal-contracts';
import { useCallback } from 'react';
import { getAddress } from 'viem';
import { getAddress, getContract } from 'viem';
import { usePublicClient } from 'wagmi';
import IVotesAbi from '../../../assets/abi/IVotes';
import { SENTINEL_ADDRESS } from '../../../constants/common';
import { useEthersProvider } from '../../../providers/Ethers/hooks/useEthersProvider';
import { useEthersSigner } from '../../../providers/Ethers/hooks/useEthersSigner';
import {
Expand All @@ -20,6 +22,8 @@ export function usePrepareFormData() {
const signer = useEthersSigner();
const provider = useEthersProvider();

const publicClient = usePublicClient();

// Helper function to prepare freezeGuard data
const prepareFreezeGuardData = useCallback(
async (
Expand Down Expand Up @@ -52,18 +56,24 @@ export function usePrepareFormData() {

const checkVotesToken = useCallback(
async (address: string) => {
if (provider) {
if (publicClient) {
try {
const votesContract = IVotes__factory.connect(address, provider);
await votesContract.delegates('0x0000000000000000000000000000000000000001');
await votesContract.getVotes('0x0000000000000000000000000000000000000001');
const votesContract = getContract({
abi: IVotesAbi,
address: getAddress(address),
client: publicClient,
});
await Promise.all([
votesContract.read.delegates([SENTINEL_ADDRESS]),
votesContract.read.getVotes([SENTINEL_ADDRESS]),
]);
return true;
} catch (error) {
return false;
}
}
},
[provider],
[publicClient],
);

const prepareMultisigFormData = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Address } from 'viem';
import { useEnsName } from 'wagmi';
import { SENTINEL_ADDRESS } from '../../../../../../constants/common';
import { useFractal } from '../../../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../../../providers/NetworkConfig/NetworkConfigProvider';
import SupportTooltip from '../../../../../ui/badges/SupportTooltip';
Expand Down Expand Up @@ -65,9 +66,7 @@ function RemoveSignerModal({

useEffect(() => {
const signerIndex = signers.findIndex(signer => signer === selectedSigner);
setPrevSigner(
signerIndex > 0 ? signers[signerIndex - 1] : '0x0000000000000000000000000000000000000001',
);
setPrevSigner(signerIndex > 0 ? signers[signerIndex - 1] : SENTINEL_ADDRESS);
}, [selectedSigner, signers]);

return (
Expand Down
6 changes: 2 additions & 4 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ERC20FreezeVoting, MultisigFreezeVoting } from '@fractal-framework/frac
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 { DAO_ROUTES } from '../../../../constants/routes';
import {
isWithinFreezePeriod,
Expand Down Expand Up @@ -91,10 +92,7 @@ export function ManageDAOMenu({

// @dev assumes the first strategy is the voting contract
const votingContractAddress = (
await azoriusContract.asProvider.getStrategies(
'0x0000000000000000000000000000000000000001',
0,
)
await azoriusContract.asProvider.getStrategies(SENTINEL_ADDRESS, 0)
)[1];
const masterCopyData = await getZodiacModuleProxyMasterCopyData(
getAddress(votingContractAddress),
Expand Down
1 change: 1 addition & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const BACKGROUND_SEMI_TRANSPARENT = 'black.900-semi-transparent';
*/
export const TOOLTIP_MAXW = '18rem';
export const ADDRESS_MULTISIG_METADATA = '0xdA00000000000000000000000000000000000Da0';
export const SENTINEL_ADDRESS = '0x0000000000000000000000000000000000000001';
11 changes: 0 additions & 11 deletions src/hooks/DAO/loaders/governance/useERC20LinearToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DelegateChangedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/VotesERC20';
import { useCallback, useEffect, useRef } from 'react';
import { getAddress } from 'viem';
import { useFractal } from '../../../../providers/App/AppProvider';
Expand Down Expand Up @@ -76,20 +75,10 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
(await tokenContract.getVotes(account)).toBigInt(),
]);

let delegateChangeEvents: DelegateChangedEvent[];
try {
delegateChangeEvents = await tokenContract.queryFilter(
tokenContract.filters.DelegateChanged(),
);
} catch (e) {
delegateChangeEvents = [];
}

const tokenAccountData = {
balance: tokenBalance,
delegatee: tokenDelegatee,
votingWeight: tokenVotingWeight,
isDelegatesSet: delegateChangeEvents.length > 0,
};

action.dispatch({
Expand Down
39 changes: 17 additions & 22 deletions src/hooks/DAO/loaders/governance/useERC721Tokens.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { ERC721__factory } from '@fractal-framework/fractal-contracts';
import { useCallback } from 'react';
import { getAddress, zeroAddress } from 'viem';
import { logError } from '../../../../helpers/errorLogging';
import { erc721Abi, getAddress, getContract, zeroAddress } from 'viem';
import { usePublicClient } from 'wagmi';
import { useFractal } from '../../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
import { ERC721TokenData } from '../../../../types';
import useSafeContracts from '../../../safe/useSafeContracts';
import useSignerOrProvider from '../../../utils/useSignerOrProvider';

export default function useERC721Tokens() {
const signerOrProvider = useSignerOrProvider();
const {
governanceContracts: { erc721LinearVotingContractAddress },
action,
} = useFractal();
const baseContracts = useSafeContracts();
const publicClient = usePublicClient();
const loadERC721Tokens = useCallback(async () => {
if (!erc721LinearVotingContractAddress || !signerOrProvider || !baseContracts) {
if (!erc721LinearVotingContractAddress || !baseContracts || !publicClient) {
return;
}
const erc721LinearVotingContract =
Expand All @@ -26,22 +24,19 @@ export default function useERC721Tokens() {
const addresses = await erc721LinearVotingContract.getAllTokenAddresses();
const erc721Tokens: ERC721TokenData[] = await Promise.all(
addresses.map(async address => {
const tokenContract = ERC721__factory.connect(address, signerOrProvider);
const tokenContract = getContract({
abi: erc721Abi,
address: getAddress(address),
client: publicClient,
});
const votingWeight = (await erc721LinearVotingContract.getTokenWeight(address)).toBigInt();
const name = await tokenContract.name();
const symbol = await tokenContract.symbol();
let totalSupply = undefined;
try {
const tokenMintEvents = await tokenContract.queryFilter(
tokenContract.filters.Transfer(zeroAddress, null),
);
const tokenBurnEvents = await tokenContract.queryFilter(
tokenContract.filters.Transfer(null, zeroAddress),
);
totalSupply = BigInt(tokenMintEvents.length - tokenBurnEvents.length);
} catch (e) {
logError('Error while getting ERC721 total supply');
}
const [name, symbol, tokenMintEvents, tokenBurnEvents] = await Promise.all([
tokenContract.read.name(),
tokenContract.read.symbol(),
tokenContract.getEvents.Transfer({ from: zeroAddress }),
tokenContract.getEvents.Transfer({ to: zeroAddress }),
]);
const totalSupply = BigInt(tokenMintEvents.length - tokenBurnEvents.length);
return { name, symbol, address: getAddress(address), votingWeight, totalSupply };
}),
);
Expand All @@ -50,7 +45,7 @@ export default function useERC721Tokens() {
type: FractalGovernanceAction.SET_ERC721_TOKENS_DATA,
payload: erc721Tokens,
});
}, [erc721LinearVotingContractAddress, signerOrProvider, action, baseContracts]);
}, [action, baseContracts, erc721LinearVotingContractAddress, publicClient]);

return loadERC721Tokens;
}
Loading

0 comments on commit 0ae57da

Please sign in to comment.