Skip to content

Commit

Permalink
Remove safeFactoryContract from FractalContracts & BaseContracts inte…
Browse files Browse the repository at this point in the history
…rfaces, resolve downstream issues
  • Loading branch information
adamgall committed May 7, 2024
1 parent 558a1b2 commit 8942b18
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/hooks/DAO/useBuildDAOTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const useBuildDAOTx = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
},
} = useNetworkConfig();

Expand All @@ -49,7 +50,6 @@ const useBuildDAOTx = () => {
}
const {
multiSendContract,
safeFactoryContract,
safeSingletonContract,
linearVotingMasterCopyContract,
linearVotingERC721MasterCopyContract,
Expand Down Expand Up @@ -94,7 +94,6 @@ const useBuildDAOTx = () => {

const buildrerBaseContracts: BaseContracts = {
fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asSigner,
safeFactoryContract: safeFactoryContract.asSigner,
safeSingletonContract: safeSingletonContract.asSigner,
multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asSigner,
multiSendContract: multiSendContract.asSigner,
Expand All @@ -115,6 +114,7 @@ const useBuildDAOTx = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
parentAddress,
parentTokenAddress,
);
Expand Down Expand Up @@ -166,6 +166,7 @@ const useBuildDAOTx = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
],
);

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const useDeployAzorius = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
},
addressPrefix,
} = useNetworkConfig();
Expand All @@ -52,7 +53,6 @@ const useDeployAzorius = () => {
}
const {
multiSendContract,
safeFactoryContract,
safeSingletonContract,
linearVotingMasterCopyContract,
linearVotingERC721MasterCopyContract,
Expand All @@ -78,7 +78,6 @@ const useDeployAzorius = () => {

const builderBaseContracts: BaseContracts = {
fractalModuleMasterCopyContract: fractalModuleMasterCopyContract.asProvider,
safeFactoryContract: safeFactoryContract.asProvider,
safeSingletonContract: safeSingletonContract.asProvider,
multisigFreezeGuardMasterCopyContract: multisigFreezeGuardMasterCopyContract.asProvider,
multiSendContract: multiSendContract.asProvider,
Expand All @@ -99,6 +98,7 @@ const useDeployAzorius = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
undefined,
undefined,
);
Expand Down Expand Up @@ -161,6 +161,7 @@ const useDeployAzorius = () => {
votesERC20MasterCopy,
keyValuePairs,
fractalRegistry,
safeFactory,
],
);

Expand Down
13 changes: 11 additions & 2 deletions src/models/TxBuilderFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ethers } from 'ethers';
import { PublicClient, getAddress } from 'viem';
import { PublicClient, getAddress, getContract } from 'viem';
import GnosisSafeProxyFactoryAbi from '../assets/abi/GnosisSafeProxyFactory';
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';
Expand Down Expand Up @@ -33,6 +34,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
private votesERC20MasterCopyAddress: string;
private keyValuePairsAddress: string;
private fractalRegistryAddress: string;
private gnosisSafeProxyFactoryAddress: string;

constructor(
signerOrProvider: ethers.Signer | any,
Expand All @@ -45,6 +47,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
votesERC20MasterCopyAddress: string,
keyValuePairsAddress: string,
fractalRegistryAddress: string,
gnosisSafeProxyFactoryAddress: string,
parentAddress?: string,
parentTokenAddress?: string,
) {
Expand All @@ -64,6 +67,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
this.votesERC20MasterCopyAddress = votesERC20MasterCopyAddress;
this.keyValuePairsAddress = keyValuePairsAddress;
this.fractalRegistryAddress = fractalRegistryAddress;
this.gnosisSafeProxyFactoryAddress = gnosisSafeProxyFactoryAddress;
}

public setSafeContract(safeAddress: string) {
Expand All @@ -72,9 +76,14 @@ export class TxBuilderFactory extends BaseTxBuilder {
}

public async setupSafeData(): Promise<void> {
const safeProxyFactoryContract = getContract({
abi: GnosisSafeProxyFactoryAbi,
address: getAddress(this.gnosisSafeProxyFactoryAddress),
client: this.publicClient,
});
const { predictedSafeAddress, createSafeTx } = await safeData(
this.baseContracts.multiSendContract,
this.baseContracts.safeFactoryContract,
safeProxyFactoryContract,
this.baseContracts.safeSingletonContract,
this.daoData as SafeMultisigDAO,
this.saltNum,
Expand Down
15 changes: 9 additions & 6 deletions src/models/helpers/safeData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GnosisSafeProxyFactory } from '@fractal-framework/fractal-contracts';
import {
getCreate2Address,
zeroAddress,
Expand All @@ -9,16 +8,19 @@ import {
encodeFunctionData,
isHex,
hexToBigInt,
GetContractReturnType,
PublicClient,
} from 'viem';
import GnosisSafeL2Abi from '../../assets/abi/GnosisSafeL2';
import GnosisSafeProxyFactoryAbi from '../../assets/abi/GnosisSafeProxyFactory';
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 { buildContractCallViem } from '../../helpers/crypto';
import { SafeMultisigDAO } from '../../types';

export const safeData = async (
multiSendContract: MultiSend,
safeFactoryContract: GnosisSafeProxyFactory,
safeFactoryContract: GetContractReturnType<typeof GnosisSafeProxyFactoryAbi, PublicClient>,
safeSingletonContract: GnosisSafeL2,
daoData: SafeMultisigDAO,
saltNum: bigint,
Expand All @@ -44,7 +46,7 @@ export const safeData = async (
abi: GnosisSafeL2Abi,
});

const safeFactoryContractProxyCreationCode = await safeFactoryContract.proxyCreationCode();
const safeFactoryContractProxyCreationCode = await safeFactoryContract.read.proxyCreationCode();
if (!isHex(safeFactoryContractProxyCreationCode)) {
throw new Error('Error retrieving proxy creation code from Safe Factory Contract ');
}
Expand All @@ -68,8 +70,9 @@ export const safeData = async (
),
});

const createSafeTx = buildContractCall(
safeFactoryContract,
const createSafeTx = buildContractCallViem(
GnosisSafeProxyFactoryAbi,
safeFactoryContract.address,
'createProxyWithNonce',
[safeSingletonContract.address, createSafeCalldata, saltNum],
0,
Expand Down
2 changes: 0 additions & 2 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
GnosisSafeProxyFactory,
ModuleProxyFactory,
FractalModule,
MultisigFreezeGuard,
Expand All @@ -21,7 +20,6 @@ export type ContractConnection<T> = {

export interface BaseContracts {
fractalModuleMasterCopyContract: FractalModule;
safeFactoryContract: GnosisSafeProxyFactory;
safeSingletonContract: GnosisSafeL2;
multisigFreezeGuardMasterCopyContract: MultisigFreezeGuard;
multiSendContract: MultiSend;
Expand Down
2 changes: 0 additions & 2 deletions src/types/fractal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
FractalModule,
GnosisSafeProxyFactory,
ModuleProxyFactory,
LinearERC20Voting,
Azorius,
Expand Down Expand Up @@ -331,7 +330,6 @@ export interface NodeHierarchy {

export interface FractalContracts {
multiSendContract: ContractConnection<MultiSend>;
safeFactoryContract: ContractConnection<GnosisSafeProxyFactory>;
fractalAzoriusMasterCopyContract: ContractConnection<Azorius>;
linearVotingMasterCopyContract: ContractConnection<LinearERC20Voting>;
linearVotingERC721MasterCopyContract: ContractConnection<LinearERC721Voting>;
Expand Down

0 comments on commit 8942b18

Please sign in to comment.