From 07696c881a8bac26c41b45b3c05b3505ed33240e Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Wed, 8 May 2024 15:54:48 -0400 Subject: [PATCH] Remove GnosisSafeL2 Typechain from TxBuilderFactory and Builder classes --- src/models/AzoriusTxBuilder.ts | 38 +++++++++++++++++------------- src/models/DaoTxBuilder.ts | 21 +++++++++-------- src/models/FreezeGuardTxBuilder.ts | 23 +++++++++++++----- src/models/MultisigTxBuilder.ts | 20 ++++++++++------ src/models/TxBuilderFactory.ts | 20 +++++++--------- 5 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/models/AzoriusTxBuilder.ts b/src/models/AzoriusTxBuilder.ts index 7334cb4999..d22cbad6a0 100644 --- a/src/models/AzoriusTxBuilder.ts +++ b/src/models/AzoriusTxBuilder.ts @@ -20,10 +20,10 @@ import { encodeFunctionData, PublicClient, } from 'viem'; +import GnosisSafeL2Abi from '../assets/abi/GnosisSafeL2'; import ModuleProxyFactoryAbi from '../assets/abi/ModuleProxyFactory'; import VotesERC20Abi from '../assets/abi/VotesERC20'; import VotesERC20WrapperAbi from '../assets/abi/VotesERC20Wrapper'; -import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts'; import { SENTINEL_ADDRESS } from '../constants/common'; import { buildContractCall, buildContractCallViem, getRandomBytes } from '../helpers'; import { @@ -39,7 +39,7 @@ import { BaseTxBuilder } from './BaseTxBuilder'; import { generateContractByteCodeLinear, generateSalt } from './helpers/utils'; export class AzoriusTxBuilder extends BaseTxBuilder { - private readonly safeContract: GnosisSafeL2; + private readonly safeContractAddress: Address; private encodedSetupTokenData: Hex | undefined; private encodedSetupERC20WrapperData: Hex | undefined; @@ -72,7 +72,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { baseContracts: BaseContracts, azoriusContracts: AzoriusContracts, daoData: AzoriusERC20DAO | AzoriusERC721DAO, - safeContract: GnosisSafeL2, + safeContractAddress: Address, votesERC20WrapperMasterCopyAddress: string, votesERC20MasterCopyAddress: string, moduleProxyFactoryAddress: Address, @@ -89,7 +89,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { parentTokenAddress, ); - this.safeContract = safeContract; + this.safeContractAddress = safeContractAddress; this.tokenNonce = getRandomBytes(); this.claimNonce = getRandomBytes(); @@ -139,8 +139,9 @@ export class AzoriusTxBuilder extends BaseTxBuilder { public buildRemoveOwners(owners: string[]): SafeTransaction[] { const removeOwnerTxs = owners.map(owner => - buildContractCall( - this.safeContract!, + buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'removeOwner', [this.baseContracts.multiSendContract.address, owner, 1], 0, @@ -164,8 +165,9 @@ export class AzoriusTxBuilder extends BaseTxBuilder { } public buildEnableAzoriusModuleTx(): SafeTransaction { - return buildContractCall( - this.safeContract!, + return buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'enableModule', [this.azoriusContract!.address], 0, @@ -174,8 +176,9 @@ export class AzoriusTxBuilder extends BaseTxBuilder { } public buildAddAzoriusContractAsOwnerTx(): SafeTransaction { - return buildContractCall( - this.safeContract!, + return buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'addOwnerWithThreshold', [this.azoriusContract!.address, 1], 0, @@ -184,8 +187,9 @@ export class AzoriusTxBuilder extends BaseTxBuilder { } public buildRemoveMultiSendOwnerTx(): SafeTransaction { - return buildContractCall( - this.safeContract!, + return buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'removeOwner', [this.azoriusContract!.address, this.baseContracts.multiSendContract.address, 1], 0, @@ -339,7 +343,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { // Send any un-allocated tokens to the Safe Treasury if (azoriusGovernanceDaoData.tokenSupply > tokenAllocationSum) { // TODO -- verify this doesn't need to be the predicted safe address (that they are the same) - tokenAllocationsOwners.push(getAddress(this.safeContract.address)); + tokenAllocationsOwners.push(this.safeContractAddress); tokenAllocationsValues.push(azoriusGovernanceDaoData.tokenSupply - tokenAllocationSum); } @@ -391,7 +395,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { parseAbiParameters('uint32, address, address, address, uint256'), [ 0, // `deadlineBlock`, 0 means never expires, currently no UI for setting this in the app. - getAddress(this.safeContract.address), + this.safeContractAddress, getAddress(this.parentTokenAddress), getAddress(this.predictedTokenAddress), azoriusGovernanceDaoData.parentAllocationAmount, @@ -435,7 +439,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { const encodedStrategyInitParams = encodeAbiParameters( parseAbiParameters('address, address, address, uint32, uint256, uint256, uint256'), [ - getAddress(this.safeContract.address), // owner + this.safeContractAddress, // owner getAddress(this.predictedTokenAddress), // governance token SENTINEL_ADDRESS, // Azorius module Number(azoriusGovernanceDaoData.votingPeriod), @@ -480,7 +484,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { 'address, address[], uint256[], address, uint32, uint256, uint256, uint256', ), [ - getAddress(this.safeContract.address), // owner + this.safeContractAddress, // owner daoData.nfts.map(nft => nft.tokenAddress!), // governance tokens addresses daoData.nfts.map(nft => nft.tokenWeight), // governance tokens weights SENTINEL_ADDRESS, // Azorius module @@ -525,7 +529,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { // TODO - verify we can use safe contract address private setPredictedAzoriusAddress() { const azoriusGovernanceDaoData = this.daoData as AzoriusGovernanceDAO; - const safeContractAddress = getAddress(this.safeContract.address); + const safeContractAddress = this.safeContractAddress; const encodedInitAzoriusData = encodeAbiParameters( parseAbiParameters(['address, address, address, address[], uint32, uint32']), [ diff --git a/src/models/DaoTxBuilder.ts b/src/models/DaoTxBuilder.ts index ca50f19db2..44cacb9dd2 100644 --- a/src/models/DaoTxBuilder.ts +++ b/src/models/DaoTxBuilder.ts @@ -1,9 +1,9 @@ import { ethers } from 'ethers'; -import { PublicClient, getAddress, zeroAddress } from 'viem'; +import { Address, PublicClient, getAddress, zeroAddress } from 'viem'; import FractalRegistryAbi from '../assets/abi/FractalRegistry'; +import GnosisSafeL2Abi from '../assets/abi/GnosisSafeL2'; import KeyValuePairsAbi from '../assets/abi/KeyValuePairs'; -import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts'; -import { buildContractCall, buildContractCallViem, encodeMultiSend } from '../helpers'; +import { buildContractCallViem, encodeMultiSend } from '../helpers'; import { BaseContracts, SafeMultisigDAO, @@ -24,7 +24,7 @@ export class DaoTxBuilder extends BaseTxBuilder { // Safe Data private readonly createSafeTx: SafeTransaction; - private readonly safeContract: GnosisSafeL2; + private readonly safeContractAddress: Address; private readonly parentStrategyType?: VotingStrategyType; private readonly parentStrategyAddress?: string; @@ -46,7 +46,7 @@ export class DaoTxBuilder extends BaseTxBuilder { daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO, saltNum: bigint, createSafeTx: SafeTransaction, - safeContract: GnosisSafeL2, + safeContractAddress: Address, txBuilderFactory: TxBuilderFactory, keyValuePairsAddress: string, fractalRegistryAddress: string, @@ -67,7 +67,7 @@ export class DaoTxBuilder extends BaseTxBuilder { ); this.createSafeTx = createSafeTx; - this.safeContract = safeContract; + this.safeContractAddress = safeContractAddress; this.txBuilderFactory = txBuilderFactory; this.saltNum = saltNum; this.parentStrategyType = parentStrategyType; @@ -192,7 +192,7 @@ export class DaoTxBuilder extends BaseTxBuilder { freezeGuardTxBuilder.buildDeployZodiacModuleTx(), freezeGuardTxBuilder.buildFreezeVotingSetupTx(), freezeGuardTxBuilder.buildDeployFreezeGuardTx(), - freezeGuardTxBuilder.buildSetGuardTx(this.safeContract), + freezeGuardTxBuilder.buildSetGuardTxSafe(this.safeContractAddress), ]); } @@ -220,7 +220,7 @@ export class DaoTxBuilder extends BaseTxBuilder { const { enableFractalModuleTx, deployFractalModuleTx }: FractalModuleData = fractalModuleData( this.baseContracts.fractalModuleMasterCopyContract, getAddress(this.moduleProxyFactoryAddress), - getAddress(this.safeContract.address), + this.safeContractAddress, this.saltNum, !this.parentAddress ? undefined : getAddress(this.parentAddress), ); @@ -257,8 +257,9 @@ export class DaoTxBuilder extends BaseTxBuilder { private buildExecInternalSafeTx(signatures: string): SafeTransaction { const safeInternalTx = encodeMultiSend(this.internalTxs); - return buildContractCall( - this.safeContract!, + return buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'execTransaction', [ this.baseContracts.multiSendContract.address, // to diff --git a/src/models/FreezeGuardTxBuilder.ts b/src/models/FreezeGuardTxBuilder.ts index 48875e604c..7a70c767a6 100644 --- a/src/models/FreezeGuardTxBuilder.ts +++ b/src/models/FreezeGuardTxBuilder.ts @@ -21,8 +21,8 @@ import { isHex, PublicClient, } from 'viem'; +import GnosisSafeL2Abi from '../assets/abi/GnosisSafeL2'; import ModuleProxyFactoryAbi from '../assets/abi/ModuleProxyFactory'; -import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts'; import { buildContractCall, buildContractCallViem } from '../helpers'; import { BaseContracts, @@ -39,7 +39,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { private readonly saltNum; // Safe Data - private readonly safeContract: GnosisSafeL2; + private readonly safeContractAddress: Address; // Freeze Voting Data private freezeVotingType: any; @@ -63,7 +63,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { publicClient: PublicClient, baseContracts: BaseContracts, daoData: SubDAO, - safeContract: GnosisSafeL2, + safeContractAddress: Address, saltNum: bigint, parentAddress: Address, moduleProxyFactoryAddress: Address, @@ -84,7 +84,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { parentTokenAddress, ); - this.safeContract = safeContract; + this.safeContractAddress = safeContractAddress; this.saltNum = saltNum; this.azoriusAddress = azoriusAddress; this.strategyAddress = strategyAddress; @@ -151,10 +151,21 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { ); } - public buildSetGuardTx(contract: GnosisSafeL2 | Azorius): SafeTransaction { + public buildSetGuardTx(contract: Azorius): SafeTransaction { return buildContractCall(contract, 'setGuard', [this.freezeGuardAddress], 0, false); } + public buildSetGuardTxSafe(safeAddress: Address): SafeTransaction { + return buildContractCallViem( + GnosisSafeL2Abi, + safeAddress, + 'setGuard', + [this.freezeGuardAddress], + 0, + false, + ); + } + public buildDeployFreezeGuardTx() { return buildContractCallViem( ModuleProxyFactoryAbi, @@ -246,7 +257,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { Number(subDaoData.executionPeriod), // Execution Period getAddress(this.parentAddress), // Owner -- Parent DAO getAddress(this.freezeVotingAddress), // Freeze Voting - getAddress(this.safeContract.address), // Safe + this.safeContractAddress, // Safe ]), ], ); diff --git a/src/models/MultisigTxBuilder.ts b/src/models/MultisigTxBuilder.ts index 89cac1fd6c..5139cd463d 100644 --- a/src/models/MultisigTxBuilder.ts +++ b/src/models/MultisigTxBuilder.ts @@ -1,16 +1,21 @@ -import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts'; -import { buildContractCall } from '../helpers'; +import { Address } from 'viem'; +import GnosisSafeL2Abi from '../assets/abi/GnosisSafeL2'; +import { buildContractCallViem } from '../helpers'; import { BaseContracts, SafeMultisigDAO, SafeTransaction } from '../types'; export class MultisigTxBuilder { private baseContracts: BaseContracts; private readonly daoData: SafeMultisigDAO; - private readonly safeContract: GnosisSafeL2; + private readonly safeContractAddress: Address; - constructor(baseContracts: BaseContracts, daoData: SafeMultisigDAO, safeContract: GnosisSafeL2) { + constructor( + baseContracts: BaseContracts, + daoData: SafeMultisigDAO, + safeContractAddress: Address, + ) { this.baseContracts = baseContracts; this.daoData = daoData; - this.safeContract = safeContract; + this.safeContractAddress = safeContractAddress; } public signatures = (): string => { @@ -23,8 +28,9 @@ export class MultisigTxBuilder { }; public buildRemoveMultiSendOwnerTx(): SafeTransaction { - return buildContractCall( - this.safeContract!, + return buildContractCallViem( + GnosisSafeL2Abi, + this.safeContractAddress, 'removeOwner', [ this.daoData.trustedAddresses[this.daoData.trustedAddresses.length - 1], diff --git a/src/models/TxBuilderFactory.ts b/src/models/TxBuilderFactory.ts index d03b807133..fc64d9f701 100644 --- a/src/models/TxBuilderFactory.ts +++ b/src/models/TxBuilderFactory.ts @@ -1,9 +1,7 @@ import { ethers } from 'ethers'; -import { PublicClient, getAddress, getContract } from 'viem'; +import { Address, PublicClient, getAddress, getContract } from 'viem'; import GnosisSafeL2Abi from '../assets/abi/GnosisSafeL2'; 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'; import { BaseContracts, @@ -28,7 +26,7 @@ export class TxBuilderFactory extends BaseTxBuilder { // Safe Data public predictedSafeAddress: string | undefined; public createSafeTx: SafeTransaction | undefined; - private safeContract: GnosisSafeL2 | undefined; + private safeContractAddress: Address | undefined; public fallbackHandler: string; private votesERC20WrapperMasterCopyAddress: string; @@ -77,9 +75,9 @@ export class TxBuilderFactory extends BaseTxBuilder { this.moduleProxyFactoryAddress = moduleProxyFactoryAddress; } - public setSafeContract(safeAddress: string) { - const safeContract = GnosisSafeL2__factory.connect(safeAddress, this.signerOrProvider); - this.safeContract = safeContract; + public setSafeContract(safeAddress: Address) { + // const safeContract = GnosisSafeL2__factory.connect(safeAddress, this.signerOrProvider); + this.safeContractAddress = safeAddress; } public async setupSafeData(): Promise { @@ -121,7 +119,7 @@ export class TxBuilderFactory extends BaseTxBuilder { this.daoData, this.saltNum, this.createSafeTx!, - this.safeContract!, + this.safeContractAddress!, this, this.keyValuePairsAddress, this.fractalRegistryAddress, @@ -144,7 +142,7 @@ export class TxBuilderFactory extends BaseTxBuilder { this.publicClient, this.baseContracts, this.daoData as SubDAO, - this.safeContract!, + this.safeContractAddress!, this.saltNum, getAddress(this.parentAddress!), getAddress(this.moduleProxyFactoryAddress), @@ -161,7 +159,7 @@ export class TxBuilderFactory extends BaseTxBuilder { return new MultisigTxBuilder( this.baseContracts, this.daoData as SafeMultisigDAO, - this.safeContract!, + getAddress(this.safeContractAddress!), ); } @@ -172,7 +170,7 @@ export class TxBuilderFactory extends BaseTxBuilder { this.baseContracts, this.azoriusContracts!, this.daoData as AzoriusERC20DAO, - this.safeContract!, + this.safeContractAddress!, this.votesERC20WrapperMasterCopyAddress, this.votesERC20MasterCopyAddress, getAddress(this.moduleProxyFactoryAddress),