Skip to content

Commit

Permalink
Remove GnosisSafeL2 Typechain from TxBuilderFactory and Builder classes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed May 8, 2024
1 parent 0a98bd9 commit 07696c8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 51 deletions.
38 changes: 21 additions & 17 deletions src/models/AzoriusTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -89,7 +89,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
parentTokenAddress,
);

this.safeContract = safeContract;
this.safeContractAddress = safeContractAddress;

this.tokenNonce = getRandomBytes();
this.claimNonce = getRandomBytes();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']),
[
Expand Down
21 changes: 11 additions & 10 deletions src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -192,7 +192,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
freezeGuardTxBuilder.buildDeployZodiacModuleTx(),
freezeGuardTxBuilder.buildFreezeVotingSetupTx(),
freezeGuardTxBuilder.buildDeployFreezeGuardTx(),
freezeGuardTxBuilder.buildSetGuardTx(this.safeContract),
freezeGuardTxBuilder.buildSetGuardTxSafe(this.safeContractAddress),
]);
}

Expand Down Expand Up @@ -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),
);
Expand Down Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions src/models/FreezeGuardTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
]),
],
);
Expand Down
20 changes: 13 additions & 7 deletions src/models/MultisigTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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],
Expand Down
20 changes: 9 additions & 11 deletions src/models/TxBuilderFactory.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -121,7 +119,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
this.daoData,
this.saltNum,
this.createSafeTx!,
this.safeContract!,
this.safeContractAddress!,
this,
this.keyValuePairsAddress,
this.fractalRegistryAddress,
Expand All @@ -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),
Expand All @@ -161,7 +159,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
return new MultisigTxBuilder(
this.baseContracts,
this.daoData as SafeMultisigDAO,
this.safeContract!,
getAddress(this.safeContractAddress!),
);
}

Expand All @@ -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),
Expand Down

0 comments on commit 07696c8

Please sign in to comment.