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

Remove safe factory contract from fractal contracts and base contracts #1655

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
71 changes: 71 additions & 0 deletions src/assets/abi/GnosisSafeProxyFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const GnosisSafeProxyFactoryAbi = [
{
anonymous: false,
inputs: [
{ indexed: false, internalType: 'contract GnosisSafeProxy', name: 'proxy', type: 'address' },
{ indexed: false, internalType: 'address', name: 'singleton', type: 'address' },
],
name: 'ProxyCreation',
type: 'event',
},
{
inputs: [
{ internalType: 'address', name: '_singleton', type: 'address' },
{ internalType: 'bytes', name: 'initializer', type: 'bytes' },
{ internalType: 'uint256', name: 'saltNonce', type: 'uint256' },
],
name: 'calculateCreateProxyWithNonceAddress',
outputs: [{ internalType: 'contract GnosisSafeProxy', name: 'proxy', type: 'address' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ internalType: 'address', name: 'singleton', type: 'address' },
{ internalType: 'bytes', name: 'data', type: 'bytes' },
],
name: 'createProxy',
outputs: [{ internalType: 'contract GnosisSafeProxy', name: 'proxy', type: 'address' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ internalType: 'address', name: '_singleton', type: 'address' },
{ internalType: 'bytes', name: 'initializer', type: 'bytes' },
{ internalType: 'uint256', name: 'saltNonce', type: 'uint256' },
{ internalType: 'contract IProxyCreationCallback', name: 'callback', type: 'address' },
],
name: 'createProxyWithCallback',
outputs: [{ internalType: 'contract GnosisSafeProxy', name: 'proxy', type: 'address' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ internalType: 'address', name: '_singleton', type: 'address' },
{ internalType: 'bytes', name: 'initializer', type: 'bytes' },
{ internalType: 'uint256', name: 'saltNonce', type: 'uint256' },
],
name: 'createProxyWithNonce',
outputs: [{ internalType: 'contract GnosisSafeProxy', name: 'proxy', type: 'address' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'proxyCreationCode',
outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [],
name: 'proxyRuntimeCode',
outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
stateMutability: 'pure',
type: 'function',
},
] as const;

export default GnosisSafeProxyFactoryAbi;
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;
Da-Colon marked this conversation as resolved.
Show resolved Hide resolved

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
Loading