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

Align deployment of Safe to be of same version as Safe UI-deployed and having fallback handler attached #1375

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Box, Button, Text, Flex } from '@chakra-ui/react';
import { Check } from '@decent-org/fractal-ui';
import { TypedDataSigner } from '@ethersproject/abstract-signer';
import { GnosisSafe__factory, MultisigFreezeGuard } from '@fractal-framework/fractal-contracts';
import { MultisigFreezeGuard } from '@fractal-framework/fractal-contracts';
import { SafeMultisigTransactionWithTransfersResponse } from '@safe-global/safe-service-client';
import { Signer } from 'ethers';
import { useTranslation } from 'react-i18next';
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';
import { logError } from '../../../helpers/errorLogging';
Expand Down Expand Up @@ -121,7 +122,7 @@ export function TxActions({
if (!signerOrProvider || !safe?.address || !multisigTx.confirmations) {
return;
}
const safeContract = GnosisSafe__factory.connect(safe.address, signerOrProvider);
const safeContract = GnosisSafeL2__factory.connect(safe.address, signerOrProvider);
const safeTx = buildSafeTransaction({
...multisigTx,
});
Expand Down
9 changes: 3 additions & 6 deletions src/hooks/DAO/proposal/useSubmitProposal.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { TypedDataSigner } from '@ethersproject/abstract-signer';
import {
Azorius,
BaseStrategy__factory,
GnosisSafe__factory,
} from '@fractal-framework/fractal-contracts';
import { Azorius, BaseStrategy__factory } from '@fractal-framework/fractal-contracts';
import axios from 'axios';
import { BigNumber, Signer, utils } from 'ethers';
import { getAddress, isAddress } from 'ethers/lib/utils';
import { useCallback, useMemo, useState, useEffect } from 'react';
import { toast } from 'react-toastify';
import { GnosisSafeL2__factory } from '../../../assets/typechain-types/usul/factories/@gnosis.pm/safe-contracts/contracts';
import { ADDRESS_MULTISIG_METADATA } from '../../../constants/common';
import { buildSafeAPIPost, encodeMultiSend } from '../../../helpers';
import { logError } from '../../../helpers/errorLogging';
Expand Down Expand Up @@ -240,7 +237,7 @@ export default function useSubmitProposal() {
operation = 0;
}

const safeContract = GnosisSafe__factory.connect(safeAddress, signerOrProvider);
const safeContract = GnosisSafeL2__factory.connect(safeAddress, signerOrProvider);
await axios.post(
buildSafeApiUrl(safeBaseURL, `/safes/${safeAddress}/multisig-transactions/`),
await buildSafeAPIPost(
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/DAO/useBuildDAOTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import useSignerOrProvider from '../utils/useSignerOrProvider';

const useBuildDAOTx = () => {
const signerOrProvider = useSignerOrProvider();
const { createOptions } = useNetworkConfig();
const {
createOptions,
contracts: { fallbackHandler },
} = useNetworkConfig();

const {
baseContracts: {
Expand Down Expand Up @@ -121,6 +124,7 @@ const useBuildDAOTx = () => {
baseContracts,
azoriusContracts,
daoData,
fallbackHandler,
parentAddress,
parentTokenAddress
);
Expand Down Expand Up @@ -183,6 +187,7 @@ const useBuildDAOTx = () => {
dao,
governance,
createOptions,
fallbackHandler,
]
);

Expand Down
6 changes: 6 additions & 0 deletions src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
import { DAO_ROUTES } from '../../constants/routes';
import { TxBuilderFactory } from '../../models/TxBuilderFactory';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import {
BaseContracts,
AzoriusContracts,
Expand All @@ -18,6 +19,9 @@ import useSubmitProposal from './proposal/useSubmitProposal';
const useDeployAzorius = () => {
const signerOrProvider = useSignerOrProvider();
const { push } = useRouter();
const {
contracts: { fallbackHandler },
} = useNetworkConfig();
const {
node: { daoAddress, safe },
baseContracts: {
Expand Down Expand Up @@ -81,6 +85,7 @@ const useDeployAzorius = () => {
baseContracts,
azoriusContracts,
daoData,
fallbackHandler,
undefined,
undefined
);
Expand Down Expand Up @@ -142,6 +147,7 @@ const useDeployAzorius = () => {
submitProposal,
push,
safe,
fallbackHandler,
]
);

Expand Down
6 changes: 3 additions & 3 deletions src/hooks/safe/useSafeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MultisigFreezeVoting__factory,
VotesERC20__factory,
GnosisSafeProxyFactory__factory,
GnosisSafe__factory,
ModuleProxyFactory__factory,
LinearERC20Voting__factory,
Azorius__factory,
Expand All @@ -19,6 +18,7 @@ import {
} from '@fractal-framework/fractal-contracts';
import { useMemo } from 'react';
import { MultiSend__factory } from '../../assets/typechain-types/usul';
import { GnosisSafeL2__factory } from '../../assets/typechain-types/usul/factories/@gnosis.pm/safe-contracts/contracts';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import { useEthersProvider } from '../utils/useEthersProvider';
import useSignerOrProvider from '../utils/useSignerOrProvider';
Expand Down Expand Up @@ -76,8 +76,8 @@ export default function useSafeContracts() {
};

const safeSingletonContract = {
asSigner: GnosisSafe__factory.connect(safe, signerOrProvider),
asProvider: GnosisSafe__factory.connect(safe, provider),
asSigner: GnosisSafeL2__factory.connect(safe, signerOrProvider),
asProvider: GnosisSafeL2__factory.connect(safe, provider),
};

const zodiacModuleProxyFactoryContract = {
Expand Down
6 changes: 3 additions & 3 deletions src/models/AzoriusTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Azorius,
Azorius__factory,
GnosisSafe,
LinearERC20Voting,
LinearERC20Voting__factory,
LinearERC721Voting,
Expand All @@ -11,6 +10,7 @@ import {
} from '@fractal-framework/fractal-contracts';
import { BigNumber } from 'ethers';
import { defaultAbiCoder, getCreate2Address, solidityKeccak256 } from 'ethers/lib/utils';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall, getRandomBytes } from '../helpers';
import {
BaseContracts,
Expand All @@ -25,7 +25,7 @@ import { BaseTxBuilder } from './BaseTxBuilder';
import { generateContractByteCodeLinear, generateSalt } from './helpers/utils';

export class AzoriusTxBuilder extends BaseTxBuilder {
private readonly safeContract: GnosisSafe;
private readonly safeContract: GnosisSafeL2;
private readonly predictedSafeAddress: string;

private encodedSetupTokenData: string | undefined;
Expand Down Expand Up @@ -54,7 +54,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts,
daoData: AzoriusERC20DAO | AzoriusERC721DAO,
safeContract: GnosisSafe,
safeContract: GnosisSafeL2,
predictedSafeAddress: string,
parentAddress?: string,
parentTokenAddress?: string
Expand Down
6 changes: 3 additions & 3 deletions src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GnosisSafe } from '@fractal-framework/fractal-contracts';
import { ethers } from 'ethers';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall, encodeMultiSend } from '../helpers';
import {
BaseContracts,
Expand All @@ -24,7 +24,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
// Safe Data
private predictedSafeAddress: string;
private readonly createSafeTx: SafeTransaction;
private readonly safeContract: GnosisSafe;
private readonly safeContract: GnosisSafeL2;
private readonly parentStrategyType?: VotingStrategyType;
private readonly parentStrategyAddress?: string;

Expand All @@ -42,7 +42,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
saltNum: string,
predictedSafeAddress: string,
createSafeTx: SafeTransaction,
safeContract: GnosisSafe,
safeContract: GnosisSafeL2,
txBuilderFactory: TxBuilderFactory,
parentAddress?: string,
parentTokenAddress?: string,
Expand Down
8 changes: 4 additions & 4 deletions src/models/FreezeGuardTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Azorius,
GnosisSafe,
AzoriusFreezeGuard__factory,
ERC20FreezeVoting__factory,
MultisigFreezeGuard__factory,
Expand All @@ -12,6 +11,7 @@ import {
} from '@fractal-framework/fractal-contracts';
import { ethers } from 'ethers';
import { getCreate2Address, solidityKeccak256 } from 'ethers/lib/utils';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall } from '../helpers';
import {
BaseContracts,
Expand All @@ -33,7 +33,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder {
private readonly saltNum;

// Safe Data
private readonly safeContract: GnosisSafe;
private readonly safeContract: GnosisSafeL2;

// Freeze Voting Data
private freezeVotingType: any;
Expand All @@ -55,7 +55,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder {
signerOrProvider: any,
baseContracts: BaseContracts,
daoData: SubDAO,
safeContract: GnosisSafe,
safeContract: GnosisSafeL2,
saltNum: string,
parentAddress: string,
parentTokenAddress?: string,
Expand Down Expand Up @@ -134,7 +134,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder {
);
}

public buildSetGuardTx(contract: GnosisSafe | Azorius): SafeTransaction {
public buildSetGuardTx(contract: GnosisSafeL2 | Azorius): SafeTransaction {
return buildContractCall(contract, 'setGuard', [this.freezeGuardAddress], 0, false);
}

Expand Down
6 changes: 3 additions & 3 deletions src/models/MultisigTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GnosisSafe } from '@fractal-framework/fractal-contracts';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall } from '../helpers';
import { BaseContracts, SafeMultisigDAO, SafeTransaction } from '../types';

export class MultisigTxBuilder {
private baseContracts: BaseContracts;
private readonly daoData: SafeMultisigDAO;
private readonly safeContract: GnosisSafe;
private readonly safeContract: GnosisSafeL2;

constructor(baseContracts: BaseContracts, daoData: SafeMultisigDAO, safeContract: GnosisSafe) {
constructor(baseContracts: BaseContracts, daoData: SafeMultisigDAO, safeContract: GnosisSafeL2) {
this.baseContracts = baseContracts;
this.daoData = daoData;
this.safeContract = safeContract;
Expand Down
11 changes: 8 additions & 3 deletions src/models/TxBuilderFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GnosisSafe, GnosisSafe__factory } from '@fractal-framework/fractal-contracts';
import { ethers } from 'ethers';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { GnosisSafeL2__factory } from '../assets/typechain-types/usul/factories/@gnosis.pm/safe-contracts/contracts';
import { getRandomBytes } from '../helpers';
import {
BaseContracts,
Expand All @@ -24,13 +25,15 @@ export class TxBuilderFactory extends BaseTxBuilder {
// Safe Data
public predictedSafeAddress: string | undefined;
public createSafeTx: SafeTransaction | undefined;
private safeContract: GnosisSafe | undefined;
private safeContract: GnosisSafeL2 | undefined;
public fallbackHandler: string;

constructor(
signerOrProvider: ethers.Signer | any,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts | undefined,
daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO | SubDAO,
fallbackHandler: string,
parentAddress?: string,
parentTokenAddress?: string
) {
Expand All @@ -43,11 +46,12 @@ export class TxBuilderFactory extends BaseTxBuilder {
parentTokenAddress
);

this.fallbackHandler = fallbackHandler;
this.saltNum = getRandomBytes();
}

public setSafeContract(safeAddress: string) {
const safeContract = GnosisSafe__factory.connect(safeAddress, this.signerOrProvider);
const safeContract = GnosisSafeL2__factory.connect(safeAddress, this.signerOrProvider);
this.safeContract = safeContract;
}

Expand All @@ -58,6 +62,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
this.baseContracts.safeSingletonContract,
this.daoData as SafeMultisigDAO,
this.saltNum,
this.fallbackHandler,
!!this.azoriusContracts
);

Expand Down
4 changes: 2 additions & 2 deletions src/models/helpers/fractalModuleData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
FractalModule,
FractalModule__factory,
GnosisSafe,
ModuleProxyFactory,
} from '@fractal-framework/fractal-contracts';
import { ethers } from 'ethers';
import { GnosisSafeL2 } from '../../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall } from '../../helpers/crypto';
import { SafeTransaction } from '../../types';
import {
Expand All @@ -23,7 +23,7 @@ export interface FractalModuleData {
export const fractalModuleData = (
fractalModuleMasterCopyContract: FractalModule,
zodiacModuleProxyFactoryContract: ModuleProxyFactory,
safeContract: GnosisSafe,
safeContract: GnosisSafeL2,
saltNum: string,
parentAddress?: string
): FractalModuleData => {
Expand Down
8 changes: 5 additions & 3 deletions src/models/helpers/safeData.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { GnosisSafe, GnosisSafeProxyFactory } from '@fractal-framework/fractal-contracts';
import { GnosisSafeProxyFactory } from '@fractal-framework/fractal-contracts';
import { ethers } from 'ethers';
import { getCreate2Address, solidityKeccak256 } from 'ethers/lib/utils';
import { MultiSend } from '../../assets/typechain-types/usul';
import { GnosisSafeL2 } from '../../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall } from '../../helpers/crypto';
import { SafeMultisigDAO } from '../../types';
const { AddressZero, HashZero } = ethers.constants;

export const safeData = async (
multiSendContract: MultiSend,
safeFactoryContract: GnosisSafeProxyFactory,
safeSingletonContract: GnosisSafe,
safeSingletonContract: GnosisSafeL2,
daoData: SafeMultisigDAO,
saltNum: string,
fallbackHandler: string,
hasAzorius?: boolean
) => {
const signers = hasAzorius
Expand All @@ -26,7 +28,7 @@ export const safeData = async (
1, // Threshold
AddressZero,
HashZero,
AddressZero,
fallbackHandler, // Fallback handler
AddressZero,
0,
AddressZero,
Expand Down
15 changes: 10 additions & 5 deletions src/providers/NetworkConfig/networks/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import MultisigFreezeVoting from '@fractal-framework/fractal-contracts/deploymen
import VotesERC20 from '@fractal-framework/fractal-contracts/deployments/mainnet/VotesERC20.json';
import VotesERC20Wrapper from '@fractal-framework/fractal-contracts/deployments/mainnet/VotesERC20Wrapper.json';
import {
getSafeSingletonDeployment,
getProxyFactoryDeployment,
getMultiSendCallOnlyDeployment,
getSafeL2SingletonDeployment,
getCompatibilityFallbackHandlerDeployment,
} from '@safe-global/safe-deployments';
import { mainnet } from 'wagmi/chains';
import { GovernanceType } from '../../../types';
Expand Down Expand Up @@ -47,18 +48,22 @@ export const mainnetConfig: NetworkConfig = {
erc20FreezeVotingMasterCopy: ERC20FreezeVoting.address,
erc721FreezeVotingMasterCopy: '', // TODO - Add actual address once contract is deployed on mainnet
multisigFreezeGuardMasterCopy: MultisigFreezeGuard.address,
safe: getSafeSingletonDeployment({ version: SAFE_VERSION, network: CHAIN_ID.toString() })
?.defaultAddress!,
fallbackHandler: getCompatibilityFallbackHandlerDeployment({
version: SAFE_VERSION,
network: CHAIN_ID.toString(),
})?.networkAddresses[CHAIN_ID.toString()]!,
safe: getSafeL2SingletonDeployment({ version: SAFE_VERSION, network: CHAIN_ID.toString() })
?.networkAddresses[CHAIN_ID.toString()]!,
safeFactory: getProxyFactoryDeployment({
version: SAFE_VERSION,
network: CHAIN_ID.toString(),
})?.defaultAddress!,
})?.networkAddresses[CHAIN_ID.toString()]!,
zodiacModuleProxyFactory: ModuleProxyFactory.address,
linearVotingMasterCopy: LinearERC20Voting.address,
multisend: getMultiSendCallOnlyDeployment({
version: SAFE_VERSION,
network: CHAIN_ID.toString(),
})?.defaultAddress!,
})?.networkAddresses[CHAIN_ID.toString()]!,
votesERC20WrapperMasterCopy: VotesERC20Wrapper.address,
keyValuePairs: KeyValuePairs.address,
},
Expand Down
Loading