Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Apr 26, 2024
1 parent d6e7ec6 commit bb8a36c
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TypedDataSigner } from '@ethersproject/abstract-signer';
import { SafeMultisigTransactionWithTransfersResponse } from '@safe-global/safe-service-client';
import { Signer } from 'ethers';
import { useTranslation } from 'react-i18next';
import { getAddress } from 'viem';
import { GnosisSafeL2__factory } from '../../../assets/typechain-types/usul/factories/@gnosis.pm/safe-contracts/contracts';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../../constants/common';
import { buildSafeTransaction, buildSignatureBytes, EIP712_SAFE_TX_TYPE } from '../../../helpers';
Expand Down Expand Up @@ -49,6 +50,7 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
try {
const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
});

asyncRequest({
Expand Down Expand Up @@ -78,6 +80,7 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
}
const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
});
const signatures = buildSignatureBytes(
multisigTx.confirmations.map(confirmation => ({
Expand Down Expand Up @@ -123,6 +126,7 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) {
const safeContract = GnosisSafeL2__factory.connect(safe.address, signerOrProvider);
const safeTx = buildSafeTransaction({
...multisigTx,
to: getAddress(multisigTx.to),
});
const signatures = buildSignatureBytes(
multisigTx.confirmations.map(confirmation => ({
Expand Down
45 changes: 24 additions & 21 deletions src/components/pages/DAOTreasury/hooks/useSendAssets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SafeBalanceUsdResponse } from '@safe-global/safe-service-client';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { encodeAbiParameters, parseAbiParameters, isAddress } from 'viem';
import { encodeAbiParameters, parseAbiParameters, isAddress, getAddress, Hex } from 'viem';
import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal';
import { ProposalExecuteData } from '../../../../types';
import { formatCoin } from '../../../../utils/numberFormats';
Expand Down Expand Up @@ -30,33 +30,36 @@ const useSendAssets = ({
asset?.token?.symbol,
);

if (destinationAddress && isAddress(destinationAddress)) {
const calldatas = [
let calldatas = ['0x' as Hex];
let target =
isEth && destinationAddress ? getAddress(destinationAddress) : getAddress(asset.tokenAddress);
if (!isEth && destinationAddress && isAddress(destinationAddress)) {
calldatas = [
encodeAbiParameters(parseAbiParameters('address, uint256'), [
destinationAddress,
transferAmount,
]),
];
}

const proposalData: ProposalExecuteData = {
targets: [isEth ? destinationAddress : asset.tokenAddress],
values: [isEth ? transferAmount : 0n],
calldatas: isEth ? ['0x'] : calldatas,
metaData: {
title: t(isEth ? 'Send Eth' : 'Send Token', { ns: 'proposalMetadata' }),
description: description,
documentationUrl: '',
},
};
const proposalData: ProposalExecuteData = {
targets: [target],
values: [isEth ? transferAmount : 0n],
calldatas,
metaData: {
title: t(isEth ? 'Send Eth' : 'Send Token', { ns: 'proposalMetadata' }),
description: description,
documentationUrl: '',
},
};

await submitProposal({
proposalData,
nonce,
pendingToastMessage: t('sendAssetsPendingToastMessage'),
successToastMessage: t('sendAssetsSuccessToastMessage'),
failedToastMessage: t('sendAssetsFailureToastMessage'),
});
}
await submitProposal({
proposalData,
nonce,
pendingToastMessage: t('sendAssetsPendingToastMessage'),
successToastMessage: t('sendAssetsSuccessToastMessage'),
failedToastMessage: t('sendAssetsFailureToastMessage'),
});
}, [
asset.tokenAddress,
asset?.token?.decimals,
Expand Down
30 changes: 19 additions & 11 deletions src/components/pages/DaoSettings/components/Metadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Flex, Text, Button, Divider } from '@chakra-ui/react';
import { useState, useEffect, ChangeEventHandler } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { isHex, getAddress } from 'viem';
import { SettingsSection } from '..';
import { DAO_ROUTES } from '../../../../../constants/routes';
import useSubmitProposal from '../../../../../hooks/DAO/proposal/useSubmitProposal';
Expand Down Expand Up @@ -64,17 +65,22 @@ export default function MetadataContainer() {
return;
}
const { fractalRegistryContract } = baseContracts;
const encodedUpdateDAOName = fractalRegistryContract.asProvider.interface.encodeFunctionData(
'updateDAOName',
[name],
);
if (!isHex(encodedUpdateDAOName)) {
return;
}
const proposalData: ProposalExecuteData = {
metaData: {
title: t('Update Safe Name', { ns: 'proposalMetadata' }),
description: '',
documentationUrl: '',
},
targets: [fractalRegistryContract.asProvider.address],
targets: [getAddress(fractalRegistryContract.asProvider.address)],
values: [0n],
calldatas: [
fractalRegistryContract.asProvider.interface.encodeFunctionData('updateDAOName', [name]),
],
calldatas: [encodedUpdateDAOName],
};

submitProposal({
Expand All @@ -92,20 +98,22 @@ export default function MetadataContainer() {
return;
}
const { keyValuePairsContract } = baseContracts;
const encodedUpdateValues = keyValuePairsContract.asProvider.interface.encodeFunctionData(
'updateValues',
[['snapshotENS'], [snapshotENS]],
);
if (!isHex(encodedUpdateValues)) {
return;
}
const proposalData: ProposalExecuteData = {
metaData: {
title: t('Update Snapshot Space', { ns: 'proposalMetadata' }),
description: '',
documentationUrl: '',
},
targets: [keyValuePairsContract.asProvider.address],
targets: [getAddress(keyValuePairsContract.asProvider.address)],
values: [0n],
calldatas: [
keyValuePairsContract.asProvider.interface.encodeFunctionData('updateValues', [
['snapshotENS'],
[snapshotENS],
]),
],
calldatas: [encodedUpdateValues],
};

submitProposal({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { getAddress, isHex } from 'viem';
import useSubmitProposal from '../../../../../../hooks/DAO/proposal/useSubmitProposal';
import { useFractal } from '../../../../../../providers/App/AppProvider';
import { ProposalExecuteData } from '../../../../../../types';
Expand All @@ -22,23 +23,25 @@ const useAddSigner = () => {
daoAddress: string | null;
close: () => void;
}) => {
if (!baseContracts) {
if (!baseContracts || !daoAddress) {
return;
}
const { safeSingletonContract } = baseContracts;
const description = 'Add Signer';

const calldatas = [
safeSingletonContract.asSigner.interface.encodeFunctionData('addOwnerWithThreshold', [
newSigner,
BigInt(threshold),
]),
];
const encodedAddOwner = safeSingletonContract.asSigner.interface.encodeFunctionData(
'addOwnerWithThreshold',
[newSigner, BigInt(threshold)],
);
if (!isHex(encodedAddOwner)) {
return;
}
const calldatas = [encodedAddOwner];

const proposalData: ProposalExecuteData = {
targets: [daoAddress!],
targets: [getAddress(daoAddress)],
values: [0n],
calldatas: calldatas,
calldatas,
metaData: {
title: 'Add Signer',
description: description,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { isHex, getAddress } from 'viem';
import useSubmitProposal from '../../../../../../hooks/DAO/proposal/useSubmitProposal';
import { useFractal } from '../../../../../../providers/App/AppProvider';
import { ProposalExecuteData } from '../../../../../../types';
Expand All @@ -22,24 +23,27 @@ const useRemoveSigner = ({
const { baseContracts } = useFractal();

const removeSigner = useCallback(async () => {
if (!baseContracts) {
if (!baseContracts || !daoAddress) {
return;
}
const { safeSingletonContract } = baseContracts;
const description = 'Remove Signers';

const calldatas = [
safeSingletonContract.asProvider.interface.encodeFunctionData('removeOwner', [
prevSigner,
signerToRemove,
BigInt(threshold),
]),
];
const encodedRemoveOwner = safeSingletonContract.asProvider.interface.encodeFunctionData(
'removeOwner',
[prevSigner, signerToRemove, BigInt(threshold)],
);

if (!isHex(encodedRemoveOwner)) {
return;
}

const calldatas = [encodedRemoveOwner];

const proposalData: ProposalExecuteData = {
targets: [daoAddress!],
targets: [getAddress(daoAddress)],
values: [0n],
calldatas: calldatas,
calldatas,
metaData: {
title: 'Remove Signers',
description: description,
Expand Down
3 changes: 1 addition & 2 deletions src/components/ui/forms/InputComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ResponsiveValue,
} from '@chakra-ui/react';
import { LabelWrapper } from '@decent-org/fractal-ui';
import { Address } from 'viem';
import { BigIntInput, BigIntInputProps } from './BigIntInput';
import { EthAddressInput } from './EthAddressInput';

Expand Down Expand Up @@ -38,7 +37,7 @@ interface InputProps extends Omit<BaseProps, 'children'> {
}

interface EthAddressProps extends Omit<BaseProps, 'children' | 'value'> {
onAddressChange: (address: Address | undefined, isValid: boolean) => void;
onAddressChange: (address: string | undefined, isValid: boolean) => void;
}

interface TextareaProps extends Omit<BaseProps, 'children'> {
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/DAO/loaders/governance/useAzoriusListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { VotedEvent as ERC20VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting';
import { VotedEvent as ERC721VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC721Voting';
import { Dispatch, useEffect, useMemo } from 'react';
import { getAddress } from 'viem';
import { useFractal } from '../../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
import { useEthersProvider } from '../../../../providers/Ethers/hooks/useEthersProvider';
Expand Down Expand Up @@ -48,7 +49,11 @@ const proposalCreatedEventListener = (
return;
}

const typedTransactions = transactions.map(t => ({ ...t, value: t.value.toBigInt() }));
const typedTransactions = transactions.map(t => ({
...t,
to: getAddress(t.to),
value: t.value.toBigInt(),
}));

const metaDataEvent: CreateProposalMetadata = JSON.parse(metadata);
const proposalData = {
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/DAO/loaders/governance/useAzoriusProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { VotedEvent as ERC20VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting';
import { VotedEvent as ERC721VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC721Voting';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { getAddress } from 'viem';
import { logError } from '../../../../helpers/errorLogging';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useEthersProvider } from '../../../../providers/Ethers/hooks/useEthersProvider';
Expand Down Expand Up @@ -150,6 +151,7 @@ export const useAzoriusProposals = () => {
_decode,
proposalCreatedEvent.args.transactions.map(t => ({
...t,
to: getAddress(t.to),
value: t.value.toBigInt(),
})),
);
Expand All @@ -161,6 +163,7 @@ export const useAzoriusProposals = () => {
},
transactions: proposalCreatedEvent.args.transactions.map(t => ({
...t,
to: getAddress(t.to),
value: t.value.toBigInt(),
})),
decodedTransactions,
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/DAO/loaders/governance/useERC20LinearToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
import useSafeContracts from '../../../safe/useSafeContracts';
Expand Down Expand Up @@ -32,7 +33,7 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
name: tokenName,
symbol: tokenSymbol,
decimals: tokenDecimals,
address: votesTokenContractAddress,
address: getAddress(votesTokenContractAddress),
totalSupply,
};
isTokenLoaded.current = true;
Expand All @@ -53,7 +54,7 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
const tokenData = {
name: tokenName,
symbol: tokenSymbol,
address: underlyingTokenAddress,
address: getAddress(underlyingTokenAddress),
};
action.dispatch({
type: FractalGovernanceAction.SET_UNDERLYING_TOKEN_DATA,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/loaders/governance/useERC721Tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ERC721__factory } from '@fractal-framework/fractal-contracts';
import { useCallback } from 'react';
import { zeroAddress } from 'viem';
import { getAddress, zeroAddress } from 'viem';
import { logError } from '../../../../helpers/errorLogging';
import { useFractal } from '../../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function useERC721Tokens() {
} catch (e) {
logError('Error while getting ERC721 total supply');
}
return { name, symbol, address, votingWeight, totalSupply };
return { name, symbol, address: getAddress(address), votingWeight, totalSupply };
}),
);

Expand Down
18 changes: 11 additions & 7 deletions src/hooks/DAO/proposal/useCreateProposalTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react';
import { isHex, getAddress } from 'viem';
import { useFractal } from '../../../providers/App/AppProvider';
import useIPFSClient from '../../../providers/App/hooks/useIPFSClient';
import { ProposalExecuteData } from '../../../types';
Expand Down Expand Up @@ -53,16 +54,19 @@ export default function useCreateProposalTemplate() {

const { Hash } = await client.add(JSON.stringify(updatedTemplatesList));

const encodedUpdateValues = keyValuePairsContract.asProvider.interface.encodeFunctionData(
'updateValues',
[['proposalTemplates'], [Hash]],
);
if (!isHex(encodedUpdateValues)) {
return;
}

const proposal: ProposalExecuteData = {
metaData: proposalMetadata,
targets: [keyValuePairsContract.asProvider.address],
targets: [getAddress(keyValuePairsContract.asProvider.address)],
values: [0n],
calldatas: [
keyValuePairsContract.asProvider.interface.encodeFunctionData('updateValues', [
['proposalTemplates'],
[Hash],
]),
],
calldatas: [encodedUpdateValues],
};

return proposal;
Expand Down
Loading

0 comments on commit bb8a36c

Please sign in to comment.